107 int header_size = 17;
113 fd = open(
"rom0:KROM", O_RDONLY);
118 printf(
"Error opening KROM font.\n");
124 size = header_size + char_size * 256;
126 fontx->
font = (
char*)malloc(size);
131 printf(
"Error allocating %d bytes of memory.\n", size);
138 memset(fontx->
font,0,size);
141 lseek(fd, 0x198DE, SEEK_SET);
145 if (read(fd,fontx->
font + header_size+char_size*33, char_size*95) < 0)
148 printf(
"Error reading rom0:KROM.\n");
162 strncpy(fontx_header->
id,
"FONTX2", 6);
163 fontx_header->
id[6] =
'\0';
164 strncpy(fontx_header->
name,
"KROM", 8);
165 fontx_header->
name[8] =
'\0';
167 fontx_header->
width = 8;
168 fontx_header->
height = 15;
189 int header_size = 18;
195 fd = open(
"rom0:KROM", O_RDONLY);
200 printf(
"Error opening KROM font.\n");
204 size = header_size + table_num*table_size + char_num*char_size;
206 fontx->
font = (
char*)malloc(size);
211 printf(
"Error allocating memory.\n");
218 memset(fontx->
font,0,size);
221 lseek(fd, 0, SEEK_SET);
224 if (read(fd, fontx->
font+header_size+table_num*table_size, char_size*char_num) < 0)
227 printf(
"Error reading font.\n");
240 strncpy(fontx_header->
id,
"FONTX2", 6);
241 fontx_header->
id[6] =
'\0';
242 strncpy(fontx_header->
name,
"KROM", 8);
243 fontx_header->
name[8] =
'\0';
245 fontx_header->
width = 16;
246 fontx_header->
height = 15;
272 if (!strcmp(
"rom0:KROM",path) || !strcmp(
"rom0:/KROM",path))
291 printf(
"Error opening %s\n", path);
301 file = fopen(path,
"r");
306 printf(
"Error opening %s\n", path);
312 fseek(file, 0, SEEK_END);
314 fseek(file, 0, SEEK_SET);
316 fontx->
font = (
char *)malloc(size);
321 printf(
"Error allocating %ld bytes of memory.\n", size);
327 fread(fontx->
font, size, 1, file);
335 if (strncmp(fontx_header->
id,
"FONTX2", 6) != 0)
338 printf(
"Not FONTX2 type font!\n");
345 if (fontx_header->
type != type)
348 printf(
"Type mismatch\n");
356 strcpy(fontx->
name,fontx_header->
name);
401 int table_offset = 0;
408 printf(
"Font data not loaded.\n");
422 for (i = 0; i < fontx_header->
table_num; i++)
442 for (i = 0; i < table; i++)
449 table_offset = table_offset + table + ( c - fontx_header->
block[table].
start);
459 unsigned char mask = 0x80;
528 for (i=0;i<fontx_header->
height;i++)
534 for (j=0;j < fontx->
rowsize;j++)
568 int length = strlen((
const char *)str);
575 float w = fontx_header->
width;
576 float h = fontx_header->
height;
589 for (i = 0; i < length; i++)
592 while (str[i] ==
'\t' || str[i] ==
'\n')
597 x_orig[line] = v_pos.x;
609 x_orig[line] = v_pos.x;
619 for (i = 0; i < length; i++)
622 while (str[i] ==
'\t' || str[i] ==
'\n')
632 x_orig[line] = v_pos.x - (line_num[line] * (w + wm));
646 x_orig[line] = v_pos.x - (line_num[line] * (w + wm));
656 for (i = 0; i < length; i++)
659 while (str[i] ==
'\t' || str[i] ==
'\n')
669 x_orig[line] = v_pos.x - (line_num[line] * (w + wm))/2.0f;
682 x_orig[line] = v_pos.x - (line_num[line] * (w + wm))/2.0f;
698 for (j = 0; j < length; j++)
701 while(str[j] ==
'\n' || str[j] ==
'\t')
707 v_pos.x = x_orig[line];
720 else if (str[j] >= 0xA1 && str[j] <= 0xDF)
745 int length = strlen((
const char *)str);
748 short halfwidth[100];
749 short fullwidth[100];
755 float hw = ascii_header->
width;
757 float fw = kanji_header->width;
758 float h = kanji_header->height;
772 for (i = 0; i < length; i++)
775 while (str[i] ==
'\t'|| str[i] ==
'\n')
779 halfwidth[line] += 4;
783 x_orig[line] = v_pos.
x;
794 x_orig[line] = v_pos.
x;
804 for (i = 0; i < length; i++)
807 while (str[i] ==
'\t'|| str[i] ==
'\n')
811 halfwidth[line] += 4;
815 x_orig[line] = v_pos.
x - ((halfwidth[line] * (hw+wm)) + (fullwidth[line] * (fw + wm)));;
827 else if (str[i] >= 0xA1 && str[i] <= 0xDF)
831 else if (str[i] >= 0x81 && str[i] <= 0x9F)
835 else if (str[i] >= 0xE0 && str[i] <= 0xEF)
842 x_orig[line] = v_pos.
x - ((halfwidth[line] * (hw+wm)) + (fullwidth[line] * (fw + wm)));
852 for (i = 0; i < length; i++)
855 while (str[i] ==
'\t'|| str[i] ==
'\n')
859 halfwidth[line] += 4;
863 x_orig[line] = v_pos.
x - ((halfwidth[line] * (hw+wm)) + (fullwidth[line] * (fw + wm)))/2.0f;
875 else if (str[i] >= 0xA1 && str[i] <= 0xDF)
879 else if (str[i] >= 0x81 && str[i] <= 0x9F)
883 else if (str[i] >= 0xE0 && str[i] <= 0xEF)
890 x_orig[line] = v_pos.
x - ((halfwidth[line] * (hw+wm)) + (fullwidth[line] * (fw + wm)))/2.0f;
906 for (j = 0; j < length; j++)
911 while(str[j] ==
'\n' || str[j] ==
'\t')
917 v_pos.
x = x_orig[line];
921 v_pos.
x += hw * 5.0f;
931 else if (str[j] >= 0xA1 && str[j] <= 0xDF)
936 else if (str[j] >= 0x81 && str[j] <= 0x9F)
943 else if (str[j] >= 0xE0 && str[j] <= 0xEF)
qword_t * draw_prim_start(qword_t *q, int context, prim_t *prim, color_t *color)
qword_t * draw_prim_end(qword_t *q, int nreg, u64 reglist)
void fontx_unload(fontx_t *fontx)
int fontx_load(const char *path, fontx_t *fontx, int type, int wmargin, int hmargin, int bold)
int fontx_load_single_krom(fontx_t *fontx)
unsigned short sjis_table[]
qword_t * fontx_print_ascii(qword_t *q, int context, const unsigned char *str, int alignment, vertex_t *v0, color_t *c0, fontx_t *fontx)
char * fontx_get_char(fontx_t *fontx, unsigned short c)
u64 * draw_fontx_row(u64 *dw, unsigned char byte, int x, int y, int z, int bold)
qword_t * draw_fontx_char(qword_t *q, unsigned short c, vertex_t *v0, fontx_t *fontx)
qword_t * fontx_print_sjis(qword_t *q, int context, const unsigned char *str, int alignment, vertex_t *v0, color_t *c0, fontx_t *ascii, fontx_t *kanji)
int fontx_load_double_krom(fontx_t *fontx)
#define GS_SET_XYZ(X, Y, Z)
struct fontx_hdr::@15 block[]