43 DRAW_DISABLE, DRAW_ENABLE, DRAW_DISABLE,
48unsigned short sjis_table[] = {
102int fontx_load_single_krom(
fontx_t *fontx)
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);
128 if (fontx->
font == NULL)
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;
180int fontx_load_double_krom(
fontx_t *fontx)
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);
208 if (fontx->
font == NULL)
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;
247 fontx_header->
type = DOUBLE_BYTE;
251 memcpy(fontx->
font+header_size,sjis_table,table_num*table_size);
269 if (!strcmp(
"rom0:KROM",path) || !strcmp(
"rom0:/KROM",path))
276 ret = fontx_load_single_krom(fontx);
282 ret = fontx_load_double_krom(fontx);
289 printf(
"Error opening %s\n", path);
300 FILE *file = fopen(path,
"r");
305 printf(
"Error opening %s\n", path);
311 fseek(file, 0, SEEK_END);
313 fseek(file, 0, SEEK_SET);
315 fontx->
font = (
char *)malloc(size);
317 if (fontx->
font == NULL)
320 printf(
"Error allocating %ld bytes of memory.\n", size);
326 fread(fontx->
font, size, 1, file);
334 if (strncmp(fontx_header->
id,
"FONTX2", 6) != 0)
337 printf(
"Not FONTX2 type font!\n");
344 if (fontx_header->
type != type)
347 printf(
"Type mismatch\n");
355 strcpy(fontx->
name,fontx_header->
name);
385 if (fontx->
font != NULL)
394char *fontx_get_char(
fontx_t* fontx,
unsigned short c)
400 int table_offset = 0;
404 if (fontx->
font == NULL)
407 printf(
"Font data not loaded.\n");
421 for (i = 0; i < fontx_header->
table_num; i++)
424 if ((fontx_header->block[i].start <= c) && (fontx_header->block[i].end >= c))
441 for (i = 0; i < (
unsigned int)table; i++)
444 table_offset += fontx_header->block[i].end - fontx_header->block[i].start;
448 table_offset = table_offset + table + ( c - fontx_header->block[table].start);
455u64 *draw_fontx_row(u64 *dw,
unsigned char byte,
int x,
int y,
int z,
int bold)
458 unsigned char mask = 0x80;
471 *dw++ = GS_SET_XYZ((x+(i<<4)) + 32768,y+32768,z);
479 *dw++ = GS_SET_XYZ((x+(i<<4)) + 32768,y+32768,z);
493 *dw++ = GS_SET_XYZ((x+(i<<4)) + 32768,y+32768,z);
501qword_t *draw_fontx_char(qword_t *q,
unsigned short c,
vertex_t *v0,
fontx_t *fontx)
518 char_offset = fontx_get_char(fontx,c);
527 for (i=0;i<fontx_header->
height;i++)
534 for (j=0;j < fontx->
rowsize;j++)
539 dw = draw_fontx_row(dw,char_offset[(i*fontx->
rowsize) + j],xi,yi,z,fontx->
bold);
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];
718 q = draw_fontx_char(q,str[j],&v_pos,fontx);
720 else if (str[j] >= 0xA1 && str[j] <= 0xDF)
722 q = draw_fontx_char(q,str[j],&v_pos,fontx);
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++)
910 while(str[j] ==
'\n' || str[j] ==
'\t')
916 v_pos.x = x_orig[line];
920 v_pos.x += hw * 5.0f;
927 q = draw_fontx_char(q,str[j],&v_pos,ascii);
930 else if (str[j] >= 0xA1 && str[j] <= 0xDF)
932 q = draw_fontx_char(q,str[j],&v_pos,ascii);
935 else if (str[j] >= 0x81 && str[j] <= 0x9F)
939 q = draw_fontx_char(q,wide,&v_pos,kanji);
942 else if (str[j] >= 0xE0 && str[j] <= 0xEF)
946 q = draw_fontx_char(q,wide,&v_pos,kanji);
qword_t * draw_prim_end(qword_t *q, int nreg, u64 reglist)
qword_t * draw_prim_start(qword_t *q, int context, prim_t *prim, color_t *color)
void fontx_unload(fontx_t *fontx)
int fontx_load(const char *path, fontx_t *fontx, int type, int wmargin, int hmargin, int bold)
qword_t * fontx_print_ascii(qword_t *q, int context, const unsigned char *str, int alignment, const vertex_t *v0, color_t *c0, fontx_t *fontx)
qword_t * fontx_print_sjis(qword_t *q, int context, const unsigned char *str, int alignment, const vertex_t *v0, color_t *c0, fontx_t *ascii, fontx_t *kanji)