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 19519017: Inverse fill support in PDF (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: More style fixes Created 7 years, 4 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 | Annotate | Revision Log
« gm/inversestrokefill.cpp ('K') | « include/config/SkUserConfig.h ('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"
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 735 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 &content.entry()->fContent); 765 &content.entry()->fContent);
765 SkPDFUtils::ClosePath(&content.entry()->fContent); 766 SkPDFUtils::ClosePath(&content.entry()->fContent);
766 SkPDFUtils::StrokePath(&content.entry()->fContent); 767 SkPDFUtils::StrokePath(&content.entry()->fContent);
767 } 768 }
768 break; 769 break;
769 default: 770 default:
770 SkASSERT(false); 771 SkASSERT(false);
771 } 772 }
772 } 773 }
773 774
774 void SkPDFDevice::drawRect(const SkDraw& d, const SkRect& rect, 775 void SkPDFDevice::drawRect(const SkDraw& d, const SkRect& rect,
vandebo (ex-Chrome) 2013/07/26 17:48:44 Shouldn't this handle inverse fill as well?
reed1 2013/07/29 13:09:09 Inverseness is on the SkPath, not the paint, so th
775 const SkPaint& paint) { 776 const SkPaint& paint) {
776 SkRect r = rect; 777 SkRect r = rect;
777 r.sort(); 778 r.sort();
778 779
779 if (paint.getPathEffect()) { 780 if (paint.getPathEffect()) {
780 if (d.fClip->isEmpty()) { 781 if (d.fClip->isEmpty()) {
781 return; 782 return;
782 } 783 }
783 SkPath path; 784 SkPath path;
784 path.addRect(r); 785 path.addRect(r);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 } 820 }
820 } 821 }
821 } 822 }
822 823
823 if (paint.getPathEffect()) { 824 if (paint.getPathEffect()) {
824 if (d.fClip->isEmpty()) { 825 if (d.fClip->isEmpty()) {
825 return; 826 return;
826 } 827 }
827 if (!pathIsMutable) { 828 if (!pathIsMutable) {
828 pathPtr = &modifiedPath; 829 pathPtr = &modifiedPath;
829 pathIsMutable = true;
vandebo (ex-Chrome) 2013/07/26 17:48:44 Even though this isn't (currently) used after this
ducky 2013/07/29 19:07:51 Done.
830 } 830 }
831 bool fill = paint.getFillPath(origPath, pathPtr); 831 bool fill = paint.getFillPath(origPath, pathPtr);
832 832
833 SkPaint noEffectPaint(paint); 833 SkPaint noEffectPaint(paint);
834 noEffectPaint.setPathEffect(NULL); 834 noEffectPaint.setPathEffect(NULL);
835 if (fill) { 835 if (fill) {
836 noEffectPaint.setStyle(SkPaint::kFill_Style); 836 noEffectPaint.setStyle(SkPaint::kFill_Style);
837 } else { 837 } else {
838 noEffectPaint.setStyle(SkPaint::kStroke_Style); 838 noEffectPaint.setStyle(SkPaint::kStroke_Style);
839 noEffectPaint.setStrokeWidth(0); 839 noEffectPaint.setStrokeWidth(0);
840 } 840 }
841 drawPath(d, *pathPtr, noEffectPaint, NULL, true); 841 drawPath(d, *pathPtr, noEffectPaint, NULL, true);
842 return; 842 return;
843 } 843 }
844 844
845 #ifdef SK_PDF_USE_PATHOPS
846 if (origPath.isInverseFillType()) {
vandebo (ex-Chrome) 2013/07/26 17:48:44 Lets put this all into a method: handleInverseFill
vandebo (ex-Chrome) 2013/07/26 17:48:44 If paint style is just stroke do we need to do any
ducky 2013/07/29 19:07:51 Inverse stroke is kind of funny: For a hairline (o
ducky 2013/07/29 19:07:51 Done.
847 if (d.fClip->isEmpty()) {
848 return;
849 }
850 if (!pathIsMutable) {
vandebo (ex-Chrome) 2013/07/26 17:48:44 Pull this into the if on line 857 so that you can
ducky 2013/07/29 19:07:51 Done - though this whole PathIsMutable thing is a
vandebo (ex-Chrome) 2013/07/30 16:50:42 It depends on how big the thing you are copying is
851 pathPtr = &modifiedPath;
vandebo (ex-Chrome) 2013/07/26 17:48:44 pathIsMutable = true;
ducky 2013/07/29 19:07:51 Done.
852 }
853
854 SkPaint finalPaint(paint);
vandebo (ex-Chrome) 2013/07/26 17:48:44 nit: finalPaint -> noInversePaint
ducky 2013/07/29 19:07:51 Done.
855
856 // Merge stroking operations into final path.
857 if (SkPaint::kStroke_Style == paint.getStyle()
858 || SkPaint::kStrokeAndFill_Style == paint.getStyle()) {
vandebo (ex-Chrome) 2013/07/26 17:48:44 predominate style in this file (and Chrome style)
ducky 2013/07/29 19:07:51 Done.
859 if (paint.getFillPath(origPath, pathPtr)) {
860 finalPaint.setStyle(SkPaint::kFill_Style);
861 finalPaint.setStrokeWidth(0);
862 } else {
863 // Hairline strokes rendered as non-inverted.
vandebo (ex-Chrome) 2013/07/26 17:48:44 What does this comment mean?
ducky 2013/07/29 19:07:51 See above explanation of inverse hairline strokes.
864 pathPtr->toggleInverseFillType();
865 drawPath(d, *pathPtr, paint, NULL, true);
866 return;
867 }
868 } else {
869 *pathPtr = origPath;
870 }
871
872 // Get bounds of clip in current transform space
873 // (clip bounds are given in device space).
874 SkRect bounds;
875 SkMatrix transformInverse;
876 if (!d.fMatrix->invert(&transformInverse)) {
877 return;
878 }
879 bounds.set(d.fClip->getBounds());
880 transformInverse.mapRect(&bounds);
881
882 // Extend the bounds by the line width (and then some, for hairline
883 // strokes) so the edge doesn't cause a visible stroke.
884 bounds.outset(paint.getStrokeWidth() + SK_Scalar1,
885 paint.getStrokeWidth() + SK_Scalar1);
886
887 SkPath clipPath;
888 clipPath.addRect(bounds);
889
890 if (Op(clipPath, *pathPtr, kIntersect_PathOp, pathPtr)) {
891 drawPath(d, *pathPtr, finalPaint, NULL, true);
892 }
893 return;
894 }
895 #endif
896
845 if (handleRectAnnotation(pathPtr->getBounds(), *d.fMatrix, paint)) { 897 if (handleRectAnnotation(pathPtr->getBounds(), *d.fMatrix, paint)) {
846 return; 898 return;
847 } 899 }
848 900
849 ScopedContentEntry content(this, d, paint); 901 ScopedContentEntry content(this, d, paint);
850 if (!content.entry()) { 902 if (!content.entry()) {
851 return; 903 return;
852 } 904 }
853 SkPDFUtils::EmitPath(*pathPtr, paint.getStyle(), 905 SkPDFUtils::EmitPath(*pathPtr, paint.getStyle(),
854 &content.entry()->fContent); 906 &content.entry()->fContent);
(...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after
1753 } 1805 }
1754 1806
1755 bool SkPDFDevice::onReadPixels(const SkBitmap& bitmap, int x, int y, 1807 bool SkPDFDevice::onReadPixels(const SkBitmap& bitmap, int x, int y,
1756 SkCanvas::Config8888) { 1808 SkCanvas::Config8888) {
1757 return false; 1809 return false;
1758 } 1810 }
1759 1811
1760 bool SkPDFDevice::allowImageFilter(SkImageFilter*) { 1812 bool SkPDFDevice::allowImageFilter(SkImageFilter*) {
1761 return false; 1813 return false;
1762 } 1814 }
OLDNEW
« gm/inversestrokefill.cpp ('K') | « include/config/SkUserConfig.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698