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 i,j; fontx_hdr *ascii_header = (fontx_hdr*)ascii->font; fontx_hdr *kanji_header = (fontx_hdr*)kanji->font; vertex_t v_pos = *v0; int length = strlen(str); int line = 0; short halfwidth[100]; short fullwidth[100]; float x_orig[100]; unsigned short wide; float hw = ascii_header->width; float fw = kanji_header->width; float h = kanji_header->height; float wm = kanji->w_margin; float hm = kanji->h_margin; // line_num is used to keep track of number of characters per line halfwidth[0] = 0; fullwidth[0] = 0; switch (alignment) { default: case LEFT_ALIGN: { for (i = 0; i < length; i++) { while (str[i] == '\t'|| str[i] == '\n') { if (str[i] == '\t') { halfwidth[line] += 4; } if (str[i] == '\n') { x_orig[line] = v_pos.x; line++; halfwidth[line] = 0; fullwidth[line] = 0; } i++; } if (i == length-1) { x_orig[line] = v_pos.x; line++; } } break; } case RIGHT_ALIGN: { for (i = 0; i < length; i++) { while (str[i] == '\t'|| str[i] == '\n') { if (str[i] == '\t') { halfwidth[line] += 4; } if (str[i] == '\n') { x_orig[line] = v_pos.x - ((halfwidth[line] * (hw+wm)) + (fullwidth[line] * (fw + wm)));; line++; halfwidth[line] = 0; fullwidth[line] = 0; } i++; } if (str[i] < 0x80) { halfwidth[line]++; } else if (str[i] >= 0xA1 && str[i] <= 0xDF) { halfwidth[line]++; } else if (str[i] >= 0x81 && str[i] <= 0x9F) { fullwidth[line]++; } else if (str[i] >= 0xE0 && str[i] <= 0xEF) { fullwidth[line]++; } if (i == length-1) { x_orig[line] = v_pos.x - ((halfwidth[line] * (hw+wm)) + (fullwidth[line] * (fw + wm))); line++; } } break; } case CENTER_ALIGN: { for (i = 0; i < length; i++) { while (str[i] == '\t'|| str[i] == '\n') { if (str[i] == '\t') { halfwidth[line] += 4; } if (str[i] == '\n') { x_orig[line] = v_pos.x - ((halfwidth[line] * (hw+wm)) + (fullwidth[line] * (fw + wm)))/2.0f; line++; halfwidth[line] = 0; fullwidth[line] = 0; } i++; } if (str[i] < 0x80) { halfwidth[line]++; } else if (str[i] >= 0xA1 && str[i] <= 0xDF) { halfwidth[line]++; } else if (str[i] >= 0x81 && str[i] <= 0x9F) { fullwidth[line]++; } else if (str[i] >= 0xE0 && str[i] <= 0xEF) { fullwidth[line]++; } if (i == length-1) { x_orig[line] = v_pos.x - ((halfwidth[line] * (hw+wm)) + (fullwidth[line] * (fw + wm)))/2.0f; line++; } } break; } }; line = 0; v_pos.x = x_orig[0]; q = draw_prim_start(q,context,&charprim,c0); for (j = 0; j < length; j++) { wide = 0; while(str[j] == '\n' || str[j] == '\t') { if (str[j] == '\n') { line++; v_pos.y += h + hm; v_pos.x = x_orig[line]; } if (str[j] == '\t') { v_pos.x += hw * 5.0f; } j++; } if (str[j] < 0x80) { q = draw_fontx_char(q,str[j],&v_pos,ascii); v_pos.x += hw + wm; } else if (str[j] >= 0xA1 && str[j] <= 0xDF) { q = draw_fontx_char(q,str[j],&v_pos,ascii); v_pos.x += hw + wm; } else if (str[j] >= 0x81 && str[j] <= 0x9F) { wide = str[j++]<<8; wide += str[j]; q = draw_fontx_char(q,wide,&v_pos,kanji); v_pos.x += fw + wm; } else if (str[j] >= 0xE0 && str[j] <= 0xEF) { wide = str[j++]<<8; wide += str[j]; q = draw_fontx_char(q,wide,&v_pos,kanji); v_pos.x += fw + wm; } else { v_pos.x += fw + wm; } } q = draw_prim_end(q,2,DRAW_XYZ_REGLIST); return q; }
qword_t *fontstudio_print_string(qword_t *q, int context, const unsigned char *str, int alignment, vertex_t *v0, color_t *c0, fsfont_t *font) { int i = 0,j; unsigned short curchar = 0; int length; vertex_t v_pos = *v0; unsigned short utf8[2048]; memset(utf8,0,sizeof(short)*2048); // Decodes the encoded string into unicode numbers U+xxxx // length is the number of characters in the string length = decode_unicode(str, utf8); //for (i = 0; i < length; i++) //{ // printf("utf8[%d] = %d\n", i, utf8[i]); //} // Converts the unicode numbers into the index numbers // used by the FontStudio ini convert_to_index(utf8,length,font); //for (i = 0; i < length; i++) //{ // printf("utf8[%d] = %d\n", i, utf8[i]); //} float line_num[100]; int line = 0; float x_orig[100]; x_orig[0] = 0; // line_num is used to keep track of number of characters per line line_num[0] = 0; switch (alignment) { default: case LEFT_ALIGN: { for (i = 0; i < length; i++) { while (utf8[i] == TAB || utf8[i] == NEWLINE) { if (utf8[i] == NEWLINE) { x_orig[line] = v_pos.x; line++; line_num[line] = 0; } i++; } if (i == length-1) { x_orig[line] = v_pos.x; line++; } } break; } case RIGHT_ALIGN: { for (i = 0; i < length; i++) { while (utf8[i] == TAB || utf8[i] == NEWLINE || utf8[i] == SPACE) { if (utf8[i] == NEWLINE) { x_orig[line] = v_pos.x - line_num[line]*font->scale; line++; line_num[line] = 0; } if (utf8[i] == TAB) { line_num[line] += font->spacewidth * 4; } if (utf8[i] == SPACE) { line_num[line] += font->spacewidth; } i++; } curchar = utf8[i]; line_num[line] += font->chardata[curchar].A + font->chardata[curchar].B + font->chardata[curchar].C; if (i == length-1) { x_orig[line] = v_pos.x - line_num[line]*font->scale; line++; } } break; } case CENTER_ALIGN: { for (i = 0; i < length; i++) { while (utf8[i] == TAB || utf8[i] == NEWLINE || utf8[i] == SPACE) { if (utf8[i] == NEWLINE) { x_orig[line] = v_pos.x - (line_num[line]*font->scale)/2.0f; line++; line_num[line] = 0; } if (utf8[i] == TAB) { line_num[line] += font->spacewidth * 4; } if (utf8[i] == SPACE) { line_num[line] += font->spacewidth; } i++; } curchar = utf8[i]; line_num[line] += font->chardata[curchar].A + font->chardata[curchar].B + font->chardata[curchar].C; if (i == length-1) { x_orig[line] = v_pos.x - (line_num[line]*font->scale)/2.0f; line++; } } break; } }; line = 0; v_pos.x = x_orig[0]; q = draw_prim_start(q,context,&charprim,c0); for (j = 0; j < length; j++) { while(utf8[j] == NEWLINE || utf8[j] == TAB || utf8[j] == SPACE) { if (utf8[j] == NEWLINE) { line++; v_pos.y += font->height*font->scale; v_pos.x = x_orig[line]; } if (utf8[j] == TAB) { v_pos.x += font->spacewidth*font->scale * 4.0f; } if (utf8[j] == SPACE) { v_pos.x += font->spacewidth*font->scale; } j++; } v_pos.x += (font->chardata[utf8[j]].A*font->scale); q = draw_fontstudio_char(q,utf8[j],&v_pos,font); v_pos.x += (font->chardata[utf8[j]].B*font->scale) + (font->chardata[utf8[j]].C*font->scale); } q = draw_prim_end(q,2,DRAW_UV_REGLIST); return q; }
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) { int i,j; fontx_hdr *fontx_header = (fontx_hdr*)fontx->font; vertex_t v_pos = *v0; int length = strlen(str); short line_num[100]; int line = 0; float x_orig[100]; float w = fontx_header->width; float h = fontx_header->height; float wm = fontx->w_margin; float hm = fontx->h_margin; // line_num is used to keep track of number of characters per line line_num[0] = 0; switch (alignment) { default: case LEFT_ALIGN: { for (i = 0; i < length; i++) { while (str[i] == '\t' || str[i] == '\n') { if(str[i] == '\n') { x_orig[line] = v_pos.x; line++; line_num[line] = 0; } i++; } if (i == length-1) { x_orig[line] = v_pos.x; line++; } } break; } case RIGHT_ALIGN: { for (i = 0; i < length; i++) { while (str[i] == '\t' || str[i] == '\n') { if (str[i] == '\t') { line_num[line] += 4; } if (str[i] == '\n') { x_orig[line] = v_pos.x - (line_num[line] * (w + wm)); line++; line_num[line] = 0; } i++; } line_num[line]++; if (i == length-1) { x_orig[line] = v_pos.x - (line_num[line] * (w + wm)); line++; } } break; } case CENTER_ALIGN: { for (i = 0; i < length; i++) { while (str[i] == '\t' || str[i] == '\n') { if (str[i] == '\t') { line_num[line] += 4; } if (str[i] == '\n') { x_orig[line] = v_pos.x - (line_num[line] * (w + wm))/2.0f; line++; line_num[line] = 0; } i++; } line_num[line]++; if (i == length-1) { x_orig[line] = v_pos.x - (line_num[line] * (w + wm))/2.0f; line++; } } break; } }; line = 0; v_pos.x = x_orig[0]; q = draw_prim_start(q,context,&charprim,c0); for (j = 0; j < length; j++) { while(str[j] == '\n' || str[j] == '\t') { if (str[j] == '\n') { line++; v_pos.y += h + hm; v_pos.x = x_orig[line]; } if (str[j] == '\t') { v_pos.x += w * 5.0f; } j++; } if (str[j] < 0x80) { q = draw_fontx_char(q,str[j],&v_pos,fontx); } else if (str[j] >= 0xA1 && str[j] <= 0xDF) { q = draw_fontx_char(q,str[j],&v_pos,fontx); } v_pos.x += w + wm; } q = draw_prim_end(q,2,DRAW_XYZ_REGLIST); return q; }