xref: /aosp_15_r20/external/skia/modules/svg/src/SkSVGClipPath.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2016 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #include "modules/svg/include/SkSVGClipPath.h"
9 
10 #include "include/core/SkM44.h"
11 #include "include/core/SkMatrix.h"
12 #include "modules/svg/include/SkSVGAttributeParser.h"
13 #include "modules/svg/include/SkSVGRenderContext.h"
14 
SkSVGClipPath()15 SkSVGClipPath::SkSVGClipPath() : INHERITED(SkSVGTag::kClipPath) {}
16 
parseAndSetAttribute(const char * n,const char * v)17 bool SkSVGClipPath::parseAndSetAttribute(const char* n, const char* v) {
18     return INHERITED::parseAndSetAttribute(n, v) ||
19            this->setClipPathUnits(
20                 SkSVGAttributeParser::parse<SkSVGObjectBoundingBoxUnits>("clipPathUnits", n, v));
21 }
22 
resolveClip(const SkSVGRenderContext & ctx) const23 SkPath SkSVGClipPath::resolveClip(const SkSVGRenderContext& ctx) const {
24     auto clip = this->asPath(ctx);
25 
26     const auto obbt = ctx.transformForCurrentOBB(fClipPathUnits);
27     const auto m = SkMatrix::Translate(obbt.offset.x, obbt.offset.y)
28                  * SkMatrix::Scale(obbt.scale.x, obbt.scale.y);
29     clip.transform(m);
30 
31     return clip;
32 }
33