forked from mirrors/gecko-dev
Bug 1871009 - Improve mapping of the CoreText font-weight trait to values for the CSS font-weight property. r=layout-reviewers,emilio
Checking the fonts in HelveticaNeue.ttc on macOS Sonoma, both HelveticaNeue-Medium and -MediumItalic have the same weight (500) in their OS/2 table, and return the same value (0.23) for their kCTFontWeightTrait. Back in bug 931426 when the weight override pref was added, we were getting different weights from appKit for these two "Medium" faces, but that no longer appears to be an issue. This patch makes our CoreTextWeightToCSSWeight mapping a bit more sophisticated, with the added data point of CSS/OpenType weight 500 = CoreText weight 0.23, which we're seeing here in HelveticaNeue. With this refinement in the mapping, we can drop the old override for the HelveticaNeue-MediumItalic face. Differential Revision: https://phabricator.services.mozilla.com/D197665
This commit is contained in:
parent
cd901e4e4f
commit
4170df881e
2 changed files with 11 additions and 7 deletions
|
|
@ -736,17 +736,22 @@ static inline int GetWeightOverride(const nsAString& aPSName) {
|
|||
//
|
||||
// CSS 'normal' font-weight is defined as 400, so we map 0.0 to this.
|
||||
// The exact mapping to use for other values is not well defined; for now,
|
||||
// we arbitrarily map the smallest value (-1.0) to CSS weight 100. For weights
|
||||
// greater than 0.0, we map 0.4 (seems to be what Core Text uses for standard
|
||||
// "bold" fonts) to CSS 700, and interpolate linearly either side of that.
|
||||
// we arbitrarily map the smallest value (-1.0) to CSS weight 100.
|
||||
// For weights greater than 0.0, we map 0.23 to 500 (per HelveticaNeue-Medium),
|
||||
// and 0.4 (seems to be what Core Text uses for standard "bold" fonts) to 700,
|
||||
// and interpolate linearly for other values.
|
||||
static inline int32_t CoreTextWeightToCSSWeight(CGFloat aCTWeight) {
|
||||
if (aCTWeight >= 0.4) {
|
||||
// map weights from 0.4 upwards to [700..1000]
|
||||
return 700 + NS_round((aCTWeight - 0.4) * 500);
|
||||
return 700 + NS_round((aCTWeight - 0.4) * (1000 - 700) / (1.0 - 0.4));
|
||||
}
|
||||
if (aCTWeight >= 0.23) {
|
||||
// weights from 0.23 to 0.4 map to [500..700]
|
||||
return 500 + NS_round((aCTWeight - 0.23) * (700 - 500) / (0.4 - 0.23));
|
||||
}
|
||||
if (aCTWeight >= 0.0) {
|
||||
// map weights from 0.0 to 0.4 to [400..700]
|
||||
return 400 + NS_round(aCTWeight * 750);
|
||||
// map weights from 0.0 to 0.23 to [400..500]
|
||||
return 400 + NS_round(aCTWeight * (500 - 400) / 0.23);
|
||||
}
|
||||
// weights less than 0.0
|
||||
return 400 + NS_round(aCTWeight * 300);
|
||||
|
|
|
|||
|
|
@ -2652,7 +2652,6 @@ pref("font.size.monospace.x-math", 13);
|
|||
|
||||
pref("font.weight-override.HelveticaNeue-Light", 300); // Ensure Light > Thin (200)
|
||||
pref("font.weight-override.HelveticaNeue-LightItalic", 300);
|
||||
pref("font.weight-override.HelveticaNeue-MediumItalic", 500); // Harmonize MediumItalic with Medium
|
||||
|
||||
// See bug 404131, topmost <panel> element wins to Dashboard on MacOSX.
|
||||
pref("ui.panel.default_level_parent", false);
|
||||
|
|
|
|||
Loading…
Reference in a new issue