coregraphics : strokes and gradients Be sure to convert the stroke to a fillable path if we need to draw a stroke **with** a gradient. CoreGraphics can natively draw a stroke (without having to explicitly set a clip), so we only do this convert-fill-to-stroke if we have to draw with a gradient. This PR also fixes the case when the gradient needs to extend beyond its logical domain (i.e. clamp-tile). That fix is needed for fills as well as strokes. Diffs= c3f7325d8 Handle strokes and gradients
diff --git a/.rive_head b/.rive_head index a98cdd0..844f5ea 100644 --- a/.rive_head +++ b/.rive_head
@@ -1 +1 @@ -ff3c43ce47aea58c9592aad5f8be0b434e89901a +c3f7325d8ec878b518b04c0399837d5b07b1cd34
diff --git a/skia/renderer/src/cg_factory.cpp b/skia/renderer/src/cg_factory.cpp index e8db79b..6af4db9 100644 --- a/skia/renderer/src/cg_factory.cpp +++ b/skia/renderer/src/cg_factory.cpp
@@ -148,6 +148,9 @@ public: CGRenderShader() {} + static constexpr int clampOptions = + kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation; + virtual void draw(CGContextRef) {} }; @@ -226,8 +229,7 @@ } void draw(CGContextRef ctx) override { - CGGradientDrawingOptions options = 0; - CGContextDrawRadialGradient(ctx, m_grad, m_center, 0, m_center, m_radius, options); + CGContextDrawRadialGradient(ctx, m_grad, m_center, 0, m_center, m_radius, clampOptions); } }; @@ -249,8 +251,7 @@ } void draw(CGContextRef ctx) override { - CGGradientDrawingOptions options = 0; - CGContextDrawLinearGradient(ctx, m_grad, m_start, m_end, options); + CGContextDrawLinearGradient(ctx, m_grad, m_start, m_end, clampOptions); } }; @@ -295,6 +296,10 @@ CGContextBeginPath(m_ctx); CGContextAddPath(m_ctx, cgpath->path()); if (auto sh = cgpaint->shader()) { + if (cgpaint->isStroke()) { + // so we can clip against the "stroke" of the path + CGContextReplacePathWithStrokedPath(m_ctx); + } CGContextSaveGState(m_ctx); CGContextClip(m_ctx); sh->draw(m_ctx);