Update CSSFontSelector's matching algorithm to understand ranges
authormmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 5 Mar 2017 20:14:02 +0000 (20:14 +0000)
committermmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 5 Mar 2017 20:14:02 +0000 (20:14 +0000)
commitc3ecb912a38ac339e573e55219724ac844ce933a
tree2229d1b57b65b41d0b2e54eb82cabdfa2cf65ca5
parent05dabe26a3083464a2b4e57faa75b81c898f7afd
Update CSSFontSelector's matching algorithm to understand ranges
https://bugs.webkit.org/show_bug.cgi?id=168892

Reviewed by Jon Lee.

Source/WebCore:

This patch migrates the font selection algorithm out of FontCacheCoreText and into its own file which can be shared
among all ports. It then migrates our web font selection algorithm to use it.

This patch doesn't actually change the parsing rules; it just changes the internal machinery for how fonts get
selected. Therefore, this patch simply makes zero-length ranges from the discrete values the parser emits, and passes
those zero-length ranges to the range-based font selection routine. This means that this patch doesn't actually
change the results of the font selection algorithm.

One of the inputs to the new font selection algorithm is font-stretch, which previously was not parsed inside
@font-face blocks or the CSS Font Loading API. This patch therefore adds parsing support and modifies the existing
tests for these pieces to expect parsing to work. Because the font selection algorithm itself is shared between
installed fonts and webfonts, this patch doesn't add any additional tests for it (because it is already covered under
existing tests).

No new tests because there is no behavior change.

* CMakeLists.txt:
* WebCore.xcodeproj/project.pbxproj: Add new file for the font selection algorithm.
* css/CSSFontFace.cpp:
(WebCore::CSSFontFace::calculateStretch): Used on @font-face blocks and the CSS Font Loading API.
(WebCore::CSSFontFace::setStretch): Fill out the previously stubbed function.
* css/CSSFontFace.h: Add the range member variable to CSSFontFaces.
* css/CSSFontFaceSet.cpp:
(WebCore::CSSFontFaceSet::ensureLocalFontFacesForFamilyRegistered): Now that we care about font-stretch, we need to
look it up for local fonts too. This current approach of an extra FontSelectionValue hanging around with a
FontTraitsMask is very ugly and will be removed soon (https://bugs.webkit.org/show_bug.cgi?id=168889 and
https://bugs.webkit.org/show_bug.cgi?id=168890).
(WebCore::computeFontStretch): Used on @font-face blocks and the CSS Font Loading API.
(WebCore::CSSFontFaceSet::matchingFaces): Educate about font-stretch.
(WebCore::CSSFontFaceSet::fontFace): Migrate to the new font-selection algorithm.
(WebCore::fontFaceComparator): Deleted.
* css/CSSFontFaceSet.h:
* css/CSSFontSelector.cpp:
(WebCore::CSSFontSelector::addFontFaceRule): Educate about font-stretch.
(WebCore::CSSFontSelector::fontRangesForFamily): Ditto.
* css/FontFace.cpp:
(WebCore::FontFace::setStretch): Ditto.
(WebCore::FontFace::stretch): Ditto.
* css/parser/CSSPropertyParser.cpp:
(WebCore::CSSPropertyParser::parseFontFaceDescriptor): Ditto.
* platform/graphics/FontCache.h: Ditto.
* platform/graphics/FontDescription.h:
* platform/graphics/FontSelectionAlgorithm.cpp: Added.
(WebCore::FontSelectionAlgorithm::filterCapability):
(WebCore::FontSelectionAlgorithm::indexOfBestCapabilities):
(WebCore::fontSelectionRequestForTraitsMask):
(WebCore::initialFontSelectionCapabilitiesForTraitsMask):
(WebCore::fontSelectionCapabilitiesForTraitsMask):
* platform/graphics/FontSelectionAlgorithm.h: Added. Taken from FontCacheCoreText.cpp.
(WebCore::FontSelectionValue::FontSelectionValue):
(WebCore::FontSelectionValue::operator float):
(WebCore::FontSelectionValue::rawValue):
(WebCore::FontSelectionValue::maximumValue):
(WebCore::FontSelectionValue::minimumValue):
(WebCore::FontSelectionValue::operator+):
(WebCore::FontSelectionValue::operator-):
(WebCore::FontSelectionValue::operator*):
(WebCore::FontSelectionValue::operator/):
(WebCore::FontSelectionValue::operator==):
(WebCore::FontSelectionValue::operator!=):
(WebCore::FontSelectionValue::operator<):
(WebCore::FontSelectionValue::operator<=):
(WebCore::FontSelectionValue::operator>):
(WebCore::FontSelectionValue::operator>=):
(WebCore::FontSelectionRange::isValid):
(WebCore::FontSelectionRange::expand):
(WebCore::FontSelectionRange::includes):
(WebCore::FontSelectionRequest::operator==):
(WebCore::FontSelectionRequest::operator!=):
(WebCore::FontSelectionRequestKey::FontSelectionRequestKey):
(WebCore::FontSelectionRequestKey::isHashTableDeletedValue):
(WebCore::FontSelectionRequestKey::operator==):
(WebCore::FontSelectionRequestKeyHash::hash):
(WebCore::FontSelectionRequestKeyHash::equal):
(WebCore::FontSelectionCapabilities::expand):
(WebCore::FontSelectionAlgorithm::FontSelectionAlgorithm):
(WebCore::FontSelectionAlgorithm::iterateActiveCapabilitiesWithReturn):
(WebCore::FontSelectionAlgorithm::iterateActiveCapabilities):
* platform/graphics/cocoa/FontCacheCoreText.cpp: Moved to FontSelectionAlgorithm.
(WebCore::stretchFromCoreTextTraits):
(WebCore::FontDatabase::capabilitiesForFontDescriptor):
(WebCore::findClosestFont):
(WebCore::calculateFontSelectionRequest):
(WebCore::platformFontLookupWithFamily):
(WebCore::FontCache::getTraitsInFamily): Deleted.
(WebCore::iterateActiveFontsWithReturn): Deleted.
(WebCore::iterateActiveFonts): Deleted.
(WebCore::findClosestStretch): Deleted.
(WebCore::filterStretch): Deleted.
(WebCore::findClosestStyle): Deleted.
(WebCore::filterStyle): Deleted.
(WebCore::findClosestWeight): Deleted.
(WebCore::filterWeight): Deleted.
(WebCore::computeTargetWeight): Deleted.
* platform/text/TextFlags.h: Moved to FontSelectionAlgorithm.
(WebCore::FontSelectionValue::FontSelectionValue): Deleted.
(WebCore::FontSelectionValue::operator float): Deleted.
(WebCore::FontSelectionValue::operator+): Deleted.
(WebCore::FontSelectionValue::operator-): Deleted.
(WebCore::FontSelectionValue::operator*): Deleted.
(WebCore::FontSelectionValue::operator/): Deleted.
(WebCore::FontSelectionValue::operator==): Deleted.
(WebCore::FontSelectionValue::operator!=): Deleted.
(WebCore::FontSelectionValue::operator<): Deleted.
(WebCore::FontSelectionValue::operator<=): Deleted.
(WebCore::FontSelectionValue::operator>): Deleted.
(WebCore::FontSelectionValue::operator>=): Deleted.
(WebCore::FontSelectionValue::rawValue): Deleted.
(WebCore::FontSelectionValue::maximumValue): Deleted.
(WebCore::FontSelectionValue::minimumValue): Deleted.
(WebCore::FontSelectionRange::isValid): Deleted.
(WebCore::FontSelectionRange::expand): Deleted.
(WebCore::FontSelectionRange::includes): Deleted.
(WebCore::FontSelectionCapabilities::expand): Deleted.

LayoutTests:

Update CSS Font Loading API test to accept font-stretch values.

* fast/text/font-face-javascript-expected.txt:
* fast/text/font-face-javascript.html:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@213436 268f45cc-cd09-0410-ab3c-d52691b4dbfc
21 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/text/font-face-javascript-expected.txt
LayoutTests/fast/text/font-face-javascript.html
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/css/CSSFontFace.cpp
Source/WebCore/css/CSSFontFace.h
Source/WebCore/css/CSSFontFaceSet.cpp
Source/WebCore/css/CSSFontFaceSet.h
Source/WebCore/css/CSSFontSelector.cpp
Source/WebCore/css/FontFace.cpp
Source/WebCore/css/parser/CSSPropertyParser.cpp
Source/WebCore/platform/graphics/FontCache.h
Source/WebCore/platform/graphics/FontDescription.h
Source/WebCore/platform/graphics/FontSelectionAlgorithm.cpp [new file with mode: 0644]
Source/WebCore/platform/graphics/FontSelectionAlgorithm.h [new file with mode: 0644]
Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp
Source/WebCore/platform/graphics/freetype/FontCacheFreeType.cpp
Source/WebCore/platform/graphics/win/FontCacheWin.cpp
Source/WebCore/platform/text/TextFlags.h