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 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
625 ContentEntry* entry() { return fContentEntry; } | 625 ContentEntry* entry() { return fContentEntry; } |
626 private: | 626 private: |
627 SkPDFDevice* fDevice; | 627 SkPDFDevice* fDevice; |
628 ContentEntry* fContentEntry; | 628 ContentEntry* fContentEntry; |
629 SkXfermode::Mode fXfermode; | 629 SkXfermode::Mode fXfermode; |
630 SkPDFFormXObject* fDstFormXObject; | 630 SkPDFFormXObject* fDstFormXObject; |
631 | 631 |
632 void init(const SkClipStack* clipStack, const SkRegion& clipRegion, | 632 void init(const SkClipStack* clipStack, const SkRegion& clipRegion, |
633 const SkMatrix& matrix, const SkPaint& paint, bool hasText) { | 633 const SkMatrix& matrix, const SkPaint& paint, bool hasText) { |
634 fDstFormXObject = NULL; | 634 fDstFormXObject = NULL; |
635 if (matrix.hasPerspective() || | |
vandebo (ex-Chrome)
2013/09/17 16:35:09
The predominate style of this file is 80col. The
edisonn
2013/09/17 17:32:04
Done.
| |
636 (paint.getShader() && paint.getShader()->getLocalMatrix().hasPer spective())) { | |
637 NOT_IMPLEMENTED(true, false); // just report that PDF does not supp orts perspective | |
638 // TODO(edisonn): update the shape wh en possible | |
639 // or dump in an image otherwise | |
640 return; | |
641 } | |
642 | |
635 if (paint.getXfermode()) { | 643 if (paint.getXfermode()) { |
636 paint.getXfermode()->asMode(&fXfermode); | 644 paint.getXfermode()->asMode(&fXfermode); |
637 } | 645 } |
638 fContentEntry = fDevice->setUpContentEntry(clipStack, clipRegion, | 646 fContentEntry = fDevice->setUpContentEntry(clipStack, clipRegion, |
639 matrix, paint, hasText, | 647 matrix, paint, hasText, |
640 &fDstFormXObject); | 648 &fDstFormXObject); |
641 } | 649 } |
642 }; | 650 }; |
643 | 651 |
644 //////////////////////////////////////////////////////////////////////////////// | 652 //////////////////////////////////////////////////////////////////////////////// |
(...skipping 27 matching lines...) Expand all Loading... | |
672 // TODO(vandebo) change pageSize to SkSize. | 680 // TODO(vandebo) change pageSize to SkSize. |
673 SkPDFDevice::SkPDFDevice(const SkISize& pageSize, const SkISize& contentSize, | 681 SkPDFDevice::SkPDFDevice(const SkISize& pageSize, const SkISize& contentSize, |
674 const SkMatrix& initialTransform) | 682 const SkMatrix& initialTransform) |
675 : SkBitmapDevice(makeContentBitmap(contentSize, &initialTransform)), | 683 : SkBitmapDevice(makeContentBitmap(contentSize, &initialTransform)), |
676 fPageSize(pageSize), | 684 fPageSize(pageSize), |
677 fContentSize(contentSize), | 685 fContentSize(contentSize), |
678 fLastContentEntry(NULL), | 686 fLastContentEntry(NULL), |
679 fLastMarginContentEntry(NULL), | 687 fLastMarginContentEntry(NULL), |
680 fClipStack(NULL), | 688 fClipStack(NULL), |
681 fEncoder(NULL) { | 689 fEncoder(NULL) { |
690 // just report that PDF does not supports perspective | |
691 // TODO(edisonn): update the shape when possible | |
692 // or dump in an image otherwise | |
693 NOT_IMPLEMENTED(initialTransform.hasPerspective(), true); | |
694 | |
682 // Skia generally uses the top left as the origin but PDF natively has the | 695 // 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 | 696 // 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. | 697 // needs to be done once, we don't do it when layering. |
685 fInitialTransform.setTranslate(0, SkIntToScalar(pageSize.fHeight)); | 698 fInitialTransform.setTranslate(0, SkIntToScalar(pageSize.fHeight)); |
686 fInitialTransform.preScale(SK_Scalar1, -SK_Scalar1); | 699 fInitialTransform.preScale(SK_Scalar1, -SK_Scalar1); |
687 fInitialTransform.preConcat(initialTransform); | 700 fInitialTransform.preConcat(initialTransform); |
688 | 701 |
689 SkIRect existingClip = SkIRect::MakeWH(this->width(), this->height()); | 702 SkIRect existingClip = SkIRect::MakeWH(this->width(), this->height()); |
690 fExistingClipRegion.setRect(existingClip); | 703 fExistingClipRegion.setRect(existingClip); |
691 | 704 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
770 return; | 783 return; |
771 } | 784 } |
772 SkRect bbox = SkRect::MakeWH(SkIntToScalar(this->width()), | 785 SkRect bbox = SkRect::MakeWH(SkIntToScalar(this->width()), |
773 SkIntToScalar(this->height())); | 786 SkIntToScalar(this->height())); |
774 SkMatrix totalTransform = fInitialTransform; | 787 SkMatrix totalTransform = fInitialTransform; |
775 totalTransform.preConcat(contentEntry->fState.fMatrix); | 788 totalTransform.preConcat(contentEntry->fState.fMatrix); |
776 SkMatrix inverse; | 789 SkMatrix inverse; |
777 if (!totalTransform.invert(&inverse)) { | 790 if (!totalTransform.invert(&inverse)) { |
778 return; | 791 return; |
779 } | 792 } |
793 | |
794 if (totalTransform.hasPerspective()) { | |
vandebo (ex-Chrome)
2013/09/17 16:35:09
This isn't needed. totalTransform is formed from
edisonn
2013/09/17 17:32:04
Done.
| |
795 NOT_IMPLEMENTED(true, false); // just report that PDF does not supports perspective | |
796 // TODO(edisonn): update the shape when p ossible | |
797 // or dump in an image otherwise | |
798 return; | |
799 } | |
800 | |
780 inverse.mapRect(&bbox); | 801 inverse.mapRect(&bbox); |
781 | 802 |
782 SkPDFUtils::AppendRectangle(bbox, &contentEntry->fContent); | 803 SkPDFUtils::AppendRectangle(bbox, &contentEntry->fContent); |
783 SkPDFUtils::PaintPath(paint.getStyle(), SkPath::kWinding_FillType, | 804 SkPDFUtils::PaintPath(paint.getStyle(), SkPath::kWinding_FillType, |
784 &contentEntry->fContent); | 805 &contentEntry->fContent); |
785 } | 806 } |
786 | 807 |
787 void SkPDFDevice::drawPoints(const SkDraw& d, SkCanvas::PointMode mode, | 808 void SkPDFDevice::drawPoints(const SkDraw& d, SkCanvas::PointMode mode, |
788 size_t count, const SkPoint* points, | 809 size_t count, const SkPoint* points, |
789 const SkPaint& passedPaint) { | 810 const SkPaint& passedPaint) { |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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? | |
vandebo (ex-Chrome)
2013/09/17 16:35:09
Log statement?
edisonn
2013/09/17 17:32:04
it is a todo, not looking for an answer in this cl
| |
918 return; | 940 return; |
919 } | 941 } |
920 } | 942 } |
921 } | 943 } |
922 | 944 |
945 if (matrix.hasPerspective()) { | |
vandebo (ex-Chrome)
2013/09/17 16:35:09
Not necessary, the matrix will eventually get chec
edisonn
2013/09/17 17:32:04
Done.
| |
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()) { | |
vandebo (ex-Chrome)
2013/09/17 16:35:09
Not needed - scaled in passed into ScopedContentEn
edisonn
2013/09/17 17:32:04
Done.
| |
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 |