| 110 | } |
| 111 | |
| 112 | static 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 | |
| 155 | static std::pair<float, float> FindMinMaxPathPosition( |
| 156 | const TextPathLayout& pathLayout, const std::vector<std::vector<GlyphHandle>>& glyphLines) { |
no test coverage detected