[FONT][WIN32SS] Use GOT_PENALTY macro to specify the penalty (#910)

Define and use GOT_PENALTY macro to specify the font penalty info.
CORE-5519
This commit is contained in:
Katayama Hirofumi MZ 2018-10-08 21:38:38 +09:00 committed by Hermès BÉLUSCA - MAÏTO
parent cb499cd1fd
commit 951335cd15

View file

@ -4346,6 +4346,8 @@ ftGdiGetFontData(
return Result; return Result;
} }
#define GOT_PENALTY(name, value) Penalty += (value)
// NOTE: See Table 1. of https://msdn.microsoft.com/en-us/library/ms969909.aspx // NOTE: See Table 1. of https://msdn.microsoft.com/en-us/library/ms969909.aspx
static UINT static UINT
GetFontPenalty(const LOGFONTW * LogFont, GetFontPenalty(const LOGFONTW * LogFont,
@ -4387,18 +4389,19 @@ GetFontPenalty(const LOGFONTW * LogFont,
{ {
/* CharSet Penalty 65000 */ /* CharSet Penalty 65000 */
/* Requested charset does not match the candidate's. */ /* Requested charset does not match the candidate's. */
Penalty += 65000; GOT_PENALTY("CharSet", 65000);
} }
else else
{ {
if (UserCharSet != TM->tmCharSet) if (UserCharSet != TM->tmCharSet)
{ {
/* UNDOCUMENTED */ /* UNDOCUMENTED: Not user language */
Penalty += 100; GOT_PENALTY("UNDOCUMENTED:NotUserLanguage", 100);
if (ANSI_CHARSET != TM->tmCharSet) if (ANSI_CHARSET != TM->tmCharSet)
{ {
/* UNDOCUMENTED */ /* UNDOCUMENTED: Not ANSI charset */
Penalty += 100; GOT_PENALTY("UNDOCUMENTED:NotAnsiCharSet", 100);
} }
} }
} }
@ -4416,7 +4419,7 @@ GetFontPenalty(const LOGFONTW * LogFont,
/* OutputPrecision Penalty 19000 */ /* OutputPrecision Penalty 19000 */
/* Requested OUT_STROKE_PRECIS, but the device can't do it /* Requested OUT_STROKE_PRECIS, but the device can't do it
or the candidate is not a vector font. */ or the candidate is not a vector font. */
Penalty += 19000; GOT_PENALTY("OutputPrecision", 19000);
} }
break; break;
default: default:
@ -4425,7 +4428,7 @@ GetFontPenalty(const LOGFONTW * LogFont,
/* OutputPrecision Penalty 19000 */ /* OutputPrecision Penalty 19000 */
/* Or OUT_STROKE_PRECIS not requested, and the candidate /* Or OUT_STROKE_PRECIS not requested, and the candidate
is a vector font that requires GDI support. */ is a vector font that requires GDI support. */
Penalty += 19000; GOT_PENALTY("OutputPrecision", 19000);
} }
break; break;
} }
@ -4440,7 +4443,7 @@ GetFontPenalty(const LOGFONTW * LogFont,
/* FixedPitch Penalty 15000 */ /* FixedPitch Penalty 15000 */
/* Requested a fixed pitch font, but the candidate is a /* Requested a fixed pitch font, but the candidate is a
variable pitch font. */ variable pitch font. */
Penalty += 15000; GOT_PENALTY("FixedPitch", 15000);
} }
} }
if (Byte == VARIABLE_PITCH) if (Byte == VARIABLE_PITCH)
@ -4450,7 +4453,7 @@ GetFontPenalty(const LOGFONTW * LogFont,
/* PitchVariable Penalty 350 */ /* PitchVariable Penalty 350 */
/* Requested a variable pitch font, but the candidate is not a /* Requested a variable pitch font, but the candidate is not a
variable pitch font. */ variable pitch font. */
Penalty += 350; GOT_PENALTY("PitchVariable", 350);
} }
} }
@ -4461,7 +4464,7 @@ GetFontPenalty(const LOGFONTW * LogFont,
{ {
/* DefaultPitchFixed Penalty 1 */ /* DefaultPitchFixed Penalty 1 */
/* Requested DEFAULT_PITCH, but the candidate is fixed pitch. */ /* Requested DEFAULT_PITCH, but the candidate is fixed pitch. */
Penalty += 1; GOT_PENALTY("DefaultPitchFixed", 1);
} }
} }
@ -4487,7 +4490,7 @@ GetFontPenalty(const LOGFONTW * LogFont,
/* FaceName Penalty 10000 */ /* FaceName Penalty 10000 */
/* Requested a face name, but the candidate's face name /* Requested a face name, but the candidate's face name
does not match. */ does not match. */
Penalty += 10000; GOT_PENALTY("FaceName", 10000);
} }
} }
@ -4498,13 +4501,13 @@ GetFontPenalty(const LOGFONTW * LogFont,
{ {
/* Family Penalty 9000 */ /* Family Penalty 9000 */
/* Requested a family, but the candidate's family is different. */ /* Requested a family, but the candidate's family is different. */
Penalty += 9000; GOT_PENALTY("Family", 9000);
} }
if ((TM->tmPitchAndFamily & 0xF0) == FF_DONTCARE) if ((TM->tmPitchAndFamily & 0xF0) == FF_DONTCARE)
{ {
/* FamilyUnknown Penalty 8000 */ /* FamilyUnknown Penalty 8000 */
/* Requested a family, but the candidate has no family. */ /* Requested a family, but the candidate has no family. */
Penalty += 8000; GOT_PENALTY("FamilyUnknown", 8000);
} }
} }
@ -4519,11 +4522,11 @@ GetFontPenalty(const LOGFONTW * LogFont,
/* HeightBigger Penalty 600 */ /* HeightBigger Penalty 600 */
/* The candidate is a nonvector font and is bigger than the /* The candidate is a nonvector font and is bigger than the
requested height. */ requested height. */
Penalty += 600; GOT_PENALTY("HeightBigger", 600);
/* HeightBiggerDifference Penalty 150 */ /* HeightBiggerDifference Penalty 150 */
/* The candidate is a raster font and is larger than the /* The candidate is a raster font and is larger than the
requested height. Penalty * height difference */ requested height. Penalty * height difference */
Penalty += 150 * labs(TM->tmHeight - labs(LogFont->lfHeight)); GOT_PENALTY("HeightBiggerDifference", 150 * labs(TM->tmHeight - labs(LogFont->lfHeight)));
fNeedScaling = TRUE; fNeedScaling = TRUE;
} }
@ -4532,7 +4535,7 @@ GetFontPenalty(const LOGFONTW * LogFont,
/* HeightSmaller Penalty 150 */ /* HeightSmaller Penalty 150 */
/* The candidate is a raster font and is smaller than the /* The candidate is a raster font and is smaller than the
requested height. Penalty * height difference */ requested height. Penalty * height difference */
Penalty += 150 * labs(TM->tmHeight - labs(LogFont->lfHeight)); GOT_PENALTY("HeightSmaller", 150 * labs(TM->tmHeight - labs(LogFont->lfHeight)));
fNeedScaling = TRUE; fNeedScaling = TRUE;
} }
@ -4548,7 +4551,7 @@ GetFontPenalty(const LOGFONTW * LogFont,
/* FamilyUnlikely Penalty 50 */ /* FamilyUnlikely Penalty 50 */
/* Requested a roman/modern/swiss family, but the /* Requested a roman/modern/swiss family, but the
candidate is decorative/script. */ candidate is decorative/script. */
Penalty += 50; GOT_PENALTY("FamilyUnlikely", 50);
break; break;
default: default:
break; break;
@ -4561,7 +4564,7 @@ GetFontPenalty(const LOGFONTW * LogFont,
/* FamilyUnlikely Penalty 50 */ /* FamilyUnlikely Penalty 50 */
/* Or requested decorative/script, and the candidate is /* Or requested decorative/script, and the candidate is
roman/modern/swiss. */ roman/modern/swiss. */
Penalty += 50; GOT_PENALTY("FamilyUnlikely", 50);
break; break;
default: default:
break; break;
@ -4577,7 +4580,7 @@ GetFontPenalty(const LOGFONTW * LogFont,
/* Width Penalty 50 */ /* Width Penalty 50 */
/* Requested a nonzero width, but the candidate's width /* Requested a nonzero width, but the candidate's width
doesn't match. Penalty * width difference */ doesn't match. Penalty * width difference */
Penalty += 50 * labs(LogFont->lfWidth - TM->tmAveCharWidth); GOT_PENALTY("Width", 50 * labs(LogFont->lfWidth - TM->tmAveCharWidth));
if (!(TM->tmPitchAndFamily & (TMPF_TRUETYPE | TMPF_VECTOR))) if (!(TM->tmPitchAndFamily & (TMPF_TRUETYPE | TMPF_VECTOR)))
fNeedScaling = TRUE; fNeedScaling = TRUE;
@ -4588,7 +4591,7 @@ GetFontPenalty(const LOGFONTW * LogFont,
{ {
/* SizeSynth Penalty 50 */ /* SizeSynth Penalty 50 */
/* The candidate is a raster font that needs scaling by GDI. */ /* The candidate is a raster font that needs scaling by GDI. */
Penalty += 50; GOT_PENALTY("SizeSynth", 50);
} }
if (!!LogFont->lfItalic != !!TM->tmItalic) if (!!LogFont->lfItalic != !!TM->tmItalic)
@ -4599,14 +4602,14 @@ GetFontPenalty(const LOGFONTW * LogFont,
/* Requested font and candidate font do not agree on italic status, /* Requested font and candidate font do not agree on italic status,
and the desired result cannot be simulated. */ and the desired result cannot be simulated. */
/* Adjusted to 40 to satisfy (Oblique Penalty > Book Penalty). */ /* Adjusted to 40 to satisfy (Oblique Penalty > Book Penalty). */
Penalty += 40; GOT_PENALTY("Italic", 40);
} }
else if (LogFont->lfItalic && !ItalicFromStyle(style_name)) else if (LogFont->lfItalic && !ItalicFromStyle(style_name))
{ {
/* ItalicSim Penalty 1 */ /* ItalicSim Penalty 1 */
/* Requested italic font but the candidate is not italic, /* Requested italic font but the candidate is not italic,
although italics can be simulated. */ although italics can be simulated. */
Penalty += 1; GOT_PENALTY("ItalicSim", 1);
} }
} }
@ -4617,7 +4620,7 @@ GetFontPenalty(const LOGFONTW * LogFont,
/* NotTrueType Penalty 4 */ /* NotTrueType Penalty 4 */
/* Requested OUT_TT_PRECIS, but the candidate is not a /* Requested OUT_TT_PRECIS, but the candidate is not a
TrueType font. */ TrueType font. */
Penalty += 4; GOT_PENALTY("NotTrueType", 4);
} }
} }
@ -4629,7 +4632,7 @@ GetFontPenalty(const LOGFONTW * LogFont,
/* Weight Penalty 3 */ /* Weight Penalty 3 */
/* The candidate's weight does not match the requested weight. /* The candidate's weight does not match the requested weight.
Penalty * (weight difference/10) */ Penalty * (weight difference/10) */
Penalty += 3 * (labs(Long - TM->tmWeight) / 10); GOT_PENALTY("Weight", 3 * (labs(Long - TM->tmWeight) / 10));
} }
if (!LogFont->lfUnderline && TM->tmUnderlined) if (!LogFont->lfUnderline && TM->tmUnderlined)
@ -4637,7 +4640,7 @@ GetFontPenalty(const LOGFONTW * LogFont,
/* Underline Penalty 3 */ /* Underline Penalty 3 */
/* Requested font has no underline, but the candidate is /* Requested font has no underline, but the candidate is
underlined. */ underlined. */
Penalty += 3; GOT_PENALTY("Underline", 3);
} }
if (!LogFont->lfStrikeOut && TM->tmStruckOut) if (!LogFont->lfStrikeOut && TM->tmStruckOut)
@ -4645,7 +4648,7 @@ GetFontPenalty(const LOGFONTW * LogFont,
/* StrikeOut Penalty 3 */ /* StrikeOut Penalty 3 */
/* Requested font has no strike-out, but the candidate is /* Requested font has no strike-out, but the candidate is
struck out. */ struck out. */
Penalty += 3; GOT_PENALTY("StrikeOut", 3);
} }
/* Is the candidate a non-vector font? */ /* Is the candidate a non-vector font? */
@ -4656,14 +4659,14 @@ GetFontPenalty(const LOGFONTW * LogFont,
/* VectorHeightSmaller Penalty 2 */ /* VectorHeightSmaller Penalty 2 */
/* Candidate is a vector font that is smaller than the /* Candidate is a vector font that is smaller than the
requested height. Penalty * height difference */ requested height. Penalty * height difference */
Penalty += 2 * labs(TM->tmHeight - LogFont->lfHeight); GOT_PENALTY("VectorHeightSmaller", 2 * labs(TM->tmHeight - LogFont->lfHeight));
} }
if (LogFont->lfHeight != 0 && TM->tmHeight > LogFont->lfHeight) if (LogFont->lfHeight != 0 && TM->tmHeight > LogFont->lfHeight)
{ {
/* VectorHeightBigger Penalty 1 */ /* VectorHeightBigger Penalty 1 */
/* Candidate is a vector font that is bigger than the /* Candidate is a vector font that is bigger than the
requested height. Penalty * height difference */ requested height. Penalty * height difference */
Penalty += 1 * labs(TM->tmHeight - LogFont->lfHeight); GOT_PENALTY("VectorHeightBigger", 1 * labs(TM->tmHeight - LogFont->lfHeight));
} }
} }
@ -4671,7 +4674,7 @@ GetFontPenalty(const LOGFONTW * LogFont,
{ {
/* DeviceFavor Penalty 2 */ /* DeviceFavor Penalty 2 */
/* Extra penalty for all nondevice fonts. */ /* Extra penalty for all nondevice fonts. */
Penalty += 2; GOT_PENALTY("DeviceFavor", 2);
} }
if (TM->tmAveCharWidth >= 5 && TM->tmHeight >= 5) if (TM->tmAveCharWidth >= 5 && TM->tmHeight >= 5)
@ -4680,13 +4683,13 @@ GetFontPenalty(const LOGFONTW * LogFont,
{ {
/* Aspect Penalty 30 */ /* Aspect Penalty 30 */
/* The aspect rate is >= 3. It seems like a bad font. */ /* The aspect rate is >= 3. It seems like a bad font. */
Penalty += ((TM->tmAveCharWidth / TM->tmHeight) - 2) * 30; GOT_PENALTY("Aspect", ((TM->tmAveCharWidth / TM->tmHeight) - 2) * 30);
} }
else if (TM->tmHeight / TM->tmAveCharWidth >= 3) else if (TM->tmHeight / TM->tmAveCharWidth >= 3)
{ {
/* Aspect Penalty 30 */ /* Aspect Penalty 30 */
/* The aspect rate is >= 3. It seems like a bad font. */ /* The aspect rate is >= 3. It seems like a bad font. */
Penalty += ((TM->tmHeight / TM->tmAveCharWidth) - 2) * 30; GOT_PENALTY("Aspect", ((TM->tmHeight / TM->tmAveCharWidth) - 2) * 30);
} }
} }
@ -4703,6 +4706,8 @@ GetFontPenalty(const LOGFONTW * LogFont,
return Penalty; /* success */ return Penalty; /* success */
} }
#undef GOT_PENALTY
static __inline VOID static __inline VOID
FindBestFontFromList(FONTOBJ **FontObj, ULONG *MatchPenalty, FindBestFontFromList(FONTOBJ **FontObj, ULONG *MatchPenalty,
const LOGFONTW *LogFont, const LOGFONTW *LogFont,