Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Unified Diff: tools/SkShaper_primitive.cpp

Issue 2332473003: SkPDF: SkShaper_primitive uses new textblob API (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « BUILD.gn ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/SkShaper_primitive.cpp
diff --git a/tools/SkShaper_primitive.cpp b/tools/SkShaper_primitive.cpp
index 65081b3447ac342e05a485282439f01353928e0c..b1652852872b168e4427b011abdae66ccf69e3ef 100644
--- a/tools/SkShaper_primitive.cpp
+++ b/tools/SkShaper_primitive.cpp
@@ -21,6 +21,14 @@ SkShaper::~SkShaper() {}
bool SkShaper::good() const { return true; }
+// This example only uses public API, so we don't use SkUTF8_NextUnichar.
+unsigned utf8_lead_byte_to_count(const char* ptr) {
+ uint8_t c = *(const uint8_t*)ptr;
+ SkASSERT(c <= 0xF7);
+ SkASSERT((c & 0xC0) != 0x80);
+ return (((0xE5 << 24) >> ((unsigned)c >> 4 << 1)) & 3) + 1;
+}
+
SkScalar SkShaper::shape(SkTextBlobBuilder* builder,
const SkPaint& srcPaint,
const char* utf8text,
@@ -36,8 +44,16 @@ SkScalar SkShaper::shape(SkTextBlobBuilder* builder,
SkRect bounds;
(void)paint.measureText(utf8text, textBytes, &bounds);
paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
- const SkTextBlobBuilder::RunBuffer& runBuffer = builder->allocRunPosH(
- paint, glyphCount, point.y(), &bounds);
+ const SkTextBlobBuilder::RunBuffer& runBuffer =
+ builder->allocRunTextPosH(paint, glyphCount, point.y(), textBytes, SkString(), &bounds);
+ memcpy(runBuffer.utf8text, utf8text, textBytes);
+ const char* txtPtr = utf8text;
+ for (int i = 0; i < glyphCount; ++i) {
+ // Each charater maps to exactly one glyph via SkGlyphCache::unicharToGlyph().
+ runBuffer.clusters[i] = SkToU32(txtPtr - utf8text);
+ txtPtr += utf8_lead_byte_to_count(txtPtr);
+ SkASSERT(txtPtr <= utf8text + textBytes);
+ }
paint.setTextEncoding(SkPaint::kUTF8_TextEncoding);
(void)paint.textToGlyphs(utf8text, textBytes, runBuffer.glyphs);
(void)paint.getTextWidths(utf8text, textBytes, runBuffer.pos);
« no previous file with comments | « BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698