MCPcopy Create free account
hub / github.com/Tencent/tgfx / onAsPaint

Method onAsPaint

src/svg/node/SVGPattern.cpp:131–159  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

129}
130
131bool SVGPattern::onAsPaint(const SVGRenderContext& context, Paint* paint) const {
132 PatternAttributes attrs;
133 const auto contentNode = this->resolveHref(context, &attrs);
134 auto lengthContext = context.lengthContext();
135 lengthContext.setBoundingBoxUnits(PatternUnits);
136 Rect tile = lengthContext.resolveRect(attrs.x.has_value() ? *attrs.x : SVGLength(0),
137 attrs.y.has_value() ? *attrs.y : SVGLength(0),
138 attrs.width.has_value() ? *attrs.width : SVGLength(0),
139 attrs.height.has_value() ? *attrs.height : SVGLength(0));
140
141 if (tile.isEmpty()) {
142 return false;
143 }
144
145 Recorder patternRecorder;
146 auto canvas = patternRecorder.beginRecording();
147 auto patternMatrix = attrs.patternTransform.value_or(Matrix::I());
148 canvas->concat(patternMatrix);
149 {
150 SVGRenderContext recordingContext(context, canvas, lengthContext);
151 contentNode->SVGContainer::onRender(recordingContext);
152 }
153 auto picture = patternRecorder.finishRecordingAsPicture();
154 auto shaderImage =
155 Image::MakeFrom(picture, static_cast<int>(tile.width()), static_cast<int>(tile.height()));
156 auto shader = Shader::MakeImageShader(shaderImage, TileMode::Repeat, TileMode::Repeat);
157 paint->setShader(shader);
158 return true;
159}
160
161} // namespace tgfx

Callers

nothing calls this directly

Calls 11

resolveHrefMethod · 0.95
SVGLengthClass · 0.85
setBoundingBoxUnitsMethod · 0.80
resolveRectMethod · 0.80
beginRecordingMethod · 0.80
setShaderMethod · 0.80
isEmptyMethod · 0.45
concatMethod · 0.45
widthMethod · 0.45
heightMethod · 0.45

Tested by

no test coverage detected