Title: [273964] trunk
Revision
273964
Author
[email protected]
Date
2021-03-05 07:05:07 -0800 (Fri, 05 Mar 2021)

Log Message

Allow CSS font-styling for canvas without RenderStyle
https://bugs.webkit.org/show_bug.cgi?id=222665

Reviewed by Darin Adler.

LayoutTests/imported/w3c:

* web-platform-tests/html/canvas/element/drawing-text-to-the-canvas/2d.text.draw.fontface.notinpage-expected.txt: Now passes

Source/WebCore:

Refactor CSSPrimitiveValue::computeNonCalcLengthDouble to allow for
its use without requiring CSSToLengthConversionData and RenderStyle.

No new tests, already covered by existing tests.

* css/CSSPrimitiveValue.cpp:
(WebCore::CSSPrimitiveValue::computeUnzoomedNonCalcLengthDouble):
(WebCore::CSSPrimitiveValue::computeNonCalcLengthDouble):
* css/CSSPrimitiveValue.h:
* css/CSSToLengthConversionData.h:
(WebCore::CSSToLengthConversionData::propertyToCompute const):
(WebCore::CSSToLengthConversionData::renderView const):
* html/canvas/CanvasRenderingContext2D.cpp:
(WebCore::CanvasRenderingContext2D::setFont):
* html/canvas/CanvasRenderingContext2DBase.cpp:
(WebCore::CanvasRenderingContext2DBase::FontProxy::initialize):
* html/canvas/CanvasRenderingContext2DBase.h:
* html/canvas/OffscreenCanvasRenderingContext2D.cpp:
(WebCore::OffscreenCanvasRenderingContext2D::setFont):
* style/StyleFontSizeFunctions.cpp:
(WebCore::Style::computedFontSizeFromSpecifiedSize):
(WebCore::Style::computedFontSizeFromSpecifiedSizeForSVGInlineText):
(WebCore::Style::fontSizeForKeyword):
* style/StyleFontSizeFunctions.h:
* style/StyleResolveForFontRaw.cpp:
(WebCore::Style::resolveForFontRaw):
* style/StyleResolveForFontRaw.h:

Modified Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (273963 => 273964)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2021-03-05 13:15:25 UTC (rev 273963)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2021-03-05 15:05:07 UTC (rev 273964)
@@ -1,3 +1,12 @@
+2021-03-05  Chris Lord  <[email protected]>
+
+        Allow CSS font-styling for canvas without RenderStyle
+        https://bugs.webkit.org/show_bug.cgi?id=222665
+
+        Reviewed by Darin Adler.
+
+        * web-platform-tests/html/canvas/element/drawing-text-to-the-canvas/2d.text.draw.fontface.notinpage-expected.txt: Now passes
+
 2021-03-05  Imanol Fernandez  <[email protected]>
 
         XRFrame getViewerPose has emulatedPosition set properly

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/drawing-text-to-the-canvas/2d.text.draw.fontface.notinpage-expected.txt (273963 => 273964)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/drawing-text-to-the-canvas/2d.text.draw.fontface.notinpage-expected.txt	2021-03-05 13:15:25 UTC (rev 273963)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/drawing-text-to-the-canvas/2d.text.draw.fontface.notinpage-expected.txt	2021-03-05 15:05:07 UTC (rev 273964)
@@ -4,5 +4,5 @@
 Expected output:
 
 
-FAIL @font-face fonts should work even if they are not used in the page assert_approx_equals: Red channel of the pixel at (5, 5) expected 0 +/- 2 but got 255
+PASS @font-face fonts should work even if they are not used in the page
 

Modified: trunk/Source/WebCore/ChangeLog (273963 => 273964)


--- trunk/Source/WebCore/ChangeLog	2021-03-05 13:15:25 UTC (rev 273963)
+++ trunk/Source/WebCore/ChangeLog	2021-03-05 15:05:07 UTC (rev 273964)
@@ -1,3 +1,38 @@
+2021-03-05  Chris Lord  <[email protected]>
+
+        Allow CSS font-styling for canvas without RenderStyle
+        https://bugs.webkit.org/show_bug.cgi?id=222665
+
+        Reviewed by Darin Adler.
+
+        Refactor CSSPrimitiveValue::computeNonCalcLengthDouble to allow for
+        its use without requiring CSSToLengthConversionData and RenderStyle.
+
+        No new tests, already covered by existing tests.
+
+        * css/CSSPrimitiveValue.cpp:
+        (WebCore::CSSPrimitiveValue::computeUnzoomedNonCalcLengthDouble):
+        (WebCore::CSSPrimitiveValue::computeNonCalcLengthDouble):
+        * css/CSSPrimitiveValue.h:
+        * css/CSSToLengthConversionData.h:
+        (WebCore::CSSToLengthConversionData::propertyToCompute const):
+        (WebCore::CSSToLengthConversionData::renderView const):
+        * html/canvas/CanvasRenderingContext2D.cpp:
+        (WebCore::CanvasRenderingContext2D::setFont):
+        * html/canvas/CanvasRenderingContext2DBase.cpp:
+        (WebCore::CanvasRenderingContext2DBase::FontProxy::initialize):
+        * html/canvas/CanvasRenderingContext2DBase.h:
+        * html/canvas/OffscreenCanvasRenderingContext2D.cpp:
+        (WebCore::OffscreenCanvasRenderingContext2D::setFont):
+        * style/StyleFontSizeFunctions.cpp:
+        (WebCore::Style::computedFontSizeFromSpecifiedSize):
+        (WebCore::Style::computedFontSizeFromSpecifiedSizeForSVGInlineText):
+        (WebCore::Style::fontSizeForKeyword):
+        * style/StyleFontSizeFunctions.h:
+        * style/StyleResolveForFontRaw.cpp:
+        (WebCore::Style::resolveForFontRaw):
+        * style/StyleResolveForFontRaw.h:
+
 2021-03-05  Imanol Fernandez  <[email protected]>
 
         XRFrame getViewerPose has emulatedPosition set properly

Modified: trunk/Source/WebCore/css/CSSPrimitiveValue.cpp (273963 => 273964)


--- trunk/Source/WebCore/css/CSSPrimitiveValue.cpp	2021-03-05 13:15:25 UTC (rev 273963)
+++ trunk/Source/WebCore/css/CSSPrimitiveValue.cpp	2021-03-05 15:05:07 UTC (rev 273964)
@@ -40,6 +40,7 @@
 #include "Pair.h"
 #include "Rect.h"
 #include "RenderStyle.h"
+#include "RenderView.h"
 #include <wtf/NeverDestroyed.h>
 #include <wtf/StdLibExtras.h>
 #include <wtf/text/StringBuilder.h>
@@ -583,96 +584,139 @@
 static constexpr double cmPerInch = 2.54;
 static constexpr double QPerInch = 25.4 * 4.0;
 
+double CSSPrimitiveValue::computeUnzoomedNonCalcLengthDouble(CSSUnitType primitiveType, double value, CSSPropertyID propertyToCompute, const FontMetrics* fontMetrics, const FontCascadeDescription* fontDescription, const FontCascadeDescription* rootFontDescription, const RenderView* renderView)
+{
+    switch (primitiveType) {
+    case CSSUnitType::CSS_EMS:
+    case CSSUnitType::CSS_QUIRKY_EMS:
+        ASSERT(fontDescription);
+        return ((propertyToCompute == CSSPropertyFontSize) ? fontDescription->specifiedSize() : fontDescription->computedSize()) * value;
+    case CSSUnitType::CSS_EXS:
+        ASSERT(fontMetrics);
+        if (fontMetrics->hasXHeight())
+            return fontMetrics->xHeight() * value;
+        ASSERT(fontDescription);
+        return ((propertyToCompute == CSSPropertyFontSize) ? fontDescription->specifiedSize() : fontDescription->computedSize()) / 2.0 * value;
+    case CSSUnitType::CSS_REMS:
+        if (!rootFontDescription)
+            return value;
+        return ((propertyToCompute == CSSPropertyFontSize) ? rootFontDescription->specifiedSize() : rootFontDescription->computedSize()) * value;
+    case CSSUnitType::CSS_CHS:
+        ASSERT(fontMetrics);
+        return fontMetrics->zeroWidth() * value;
+    case CSSUnitType::CSS_PX:
+        return value;
+    case CSSUnitType::CSS_CM:
+        return cssPixelsPerInch / cmPerInch * value;
+    case CSSUnitType::CSS_MM:
+        return cssPixelsPerInch / mmPerInch * value;
+    case CSSUnitType::CSS_Q:
+        return cssPixelsPerInch / QPerInch * value;
+    case CSSUnitType::CSS_LHS:
+    case CSSUnitType::CSS_RLHS:
+        ASSERT_NOT_REACHED();
+        return -1.0;
+    case CSSUnitType::CSS_IN:
+        return cssPixelsPerInch * value;
+    case CSSUnitType::CSS_PT:
+        return cssPixelsPerInch / 72.0 * value;
+    case CSSUnitType::CSS_PC:
+        // 1 pc == 12 pt
+        return cssPixelsPerInch * 12.0 / 72.0 * value;
+    case CSSUnitType::CSS_CALC_PERCENTAGE_WITH_LENGTH:
+    case CSSUnitType::CSS_CALC_PERCENTAGE_WITH_NUMBER:
+        ASSERT_NOT_REACHED();
+        return -1.0;
+    case CSSUnitType::CSS_VH:
+        return renderView ? renderView->viewportSizeForCSSViewportUnits().height() / 100.0 * value : 0;
+    case CSSUnitType::CSS_VW:
+        return renderView ? renderView->viewportSizeForCSSViewportUnits().width() / 100.0 * value : 0;
+    case CSSUnitType::CSS_VMAX:
+        if (renderView) {
+            IntSize viewportSizeForCSSViewportUnits = renderView->viewportSizeForCSSViewportUnits();
+            return std::max(viewportSizeForCSSViewportUnits.width(), viewportSizeForCSSViewportUnits.height()) / 100.0 * value;
+        }
+        return value;
+    case CSSUnitType::CSS_VMIN:
+        if (renderView) {
+            IntSize viewportSizeForCSSViewportUnits = renderView->viewportSizeForCSSViewportUnits();
+            return std::min(viewportSizeForCSSViewportUnits.width(), viewportSizeForCSSViewportUnits.height()) / 100.0 * value;
+        }
+        return value;
+    default:
+        ASSERT_NOT_REACHED();
+        return -1.0;
+    }
+}
+
 double CSSPrimitiveValue::computeNonCalcLengthDouble(const CSSToLengthConversionData& conversionData, CSSUnitType primitiveType, double value)
 {
-    double factor;
-    bool applyZoom = true;
-
     switch (primitiveType) {
     case CSSUnitType::CSS_EMS:
     case CSSUnitType::CSS_QUIRKY_EMS:
         ASSERT(conversionData.style());
-        factor = conversionData.computingFontSize() ? conversionData.style()->fontDescription().specifiedSize() : conversionData.style()->fontDescription().computedSize();
+        value = computeUnzoomedNonCalcLengthDouble(primitiveType, value, conversionData.propertyToCompute(), nullptr, &conversionData.style()->fontDescription());
         break;
+
     case CSSUnitType::CSS_EXS:
-        ASSERT(conversionData.style());
         // FIXME: We have a bug right now where the zoom will be applied twice to EX units.
         // We really need to compute EX using fontMetrics for the original specifiedSize and not use
         // our actual constructed rendering font.
-        if (conversionData.style()->fontMetrics().hasXHeight())
-            factor = conversionData.style()->fontMetrics().xHeight();
-        else
-            factor = (conversionData.computingFontSize() ? conversionData.style()->fontDescription().specifiedSize() : conversionData.style()->fontDescription().computedSize()) / 2.0;
+        ASSERT(conversionData.style());
+        value = computeUnzoomedNonCalcLengthDouble(primitiveType, value, conversionData.propertyToCompute(), &conversionData.style()->fontMetrics(), &conversionData.style()->fontDescription());
         break;
+
     case CSSUnitType::CSS_REMS:
-        if (conversionData.rootStyle())
-            factor = conversionData.computingFontSize() ? conversionData.rootStyle()->fontDescription().specifiedSize() : conversionData.rootStyle()->fontDescription().computedSize();
-        else
-            factor = 1.0;
+        value = computeUnzoomedNonCalcLengthDouble(primitiveType, value, conversionData.propertyToCompute(), nullptr, nullptr, conversionData.rootStyle() ? &conversionData.rootStyle()->fontDescription() : nullptr);
         break;
+
     case CSSUnitType::CSS_CHS:
         ASSERT(conversionData.style());
-        factor = conversionData.style()->fontMetrics().zeroWidth();
+        value = computeUnzoomedNonCalcLengthDouble(primitiveType, value, conversionData.propertyToCompute(), &conversionData.style()->fontMetrics());
         break;
+
     case CSSUnitType::CSS_PX:
-        factor = 1.0;
-        break;
     case CSSUnitType::CSS_CM:
-        factor = cssPixelsPerInch / cmPerInch;
-        break;
     case CSSUnitType::CSS_MM:
-        factor = cssPixelsPerInch / mmPerInch;
-        break;
     case CSSUnitType::CSS_Q:
-        factor = cssPixelsPerInch / QPerInch;
+    case CSSUnitType::CSS_IN:
+    case CSSUnitType::CSS_PT:
+    case CSSUnitType::CSS_PC:
+    case CSSUnitType::CSS_CALC_PERCENTAGE_WITH_LENGTH:
+    case CSSUnitType::CSS_CALC_PERCENTAGE_WITH_NUMBER:
+        value = computeUnzoomedNonCalcLengthDouble(primitiveType, value, conversionData.propertyToCompute());
         break;
+
+    case CSSUnitType::CSS_VH:
+        return value * conversionData.viewportHeightFactor();
+
+    case CSSUnitType::CSS_VW:
+        return value * conversionData.viewportWidthFactor();
+
+    case CSSUnitType::CSS_VMAX:
+        return value * conversionData.viewportMaxFactor();
+
+    case CSSUnitType::CSS_VMIN:
+        return value * conversionData.viewportMinFactor();
+
     case CSSUnitType::CSS_LHS:
         ASSERT(conversionData.style());
         if (conversionData.computingLineHeight() || conversionData.computingFontSize()) {
             // Try to get the parent's computed line-height, or fall back to the initial line-height of this element's font spacing.
-            factor = conversionData.parentStyle() ? conversionData.parentStyle()->computedLineHeight() : conversionData.style()->fontMetrics().lineSpacing();
+            value *= conversionData.parentStyle() ? conversionData.parentStyle()->computedLineHeight() : conversionData.style()->fontMetrics().lineSpacing();
         } else
-            factor = conversionData.style()->computedLineHeight();
+            value *= conversionData.style()->computedLineHeight();
         break;
+
     case CSSUnitType::CSS_RLHS:
         if (conversionData.rootStyle()) {
             if (conversionData.computingLineHeight() || conversionData.computingFontSize())
-                factor = conversionData.rootStyle()->computeLineHeight(conversionData.rootStyle()->specifiedLineHeight());
+                value *= conversionData.rootStyle()->computeLineHeight(conversionData.rootStyle()->specifiedLineHeight());
             else
-                factor = conversionData.rootStyle()->computedLineHeight();
-        } else
-            factor = 1.0;
+                value *= conversionData.rootStyle()->computedLineHeight();
+        }
         break;
-    case CSSUnitType::CSS_IN:
-        factor = cssPixelsPerInch;
-        break;
-    case CSSUnitType::CSS_PT:
-        factor = cssPixelsPerInch / 72.0;
-        break;
-    case CSSUnitType::CSS_PC:
-        // 1 pc == 12 pt
-        factor = cssPixelsPerInch * 12.0 / 72.0;
-        break;
-    case CSSUnitType::CSS_CALC_PERCENTAGE_WITH_LENGTH:
-    case CSSUnitType::CSS_CALC_PERCENTAGE_WITH_NUMBER:
-        ASSERT_NOT_REACHED();
-        return -1.0;
-    case CSSUnitType::CSS_VH:
-        factor = conversionData.viewportHeightFactor();
-        applyZoom = false;
-        break;
-    case CSSUnitType::CSS_VW:
-        factor = conversionData.viewportWidthFactor();
-        applyZoom = false;
-        break;
-    case CSSUnitType::CSS_VMAX:
-        factor = conversionData.viewportMaxFactor();
-        applyZoom = false;
-        break;
-    case CSSUnitType::CSS_VMIN:
-        factor = conversionData.viewportMinFactor();
-        applyZoom = false;
-        break;
+
     default:
         ASSERT_NOT_REACHED();
         return -1.0;
@@ -681,14 +725,10 @@
     // We do not apply the zoom factor when we are computing the value of the font-size property. The zooming
     // for font sizes is much more complicated, since we have to worry about enforcing the minimum font size preference
     // as well as enforcing the implicit "smart minimum."
-    double result = value * factor;
     if (conversionData.computingFontSize() || isFontRelativeLength(primitiveType))
-        return result;
+        return value;
 
-    if (applyZoom)
-        result *= conversionData.zoom();
-
-    return result;
+    return value * conversionData.zoom();
 }
 
 bool CSSPrimitiveValue::equalForLengthResolution(const RenderStyle& styleA, const RenderStyle& styleB)

Modified: trunk/Source/WebCore/css/CSSPrimitiveValue.h (273963 => 273964)


--- trunk/Source/WebCore/css/CSSPrimitiveValue.h	2021-03-05 13:15:25 UTC (rev 273963)
+++ trunk/Source/WebCore/css/CSSPrimitiveValue.h	2021-03-05 15:05:07 UTC (rev 273964)
@@ -39,11 +39,14 @@
 class CSSToLengthConversionData;
 class Counter;
 class DeprecatedCSSOMPrimitiveValue;
+class FontCascadeDescription;
+class FontMetrics;
 class Pair;
 class Quad;
 class RGBColor;
 class Rect;
 class RenderStyle;
+class RenderView;
 
 struct CSSFontFamily;
 struct Length;
@@ -188,6 +191,7 @@
     static double conversionToCanonicalUnitsScaleFactor(CSSUnitType);
     static String unitTypeString(CSSUnitType);
 
+    static double computeUnzoomedNonCalcLengthDouble(CSSUnitType, double value, CSSPropertyID, const FontMetrics* = nullptr, const FontCascadeDescription* = nullptr, const FontCascadeDescription* rootFontDescription = nullptr, const RenderView* = nullptr);
     static double computeNonCalcLengthDouble(const CSSToLengthConversionData&, CSSUnitType, double value);
     // True if computeNonCalcLengthDouble would produce identical results when resolved against both these styles.
     static bool equalForLengthResolution(const RenderStyle&, const RenderStyle&);

Modified: trunk/Source/WebCore/css/CSSToLengthConversionData.h (273963 => 273964)


--- trunk/Source/WebCore/css/CSSToLengthConversionData.h	2021-03-05 13:15:25 UTC (rev 273963)
+++ trunk/Source/WebCore/css/CSSToLengthConversionData.h	2021-03-05 15:05:07 UTC (rev 273964)
@@ -75,6 +75,8 @@
     float zoom() const;
     bool computingFontSize() const { return m_propertyToCompute == CSSPropertyFontSize; }
     bool computingLineHeight() const { return m_propertyToCompute == CSSPropertyLineHeight; }
+    CSSPropertyID propertyToCompute() const { return m_propertyToCompute.valueOr(CSSPropertyInvalid); }
+    const RenderView* renderView() const { return m_renderView; }
 
     double viewportWidthFactor() const;
     double viewportHeightFactor() const;

Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp (273963 => 273964)


--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp	2021-03-05 13:15:25 UTC (rev 273963)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp	2021-03-05 15:05:07 UTC (rev 273964)
@@ -126,8 +126,8 @@
         fontDescription.setComputedSize(DefaultFontSize);
     }
 
-    auto fontStyle = Style::resolveForFontRaw(*fontRaw, WTFMove(fontDescription), document);
-    if (!fontStyle)
+    auto fontCascade = Style::resolveForFontRaw(*fontRaw, WTFMove(fontDescription), document);
+    if (!fontCascade)
         return;
 
     String newFontSafeCopy(newFont); // Create a string copy since newFont can be deleted inside realizeSaves.
@@ -134,7 +134,7 @@
     realizeSaves();
     modifiableState().unparsedFont = newFontSafeCopy;
 
-    modifiableState().font.initialize(document.fontSelector(), *fontStyle);
+    modifiableState().font.initialize(document.fontSelector(), *fontCascade);
     ASSERT(state().font.realized());
     ASSERT(state().font.isPopulated());
 }

Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp (273963 => 273964)


--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp	2021-03-05 13:15:25 UTC (rev 273963)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp	2021-03-05 15:05:07 UTC (rev 273964)
@@ -292,13 +292,13 @@
     update(selector);
 }
 
-void CanvasRenderingContext2DBase::FontProxy::initialize(FontSelector& fontSelector, const RenderStyle& newStyle)
+void CanvasRenderingContext2DBase::FontProxy::initialize(FontSelector& fontSelector, const FontCascade& fontCascade)
 {
     // Beware! m_font.fontSelector() might not point to document.fontSelector()!
-    ASSERT(newStyle.fontCascade().fontSelector() == &fontSelector);
+    ASSERT(fontCascade.fontSelector() == &fontSelector);
     if (realized())
         m_font.fontSelector()->unregisterForInvalidationCallbacks(*this);
-    m_font = newStyle.fontCascade();
+    m_font = fontCascade;
     m_font.update(&fontSelector);
     ASSERT(&fontSelector == m_font.fontSelector());
     m_font.fontSelector()->registerForInvalidationCallbacks(*this);

Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.h (273963 => 273964)


--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.h	2021-03-05 13:15:25 UTC (rev 273963)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.h	2021-03-05 15:05:07 UTC (rev 273964)
@@ -64,7 +64,6 @@
 class ImageData;
 class OffscreenCanvas;
 class Path2D;
-class RenderStyle;
 class RenderObject;
 class TextMetrics;
 
@@ -235,7 +234,7 @@
         FontProxy& operator=(const FontProxy&);
 
         bool realized() const { return m_font.fontSelector(); }
-        void initialize(FontSelector&, const RenderStyle&);
+        void initialize(FontSelector&, const FontCascade&);
         const FontMetrics& fontMetrics() const;
         const FontCascadeDescription& fontDescription() const;
         float width(const TextRun&, GlyphOverflow* = 0) const;

Modified: trunk/Source/WebCore/html/canvas/OffscreenCanvasRenderingContext2D.cpp (273963 => 273964)


--- trunk/Source/WebCore/html/canvas/OffscreenCanvasRenderingContext2D.cpp	2021-03-05 13:15:25 UTC (rev 273963)
+++ trunk/Source/WebCore/html/canvas/OffscreenCanvasRenderingContext2D.cpp	2021-03-05 15:05:07 UTC (rev 273964)
@@ -91,10 +91,10 @@
     fontDescription.setComputedSize(DefaultFontSize);
 
     auto& document = downcast<Document>(context);
-    auto fontStyle = Style::resolveForFontRaw(*fontRaw, WTFMove(fontDescription), document);
+    auto fontCascade = Style::resolveForFontRaw(*fontRaw, WTFMove(fontDescription), document);
 
-    if (fontStyle)
-        modifiableState().font.initialize(document.fontSelector(), *fontStyle);
+    if (fontCascade)
+        modifiableState().font.initialize(document.fontSelector(), *fontCascade);
 }
 
 CanvasDirection OffscreenCanvasRenderingContext2D::direction() const

Modified: trunk/Source/WebCore/style/StyleFontSizeFunctions.cpp (273963 => 273964)


--- trunk/Source/WebCore/style/StyleFontSizeFunctions.cpp	2021-03-05 13:15:25 UTC (rev 273963)
+++ trunk/Source/WebCore/style/StyleFontSizeFunctions.cpp	2021-03-05 15:05:07 UTC (rev 273964)
@@ -39,13 +39,7 @@
 
 namespace Style {
 
-enum class MinimumFontSizeRule {
-    None,
-    Absolute,
-    AbsoluteAndRelative
-};
-
-static float computedFontSizeFromSpecifiedSize(float specifiedSize, bool isAbsoluteSize, float zoomFactor, MinimumFontSizeRule minimumSizeRule, const Settings& settings)
+float computedFontSizeFromSpecifiedSize(float specifiedSize, bool isAbsoluteSize, float zoomFactor, MinimumFontSizeRule minimumSizeRule, const Settings::Values& settings)
 {
     // Text with a 0px font size should not be visible and therefore needs to be
     // exempt from minimum font size rules. Acid3 relies on this for pixel-perfect
@@ -67,8 +61,8 @@
     if (minimumSizeRule == MinimumFontSizeRule::None)
         return specifiedSize;
 
-    int minSize = settings.minimumFontSize();
-    int minLogicalSize = settings.minimumLogicalFontSize();
+    int minSize = settings.minimumFontSize;
+    int minLogicalSize = settings.minimumLogicalFontSize;
     float zoomedSize = specifiedSize * zoomFactor;
 
     // Apply the hard minimum first. We only apply the hard minimum if after zooming we're still too small.
@@ -95,12 +89,12 @@
         if (frame && style->textZoom() != TextZoom::Reset)
             zoomFactor *= frame->textZoomFactor();
     }
-    return computedFontSizeFromSpecifiedSize(specifiedSize, isAbsoluteSize, zoomFactor, useSVGZoomRules ? MinimumFontSizeRule::None : MinimumFontSizeRule::AbsoluteAndRelative, document.settings());
+    return computedFontSizeFromSpecifiedSize(specifiedSize, isAbsoluteSize, zoomFactor, useSVGZoomRules ? MinimumFontSizeRule::None : MinimumFontSizeRule::AbsoluteAndRelative, document.settingsValues());
 }
 
 float computedFontSizeFromSpecifiedSizeForSVGInlineText(float specifiedSize, bool isAbsoluteSize, float zoomFactor, const Document& document)
 {
-    return computedFontSizeFromSpecifiedSize(specifiedSize, isAbsoluteSize, zoomFactor, MinimumFontSizeRule::Absolute, document.settings());
+    return computedFontSizeFromSpecifiedSize(specifiedSize, isAbsoluteSize, zoomFactor, MinimumFontSizeRule::Absolute, document.settingsValues());
 }
 
 const int fontSizeTableMax = 16;
@@ -145,22 +139,26 @@
 // factors for each keyword value.
 static const float fontSizeFactors[totalKeywords] = { 0.60f, 0.75f, 0.89f, 1.0f, 1.2f, 1.5f, 2.0f, 3.0f };
 
-float fontSizeForKeyword(unsigned keywordID, bool shouldUseFixedDefaultSize, const Document& document)
+float fontSizeForKeyword(unsigned keywordID, bool shouldUseFixedDefaultSize, const Settings::Values& settings, bool inQuirksMode)
 {
-    bool quirksMode = document.inQuirksMode();
-    int mediumSize = shouldUseFixedDefaultSize ? document.settings().defaultFixedFontSize() : document.settings().defaultFontSize();
+    int mediumSize = shouldUseFixedDefaultSize ? settings.defaultFixedFontSize : settings.defaultFontSize;
     if (mediumSize >= fontSizeTableMin && mediumSize <= fontSizeTableMax) {
         // Look up the entry in the table.
         int row = mediumSize - fontSizeTableMin;
         int col = (keywordID - CSSValueXxSmall);
-        return quirksMode ? quirksFontSizeTable[row][col] : strictFontSizeTable[row][col];
+        return inQuirksMode ? quirksFontSizeTable[row][col] : strictFontSizeTable[row][col];
     }
 
     // Value is outside the range of the table. Apply the scale factor instead.
-    float minLogicalSize = std::max<float>(document.settings().minimumLogicalFontSize(), 1);
+    float minLogicalSize = std::max<float>(settings.minimumLogicalFontSize, 1);
     return std::max(fontSizeFactors[keywordID - CSSValueXxSmall] * mediumSize, minLogicalSize);
 }
 
+float fontSizeForKeyword(unsigned keywordID, bool shouldUseFixedDefaultSize, const Document& document)
+{
+    return fontSizeForKeyword(keywordID, shouldUseFixedDefaultSize, document.settingsValues(), document.inQuirksMode());
+}
+
 template<typename T>
 static int findNearestLegacyFontSize(int pixelFontSize, const T* table, int multiplier)
 {

Modified: trunk/Source/WebCore/style/StyleFontSizeFunctions.h (273963 => 273964)


--- trunk/Source/WebCore/style/StyleFontSizeFunctions.h	2021-03-05 13:15:25 UTC (rev 273963)
+++ trunk/Source/WebCore/style/StyleFontSizeFunctions.h	2021-03-05 15:05:07 UTC (rev 273964)
@@ -25,6 +25,7 @@
 
 #pragma once
 
+#include "Settings.h"
 
 namespace WebCore {
 
@@ -33,11 +34,15 @@
 
 namespace Style {
 
+enum class MinimumFontSizeRule : uint8_t { None, Absolute, AbsoluteAndRelative };
+
+float computedFontSizeFromSpecifiedSize(float specifiedSize, bool isAbsoluteSize, float zoomFactor, MinimumFontSizeRule, const Settings::Values&);
 float computedFontSizeFromSpecifiedSize(float specifiedSize, bool isAbsoluteSize, bool useSVGZoomRules, const RenderStyle*, const Document&);
 float computedFontSizeFromSpecifiedSizeForSVGInlineText(float specifiedSize, bool isAbsoluteSize, float zoomFactor, const Document&);
 
 // Given a CSS keyword id in the range (CSSValueXxSmall to CSSValueWebkitXxxLarge), this function will return
 // the correct font size scaled relative to the user's default (medium).
+float fontSizeForKeyword(unsigned keywordID, bool shouldUseFixedDefaultSize, const Settings::Values&, bool inQuirksMode = false);
 float fontSizeForKeyword(unsigned keywordID, bool shouldUseFixedDefaultSize, const Document&);
 
 // Given a font size in pixel, this function will return legacy font size between 1 and 7.

Modified: trunk/Source/WebCore/style/StyleResolveForFontRaw.cpp (273963 => 273964)


--- trunk/Source/WebCore/style/StyleResolveForFontRaw.cpp	2021-03-05 13:15:25 UTC (rev 273963)
+++ trunk/Source/WebCore/style/StyleResolveForFontRaw.cpp	2021-03-05 15:05:07 UTC (rev 273964)
@@ -33,7 +33,6 @@
 
 #include "CSSFontSelector.h"
 #include "CSSPropertyParserHelpers.h"
-#include "CSSToLengthConversionData.h"
 #include "Document.h"
 #include "FontCascade.h"
 #include "FontCascadeDescription.h"
@@ -47,17 +46,8 @@
 
 using namespace CSSPropertyParserHelpers;
 
-Optional<RenderStyle> resolveForFontRaw(const FontRaw& fontRaw, FontCascadeDescription&& fontDescription, Document& document)
+Optional<FontCascade> resolveForFontRaw(const FontRaw& fontRaw, FontCascadeDescription&& fontDescription, Document& document)
 {
-    auto fontStyle = RenderStyle::create();
-
-    auto getParentStyle = [&] () -> std::unique_ptr<RenderStyle> {
-        auto parentStyle = RenderStyle::clonePtr(fontStyle);
-        parentStyle->setFontDescription(FontCascadeDescription(fontDescription));
-        parentStyle->fontCascade().update(&document.fontSelector());
-        return parentStyle;
-    };
-
     // Map the font property longhands into the style.
     float parentSize = fontDescription.specifiedSize();
 
@@ -93,7 +83,7 @@
         if (CSSValueID sizeIdentifier = fontDescription.keywordSizeAsIdentifier()) {
             auto size = Style::fontSizeForKeyword(sizeIdentifier, !oldFamilyUsedFixedDefaultSize, document);
             fontDescription.setSpecifiedSize(size);
-            fontDescription.setComputedSize(Style::computedFontSizeFromSpecifiedSize(size, fontDescription.isAbsoluteSize(), false, &fontStyle, document));
+            fontDescription.setComputedSize(Style::computedFontSizeFromSpecifiedSize(size, fontDescription.isAbsoluteSize(), 1.0, MinimumFontSizeRule::None, document.settingsValues()));
         }
     }
 
@@ -196,9 +186,9 @@
         }
     }, [&] (const CSSPropertyParserHelpers::LengthOrPercentRaw& lengthOrPercent) {
         return switchOn(lengthOrPercent, [&] (const CSSPropertyParserHelpers::LengthRaw& length) {
-            auto parentStyle = getParentStyle();
-            CSSToLengthConversionData conversionData { parentStyle.get(), nullptr, parentStyle.get(), document.renderView(), 1.0f, CSSPropertyFontSize };
-            return static_cast<float>(CSSPrimitiveValue::computeNonCalcLengthDouble(conversionData, length.type, length.value));
+            auto fontCascade = FontCascade(FontCascadeDescription(fontDescription));
+            fontCascade.update(&document.fontSelector());
+            return static_cast<float>(CSSPrimitiveValue::computeUnzoomedNonCalcLengthDouble(length.type, length.value, CSSPropertyFontSize, &fontCascade.fontMetrics(), &fontCascade.fontDescription(), &fontCascade.fontDescription(), document.renderView()));
         }, [&] (double percentage) {
             return static_cast<float>((parentSize * percentage) / 100.0);
         });
@@ -209,31 +199,12 @@
         fontDescription.setComputedSize(size);
     }
 
-    if (fontRaw.lineHeight) {
-        Optional<Length> lineHeight = switchOn(*fontRaw.lineHeight, [&] (CSSValueID ident) {
-            if (ident == CSSValueNormal)
-                return Optional<Length>(RenderStyle::initialLineHeight());
-            return Optional<Length>(WTF::nullopt);
-        }, [&] (double number) {
-            return Optional<Length>(Length(number * 100.0, LengthType::Percent));
-        }, [&] (const CSSPropertyParserHelpers::LengthOrPercentRaw& lengthOrPercent) {
-            return switchOn(lengthOrPercent, [&] (const CSSPropertyParserHelpers::LengthRaw& length) {
-                auto parentStyle = getParentStyle();
-                CSSToLengthConversionData conversionData { parentStyle.get(), nullptr, parentStyle.get(), document.renderView(), 1.0f, CSSPropertyLineHeight };
-                return Optional<Length>(Length(clampTo<float>(CSSPrimitiveValue::computeNonCalcLengthDouble(conversionData, length.type, length.value), minValueForCssLength, maxValueForCssLength), LengthType::Fixed));
-            }, [&] (double percentage) {
-                return Optional<Length>(Length((fontDescription.computedSize() * static_cast<int>(percentage)) / 100, LengthType::Fixed));
-            });
-        });
+    // As there is no line-height on FontCascade, there's no need to resolve
+    // it, even though there is line-height information on FontRaw.
 
-        if (lineHeight)
-            fontStyle.setLineHeight(WTFMove(lineHeight.value()));
-    }
-
-    fontStyle.setFontDescription(WTFMove(fontDescription));
-    fontStyle.fontCascade().update(&document.fontSelector());
-
-    return fontStyle;
+    auto fontCascade = FontCascade(WTFMove(fontDescription));
+    fontCascade.update(&document.fontSelector());
+    return fontCascade;
 }
 
 }

Modified: trunk/Source/WebCore/style/StyleResolveForFontRaw.h (273963 => 273964)


--- trunk/Source/WebCore/style/StyleResolveForFontRaw.h	2021-03-05 13:15:25 UTC (rev 273963)
+++ trunk/Source/WebCore/style/StyleResolveForFontRaw.h	2021-03-05 15:05:07 UTC (rev 273964)
@@ -33,8 +33,8 @@
 namespace WebCore {
 
 class Document;
+class FontCascade;
 class FontCascadeDescription;
-class RenderStyle;
 
 namespace CSSPropertyParserHelpers {
 struct FontRaw;
@@ -42,7 +42,7 @@
 
 namespace Style {
 
-Optional<RenderStyle> resolveForFontRaw(const CSSPropertyParserHelpers::FontRaw&, FontCascadeDescription&&, Document&);
+Optional<FontCascade> resolveForFontRaw(const CSSPropertyParserHelpers::FontRaw&, FontCascadeDescription&&, Document&);
 
 }
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to