SkPDF: SkShaper_primitive uses new textblob API
This will enable me to test the new API in unit tests without depending on HarfBuzz (after https://crrev.com/2322403002 lands). TBR= BUG=skia:5434 Review-Url: https://codereview.chromium.org/2332473003
This commit is contained in:
parent
4a56318d4c
commit
3eee9d941e
12
BUILD.gn
12
BUILD.gn
@ -786,7 +786,7 @@ if (skia_enable_tools) {
|
||||
}
|
||||
|
||||
if (current_cpu != "mipsel") { # Clang 3.8 crashes while compiling hb-icu.cc for mipsel.
|
||||
executable("sktexttopdf") {
|
||||
executable("sktexttopdf-hb") {
|
||||
sources = [
|
||||
"tools/SkShaper_harfbuzz.cpp",
|
||||
"tools/using_skia_and_harfbuzz.cpp",
|
||||
@ -798,4 +798,14 @@ if (skia_enable_tools) {
|
||||
testonly = true
|
||||
}
|
||||
}
|
||||
executable("sktexttopdf") {
|
||||
sources = [
|
||||
"tools/SkShaper_primitive.cpp",
|
||||
"tools/using_skia_and_harfbuzz.cpp",
|
||||
]
|
||||
deps = [
|
||||
":skia",
|
||||
]
|
||||
testonly = true
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user