diff options
author | halcanary <halcanary@google.com> | 2016-09-09 05:34:55 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-09-09 05:34:55 -0700 |
commit | e06ca96174b99d451db17540a8df540035ab020d (patch) | |
tree | bde00b3d0f6af6eb2891764b1ba72fdbf9acdea7 /src/pdf | |
parent | 426a2459290a57bf32151f042fe5cd67da61d02f (diff) |
SkPDF: implement drawTextBlob()
Pass new fields from https://skia.googlesource.com/skia/+/4f0a23a into
SkPDFDevice::internalDrawText() (a later CL will use
them for /ActualText.
No change in PDF output.
BUG=skia:5434
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2300393002
Review-Url: https://codereview.chromium.org/2300393002
Diffstat (limited to 'src/pdf')
-rw-r--r-- | src/pdf/SkPDFDevice.cpp | 41 | ||||
-rw-r--r-- | src/pdf/SkPDFDevice.h | 6 |
2 files changed, 41 insertions, 6 deletions
diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp index 4dd21da7f0..9635f54367 100644 --- a/src/pdf/SkPDFDevice.cpp +++ b/src/pdf/SkPDFDevice.cpp @@ -6,12 +6,14 @@ */ #include "SkPDFDevice.h" + #include "SkAnnotationKeys.h" #include "SkBitmapDevice.h" #include "SkBitmapKey.h" #include "SkColor.h" #include "SkColorFilter.h" #include "SkDraw.h" +#include "SkDrawFilter.h" #include "SkGlyphCache.h" #include "SkMakeUnique.h" #include "SkPath.h" @@ -32,8 +34,9 @@ #include "SkScopeExit.h" #include "SkString.h" #include "SkSurface.h" -#include "SkTextFormatParams.h" #include "SkTemplates.h" +#include "SkTextBlobRunIterator.h" +#include "SkTextFormatParams.h" #include "SkXfermodeInterpretation.h" #define DPI_FOR_RASTER_SCALE_ONE 72 @@ -969,7 +972,8 @@ static void draw_transparent_text(SkPDFDevice* device, void SkPDFDevice::internalDrawText( const SkDraw& d, const void* sourceText, size_t sourceByteCount, const SkScalar pos[], SkTextBlob::GlyphPositioning positioning, - SkPoint offset, const SkPaint& srcPaint) { + SkPoint offset, const SkPaint& srcPaint, const uint32_t* clusters, + uint32_t textByteLength, const char* utf8Text) { NOT_IMPLEMENTED(srcPaint.getMaskFilter() != nullptr, false); if (srcPaint.getMaskFilter() != nullptr) { // Don't pretend we support drawing MaskFilters, it makes for artifacts @@ -984,6 +988,19 @@ void SkPDFDevice::internalDrawText( // https://bug.skia.org/5665 return; } + // TODO(halcanary): implement /ActualText with these values. + (void)clusters; + (void)textByteLength; + (void)utf8Text; + if (textByteLength > 0) { + SkASSERT(clusters); + SkASSERT(utf8Text); + SkASSERT(srcPaint.getTextEncoding() == SkPaint::kGlyphID_TextEncoding); + } else { + SkASSERT(nullptr == clusters); + SkASSERT(nullptr == utf8Text); + } + SkPaint paint = calculate_text_paint(srcPaint); replace_srcmode_on_opaque_paint(&paint); if (!paint.getTypeface()) { @@ -1124,14 +1141,30 @@ void SkPDFDevice::internalDrawText( void SkPDFDevice::drawText(const SkDraw& d, const void* text, size_t len, SkScalar x, SkScalar y, const SkPaint& paint) { this->internalDrawText(d, text, len, nullptr, SkTextBlob::kDefault_Positioning, - SkPoint{x, y}, paint); + SkPoint{x, y}, paint, nullptr, 0, nullptr); } void SkPDFDevice::drawPosText(const SkDraw& d, const void* text, size_t len, const SkScalar pos[], int scalarsPerPos, const SkPoint& offset, const SkPaint& paint) { this->internalDrawText(d, text, len, pos, (SkTextBlob::GlyphPositioning)scalarsPerPos, - offset, paint); + offset, paint, nullptr, 0, nullptr); +} + +void SkPDFDevice::drawTextBlob(const SkDraw& draw, const SkTextBlob* blob, SkScalar x, SkScalar y, + const SkPaint &paint, SkDrawFilter* drawFilter) { + for (SkTextBlobRunIterator it(blob); !it.done(); it.next()) { + SkPaint runPaint(paint); + it.applyFontToPaint(&runPaint); + if (drawFilter && !drawFilter->filter(&runPaint, SkDrawFilter::kText_Type)) { + continue; + } + runPaint.setFlags(this->filterTextFlags(runPaint)); + SkPoint offset = it.offset() + SkPoint{x, y}; + this->internalDrawText(draw, it.glyphs(), sizeof(SkGlyphID) * it.glyphCount(), + it.pos(), it.positioning(), offset, runPaint, + it.clusters(), it.textSize(), it.text()); + } } void SkPDFDevice::drawVertices(const SkDraw& d, SkCanvas::VertexMode, diff --git a/src/pdf/SkPDFDevice.h b/src/pdf/SkPDFDevice.h index 79b272d9ac..344fcb5e46 100644 --- a/src/pdf/SkPDFDevice.h +++ b/src/pdf/SkPDFDevice.h @@ -111,6 +111,8 @@ public: void drawPosText(const SkDraw&, const void* text, size_t len, const SkScalar pos[], int scalarsPerPos, const SkPoint& offset, const SkPaint&) override; + void drawTextBlob(const SkDraw&, const SkTextBlob*, SkScalar x, SkScalar y, + const SkPaint &, SkDrawFilter*) override; void drawVertices(const SkDraw&, SkCanvas::VertexMode, int vertexCount, const SkPoint verts[], const SkPoint texs[], const SkColor colors[], @@ -286,8 +288,8 @@ private: void internalDrawText(const SkDraw&, const void*, size_t, const SkScalar pos[], - SkTextBlob::GlyphPositioning, SkPoint, const SkPaint&); - + SkTextBlob::GlyphPositioning, SkPoint, const SkPaint&, + const uint32_t*, uint32_t, const char*); void internalDrawPaint(const SkPaint& paint, ContentEntry* contentEntry); |