haikuwebkit/LayoutTests/css3/font-feature-settings-font-...

106 lines
6.7 KiB
HTML
Raw Permalink Normal View History

font-variant-* properties in @font-face declarations should be honored https://bugs.webkit.org/show_bug.cgi?id=149771 Reviewed by Simon Fraser. Source/WebCore: According to the CSS Fonts Level 3 spec, web authors are allowed to put font-feature-settings / font-variant-* inside @font-face blocks. These properties are supposed to be applied at a specific time during the font selection algorithm. This patch gives a FontFeatureSettings object and a FontVariantSettings object to CSSFontFace, and moves common parsing logic from StyleBuilderCustom to a shared location. Then, once the two properties are parsed from the @font-face block, the relevant data structures are passed down into the font selection algorithm. This algorithm then consults with these values at the correct time (inside preparePlatformFont()). Tests: css3/font-feature-settings-font-face-rendering.html css3/font-variant-font-face-all.html css3/font-variant-font-face-override.html * WebCore.xcodeproj/project.pbxproj: Add a header for the common location of parsing font-variant-ligatures, font-variant-numeric, and font-variant-east-asian. * css/CSSFontFace.cpp: (WebCore::CSSFontFace::font): Pass the relevant data structures into the font selection algorithm. * css/CSSFontFace.h: Add FontFeatureSettings and FontVariantSettings member variables. (WebCore::CSSFontFace::insertFeature): (WebCore::CSSFontFace::setVariantCommonLigatures): (WebCore::CSSFontFace::setVariantDiscretionaryLigatures): (WebCore::CSSFontFace::setVariantHistoricalLigatures): (WebCore::CSSFontFace::setVariantContextualAlternates): (WebCore::CSSFontFace::setVariantPosition): (WebCore::CSSFontFace::setVariantCaps): (WebCore::CSSFontFace::setVariantNumericFigure): (WebCore::CSSFontFace::setVariantNumericSpacing): (WebCore::CSSFontFace::setVariantNumericFraction): (WebCore::CSSFontFace::setVariantNumericOrdinal): (WebCore::CSSFontFace::setVariantNumericSlashedZero): (WebCore::CSSFontFace::setVariantAlternates): (WebCore::CSSFontFace::setVariantEastAsianVariant): (WebCore::CSSFontFace::setVariantEastAsianWidth): (WebCore::CSSFontFace::setVariantEastAsianRuby): * css/CSSFontFaceSource.cpp: (WebCore::CSSFontFaceSource::font): Pass the relevant data structures into the font selection algorithm. * css/CSSFontFaceSource.h: Ditto. * css/CSSFontSelector.cpp: (WebCore::CSSFontSelector::addFontFaceRule): Call the shared parsing logic to populate the FontFeatureSettings and FontVariantSettings members. * css/FontVariantBuilder.h: Added. Destination for shared parsing logic. (WebCore::applyValueFontVariantLigatures): (WebCore::applyValueFontVariantNumeric): (WebCore::applyValueFontVariantEastAsian): * css/StyleBuilderCustom.h: Source for shared parsing logic. (WebCore::StyleBuilderCustom::applyValueFontVariantLigatures): (WebCore::StyleBuilderCustom::applyValueFontVariantNumeric): (WebCore::StyleBuilderCustom::applyValueFontVariantEastAsian): * loader/cache/CachedFont.cpp: Pass the relevant data structures into the font selection algorithm. (WebCore::CachedFont::createFont): (WebCore::CachedFont::platformDataFromCustomData): * loader/cache/CachedFont.h: Ditto. * loader/cache/CachedSVGFont.cpp: Ditto. (WebCore::CachedSVGFont::createFont): (WebCore::CachedSVGFont::platformDataFromCustomData): * loader/cache/CachedSVGFont.h: Ditto. * platform/graphics/FontCache.h: Ditto. * platform/graphics/FontCascade.cpp: (WebCore::FontCascade::codePath): Adjust comment. * platform/graphics/cocoa/FontCacheCoreText.cpp: (WebCore::preparePlatformFont): Consult with the newly parsed values. (WebCore::fontWithFamily): Pass the relevant data structures into the font selection algorithm. (WebCore::FontCache::systemFallbackForCharacters): Ditto. * platform/graphics/mac/FontCustomPlatformData.cpp: (WebCore::FontCustomPlatformData::fontPlatformData): Ditto. * platform/graphics/mac/FontCustomPlatformData.h: Ditto. LayoutTests: * css3/font-variant-font-face-override-expected.html: Added * css3/font-variant-font-face-override.html: Added * css3/font-feature-settings-font-face-rendering-expected.html: Added. * css3/font-feature-settings-font-face-rendering.html: Added. * css3/font-variant-font-face-all-expected.html: Added. * css3/font-variant-font-face-all.html: Added. Canonical link: https://commits.webkit.org/169055@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@191968 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2015-11-03 20:31:33 +00:00
<!DOCTYPE html>
<html>
<head>
<style>
@font-face {
font-family: "FontFeaturesTestOTF";
src: url("resources/FontWithFeatures.otf") format("opentype");
}
@font-face {
font-family: "FontFeaturesTestTTF";
src: url("resources/FontWithFeatures.ttf") format("truetype");
}
</style>
</head>
<body>
This tests that font features are able to be turned on and off as desired. It uses a special font
designed specifically for this purpose. The test passes if you see a sequence of alternating check
marks and X below.
<div id="insertionPoint"></div>
<div id="insertionPoint2"></div>
<script>
var insertionPoint = document.getElementById("insertionPoint");
var insertionPoint2 = document.getElementById("insertionPoint2");
var styleNode = document.createElement("style");
document.head.appendChild(styleNode);
function addElement(placeToInsert, familyName, extension, format, feature, c) {
["0", "1"].map(function(state) {
styleNode.sheet.insertRule("@font-face { font-family: " + familyName + "_" + feature + "_" + state + "; src: url('resources/FontWithFeatures." + extension + "') format('" + format + "'); font-feature-settings: '" + feature + "'" + state + "; }", 0);
var element = document.createElement("span");
element.textContent = c + c;
element.style.fontFamily = familyName + "_" + feature + "_" + state;
placeToInsert.appendChild(element);
});
placeToInsert.appendChild(document.createTextNode(" "));
}
addElement(insertionPoint, "FontFeaturesTestOTF", "otf", "opentype", "liga", "C");
addElement(insertionPoint, "FontFeaturesTestOTF", "otf", "opentype", "clig", "D");
addElement(insertionPoint, "FontFeaturesTestOTF", "otf", "opentype", "dlig", "E");
addElement(insertionPoint, "FontFeaturesTestOTF", "otf", "opentype", "hlig", "F");
addElement(insertionPoint, "FontFeaturesTestOTF", "otf", "opentype", "calt", "G");
addElement(insertionPoint, "FontFeaturesTestOTF", "otf", "opentype", "subs", "H");
addElement(insertionPoint, "FontFeaturesTestOTF", "otf", "opentype", "sups", "I");
addElement(insertionPoint, "FontFeaturesTestOTF", "otf", "opentype", "smcp", "J");
addElement(insertionPoint, "FontFeaturesTestOTF", "otf", "opentype", "c2sc", "K");
addElement(insertionPoint, "FontFeaturesTestOTF", "otf", "opentype", "pcap", "L");
addElement(insertionPoint, "FontFeaturesTestOTF", "otf", "opentype", "c2pc", "M");
addElement(insertionPoint, "FontFeaturesTestOTF", "otf", "opentype", "unic", "N");
addElement(insertionPoint, "FontFeaturesTestOTF", "otf", "opentype", "titl", "O");
addElement(insertionPoint, "FontFeaturesTestOTF", "otf", "opentype", "lnum", "P");
addElement(insertionPoint, "FontFeaturesTestOTF", "otf", "opentype", "onum", "Q");
addElement(insertionPoint, "FontFeaturesTestOTF", "otf", "opentype", "pnum", "R");
addElement(insertionPoint, "FontFeaturesTestOTF", "otf", "opentype", "tnum", "S");
addElement(insertionPoint, "FontFeaturesTestOTF", "otf", "opentype", "frac", "T");
//addElement(insertionPoint, "FontFeaturesTestOTF", "otf", "opentype", "afrc", "U");
addElement(insertionPoint, "FontFeaturesTestOTF", "otf", "opentype", "ordn", "V");
addElement(insertionPoint, "FontFeaturesTestOTF", "otf", "opentype", "zero", "W");
addElement(insertionPoint, "FontFeaturesTestOTF", "otf", "opentype", "hist", "X");
addElement(insertionPoint, "FontFeaturesTestOTF", "otf", "opentype", "jp78", "Y");
addElement(insertionPoint, "FontFeaturesTestOTF", "otf", "opentype", "jp83", "Z");
addElement(insertionPoint, "FontFeaturesTestOTF", "otf", "opentype", "jp90", "a");
addElement(insertionPoint, "FontFeaturesTestOTF", "otf", "opentype", "jp04", "b");
addElement(insertionPoint, "FontFeaturesTestOTF", "otf", "opentype", "smpl", "c");
addElement(insertionPoint, "FontFeaturesTestOTF", "otf", "opentype", "trad", "d");
addElement(insertionPoint, "FontFeaturesTestOTF", "otf", "opentype", "fwid", "e");
addElement(insertionPoint, "FontFeaturesTestOTF", "otf", "opentype", "pwid", "f");
addElement(insertionPoint, "FontFeaturesTestOTF", "otf", "opentype", "ruby", "g");
addElement(insertionPoint2, "FontFeaturesTestTTF", "ttf", "truetype", "liga", "C");
addElement(insertionPoint2, "FontFeaturesTestTTF", "ttf", "truetype", "liga", "D");
addElement(insertionPoint2, "FontFeaturesTestTTF", "ttf", "truetype", "clig", "C");
addElement(insertionPoint2, "FontFeaturesTestTTF", "ttf", "truetype", "clig", "D");
addElement(insertionPoint2, "FontFeaturesTestTTF", "ttf", "truetype", "dlig", "G");
addElement(insertionPoint2, "FontFeaturesTestTTF", "ttf", "truetype", "hlig", "I");
addElement(insertionPoint2, "FontFeaturesTestTTF", "ttf", "truetype", "calt", "L");
addElement(insertionPoint2, "FontFeaturesTestTTF", "ttf", "truetype", "subs", "O");
addElement(insertionPoint2, "FontFeaturesTestTTF", "ttf", "truetype", "sups", "P");
addElement(insertionPoint2, "FontFeaturesTestTTF", "ttf", "truetype", "smcp", "S");
addElement(insertionPoint2, "FontFeaturesTestTTF", "ttf", "truetype", "c2sc", "V");
addElement(insertionPoint2, "FontFeaturesTestTTF", "ttf", "truetype", "pcap", "T");
addElement(insertionPoint2, "FontFeaturesTestTTF", "ttf", "truetype", "c2pc", "W");
addElement(insertionPoint2, "FontFeaturesTestTTF", "ttf", "truetype", "unic", "Y");
addElement(insertionPoint2, "FontFeaturesTestTTF", "ttf", "truetype", "titl", "a");
addElement(insertionPoint2, "FontFeaturesTestTTF", "ttf", "truetype", "lnum", "c");
addElement(insertionPoint2, "FontFeaturesTestTTF", "ttf", "truetype", "onum", "d");
addElement(insertionPoint2, "FontFeaturesTestTTF", "ttf", "truetype", "pnum", "f");
addElement(insertionPoint2, "FontFeaturesTestTTF", "ttf", "truetype", "tnum", "g");
addElement(insertionPoint2, "FontFeaturesTestTTF", "ttf", "truetype", "frac", "i");
addElement(insertionPoint2, "FontFeaturesTestTTF", "ttf", "truetype", "afrc", "j");
addElement(insertionPoint2, "FontFeaturesTestTTF", "ttf", "truetype", "ordn", "Q");
addElement(insertionPoint2, "FontFeaturesTestTTF", "ttf", "truetype", "zero", "k");
addElement(insertionPoint2, "FontFeaturesTestTTF", "ttf", "truetype", "hist", "K");
addElement(insertionPoint2, "FontFeaturesTestTTF", "ttf", "truetype", "jp78", "m");
addElement(insertionPoint2, "FontFeaturesTestTTF", "ttf", "truetype", "jp83", "n");
addElement(insertionPoint2, "FontFeaturesTestTTF", "ttf", "truetype", "jp90", "o");
addElement(insertionPoint2, "FontFeaturesTestTTF", "ttf", "truetype", "jp04", "p");
addElement(insertionPoint2, "FontFeaturesTestTTF", "ttf", "truetype", "smpl", "q");
addElement(insertionPoint2, "FontFeaturesTestTTF", "ttf", "truetype", "trad", "r");
addElement(insertionPoint2, "FontFeaturesTestTTF", "ttf", "truetype", "fwid", "t");
addElement(insertionPoint2, "FontFeaturesTestTTF", "ttf", "truetype", "pwid", "u");
addElement(insertionPoint2, "FontFeaturesTestTTF", "ttf", "truetype", "ruby", "v");
</script>
</body>
</html>