OLD | NEW |
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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 } | 124 } |
125 | 125 |
126 static int max_glyphid_for_typeface(SkTypeface* typeface) { | 126 static int max_glyphid_for_typeface(SkTypeface* typeface) { |
127 SkAutoResolveDefaultTypeface autoResolve(typeface); | 127 SkAutoResolveDefaultTypeface autoResolve(typeface); |
128 typeface = autoResolve.get(); | 128 typeface = autoResolve.get(); |
129 return typeface->countGlyphs() - 1; | 129 return typeface->countGlyphs() - 1; |
130 } | 130 } |
131 | 131 |
132 typedef SkAutoSTMalloc<128, uint16_t> SkGlyphStorage; | 132 typedef SkAutoSTMalloc<128, uint16_t> SkGlyphStorage; |
133 | 133 |
134 static size_t force_glyph_encoding(const SkPaint& paint, const void* text, | 134 static int force_glyph_encoding(const SkPaint& paint, const void* text, |
135 size_t len, SkGlyphStorage* storage, | 135 size_t len, SkGlyphStorage* storage, |
136 uint16_t** glyphIDs) { | 136 uint16_t** glyphIDs) { |
137 // Make sure we have a glyph id encoding. | 137 // Make sure we have a glyph id encoding. |
138 if (paint.getTextEncoding() != SkPaint::kGlyphID_TextEncoding) { | 138 if (paint.getTextEncoding() != SkPaint::kGlyphID_TextEncoding) { |
139 size_t numGlyphs = paint.textToGlyphs(text, len, NULL); | 139 int numGlyphs = paint.textToGlyphs(text, len, NULL); |
140 storage->reset(numGlyphs); | 140 storage->reset(numGlyphs); |
141 paint.textToGlyphs(text, len, storage->get()); | 141 paint.textToGlyphs(text, len, storage->get()); |
142 *glyphIDs = storage->get(); | 142 *glyphIDs = storage->get(); |
143 return numGlyphs; | 143 return numGlyphs; |
144 } | 144 } |
145 | 145 |
146 // For user supplied glyph ids we need to validate them. | 146 // For user supplied glyph ids we need to validate them. |
147 SkASSERT((len & 1) == 0); | 147 SkASSERT((len & 1) == 0); |
148 size_t numGlyphs = len / 2; | 148 int numGlyphs = SkToInt(len / 2); |
149 const uint16_t* input = | 149 const uint16_t* input = |
150 reinterpret_cast<uint16_t*>(const_cast<void*>((text))); | 150 reinterpret_cast<uint16_t*>(const_cast<void*>((text))); |
151 | 151 |
152 int maxGlyphID = max_glyphid_for_typeface(paint.getTypeface()); | 152 int maxGlyphID = max_glyphid_for_typeface(paint.getTypeface()); |
153 size_t validated; | 153 int validated; |
154 for (validated = 0; validated < numGlyphs; ++validated) { | 154 for (validated = 0; validated < numGlyphs; ++validated) { |
155 if (input[validated] > maxGlyphID) { | 155 if (input[validated] > maxGlyphID) { |
156 break; | 156 break; |
157 } | 157 } |
158 } | 158 } |
159 if (validated >= numGlyphs) { | 159 if (validated >= numGlyphs) { |
160 *glyphIDs = reinterpret_cast<uint16_t*>(const_cast<void*>((text))); | 160 *glyphIDs = reinterpret_cast<uint16_t*>(const_cast<void*>((text))); |
161 return numGlyphs; | 161 return numGlyphs; |
162 } | 162 } |
163 | 163 |
164 // Silently drop anything out of range. | 164 // Silently drop anything out of range. |
165 storage->reset(numGlyphs); | 165 storage->reset(numGlyphs); |
166 if (validated > 0) { | 166 if (validated > 0) { |
167 memcpy(storage->get(), input, validated * sizeof(uint16_t)); | 167 memcpy(storage->get(), input, validated * sizeof(uint16_t)); |
168 } | 168 } |
169 | 169 |
170 for (size_t i = validated; i < numGlyphs; ++i) { | 170 for (int i = validated; i < numGlyphs; ++i) { |
171 storage->get()[i] = input[i]; | 171 storage->get()[i] = input[i]; |
172 if (input[i] > maxGlyphID) { | 172 if (input[i] > maxGlyphID) { |
173 storage->get()[i] = 0; | 173 storage->get()[i] = 0; |
174 } | 174 } |
175 } | 175 } |
176 *glyphIDs = storage->get(); | 176 *glyphIDs = storage->get(); |
177 return numGlyphs; | 177 return numGlyphs; |
178 } | 178 } |
179 | 179 |
180 static void set_text_transform(SkScalar x, SkScalar y, SkScalar textSkewX, | 180 static void set_text_transform(SkScalar x, SkScalar y, SkScalar textSkewX, |
(...skipping 938 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1119 return; | 1119 return; |
1120 } | 1120 } |
1121 SkPaint textPaint = calculate_text_paint(paint); | 1121 SkPaint textPaint = calculate_text_paint(paint); |
1122 ScopedContentEntry content(this, d, textPaint, true); | 1122 ScopedContentEntry content(this, d, textPaint, true); |
1123 if (!content.entry()) { | 1123 if (!content.entry()) { |
1124 return; | 1124 return; |
1125 } | 1125 } |
1126 | 1126 |
1127 SkGlyphStorage storage(0); | 1127 SkGlyphStorage storage(0); |
1128 uint16_t* glyphIDs = NULL; | 1128 uint16_t* glyphIDs = NULL; |
1129 size_t numGlyphs = force_glyph_encoding(paint, text, len, &storage, | 1129 int numGlyphs = force_glyph_encoding(paint, text, len, &storage, &glyphIDs); |
1130 &glyphIDs); | |
1131 textPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 1130 textPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
1132 | 1131 |
1133 SkDrawCacheProc glyphCacheProc = textPaint.getDrawCacheProc(); | 1132 SkDrawCacheProc glyphCacheProc = textPaint.getDrawCacheProc(); |
1134 align_text(glyphCacheProc, textPaint, glyphIDs, numGlyphs, &x, &y); | 1133 align_text(glyphCacheProc, textPaint, glyphIDs, numGlyphs, &x, &y); |
1135 content.entry()->fContent.writeText("BT\n"); | 1134 content.entry()->fContent.writeText("BT\n"); |
1136 set_text_transform(x, y, textPaint.getTextSkewX(), | 1135 set_text_transform(x, y, textPaint.getTextSkewX(), |
1137 &content.entry()->fContent); | 1136 &content.entry()->fContent); |
1138 size_t consumedGlyphCount = 0; | 1137 int consumedGlyphCount = 0; |
1139 while (numGlyphs > consumedGlyphCount) { | 1138 while (numGlyphs > consumedGlyphCount) { |
1140 updateFont(textPaint, glyphIDs[consumedGlyphCount], content.entry()); | 1139 updateFont(textPaint, glyphIDs[consumedGlyphCount], content.entry()); |
1141 SkPDFFont* font = content.entry()->fState.fFont; | 1140 SkPDFFont* font = content.entry()->fState.fFont; |
1142 size_t availableGlyphs = | 1141 int availableGlyphs = |
1143 font->glyphsToPDFFontEncoding(glyphIDs + consumedGlyphCount, | 1142 font->glyphsToPDFFontEncoding(glyphIDs + consumedGlyphCount, |
1144 numGlyphs - consumedGlyphCount); | 1143 numGlyphs - consumedGlyphCount); |
1145 fFontGlyphUsage->noteGlyphUsage(font, glyphIDs + consumedGlyphCount, | 1144 fFontGlyphUsage->noteGlyphUsage(font, glyphIDs + consumedGlyphCount, |
1146 availableGlyphs); | 1145 availableGlyphs); |
1147 SkString encodedString = | 1146 SkString encodedString = |
1148 SkPDFString::FormatString(glyphIDs + consumedGlyphCount, | 1147 SkPDFString::FormatString(glyphIDs + consumedGlyphCount, |
1149 availableGlyphs, font->multiByteGlyphs()); | 1148 availableGlyphs, font->multiByteGlyphs()); |
1150 content.entry()->fContent.writeText(encodedString.c_str()); | 1149 content.entry()->fContent.writeText(encodedString.c_str()); |
1151 consumedGlyphCount += availableGlyphs; | 1150 consumedGlyphCount += availableGlyphs; |
1152 content.entry()->fContent.writeText(" Tj\n"); | 1151 content.entry()->fContent.writeText(" Tj\n"); |
(...skipping 1150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2303 return; | 2302 return; |
2304 } | 2303 } |
2305 | 2304 |
2306 SkPDFUtils::DrawFormXObject(this->addXObjectResource(image.get()), | 2305 SkPDFUtils::DrawFormXObject(this->addXObjectResource(image.get()), |
2307 &content.entry()->fContent); | 2306 &content.entry()->fContent); |
2308 } | 2307 } |
2309 | 2308 |
2310 bool SkPDFDevice::allowImageFilter(const SkImageFilter*) { | 2309 bool SkPDFDevice::allowImageFilter(const SkImageFilter*) { |
2311 return false; | 2310 return false; |
2312 } | 2311 } |
OLD | NEW |