mirror of
https://github.com/VincentWei/MiniGUI.git
synced 2026-09-24 09:14:09 +08:00
add df_slot to get_font_size of DEVFONT operators in order to set scale correctly
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
+71
-16
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
+19
-16
@@ -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;
|
||||
|
||||
|
||||
+3
-2
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
+4
-1
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
+4
-16
@@ -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);
|
||||
|
||||
@@ -32,6 +32,8 @@
|
||||
* <http://www.minigui.com/en/about/licensing-policy/>.
|
||||
*/
|
||||
/*
|
||||
** NOTE: DEPRECATED.
|
||||
**
|
||||
** logfont.c: Log fonts management.
|
||||
**
|
||||
** Current maintainer: Wei Yongming.
|
||||
Reference in New Issue
Block a user