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 #include "SkAnnotationKeys.h" | 9 #include "SkAnnotationKeys.h" |
10 #include "SkBitmapDevice.h" | 10 #include "SkBitmapDevice.h" |
(...skipping 1252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1263 SkPaint textPaint = calculate_text_paint(paint); | 1263 SkPaint textPaint = calculate_text_paint(paint); |
1264 ScopedContentEntry content(this, d, textPaint, true); | 1264 ScopedContentEntry content(this, d, textPaint, true); |
1265 if (!content.entry()) { | 1265 if (!content.entry()) { |
1266 return; | 1266 return; |
1267 } | 1267 } |
1268 | 1268 |
1269 SkGlyphStorage storage(0); | 1269 SkGlyphStorage storage(0); |
1270 const uint16_t* glyphIDs = nullptr; | 1270 const uint16_t* glyphIDs = nullptr; |
1271 size_t numGlyphs = force_glyph_encoding(paint, text, len, &storage, &glyphID
s); | 1271 size_t numGlyphs = force_glyph_encoding(paint, text, len, &storage, &glyphID
s); |
1272 textPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 1272 textPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
| 1273 SkAutoGlyphCache autoGlyphCache(textPaint, nullptr, nullptr); |
1273 | 1274 |
1274 content.entry()->fContent.writeText("BT\n"); | 1275 content.entry()->fContent.writeText("BT\n"); |
1275 this->updateFont(textPaint, glyphIDs[0], content.entry()); | 1276 this->updateFont(textPaint, glyphIDs[0], content.entry()); |
1276 GlyphPositioner glyphPositioner(&content.entry()->fContent, | 1277 GlyphPositioner glyphPositioner(&content.entry()->fContent, |
1277 textPaint.getTextSkewX(), | 1278 textPaint.getTextSkewX(), |
1278 content.entry()->fState.fFont->multiByteGlyp
hs()); | 1279 content.entry()->fState.fFont->multiByteGlyp
hs()); |
1279 SkPDFGlyphSetMap* fontGlyphUsage = fDocument->getGlyphUsage(); | 1280 SkPDFGlyphSetMap* fontGlyphUsage = fDocument->getGlyphUsage(); |
1280 for (size_t i = 0; i < numGlyphs; i++) { | 1281 for (size_t i = 0; i < numGlyphs; i++) { |
1281 SkPDFFont* font = content.entry()->fState.fFont; | 1282 SkPDFFont* font = content.entry()->fState.fFont; |
1282 uint16_t encodedValue = glyphIDs[i]; | 1283 uint16_t encodedValue = glyphIDs[i]; |
| 1284 SkScalar advanceWidth = autoGlyphCache->getGlyphIDAdvance(encodedValue).
fAdvanceX; |
1283 if (font->glyphsToPDFFontEncoding(&encodedValue, 1) != 1) { | 1285 if (font->glyphsToPDFFontEncoding(&encodedValue, 1) != 1) { |
1284 // The current pdf font cannot encode the current glyph. | 1286 // The current pdf font cannot encode the current glyph. |
1285 // Try to get a pdf font which can encode the current glyph. | 1287 // Try to get a pdf font which can encode the current glyph. |
1286 glyphPositioner.flush(); | 1288 glyphPositioner.flush(); |
1287 this->updateFont(textPaint, glyphIDs[i], content.entry()); | 1289 this->updateFont(textPaint, glyphIDs[i], content.entry()); |
1288 font = content.entry()->fState.fFont; | 1290 font = content.entry()->fState.fFont; |
1289 glyphPositioner.setWideChars(font->multiByteGlyphs()); | 1291 glyphPositioner.setWideChars(font->multiByteGlyphs()); |
1290 if (font->glyphsToPDFFontEncoding(&encodedValue, 1) != 1) { | 1292 if (font->glyphsToPDFFontEncoding(&encodedValue, 1) != 1) { |
1291 SkDEBUGFAIL("PDF could not encode glyph."); | 1293 SkDEBUGFAIL("PDF could not encode glyph."); |
1292 continue; | 1294 continue; |
1293 } | 1295 } |
1294 } | 1296 } |
1295 | |
1296 fontGlyphUsage->noteGlyphUsage(font, &encodedValue, 1); | 1297 fontGlyphUsage->noteGlyphUsage(font, &encodedValue, 1); |
1297 SkScalar x = offset.x() + pos[i * scalarsPerPos]; | 1298 SkScalar x = offset.x() + pos[i * scalarsPerPos]; |
1298 SkScalar y = offset.y() + (2 == scalarsPerPos ? pos[i * scalarsPerPos +
1] : 0); | 1299 SkScalar y = offset.y() + (2 == scalarsPerPos ? pos[i * scalarsPerPos +
1] : 0); |
1299 align_text(textPaint, glyphIDs + i, 1, &x, &y); | 1300 align_text(textPaint, glyphIDs + i, 1, &x, &y); |
1300 | 1301 |
1301 SkScalar advanceWidth = textPaint.measureText(&encodedValue, sizeof(uint
16_t)); | |
1302 glyphPositioner.writeGlyph(x, y, advanceWidth, encodedValue); | 1302 glyphPositioner.writeGlyph(x, y, advanceWidth, encodedValue); |
1303 } | 1303 } |
1304 glyphPositioner.flush(); // Must flush before ending text object. | 1304 glyphPositioner.flush(); // Must flush before ending text object. |
1305 content.entry()->fContent.writeText("ET\n"); | 1305 content.entry()->fContent.writeText("ET\n"); |
1306 } | 1306 } |
1307 | 1307 |
1308 void SkPDFDevice::drawVertices(const SkDraw& d, SkCanvas::VertexMode, | 1308 void SkPDFDevice::drawVertices(const SkDraw& d, SkCanvas::VertexMode, |
1309 int vertexCount, const SkPoint verts[], | 1309 int vertexCount, const SkPoint verts[], |
1310 const SkPoint texs[], const SkColor colors[], | 1310 const SkPoint texs[], const SkColor colors[], |
1311 SkXfermode* xmode, const uint16_t indices[], | 1311 SkXfermode* xmode, const uint16_t indices[], |
(...skipping 920 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2232 } | 2232 } |
2233 | 2233 |
2234 sk_sp<SkSpecialImage> SkPDFDevice::makeSpecial(const SkImage* image) { | 2234 sk_sp<SkSpecialImage> SkPDFDevice::makeSpecial(const SkImage* image) { |
2235 return SkSpecialImage::MakeFromImage(SkIRect::MakeWH(image->width(), image->
height()), | 2235 return SkSpecialImage::MakeFromImage(SkIRect::MakeWH(image->width(), image->
height()), |
2236 image->makeNonTextureImage()); | 2236 image->makeNonTextureImage()); |
2237 } | 2237 } |
2238 | 2238 |
2239 sk_sp<SkSpecialImage> SkPDFDevice::snapSpecial() { | 2239 sk_sp<SkSpecialImage> SkPDFDevice::snapSpecial() { |
2240 return nullptr; | 2240 return nullptr; |
2241 } | 2241 } |
OLD | NEW |