diff options
author | 2014-10-16 09:53:20 -0700 | |
---|---|---|
committer | 2014-10-16 09:53:21 -0700 | |
commit | 2f912f39b005b1725bd367c9dc5f1827cdde7be5 (patch) | |
tree | 850817fff4536986f3f9f389d65841ece7094875 /src/pdf/SkPDFDevice.cpp | |
parent | 4ba7686eb79a06b7165c007b41cd0cf7bb3ddb2d (diff) |
Const-correctness in PDF drawText() call
If SkPDFDevice::drawText is called with glyph encoding and a font with
cubic outlines (CFF or Type1) and a glyph code > 255 then it was
mutating the in(const) glyph codes in place. Instead, a copy is made.
BUG=skia:3019
Review URL: https://codereview.chromium.org/656143002
Diffstat (limited to 'src/pdf/SkPDFDevice.cpp')
-rw-r--r-- | src/pdf/SkPDFDevice.cpp | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp index 564fdc2123..736c50b9a6 100644 --- a/src/pdf/SkPDFDevice.cpp +++ b/src/pdf/SkPDFDevice.cpp @@ -1124,17 +1124,21 @@ void SkPDFDevice::drawText(const SkDraw& d, const void* text, size_t len, set_text_transform(x, y, textPaint.getTextSkewX(), &content.entry()->fContent); int consumedGlyphCount = 0; + + SkTDArray<uint16_t> glyphIDsCopy(glyphIDs, numGlyphs); + while (numGlyphs > consumedGlyphCount) { updateFont(textPaint, glyphIDs[consumedGlyphCount], content.entry()); SkPDFFont* font = content.entry()->fState.fFont; - //TODO: the const_cast here is a bug if the encoding started out as glyph encoding. - int availableGlyphs = - font->glyphsToPDFFontEncoding(const_cast<uint16_t*>(glyphIDs) + consumedGlyphCount, - numGlyphs - consumedGlyphCount); - fFontGlyphUsage->noteGlyphUsage(font, glyphIDs + consumedGlyphCount, - availableGlyphs); + + int availableGlyphs = font->glyphsToPDFFontEncoding( + glyphIDsCopy.begin() + consumedGlyphCount, + numGlyphs - consumedGlyphCount); + fFontGlyphUsage->noteGlyphUsage( + font, glyphIDsCopy.begin() + consumedGlyphCount, + availableGlyphs); SkString encodedString = - SkPDFString::FormatString(glyphIDs + consumedGlyphCount, + SkPDFString::FormatString(glyphIDsCopy.begin() + consumedGlyphCount, availableGlyphs, font->multiByteGlyphs()); content.entry()->fContent.writeText(encodedString.c_str()); consumedGlyphCount += availableGlyphs; |