Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Side by Side Diff: src/pdf/SkPDFDevice.cpp

Issue 1064013003: SkPDF: SkPDFString is no longer aware of wide strings. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-04-07 (Tuesday) 10:52:40 EDT Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/pdf/SkPDFTypes.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkPDFDevice.h" 8 #include "SkPDFDevice.h"
9 9
10 #include "SkAnnotation.h" 10 #include "SkAnnotation.h"
(...skipping 1033 matching lines...) Expand 10 before | Expand all | Expand 10 after
1044 if (d.fClip->isEmpty()) { 1044 if (d.fClip->isEmpty()) {
1045 return; 1045 return;
1046 } 1046 }
1047 1047
1048 SkMatrix matrix; 1048 SkMatrix matrix;
1049 matrix.setTranslate(SkIntToScalar(x), SkIntToScalar(y)); 1049 matrix.setTranslate(SkIntToScalar(x), SkIntToScalar(y));
1050 this->internalDrawBitmap(matrix, d.fClipStack, *d.fClip, bitmap, NULL, 1050 this->internalDrawBitmap(matrix, d.fClipStack, *d.fClip, bitmap, NULL,
1051 paint); 1051 paint);
1052 } 1052 }
1053 1053
1054 // Create a PDF string. Maximum length (in bytes) is 65,535.
1055 // @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.
1056 // @param len The length of value.
1057 // @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.
1058 // 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.
1059 static SkString format_wide_string(const uint16_t* input,
1060 size_t len,
1061 bool wideChars) {
1062 SkASSERT(len <= 65535);
1063 if (wideChars) {
1064 static const char gHex[] = "0123456789ABCDEF";
1065 SkString result(4 * len + 2);
1066 result[0] = '<';
1067 for (size_t i = 0; i < len; i++) {
1068 result[4 * i + 1] = gHex[(input[i] >> 12) & 0xF];
1069 result[4 * i + 2] = gHex[(input[i] >> 8) & 0xF];
1070 result[4 * i + 3] = gHex[(input[i] >> 4) & 0xF];
1071 result[4 * i + 4] = gHex[(input[i] ) & 0xF];
1072 }
1073 result[4 * len + 1] = '>';
1074 return result;
1075 } else {
1076 SkString tmp(len);
1077 for (size_t i = 0; i < len; i++) {
1078 SkASSERT(0 == input[i] >> 8);
1079 tmp[i] = static_cast<uint8_t>(input[i]);
1080 }
1081 return SkPDFString::FormatString(tmp.c_str(), tmp.size());
1082 }
1083 }
1084
1054 void SkPDFDevice::drawText(const SkDraw& d, const void* text, size_t len, 1085 void SkPDFDevice::drawText(const SkDraw& d, const void* text, size_t len,
1055 SkScalar x, SkScalar y, const SkPaint& paint) { 1086 SkScalar x, SkScalar y, const SkPaint& paint) {
1056 NOT_IMPLEMENTED(paint.getMaskFilter() != NULL, false); 1087 NOT_IMPLEMENTED(paint.getMaskFilter() != NULL, false);
1057 if (paint.getMaskFilter() != NULL) { 1088 if (paint.getMaskFilter() != NULL) {
1058 // Don't pretend we support drawing MaskFilters, it makes for artifacts 1089 // Don't pretend we support drawing MaskFilters, it makes for artifacts
1059 // making text unreadable (e.g. same text twice when using CSS shadows). 1090 // making text unreadable (e.g. same text twice when using CSS shadows).
1060 return; 1091 return;
1061 } 1092 }
1062 SkPaint textPaint = calculate_text_paint(paint); 1093 SkPaint textPaint = calculate_text_paint(paint);
1063 ScopedContentEntry content(this, d, textPaint, true); 1094 ScopedContentEntry content(this, d, textPaint, true);
(...skipping 19 matching lines...) Expand all
1083 updateFont(textPaint, glyphIDs[consumedGlyphCount], content.entry()); 1114 updateFont(textPaint, glyphIDs[consumedGlyphCount], content.entry());
1084 SkPDFFont* font = content.entry()->fState.fFont; 1115 SkPDFFont* font = content.entry()->fState.fFont;
1085 1116
1086 int availableGlyphs = font->glyphsToPDFFontEncoding( 1117 int availableGlyphs = font->glyphsToPDFFontEncoding(
1087 glyphIDsCopy.begin() + consumedGlyphCount, 1118 glyphIDsCopy.begin() + consumedGlyphCount,
1088 numGlyphs - consumedGlyphCount); 1119 numGlyphs - consumedGlyphCount);
1089 fFontGlyphUsage->noteGlyphUsage( 1120 fFontGlyphUsage->noteGlyphUsage(
1090 font, glyphIDsCopy.begin() + consumedGlyphCount, 1121 font, glyphIDsCopy.begin() + consumedGlyphCount,
1091 availableGlyphs); 1122 availableGlyphs);
1092 SkString encodedString = 1123 SkString encodedString =
1093 SkPDFString::FormatString(glyphIDsCopy.begin() + consumedGlyphCount, 1124 format_wide_string(glyphIDsCopy.begin() + consumedGlyphCount,
1094 availableGlyphs, font->multiByteGlyphs()); 1125 availableGlyphs, font->multiByteGlyphs());
1095 content.entry()->fContent.writeText(encodedString.c_str()); 1126 content.entry()->fContent.writeText(encodedString.c_str());
1096 consumedGlyphCount += availableGlyphs; 1127 consumedGlyphCount += availableGlyphs;
1097 content.entry()->fContent.writeText(" Tj\n"); 1128 content.entry()->fContent.writeText(" Tj\n");
1098 } 1129 }
1099 content.entry()->fContent.writeText("ET\n"); 1130 content.entry()->fContent.writeText("ET\n");
1100 } 1131 }
1101 1132
1102 void SkPDFDevice::drawPosText(const SkDraw& d, const void* text, size_t len, 1133 void SkPDFDevice::drawPosText(const SkDraw& d, const void* text, size_t len,
1103 const SkScalar pos[], int scalarsPerPos, 1134 const SkScalar pos[], int scalarsPerPos,
1104 const SkPoint& offset, const SkPaint& paint) { 1135 const SkPoint& offset, const SkPaint& paint) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1137 } 1168 }
1138 } 1169 }
1139 1170
1140 fFontGlyphUsage->noteGlyphUsage(font, &encodedValue, 1); 1171 fFontGlyphUsage->noteGlyphUsage(font, &encodedValue, 1);
1141 SkScalar x = offset.x() + pos[i * scalarsPerPos]; 1172 SkScalar x = offset.x() + pos[i * scalarsPerPos];
1142 SkScalar y = offset.y() + (2 == scalarsPerPos ? pos[i * scalarsPerPos + 1] : 0); 1173 SkScalar y = offset.y() + (2 == scalarsPerPos ? pos[i * scalarsPerPos + 1] : 0);
1143 1174
1144 align_text(glyphCacheProc, textPaint, glyphIDs + i, 1, &x, &y); 1175 align_text(glyphCacheProc, textPaint, glyphIDs + i, 1, &x, &y);
1145 set_text_transform(x, y, textPaint.getTextSkewX(), &content.entry()->fCo ntent); 1176 set_text_transform(x, y, textPaint.getTextSkewX(), &content.entry()->fCo ntent);
1146 SkString encodedString = 1177 SkString encodedString =
1147 SkPDFString::FormatString(&encodedValue, 1, font->multiByteGlyphs()) ; 1178 format_wide_string(&encodedValue, 1, font->multiByteGlyphs());
1148 content.entry()->fContent.writeText(encodedString.c_str()); 1179 content.entry()->fContent.writeText(encodedString.c_str());
1149 content.entry()->fContent.writeText(" Tj\n"); 1180 content.entry()->fContent.writeText(" Tj\n");
1150 } 1181 }
1151 content.entry()->fContent.writeText("ET\n"); 1182 content.entry()->fContent.writeText("ET\n");
1152 } 1183 }
1153 1184
1154 void SkPDFDevice::drawVertices(const SkDraw& d, SkCanvas::VertexMode, 1185 void SkPDFDevice::drawVertices(const SkDraw& d, SkCanvas::VertexMode,
1155 int vertexCount, const SkPoint verts[], 1186 int vertexCount, const SkPoint verts[],
1156 const SkPoint texs[], const SkColor colors[], 1187 const SkPoint texs[], const SkColor colors[],
1157 SkXfermode* xmode, const uint16_t indices[], 1188 SkXfermode* xmode, const uint16_t indices[],
(...skipping 974 matching lines...) Expand 10 before | Expand all | Expand 10 after
2132 return; 2163 return;
2133 } 2164 }
2134 SkAutoTUnref<SkPDFObject> image(SkPDFBitmap::Create(fCanon, subsetBitmap)); 2165 SkAutoTUnref<SkPDFObject> image(SkPDFBitmap::Create(fCanon, subsetBitmap));
2135 if (!image) { 2166 if (!image) {
2136 return; 2167 return;
2137 } 2168 }
2138 2169
2139 SkPDFUtils::DrawFormXObject(this->addXObjectResource(image.get()), 2170 SkPDFUtils::DrawFormXObject(this->addXObjectResource(image.get()),
2140 &content.entry()->fContent); 2171 &content.entry()->fContent);
2141 } 2172 }
OLDNEW
« no previous file with comments | « no previous file | src/pdf/SkPDFTypes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698