@@ -245,6 +245,7 @@ static already_AddRefed<Path> BuildPathInternal(
245245
246246 for (const auto & cmd : aPath) {
247247 seg = &cmd;
248+ bool isRelative = false ;
248249 switch (cmd.tag ) {
249250 case Command::Tag::Close:
250251 // set this early to allow drawing of square caps for "M{x},{y} Z":
@@ -271,15 +272,13 @@ static already_AddRefed<Path> BuildPathInternal(
271272 break ;
272273 }
273274 case Command::Tag::CubicCurve:
274- cp1 = cmd.cubic_curve .control1 .ToGfxPoint (aPercentageBasis);
275- cp2 = cmd.cubic_curve .control2 .ToGfxPoint (aPercentageBasis);
275+ isRelative = cmd.cubic_curve .point .IsByCoordinate ();
276276 segEnd = cmd.cubic_curve .point .ToGfxPoint (aPercentageBasis);
277-
278- if (cmd.cubic_curve .point .IsByCoordinate ()) {
279- cp1 += segStart;
280- cp2 += segStart;
281- segEnd += segStart;
282- }
277+ segEnd = isRelative ? segEnd + segStart : segEnd;
278+ cp1 = cmd.cubic_curve .control1 .ToGfxPoint (segStart, segEnd, isRelative,
279+ aPercentageBasis);
280+ cp2 = cmd.cubic_curve .control2 .ToGfxPoint (segStart, segEnd, isRelative,
281+ aPercentageBasis);
283282
284283 if (segEnd != segStart || segEnd != cp1 || segEnd != cp2) {
285284 subpathHasLength = true ;
@@ -288,13 +287,12 @@ static already_AddRefed<Path> BuildPathInternal(
288287 break ;
289288
290289 case Command::Tag::QuadCurve:
291- cp1 = cmd.quad_curve .control1 . ToGfxPoint (aPercentageBasis );
290+ isRelative = cmd.quad_curve .point . IsByCoordinate ( );
292291 segEnd = cmd.quad_curve .point .ToGfxPoint (aPercentageBasis);
293-
294- if (cmd.quad_curve .point .IsByCoordinate ()) {
295- cp1 += segStart;
296- segEnd += segStart; // set before setting tcp2!
297- }
292+ segEnd = isRelative ? segEnd + segStart
293+ : segEnd; // set before setting tcp2!
294+ cp1 = cmd.quad_curve .control1 .ToGfxPoint (segStart, segEnd, isRelative,
295+ aPercentageBasis);
298296
299297 // Convert quadratic curve to cubic curve:
300298 tcp1 = segStart + (cp1 - segStart) * 2 / 3 ;
@@ -359,14 +357,12 @@ static already_AddRefed<Path> BuildPathInternal(
359357 break ;
360358 }
361359 case Command::Tag::SmoothCubic:
362- cp1 = prevSeg && prevSeg->IsCubicType () ? segStart * 2 - cp2 : segStart;
363- cp2 = cmd.smooth_cubic .control2 .ToGfxPoint (aPercentageBasis);
360+ isRelative = cmd.smooth_cubic .point .IsByCoordinate ();
364361 segEnd = cmd.smooth_cubic .point .ToGfxPoint (aPercentageBasis);
365-
366- if (cmd.smooth_cubic .point .IsByCoordinate ()) {
367- cp2 += segStart;
368- segEnd += segStart;
369- }
362+ segEnd = isRelative ? segEnd + segStart : segEnd;
363+ cp1 = prevSeg && prevSeg->IsCubicType () ? segStart * 2 - cp2 : segStart;
364+ cp2 = cmd.smooth_cubic .control2 .ToGfxPoint (segStart, segEnd, isRelative,
365+ aPercentageBasis);
370366
371367 if (segEnd != segStart || segEnd != cp1 || segEnd != cp2) {
372368 subpathHasLength = true ;
@@ -546,6 +542,7 @@ void SVGPathData::GetMarkerPositioningData(Span<const StylePathCommand> aPath,
546542 Point& segStart = prevSegEnd;
547543 Point segEnd;
548544 float segStartAngle, segEndAngle;
545+ bool isRelative = false ;
549546
550547 switch (cmd.tag ) // to find segStartAngle, segEnd and segEndAngle
551548 {
@@ -570,15 +567,15 @@ void SVGPathData::GetMarkerPositioningData(Span<const StylePathCommand> aPath,
570567 break ;
571568 }
572569 case StylePathCommand::Tag::CubicCurve: {
573- Point cp1 = cmd.cubic_curve .control1 .ToGfxPoint () * aZoom;
574- Point cp2 = cmd.cubic_curve .control2 .ToGfxPoint () * aZoom;
570+ isRelative = cmd.cubic_curve .point .IsByCoordinate ();
575571 segEnd = cmd.cubic_curve .point .ToGfxPoint () * aZoom;
576-
577- if (cmd.cubic_curve .point .IsByCoordinate ()) {
578- cp1 += segStart;
579- cp2 += segStart;
580- segEnd += segStart;
581- }
572+ segEnd = isRelative ? segEnd + segStart : segEnd;
573+ Point cp1 =
574+ cmd.cubic_curve .control1 .ToGfxPoint (segStart, segEnd, isRelative) *
575+ aZoom;
576+ Point cp2 =
577+ cmd.cubic_curve .control2 .ToGfxPoint (segStart, segEnd, isRelative) *
578+ aZoom;
582579
583580 prevCP = cp2;
584581 segStartAngle = AngleOfVector (
@@ -588,13 +585,13 @@ void SVGPathData::GetMarkerPositioningData(Span<const StylePathCommand> aPath,
588585 break ;
589586 }
590587 case StylePathCommand::Tag::QuadCurve: {
591- Point cp1 = cmd.quad_curve .control1 . ToGfxPoint () * aZoom ;
588+ isRelative = cmd.quad_curve .point . IsByCoordinate () ;
592589 segEnd = cmd.quad_curve .point .ToGfxPoint () * aZoom;
593-
594- if (cmd. quad_curve . point . IsByCoordinate ()) {
595- cp1 += segStart;
596- segEnd += segStart; // set before setting tcp2!
597- }
590+ segEnd = isRelative ? segEnd + segStart
591+ : segEnd; // set before setting tcp2!
592+ Point cp1 =
593+ cmd. quad_curve . control1 . ToGfxPoint ( segStart, segEnd, isRelative) *
594+ aZoom;
598595
599596 prevCP = cp1;
600597 segStartAngle = AngleOfVector (cp1 == segStart ? segEnd : cp1, segStart);
@@ -665,13 +662,12 @@ void SVGPathData::GetMarkerPositioningData(Span<const StylePathCommand> aPath,
665662 const Point& cp1 = prevSeg && prevSeg->IsCubicType ()
666663 ? segStart * 2 - prevCP
667664 : segStart;
668- Point cp2 = cmd.smooth_cubic .control2 . ToGfxPoint () * aZoom ;
665+ isRelative = cmd.smooth_cubic .point . IsByCoordinate () ;
669666 segEnd = cmd.smooth_cubic .point .ToGfxPoint () * aZoom;
670-
671- if (cmd.smooth_cubic .point .IsByCoordinate ()) {
672- cp2 += segStart;
673- segEnd += segStart;
674- }
667+ segEnd = isRelative ? segEnd + segStart : segEnd;
668+ Point cp2 =
669+ cmd.smooth_cubic .control2 .ToGfxPoint (segStart, segEnd, isRelative) *
670+ aZoom;
675671
676672 prevCP = cp2;
677673 segStartAngle = AngleOfVector (
0 commit comments