From f123ed101f6651b15175a9cf33038bf54975dd8b Mon Sep 17 00:00:00 2001 From: Chris Young Date: Tue, 3 Feb 2015 19:48:28 +0000 Subject: Lazy bitmap font rendered text for slow hardware (non-working) --- amiga/font.c | 72 ++++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 51 insertions(+), 21 deletions(-) (limited to 'amiga/font.c') diff --git a/amiga/font.c b/amiga/font.c index 435e75992..80e34bd10 100644 --- a/amiga/font.c +++ b/amiga/font.c @@ -160,26 +160,8 @@ 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 bool nsfont_width(const plot_font_style_t *fstyle, - const char *string, size_t length, - int *width); - -static 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); - -static bool nsfont_split(const plot_font_style_t *fstyle, - const char *string, size_t length, - int x, size_t *char_offset, int *actual_x); -const struct font_functions nsfont = { - nsfont_width, - nsfont_position_in_string, - nsfont_split -}; - - -bool nsfont_width(const plot_font_style_t *fstyle, +static bool amiga_nsfont_width(const plot_font_style_t *fstyle, const char *string, size_t length, int *width) { @@ -202,7 +184,7 @@ bool nsfont_width(const plot_font_style_t *fstyle, * \return true on success, false on error and error reported */ -bool nsfont_position_in_string(const plot_font_style_t *fstyle, +static bool amiga_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) { @@ -289,7 +271,7 @@ bool nsfont_position_in_string(const plot_font_style_t *fstyle, * Returning char_offset == length means no split possible */ -bool nsfont_split(const plot_font_style_t *fstyle, +static bool amiga_nsfont_split(const plot_font_style_t *fstyle, const char *string, size_t length, int x, size_t *char_offset, int *actual_x) { @@ -752,6 +734,10 @@ ULONG ami_unicode_text(struct RastPort *rp, const char *string, ULONG length, if(!string || string[0]=='\0') return 0; if(!length) return 0; + if(nsoption_bool(use_diskfont) == true) { + return ami_font_bm_text(rp, string, length, fstyle, dx, dy); + } + 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; @@ -949,3 +935,47 @@ void ami_font_close_disk_font(struct TextFont *tfont) { CloseFont(tfont); } + + +/* Stub entry points */ +static bool nsfont_width(const plot_font_style_t *fstyle, + const char *string, size_t length, + int *width) +{ + if(nsoption_bool(use_diskfont) == false) { + return amiga_nsfont_width(fstyle, string, length, width); + } else { + return amiga_bm_nsfont_width(fstyle, string, length, width); + } +} + +static 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) +{ + if(nsoption_bool(use_diskfont) == false) { + return amiga_nsfont_position_in_string(fstyle, string, length, x, + char_offset, actual_x); + } else { + return amiga_bm_nsfont_position_in_string(fstyle, string, length, x, + char_offset, actual_x); + } +} + +static bool nsfont_split(const plot_font_style_t *fstyle, + const char *string, size_t length, + int x, size_t *char_offset, int *actual_x) +{ + if(nsoption_bool(use_diskfont) == false) { + return amiga_nsfont_split(fstyle, string, length, x, char_offset, actual_x); + } else { + return amiga_bm_nsfont_split(fstyle, string, length, x, char_offset, actual_x); + } +} + +const struct font_functions nsfont = { + nsfont_width, + nsfont_position_in_string, + nsfont_split +}; + -- cgit v1.2.3 From 5d43025adfa9eb6317515fcce80ee410f30558ee Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sun, 22 Feb 2015 16:50:41 +0000 Subject: Mostly working bitmap font support --- amiga/font.c | 5 +++++ amiga/font_bitmap.c | 20 ++++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) (limited to 'amiga/font.c') diff --git a/amiga/font.c b/amiga/font.c index 80e34bd10..5e4c9fc63 100644 --- a/amiga/font.c +++ b/amiga/font.c @@ -891,6 +891,11 @@ void ami_font_setdevicedpi(int id) ULONG ydpi = nsoption_int(screen_ydpi); ULONG xdpi = nsoption_int(screen_ydpi); + if(nsoption_bool(use_diskfont) == true) { + LOG(("WARNING: Using diskfont.library for text. Forcing DPI to 72.")); + nsoption_int(screen_ydpi) = 72; + } + browser_set_dpi(nsoption_int(screen_ydpi)); if(id && (nsoption_int(monitor_aspect_x) != 0) && (nsoption_int(monitor_aspect_y) != 0)) diff --git a/amiga/font_bitmap.c b/amiga/font_bitmap.c index d620ea90c..2bf411209 100644 --- a/amiga/font_bitmap.c +++ b/amiga/font_bitmap.c @@ -44,7 +44,7 @@ static struct TextFont *ami_font_bm_open(struct RastPort *rp, const plot_font_st { struct TextFont *bmfont = NULL; struct TextAttr tattr; - char *fontname, font; + char *fontname, *font; if(rp == NULL) return NULL; @@ -84,7 +84,7 @@ static struct TextFont *ami_font_bm_open(struct RastPort *rp, const plot_font_st if(font = ASPrintf("%s.font", fontname)) { tattr.ta_Name = font; tattr.ta_YSize = fstyle->size / FONT_SIZE_SCALE; - +LOG(("font: %s/%d", tattr.ta_Name, tattr.ta_YSize)); if(bmfont = OpenDiskFont(&tattr)) { SetRPAttrs(rp, RPTAG_Font, bmfont, TAG_DONE); } @@ -103,7 +103,14 @@ bool amiga_bm_nsfont_width(const plot_font_style_t *fstyle, const char *string, size_t length, int *width) { + *width = length; + + if((glob == NULL) || (glob->rp == NULL)) return false; + struct TextFont *bmfont = ami_font_bm_open(glob->rp, fstyle); + + if(bmfont == NULL) return false; + // convert to local charset *width = TextLength(glob->rp, string, length); ami_font_bm_close(bmfont); @@ -130,8 +137,12 @@ bool amiga_bm_nsfont_position_in_string(const plot_font_style_t *fstyle, struct TextExtent extent; struct TextFont *bmfont; + if((glob == NULL) || (glob->rp == NULL)) return false; + bmfont = ami_font_bm_open(glob->rp, fstyle); + if(bmfont == NULL) return false; + // convert to local charset *char_offset = TextFit(glob->rp, string, length, &extent, NULL, 1, x, 32767); @@ -174,8 +185,13 @@ bool amiga_bm_nsfont_split(const plot_font_style_t *fstyle, struct TextExtent extent; ULONG co; char *charp; + + if((glob == NULL) || (glob->rp == NULL)) return false; + struct TextFont *bmfont = ami_font_bm_open(glob->rp, fstyle); + if(bmfont == NULL) return false; + co = TextFit(glob->rp, string, length, &extent, NULL, 1, x, 32767); -- cgit v1.2.3 From 6fda772b892c18f100c066bd9207156716b43f32 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Mon, 23 Feb 2015 18:44:47 +0000 Subject: Avoid clobbering the PPC pipeline --- amiga/font.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'amiga/font.c') diff --git a/amiga/font.c b/amiga/font.c index 5e4c9fc63..254f0567e 100644 --- a/amiga/font.c +++ b/amiga/font.c @@ -152,16 +152,16 @@ lwc_string *glypharray[0xffff + 1]; ULONG ami_devicedpi; ULONG ami_xdpi; -int32 ami_font_plot_glyph(struct OutlineFont *ofont, struct RastPort *rp, +static int32 ami_font_plot_glyph(struct OutlineFont *ofont, struct RastPort *rp, uint16 *char1, uint16 *char2, uint32 x, uint32 y, uint32 emwidth, bool aa); -int32 ami_font_width_glyph(struct OutlineFont *ofont, +static int32 ami_font_width_glyph(struct OutlineFont *ofont, const uint16 *char1, const uint16 *char2, uint32 emwidth); -struct OutlineFont *ami_open_outline_font(const plot_font_style_t *fstyle, +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 bool amiga_nsfont_width(const plot_font_style_t *fstyle, +static inline bool amiga_nsfont_width(const plot_font_style_t *fstyle, const char *string, size_t length, int *width) { @@ -184,7 +184,7 @@ static bool amiga_nsfont_width(const plot_font_style_t *fstyle, * \return true on success, false on error and error reported */ -static bool amiga_nsfont_position_in_string(const plot_font_style_t *fstyle, +static inline bool amiga_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) { @@ -271,7 +271,7 @@ static bool amiga_nsfont_position_in_string(const plot_font_style_t *fstyle, * Returning char_offset == length means no split possible */ -static bool amiga_nsfont_split(const plot_font_style_t *fstyle, +static inline bool amiga_nsfont_split(const plot_font_style_t *fstyle, const char *string, size_t length, int x, size_t *char_offset, int *actual_x) { @@ -410,7 +410,7 @@ static struct ami_font_node *ami_font_open(const char *font) * \param codepoint open a default font instead of the one specified by fstyle * \return outline font or NULL on error */ -struct OutlineFont *ami_open_outline_font(const plot_font_style_t *fstyle, +static struct OutlineFont *ami_open_outline_font(const plot_font_style_t *fstyle, const uint16 *codepoint) { struct ami_font_node *node; @@ -549,7 +549,7 @@ struct OutlineFont *ami_open_outline_font(const plot_font_style_t *fstyle, return NULL; } -int32 ami_font_plot_glyph(struct OutlineFont *ofont, struct RastPort *rp, +static int32 ami_font_plot_glyph(struct OutlineFont *ofont, struct RastPort *rp, uint16 *char1, uint16 *char2, uint32 x, uint32 y, uint32 emwidth, bool aa) { struct GlyphMap *glyph; @@ -640,7 +640,7 @@ int32 ami_font_plot_glyph(struct OutlineFont *ofont, struct RastPort *rp, return char_advance; } -int32 ami_font_width_glyph(struct OutlineFont *ofont, +static int32 ami_font_width_glyph(struct OutlineFont *ofont, const uint16 *char1, const uint16 *char2, uint32 emwidth) { int32 char_advance = 0; @@ -947,7 +947,7 @@ static bool nsfont_width(const plot_font_style_t *fstyle, const char *string, size_t length, int *width) { - if(nsoption_bool(use_diskfont) == false) { + if(__builtin_expect(nsoption_bool(use_diskfont) == false, 1)) { return amiga_nsfont_width(fstyle, string, length, width); } else { return amiga_bm_nsfont_width(fstyle, string, length, width); @@ -958,7 +958,7 @@ static 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) { - if(nsoption_bool(use_diskfont) == false) { + if(__builtin_expect(nsoption_bool(use_diskfont) == false, 1)) { return amiga_nsfont_position_in_string(fstyle, string, length, x, char_offset, actual_x); } else { @@ -971,7 +971,7 @@ static bool nsfont_split(const plot_font_style_t *fstyle, const char *string, size_t length, int x, size_t *char_offset, int *actual_x) { - if(nsoption_bool(use_diskfont) == false) { + if(__builtin_expect(nsoption_bool(use_diskfont) == false, 1)) { return amiga_nsfont_split(fstyle, string, length, x, char_offset, actual_x); } else { return amiga_bm_nsfont_split(fstyle, string, length, x, char_offset, actual_x); -- cgit v1.2.3 From 85df94f47a32ecea89e6905fb43af69a0a392fc6 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Mon, 23 Feb 2015 18:47:58 +0000 Subject: more microoptimisation --- amiga/font.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'amiga/font.c') diff --git a/amiga/font.c b/amiga/font.c index 254f0567e..f930f77d6 100644 --- a/amiga/font.c +++ b/amiga/font.c @@ -734,7 +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(nsoption_bool(use_diskfont) == true) { + if(__builtin_expect(nsoption_bool(use_diskfont) == true, 0)) { return ami_font_bm_text(rp, string, length, fstyle, dx, dy); } -- cgit v1.2.3 From df25135a4d2007510b03487b517dad13b23f1a98 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sat, 28 Feb 2015 12:41:50 +0000 Subject: micro-optimisation --- amiga/font.c | 14 +++++++------- amiga/font_bitmap.c | 7 ++++--- 2 files changed, 11 insertions(+), 10 deletions(-) (limited to 'amiga/font.c') diff --git a/amiga/font.c b/amiga/font.c index f930f77d6..1f3269e5c 100644 --- a/amiga/font.c +++ b/amiga/font.c @@ -549,7 +549,7 @@ static struct OutlineFont *ami_open_outline_font(const plot_font_style_t *fstyle return NULL; } -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) { struct GlyphMap *glyph; @@ -562,12 +562,12 @@ static int32 ami_font_plot_glyph(struct OutlineFont *ofont, struct RastPort *rp, struct BulletBase *BulletBase = ofont->BulletBase; #endif - if ((*char1 >= 0xD800) && (*char1 <= 0xDBFF)) { + if (__builtin_expect(((*char1 >= 0xD800) && (*char1 <= 0xDBFF)), 0)) { /* We don't support UTF-16 surrogates yet, so just return. */ return 0; } - if ((*char2 >= 0xD800) && (*char2 <= 0xDBFF)) { + if (__builtin_expect(((*char2 >= 0xD800) && (*char2 <= 0xDBFF)), 0)) { /* Don't attempt to kern a UTF-16 surrogate */ *char2 = 0; } @@ -640,7 +640,7 @@ static int32 ami_font_plot_glyph(struct OutlineFont *ofont, struct RastPort *rp, return char_advance; } -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) { int32 char_advance = 0; @@ -653,12 +653,12 @@ static int32 ami_font_width_glyph(struct OutlineFont *ofont, struct BulletBase *BulletBase = ofont->BulletBase; #endif - if ((*char1 >= 0xD800) && (*char1 <= 0xDBFF)) { + if (__builtin_expect(((*char1 >= 0xD800) && (*char1 <= 0xDBFF)), 0)) { /* We don't support UTF-16 surrogates yet, so just return. */ return 0; } - - if ((*char2 >= 0xD800) && (*char2 <= 0xDBFF)) { + + if (__builtin_expect(((*char2 >= 0xD800) && (*char2 <= 0xDBFF)), 0)) { /* Don't attempt to kern a UTF-16 surrogate */ skip_c2 = true; } diff --git a/amiga/font_bitmap.c b/amiga/font_bitmap.c index 0b5b7ce85..8f142ae6b 100644 --- a/amiga/font_bitmap.c +++ b/amiga/font_bitmap.c @@ -202,11 +202,12 @@ bool amiga_bm_nsfont_split(const plot_font_style_t *fstyle, co--; } - *char_offset = co; - if(string && co) { + if(co > 0) { *actual_x = TextLength(glob->rp, string, co); + *char_offset = co; } else { - *actual_x = 0; + *actual_x = x; + *char_offset = length; } ami_font_bm_close(bmfont); -- cgit v1.2.3 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(-) (limited to 'amiga/font.c') 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