Skip to content

Commit

Permalink
Bug 1864039 - clip-path path reference box is incorrect with stroke r…
Browse files Browse the repository at this point in the history
…=boris

Differential Revision: https://phabricator.services.mozilla.com/D193643
  • Loading branch information
longsonr committed Nov 15, 2023
1 parent 6e4a680 commit 1b18e7f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
7 changes: 4 additions & 3 deletions dom/svg/SVGPathData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,8 @@ already_AddRefed<Path> SVGPathData::BuildPathForMeasuring(
/* static */
already_AddRefed<Path> SVGPathData::BuildPath(
Span<const StylePathCommand> aPath, PathBuilder* aBuilder,
StyleStrokeLinecap aStrokeLineCap, Float aStrokeWidth, float aZoomFactor) {
StyleStrokeLinecap aStrokeLineCap, Float aStrokeWidth, const Point& aOffset,
float aZoomFactor) {
if (aPath.IsEmpty() || !aPath[0].IsMoveTo()) {
return nullptr; // paths without an initial moveto are invalid
}
Expand All @@ -599,8 +600,8 @@ already_AddRefed<Path> SVGPathData::BuildPath(
Point cp1, cp2; // previous bezier's control points
Point tcp1, tcp2; // temporaries

auto scale = [aZoomFactor](const Point& p) {
return Point(p.x * aZoomFactor, p.y * aZoomFactor);
auto scale = [aOffset, aZoomFactor](const Point& p) {
return Point(p.x * aZoomFactor, p.y * aZoomFactor) + aOffset;
};

// Regarding cp1 and cp2: If the previous segment was a cubic bezier curve,
Expand Down
9 changes: 4 additions & 5 deletions dom/svg/SVGPathData.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,10 @@ class SVGPathData {
* which is generated by cbindgen from Rust (see ServoStyleConsts.h).
* Basically, this is a variant of the above BuildPath() functions.
*/
static already_AddRefed<Path> BuildPath(Span<const StylePathCommand> aPath,
PathBuilder* aBuilder,
StyleStrokeLinecap aStrokeLineCap,
Float aStrokeWidth,
float aZoomFactor = 1.0);
static already_AddRefed<Path> BuildPath(
Span<const StylePathCommand> aPath, PathBuilder* aBuilder,
StyleStrokeLinecap aStrokeLineCap, Float aStrokeWidth,
const gfx::Point& aOffset = gfx::Point(), float aZoomFactor = 1.0);

const_iterator begin() const { return mData.Elements(); }
const_iterator end() const { return mData.Elements() + mData.Length(); }
Expand Down
17 changes: 9 additions & 8 deletions layout/svg/CSSClipPathInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@ Maybe<Rect> CSSClipPathInstance::GetBoundingRectForBasicShapeOrPathClip(

already_AddRefed<Path> CSSClipPathInstance::CreateClipPath(
DrawTarget* aDrawTarget, const gfxMatrix& aTransform) {
if (mClipPathStyle.IsShape() && mClipPathStyle.AsShape()._0->IsPath()) {
return CreateClipPathPath(aDrawTarget);
}

nscoord appUnitsPerDevPixel =
mTargetFrame->PresContext()->AppUnitsPerDevPixel();

Expand Down Expand Up @@ -125,6 +121,8 @@ already_AddRefed<Path> CSSClipPathInstance::CreateClipPath(
return CreateClipPathPolygon(aDrawTarget, r);
case StyleBasicShape::Tag::Rect:
return CreateClipPathInset(aDrawTarget, r);
case StyleBasicShape::Tag::Path:
return CreateClipPathPath(aDrawTarget, r);
default:
MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE("Unexpected shape type");
}
Expand Down Expand Up @@ -176,16 +174,19 @@ already_AddRefed<Path> CSSClipPathInstance::CreateClipPathInset(
}

already_AddRefed<Path> CSSClipPathInstance::CreateClipPathPath(
DrawTarget* aDrawTarget) {
DrawTarget* aDrawTarget, const nsRect& aRefBox) {
const auto& path = mClipPathStyle.AsShape()._0->AsPath();

RefPtr<PathBuilder> builder = aDrawTarget->CreatePathBuilder(
path.fill == StyleFillRule::Nonzero ? FillRule::FILL_WINDING
: FillRule::FILL_EVEN_ODD);
float scale = float(AppUnitsPerCSSPixel()) /
mTargetFrame->PresContext()->AppUnitsPerDevPixel();
nscoord appUnitsPerDevPixel =
mTargetFrame->PresContext()->AppUnitsPerDevPixel();
float scale = float(AppUnitsPerCSSPixel()) / appUnitsPerDevPixel;
Point offset = Point(aRefBox.x, aRefBox.y) / appUnitsPerDevPixel;

return SVGPathData::BuildPath(path.path._0.AsSpan(), builder,
StyleStrokeLinecap::Butt, 0.0, scale);
StyleStrokeLinecap::Butt, 0.0, offset, scale);
}

} // namespace mozilla
3 changes: 2 additions & 1 deletion layout/svg/CSSClipPathInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ class MOZ_STACK_CLASS CSSClipPathInstance {
already_AddRefed<Path> CreateClipPathInset(DrawTarget* aDrawTarget,
const nsRect& aRefBox);

already_AddRefed<Path> CreateClipPathPath(DrawTarget* aDrawTarget);
already_AddRefed<Path> CreateClipPathPath(DrawTarget* aDrawTarget,
const nsRect& aRefBox);

/**
* The frame for the element that is currently being clipped.
Expand Down

This file was deleted.

0 comments on commit 1b18e7f

Please sign in to comment.