From cc7441c4dda1ecc5f0852b89196f9da55573cdc5 Mon Sep 17 00:00:00 2001 From: Vincent Wei Date: Tue, 5 Mar 2019 09:16:36 +0800 Subject: [PATCH] add df_slot to get_font_size of DEVFONT operators in order to set scale correctly --- src/font/bitmapfont.c | 5 +- src/font/devfont.c | 87 +++++++++++++++++++++++------ src/font/freetype1.c | 7 ++- src/font/freetype2.c | 7 ++- src/font/logfont.c | 35 ++++++------ src/font/qpf.c | 5 +- src/font/rawbitmap.c | 5 +- src/font/type1.c | 5 +- src/font/upf.c | 5 +- src/font/varbitmap.c | 5 +- src/include/devfont.h | 20 ++----- src/newgdi/{ => obsolote}/logfont.c | 2 + 12 files changed, 126 insertions(+), 62 deletions(-) rename src/newgdi/{ => obsolote}/logfont.c (99%) diff --git a/src/font/bitmapfont.c b/src/font/bitmapfont.c index f602c1fd..a7b40168 100644 --- a/src/font/bitmapfont.c +++ b/src/font/bitmapfont.c @@ -210,8 +210,11 @@ static int get_font_height (LOGFONT* logfont, DEVFONT* devfont) return ((BMPFONTINFO *)devfont->data)->height; } -static int get_font_size (LOGFONT* logfont, DEVFONT* devfont, int expect) +static int get_font_size (LOGFONT* logfont, DEVFONT* devfont, int expect, int df_slot) { + if (df_slot >= 0 && df_slot < MAXNR_DEVFONTS) + SET_DEVFONT_SCALE (logfont, df_slot, 1); + return ((BMPFONTINFO *)devfont->data)->height; } diff --git a/src/font/devfont.c b/src/font/devfont.c index 9875f5b9..f429ab08 100644 --- a/src/font/devfont.c +++ b/src/font/devfont.c @@ -109,7 +109,7 @@ void font_ResetDevFont (void) #define MATCHED_SLANT 0x10 static DEVFONT* get_matched_devfont (LOGFONT* lf, const char* family, - DEVFONT* list_head, int list_len, char* req_charset) + DEVFONT* list_head, int list_len, char* req_charset, int slot) { int i = 0; BYTE* match_bits; @@ -123,7 +123,7 @@ static DEVFONT* get_matched_devfont (LOGFONT* lf, const char* family, match_bits = (BYTE *)FixStrAlloc (list_len); #endif - _DBG_PRINTF("%s, family(%s), req_charset(%s), list_head(%p), list_len(%d)\n", + _DBG_PRINTF("%s, family(%s), charset(%s), list_head(%p), list_len(%d)\n", __FUNCTION__, family, req_charset, list_head, list_len); i = 0; @@ -205,24 +205,24 @@ static DEVFONT* get_matched_devfont (LOGFONT* lf, const char* family, size_error = lf->size - (*dev_font->font_ops->get_font_size) (lf, dev_font, - lf->size); + lf->size, -1); size_error = ABS (size_error); if (match_bits [i] & MATCHED_WEIGHT) { weight_error = 0; } else { - weight_error = (lf->style & FS_WEIGHT_MASK) - - (dev_font->style & FS_WEIGHT_MASK); + weight_error = (int)(lf->style & FS_WEIGHT_MASK) - + (int)(dev_font->style & FS_WEIGHT_MASK); weight_error = ABS (weight_error); } - if (match_bits [i] & MATCHED_FAMILY) { + if (match_bits [i] & MATCHED_SLANT) { slant_error = 0; } else { - slant_error = (lf->style & FS_SLANT_MASK) - - (dev_font->style & FS_SLANT_MASK); + slant_error = (int)(lf->style & FS_SLANT_MASK) - + (int)(dev_font->style & FS_SLANT_MASK); slant_error = ABS (slant_error); } @@ -241,7 +241,59 @@ static DEVFONT* get_matched_devfont (LOGFONT* lf, const char* family, } if (matched_font) { - _DBG_PRINTF("%s, got a matched devfont (%s): %d\n", + _DBG_PRINTF("%s, got a matched devfont (%s) in the first run: %d\n", + __FUNCTION__, matched_font->name, min_error); + goto matched; + } + + min_error = (FONT_MAX_SIZE << 16) + 0xFFFF; + matched_font = NULL; + dev_font = list_head; + for (i = 0; i < list_len; i++) { + if ((match_bits [i] & MATCHED_TYPE) + && (match_bits [i] & MATCHED_CHARSET)) { + + int error, size_error, weight_error, slant_error; + + size_error = lf->size - + (*dev_font->font_ops->get_font_size) (lf, dev_font, + lf->size, -1); + size_error = ABS (size_error); + + if (match_bits [i] & MATCHED_WEIGHT) { + weight_error = 0; + } + else { + weight_error = (int)(lf->style & FS_WEIGHT_MASK) - + (int)(dev_font->style & FS_WEIGHT_MASK); + weight_error = ABS (weight_error); + } + + if (match_bits [i] & MATCHED_SLANT) { + slant_error = 0; + } + else { + slant_error = (int)(lf->style & FS_SLANT_MASK) - + (int)(dev_font->style & FS_SLANT_MASK); + slant_error = ABS (slant_error); + } + + error = (size_error << 16) + slant_error + weight_error; + _DBG_PRINTF("%s, error of devfont#%d(%s): %d\n", + __FUNCTION__, i, dev_font->name, error); + + if (min_error >= error) { + /* use >=, make the later has a higher priority */ + min_error = error; + matched_font = dev_font; + } + } + + dev_font = dev_font->next; + } + + if (matched_font) { + _DBG_PRINTF("%s, got a matched devfont (%s) in the second run: %d\n", __FUNCTION__, matched_font->name, min_error); goto matched; } @@ -252,9 +304,11 @@ static DEVFONT* get_matched_devfont (LOGFONT* lf, const char* family, int error; if (match_bits [i] & MATCHED_CHARSET) { error = lf->size - - (*dev_font->font_ops->get_font_size) (lf, dev_font, lf->size); + (*dev_font->font_ops->get_font_size) (lf, dev_font, + lf->size, -1); error = ABS (error); - if (min_error >= error) { /* use >=, make the later has a higher priority */ + if (min_error >= error) { + /* use >=, make the later has a higher priority */ min_error = error; matched_font = dev_font; } @@ -269,7 +323,8 @@ matched: #endif if (matched_font) - matched_font->font_ops->get_font_size (lf, matched_font, lf->size); + matched_font->font_ops->get_font_size (lf, matched_font, + lf->size, slot); return matched_font; } @@ -284,18 +339,18 @@ DEVFONT* font_GetMatchedSBDevFont (LOGFONT* lf, const char* family) fontGetCharsetFromName (g_SysLogFont[0]->devfonts[0]->name, sysfont_charset); matched_devfont = get_matched_devfont (lf, family, sb_dev_font_head, - nr_sb_dev_fonts, sysfont_charset); + nr_sb_dev_fonts, sysfont_charset, 0); } else { /*sbc logfont --- sbc devfont*/ matched_devfont = get_matched_devfont (lf, family, sb_dev_font_head, - nr_sb_dev_fonts, lf->charset); + nr_sb_dev_fonts, lf->charset, 0); } return matched_devfont; } -DEVFONT* font_GetMatchedMBDevFont (LOGFONT* lf, const char* family) +DEVFONT* font_GetMatchedMBDevFont (LOGFONT* lf, const char* family, int slot) { /*sbc logfont doesn't need mbc font*/ if (GetCharsetOps (lf->charset)->bytes_maxlen_char == 1) @@ -303,7 +358,7 @@ DEVFONT* font_GetMatchedMBDevFont (LOGFONT* lf, const char* family) /*mbc logfont --- mbc devfont*/ else return get_matched_devfont (lf, family, mb_dev_font_head, - nr_mb_dev_fonts, lf->charset); + nr_mb_dev_fonts, lf->charset, slot); } const DEVFONT* GUIAPI GetNextDevFont (const DEVFONT* dev_font) diff --git a/src/font/freetype1.c b/src/font/freetype1.c index de1b1e7a..aa462c68 100644 --- a/src/font/freetype1.c +++ b/src/font/freetype1.c @@ -263,10 +263,13 @@ static int get_font_height (LOGFONT* logfont, DEVFONT* devfont) return ttf_inst_info->height; } -static int get_font_size (LOGFONT* logfont, DEVFONT* devfont, int expect) +static int get_font_size (LOGFONT* logfont, DEVFONT* devfont, int expect, int df_slot) { unsigned short scale = 1; - SET_DEVFONT_SCALE (logfont, devfont, scale); + + if (df_slot >= 0 && df_slot < MAXNR_DEVFONTS) + SET_DEVFONT_SCALE (logfont, df_slot, scale); + return expect; } diff --git a/src/font/freetype2.c b/src/font/freetype2.c index 9c0fdd78..0bd38e0f 100644 --- a/src/font/freetype2.c +++ b/src/font/freetype2.c @@ -246,10 +246,13 @@ get_font_height (LOGFONT* logfont, DEVFONT* devfont) } static int -get_font_size (LOGFONT* logfont, DEVFONT* devfont, int expect) +get_font_size (LOGFONT* logfont, DEVFONT* devfont, int expect, int df_slot) { unsigned short scale = 1; - SET_DEVFONT_SCALE (logfont, devfont, scale); + + if (df_slot >= 0 && df_slot < MAXNR_DEVFONTS) + SET_DEVFONT_SCALE (logfont, df_slot, scale); + return expect; } diff --git a/src/font/logfont.c b/src/font/logfont.c index 78479d42..93baeae6 100644 --- a/src/font/logfont.c +++ b/src/font/logfont.c @@ -147,9 +147,10 @@ static PLOGFONT gdiCreateLogFont (const char* type, const char* family, newlf->rotation = rotation; - _DBG_PRINTF ("FONT>LogFont: requested info: type: %s, family: %s, style: %x, charset: %s, size: %d.\n", + _DBG_PRINTF ("%s: requested LOGFONT: %s-%s-%x-%d-%s.\n", + __FUNCTION__, newlf->type, newlf->family, - newlf->style, newlf->charset, newlf->size); + newlf->style, newlf->size, newlf->charset); iter = family; if ((n = get_family_name_len(iter)) <= 0 || n > LEN_LOGFONT_NAME_FIELD) @@ -158,11 +159,11 @@ static PLOGFONT gdiCreateLogFont (const char* type, const char* family, strncpy (name_field, iter, n); name_field[n] = '\0'; - _DBG_PRINTF ("FONT>LogFont: try to create SBC Devfont for family(%s)\n", - name_field); + _DBG_PRINTF ("%s: try to create SBC Devfont for family(%s)\n", + __FUNCTION__, name_field); newlf->scales[0] = 1; - if ((devfonts[0] = font_GetMatchedSBDevFont (newlf, name_field)) == NULL) + if ((devfonts[0] = font_GetMatchedSBDevFont(newlf, name_field)) == NULL) goto error; iter = family; @@ -174,31 +175,31 @@ static PLOGFONT gdiCreateLogFont (const char* type, const char* family, strncpy (name_field, iter, n); name_field[n] = '\0'; - _DBG_PRINTF ("FONT>LogFont: try to create MBC Devfont for family(%s)\n", - name_field); + _DBG_PRINTF("%s: try to create MBC Devfont for family(%s)\n", + __FUNCTION__, name_field); newlf->scales[i] = 1; - if ((df = font_GetMatchedMBDevFont (newlf, name_field))) { + if ((df = font_GetMatchedMBDevFont (newlf, name_field, i))) { int j; // check duplicated. for (j = 1; j <= i; j++) { if (df == devfonts[j]) { // duplicated - _DBG_PRINTF ("FONT>LogFont: ignore the duplicated devfont (%s)\n", - name_field); + _DBG_PRINTF("%s: ignore the duplicated devfont (%s)\n", + __FUNCTION__, name_field); break; } else if (devfonts[j] == NULL) { devfonts[j] = df; - _DBG_PRINTF ("FONT>LogFont: created new devfont for family(%s)\n", - name_field); + _DBG_PRINTF("%s: created new devfont for family(%s)\n", + __FUNCTION__, name_field); break; } } } else { - _DBG_PRINTF ("FONT>LogFont: failed to created new devfont for family(%s)\n", - name_field); + _DBG_PRINTF("%s: failed to created new devfont for family(%s)\n", + __FUNCTION__, name_field); } iter += n; @@ -231,8 +232,10 @@ static PLOGFONT gdiCreateLogFont (const char* type, const char* family, adjust_newlf_info(newlf); - _DBG_PRINTF ("FONT>LogFont: created info: type: %s, family: %s, style: %x, charset: %s, size: %d.\n", - newlf->type, newlf->family, newlf->style, newlf->charset, newlf->size); + _DBG_PRINTF ("%s: NEW LOGFONT: %s-%s-%x-%d-%s.\n", + __FUNCTION__, + newlf->type, newlf->family, newlf->style, + newlf->size, newlf->charset); return newlf; diff --git a/src/font/qpf.c b/src/font/qpf.c index 0f6ce611..4458dec0 100644 --- a/src/font/qpf.c +++ b/src/font/qpf.c @@ -302,7 +302,7 @@ static int get_font_height (LOGFONT* logfont, DEVFONT* devfont) * GET_DEVFONT_SCALE (logfont, devfont); } -static int get_font_size (LOGFONT* logfont, DEVFONT* devfont, int expect) +static int get_font_size (LOGFONT* logfont, DEVFONT* devfont, int expect, int df_slot) { int height = QPFONT_INFO_P (devfont)->fm->ascent + QPFONT_INFO_P (devfont)->fm->descent; @@ -311,7 +311,8 @@ static int get_font_size (LOGFONT* logfont, DEVFONT* devfont, int expect) if (logfont->style & FS_OTHER_AUTOSCALE) scale = font_GetBestScaleFactor (height, expect); - SET_DEVFONT_SCALE (logfont, devfont, scale); + if (df_slot >= 0 && df_slot < MAXNR_DEVFONTS) + SET_DEVFONT_SCALE (logfont, df_slot, scale); return height * scale; } diff --git a/src/font/rawbitmap.c b/src/font/rawbitmap.c index 0612bc9a..67545327 100644 --- a/src/font/rawbitmap.c +++ b/src/font/rawbitmap.c @@ -154,7 +154,7 @@ static int get_font_height (LOGFONT* logfont, DEVFONT* devfont) return RBFONT_INFO_P (devfont)->height * GET_DEVFONT_SCALE (logfont, devfont); } -static int get_font_size (LOGFONT* logfont, DEVFONT* devfont, int expect) +static int get_font_size (LOGFONT* logfont, DEVFONT* devfont, int expect, int df_slot) { int height = RBFONT_INFO_P (devfont)->height; unsigned short scale = 1; @@ -162,7 +162,8 @@ static int get_font_size (LOGFONT* logfont, DEVFONT* devfont, int expect) if (logfont->style & FS_OTHER_AUTOSCALE) scale = font_GetBestScaleFactor (height, expect); - SET_DEVFONT_SCALE (logfont, devfont, scale); + if (df_slot >= 0 && df_slot < MAXNR_DEVFONTS) + SET_DEVFONT_SCALE (logfont, df_slot, scale); return height * scale; } diff --git a/src/font/type1.c b/src/font/type1.c index 43caf1f7..65572955 100644 --- a/src/font/type1.c +++ b/src/font/type1.c @@ -200,8 +200,11 @@ static int get_font_height (LOGFONT* logfont, DEVFONT* devfont) return type1_inst_info->font_height; } -static int get_font_size (LOGFONT* logfont, DEVFONT* devfont, int expect) +static int get_font_size (LOGFONT* logfont, DEVFONT* devfont, int expect, int df_slot) { + if (df_slot >= 0 && df_slot < MAXNR_DEVFONTS) + SET_DEVFONT_SCALE (logfont, df_slot, scale); + return expect; } diff --git a/src/font/upf.c b/src/font/upf.c index 56cbeaae..8e27dade 100644 --- a/src/font/upf.c +++ b/src/font/upf.c @@ -170,7 +170,7 @@ static int get_font_height (LOGFONT* logfont, DEVFONT* devfont) return (p_upf->ascent + p_upf->descent) * GET_DEVFONT_SCALE (logfont, devfont); } -static int get_font_size (LOGFONT* logfont, DEVFONT* devfont, int expect) +static int get_font_size (LOGFONT* logfont, DEVFONT* devfont, int expect, int df_slot) { UPFV1_FILE_HEADER * p_upf; int height; @@ -187,7 +187,8 @@ static int get_font_size (LOGFONT* logfont, DEVFONT* devfont, int expect) if (logfont->style & FS_OTHER_AUTOSCALE) scale = font_GetBestScaleFactor (height, expect); - SET_DEVFONT_SCALE (logfont, devfont, scale); + if (df_slot >= 0 && df_slot < MAXNR_DEVFONTS) + SET_DEVFONT_SCALE (logfont, df_slot, scale); return height * scale; } diff --git a/src/font/varbitmap.c b/src/font/varbitmap.c index 58efd4f6..05f5b13b 100644 --- a/src/font/varbitmap.c +++ b/src/font/varbitmap.c @@ -133,7 +133,7 @@ static int get_font_height (LOGFONT* logfont, DEVFONT* devfont) return VARFONT_INFO_P (devfont)->height * GET_DEVFONT_SCALE (logfont, devfont); } -static int get_font_size (LOGFONT* logfont, DEVFONT* devfont, int expect) +static int get_font_size (LOGFONT* logfont, DEVFONT* devfont, int expect, int df_slot) { int height = VARFONT_INFO_P (devfont)->height; unsigned short scale = 1; @@ -141,7 +141,8 @@ static int get_font_size (LOGFONT* logfont, DEVFONT* devfont, int expect) if (logfont->style & FS_OTHER_AUTOSCALE) scale = font_GetBestScaleFactor (height, expect); - SET_DEVFONT_SCALE (logfont, devfont, scale); + if (df_slot >= 0 && df_slot < MAXNR_DEVFONTS) + SET_DEVFONT_SCALE (logfont, df_slot, scale); return height * scale; } diff --git a/src/include/devfont.h b/src/include/devfont.h index f91b66ed..6c340266 100644 --- a/src/include/devfont.h +++ b/src/include/devfont.h @@ -69,7 +69,7 @@ void font_DelRelatedDevFont (DEVFONT* dev_font); void font_ResetDevFont (void); DEVFONT* font_GetMatchedSBDevFont (LOGFONT* lf, const char* family); -DEVFONT* font_GetMatchedMBDevFont (LOGFONT* lf, const char* family); +DEVFONT* font_GetMatchedMBDevFont (LOGFONT* lf, const char* family, int slot); static inline unsigned short get_devfont_scale(LOGFONT* lf, const DEVFONT* df) @@ -83,23 +83,11 @@ static inline unsigned short get_devfont_scale(LOGFONT* lf, return 1; } -static inline void set_devfont_scale(LOGFONT* lf, DEVFONT* df, - unsigned short s) -{ - int i; - for (i = 0; i < MAXNR_DEVFONTS; i++) { - if (lf->devfonts[i] == df) { - lf->scales[i] = s; - break; - } - } -} - #define GET_DEVFONT_SCALE(logfont, devfont) \ get_devfont_scale(logfont, devfont) -#define SET_DEVFONT_SCALE(logfont, devfont, scale) \ - set_devfont_scale(logfont, devfont, scale) +#define SET_DEVFONT_SCALE(logfont, df_slot, scale) \ + (logfont)->scales[(df_slot)] = (scale) unsigned short font_GetBestScaleFactor (int height, int expect); @@ -232,7 +220,7 @@ struct _FONTOPS int (*get_font_height) (LOGFONT* logfont, DEVFONT* devfont); /** The method to get font size function. */ - int (*get_font_size) (LOGFONT* logfont, DEVFONT* devfont, int expect); + int (*get_font_size) (LOGFONT* logfont, DEVFONT* devfont, int expect, int slot); /** The method to get font ascent function. */ int (*get_font_ascent) (LOGFONT* logfont, DEVFONT* devfont); diff --git a/src/newgdi/logfont.c b/src/newgdi/obsolote/logfont.c similarity index 99% rename from src/newgdi/logfont.c rename to src/newgdi/obsolote/logfont.c index 139c48e0..e4a39da7 100644 --- a/src/newgdi/logfont.c +++ b/src/newgdi/obsolote/logfont.c @@ -32,6 +32,8 @@ * . */ /* +** NOTE: DEPRECATED. +** ** logfont.c: Log fonts management. ** ** Current maintainer: Wei Yongming.