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 |
10 #include "SkAnnotation.h" | 10 #include "SkAnnotation.h" |
11 #include "SkColor.h" | 11 #include "SkColor.h" |
12 #include "SkClipStack.h" | 12 #include "SkClipStack.h" |
13 #include "SkData.h" | 13 #include "SkData.h" |
14 #include "SkDraw.h" | 14 #include "SkDraw.h" |
15 #include "SkFontHost.h" | 15 #include "SkFontHost.h" |
16 #include "SkGlyphCache.h" | 16 #include "SkGlyphCache.h" |
17 #include "SkPaint.h" | 17 #include "SkPaint.h" |
18 #include "SkPath.h" | 18 #include "SkPath.h" |
19 #include "SkPathOps.h" | |
19 #include "SkPDFFont.h" | 20 #include "SkPDFFont.h" |
20 #include "SkPDFFormXObject.h" | 21 #include "SkPDFFormXObject.h" |
21 #include "SkPDFGraphicState.h" | 22 #include "SkPDFGraphicState.h" |
22 #include "SkPDFImage.h" | 23 #include "SkPDFImage.h" |
23 #include "SkPDFResourceDict.h" | 24 #include "SkPDFResourceDict.h" |
24 #include "SkPDFShader.h" | 25 #include "SkPDFShader.h" |
25 #include "SkPDFStream.h" | 26 #include "SkPDFStream.h" |
26 #include "SkPDFTypes.h" | 27 #include "SkPDFTypes.h" |
27 #include "SkPDFUtils.h" | 28 #include "SkPDFUtils.h" |
28 #include "SkRect.h" | 29 #include "SkRect.h" |
(...skipping 806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
835 if (fill) { | 836 if (fill) { |
836 noEffectPaint.setStyle(SkPaint::kFill_Style); | 837 noEffectPaint.setStyle(SkPaint::kFill_Style); |
837 } else { | 838 } else { |
838 noEffectPaint.setStyle(SkPaint::kStroke_Style); | 839 noEffectPaint.setStyle(SkPaint::kStroke_Style); |
839 noEffectPaint.setStrokeWidth(0); | 840 noEffectPaint.setStrokeWidth(0); |
840 } | 841 } |
841 drawPath(d, *pathPtr, noEffectPaint, NULL, true); | 842 drawPath(d, *pathPtr, noEffectPaint, NULL, true); |
842 return; | 843 return; |
843 } | 844 } |
844 | 845 |
846 #ifdef SK_PDF_USE_PATHOPS | |
847 if (origPath.isInverseFillType()) { | |
vandebo (ex-Chrome)
2013/07/30 16:50:42
nit: Push this into the handle method...
if (hand
ducky
2013/07/30 22:01:55
Done.
| |
848 handleInversePath(d, origPath, paint, pathIsMutable); | |
849 return; | |
850 } | |
851 #endif | |
852 | |
845 if (handleRectAnnotation(pathPtr->getBounds(), *d.fMatrix, paint)) { | 853 if (handleRectAnnotation(pathPtr->getBounds(), *d.fMatrix, paint)) { |
846 return; | 854 return; |
847 } | 855 } |
848 | 856 |
849 ScopedContentEntry content(this, d, paint); | 857 ScopedContentEntry content(this, d, paint); |
850 if (!content.entry()) { | 858 if (!content.entry()) { |
851 return; | 859 return; |
852 } | 860 } |
853 SkPDFUtils::EmitPath(*pathPtr, paint.getStyle(), | 861 SkPDFUtils::EmitPath(*pathPtr, paint.getStyle(), |
854 &content.entry()->fContent); | 862 &content.entry()->fContent); |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1225 emit_clip(NULL, &r, &data); | 1233 emit_clip(NULL, &r, &data); |
1226 } | 1234 } |
1227 | 1235 |
1228 SkPDFDevice::copyContentEntriesToData(fContentEntries.get(), &data); | 1236 SkPDFDevice::copyContentEntriesToData(fContentEntries.get(), &data); |
1229 | 1237 |
1230 // potentially we could cache this SkData, and only rebuild it if we | 1238 // potentially we could cache this SkData, and only rebuild it if we |
1231 // see that our state has changed. | 1239 // see that our state has changed. |
1232 return data.copyToData(); | 1240 return data.copyToData(); |
1233 } | 1241 } |
1234 | 1242 |
1243 /* Calculate an inverted path's equivalent non-inverted path, given the | |
1244 * canvas bounds. | |
1245 */ | |
1246 bool calculate_inverse_path(const SkRect& bounds, const SkPath& invPath, | |
vandebo (ex-Chrome)
2013/07/30 16:50:42
You can inline this function unless you intend to
ducky
2013/07/30 22:01:55
I probably should have noted that this was to get
| |
1247 SkPath* outPath) { | |
1248 SkASSERT(invPath.isInverseFillType()); | |
1249 | |
1250 SkPath clipPath; | |
1251 clipPath.addRect(bounds); | |
1252 | |
1253 return Op(clipPath, invPath, kIntersect_PathOp, outPath); | |
1254 } | |
1255 | |
1256 /* Draws an inverse filled path by using Path Ops to compute the positive | |
1257 * inverse using the current clip as the inverse bounds. | |
1258 */ | |
1259 void SkPDFDevice::handleInversePath(const SkDraw& d, const SkPath& origPath, | |
1260 const SkPaint& paint, bool pathIsMutable) { | |
1261 SkASSERT(origPath.isInverseFillType()); | |
1262 | |
1263 if (d.fClip->isEmpty()) { | |
1264 return; | |
1265 } | |
1266 | |
1267 SkPath modifiedPath; | |
1268 SkPath* pathPtr = const_cast<SkPath*>(&origPath); | |
1269 SkPaint noInversePaint(paint); | |
1270 | |
1271 // Merge stroking operations into final path. | |
1272 if (SkPaint::kStroke_Style == paint.getStyle() || | |
1273 SkPaint::kStrokeAndFill_Style == paint.getStyle()) { | |
1274 pathPtr = &modifiedPath; | |
1275 if (paint.getFillPath(origPath, pathPtr)) { | |
1276 noInversePaint.setStyle(SkPaint::kFill_Style); | |
1277 noInversePaint.setStrokeWidth(0); | |
1278 } else { | |
1279 // To be consistent with the raster output, hairline strokes | |
vandebo (ex-Chrome)
2013/07/30 16:50:42
At this point pathPtr points to modifiedPath that
ducky
2013/07/30 22:01:55
I think paint.getFillPath still duplicates the pai
| |
1280 // are rendered as non-inverted. | |
1281 pathPtr->toggleInverseFillType(); | |
1282 drawPath(d, *pathPtr, paint, NULL, true); | |
1283 return; | |
vandebo (ex-Chrome)
2013/07/30 16:50:42
After you've changed this to return a bool though,
ducky
2013/07/30 22:01:55
I can see how that would be faster, but it seems l
| |
1284 } | |
1285 } | |
1286 | |
1287 // Get bounds of clip in current transform space | |
1288 // (clip bounds are given in device space). | |
1289 SkRect bounds; | |
1290 SkMatrix transformInverse; | |
1291 if (!d.fMatrix->invert(&transformInverse)) { | |
1292 return; | |
1293 } | |
1294 bounds.set(d.fClip->getBounds()); | |
1295 transformInverse.mapRect(&bounds); | |
1296 | |
1297 // Extend the bounds by the line width (plus some padding) | |
1298 // so the edge doesn't cause a visible stroke. | |
1299 bounds.outset(paint.getStrokeWidth() + SK_Scalar1, | |
1300 paint.getStrokeWidth() + SK_Scalar1); | |
1301 | |
1302 if (calculate_inverse_path(bounds, *pathPtr, &modifiedPath)) { | |
1303 drawPath(d, modifiedPath, noInversePaint, NULL, true); | |
1304 } | |
1305 } | |
1306 | |
1235 bool SkPDFDevice::handleRectAnnotation(const SkRect& r, const SkMatrix& matrix, | 1307 bool SkPDFDevice::handleRectAnnotation(const SkRect& r, const SkMatrix& matrix, |
1236 const SkPaint& p) { | 1308 const SkPaint& p) { |
1237 SkAnnotation* annotationInfo = p.getAnnotation(); | 1309 SkAnnotation* annotationInfo = p.getAnnotation(); |
1238 if (!annotationInfo) { | 1310 if (!annotationInfo) { |
1239 return false; | 1311 return false; |
1240 } | 1312 } |
1241 SkData* urlData = annotationInfo->find(SkAnnotationKeys::URL_Key()); | 1313 SkData* urlData = annotationInfo->find(SkAnnotationKeys::URL_Key()); |
1242 if (urlData) { | 1314 if (urlData) { |
1243 handleLinkToURL(urlData, r, matrix); | 1315 handleLinkToURL(urlData, r, matrix); |
1244 return p.isNoDrawAnnotation(); | 1316 return p.isNoDrawAnnotation(); |
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1751 } | 1823 } |
1752 | 1824 |
1753 bool SkPDFDevice::onReadPixels(const SkBitmap& bitmap, int x, int y, | 1825 bool SkPDFDevice::onReadPixels(const SkBitmap& bitmap, int x, int y, |
1754 SkCanvas::Config8888) { | 1826 SkCanvas::Config8888) { |
1755 return false; | 1827 return false; |
1756 } | 1828 } |
1757 | 1829 |
1758 bool SkPDFDevice::allowImageFilter(SkImageFilter*) { | 1830 bool SkPDFDevice::allowImageFilter(SkImageFilter*) { |
1759 return false; | 1831 return false; |
1760 } | 1832 } |
OLD | NEW |