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

Unified Diff: src/pdf/SkPDFDevice.cpp

Issue 2188303003: SkPDF: drawText makes use of SkPaint.measureText() for alignment. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pdf/SkPDFDevice.cpp
diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp
index 6972f8b01f46e255f2ed5bc995948462bbdd04cb..92f190732f748a3cfaf3dc49bef18e1e9fd3e65f 100644
--- a/src/pdf/SkPDFDevice.cpp
+++ b/src/pdf/SkPDFDevice.cpp
@@ -78,38 +78,21 @@ static SkPaint calculate_text_paint(const SkPaint& paint) {
}
// Stolen from measure_text in SkDraw.cpp and then tweaked.
-static void align_text(SkPaint::GlyphCacheProc glyphCacheProc, const SkPaint& paint,
+static void align_text(const SkPaint& paint,
const uint16_t* glyphs, size_t len,
SkScalar* x, SkScalar* y) {
if (paint.getTextAlign() == SkPaint::kLeft_Align) {
return;
}
-
- SkMatrix ident;
- ident.reset();
- SkAutoGlyphCache autoCache(paint, nullptr, &ident);
- SkGlyphCache* cache = autoCache.getCache();
-
- const char* start = reinterpret_cast<const char*>(glyphs);
- const char* stop = reinterpret_cast<const char*>(glyphs + len);
- SkScalar xAdv = 0, yAdv = 0;
-
- // TODO(vandebo): This probably needs to take kerning into account.
- while (start < stop) {
- const SkGlyph& glyph = glyphCacheProc(cache, &start);
- xAdv += SkFloatToScalar(glyph.fAdvanceX);
- yAdv += SkFloatToScalar(glyph.fAdvanceY);
- };
- if (paint.getTextAlign() == SkPaint::kLeft_Align) {
- return;
- }
-
+ SkScalar advance = paint.measureText(glyphs, len * sizeof(uint16_t));
if (paint.getTextAlign() == SkPaint::kCenter_Align) {
- xAdv = SkScalarHalf(xAdv);
- yAdv = SkScalarHalf(yAdv);
+ advance *= 0.5f;
+ }
+ if (paint.isVerticalText()) {
+ *y -= advance;
+ } else {
+ *x -= advance;
}
- *x = *x - xAdv;
- *y = *y - yAdv;
}
static int max_glyphid_for_typeface(SkTypeface* typeface) {
@@ -1214,10 +1197,7 @@ void SkPDFDevice::drawText(const SkDraw& d, const void* text, size_t len,
int numGlyphs = force_glyph_encoding(paint, text, len, &storage, &glyphIDs);
textPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
- SkPaint::GlyphCacheProc glyphCacheProc = SkPaint::GetGlyphCacheProc(textPaint.getTextEncoding(),
- textPaint.isDevKernText(),
- true);
- align_text(glyphCacheProc, textPaint, glyphIDs, numGlyphs, &x, &y);
+ align_text(textPaint, glyphIDs, numGlyphs, &x, &y);
content.entry()->fContent.writeText("BT\n");
set_text_transform(x, y, textPaint.getTextSkewX(),
&content.entry()->fContent);
@@ -1293,9 +1273,6 @@ void SkPDFDevice::drawPosText(const SkDraw& d, const void* text, size_t len,
size_t numGlyphs = force_glyph_encoding(paint, text, len, &storage, &glyphIDs);
textPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
- SkPaint::GlyphCacheProc glyphCacheProc = SkPaint::GetGlyphCacheProc(textPaint.getTextEncoding(),
- textPaint.isDevKernText(),
- true);
content.entry()->fContent.writeText("BT\n");
this->updateFont(textPaint, glyphIDs[0], content.entry());
GlyphPositioner glyphPositioner(&content.entry()->fContent,
@@ -1321,7 +1298,7 @@ void SkPDFDevice::drawPosText(const SkDraw& d, const void* text, size_t len,
fontGlyphUsage->noteGlyphUsage(font, &encodedValue, 1);
SkScalar x = offset.x() + pos[i * scalarsPerPos];
SkScalar y = offset.y() + (2 == scalarsPerPos ? pos[i * scalarsPerPos + 1] : 0);
- align_text(glyphCacheProc, textPaint, glyphIDs + i, 1, &x, &y);
+ align_text(textPaint, glyphIDs + i, 1, &x, &y);
SkScalar advanceWidth = textPaint.measureText(&encodedValue, sizeof(uint16_t));
glyphPositioner.writeGlyph(x, y, advanceWidth, encodedValue);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698