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" |
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
672 // TODO(vandebo) change pageSize to SkSize. | 672 // TODO(vandebo) change pageSize to SkSize. |
673 SkPDFDevice::SkPDFDevice(const SkISize& pageSize, const SkISize& contentSize, | 673 SkPDFDevice::SkPDFDevice(const SkISize& pageSize, const SkISize& contentSize, |
674 const SkMatrix& initialTransform) | 674 const SkMatrix& initialTransform) |
675 : SkBitmapDevice(makeContentBitmap(contentSize, &initialTransform)), | 675 : SkBitmapDevice(makeContentBitmap(contentSize, &initialTransform)), |
676 fPageSize(pageSize), | 676 fPageSize(pageSize), |
677 fContentSize(contentSize), | 677 fContentSize(contentSize), |
678 fLastContentEntry(NULL), | 678 fLastContentEntry(NULL), |
679 fLastMarginContentEntry(NULL), | 679 fLastMarginContentEntry(NULL), |
680 fClipStack(NULL), | 680 fClipStack(NULL), |
681 fEncoder(NULL) { | 681 fEncoder(NULL) { |
682 SkASSERT(!initialTransform.hasPerspective()); | |
vandebo (ex-Chrome)
2013/09/12 21:37:05
If you want to assert, just pass true for the seco
edisonn
2013/09/17 15:14:23
Done.
| |
682 // Skia generally uses the top left as the origin but PDF natively has the | 683 // Skia generally uses the top left as the origin but PDF natively has the |
683 // origin at the bottom left. This matrix corrects for that. But that only | 684 // origin at the bottom left. This matrix corrects for that. But that only |
684 // needs to be done once, we don't do it when layering. | 685 // needs to be done once, we don't do it when layering. |
685 fInitialTransform.setTranslate(0, SkIntToScalar(pageSize.fHeight)); | 686 fInitialTransform.setTranslate(0, SkIntToScalar(pageSize.fHeight)); |
686 fInitialTransform.preScale(SK_Scalar1, -SK_Scalar1); | 687 fInitialTransform.preScale(SK_Scalar1, -SK_Scalar1); |
687 fInitialTransform.preConcat(initialTransform); | 688 fInitialTransform.preConcat(initialTransform); |
688 | 689 |
689 SkIRect existingClip = SkIRect::MakeWH(this->width(), this->height()); | 690 SkIRect existingClip = SkIRect::MakeWH(this->width(), this->height()); |
690 fExistingClipRegion.setRect(existingClip); | 691 fExistingClipRegion.setRect(existingClip); |
691 | 692 |
692 this->init(); | 693 this->init(); |
694 if (initialTransform.hasPerspective()) { | |
695 NOT_IMPLEMENTED(true, false); // just report that PDF does not supports perspective | |
696 // TODO(edisonn): update the shape when p ossible | |
697 // or dump in an image otherwise | |
698 } | |
693 } | 699 } |
694 | 700 |
695 // TODO(vandebo) change layerSize to SkSize. | 701 // TODO(vandebo) change layerSize to SkSize. |
696 SkPDFDevice::SkPDFDevice(const SkISize& layerSize, | 702 SkPDFDevice::SkPDFDevice(const SkISize& layerSize, |
697 const SkClipStack& existingClipStack, | 703 const SkClipStack& existingClipStack, |
698 const SkRegion& existingClipRegion) | 704 const SkRegion& existingClipRegion) |
699 : SkBitmapDevice(makeContentBitmap(layerSize, NULL)), | 705 : SkBitmapDevice(makeContentBitmap(layerSize, NULL)), |
700 fPageSize(layerSize), | 706 fPageSize(layerSize), |
701 fContentSize(layerSize), | 707 fContentSize(layerSize), |
702 fExistingClipStack(existingClipStack), | 708 fExistingClipStack(existingClipStack), |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
770 return; | 776 return; |
771 } | 777 } |
772 SkRect bbox = SkRect::MakeWH(SkIntToScalar(this->width()), | 778 SkRect bbox = SkRect::MakeWH(SkIntToScalar(this->width()), |
773 SkIntToScalar(this->height())); | 779 SkIntToScalar(this->height())); |
774 SkMatrix totalTransform = fInitialTransform; | 780 SkMatrix totalTransform = fInitialTransform; |
775 totalTransform.preConcat(contentEntry->fState.fMatrix); | 781 totalTransform.preConcat(contentEntry->fState.fMatrix); |
776 SkMatrix inverse; | 782 SkMatrix inverse; |
777 if (!totalTransform.invert(&inverse)) { | 783 if (!totalTransform.invert(&inverse)) { |
778 return; | 784 return; |
779 } | 785 } |
786 | |
787 if (totalTransform.hasPerspective()) { | |
788 NOT_IMPLEMENTED(true, false); // just report that PDF does not supports perspective | |
789 // TODO(edisonn): update the shape when p ossible | |
790 // or dump in an image otherwise | |
791 return; | |
792 } | |
793 | |
780 inverse.mapRect(&bbox); | 794 inverse.mapRect(&bbox); |
781 | 795 |
782 SkPDFUtils::AppendRectangle(bbox, &contentEntry->fContent); | 796 SkPDFUtils::AppendRectangle(bbox, &contentEntry->fContent); |
783 SkPDFUtils::PaintPath(paint.getStyle(), SkPath::kWinding_FillType, | 797 SkPDFUtils::PaintPath(paint.getStyle(), SkPath::kWinding_FillType, |
784 &contentEntry->fContent); | 798 &contentEntry->fContent); |
785 } | 799 } |
786 | 800 |
787 void SkPDFDevice::drawPoints(const SkDraw& d, SkCanvas::PointMode mode, | 801 void SkPDFDevice::drawPoints(const SkDraw& d, SkCanvas::PointMode mode, |
788 size_t count, const SkPoint* points, | 802 size_t count, const SkPoint* points, |
789 const SkPaint& passedPaint) { | 803 const SkPaint& passedPaint) { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
883 SkPath path; | 897 SkPath path; |
884 path.addRect(r); | 898 path.addRect(r); |
885 drawPath(d, path, paint, NULL, true); | 899 drawPath(d, path, paint, NULL, true); |
886 return; | 900 return; |
887 } | 901 } |
888 | 902 |
889 if (handleRectAnnotation(r, *d.fMatrix, paint)) { | 903 if (handleRectAnnotation(r, *d.fMatrix, paint)) { |
890 return; | 904 return; |
891 } | 905 } |
892 | 906 |
907 if (d.fMatrix->hasPerspective()) { | |
vandebo (ex-Chrome)
2013/09/12 21:37:05
If you put this in ScopedContentEntry, you'll cove
edisonn
2013/09/17 15:14:23
Done.
| |
908 NOT_IMPLEMENTED(true, false); // just report that PDF does not supports perspective | |
909 // TODO(edisonn): update the shape when p ossible | |
910 // or dump in an image otherwise | |
911 return; | |
912 } | |
913 | |
893 ScopedContentEntry content(this, d, paint); | 914 ScopedContentEntry content(this, d, paint); |
894 if (!content.entry()) { | 915 if (!content.entry()) { |
895 return; | 916 return; |
896 } | 917 } |
897 SkPDFUtils::AppendRectangle(r, &content.entry()->fContent); | 918 SkPDFUtils::AppendRectangle(r, &content.entry()->fContent); |
898 SkPDFUtils::PaintPath(paint.getStyle(), SkPath::kWinding_FillType, | 919 SkPDFUtils::PaintPath(paint.getStyle(), SkPath::kWinding_FillType, |
899 &content.entry()->fContent); | 920 &content.entry()->fContent); |
900 } | 921 } |
901 | 922 |
902 void SkPDFDevice::drawPath(const SkDraw& d, const SkPath& origPath, | 923 void SkPDFDevice::drawPath(const SkDraw& d, const SkPath& origPath, |
903 const SkPaint& paint, const SkMatrix* prePathMatrix, | 924 const SkPaint& paint, const SkMatrix* prePathMatrix, |
904 bool pathIsMutable) { | 925 bool pathIsMutable) { |
905 SkPath modifiedPath; | 926 SkPath modifiedPath; |
906 SkPath* pathPtr = const_cast<SkPath*>(&origPath); | 927 SkPath* pathPtr = const_cast<SkPath*>(&origPath); |
907 | 928 |
908 SkMatrix matrix = *d.fMatrix; | 929 SkMatrix matrix = *d.fMatrix; |
909 if (prePathMatrix) { | 930 if (prePathMatrix) { |
910 if (paint.getPathEffect() || paint.getStyle() != SkPaint::kFill_Style) { | 931 if (paint.getPathEffect() || paint.getStyle() != SkPaint::kFill_Style) { |
911 if (!pathIsMutable) { | 932 if (!pathIsMutable) { |
912 pathPtr = &modifiedPath; | 933 pathPtr = &modifiedPath; |
913 pathIsMutable = true; | 934 pathIsMutable = true; |
914 } | 935 } |
915 origPath.transform(*prePathMatrix, pathPtr); | 936 origPath.transform(*prePathMatrix, pathPtr); |
916 } else { | 937 } else { |
917 if (!matrix.preConcat(*prePathMatrix)) { | 938 if (!matrix.preConcat(*prePathMatrix)) { |
939 // TODO(edisonn): report somewhow why we failed? | |
918 return; | 940 return; |
919 } | 941 } |
920 } | 942 } |
921 } | 943 } |
922 | 944 |
945 if (matrix.hasPerspective()) { | |
946 NOT_IMPLEMENTED(true, false); // just report that PDF does not supports perspective | |
947 // TODO(edisonn): update the shape when p ossible | |
948 // or dump in an image otherwise | |
949 return; | |
950 } | |
951 | |
923 if (paint.getPathEffect()) { | 952 if (paint.getPathEffect()) { |
924 if (d.fClip->isEmpty()) { | 953 if (d.fClip->isEmpty()) { |
925 return; | 954 return; |
926 } | 955 } |
927 if (!pathIsMutable) { | 956 if (!pathIsMutable) { |
928 pathPtr = &modifiedPath; | 957 pathPtr = &modifiedPath; |
929 pathIsMutable = true; | 958 pathIsMutable = true; |
930 } | 959 } |
931 bool fill = paint.getFillPath(origPath, pathPtr); | 960 bool fill = paint.getFillPath(origPath, pathPtr); |
932 | 961 |
(...skipping 962 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1895 const SkPaint& paint) { | 1924 const SkPaint& paint) { |
1896 SkMatrix scaled; | 1925 SkMatrix scaled; |
1897 // Adjust for origin flip. | 1926 // Adjust for origin flip. |
1898 scaled.setScale(SK_Scalar1, -SK_Scalar1); | 1927 scaled.setScale(SK_Scalar1, -SK_Scalar1); |
1899 scaled.postTranslate(0, SK_Scalar1); | 1928 scaled.postTranslate(0, SK_Scalar1); |
1900 // Scale the image up from 1x1 to WxH. | 1929 // Scale the image up from 1x1 to WxH. |
1901 SkIRect subset = SkIRect::MakeWH(bitmap.width(), bitmap.height()); | 1930 SkIRect subset = SkIRect::MakeWH(bitmap.width(), bitmap.height()); |
1902 scaled.postScale(SkIntToScalar(subset.width()), | 1931 scaled.postScale(SkIntToScalar(subset.width()), |
1903 SkIntToScalar(subset.height())); | 1932 SkIntToScalar(subset.height())); |
1904 scaled.postConcat(matrix); | 1933 scaled.postConcat(matrix); |
1934 | |
1935 if (scaled.hasPerspective()) { | |
1936 NOT_IMPLEMENTED(true, false); // just report that PDF does not supports perspective | |
1937 // TODO(edisonn): update the shape when p ossible | |
1938 // or dump in an image otherwise | |
1939 return; | |
1940 } | |
1941 | |
1905 ScopedContentEntry content(this, clipStack, clipRegion, scaled, paint); | 1942 ScopedContentEntry content(this, clipStack, clipRegion, scaled, paint); |
1906 if (!content.entry()) { | 1943 if (!content.entry()) { |
1907 return; | 1944 return; |
1908 } | 1945 } |
1909 | 1946 |
1910 if (srcRect && !subset.intersect(*srcRect)) { | 1947 if (srcRect && !subset.intersect(*srcRect)) { |
1911 return; | 1948 return; |
1912 } | 1949 } |
1913 | 1950 |
1914 SkPDFImage* image = SkPDFImage::CreateImage(bitmap, subset, fEncoder); | 1951 SkPDFImage* image = SkPDFImage::CreateImage(bitmap, subset, fEncoder); |
1915 if (!image) { | 1952 if (!image) { |
1916 return; | 1953 return; |
1917 } | 1954 } |
1918 | 1955 |
1919 fXObjectResources.push(image); // Transfer reference. | 1956 fXObjectResources.push(image); // Transfer reference. |
1920 SkPDFUtils::DrawFormXObject(fXObjectResources.count() - 1, | 1957 SkPDFUtils::DrawFormXObject(fXObjectResources.count() - 1, |
1921 &content.entry()->fContent); | 1958 &content.entry()->fContent); |
1922 } | 1959 } |
1923 | 1960 |
1924 bool SkPDFDevice::onReadPixels(const SkBitmap& bitmap, int x, int y, | 1961 bool SkPDFDevice::onReadPixels(const SkBitmap& bitmap, int x, int y, |
1925 SkCanvas::Config8888) { | 1962 SkCanvas::Config8888) { |
1926 return false; | 1963 return false; |
1927 } | 1964 } |
1928 | 1965 |
1929 bool SkPDFDevice::allowImageFilter(SkImageFilter*) { | 1966 bool SkPDFDevice::allowImageFilter(SkImageFilter*) { |
1930 return false; | 1967 return false; |
1931 } | 1968 } |
OLD | NEW |