breakText can be "revived" via
const SkFont* skfont = AsFont(font);
SkTextEncoding skencoding = (SkTextEncoding)encoding;
const SkPaint* skpaint = AsPaint(paint);
if (0 == byteLength || 0 >= maxWidth) {
if (measuredWidth) {
*measuredWidth = 0;
}
return 0;
}
if (0 == skfont->getSize()) {
if (measuredWidth) {
*measuredWidth = 0;
}
return byteLength;
}
SkASSERT(text != nullptr);
auto [strikeSpec, scale] = SkStrikeSpec::MakeCanonicalized(*skfont, skpaint);
SkBulkGlyphMetrics metrics{ strikeSpec };
// adjust max instead of each glyph
if (scale) {
maxWidth /= scale;
}
SkScalar width = 0;
const char* start = (const char*)text;
const char* stop = start + byteLength;
while (start < stop) {
const char* curr = start;
// read the glyph and move the pointer
SkGlyphID glyphID;
if (skencoding == SkTextEncoding::kGlyphID) {
auto glyphs = (const uint16_t*)start;
glyphID = *glyphs;
glyphs++;
start = (const char*)glyphs;
}
else {
auto t = (const void*)start;
auto unichar = SkUTFN_Next(skencoding, &t, stop);
start = (const char*)t;
glyphID = skfont->getTypefaceOrDefault()->unicharToGlyph(unichar);
}
auto glyph = metrics.glyph(glyphID);
SkScalar x = glyph->advanceX();
if ((width += x) > maxWidth) {
width -= x;
start = curr;
break;
}
}
if (measuredWidth) {
if (scale) {
width *= scale;
}
*measuredWidth = width;
}
// return the number of bytes measured
return start - stop + byteLength;