| 129 | } |
| 130 | |
| 131 | bool 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 |
nothing calls this directly
no test coverage detected