From 2bd295e5a3c24240f6536a72675cc268efb5414e Mon Sep 17 00:00:00 2001 From: halcanary Date: Fri, 16 Sep 2016 08:15:56 -0700 Subject: SkPDF: fix unembeddable text drawn with positioning (broken in 6059dc3) BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2347183002 Review-Url: https://codereview.chromium.org/2347183002 --- src/pdf/SkPDFDevice.cpp | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp index 608d284bf2..1a1bd8a411 100644 --- a/src/pdf/SkPDFDevice.cpp +++ b/src/pdf/SkPDFDevice.cpp @@ -1023,22 +1023,44 @@ void SkPDFDevice::internalDrawText( if (!metrics) { return; } + int glyphCount = paint.textToGlyphs(sourceText, sourceByteCount, nullptr); + if (glyphCount <= 0) { + return; + } // TODO(halcanary): use metrics->fGlyphToUnicode to check Unicode mapping. const SkGlyphID maxGlyphID = metrics->fLastGlyphID; if (!SkPDFFont::CanEmbedTypeface(typeface, fDocument->canon())) { SkPath path; // https://bug.skia.org/3866 - paint.getTextPath(sourceText, sourceByteCount, - offset.x(), offset.y(), &path); + switch (positioning) { + case SkTextBlob::kDefault_Positioning: + srcPaint.getTextPath(sourceText, sourceByteCount, + offset.x(), offset.y(), &path); + break; + case SkTextBlob::kHorizontal_Positioning: { + SkAutoTMalloc positionsBuffer(glyphCount); + for (int i = 0; i < glyphCount; ++i) { + positionsBuffer[i] = offset + SkPoint{pos[i], 0}; + } + srcPaint.getPosTextPath(sourceText, sourceByteCount, + &positionsBuffer[0], &path); + break; + } + case SkTextBlob::kFull_Positioning: { + SkAutoTMalloc positionsBuffer(glyphCount); + for (int i = 0; i < glyphCount; ++i) { + positionsBuffer[i] = offset + SkPoint{pos[2 * i], pos[2 * i + 1]}; + } + srcPaint.getPosTextPath(sourceText, sourceByteCount, + &positionsBuffer[0], &path); + break; + } + } this->drawPath(d, path, srcPaint, &SkMatrix::I(), true); // Draw text transparently to make it copyable/searchable/accessable. draw_transparent_text(this, d, sourceText, sourceByteCount, offset.x(), offset.y(), paint); return; } - int glyphCount = paint.textToGlyphs(sourceText, sourceByteCount, nullptr); - if (glyphCount <= 0) { - return; - } SkAutoSTMalloc<128, SkGlyphID> glyphStorage; const SkGlyphID* glyphs = nullptr; if (paint.getTextEncoding() == SkPaint::kGlyphID_TextEncoding) { -- cgit v1.2.3