diff --git a/src/svg/SkSVGDevice.cpp b/src/svg/SkSVGDevice.cpp index 59a94364d3..ac2222eb58 100644 --- a/src/svg/SkSVGDevice.cpp +++ b/src/svg/SkSVGDevice.cpp @@ -404,8 +404,11 @@ void SkSVGDevice::AutoElement::addGradientShaderResources(const SkShader* shader Resources* resources) { SkShader::GradientInfo grInfo; memset(&grInfo, 0, sizeof(grInfo)); - if (SkShader::kLinear_GradientType != shader->asAGradient(&grInfo)) { - // TODO: non-linear gradient support + const auto gradient_type = shader->asAGradient(&grInfo); + + if (gradient_type != SkShader::kColor_GradientType && + gradient_type != SkShader::kLinear_GradientType) { + // TODO: other gradient support return; } @@ -419,7 +422,10 @@ void SkSVGDevice::AutoElement::addGradientShaderResources(const SkShader* shader SkASSERT(grInfo.fColorCount <= grColors.count()); SkASSERT(grInfo.fColorCount <= grOffsets.count()); - resources->fPaintServer.printf("url(#%s)", addLinearGradientDef(grInfo, shader).c_str()); + SkASSERT(grColors.size() > 0); + resources->fPaintServer = gradient_type == SkShader::kColor_GradientType + ? svg_color(grColors[0]) + : SkStringPrintf("url(#%s)", addLinearGradientDef(grInfo, shader).c_str()); } void SkSVGDevice::AutoElement::addColorFilterResources(const SkColorFilter& cf, diff --git a/tests/SVGDeviceTest.cpp b/tests/SVGDeviceTest.cpp index 547d7d82b4..0463ee69d1 100644 --- a/tests/SVGDeviceTest.cpp +++ b/tests/SVGDeviceTest.cpp @@ -588,4 +588,24 @@ DEF_TEST(SVGDevice_relative_path_encoding, reporter) { REPORTER_ASSERT(reporter, !strcmp(d, "m100 50l100 0l0 100l-100 -100Z")); } +DEF_TEST(SVGDevice_color_shader, reporter) { + SkDOM dom; + { + auto svgCanvas = MakeDOMCanvas(&dom); + + SkPaint paint; + paint.setShader(SkShaders::Color(0xffffff00)); + + svgCanvas->drawCircle(100, 100, 100, paint); + } + + const auto* rootElement = dom.finishParsing(); + REPORTER_ASSERT(reporter, rootElement, "root element not found"); + const auto* ellipseElement = dom.getFirstChild(rootElement, "ellipse"); + REPORTER_ASSERT(reporter, ellipseElement, "ellipse element not found"); + const auto* fill = dom.findAttr(ellipseElement, "fill"); + REPORTER_ASSERT(reporter, fill, "fill attribute not found"); + REPORTER_ASSERT(reporter, !strcmp(fill, "yellow")); +} + #endif