static bool nsfont_width(const plot_font_style_t *fstyle, const char *string, size_t length, int *width) { *width = (fstyle->size * utf8_bounded_length(string, length)) / FONT_SIZE_SCALE; return true; }
static bool nsfont_width(const plot_font_style_t *fstyle, const char *string, size_t length, int *width) { const struct fb_font_desc* fb_font = fb_get_font(fstyle); *width = fb_font->width * utf8_bounded_length(string, length); return true; }
static bool nsfont_width(const plot_font_style_t *style, const char *string, size_t length, int *width) { HDC hdc = GetDC(NULL); HFONT font = get_font(style); HFONT fontbak = SelectObject(hdc, font); SIZE s; if (length < 8192) { /* win 95/98/ME */ /* may well need to convert utf-8 to lpctstr */ GetTextExtentPoint32(hdc, string, utf8_bounded_length(string, length), &s); *width = s.cx; font = SelectObject(hdc, fontbak); DeleteObject(font); ReleaseDC(NULL, hdc); return true; } font = SelectObject(hdc, fontbak); DeleteObject(font); ReleaseDC(NULL, hdc); return false; }
/** * Calculate the length (in characters) of a NULL-terminated UTF-8 string * * \param s The string * \return Length of string */ size_t utf8_length(const char *s) { return utf8_bounded_length(s, strlen(s)); }
bool nsfont_split(const plot_font_style_t *fstyle, const char *string, size_t length, int x, size_t *char_offset, int *actual_x) { struct TextExtent extent; ULONG co; char *ostr = (char *)string; struct TextFont *tfont; uint16 *utf16 = NULL,*outf16 = NULL; uint16 utf16next = 0; FIXED kern = 0; int utf16charlen = 0; struct OutlineFont *ofont, *ufont = NULL; struct GlyphMap *glyph; uint32 tx=0,i=0; size_t len; int utf8len, utf8clen = 0; int32 tempx = 0; ULONG emwidth = (ULONG)NSA_FONT_EMWIDTH(fstyle->size); len = utf8_bounded_length(string, length); if(utf8_to_enc((char *)string,"UTF-16",length,(char **)&utf16) != UTF8_CONVERT_OK) return false; outf16 = utf16; if(!(ofont = ami_open_outline_font(fstyle, FALSE))) return false; *char_offset = 0; *actual_x = 0; for(i=0;i<len;i++) { utf8len = utf8_char_byte_length(string+utf8clen); if (*utf16 < 0xD800 || 0xDFFF < *utf16) utf16charlen = 1; else utf16charlen = 2; utf16next = utf16[utf16charlen]; if(x < tx) { i = length+1; } else { if(string[utf8clen] == ' ') //*utf16 == 0x0020) { *actual_x = tx; *char_offset = utf8clen; } } tempx = ami_font_plot_glyph(ofont, NULL, *utf16, utf16next, 0, 0, emwidth); if(tempx == 0) { if(ufont == NULL) { ufont = ami_open_outline_font(fstyle, TRUE); } if(ufont) { tempx = ami_font_plot_glyph(ufont, NULL, *utf16, utf16next, 0, 0, emwidth); } /* if(tempx == 0) { tempx = ami_font_plot_glyph(ofont, NULL, 0xfffd, utf16next, 0, 0, emwidth); } */ } tx += tempx; utf16 += utf16charlen; utf8clen += utf8len; } free(outf16); return true; }
bool nsfont_position_in_string(const plot_font_style_t *fstyle, const char *string, size_t length, int x, size_t *char_offset, int *actual_x) { struct TextExtent extent; struct TextFont *tfont; uint16 *utf16 = NULL, *outf16 = NULL; uint16 utf16next = 0; FIXED kern = 0; struct OutlineFont *ofont, *ufont = NULL; struct GlyphMap *glyph; uint32 tx=0,i=0; size_t len, utf8len = 0; uint8 *utf8; uint32 co = 0; int utf16charlen; ULONG emwidth = (ULONG)NSA_FONT_EMWIDTH(fstyle->size); int32 tempx; len = utf8_bounded_length(string, length); if(utf8_to_enc(string,"UTF-16",length,(char **)&utf16) != UTF8_CONVERT_OK) return false; outf16 = utf16; if(!(ofont = ami_open_outline_font(fstyle, FALSE))) return false; *char_offset = length; for(i=0;i<len;i++) { if (*utf16 < 0xD800 || 0xDFFF < *utf16) utf16charlen = 1; else utf16charlen = 2; utf8len = utf8_char_byte_length(string); utf16next = utf16[utf16charlen]; tempx = ami_font_plot_glyph(ofont, NULL, *utf16, utf16next, 0, 0, emwidth); if(tempx == 0) { if(ufont == NULL) { ufont = ami_open_outline_font(fstyle, TRUE); } if(ufont) { tempx = ami_font_plot_glyph(ufont, NULL, *utf16, utf16next, 0, 0, emwidth); } /* if(tempx == 0) { tempx = ami_font_plot_glyph(ofont, NULL, 0xfffd, utf16next, 0, 0, emwidth); } */ } if(x < (tx + tempx)) { *actual_x = tx; i = len+1; } else { co += utf8len; } tx += tempx; string += utf8len; utf16 += utf16charlen; } if(co >= (length)) { *actual_x = tx; co = length; } *char_offset = co; free(outf16); return true; }