Bug 1611589 - Fix precedence of font-feature-settings vs disabling of ligatures due to letter-spacing. r=lsalzman

Differential Revision: https://phabricator.services.mozilla.com/D61060

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jonathan Kew 2020-01-25 12:18:00 +00:00
parent 880da431e7
commit f360407017
3 changed files with 33 additions and 12 deletions

View File

@ -247,6 +247,15 @@ void nsFont::AddFontFeaturesToStyle(gfxFontStyle* aStyle,
(aStyle->variantCaps == NS_FONT_VARIANT_CAPS_NORMAL) &&
(variantPosition == NS_FONT_VARIANT_POSITION_NORMAL);
// If the feature list is not empty, we insert a "fake" feature with tag=0
// as delimiter between the above "high-level" features from font-variant-*
// etc and those coming from the low-level font-feature-settings property.
// This will allow us to distinguish high- and low-level settings when it
// comes to potentially disabling ligatures because of letter-spacing.
if (!aStyle->featureSettings.IsEmpty() || !fontFeatureSettings.IsEmpty()) {
aStyle->featureSettings.AppendElement(gfxFontFeature{0, 0});
}
// add in features from font-feature-settings
aStyle->featureSettings.AppendElements(fontFeatureSettings);

View File

@ -461,13 +461,6 @@ void gfxFontShaper::MergeFontFeatures(
nsDataHashtable<nsUint32HashKey, uint32_t> mergedFeatures;
// Ligature features are enabled by default in the generic shaper,
// so we explicitly turn them off if necessary (for letter-spacing)
if (aDisableLigatures) {
mergedFeatures.Put(HB_TAG('l', 'i', 'g', 'a'), 0);
mergedFeatures.Put(HB_TAG('c', 'l', 'i', 'g'), 0);
}
// add feature values from font
for (const gfxFontFeature& feature : aFontFeatures) {
mergedFeatures.Put(feature.mTag, feature.mValue);
@ -545,9 +538,30 @@ void gfxFontShaper::MergeFontFeatures(
}
}
// add feature values from style rules
for (const gfxFontFeature& feature : styleRuleFeatures) {
mergedFeatures.Put(feature.mTag, feature.mValue);
// Add features that are already resolved to tags & values in the style.
if (styleRuleFeatures.IsEmpty()) {
// Disable common ligatures if non-zero letter-spacing is in effect.
if (aDisableLigatures) {
mergedFeatures.Put(HB_TAG('l', 'i', 'g', 'a'), 0);
mergedFeatures.Put(HB_TAG('c', 'l', 'i', 'g'), 0);
}
} else {
for (const gfxFontFeature& feature : styleRuleFeatures) {
// A dummy feature (0,0) is used as a sentinel to separate features
// originating from font-variant-* or other high-level properties from
// those directly specified as font-feature-settings. The high-level
// features may be overridden by aDisableLigatures, while low-level
// features specified directly as tags will come last and therefore
// take precedence over everything else.
if (feature.mTag) {
mergedFeatures.Put(feature.mTag, feature.mValue);
} else if (aDisableLigatures) {
// Handle ligature-disabling setting at the boundary between high-
// and low-level features.
mergedFeatures.Put(HB_TAG('l', 'i', 'g', 'a'), 0);
mergedFeatures.Put(HB_TAG('c', 'l', 'i', 'g'), 0);
}
}
}
if (mergedFeatures.Count() != 0) {

View File

@ -1,2 +0,0 @@
[font-feature-resolution-001.html]
expected: FAIL