Bug 1807479 - fill fallback should always be black and stroke fallback should always be invisible r=emilio

If we encounter fill: context-stroke, which neither Chrome nor Firefox currently support for markers Chrome falls back to the initial fill colour (black), whereas Firefox falls back to the initial stroke color (none). The reverse happens for stroke: context-fill. This patch aligns us with Chrome till we support context-fill and context-stroke properly.

https://www.w3.org/TR/SVG2/painting.html#SpecifyingFillPaint and https://www.w3.org/TR/SVG2/painting.html#SpecifyingStrokePaint define the initial fill and stroke colours.

Differential Revision: https://phabricator.services.mozilla.com/D165495
This commit is contained in:
Robert Longson
2022-12-26 11:03:36 +00:00
parent 6743fbb54b
commit 6fd06957b9
10 changed files with 45 additions and 21 deletions

View File

@@ -4,7 +4,7 @@
-->
<svg xmlns="http://www.w3.org/2000/svg" >
<title>Reference for fallback colours</title>
<title>Reference for stroke fallback colours</title>
<!-- From https://bugzilla.mozilla.org/show_bug.cgi?id=368840 -->

Before

Width:  |  Height:  |  Size: 345 B

After

Width:  |  Height:  |  Size: 352 B

View File

Before

Width:  |  Height:  |  Size: 476 B

After

Width:  |  Height:  |  Size: 476 B

View File

Before

Width:  |  Height:  |  Size: 354 B

After

Width:  |  Height:  |  Size: 354 B

View File

@@ -0,0 +1,12 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<svg xmlns="http://www.w3.org/2000/svg">
<title>Testcase for context-stroke fallback colour</title>
<!-- From https://bugzilla.mozilla.org/show_bug.cgi?id=1807479 -->
<rect width="100%" height="100%" fill="context-stroke"/>
</svg>

After

Width:  |  Height:  |  Size: 358 B

View File

@@ -0,0 +1,12 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<svg xmlns="http://www.w3.org/2000/svg" >
<title>Reference for fill fallback colours</title>
<!-- From https://bugzilla.mozilla.org/show_bug.cgi?id=1807479 -->
<rect x="0%" y="0%" width="100%" height="100%" fill="black"/>
</svg>

After

Width:  |  Height:  |  Size: 351 B

View File

Before

Width:  |  Height:  |  Size: 351 B

After

Width:  |  Height:  |  Size: 351 B

View File

@@ -204,11 +204,12 @@ random == dynamic-use-nested-01b.svg dynamic-use-nested-01-ref.svg
== fallback-color-01a.svg pass.svg
== fallback-color-01b.svg pass.svg
== fallback-color-02a.svg fallback-color-02-ref.svg
== fallback-color-02b.svg fallback-color-02-ref.svg
== fallback-color-02.svg fallback-color-02-ref.svg
== fallback-color-03.svg pass.svg
fuzzy(0-1,0-2) == fallback-color-04.svg pass.svg
== fallback-color-05.svg fallback-color-05-ref.svg
== fallback-color-05a.svg fallback-color-05-ref.svg
== fallback-color-05b.svg fallback-color-05-ref.svg
== fallback-color-06.svg fallback-color-06-ref.svg
== filter-and-clip.svg filter-and-clip-ref.svg
== filter-basic-01.svg pass.svg

View File

@@ -100,6 +100,7 @@ static void SetupInheritablePaint(const DrawTarget* aDrawTarget,
SVGContextPaint* aOuterContextPaint,
SVGContextPaintImpl::Paint& aTargetPaint,
StyleSVGPaint nsStyleSVG::*aFillOrStroke,
nscolor aDefaultFallbackColor,
imgDrawingParams& aImgParams) {
const nsStyleSVG* style = aFrame->StyleSVG();
SVGPaintServerFrame* ps =
@@ -138,8 +139,8 @@ static void SetupInheritablePaint(const DrawTarget* aDrawTarget,
}
}
nscolor color =
SVGUtils::GetFallbackOrPaintColor(*aFrame->Style(), aFillOrStroke);
nscolor color = SVGUtils::GetFallbackOrPaintColor(
*aFrame->Style(), aFillOrStroke, aDefaultFallbackColor);
aTargetPaint.SetColor(color);
}
@@ -161,7 +162,7 @@ DrawMode SVGContextPaintImpl::Init(const DrawTarget* aDrawTarget,
SetupInheritablePaint(aDrawTarget, aContextMatrix, aFrame, opacity,
aOuterContextPaint, mFillPaint, &nsStyleSVG::mFill,
aImgParams);
NS_RGB(0, 0, 0), aImgParams);
SetFillOpacity(opacity);
@@ -175,9 +176,9 @@ DrawMode SVGContextPaintImpl::Init(const DrawTarget* aDrawTarget,
float opacity =
SVGUtils::GetOpacity(style->mStrokeOpacity, aOuterContextPaint);
SetupInheritablePaint(aDrawTarget, aContextMatrix, aFrame, opacity,
aOuterContextPaint, mStrokePaint,
&nsStyleSVG::mStroke, aImgParams);
SetupInheritablePaint(
aDrawTarget, aContextMatrix, aFrame, opacity, aOuterContextPaint,
mStrokePaint, &nsStyleSVG::mStroke, NS_RGBA(0, 0, 0, 0), aImgParams);
SetStrokeOpacity(opacity);

View File

@@ -1308,20 +1308,17 @@ gfxRect SVGUtils::PathExtentsToMaxStrokeExtents(const gfxRect& aPathExtents,
/* static */
nscolor SVGUtils::GetFallbackOrPaintColor(
const ComputedStyle& aStyle, StyleSVGPaint nsStyleSVG::*aFillOrStroke) {
const ComputedStyle& aStyle, StyleSVGPaint nsStyleSVG::*aFillOrStroke,
nscolor aDefaultFallbackColor) {
const auto& paint = aStyle.StyleSVG()->*aFillOrStroke;
nscolor color;
switch (paint.kind.tag) {
case StyleSVGPaintKind::Tag::PaintServer:
case StyleSVGPaintKind::Tag::ContextStroke:
color = paint.fallback.IsColor()
? paint.fallback.AsColor().CalcColor(aStyle)
: NS_RGBA(0, 0, 0, 0);
break;
case StyleSVGPaintKind::Tag::ContextFill:
color = paint.fallback.IsColor()
? paint.fallback.AsColor().CalcColor(aStyle)
: NS_RGB(0, 0, 0);
: aDefaultFallbackColor;
break;
default:
color = paint.kind.AsColor().CalcColor(aStyle);
@@ -1407,8 +1404,8 @@ void SVGUtils::MakeFillPatternFor(nsIFrame* aFrame, gfxContext* aContext,
// On failure, use the fallback colour in case we have an
// objectBoundingBox where the width or height of the object is zero.
// See http://www.w3.org/TR/SVG11/coords.html#ObjectBoundingBox
sRGBColor color(sRGBColor::FromABGR(
GetFallbackOrPaintColor(*aFrame->Style(), &nsStyleSVG::mFill)));
sRGBColor color(sRGBColor::FromABGR(GetFallbackOrPaintColor(
*aFrame->Style(), &nsStyleSVG::mFill, NS_RGB(0, 0, 0))));
color.a *= fillOpacity;
aOutPattern->InitColorPattern(ToDeviceColor(color));
}
@@ -1474,8 +1471,8 @@ void SVGUtils::MakeStrokePatternFor(nsIFrame* aFrame, gfxContext* aContext,
// On failure, use the fallback colour in case we have an
// objectBoundingBox where the width or height of the object is zero.
// See http://www.w3.org/TR/SVG11/coords.html#ObjectBoundingBox
sRGBColor color(sRGBColor::FromABGR(
GetFallbackOrPaintColor(*aFrame->Style(), &nsStyleSVG::mStroke)));
sRGBColor color(sRGBColor::FromABGR(GetFallbackOrPaintColor(
*aFrame->Style(), &nsStyleSVG::mStroke, NS_RGBA(0, 0, 0, 0))));
color.a *= strokeOpacity;
aOutPattern->InitColorPattern(ToDeviceColor(color));
}

View File

@@ -477,7 +477,8 @@ class SVGUtils final {
}
static nscolor GetFallbackOrPaintColor(
const ComputedStyle&, StyleSVGPaint nsStyleSVG::*aFillOrStroke);
const ComputedStyle&, StyleSVGPaint nsStyleSVG::*aFillOrStroke,
nscolor aDefaultFallbackColor);
static void MakeFillPatternFor(nsIFrame* aFrame, gfxContext* aContext,
GeneralPattern* aOutPattern,