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

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

Issue 1718423002: Simplify and combine SkDrawCacheProc and SkMeasureCacheProc to SkPaint::GlyphCacheProc. (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: Created 4 years, 10 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 | « src/gpu/text/GrTextUtils.cpp ('k') | no next file » | 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 result.setStyle(SkPaint::kStrokeAndFill_Style); 73 result.setStyle(SkPaint::kStrokeAndFill_Style);
74 } else { 74 } else {
75 width += result.getStrokeWidth(); 75 width += result.getStrokeWidth();
76 } 76 }
77 result.setStrokeWidth(width); 77 result.setStrokeWidth(width);
78 } 78 }
79 return result; 79 return result;
80 } 80 }
81 81
82 // Stolen from measure_text in SkDraw.cpp and then tweaked. 82 // Stolen from measure_text in SkDraw.cpp and then tweaked.
83 static void align_text(SkDrawCacheProc glyphCacheProc, const SkPaint& paint, 83 static void align_text(SkPaint::GlyphCacheProc glyphCacheProc, const SkPaint& pa int,
84 const uint16_t* glyphs, size_t len, 84 const uint16_t* glyphs, size_t len,
85 SkScalar* x, SkScalar* y) { 85 SkScalar* x, SkScalar* y) {
86 if (paint.getTextAlign() == SkPaint::kLeft_Align) { 86 if (paint.getTextAlign() == SkPaint::kLeft_Align) {
87 return; 87 return;
88 } 88 }
89 89
90 SkMatrix ident; 90 SkMatrix ident;
91 ident.reset(); 91 ident.reset();
92 SkAutoGlyphCache autoCache(paint, nullptr, &ident); 92 SkAutoGlyphCache autoCache(paint, nullptr, &ident);
93 SkGlyphCache* cache = autoCache.getCache(); 93 SkGlyphCache* cache = autoCache.getCache();
94 94
95 const char* start = reinterpret_cast<const char*>(glyphs); 95 const char* start = reinterpret_cast<const char*>(glyphs);
96 const char* stop = reinterpret_cast<const char*>(glyphs + len); 96 const char* stop = reinterpret_cast<const char*>(glyphs + len);
97 SkFixed xAdv = 0, yAdv = 0; 97 SkFixed xAdv = 0, yAdv = 0;
98 98
99 // TODO(vandebo): This probably needs to take kerning into account. 99 // TODO(vandebo): This probably needs to take kerning into account.
100 while (start < stop) { 100 while (start < stop) {
101 const SkGlyph& glyph = glyphCacheProc(cache, &start, 0, 0); 101 const SkGlyph& glyph = glyphCacheProc(cache, &start);
102 xAdv += glyph.fAdvanceX; 102 xAdv += glyph.fAdvanceX;
103 yAdv += glyph.fAdvanceY; 103 yAdv += glyph.fAdvanceY;
104 }; 104 };
105 if (paint.getTextAlign() == SkPaint::kLeft_Align) { 105 if (paint.getTextAlign() == SkPaint::kLeft_Align) {
106 return; 106 return;
107 } 107 }
108 108
109 SkScalar xAdj = SkFixedToScalar(xAdv); 109 SkScalar xAdj = SkFixedToScalar(xAdv);
110 SkScalar yAdj = SkFixedToScalar(yAdv); 110 SkScalar yAdj = SkFixedToScalar(yAdv);
111 if (paint.getTextAlign() == SkPaint::kCenter_Align) { 111 if (paint.getTextAlign() == SkPaint::kCenter_Align) {
(...skipping 1183 matching lines...) Expand 10 before | Expand all | Expand 10 after
1295 ScopedContentEntry content(this, d, textPaint, true); 1295 ScopedContentEntry content(this, d, textPaint, true);
1296 if (!content.entry()) { 1296 if (!content.entry()) {
1297 return; 1297 return;
1298 } 1298 }
1299 1299
1300 SkGlyphStorage storage(0); 1300 SkGlyphStorage storage(0);
1301 const uint16_t* glyphIDs = nullptr; 1301 const uint16_t* glyphIDs = nullptr;
1302 int numGlyphs = force_glyph_encoding(paint, text, len, &storage, &glyphIDs); 1302 int numGlyphs = force_glyph_encoding(paint, text, len, &storage, &glyphIDs);
1303 textPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); 1303 textPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
1304 1304
1305 SkDrawCacheProc glyphCacheProc = textPaint.getDrawCacheProc(); 1305 SkPaint::GlyphCacheProc glyphCacheProc = textPaint.getGlyphCacheProc(true);
1306 align_text(glyphCacheProc, textPaint, glyphIDs, numGlyphs, &x, &y); 1306 align_text(glyphCacheProc, textPaint, glyphIDs, numGlyphs, &x, &y);
1307 content.entry()->fContent.writeText("BT\n"); 1307 content.entry()->fContent.writeText("BT\n");
1308 set_text_transform(x, y, textPaint.getTextSkewX(), 1308 set_text_transform(x, y, textPaint.getTextSkewX(),
1309 &content.entry()->fContent); 1309 &content.entry()->fContent);
1310 int consumedGlyphCount = 0; 1310 int consumedGlyphCount = 0;
1311 1311
1312 SkTDArray<uint16_t> glyphIDsCopy(glyphIDs, numGlyphs); 1312 SkTDArray<uint16_t> glyphIDsCopy(glyphIDs, numGlyphs);
1313 1313
1314 while (numGlyphs > consumedGlyphCount) { 1314 while (numGlyphs > consumedGlyphCount) {
1315 this->updateFont(textPaint, glyphIDs[consumedGlyphCount], content.entry( )); 1315 this->updateFont(textPaint, glyphIDs[consumedGlyphCount], content.entry( ));
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1371 ScopedContentEntry content(this, d, textPaint, true); 1371 ScopedContentEntry content(this, d, textPaint, true);
1372 if (!content.entry()) { 1372 if (!content.entry()) {
1373 return; 1373 return;
1374 } 1374 }
1375 1375
1376 SkGlyphStorage storage(0); 1376 SkGlyphStorage storage(0);
1377 const uint16_t* glyphIDs = nullptr; 1377 const uint16_t* glyphIDs = nullptr;
1378 size_t numGlyphs = force_glyph_encoding(paint, text, len, &storage, &glyphID s); 1378 size_t numGlyphs = force_glyph_encoding(paint, text, len, &storage, &glyphID s);
1379 textPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); 1379 textPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
1380 1380
1381 SkDrawCacheProc glyphCacheProc = textPaint.getDrawCacheProc(); 1381 SkPaint::GlyphCacheProc glyphCacheProc = textPaint.getGlyphCacheProc(true);
1382 content.entry()->fContent.writeText("BT\n"); 1382 content.entry()->fContent.writeText("BT\n");
1383 this->updateFont(textPaint, glyphIDs[0], content.entry()); 1383 this->updateFont(textPaint, glyphIDs[0], content.entry());
1384 for (size_t i = 0; i < numGlyphs; i++) { 1384 for (size_t i = 0; i < numGlyphs; i++) {
1385 SkPDFFont* font = content.entry()->fState.fFont; 1385 SkPDFFont* font = content.entry()->fState.fFont;
1386 uint16_t encodedValue = glyphIDs[i]; 1386 uint16_t encodedValue = glyphIDs[i];
1387 if (font->glyphsToPDFFontEncoding(&encodedValue, 1) != 1) { 1387 if (font->glyphsToPDFFontEncoding(&encodedValue, 1) != 1) {
1388 // The current pdf font cannot encode the current glyph. 1388 // The current pdf font cannot encode the current glyph.
1389 // Try to get a pdf font which can encode the current glyph. 1389 // Try to get a pdf font which can encode the current glyph.
1390 this->updateFont(textPaint, glyphIDs[i], content.entry()); 1390 this->updateFont(textPaint, glyphIDs[i], content.entry());
1391 font = content.entry()->fState.fFont; 1391 font = content.entry()->fState.fFont;
(...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after
2365 pdfimage.reset(SkPDFCreateBitmapObject( 2365 pdfimage.reset(SkPDFCreateBitmapObject(
2366 image, fCanon->fPixelSerializer)); 2366 image, fCanon->fPixelSerializer));
2367 if (!pdfimage) { 2367 if (!pdfimage) {
2368 return; 2368 return;
2369 } 2369 }
2370 fCanon->addPDFBitmap(image->uniqueID(), pdfimage); 2370 fCanon->addPDFBitmap(image->uniqueID(), pdfimage);
2371 } 2371 }
2372 SkPDFUtils::DrawFormXObject(this->addXObjectResource(pdfimage.get()), 2372 SkPDFUtils::DrawFormXObject(this->addXObjectResource(pdfimage.get()),
2373 &content.entry()->fContent); 2373 &content.entry()->fContent);
2374 } 2374 }
OLDNEW
« no previous file with comments | « src/gpu/text/GrTextUtils.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698