Chromium Code Reviews| Index: src/pdf/SkPDFDevice.cpp |
| diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp |
| index ced075ebf932fb2713e88ff9254a19f3db0c997b..13fc24cb1c6f435e0e76dd1bb23b56e76ba0d2eb 100644 |
| --- a/src/pdf/SkPDFDevice.cpp |
| +++ b/src/pdf/SkPDFDevice.cpp |
| @@ -1051,6 +1051,37 @@ void SkPDFDevice::drawSprite(const SkDraw& d, const SkBitmap& bitmap, |
| paint); |
| } |
| +// Create a PDF string. Maximum length (in bytes) is 65,535. |
| +// @param value A string value. |
|
tomhudson
2015/04/07 15:08:23
This parameter is now named 'input', not 'value'.
hal.canary
2015/04/07 17:32:57
Done.
|
| +// @param len The length of value. |
| +// @param wideChars Indicates if the top byte in value is significant and |
|
tomhudson
2015/04/07 15:08:23
Is the 'top' byte the first byte? If this is only
hal.canary
2015/04/07 17:32:57
Done.
|
| +// should be encoded (true) or not (false). |
|
tomhudson
2015/04/07 15:08:23
Nit: other comments need name of 'input' fixed.
hal.canary
2015/04/07 17:32:57
Done.
|
| +static SkString format_wide_string(const uint16_t* input, |
| + size_t len, |
| + bool wideChars) { |
| + SkASSERT(len <= 65535); |
| + if (wideChars) { |
| + static const char gHex[] = "0123456789ABCDEF"; |
| + SkString result(4 * len + 2); |
| + result[0] = '<'; |
| + for (size_t i = 0; i < len; i++) { |
| + result[4 * i + 1] = gHex[(input[i] >> 12) & 0xF]; |
| + result[4 * i + 2] = gHex[(input[i] >> 8) & 0xF]; |
| + result[4 * i + 3] = gHex[(input[i] >> 4) & 0xF]; |
| + result[4 * i + 4] = gHex[(input[i] ) & 0xF]; |
| + } |
| + result[4 * len + 1] = '>'; |
| + return result; |
| + } else { |
| + SkString tmp(len); |
| + for (size_t i = 0; i < len; i++) { |
| + SkASSERT(0 == input[i] >> 8); |
| + tmp[i] = static_cast<uint8_t>(input[i]); |
| + } |
| + return SkPDFString::FormatString(tmp.c_str(), tmp.size()); |
| + } |
| +} |
| + |
| void SkPDFDevice::drawText(const SkDraw& d, const void* text, size_t len, |
| SkScalar x, SkScalar y, const SkPaint& paint) { |
| NOT_IMPLEMENTED(paint.getMaskFilter() != NULL, false); |
| @@ -1090,8 +1121,8 @@ void SkPDFDevice::drawText(const SkDraw& d, const void* text, size_t len, |
| font, glyphIDsCopy.begin() + consumedGlyphCount, |
| availableGlyphs); |
| SkString encodedString = |
| - SkPDFString::FormatString(glyphIDsCopy.begin() + consumedGlyphCount, |
| - availableGlyphs, font->multiByteGlyphs()); |
| + format_wide_string(glyphIDsCopy.begin() + consumedGlyphCount, |
| + availableGlyphs, font->multiByteGlyphs()); |
| content.entry()->fContent.writeText(encodedString.c_str()); |
| consumedGlyphCount += availableGlyphs; |
| content.entry()->fContent.writeText(" Tj\n"); |
| @@ -1144,7 +1175,7 @@ void SkPDFDevice::drawPosText(const SkDraw& d, const void* text, size_t len, |
| align_text(glyphCacheProc, textPaint, glyphIDs + i, 1, &x, &y); |
| set_text_transform(x, y, textPaint.getTextSkewX(), &content.entry()->fContent); |
| SkString encodedString = |
| - SkPDFString::FormatString(&encodedValue, 1, font->multiByteGlyphs()); |
| + format_wide_string(&encodedValue, 1, font->multiByteGlyphs()); |
| content.entry()->fContent.writeText(encodedString.c_str()); |
| content.entry()->fContent.writeText(" Tj\n"); |
| } |