233{
237
239 font.getMetrics(&metrics);
240 std::unique_ptr<float[]> advances(new float[glyphCount]);
241 font.getWidths(
glyphs, glyphCount, advances.get());
242
243
244 size_t clusterStart = 0;
245 for (size_t glyphIndex = 0; glyphIndex < glyphCount; ++glyphIndex) {
246 if (glyphIndex + 1 < glyphCount
247 && clusters[glyphIndex] == clusters[glyphIndex + 1]) {
248 continue;
249 }
250 unsigned textBegin = clusters[glyphIndex];
251 unsigned textEnd = utf8TextBytes;
252 for (
size_t i = 0;
i < glyphCount; ++
i) {
253 if (clusters[
i] >= textEnd) {
254 textEnd = clusters[
i] + 1;
255 }
256 }
257 for (
size_t i = 0;
i < glyphCount; ++
i) {
258 if (clusters[
i] > textBegin && clusters[
i] < textEnd) {
259 textEnd = clusters[
i];
260 if (textEnd == textBegin + 1) { break; }
261 }
262 }
263 SkASSERT(glyphIndex + 1 > clusterStart);
264 unsigned clusterGlyphCount = glyphIndex + 1 - clusterStart;
265 const SkPoint* clusterGlyphPositions = &positions[clusterStart];
266 const float* clusterAdvances = &advances[clusterStart];
267 clusterStart = glyphIndex + 1;
268
270 for (
unsigned i = 1;
i < clusterGlyphCount; ++
i) {
272 }
273 if (textBegin + 1 == textEnd) {
274 cursors[textBegin] = clusterBox;
275 continue;
276 }
277 int textCount = textEnd - textBegin;
279 if (codePointCount == 1) {
280 cursors[textBegin] = clusterBox;
281 continue;
282 }
283
284 float width = clusterBox.
width() / codePointCount;
286 const char* ptr = utf8Text + textBegin;
287 const char*
end = utf8Text + textEnd;
288 float x = clusterBox.
left();
290 const char* nextPtr = ptr;
292 int firstIndex = ptr - utf8Text;
294 cursors[firstIndex] =
SkRect{
x, clusterBox.
top(), nextX, clusterBox.
bottom()};
296 ptr = nextPtr;
297 }
298 }
299}
SK_SPI SkUnichar NextUTF8(const char **ptr, const char *end)
SK_SPI int CountUTF8(const char *utf8, size_t byteLength)
font
Font Metadata and Metrics.
static SkRect selection_box(const SkFontMetrics &metrics, float advance, SkPoint pos)
constexpr float left() const
constexpr float top() const
constexpr float width() const
void join(const SkRect &r)
constexpr float bottom() const