From 947c466c4ba63ad84c0121453975a34935d0c1e8 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sat, 28 Feb 2015 13:01:16 +0000 Subject: Split plotting and widthing functions up --- amiga/font.c | 103 ++++++++++++++++++++++++++++++++++++++----------------- amiga/font.h | 2 +- amiga/plotters.c | 2 +- 3 files changed, 74 insertions(+), 33 deletions(-) diff --git a/amiga/font.c b/amiga/font.c index 1f3269e5c..32f12f272 100644 --- a/amiga/font.c +++ b/amiga/font.c @@ -152,20 +152,21 @@ lwc_string *glypharray[0xffff + 1]; ULONG ami_devicedpi; ULONG ami_xdpi; -static int32 ami_font_plot_glyph(struct OutlineFont *ofont, struct RastPort *rp, +static inline int32 ami_font_plot_glyph(struct OutlineFont *ofont, struct RastPort *rp, uint16 *char1, uint16 *char2, uint32 x, uint32 y, uint32 emwidth, bool aa); -static int32 ami_font_width_glyph(struct OutlineFont *ofont, +static inline int32 ami_font_width_glyph(struct OutlineFont *ofont, const uint16 *char1, const uint16 *char2, uint32 emwidth); static struct OutlineFont *ami_open_outline_font(const plot_font_style_t *fstyle, const uint16 *codepoint); static void ami_font_cleanup(struct MinList *ami_font_list); - +static inline ULONG ami_font_unicode_width(const char *string, ULONG length, + const plot_font_style_t *fstyle, ULONG x, ULONG y, bool aa); static inline bool amiga_nsfont_width(const plot_font_style_t *fstyle, const char *string, size_t length, int *width) { - *width = ami_unicode_text(NULL, string, length, fstyle, 0, 0, false); + *width = ami_font_unicode_width(string, length, fstyle, 0, 0, false); if(*width <= 0) *width == length; // fudge @@ -719,7 +720,7 @@ static const uint16 *ami_font_translate_smallcaps(uint16 *utf16char) return utf16char; } -ULONG ami_unicode_text(struct RastPort *rp, const char *string, ULONG length, +ULONG ami_font_unicode_text(struct RastPort *rp, const char *string, ULONG length, const plot_font_style_t *fstyle, ULONG dx, ULONG dy, bool aa) { uint16 *utf16 = NULL, *outf16 = NULL; @@ -733,6 +734,7 @@ ULONG ami_unicode_text(struct RastPort *rp, const char *string, ULONG length, if(!string || string[0]=='\0') return 0; if(!length) return 0; + if(rp == NULL) return 0; if(__builtin_expect(nsoption_bool(use_diskfont) == true, 0)) { return ami_font_bm_text(rp, string, length, fstyle, dx, dy); @@ -756,22 +758,14 @@ ULONG ami_unicode_text(struct RastPort *rp, const char *string, ULONG length, utf16charsc = (uint16 *)ami_font_translate_smallcaps(utf16); utf16nextsc = (uint16 *)ami_font_translate_smallcaps(utf16next); - if(rp) { - tempx = ami_font_plot_glyph(ofont, rp, utf16charsc, utf16nextsc, + tempx = ami_font_plot_glyph(ofont, rp, utf16charsc, utf16nextsc, dx + x, dy, emwidth, aa); - } else { - tempx = ami_font_width_glyph(ofont, utf16charsc, utf16nextsc, emwidth); - } } else tempx = 0; if(tempx == 0) { - if(rp) { - tempx = ami_font_plot_glyph(ofont, rp, utf16, utf16next, + tempx = ami_font_plot_glyph(ofont, rp, utf16, utf16next, dx + x, dy, emwidth, aa); - } else { - tempx = ami_font_width_glyph(ofont, utf16, utf16next, emwidth); - } } if(tempx == 0) @@ -781,26 +775,73 @@ ULONG ami_unicode_text(struct RastPort *rp, const char *string, ULONG length, ufont = ami_open_outline_font(fstyle, utf16); } - if(ufont) + if(ufont) { + tempx = ami_font_plot_glyph(ufont, rp, utf16, utf16next, + dx + x, dy, emwidth, aa); + } + } + + x += tempx; + + utf16 += utf16charlen; + } + + free(outf16); + return x; +} + +static inline ULONG ami_font_unicode_width(const char *string, ULONG length, + const plot_font_style_t *fstyle, ULONG dx, ULONG dy, bool aa) +{ + uint16 *utf16 = NULL, *outf16 = NULL; + uint16 *utf16charsc = 0, *utf16nextsc = 0; + uint16 *utf16next = 0; + int utf16charlen; + struct OutlineFont *ofont, *ufont = NULL; + uint32 x=0; + int32 tempx = 0; + ULONG emwidth = (ULONG)NSA_FONT_EMWIDTH(fstyle->size); + + if(!string || string[0]=='\0') return 0; + if(!length) return 0; + + if(utf8_to_enc(string,"UTF-16",length,(char **)&utf16) != NSERROR_OK) return 0; + outf16 = utf16; + if(!(ofont = ami_open_outline_font(fstyle, 0))) return 0; + + while(*utf16 != 0) + { + if ((*utf16 < 0xD800) || (0xDBFF < *utf16)) + utf16charlen = 1; + else + utf16charlen = 2; + + utf16next = &utf16[utf16charlen]; + + if(fstyle->flags & FONTF_SMALLCAPS) + { + utf16charsc = (uint16 *)ami_font_translate_smallcaps(utf16); + utf16nextsc = (uint16 *)ami_font_translate_smallcaps(utf16next); + + tempx = ami_font_width_glyph(ofont, utf16charsc, utf16nextsc, emwidth); + } + else tempx = 0; + + if(tempx == 0) { + tempx = ami_font_width_glyph(ofont, utf16, utf16next, emwidth); + } + + if(tempx == 0) + { + if(ufont == NULL) { - if(rp) { - tempx = ami_font_plot_glyph(ufont, rp, utf16, utf16next, - dx + x, dy, emwidth, aa); - } else { - tempx = ami_font_width_glyph(ufont, utf16, utf16next, emwidth); - } + ufont = ami_open_outline_font(fstyle, utf16); } -/* - if(tempx == 0) + + if(ufont) { - if(rp) { - tempx = ami_font_plot_glyph(ofont, rp, 0xfffd, utf16next, - dx + x, dy, emwidth, aa); - } else { - tempx = ami_font_width_glyph(ofont, 0xfffd, utf16next, emwidth); - } + tempx = ami_font_width_glyph(ufont, utf16, utf16next, emwidth); } -*/ } x += tempx; diff --git a/amiga/font.h b/amiga/font.h index 6c600abe4..375e15032 100755 --- a/amiga/font.h +++ b/amiga/font.h @@ -25,7 +25,7 @@ struct ami_font_node; -ULONG ami_unicode_text(struct RastPort *rp, const char *string, +ULONG ami_font_unicode_text(struct RastPort *rp, const char *string, ULONG length, const plot_font_style_t *fstyle, ULONG x, ULONG y, bool aa); void ami_font_setdevicedpi(int id); void ami_init_fonts(void); diff --git a/amiga/plotters.c b/amiga/plotters.c index 443077b58..660dea74d 100644 --- a/amiga/plotters.c +++ b/amiga/plotters.c @@ -414,7 +414,7 @@ static bool ami_text(int x, int y, const char *text, size_t length, aa = false; ami_plot_setapen(glob->rp, fstyle->foreground); - ami_unicode_text(glob->rp, text, length, fstyle, x, y, aa); + ami_font_unicode_text(glob->rp, text, length, fstyle, x, y, aa); return true; } -- cgit v1.2.3