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

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

Issue 2274153002: SkPDF: vertical writing: draw nothing (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 3 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 | 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 #include "SkAnnotationKeys.h" 9 #include "SkAnnotationKeys.h"
10 #include "SkBitmapDevice.h" 10 #include "SkBitmapDevice.h"
(...skipping 1061 matching lines...) Expand 10 before | Expand all | Expand 10 after
1072 void SkPDFDevice::internalDrawText( 1072 void SkPDFDevice::internalDrawText(
1073 const SkDraw& d, const void* sourceText, size_t sourceByteCount, 1073 const SkDraw& d, const void* sourceText, size_t sourceByteCount,
1074 const SkScalar pos[], SkTextBlob::GlyphPositioning positioning, 1074 const SkScalar pos[], SkTextBlob::GlyphPositioning positioning,
1075 SkPoint offset, const SkPaint& srcPaint) { 1075 SkPoint offset, const SkPaint& srcPaint) {
1076 NOT_IMPLEMENTED(srcPaint.getMaskFilter() != nullptr, false); 1076 NOT_IMPLEMENTED(srcPaint.getMaskFilter() != nullptr, false);
1077 if (srcPaint.getMaskFilter() != nullptr) { 1077 if (srcPaint.getMaskFilter() != nullptr) {
1078 // Don't pretend we support drawing MaskFilters, it makes for artifacts 1078 // Don't pretend we support drawing MaskFilters, it makes for artifacts
1079 // making text unreadable (e.g. same text twice when using CSS shadows). 1079 // making text unreadable (e.g. same text twice when using CSS shadows).
1080 return; 1080 return;
1081 } 1081 }
1082 NOT_IMPLEMENTED(srcPaint.isVerticalText(), false);
1083 if (srcPaint.isVerticalText()) {
1084 // Don't pretend we support drawing vertical text. It is not
1085 // clear to me how to switch to "vertical writing" mode in PDF.
1086 // Currently neither Chromium or Android set this flag.
1087 // https://bug.skia.org/5665
1088 return;
1089 }
1082 SkPaint paint = calculate_text_paint(srcPaint); 1090 SkPaint paint = calculate_text_paint(srcPaint);
1083 replace_srcmode_on_opaque_paint(&paint); 1091 replace_srcmode_on_opaque_paint(&paint);
1084 if (!paint.getTypeface()) { 1092 if (!paint.getTypeface()) {
1085 paint.setTypeface(SkTypeface::MakeDefault()); 1093 paint.setTypeface(SkTypeface::MakeDefault());
1086 } 1094 }
1087 SkTypeface* typeface = paint.getTypeface(); 1095 SkTypeface* typeface = paint.getTypeface();
1088 if (!typeface) { 1096 if (!typeface) {
1089 SkDebugf("SkPDF: SkTypeface::MakeDefault() returned nullptr.\n"); 1097 SkDebugf("SkPDF: SkTypeface::MakeDefault() returned nullptr.\n");
1090 return; 1098 return;
1091 } 1099 }
(...skipping 27 matching lines...) Expand all
1119 glyphs[i] = SkTMin(maxGlyphID, glyphs[i]); 1127 glyphs[i] = SkTMin(maxGlyphID, glyphs[i]);
1120 } 1128 }
1121 } else { 1129 } else {
1122 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); 1130 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
1123 } 1131 }
1124 1132
1125 bool defaultPositioning = (positioning == SkTextBlob::kDefault_Positioning); 1133 bool defaultPositioning = (positioning == SkTextBlob::kDefault_Positioning);
1126 SkAutoGlyphCache glyphCache(paint, nullptr, nullptr); 1134 SkAutoGlyphCache glyphCache(paint, nullptr, nullptr);
1127 1135
1128 SkPaint::Align alignment = paint.getTextAlign(); 1136 SkPaint::Align alignment = paint.getTextAlign();
1129 bool verticalText = paint.isVerticalText();
1130 if (defaultPositioning && alignment != SkPaint::kLeft_Align) { 1137 if (defaultPositioning && alignment != SkPaint::kLeft_Align) {
1131 SkScalar advance{0}; 1138 SkScalar advance{0};
1132 for (int i = 0; i < glyphCount; ++i) { 1139 for (int i = 0; i < glyphCount; ++i) {
1133 advance += glyphCache->getGlyphIDAdvance(glyphs[i]).fAdvanceX; 1140 advance += glyphCache->getGlyphIDAdvance(glyphs[i]).fAdvanceX;
1134 } 1141 }
1135 SkScalar m = alignment == SkPaint::kCenter_Align 1142 SkScalar m = alignment == SkPaint::kCenter_Align
1136 ? 0.5f * advance : advance; 1143 ? 0.5f * advance : advance;
1137 offset -= verticalText ? SkPoint{0, m} : SkPoint{m, 0}; 1144 offset -= SkPoint{m, 0};
1138 } 1145 }
1139 ScopedContentEntry content(this, d, paint, true); 1146 ScopedContentEntry content(this, d, paint, true);
1140 if (!content.entry()) { 1147 if (!content.entry()) {
1141 return; 1148 return;
1142 } 1149 }
1143 SkDynamicMemoryWStream* out = &content.entry()->fContent; 1150 SkDynamicMemoryWStream* out = &content.entry()->fContent;
1144 out->writeText("BT\n"); 1151 out->writeText("BT\n");
1145 if (!this->updateFont(paint, glyphs[0], content.entry())) { 1152 if (!this->updateFont(paint, glyphs[0], content.entry())) {
1146 SkDebugf("SkPDF: Font error."); 1153 SkDebugf("SkPDF: Font error.");
1147 out->writeText("ET\n%SkPDF: Font error.\n"); 1154 out->writeText("ET\n%SkPDF: Font error.\n");
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1193 } else { 1200 } else {
1194 while (stretch-- > 0) { 1201 while (stretch-- > 0) {
1195 SkScalar advance = glyphCache->getGlyphIDAdvance(*glyphs).fAdvan ceX; 1202 SkScalar advance = glyphCache->getGlyphIDAdvance(*glyphs).fAdvan ceX;
1196 SkScalar x = *pos++; 1203 SkScalar x = *pos++;
1197 // evaluate x and y in order! 1204 // evaluate x and y in order!
1198 SkScalar y = SkTextBlob::kFull_Positioning == positioning ? *pos ++ : 0; 1205 SkScalar y = SkTextBlob::kFull_Positioning == positioning ? *pos ++ : 0;
1199 SkPoint xy{x, y}; 1206 SkPoint xy{x, y};
1200 if (alignment != SkPaint::kLeft_Align) { 1207 if (alignment != SkPaint::kLeft_Align) {
1201 SkScalar m = alignment == SkPaint::kCenter_Align 1208 SkScalar m = alignment == SkPaint::kCenter_Align
1202 ? 0.5f * advance : advance; 1209 ? 0.5f * advance : advance;
1203 xy -= verticalText ? SkPoint{0, m} : SkPoint{m, 0}; 1210 xy -= SkPoint{m, 0};
1204 } 1211 }
1205 (void)font->glyphsToPDFFontEncoding(glyphs, 1); 1212 (void)font->glyphsToPDFFontEncoding(glyphs, 1);
1206 glyphPositioner.writeGlyph(xy.x(), xy.y(), advance, *glyphs); 1213 glyphPositioner.writeGlyph(xy.x(), xy.y(), advance, *glyphs);
1207 ++glyphs; 1214 ++glyphs;
1208 } 1215 }
1209 } 1216 }
1210 } 1217 }
1211 glyphPositioner.flush(); 1218 glyphPositioner.flush();
1212 out->writeText("ET\n"); 1219 out->writeText("ET\n");
1213 } 1220 }
(...skipping 923 matching lines...) Expand 10 before | Expand all | Expand 10 after
2137 } 2144 }
2138 2145
2139 sk_sp<SkSpecialImage> SkPDFDevice::makeSpecial(const SkImage* image) { 2146 sk_sp<SkSpecialImage> SkPDFDevice::makeSpecial(const SkImage* image) {
2140 return SkSpecialImage::MakeFromImage(SkIRect::MakeWH(image->width(), image-> height()), 2147 return SkSpecialImage::MakeFromImage(SkIRect::MakeWH(image->width(), image-> height()),
2141 image->makeNonTextureImage()); 2148 image->makeNonTextureImage());
2142 } 2149 }
2143 2150
2144 sk_sp<SkSpecialImage> SkPDFDevice::snapSpecial() { 2151 sk_sp<SkSpecialImage> SkPDFDevice::snapSpecial() {
2145 return nullptr; 2152 return nullptr;
2146 } 2153 }
OLDNEW
« 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