MCPcopy Create free account
hub / github.com/Tencent/libpag / CreatePath

Function CreatePath

src/rendering/renderers/TextPathRender.cpp:112–153  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

110}
111
112static std::unique_ptr<tgfx::PathMeasure> CreatePath(const PathData& pathData, float first,
113 float end) {
114 auto pathMeasure = tgfx::PathMeasure::MakeFrom(ToPath(pathData));
115 auto pathLength = pathMeasure->getLength();
116
117 if (pathMeasure->isClosed() || (first >= 0 && end <= pathLength)) {
118 return pathMeasure;
119 }
120
121 auto newPathData = pathData;
122
123 if (first < 0) {
124 tgfx::Point pos{};
125 tgfx::Point tan{};
126 newPathData.clear();
127
128 auto remainLength = abs(first);
129 // 获取起点的法线角度
130 if (pathMeasure->getPosTan(0, &pos, &tan)) {
131 auto x = pos.x - remainLength * tan.x;
132 auto y = pos.y - remainLength * tan.y;
133
134 newPathData.moveTo(x, y);
135 newPathData.lineTo(pos.x, pos.y);
136 AppendPathData(newPathData, pathData);
137 }
138 }
139
140 if (end > pathLength) {
141 tgfx::Point pos{};
142 tgfx::Point tan{};
143
144 auto remainLength = end - pathLength;
145 // 获取最后一点的法线角度
146 if (pathMeasure->getPosTan(pathLength, &pos, &tan)) {
147 auto x = pos.x + remainLength * tan.x;
148 auto y = pos.y + remainLength * tan.y;
149 newPathData.lineTo(x, y);
150 }
151 }
152 return tgfx::PathMeasure::MakeFrom(ToPath(newPathData));
153}
154
155static std::pair<float, float> FindMinMaxPathPosition(
156 const TextPathLayout& pathLayout, const std::vector<std::vector<GlyphHandle>>& glyphLines) {

Callers 1

applyToGlyphsMethod · 0.85

Calls 7

ToPathFunction · 0.85
AppendPathDataFunction · 0.85
isClosedMethod · 0.80
moveToMethod · 0.80
lineToMethod · 0.80
getLengthMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected