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 #include "SkAnnotationKeys.h" | 10 #include "SkAnnotationKeys.h" |
10 #include "SkBitmapDevice.h" | 11 #include "SkBitmapDevice.h" |
11 #include "SkBitmapKey.h" | 12 #include "SkBitmapKey.h" |
12 #include "SkColor.h" | 13 #include "SkColor.h" |
13 #include "SkColorFilter.h" | 14 #include "SkColorFilter.h" |
14 #include "SkDraw.h" | 15 #include "SkDraw.h" |
| 16 #include "SkDrawFilter.h" |
15 #include "SkGlyphCache.h" | 17 #include "SkGlyphCache.h" |
16 #include "SkPath.h" | 18 #include "SkPath.h" |
17 #include "SkPathEffect.h" | 19 #include "SkPathEffect.h" |
18 #include "SkPathOps.h" | 20 #include "SkPathOps.h" |
19 #include "SkPDFBitmap.h" | 21 #include "SkPDFBitmap.h" |
20 #include "SkPDFCanon.h" | 22 #include "SkPDFCanon.h" |
21 #include "SkPDFDocument.h" | 23 #include "SkPDFDocument.h" |
22 #include "SkPDFFont.h" | 24 #include "SkPDFFont.h" |
23 #include "SkPDFFormXObject.h" | 25 #include "SkPDFFormXObject.h" |
24 #include "SkPDFGraphicState.h" | 26 #include "SkPDFGraphicState.h" |
25 #include "SkPDFResourceDict.h" | 27 #include "SkPDFResourceDict.h" |
26 #include "SkPDFShader.h" | 28 #include "SkPDFShader.h" |
27 #include "SkPDFTypes.h" | 29 #include "SkPDFTypes.h" |
28 #include "SkPDFUtils.h" | 30 #include "SkPDFUtils.h" |
29 #include "SkRasterClip.h" | 31 #include "SkRasterClip.h" |
30 #include "SkRRect.h" | 32 #include "SkRRect.h" |
31 #include "SkScopeExit.h" | 33 #include "SkScopeExit.h" |
32 #include "SkString.h" | 34 #include "SkString.h" |
33 #include "SkSurface.h" | 35 #include "SkSurface.h" |
| 36 #include "SkTemplates.h" |
| 37 #include "SkTextBlobRunIterator.h" |
34 #include "SkTextFormatParams.h" | 38 #include "SkTextFormatParams.h" |
35 #include "SkTemplates.h" | |
36 #include "SkXfermodeInterpretation.h" | 39 #include "SkXfermodeInterpretation.h" |
37 | 40 |
38 #define DPI_FOR_RASTER_SCALE_ONE 72 | 41 #define DPI_FOR_RASTER_SCALE_ONE 72 |
39 | 42 |
40 // Utility functions | 43 // Utility functions |
41 | 44 |
42 // If the paint will definitely draw opaquely, replace kSrc_Mode with | 45 // If the paint will definitely draw opaquely, replace kSrc_Mode with |
43 // kSrcOver_Mode. http://crbug.com/473572 | 46 // kSrcOver_Mode. http://crbug.com/473572 |
44 static void replace_srcmode_on_opaque_paint(SkPaint* paint) { | 47 static void replace_srcmode_on_opaque_paint(SkPaint* paint) { |
45 if (kSrcOver_SkXfermodeInterpretation | 48 if (kSrcOver_SkXfermodeInterpretation |
(...skipping 1010 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1056 device->drawText(d, text, len, x, y, transparent); | 1059 device->drawText(d, text, len, x, y, transparent); |
1057 break; | 1060 break; |
1058 default: | 1061 default: |
1059 SkFAIL("unknown text encoding"); | 1062 SkFAIL("unknown text encoding"); |
1060 } | 1063 } |
1061 } | 1064 } |
1062 | 1065 |
1063 void SkPDFDevice::internalDrawText( | 1066 void SkPDFDevice::internalDrawText( |
1064 const SkDraw& d, const void* sourceText, size_t sourceByteCount, | 1067 const SkDraw& d, const void* sourceText, size_t sourceByteCount, |
1065 const SkScalar pos[], SkTextBlob::GlyphPositioning positioning, | 1068 const SkScalar pos[], SkTextBlob::GlyphPositioning positioning, |
1066 SkPoint offset, const SkPaint& srcPaint) { | 1069 SkPoint offset, const SkPaint& srcPaint, const uint32_t* clusters, |
| 1070 uint32_t textByteLength, const char* utf8Text) { |
1067 NOT_IMPLEMENTED(srcPaint.getMaskFilter() != nullptr, false); | 1071 NOT_IMPLEMENTED(srcPaint.getMaskFilter() != nullptr, false); |
1068 if (srcPaint.getMaskFilter() != nullptr) { | 1072 if (srcPaint.getMaskFilter() != nullptr) { |
1069 // Don't pretend we support drawing MaskFilters, it makes for artifacts | 1073 // Don't pretend we support drawing MaskFilters, it makes for artifacts |
1070 // making text unreadable (e.g. same text twice when using CSS shadows). | 1074 // making text unreadable (e.g. same text twice when using CSS shadows). |
1071 return; | 1075 return; |
1072 } | 1076 } |
1073 NOT_IMPLEMENTED(srcPaint.isVerticalText(), false); | 1077 NOT_IMPLEMENTED(srcPaint.isVerticalText(), false); |
1074 if (srcPaint.isVerticalText()) { | 1078 if (srcPaint.isVerticalText()) { |
1075 // Don't pretend we support drawing vertical text. It is not | 1079 // Don't pretend we support drawing vertical text. It is not |
1076 // clear to me how to switch to "vertical writing" mode in PDF. | 1080 // clear to me how to switch to "vertical writing" mode in PDF. |
1077 // Currently neither Chromium or Android set this flag. | 1081 // Currently neither Chromium or Android set this flag. |
1078 // https://bug.skia.org/5665 | 1082 // https://bug.skia.org/5665 |
1079 return; | 1083 return; |
1080 } | 1084 } |
| 1085 // TODO(halcanary): implement /ActualText with these values. |
| 1086 (void)clusters; |
| 1087 (void)textByteLength; |
| 1088 (void)utf8Text; |
| 1089 if (textByteLength > 0) { |
| 1090 SkASSERT(clusters); |
| 1091 SkASSERT(utf8Text); |
| 1092 SkASSERT(srcPaint.getTextEncoding() == SkPaint::kGlyphID_TextEncoding); |
| 1093 } else { |
| 1094 SkASSERT(nullptr == clusters); |
| 1095 SkASSERT(nullptr == utf8Text); |
| 1096 } |
| 1097 |
1081 SkPaint paint = calculate_text_paint(srcPaint); | 1098 SkPaint paint = calculate_text_paint(srcPaint); |
1082 replace_srcmode_on_opaque_paint(&paint); | 1099 replace_srcmode_on_opaque_paint(&paint); |
1083 if (!paint.getTypeface()) { | 1100 if (!paint.getTypeface()) { |
1084 paint.setTypeface(SkTypeface::MakeDefault()); | 1101 paint.setTypeface(SkTypeface::MakeDefault()); |
1085 } | 1102 } |
1086 SkTypeface* typeface = paint.getTypeface(); | 1103 SkTypeface* typeface = paint.getTypeface(); |
1087 if (!typeface) { | 1104 if (!typeface) { |
1088 SkDebugf("SkPDF: SkTypeface::MakeDefault() returned nullptr.\n"); | 1105 SkDebugf("SkPDF: SkTypeface::MakeDefault() returned nullptr.\n"); |
1089 return; | 1106 return; |
1090 } | 1107 } |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1211 } | 1228 } |
1212 } | 1229 } |
1213 ++index; | 1230 ++index; |
1214 } | 1231 } |
1215 } | 1232 } |
1216 } | 1233 } |
1217 | 1234 |
1218 void SkPDFDevice::drawText(const SkDraw& d, const void* text, size_t len, | 1235 void SkPDFDevice::drawText(const SkDraw& d, const void* text, size_t len, |
1219 SkScalar x, SkScalar y, const SkPaint& paint) { | 1236 SkScalar x, SkScalar y, const SkPaint& paint) { |
1220 this->internalDrawText(d, text, len, nullptr, SkTextBlob::kDefault_Positioni
ng, | 1237 this->internalDrawText(d, text, len, nullptr, SkTextBlob::kDefault_Positioni
ng, |
1221 SkPoint{x, y}, paint); | 1238 SkPoint{x, y}, paint, nullptr, 0, nullptr); |
1222 } | 1239 } |
1223 | 1240 |
1224 void SkPDFDevice::drawPosText(const SkDraw& d, const void* text, size_t len, | 1241 void SkPDFDevice::drawPosText(const SkDraw& d, const void* text, size_t len, |
1225 const SkScalar pos[], int scalarsPerPos, | 1242 const SkScalar pos[], int scalarsPerPos, |
1226 const SkPoint& offset, const SkPaint& paint) { | 1243 const SkPoint& offset, const SkPaint& paint) { |
1227 this->internalDrawText(d, text, len, pos, (SkTextBlob::GlyphPositioning)scal
arsPerPos, | 1244 this->internalDrawText(d, text, len, pos, (SkTextBlob::GlyphPositioning)scal
arsPerPos, |
1228 offset, paint); | 1245 offset, paint, nullptr, 0, nullptr); |
| 1246 } |
| 1247 |
| 1248 void SkPDFDevice::drawTextBlob(const SkDraw& draw, const SkTextBlob* blob, SkSca
lar x, SkScalar y, |
| 1249 const SkPaint &paint, SkDrawFilter* drawFilter) { |
| 1250 for (SkTextBlobRunIterator it(blob); !it.done(); it.next()) { |
| 1251 SkPaint runPaint(paint); |
| 1252 it.applyFontToPaint(&runPaint); |
| 1253 if (drawFilter && !drawFilter->filter(&runPaint, SkDrawFilter::kText_Typ
e)) { |
| 1254 continue; |
| 1255 } |
| 1256 runPaint.setFlags(this->filterTextFlags(runPaint)); |
| 1257 SkPoint offset = it.offset() + SkPoint{x, y}; |
| 1258 this->internalDrawText(draw, it.glyphs(), sizeof(SkGlyphID) * it.glyphCo
unt(), |
| 1259 it.pos(), it.positioning(), offset, runPaint, |
| 1260 it.clusters(), it.textSize(), it.text()); |
| 1261 } |
1229 } | 1262 } |
1230 | 1263 |
1231 void SkPDFDevice::drawVertices(const SkDraw& d, SkCanvas::VertexMode, | 1264 void SkPDFDevice::drawVertices(const SkDraw& d, SkCanvas::VertexMode, |
1232 int vertexCount, const SkPoint verts[], | 1265 int vertexCount, const SkPoint verts[], |
1233 const SkPoint texs[], const SkColor colors[], | 1266 const SkPoint texs[], const SkColor colors[], |
1234 SkXfermode* xmode, const uint16_t indices[], | 1267 SkXfermode* xmode, const uint16_t indices[], |
1235 int indexCount, const SkPaint& paint) { | 1268 int indexCount, const SkPaint& paint) { |
1236 if (d.fRC->isEmpty()) { | 1269 if (d.fRC->isEmpty()) { |
1237 return; | 1270 return; |
1238 } | 1271 } |
(...skipping 903 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2142 } | 2175 } |
2143 | 2176 |
2144 sk_sp<SkSpecialImage> SkPDFDevice::makeSpecial(const SkImage* image) { | 2177 sk_sp<SkSpecialImage> SkPDFDevice::makeSpecial(const SkImage* image) { |
2145 return SkSpecialImage::MakeFromImage(SkIRect::MakeWH(image->width(), image->
height()), | 2178 return SkSpecialImage::MakeFromImage(SkIRect::MakeWH(image->width(), image->
height()), |
2146 image->makeNonTextureImage()); | 2179 image->makeNonTextureImage()); |
2147 } | 2180 } |
2148 | 2181 |
2149 sk_sp<SkSpecialImage> SkPDFDevice::snapSpecial() { | 2182 sk_sp<SkSpecialImage> SkPDFDevice::snapSpecial() { |
2150 return nullptr; | 2183 return nullptr; |
2151 } | 2184 } |
OLD | NEW |