Changeset 276450 in webkit


Ignore:
Timestamp:
Apr 22, 2021 11:44:49 AM (15 months ago)
Author:
Chris Lord
Message:

Implement FontFace in Workers for OffscreenCanvas
https://bugs.webkit.org/show_bug.cgi?id=224178
<rdar://problem/76529024>

Reviewed by Darin Adler.

LayoutTests/imported/w3c:

FontFace is now available for Workers, rebaseline related tests.

  • web-platform-tests/css/css-font-loading/fontfaceset-load-css-wide-keywords-expected.txt:
  • web-platform-tests/html/canvas/offscreen/text/2d.text.draw.align.center.worker-expected.txt:
  • web-platform-tests/html/canvas/offscreen/text/2d.text.draw.align.end.ltr.worker-expected.txt:
  • web-platform-tests/html/canvas/offscreen/text/2d.text.draw.align.end.rtl.worker-expected.txt:
  • web-platform-tests/html/canvas/offscreen/text/2d.text.draw.align.left.worker-expected.txt:
  • web-platform-tests/html/canvas/offscreen/text/2d.text.draw.align.right.worker-expected.txt:
  • web-platform-tests/html/canvas/offscreen/text/2d.text.draw.align.start.ltr.worker-expected.txt:
  • web-platform-tests/html/canvas/offscreen/text/2d.text.draw.align.start.rtl.worker-expected.txt:
  • web-platform-tests/html/canvas/offscreen/text/2d.text.draw.baseline.alphabetic.worker-expected.txt:
  • web-platform-tests/html/canvas/offscreen/text/2d.text.draw.baseline.bottom.worker-expected.txt:
  • web-platform-tests/html/canvas/offscreen/text/2d.text.draw.baseline.hanging.worker-expected.txt:
  • web-platform-tests/html/canvas/offscreen/text/2d.text.draw.baseline.ideographic.worker-expected.txt:
  • web-platform-tests/html/canvas/offscreen/text/2d.text.draw.baseline.middle.worker-expected.txt:
  • web-platform-tests/html/canvas/offscreen/text/2d.text.draw.baseline.top.worker-expected.txt:
  • web-platform-tests/html/canvas/offscreen/text/2d.text.draw.fill.maxWidth.bound.worker-expected.txt:
  • web-platform-tests/html/canvas/offscreen/text/2d.text.draw.fill.maxWidth.fontface.worker-expected.txt:
  • web-platform-tests/html/canvas/offscreen/text/2d.text.draw.fontface.notinpage.worker-expected.txt:
  • web-platform-tests/html/canvas/offscreen/text/2d.text.draw.fontface.repeat.worker-expected.txt:
  • web-platform-tests/html/canvas/offscreen/text/2d.text.draw.fontface.worker-expected.txt:
  • web-platform-tests/html/canvas/offscreen/text/2d.text.draw.space.basic.worker-expected.txt:
  • web-platform-tests/html/canvas/offscreen/text/2d.text.draw.space.collapse.end.worker-expected.txt:
  • web-platform-tests/html/canvas/offscreen/text/2d.text.draw.space.collapse.nonspace.worker-expected.txt:
  • web-platform-tests/html/canvas/offscreen/text/2d.text.draw.space.collapse.other.worker-expected.txt:
  • web-platform-tests/html/canvas/offscreen/text/2d.text.draw.space.collapse.space.worker-expected.txt:
  • web-platform-tests/html/canvas/offscreen/text/2d.text.draw.space.collapse.start.worker-expected.txt:
  • web-platform-tests/html/canvas/offscreen/text/2d.text.measure.actualBoundingBox.worker-expected.txt:
  • web-platform-tests/html/canvas/offscreen/text/2d.text.measure.advances.worker-expected.txt:
  • web-platform-tests/html/canvas/offscreen/text/2d.text.measure.baselines.worker-expected.txt:
  • web-platform-tests/html/canvas/offscreen/text/2d.text.measure.emHeights.worker-expected.txt:
  • web-platform-tests/html/canvas/offscreen/text/2d.text.measure.fontBoundingBox.worker-expected.txt:
  • web-platform-tests/html/canvas/offscreen/text/2d.text.measure.width.basic.worker-expected.txt:
  • web-platform-tests/html/canvas/offscreen/text/2d.text.measure.width.empty.worker-expected.txt:
  • web-platform-tests/html/canvas/offscreen/text/2d.text.measure.width.space.worker-expected.txt:

Source/WebCore:

To comply with spec and complete the OffscreenCanvas implementation,
FontFace needs to be made available on WorkerGlobalScope. This patch
makes it available and fixes crashes using it due to accessing
main-thread only singletons.

No new tests, rebaselined existing tests.

  • Headers.cmake:
  • Sources.txt:
  • WebCore.xcodeproj/project.pbxproj: Add new files WorkerFontLoadRequest.cpp, WorkerFontLoadRequest.h
  • css/CSSFontFace.cpp:

(WebCore::CSSFontFace::fontCacheFallingBackToSingleton):
(WebCore::CSSFontFace::font):

  • css/CSSFontFace.h: Use the ScriptExecutionContext's FontCache if possible when loading fonts.
  • css/CSSFontFaceSet.cpp:

(WebCore::CSSFontFaceSet::ensureLocalFontFacesForFamilyRegistered):
(WebCore::CSSFontFaceSet::matchingFacesExcludingPreinstalledFonts):

Use the correct CSSValuePool and FontCache in
ensureLocalFontFacesForFamilyRegistered. Also clarify a vaguely-named
variable.

  • css/CSSFontFaceSource.cpp:

(WebCore::CSSFontFaceSource::CSSFontFaceSource):

Use FontLoadRequest::isPending instead of making assumptions about the
request state on construction.

  • css/FontFace.cpp:

(WebCore::FontFace::create):
(WebCore::FontFace::display const):

  • css/FontFace.h:
  • css/FontFace.idl: Construct with a ScriptExecutionContext instead of a Document and make available for Workers.
  • css/FontFaceSet.idl: Expose to Workers.
  • loader/FontLoadRequest.h:

(WebCore::FontLoadRequest::isWorkerFontLoadRequest const):

Add isPending function and new type WorkerFontLoadRequest.

  • loader/cache/CachedFont.cpp:

(WebCore::CachedFont::createCustomFontData):

Use convertWOFFToSfntIfNecessary().

  • loader/cache/CachedFontLoadRequest.h: Implement FontLoadRequest::isPending.
  • platform/graphics/Font.cpp:

(WebCore::Font::create):
(WebCore::Font::Font):
(WebCore::Font::systemFallbackFontForCharacter const):

  • platform/graphics/Font.h: Add an optional FontCache parameter for use with vertical font data retrieval and add a FontCache parameter to systemFallbackFontForCharacter instead of using the singleton.
  • platform/graphics/FontCache.cpp:

(WebCore::FontCache::fontForPlatformData):

Pass FontCache parameter when creating fonts.

  • platform/graphics/FontCache.h:

(WebCore::FontCache::fontCacheFallingBackToSingleton):

  • platform/graphics/FontCascade.cpp:

(WebCore::FontCascade::update const):

  • platform/graphics/cairo/FontCairoHarfbuzzNG.cpp:

(WebCore::FontCascade::fontForCombiningCharacterSequence const):

Rename fontCacheFallbackToSingleton -> fontCacheFallingBackToSingleton

  • platform/graphics/FontCascadeFonts.cpp:

(WebCore::FontCascadeFonts::realizeFallbackRangesAt):
(WebCore::FontCascadeFonts::glyphDataForSystemFallback):

Use familyNamesData instead of familyNames and pass the FontCache
parameter when calling glyphDataForSystemFallback to make this safe
to use in a Worker.

  • platform/graphics/FontTaggedSettings.h: Add missing wtf/Hasher.h include.
  • platform/graphics/WOFFFileFormat.cpp:

(WebCore::convertWOFFToSfntIfNecessary):

  • platform/graphics/WOFFFileFormat.h: Add utility function to convert WOFF fonts on non-Cocoa platforms.
  • workers/WorkerFontLoadRequest.cpp: Added.

(WebCore::WorkerFontLoadRequest::WorkerFontLoadRequest):
(WebCore::WorkerFontLoadRequest::load):
(WebCore::WorkerFontLoadRequest::ensureCustomFontData):
(WebCore::WorkerFontLoadRequest::createFont):
(WebCore::WorkerFontLoadRequest::setClient):
(WebCore::WorkerFontLoadRequest::didReceiveResponse):
(WebCore::WorkerFontLoadRequest::didReceiveData):
(WebCore::WorkerFontLoadRequest::didFinishLoading):
(WebCore::WorkerFontLoadRequest::didFail):

  • workers/WorkerFontLoadRequest.h: Added. Implement FontLoadRequest for Workers.
  • workers/WorkerGlobalScope.cpp:

(WebCore::WorkerGlobalScope::fonts):
(WebCore::WorkerGlobalScope::fontLoadRequest):
(WebCore::WorkerGlobalScope::beginLoadingFontSoon):

  • workers/WorkerGlobalScope.h: Implement ScriptExecutionContext font-loading related functions.
  • workers/WorkerGlobalScope.idl: Include FontFaceSource.
Location:
trunk
Files:
2 added
61 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r276433 r276450  
     12021-04-22  Chris Lord  <clord@igalia.com>
     2
     3        Implement FontFace in Workers for OffscreenCanvas
     4        https://bugs.webkit.org/show_bug.cgi?id=224178
     5        <rdar://problem/76529024>
     6
     7        Reviewed by Darin Adler.
     8
     9        FontFace is now available for Workers, rebaseline related tests.
     10
     11        * web-platform-tests/css/css-font-loading/fontfaceset-load-css-wide-keywords-expected.txt:
     12        * web-platform-tests/html/canvas/offscreen/text/2d.text.draw.align.center.worker-expected.txt:
     13        * web-platform-tests/html/canvas/offscreen/text/2d.text.draw.align.end.ltr.worker-expected.txt:
     14        * web-platform-tests/html/canvas/offscreen/text/2d.text.draw.align.end.rtl.worker-expected.txt:
     15        * web-platform-tests/html/canvas/offscreen/text/2d.text.draw.align.left.worker-expected.txt:
     16        * web-platform-tests/html/canvas/offscreen/text/2d.text.draw.align.right.worker-expected.txt:
     17        * web-platform-tests/html/canvas/offscreen/text/2d.text.draw.align.start.ltr.worker-expected.txt:
     18        * web-platform-tests/html/canvas/offscreen/text/2d.text.draw.align.start.rtl.worker-expected.txt:
     19        * web-platform-tests/html/canvas/offscreen/text/2d.text.draw.baseline.alphabetic.worker-expected.txt:
     20        * web-platform-tests/html/canvas/offscreen/text/2d.text.draw.baseline.bottom.worker-expected.txt:
     21        * web-platform-tests/html/canvas/offscreen/text/2d.text.draw.baseline.hanging.worker-expected.txt:
     22        * web-platform-tests/html/canvas/offscreen/text/2d.text.draw.baseline.ideographic.worker-expected.txt:
     23        * web-platform-tests/html/canvas/offscreen/text/2d.text.draw.baseline.middle.worker-expected.txt:
     24        * web-platform-tests/html/canvas/offscreen/text/2d.text.draw.baseline.top.worker-expected.txt:
     25        * web-platform-tests/html/canvas/offscreen/text/2d.text.draw.fill.maxWidth.bound.worker-expected.txt:
     26        * web-platform-tests/html/canvas/offscreen/text/2d.text.draw.fill.maxWidth.fontface.worker-expected.txt:
     27        * web-platform-tests/html/canvas/offscreen/text/2d.text.draw.fontface.notinpage.worker-expected.txt:
     28        * web-platform-tests/html/canvas/offscreen/text/2d.text.draw.fontface.repeat.worker-expected.txt:
     29        * web-platform-tests/html/canvas/offscreen/text/2d.text.draw.fontface.worker-expected.txt:
     30        * web-platform-tests/html/canvas/offscreen/text/2d.text.draw.space.basic.worker-expected.txt:
     31        * web-platform-tests/html/canvas/offscreen/text/2d.text.draw.space.collapse.end.worker-expected.txt:
     32        * web-platform-tests/html/canvas/offscreen/text/2d.text.draw.space.collapse.nonspace.worker-expected.txt:
     33        * web-platform-tests/html/canvas/offscreen/text/2d.text.draw.space.collapse.other.worker-expected.txt:
     34        * web-platform-tests/html/canvas/offscreen/text/2d.text.draw.space.collapse.space.worker-expected.txt:
     35        * web-platform-tests/html/canvas/offscreen/text/2d.text.draw.space.collapse.start.worker-expected.txt:
     36        * web-platform-tests/html/canvas/offscreen/text/2d.text.measure.actualBoundingBox.worker-expected.txt:
     37        * web-platform-tests/html/canvas/offscreen/text/2d.text.measure.advances.worker-expected.txt:
     38        * web-platform-tests/html/canvas/offscreen/text/2d.text.measure.baselines.worker-expected.txt:
     39        * web-platform-tests/html/canvas/offscreen/text/2d.text.measure.emHeights.worker-expected.txt:
     40        * web-platform-tests/html/canvas/offscreen/text/2d.text.measure.fontBoundingBox.worker-expected.txt:
     41        * web-platform-tests/html/canvas/offscreen/text/2d.text.measure.width.basic.worker-expected.txt:
     42        * web-platform-tests/html/canvas/offscreen/text/2d.text.measure.width.empty.worker-expected.txt:
     43        * web-platform-tests/html/canvas/offscreen/text/2d.text.measure.width.space.worker-expected.txt:
     44
    1452021-04-22  Imanol Fernandez  <ifernandez@igalia.com>
    246
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-font-loading/fontfaceset-load-css-wide-keywords-expected.txt

    r267650 r276450  
    1 CONSOLE MESSAGE: TypeError: undefined is not an object (evaluating 'self.fonts.load')
    2 
    3 Harness Error (FAIL), message = TypeError: undefined is not an object (evaluating 'self.fonts.load')
    41
    52PASS Loading CSS-wide keyword "initial" causes SyntaxError (document)
     
    74PASS Loading CSS-wide keyword "unset" causes SyntaxError (document)
    85PASS Loading CSS-wide keyword "revert" causes SyntaxError (document)
    9 TIMEOUT Loading CSS-wide keyword "initial" causes SyntaxError (worker) Test timed out
    10 NOTRUN Loading CSS-wide keyword "inherit" causes SyntaxError (worker)
    11 NOTRUN Loading CSS-wide keyword "unset" causes SyntaxError (worker)
    12 NOTRUN Loading CSS-wide keyword "revert" causes SyntaxError (worker)
     6PASS Loading CSS-wide keyword "initial" causes SyntaxError (worker)
     7PASS Loading CSS-wide keyword "inherit" causes SyntaxError (worker)
     8PASS Loading CSS-wide keyword "unset" causes SyntaxError (worker)
     9PASS Loading CSS-wide keyword "revert" causes SyntaxError (worker)
    1310
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/text/2d.text.draw.align.center.worker-expected.txt

    r270102 r276450  
    11
    2 FAIL textAlign center is the center of the em squares (not the bounding box) Can't find variable: FontFace
     2PASS textAlign center is the center of the em squares (not the bounding box)
    33
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/text/2d.text.draw.align.end.ltr.worker-expected.txt

    r270102 r276450  
    11
    2 FAIL textAlign end with ltr is the right edge Can't find variable: FontFace
     2PASS textAlign end with ltr is the right edge
    33
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/text/2d.text.draw.align.end.rtl.worker-expected.txt

    r270102 r276450  
    11
    2 FAIL textAlign end with rtl is the left edge Can't find variable: FontFace
     2PASS textAlign end with rtl is the left edge
    33
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/text/2d.text.draw.align.left.worker-expected.txt

    r270102 r276450  
    11
    2 FAIL textAlign left is the left of the first em square (not the bounding box) Can't find variable: FontFace
     2PASS textAlign left is the left of the first em square (not the bounding box)
    33
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/text/2d.text.draw.align.right.worker-expected.txt

    r270102 r276450  
    11
    2 FAIL textAlign right is the right of the last em square (not the bounding box) Can't find variable: FontFace
     2PASS textAlign right is the right of the last em square (not the bounding box)
    33
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/text/2d.text.draw.align.start.ltr.worker-expected.txt

    r270102 r276450  
    11
    2 FAIL textAlign start with ltr is the left edge Can't find variable: FontFace
     2PASS textAlign start with ltr is the left edge
    33
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/text/2d.text.draw.align.start.rtl.worker-expected.txt

    r270102 r276450  
    11
    2 FAIL textAlign start with rtl is the right edge Can't find variable: FontFace
     2PASS textAlign start with rtl is the right edge
    33
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/text/2d.text.draw.baseline.alphabetic.worker-expected.txt

    r270102 r276450  
    11
    2 FAIL 2d Can't find variable: FontFace
     2PASS 2d
    33
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/text/2d.text.draw.baseline.bottom.worker-expected.txt

    r270102 r276450  
    11
    2 FAIL textBaseline bottom is the bottom of the em square (not the bounding box) Can't find variable: FontFace
     2FAIL textBaseline bottom is the bottom of the em square (not the bounding box) assert_approx_equals: Red channel of the pixel at (25, 25) expected 0 +/- 2 but got 255
    33
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/text/2d.text.draw.baseline.hanging.worker-expected.txt

    r270102 r276450  
    11
    2 FAIL 2d Can't find variable: FontFace
     2FAIL 2d assert_approx_equals: Red channel of the pixel at (5, 5) expected 0 +/- 2 but got 255
    33
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/text/2d.text.draw.baseline.ideographic.worker-expected.txt

    r270102 r276450  
    11
    2 FAIL 2d Can't find variable: FontFace
     2FAIL 2d assert_approx_equals: Red channel of the pixel at (5, 5) expected 0 +/- 2 but got 255
    33
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/text/2d.text.draw.baseline.middle.worker-expected.txt

    r270102 r276450  
    11
    2 FAIL textBaseline middle is the middle of the em square (not the bounding box) Can't find variable: FontFace
     2FAIL textBaseline middle is the middle of the em square (not the bounding box) assert_approx_equals: Red channel of the pixel at (5, 5) expected 0 +/- 2 but got 255
    33
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/text/2d.text.draw.baseline.top.worker-expected.txt

    r270102 r276450  
    11
    2 FAIL textBaseline top is the top of the em square (not the bounding box) Can't find variable: FontFace
     2FAIL textBaseline top is the top of the em square (not the bounding box) assert_approx_equals: Red channel of the pixel at (5, 5) expected 0 +/- 2 but got 255
    33
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/text/2d.text.draw.fill.maxWidth.bound.worker-expected.txt

    r270102 r276450  
    11
    2 FAIL fillText handles maxWidth based on line size, not bounding box size Can't find variable: FontFace
     2PASS fillText handles maxWidth based on line size, not bounding box size
    33
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/text/2d.text.draw.fill.maxWidth.fontface.worker-expected.txt

    r270102 r276450  
    11
    2 FAIL fillText works on @font-face fonts Can't find variable: FontFace
     2PASS fillText works on @font-face fonts
    33
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/text/2d.text.draw.fontface.notinpage.worker-expected.txt

    r270102 r276450  
    11
    2 FAIL @font-face fonts should work even if they are not used in the page Can't find variable: FontFace
     2PASS @font-face fonts should work even if they are not used in the page
    33
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/text/2d.text.draw.fontface.repeat.worker-expected.txt

    r270102 r276450  
    11
    2 FAIL Draw with the font immediately, then wait a bit until and draw again. (This crashes some version of WebKit.) Can't find variable: FontFace
     2PASS Draw with the font immediately, then wait a bit until and draw again. (This crashes some version of WebKit.)
    33
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/text/2d.text.draw.fontface.worker-expected.txt

    r270102 r276450  
    11
    2 FAIL 2d Can't find variable: FontFace
     2PASS 2d
    33
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/text/2d.text.draw.space.basic.worker-expected.txt

    r270102 r276450  
    11
    2 FAIL U+0020 is rendered the correct size (1em wide) Can't find variable: FontFace
     2PASS U+0020 is rendered the correct size (1em wide)
    33
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/text/2d.text.draw.space.collapse.end.worker-expected.txt

    r270102 r276450  
    11
    2 FAIL Space characters at the end of a line are collapsed (per CSS) Can't find variable: FontFace
     2FAIL Space characters at the end of a line are collapsed (per CSS) assert_approx_equals: Red channel of the pixel at (75, 25) expected 0 +/- 2 but got 255
    33
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/text/2d.text.draw.space.collapse.nonspace.worker-expected.txt

    r270102 r276450  
    11
    2 FAIL Non-space characters are not converted to U+0020 and collapsed Can't find variable: FontFace
     2PASS Non-space characters are not converted to U+0020 and collapsed
    33
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/text/2d.text.draw.space.collapse.other.worker-expected.txt

    r270102 r276450  
    11
    2 FAIL Space characters are converted to U+0020, and collapsed (per CSS) Can't find variable: FontFace
     2FAIL Space characters are converted to U+0020, and collapsed (per CSS) assert_approx_equals: Red channel of the pixel at (25, 25) expected 0 +/- 2 but got 255
    33
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/text/2d.text.draw.space.collapse.space.worker-expected.txt

    r270102 r276450  
    11
    2 FAIL Space characters are converted to U+0020, and collapsed (per CSS) Can't find variable: FontFace
     2FAIL Space characters are converted to U+0020, and collapsed (per CSS) assert_approx_equals: Red channel of the pixel at (25, 25) expected 0 +/- 2 but got 255
    33
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/text/2d.text.draw.space.collapse.start.worker-expected.txt

    r270102 r276450  
    11
    2 FAIL Space characters at the start of a line are collapsed (per CSS) Can't find variable: FontFace
     2FAIL Space characters at the start of a line are collapsed (per CSS) assert_approx_equals: Red channel of the pixel at (25, 25) expected 0 +/- 2 but got 255
    33
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/text/2d.text.measure.actualBoundingBox.worker-expected.txt

    r270102 r276450  
    11
    2 FAIL Testing actualBoundingBox for OffscreenCanvas Can't find variable: FontFace
     2FAIL Testing actualBoundingBox for OffscreenCanvas assert_equals: Math.abs(ctx.measureText('A').actualBoundingBoxDescent) === 0 (got 1[number], expected 0[number]) expected 0 but got 1
    33
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/text/2d.text.measure.advances.worker-expected.txt

    r270102 r276450  
    11
    2 FAIL Testing width advances for OffscreenCanvas Can't find variable: FontFace
     2FAIL Testing width advances for OffscreenCanvas undefined is not an object (evaluating 'ctx.measureText('Hello').advances[0]')
    33
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/text/2d.text.measure.baselines.worker-expected.txt

    r270102 r276450  
    11
    2 FAIL Testing baselines for OffscreenCanvas Can't find variable: FontFace
     2FAIL Testing baselines for OffscreenCanvas ctx.measureText('A').getBaselines is not a function. (In 'ctx.measureText('A').getBaselines()', 'ctx.measureText('A').getBaselines' is undefined)
    33
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/text/2d.text.measure.emHeights.worker-expected.txt

    r270102 r276450  
    11
    2 FAIL Testing emHeights for OffscreenCanvas Can't find variable: FontFace
     2FAIL Testing emHeights for OffscreenCanvas assert_equals: ctx.measureText('A').emHeightAscent === 37.5 (got 85[number], expected 37.5[number]) expected 37.5 but got 85
    33
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/text/2d.text.measure.fontBoundingBox.worker-expected.txt

    r270102 r276450  
    11
    2 FAIL Testing fontBoundingBox for OffscreenCanvas Can't find variable: FontFace
     2PASS Testing fontBoundingBox for OffscreenCanvas
    33
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/text/2d.text.measure.width.basic.worker-expected.txt

    r270102 r276450  
    11
    2 FAIL The width of character is same as font used for OffscreenCanvas Can't find variable: FontFace
     2PASS The width of character is same as font used for OffscreenCanvas
    33
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/text/2d.text.measure.width.empty.worker-expected.txt

    r270102 r276450  
    11
    2 FAIL The empty string has zero width for OffscreenCanvas Can't find variable: FontFace
     2PASS The empty string has zero width for OffscreenCanvas
    33
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/text/2d.text.measure.width.space.worker-expected.txt

    r270102 r276450  
    11
    2 FAIL Space characters are converted to U+0020 and collapsed (per CSS) for OffscreenCanvas Can't find variable: FontFace
     2FAIL Space characters are converted to U+0020 and collapsed (per CSS) for OffscreenCanvas assert_equals: ctx.measureText('A \x09\x0a\x0c\x0d  \x09\x0a\x0c\x0dB').width === 150 (got 650[number], expected 150[number]) expected 150 but got 650
    33
  • trunk/Source/WebCore/ChangeLog

    r276448 r276450  
     12021-04-22  Chris Lord  <clord@igalia.com>
     2
     3        Implement FontFace in Workers for OffscreenCanvas
     4        https://bugs.webkit.org/show_bug.cgi?id=224178
     5        <rdar://problem/76529024>
     6
     7        Reviewed by Darin Adler.
     8
     9        To comply with spec and complete the OffscreenCanvas implementation,
     10        FontFace needs to be made available on WorkerGlobalScope. This patch
     11        makes it available and fixes crashes using it due to accessing
     12        main-thread only singletons.
     13
     14        No new tests, rebaselined existing tests.
     15
     16        * Headers.cmake:
     17        * Sources.txt:
     18        * WebCore.xcodeproj/project.pbxproj:
     19          Add new files WorkerFontLoadRequest.cpp, WorkerFontLoadRequest.h
     20
     21        * css/CSSFontFace.cpp:
     22        (WebCore::CSSFontFace::fontCacheFallingBackToSingleton):
     23        (WebCore::CSSFontFace::font):
     24        * css/CSSFontFace.h:
     25          Use the ScriptExecutionContext's FontCache if possible when loading fonts.
     26
     27        * css/CSSFontFaceSet.cpp:
     28        (WebCore::CSSFontFaceSet::ensureLocalFontFacesForFamilyRegistered):
     29        (WebCore::CSSFontFaceSet::matchingFacesExcludingPreinstalledFonts):
     30          Use the correct CSSValuePool and FontCache in
     31          ensureLocalFontFacesForFamilyRegistered. Also clarify a vaguely-named
     32          variable.
     33
     34        * css/CSSFontFaceSource.cpp:
     35        (WebCore::CSSFontFaceSource::CSSFontFaceSource):
     36          Use FontLoadRequest::isPending instead of making assumptions about the
     37          request state on construction.
     38
     39        * css/FontFace.cpp:
     40        (WebCore::FontFace::create):
     41        (WebCore::FontFace::display const):
     42        * css/FontFace.h:
     43        * css/FontFace.idl:
     44          Construct with a ScriptExecutionContext instead of a Document and
     45          make available for Workers.
     46
     47        * css/FontFaceSet.idl:
     48          Expose to Workers.
     49
     50        * loader/FontLoadRequest.h:
     51        (WebCore::FontLoadRequest::isWorkerFontLoadRequest const):
     52          Add isPending function and new type WorkerFontLoadRequest.
     53
     54        * loader/cache/CachedFont.cpp:
     55        (WebCore::CachedFont::createCustomFontData):
     56          Use convertWOFFToSfntIfNecessary().
     57
     58        * loader/cache/CachedFontLoadRequest.h:
     59          Implement FontLoadRequest::isPending.
     60
     61        * platform/graphics/Font.cpp:
     62        (WebCore::Font::create):
     63        (WebCore::Font::Font):
     64        (WebCore::Font::systemFallbackFontForCharacter const):
     65        * platform/graphics/Font.h:
     66          Add an optional FontCache parameter for use with vertical font data
     67          retrieval and add a FontCache parameter to
     68          systemFallbackFontForCharacter instead of using the singleton.
     69
     70        * platform/graphics/FontCache.cpp:
     71        (WebCore::FontCache::fontForPlatformData):
     72          Pass FontCache parameter when creating fonts.
     73
     74        * platform/graphics/FontCache.h:
     75        (WebCore::FontCache::fontCacheFallingBackToSingleton):
     76        * platform/graphics/FontCascade.cpp:
     77        (WebCore::FontCascade::update const):
     78        * platform/graphics/cairo/FontCairoHarfbuzzNG.cpp:
     79        (WebCore::FontCascade::fontForCombiningCharacterSequence const):
     80          Rename fontCacheFallbackToSingleton -> fontCacheFallingBackToSingleton
     81
     82        * platform/graphics/FontCascadeFonts.cpp:
     83        (WebCore::FontCascadeFonts::realizeFallbackRangesAt):
     84        (WebCore::FontCascadeFonts::glyphDataForSystemFallback):
     85          Use familyNamesData instead of familyNames and pass the FontCache
     86          parameter when calling glyphDataForSystemFallback to make this safe
     87          to use in a Worker.
     88
     89        * platform/graphics/FontTaggedSettings.h:
     90          Add missing wtf/Hasher.h include.
     91
     92        * platform/graphics/WOFFFileFormat.cpp:
     93        (WebCore::convertWOFFToSfntIfNecessary):
     94        * platform/graphics/WOFFFileFormat.h:
     95          Add utility function to convert WOFF fonts on non-Cocoa platforms.
     96
     97        * workers/WorkerFontLoadRequest.cpp: Added.
     98        (WebCore::WorkerFontLoadRequest::WorkerFontLoadRequest):
     99        (WebCore::WorkerFontLoadRequest::load):
     100        (WebCore::WorkerFontLoadRequest::ensureCustomFontData):
     101        (WebCore::WorkerFontLoadRequest::createFont):
     102        (WebCore::WorkerFontLoadRequest::setClient):
     103        (WebCore::WorkerFontLoadRequest::didReceiveResponse):
     104        (WebCore::WorkerFontLoadRequest::didReceiveData):
     105        (WebCore::WorkerFontLoadRequest::didFinishLoading):
     106        (WebCore::WorkerFontLoadRequest::didFail):
     107        * workers/WorkerFontLoadRequest.h: Added.
     108          Implement FontLoadRequest for Workers.
     109
     110        * workers/WorkerGlobalScope.cpp:
     111        (WebCore::WorkerGlobalScope::fonts):
     112        (WebCore::WorkerGlobalScope::fontLoadRequest):
     113        (WebCore::WorkerGlobalScope::beginLoadingFontSoon):
     114        * workers/WorkerGlobalScope.h:
     115          Implement ScriptExecutionContext font-loading related functions.
     116
     117        * workers/WorkerGlobalScope.idl:
     118          Include FontFaceSource.
     119
    11202021-04-22  Martin Robinson  <mrobinson@webkit.org>
    2121
  • trunk/Source/WebCore/Headers.cmake

    r276448 r276450  
    16581658    workers/WorkerAnimationController.h
    16591659    workers/WorkerDebuggerProxy.h
     1660    workers/WorkerFontLoadRequest.h
    16601661    workers/WorkerLoaderProxy.h
    16611662    workers/WorkerOrWorkletThread.h
  • trunk/Source/WebCore/Sources.txt

    r276433 r276450  
    26572657workers/WorkerConsoleClient.cpp
    26582658workers/WorkerEventLoop.cpp
     2659workers/WorkerFontLoadRequest.cpp
    26592660workers/WorkerGlobalScope.cpp
    26602661workers/WorkerInspectorProxy.cpp
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r276433 r276450  
    34373437                A7D20F63107F406900A80392 /* JSWebGLActiveInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = A7D20F61107F406900A80392 /* JSWebGLActiveInfo.h */; };
    34383438                A7D20F6D107F438B00A80392 /* WebGLActiveInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = A7D20F6B107F438B00A80392 /* WebGLActiveInfo.h */; };
     3439                A7D6B3490F61104500FF9FD1 /* WorkerFontLoadRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = A7D6B3470F61104500FF9FD1 /* WorkerFontLoadRequest.h */; settings = {ATTRIBUTES = (Private, ); }; };
    34393440                A7D6B3490F61104500B79FD1 /* WorkerScriptLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = A7D6B3470F61104500B79FD1 /* WorkerScriptLoader.h */; settings = {ATTRIBUTES = (Private, ); }; };
    34403441                A7DBF8DE1276919C006B6008 /* TextCheckingHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = A7DBF8DC1276919C006B6008 /* TextCheckingHelper.h */; };
     
    1285712858                A7D20F61107F406900A80392 /* JSWebGLActiveInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSWebGLActiveInfo.h; sourceTree = "<group>"; };
    1285812859                A7D20F6B107F438B00A80392 /* WebGLActiveInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebGLActiveInfo.h; sourceTree = "<group>"; };
     12860                A7D6B3470F61104500FF9FD1 /* WorkerFontLoadRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WorkerFontLoadRequest.h; sourceTree = "<group>"; };
     12861                A7D6B3480F61104500FF9FD1 /* WorkerFontLoadRequest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WorkerFontLoadRequest.cpp; sourceTree = "<group>"; };
    1285912862                A7D6B3470F61104500B79FD1 /* WorkerScriptLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WorkerScriptLoader.h; sourceTree = "<group>"; };
    1286012863                A7D6B3480F61104500B79FD1 /* WorkerScriptLoader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WorkerScriptLoader.cpp; sourceTree = "<group>"; };
     
    1942819431                                9B0ABCA323679ACF00B45085 /* WorkerEventLoop.cpp */,
    1942919432                                9B0ABCA423679ACF00B45085 /* WorkerEventLoop.h */,
     19433                                A7D6B3480F61104500FF9FD1 /* WorkerFontLoadRequest.cpp */,
     19434                                A7D6B3470F61104500FF9FD1 /* WorkerFontLoadRequest.h */,
    1943019435                                2E4346360F546A8200B0F1BA /* WorkerGlobalScope.cpp */,
    1943119436                                2E4346370F546A8200B0F1BA /* WorkerGlobalScope.h */,
     
    3584635851                                A52B349E1FA41703008B6246 /* WorkerDebuggerProxy.h in Headers */,
    3584735852                                91E0DDC4230B41F10019E1E3 /* WorkerDOMDebuggerAgent.h in Headers */,
     35853                                A7D6B3490F61104500FF9FD1 /* WorkerFontLoadRequest.h in Headers */,
    3584835854                                2E4346490F546A8200B0F1BA /* WorkerGlobalScope.h in Headers */,
    3584935855                                41D129CE1F3D0EF600D15E47 /* WorkerGlobalScopeCaches.h in Headers */,
  • trunk/Source/WebCore/css/CSSFontFace.cpp

    r275817 r276450  
    397397}
    398398
     399FontCache& CSSFontFace::fontCacheFallingBackToSingleton()
     400{
     401    if (m_wrapper && m_wrapper->scriptExecutionContext())
     402        return m_wrapper->scriptExecutionContext()->fontCache();
     403    return FontCache::singleton();
     404}
     405
    399406bool CSSFontFace::computeFailureState() const
    400407{
     
    670677        case CSSFontFaceSource::Status::Pending:
    671678        case CSSFontFaceSource::Status::Loading: {
     679            auto& fontCache = fontCacheFallingBackToSingleton();
    672680            Font::Visibility visibility = WebCore::visibility(status(), fontLoadTiming());
    673             return Font::create(FontCache::singleton().lastResortFallbackFont(fontDescription)->platformData(), Font::Origin::Local, Font::Interstitial::Yes, visibility);
     681            return Font::create(fontCache.lastResortFallbackFont(fontDescription)->platformData(), Font::Origin::Local, &fontCache, Font::Interstitial::Yes, visibility);
    674682        }
    675683        case CSSFontFaceSource::Status::Success:
  • trunk/Source/WebCore/css/CSSFontFace.h

    r273726 r276450  
    4747class CSSValue;
    4848class CSSValueList;
     49class FontCache;
    4950class FontDescription;
    5051class Font;
     
    173174
    174175    Document* document();
     176    FontCache& fontCacheFallingBackToSingleton();
    175177
    176178    RefPtr<CSSValueList> m_families;
  • trunk/Source/WebCore/css/CSSFontFaceSet.cpp

    r276295 r276450  
    113113    if (m_owningFontSelector->scriptExecutionContext())
    114114        allowUserInstalledFonts = m_owningFontSelector->scriptExecutionContext()->settingsValues().shouldAllowUserInstalledFonts ? AllowUserInstalledFonts::Yes : AllowUserInstalledFonts::No;
    115     Vector<FontSelectionCapabilities> capabilities = FontCache::singleton().getFontSelectionCapabilitiesInFamily(familyName, allowUserInstalledFonts);
     115    Vector<FontSelectionCapabilities> capabilities = m_owningFontSelector->scriptExecutionContext()->fontCache().getFontSelectionCapabilitiesInFamily(familyName, allowUserInstalledFonts);
    116116    if (capabilities.isEmpty())
    117117        return;
     
    122122       
    123123        Ref<CSSValueList> familyList = CSSValueList::createCommaSeparated();
    124         familyList->append(CSSValuePool::singleton().createFontFamilyValue(familyName));
     124        familyList->append(m_owningFontSelector->scriptExecutionContext()->cssValuePool().createFontFamilyValue(familyName));
    125125        face->setFamilies(familyList.get());
    126126        face->setFontSelectionCapabilities(item);
     
    377377    for (auto& familyRaw : font->family) {
    378378        AtomString familyAtom;
    379         WTF::switchOn(familyRaw, [&] (CSSValueID ident) {
    380             if (ident != CSSValueWebkitBody)
    381                 familyAtom = familyNamesData->at(CSSPropertyParserHelpers::genericFontFamilyIndex(ident));
     379        WTF::switchOn(familyRaw, [&] (CSSValueID familyKeyword) {
     380            if (familyKeyword != CSSValueWebkitBody)
     381                familyAtom = familyNamesData->at(CSSPropertyParserHelpers::genericFontFamilyIndex(familyKeyword));
    382382            else {
    383383                ASSERT(m_owningFontSelector && m_owningFontSelector->scriptExecutionContext());
  • trunk/Source/WebCore/css/CSSFontFaceSource.cpp

    r275817 r276450  
    8282    m_fontRequest->setClient(this);
    8383
    84     if (status() == Status::Pending && !m_fontRequest->isLoading()) {
     84    if (status() == Status::Pending && !m_fontRequest->isPending()) {
    8585        setStatus(Status::Loading);
    8686        if (!shouldIgnoreFontLoadCompletions()) {
  • trunk/Source/WebCore/css/FontFace.cpp

    r276017 r276450  
    6363}
    6464
    65 Ref<FontFace> FontFace::create(Document& document, const String& family, Source&& source, const Descriptors& descriptors)
    66 {
    67     auto result = adoptRef(*new FontFace(document.fontSelector()));
     65Ref<FontFace> FontFace::create(ScriptExecutionContext& context, const String& family, Source&& source, const Descriptors& descriptors)
     66{
     67    ASSERT(context.cssFontSelector());
     68    auto result = adoptRef(*new FontFace(*context.cssFontSelector()));
    6869    result->suspendIfNeeded();
    6970
    7071    bool dataRequiresAsynchronousLoading = true;
    7172
    72     auto setFamilyResult = result->setFamily(document, family);
     73    auto setFamilyResult = result->setFamily(context, family);
    7374    if (setFamilyResult.hasException()) {
    7475        result->setErrorState();
     
    7879    auto sourceConversionResult = WTF::switchOn(source,
    7980        [&] (String& string) -> ExceptionOr<void> {
    80             auto value = CSSPropertyParserWorkerSafe::parseFontFaceSrc(string, CSSParserContext(document));
     81            auto value = CSSPropertyParserWorkerSafe::parseFontFaceSrc(string, is<Document>(context) ? CSSParserContext(downcast<Document>(context)) : HTMLStandardMode);
    8182            if (!value)
    8283                return Exception { SyntaxError };
    83             CSSFontFace::appendSources(result->backing(), *value, &document, false);
     84            CSSFontFace::appendSources(result->backing(), *value, &context, false);
    8485            return { };
    8586        },
     
    102103
    103104    // These ternaries match the default strings inside the FontFaceDescriptors dictionary inside FontFace.idl.
    104     auto setStyleResult = result->setStyle(document, descriptors.style.isEmpty() ? "normal"_s : descriptors.style);
     105    auto setStyleResult = result->setStyle(context, descriptors.style.isEmpty() ? "normal"_s : descriptors.style);
    105106    if (setStyleResult.hasException()) {
    106107        result->setErrorState();
    107108        return result;
    108109    }
    109     auto setWeightResult = result->setWeight(document, descriptors.weight.isEmpty() ? "normal"_s : descriptors.weight);
     110    auto setWeightResult = result->setWeight(context, descriptors.weight.isEmpty() ? "normal"_s : descriptors.weight);
    110111    if (setWeightResult.hasException()) {
    111112        result->setErrorState();
    112113        return result;
    113114    }
    114     auto setStretchResult = result->setStretch(document, descriptors.stretch.isEmpty() ? "normal"_s : descriptors.stretch);
     115    auto setStretchResult = result->setStretch(context, descriptors.stretch.isEmpty() ? "normal"_s : descriptors.stretch);
    115116    if (setStretchResult.hasException()) {
    116117        result->setErrorState();
    117118        return result;
    118119    }
    119     auto setUnicodeRangeResult = result->setUnicodeRange(document, descriptors.unicodeRange.isEmpty() ? "U+0-10FFFF"_s : descriptors.unicodeRange);
     120    auto setUnicodeRangeResult = result->setUnicodeRange(context, descriptors.unicodeRange.isEmpty() ? "U+0-10FFFF"_s : descriptors.unicodeRange);
    120121    if (setUnicodeRangeResult.hasException()) {
    121122        result->setErrorState();
    122123        return result;
    123124    }
    124     auto setFeatureSettingsResult = result->setFeatureSettings(document, descriptors.featureSettings.isEmpty() ? "normal"_s : descriptors.featureSettings);
     125    auto setFeatureSettingsResult = result->setFeatureSettings(context, descriptors.featureSettings.isEmpty() ? "normal"_s : descriptors.featureSettings);
    125126    if (setFeatureSettingsResult.hasException()) {
    126127        result->setErrorState();
    127128        return result;
    128129    }
    129     auto setDisplayResult = result->setDisplay(document, descriptors.display.isEmpty() ? "auto"_s : descriptors.display);
     130    auto setDisplayResult = result->setDisplay(context, descriptors.display.isEmpty() ? "auto"_s : descriptors.display);
    130131    if (setDisplayResult.hasException()) {
    131132        result->setErrorState();
     
    400401}
    401402
    402 String FontFace::display() const
     403String FontFace::display(ScriptExecutionContext& context) const
    403404{
    404405    m_backing->updateStyleIfNeeded();
     
    406407    if (!loadingBehaviorWrapped.hasValue())
    407408        return "auto"_s;
    408     return CSSValuePool::singleton().createValue(loadingBehaviorWrapped.value())->cssText();
     409    return context.cssValuePool().createValue(loadingBehaviorWrapped.value())->cssText();
    409410}
    410411
  • trunk/Source/WebCore/css/FontFace.h

    r276017 r276450  
    5555   
    5656    using Source = Variant<String, RefPtr<JSC::ArrayBuffer>, RefPtr<JSC::ArrayBufferView>>;
    57     static Ref<FontFace> create(Document&, const String& family, Source&&, const Descriptors&);
     57    static Ref<FontFace> create(ScriptExecutionContext&, const String& family, Source&&, const Descriptors&);
    5858    static Ref<FontFace> create(ScriptExecutionContext*, CSSFontFace&);
    5959    virtual ~FontFace();
     
    7373    String unicodeRange() const;
    7474    String featureSettings() const;
    75     String display() const;
     75    String display(ScriptExecutionContext&) const;
    7676
    7777    enum class LoadStatus { Unloaded, Loading, Loaded, Error };
  • trunk/Source/WebCore/css/FontFace.idl

    r276017 r276450  
    4444[
    4545    ActiveDOMObject,
    46     Exposed=Window
     46    Exposed=(Window,Worker)
    4747] interface FontFace {
    48     [CallWith=Document] constructor(DOMString family, (DOMString or BinaryData) source, optional FontFaceDescriptors descriptors);
     48    [CallWith=ScriptExecutionContext] constructor(DOMString family, (DOMString or BinaryData) source, optional FontFaceDescriptors descriptors);
    4949
    5050    [SetterCallWith=ScriptExecutionContext] attribute DOMString family;
     
    5454    [SetterCallWith=ScriptExecutionContext] attribute DOMString unicodeRange;
    5555    [SetterCallWith=ScriptExecutionContext] attribute DOMString featureSettings;
    56     [SetterCallWith=ScriptExecutionContext] attribute DOMString display;
     56    [CallWith=ScriptExecutionContext] attribute DOMString display;
    5757
    5858    readonly attribute FontFaceLoadStatus status;
  • trunk/Source/WebCore/css/FontFaceSet.idl

    r274832 r276450  
    3131[
    3232    ActiveDOMObject,
    33     Exposed=Window
     33    Exposed=(Window,Worker)
    3434] interface FontFaceSet : EventTarget {
    3535    [CallWith=ScriptExecutionContext] constructor(sequence<FontFace> initialFaces);
  • trunk/Source/WebCore/loader/FontLoadRequest.h

    r275817 r276450  
    3636struct FontSelectionSpecifiedCapabilities;
    3737
    38 template <typename T> class FontTaggedSettings;
    39 using FontFeatureSettings = FontTaggedSettings<int>;
    40 
    4138class FontLoadRequestClient {
    4239public:
     
    5047
    5148    virtual const URL& url() const = 0;
     49    virtual bool isPending() const = 0;
    5250    virtual bool isLoading() const = 0;
    5351    virtual bool errorOccurred() const = 0;
     
    5957
    6058    virtual bool isCachedFontLoadRequest() const { return false; }
     59    virtual bool isWorkerFontLoadRequest() const { return false; }
    6160};
    6261
  • trunk/Source/WebCore/loader/cache/CachedFont.cpp

    r273094 r276450  
    105105std::unique_ptr<FontCustomPlatformData> CachedFont::createCustomFontData(SharedBuffer& bytes, const String& itemInCollection, bool& wrapping)
    106106{
    107     wrapping = true;
    108 
    109 #if !PLATFORM(COCOA)
    110     if (isWOFF(bytes)) {
    111         wrapping = false;
    112         Vector<char> convertedFont;
    113         if (!convertWOFFToSfnt(bytes, convertedFont))
    114             return nullptr;
    115 
    116         auto buffer = SharedBuffer::create(WTFMove(convertedFont));
    117         return createFontCustomPlatformData(buffer, itemInCollection);
    118     }
    119 #endif
    120 
    121     return createFontCustomPlatformData(bytes, itemInCollection);
     107    auto buffer = makeRefPtr(bytes);
     108    wrapping = !convertWOFFToSfntIfNecessary(buffer);
     109    return buffer ? createFontCustomPlatformData(*buffer, itemInCollection) : nullptr;
    122110}
    123111
  • trunk/Source/WebCore/loader/cache/CachedFontLoadRequest.h

    r276384 r276450  
    5252private:
    5353    const URL& url() const final { return m_font->url(); }
     54    bool isPending() const final { return m_font->status() == CachedResource::Status::Pending; }
    5455    bool isLoading() const final { return m_font->isLoading(); }
    5556    bool errorOccurred() const final { return m_font->errorOccurred(); }
  • trunk/Source/WebCore/platform/graphics/Font.cpp

    r275650 r276450  
    5959DEFINE_ALLOCATOR_WITH_HEAP_IDENTIFIER(Font);
    6060
    61 Ref<Font> Font::create(Ref<SharedBuffer>&& fontFaceData, Font::Origin origin, float fontSize, bool syntheticBold, bool syntheticItalic)
     61Ref<Font> Font::create(const FontPlatformData& platformData, Origin origin, Interstitial interstitial, Visibility visibility, OrientationFallback orientationFallback, Optional<RenderingResourceIdentifier> identifier)
     62{
     63    return adoptRef(*new Font(platformData, origin, interstitial, visibility, orientationFallback, identifier, nullptr));
     64}
     65
     66Ref<Font> Font::create(const FontPlatformData& platformData, Origin origin, FontCache* fontCacheForVerticalData, Interstitial interstitial, Visibility visibility, OrientationFallback orientationFallback, Optional<RenderingResourceIdentifier> identifier)
     67{
     68    return adoptRef(*new Font(platformData, origin, interstitial, visibility, orientationFallback, identifier, fontCacheForVerticalData));
     69}
     70
     71Ref<Font> Font::create(Ref<SharedBuffer>&& fontFaceData, Font::Origin origin, float fontSize, bool syntheticBold, bool syntheticItalic, FontCache* fontCacheForVerticalData)
    6272{
    6373    bool wrapping;
     
    6575    FontDescription description;
    6676    description.setComputedSize(fontSize);
    67     return Font::create(CachedFont::platformDataFromCustomData(*customFontData, description, syntheticBold, syntheticItalic, { }, { }), origin);
    68 }
    69 
    70 Font::Font(const FontPlatformData& platformData, Origin origin, Interstitial interstitial, Visibility visibility, OrientationFallback orientationFallback, Optional<RenderingResourceIdentifier> renderingResourceIdentifier)
     77    return Font::create(CachedFont::platformDataFromCustomData(*customFontData, description, syntheticBold, syntheticItalic, { }, { }), origin, fontCacheForVerticalData);
     78}
     79
     80Font::Font(const FontPlatformData& platformData, Origin origin, Interstitial interstitial, Visibility visibility, OrientationFallback orientationFallback, Optional<RenderingResourceIdentifier> renderingResourceIdentifier, FontCache* fontCacheForVerticalData)
    7181    : m_platformData(platformData)
    7282    , m_renderingResourceIdentifier(renderingResourceIdentifier)
     
    8999#if ENABLE(OPENTYPE_VERTICAL)
    90100    if (platformData.orientation() == FontOrientation::Vertical && orientationFallback == OrientationFallback::No) {
    91         m_verticalData = FontCache::singleton().verticalData(platformData);
     101        m_verticalData = fontCacheForVerticalData ? fontCacheForVerticalData->verticalData(platformData) : FontCache::singleton().verticalData(platformData);
    92102        m_hasVerticalGlyphs = m_verticalData.get() && m_verticalData->hasVerticalMetrics();
    93103    }
     104#else
     105    UNUSED_PARAM(fontCacheForVerticalData);
    94106#endif
    95107}
     
    569581}
    570582
    571 RefPtr<Font> Font::systemFallbackFontForCharacter(UChar32 character, const FontDescription& description, IsForPlatformFont isForPlatformFont) const
     583RefPtr<Font> Font::systemFallbackFontForCharacter(UChar32 character, const FontDescription& description, IsForPlatformFont isForPlatformFont, FontCache& fontCache) const
    572584{
    573585    auto fontAddResult = systemFallbackCache().add(this, CharacterFallbackMap());
     
    575587    if (!character) {
    576588        UChar codeUnit = 0;
    577         return FontCache::singleton().systemFallbackForCharacters(description, this, isForPlatformFont, FontCache::PreferColoredFont::No, &codeUnit, 1);
     589        return fontCache.systemFallbackForCharacters(description, this, isForPlatformFont, FontCache::PreferColoredFont::No, &codeUnit, 1);
    578590    }
    579591
     
    590602            codeUnitsLength = 2;
    591603        }
    592         auto font = FontCache::singleton().systemFallbackForCharacters(description, this, isForPlatformFont, FontCache::PreferColoredFont::No, codeUnits, codeUnitsLength).get();
     604        auto font = fontCache.systemFallbackForCharacters(description, this, isForPlatformFont, FontCache::PreferColoredFont::No, codeUnits, codeUnitsLength).get();
    593605        if (font)
    594606            font->m_isUsedInSystemFallbackCache = true;
  • trunk/Source/WebCore/platform/graphics/Font.h

    r275650 r276450  
    5858namespace WebCore {
    5959
     60class FontCache;
    6061class GlyphPage;
    6162class FontDescription;
     
    9394        No
    9495    };
    95     static Ref<Font> create(const FontPlatformData& platformData, Origin origin = Origin::Local, Interstitial interstitial = Interstitial::No,
    96         Visibility visibility = Visibility::Visible, OrientationFallback orientationFallback = OrientationFallback::No, Optional<RenderingResourceIdentifier> identifier = WTF::nullopt)
    97     {
    98         return adoptRef(*new Font(platformData, origin, interstitial, visibility, orientationFallback, identifier));
    99     }
    100     WEBCORE_EXPORT static Ref<Font> create(Ref<SharedBuffer>&& fontFaceData, Font::Origin, float fontSize, bool syntheticBold, bool syntheticItalic);
     96    WEBCORE_EXPORT static Ref<Font> create(const FontPlatformData&, Origin = Origin::Local, Interstitial = Interstitial::No,
     97        Visibility = Visibility::Visible, OrientationFallback = OrientationFallback::No, Optional<RenderingResourceIdentifier> = WTF::nullopt);
     98    static Ref<Font> create(const FontPlatformData&, Origin, FontCache* fontCacheForVerticalData, Interstitial = Interstitial::No,
     99        Visibility = Visibility::Visible, OrientationFallback = OrientationFallback::No, Optional<RenderingResourceIdentifier> = WTF::nullopt);
     100    WEBCORE_EXPORT static Ref<Font> create(Ref<SharedBuffer>&& fontFaceData, Font::Origin, float fontSize, bool syntheticBold, bool syntheticItalic, FontCache* = nullptr);
    101101
    102102    WEBCORE_EXPORT ~Font();
     
    190190    bool platformSupportsCodePoint(UChar32, Optional<UChar32> variation = WTF::nullopt) const;
    191191
    192     RefPtr<Font> systemFallbackFontForCharacter(UChar32, const FontDescription&, IsForPlatformFont) const;
     192    RefPtr<Font> systemFallbackFontForCharacter(UChar32, const FontDescription&, IsForPlatformFont, FontCache&) const;
    193193
    194194    const GlyphPage* glyphPage(unsigned pageNumber) const;
     
    233233
    234234private:
    235     WEBCORE_EXPORT Font(const FontPlatformData&, Origin, Interstitial, Visibility, OrientationFallback, Optional<RenderingResourceIdentifier>);
     235    WEBCORE_EXPORT Font(const FontPlatformData&, Origin, Interstitial, Visibility, OrientationFallback, Optional<RenderingResourceIdentifier>, FontCache*);
    236236
    237237    void platformInit();
  • trunk/Source/WebCore/platform/graphics/FontCache.cpp

    r275650 r276450  
    281281
    282282    auto addResult = m_fontDataCaches->data.ensure(platformData, [&] {
    283         return Font::create(platformData);
     283        return Font::create(platformData, Font::Origin::Local, this);
    284284    });
    285285
  • trunk/Source/WebCore/platform/graphics/FontCache.h

    r275650 r276450  
    221221    static Ref<FontCache> create();
    222222    WEBCORE_EXPORT static FontCache& singleton();
    223     static FontCache& fontCacheFallbackToSingleton(RefPtr<FontSelector>);
     223    static FontCache& fontCacheFallingBackToSingleton(RefPtr<FontSelector>);
    224224
    225225    ~FontCache();
     
    379379}
    380380
    381 inline FontCache& FontCache::fontCacheFallbackToSingleton(RefPtr<FontSelector> fontSelector)
     381inline FontCache& FontCache::fontCacheFallingBackToSingleton(RefPtr<FontSelector> fontSelector)
    382382{
    383383    return fontSelector ? fontSelector->fontCache() : FontCache::singleton();
  • trunk/Source/WebCore/platform/graphics/FontCascade.cpp

    r275639 r276450  
    171171void FontCascade::update(RefPtr<FontSelector>&& fontSelector) const
    172172{
    173     FontCache::fontCacheFallbackToSingleton(fontSelector).updateFontCascade(*this, WTFMove(fontSelector));
     173    FontCache::fontCacheFallingBackToSingleton(fontSelector).updateFontCascade(*this, WTFMove(fontSelector));
    174174}
    175175
  • trunk/Source/WebCore/platform/graphics/FontCascadeFonts.cpp

    r275420 r276450  
    103103    , m_fontSelector(fontSelector)
    104104    , m_fontSelectorVersion(m_fontSelector ? m_fontSelector->version() : 0)
    105     , m_generation(FontCache::fontCacheFallbackToSingleton(m_fontSelector).generation())
     105    , m_generation(FontCache::fontCacheFallingBackToSingleton(m_fontSelector).generation())
    106106{
    107107#if ASSERT_ENABLED
     
    145145    ASSERT(index < description.effectiveFamilyCount());
    146146
    147     auto& fontCache = FontCache::fontCacheFallbackToSingleton(fontSelector);
     147    auto& fontCache = FontCache::fontCacheFallingBackToSingleton(fontSelector);
    148148    while (index < description.effectiveFamilyCount()) {
    149149        auto visitor = WTF::makeVisitor([&](const AtomString& family) -> FontRanges {
     
    182182
    183183    ASSERT(index == m_realizedFallbackRanges.size());
    184     ASSERT(FontCache::fontCacheFallbackToSingleton(m_fontSelector).generation() == m_generation);
     184    ASSERT(FontCache::fontCacheFallingBackToSingleton(m_fontSelector).generation() == m_generation);
    185185
    186186    m_realizedFallbackRanges.append(FontRanges());
     
    190190        fontRanges = realizeNextFallback(description, m_lastRealizedFallbackIndex, m_fontSelector.get());
    191191        if (fontRanges.isNull() && m_fontSelector)
    192             fontRanges = m_fontSelector->fontRangesForFamily(description, standardFamily);
     192            fontRanges = m_fontSelector->fontRangesForFamily(description, familyNamesData->at(FamilyNamesIndex::StandardFamily));
    193193        if (fontRanges.isNull())
    194             fontRanges = FontRanges(FontCache::fontCacheFallbackToSingleton(m_fontSelector).lastResortFallbackFont(description));
     194            fontRanges = FontRanges(FontCache::fontCacheFallingBackToSingleton(m_fontSelector).lastResortFallbackFont(description));
    195195        return fontRanges;
    196196    }
     
    352352        font = &realizeFallbackRangesAt(description, 0).fontForFirstRange();
    353353
    354     auto systemFallbackFont = font->systemFallbackFontForCharacter(character, description, m_isForPlatformFont ? IsForPlatformFont::Yes : IsForPlatformFont::No);
     354    auto systemFallbackFont = font->systemFallbackFontForCharacter(character, description, m_isForPlatformFont ? IsForPlatformFont::Yes : IsForPlatformFont::No, FontCache::fontCacheFallingBackToSingleton(m_fontSelector));
    355355    if (!systemFallbackFont)
    356356        return GlyphData();
  • trunk/Source/WebCore/platform/graphics/WOFFFileFormat.cpp

    r222960 r276450  
    283283    return sfnt.size() == totalSfntSize;
    284284}
    285    
     285
     286bool convertWOFFToSfntIfNecessary(RefPtr<SharedBuffer>& buffer)
     287{
     288#if PLATFORM(COCOA)
     289    UNUSED_PARAM(buffer);
     290    return false;
     291#else
     292    if (!buffer || !isWOFF(*buffer))
     293        return false;
     294
     295    Vector<char> convertedFont;
     296    if (convertWOFFToSfnt(*buffer, convertedFont))
     297        buffer = SharedBuffer::create(WTFMove(convertedFont));
     298    else
     299        buffer = nullptr;
     300
     301    return true;
     302#endif
     303}
     304
    286305} // namespace WebCore
  • trunk/Source/WebCore/platform/graphics/WOFFFileFormat.h

    r222113 r276450  
    4040bool convertWOFFToSfnt(SharedBuffer& woff, Vector<char>& sfnt);
    4141
     42// If the given buffer is a WOFF file and the current platform has no native support for WOFF
     43// fonts, convert it to sfnt. Returns true if the given buffer was converted. If conversion fails,
     44// the buffer will be set to nullptr.
     45bool convertWOFFToSfntIfNecessary(RefPtr<SharedBuffer>&);
     46
    4247} // namespace WebCore
    4348
  • trunk/Source/WebCore/platform/graphics/cairo/FontCairoHarfbuzzNG.cpp

    r275420 r276450  
    139139    }
    140140
    141     if (auto systemFallback = FontCache::fontCacheFallbackToSingleton(fontSelector()).systemFallbackForCharacters(m_fontDescription, baseFont, IsForPlatformFont::No, preferColoredFont ? FontCache::PreferColoredFont::Yes : FontCache::PreferColoredFont::No, characters, length)) {
     141    if (auto systemFallback = FontCache::fontCacheFallingBackToSingleton(fontSelector()).systemFallbackForCharacters(m_fontDescription, baseFont, IsForPlatformFont::No, preferColoredFont ? FontCache::PreferColoredFont::Yes : FontCache::PreferColoredFont::No, characters, length)) {
    142142        if (systemFallback->canRenderCombiningCharacterSequence(characters, length) && (!preferColoredFont || systemFallback->platformData().isColorBitmapFont()))
    143143            return systemFallback.get();
  • trunk/Source/WebCore/workers/WorkerGlobalScope.cpp

    r275817 r276450  
    3535#include "Crypto.h"
    3636#include "FontCache.h"
     37#include "FontFaceSet.h"
    3738#include "IDBConnectionProxy.h"
    3839#include "ImageBitmapOptions.h"
     
    4647#include "ServiceWorkerGlobalScope.h"
    4748#include "SocketProvider.h"
     49#include "WorkerFontLoadRequest.h"
    4850#include "WorkerLoaderProxy.h"
    4951#include "WorkerLocation.h"
     
    522524}
    523525
     526Ref<FontFaceSet> WorkerGlobalScope::fonts()
     527{
     528    ASSERT(cssFontSelector());
     529    return cssFontSelector()->fontFaceSet();
     530}
     531
     532std::unique_ptr<FontLoadRequest> WorkerGlobalScope::fontLoadRequest(String& url, bool, bool, LoadedFromOpaqueSource loadedFromOpaqueSource)
     533{
     534    return makeUnique<WorkerFontLoadRequest>(completeURL(url), loadedFromOpaqueSource);
     535}
     536
     537void WorkerGlobalScope::beginLoadingFontSoon(FontLoadRequest& request)
     538{
     539    ASSERT(is<WorkerFontLoadRequest>(request));
     540    downcast<WorkerFontLoadRequest>(request).load(*this);
     541}
     542
    524543ReferrerPolicy WorkerGlobalScope::referrerPolicy() const
    525544{
  • trunk/Source/WebCore/workers/WorkerGlobalScope.h

    r276017 r276450  
    5252class ContentSecurityPolicyResponseHeaders;
    5353class Crypto;
     54class FontFaceSet;
    5455class Performance;
    5556class ScheduledAction;
     
    125126    CSSFontSelector* cssFontSelector() final;
    126127    FontCache& fontCache() final;
     128    Ref<FontFaceSet> fonts();
     129    std::unique_ptr<FontLoadRequest> fontLoadRequest(String& url, bool isSVG, bool isInitiatingElementInUserAgentShadowTree, LoadedFromOpaqueSource) final;
     130    void beginLoadingFontSoon(FontLoadRequest&) final;
    127131
    128132    ReferrerPolicy referrerPolicy() const final;
  • trunk/Source/WebCore/workers/WorkerGlobalScope.idl

    r274832 r276450  
    4949
    5050WorkerGlobalScope includes WindowOrWorkerGlobalScope;
     51WorkerGlobalScope includes FontFaceSource;
Note: See TracChangeset for help on using the changeset viewer.