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 683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
694 if (paint.getXfermode()) { | 694 if (paint.getXfermode()) { |
695 paint.getXfermode()->asMode(&fXfermode); | 695 paint.getXfermode()->asMode(&fXfermode); |
696 } | 696 } |
697 fContentEntry = fDevice->setUpContentEntry(clipStack, clipRegion, | 697 fContentEntry = fDevice->setUpContentEntry(clipStack, clipRegion, |
698 matrix, paint, hasText, | 698 matrix, paint, hasText, |
699 &fDstFormXObject); | 699 &fDstFormXObject); |
700 } | 700 } |
701 }; | 701 }; |
702 | 702 |
703 //////////////////////////////////////////////////////////////////////////////// | 703 //////////////////////////////////////////////////////////////////////////////// |
704 | 704 |
robertphillips
2014/06/27 12:02:58
Shouldn't this be make_content_info ?
reed1
2014/06/27 12:39:42
Done.
| |
705 static inline SkBitmap makeContentBitmap(const SkISize& contentSize, | 705 static inline SkImageInfo makeContentInfo(const SkISize& contentSize, |
706 const SkMatrix* initialTransform) { | 706 const SkMatrix* initialTransform) { |
707 SkImageInfo info; | 707 SkImageInfo info; |
708 if (initialTransform) { | 708 if (initialTransform) { |
709 // Compute the size of the drawing area. | 709 // Compute the size of the drawing area. |
710 SkVector drawingSize; | 710 SkVector drawingSize; |
711 SkMatrix inverse; | 711 SkMatrix inverse; |
712 drawingSize.set(SkIntToScalar(contentSize.fWidth), | 712 drawingSize.set(SkIntToScalar(contentSize.fWidth), |
713 SkIntToScalar(contentSize.fHeight)); | 713 SkIntToScalar(contentSize.fHeight)); |
714 if (!initialTransform->invert(&inverse)) { | 714 if (!initialTransform->invert(&inverse)) { |
715 // This shouldn't happen, initial transform should be invertible. | 715 // This shouldn't happen, initial transform should be invertible. |
716 SkASSERT(false); | 716 SkASSERT(false); |
717 inverse.reset(); | 717 inverse.reset(); |
718 } | 718 } |
719 inverse.mapVectors(&drawingSize, 1); | 719 inverse.mapVectors(&drawingSize, 1); |
720 SkISize size = SkSize::Make(drawingSize.fX, drawingSize.fY).toRound(); | 720 SkISize size = SkSize::Make(drawingSize.fX, drawingSize.fY).toRound(); |
721 info = SkImageInfo::MakeUnknown(abs(size.fWidth), abs(size.fHeight)); | 721 info = SkImageInfo::MakeUnknown(abs(size.fWidth), abs(size.fHeight)); |
722 } else { | 722 } else { |
723 info = SkImageInfo::MakeUnknown(abs(contentSize.fWidth), | 723 info = SkImageInfo::MakeUnknown(abs(contentSize.fWidth), |
724 abs(contentSize.fHeight)); | 724 abs(contentSize.fHeight)); |
725 } | 725 } |
726 | 726 return info; |
727 SkBitmap bitmap; | |
728 bitmap.setInfo(info); | |
729 return bitmap; | |
730 } | 727 } |
731 | 728 |
732 // TODO(vandebo) change pageSize to SkSize. | 729 // TODO(vandebo) change pageSize to SkSize. |
robertphillips
2014/06/27 12:02:58
Remove this TODO ?
reed1
2014/06/27 12:39:42
Done.
| |
733 // TODO: inherit from SkBaseDevice instead of SkBitmapDevice | 730 // TODO: inherit from SkBaseDevice instead of SkBitmapDevice |
734 SkPDFDevice::SkPDFDevice(const SkISize& pageSize, const SkISize& contentSize, | 731 SkPDFDevice::SkPDFDevice(const SkISize& pageSize, const SkISize& contentSize, |
735 const SkMatrix& initialTransform) | 732 const SkMatrix& initialTransform) |
736 : SkBitmapDevice(makeContentBitmap(contentSize, &initialTransform)), | 733 : fPageSize(pageSize) |
737 fPageSize(pageSize), | 734 , fContentSize(contentSize) |
738 fContentSize(contentSize), | 735 , fLastContentEntry(NULL) |
739 fLastContentEntry(NULL), | 736 , fLastMarginContentEntry(NULL) |
740 fLastMarginContentEntry(NULL), | 737 , fClipStack(NULL) |
741 fClipStack(NULL), | 738 , fEncoder(NULL) |
742 fEncoder(NULL), | 739 , fRasterDpi(72.0f) |
743 fRasterDpi(72.0f) { | 740 { |
744 // Just report that PDF does not supports perspective in the | 741 // Just report that PDF does not supports perspective in the |
745 // initial transform. | 742 // initial transform. |
746 NOT_IMPLEMENTED(initialTransform.hasPerspective(), true); | 743 NOT_IMPLEMENTED(initialTransform.hasPerspective(), true); |
747 | 744 |
748 // Skia generally uses the top left as the origin but PDF natively has the | 745 // Skia generally uses the top left as the origin but PDF natively has the |
749 // origin at the bottom left. This matrix corrects for that. But that only | 746 // origin at the bottom left. This matrix corrects for that. But that only |
750 // needs to be done once, we don't do it when layering. | 747 // needs to be done once, we don't do it when layering. |
751 fInitialTransform.setTranslate(0, SkIntToScalar(pageSize.fHeight)); | 748 fInitialTransform.setTranslate(0, SkIntToScalar(pageSize.fHeight)); |
752 fInitialTransform.preScale(SK_Scalar1, -SK_Scalar1); | 749 fInitialTransform.preScale(SK_Scalar1, -SK_Scalar1); |
753 fInitialTransform.preConcat(initialTransform); | 750 fInitialTransform.preConcat(initialTransform); |
754 | 751 |
755 SkIRect existingClip = SkIRect::MakeWH(this->width(), this->height()); | 752 SkIRect existingClip = SkIRect::MakeWH(this->width(), this->height()); |
756 fExistingClipRegion.setRect(existingClip); | 753 fExistingClipRegion.setRect(existingClip); |
757 | 754 fLegacyBitmap.setInfo(makeContentInfo(contentSize, &initialTransform)); |
758 this->init(); | 755 this->init(); |
759 } | 756 } |
760 | 757 |
761 // TODO(vandebo) change layerSize to SkSize. | 758 // TODO(vandebo) change layerSize to SkSize. |
762 SkPDFDevice::SkPDFDevice(const SkISize& layerSize, | 759 SkPDFDevice::SkPDFDevice(const SkISize& layerSize, |
763 const SkClipStack& existingClipStack, | 760 const SkClipStack& existingClipStack, |
764 const SkRegion& existingClipRegion) | 761 const SkRegion& existingClipRegion) |
765 : SkBitmapDevice(makeContentBitmap(layerSize, NULL)), | 762 : fPageSize(layerSize) |
766 fPageSize(layerSize), | 763 , fContentSize(layerSize) |
767 fContentSize(layerSize), | 764 , fExistingClipStack(existingClipStack) |
768 fExistingClipStack(existingClipStack), | 765 , fExistingClipRegion(existingClipRegion) |
769 fExistingClipRegion(existingClipRegion), | 766 , fLastContentEntry(NULL) |
770 fLastContentEntry(NULL), | 767 , fLastMarginContentEntry(NULL) |
771 fLastMarginContentEntry(NULL), | 768 , fClipStack(NULL) |
772 fClipStack(NULL), | 769 , fEncoder(NULL) |
773 fEncoder(NULL), | 770 , fRasterDpi(72.0f) |
774 fRasterDpi(72.0f) { | 771 { |
775 fInitialTransform.reset(); | 772 fInitialTransform.reset(); |
773 fLegacyBitmap.setInfo(makeContentInfo(layerSize, NULL)); | |
774 | |
776 this->init(); | 775 this->init(); |
777 } | 776 } |
778 | 777 |
779 SkPDFDevice::~SkPDFDevice() { | 778 SkPDFDevice::~SkPDFDevice() { |
780 this->cleanUp(true); | 779 this->cleanUp(true); |
781 } | 780 } |
782 | 781 |
783 void SkPDFDevice::init() { | 782 void SkPDFDevice::init() { |
784 fAnnotations = NULL; | 783 fAnnotations = NULL; |
785 fResourceDict = NULL; | 784 fResourceDict = NULL; |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
954 | 953 |
955 ScopedContentEntry content(this, d, paint); | 954 ScopedContentEntry content(this, d, paint); |
956 if (!content.entry()) { | 955 if (!content.entry()) { |
957 return; | 956 return; |
958 } | 957 } |
959 SkPDFUtils::AppendRectangle(r, &content.entry()->fContent); | 958 SkPDFUtils::AppendRectangle(r, &content.entry()->fContent); |
960 SkPDFUtils::PaintPath(paint.getStyle(), SkPath::kWinding_FillType, | 959 SkPDFUtils::PaintPath(paint.getStyle(), SkPath::kWinding_FillType, |
961 &content.entry()->fContent); | 960 &content.entry()->fContent); |
962 } | 961 } |
963 | 962 |
964 void SkPDFDevice::drawRRect(const SkDraw& draw, const SkRRect& rrect, | 963 void SkPDFDevice::drawRRect(const SkDraw& draw, const SkRRect& rrect, const SkPa int& paint) { |
965 const SkPaint& paint) { | |
966 SkPath path; | 964 SkPath path; |
967 path.addRRect(rrect); | 965 path.addRRect(rrect); |
968 this->drawPath(draw, path, paint, NULL, true); | 966 this->drawPath(draw, path, paint, NULL, true); |
969 } | 967 } |
970 | 968 |
969 void SkPDFDevice::drawOval(const SkDraw& draw, const SkRect& oval, const SkPaint & paint) { | |
970 SkPath path; | |
971 path.addOval(oval); | |
972 this->drawPath(draw, path, paint, NULL, true); | |
973 } | |
974 | |
971 void SkPDFDevice::drawPath(const SkDraw& d, const SkPath& origPath, | 975 void SkPDFDevice::drawPath(const SkDraw& d, const SkPath& origPath, |
972 const SkPaint& paint, const SkMatrix* prePathMatrix, | 976 const SkPaint& paint, const SkMatrix* prePathMatrix, |
973 bool pathIsMutable) { | 977 bool pathIsMutable) { |
974 SkPath modifiedPath; | 978 SkPath modifiedPath; |
975 SkPath* pathPtr = const_cast<SkPath*>(&origPath); | 979 SkPath* pathPtr = const_cast<SkPath*>(&origPath); |
976 | 980 |
977 SkMatrix matrix = *d.fMatrix; | 981 SkMatrix matrix = *d.fMatrix; |
978 if (prePathMatrix) { | 982 if (prePathMatrix) { |
979 if (paint.getPathEffect() || paint.getStyle() != SkPaint::kFill_Style) { | 983 if (paint.getPathEffect() || paint.getStyle() != SkPaint::kFill_Style) { |
980 if (!pathIsMutable) { | 984 if (!pathIsMutable) { |
(...skipping 1249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2230 // the image. Avoiding alpha will reduce the pdf size and generation | 2234 // the image. Avoiding alpha will reduce the pdf size and generation |
2231 // CPU time some. | 2235 // CPU time some. |
2232 | 2236 |
2233 const int w = SkScalarCeilToInt(physicalPerspectiveOutline.getBounds().w idth()); | 2237 const int w = SkScalarCeilToInt(physicalPerspectiveOutline.getBounds().w idth()); |
2234 const int h = SkScalarCeilToInt(physicalPerspectiveOutline.getBounds().h eight()); | 2238 const int h = SkScalarCeilToInt(physicalPerspectiveOutline.getBounds().h eight()); |
2235 if (!perspectiveBitmap.allocPixels(SkImageInfo::MakeN32Premul(w, h))) { | 2239 if (!perspectiveBitmap.allocPixels(SkImageInfo::MakeN32Premul(w, h))) { |
2236 return; | 2240 return; |
2237 } | 2241 } |
2238 perspectiveBitmap.eraseColor(SK_ColorTRANSPARENT); | 2242 perspectiveBitmap.eraseColor(SK_ColorTRANSPARENT); |
2239 | 2243 |
2240 SkBitmapDevice device(perspectiveBitmap); | 2244 SkCanvas canvas(perspectiveBitmap); |
2241 SkCanvas canvas(&device); | |
2242 | 2245 |
2243 SkScalar deltaX = bounds.left(); | 2246 SkScalar deltaX = bounds.left(); |
2244 SkScalar deltaY = bounds.top(); | 2247 SkScalar deltaY = bounds.top(); |
2245 | 2248 |
2246 SkMatrix offsetMatrix = origMatrix; | 2249 SkMatrix offsetMatrix = origMatrix; |
2247 offsetMatrix.postTranslate(-deltaX, -deltaY); | 2250 offsetMatrix.postTranslate(-deltaX, -deltaY); |
2248 offsetMatrix.postScale(scaleX, scaleY); | 2251 offsetMatrix.postScale(scaleX, scaleY); |
2249 | 2252 |
2250 // Translate the draw in the new canvas, so we perfectly fit the | 2253 // Translate the draw in the new canvas, so we perfectly fit the |
2251 // shape in the bitmap. | 2254 // shape in the bitmap. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2297 | 2300 |
2298 SkAutoTUnref<SkPDFImage> image( | 2301 SkAutoTUnref<SkPDFImage> image( |
2299 SkPDFImage::CreateImage(*bitmap, subset, fEncoder)); | 2302 SkPDFImage::CreateImage(*bitmap, subset, fEncoder)); |
2300 if (!image) { | 2303 if (!image) { |
2301 return; | 2304 return; |
2302 } | 2305 } |
2303 | 2306 |
2304 SkPDFUtils::DrawFormXObject(this->addXObjectResource(image.get()), | 2307 SkPDFUtils::DrawFormXObject(this->addXObjectResource(image.get()), |
2305 &content.entry()->fContent); | 2308 &content.entry()->fContent); |
2306 } | 2309 } |
2307 | 2310 |
robertphillips
2014/06/27 12:02:58
Can these last two be put in the header ?
reed1
2014/06/27 12:39:42
Done.
| |
2311 const SkBitmap& SkPDFDevice::onAccessBitmap() { | |
2312 return fLegacyBitmap; | |
2313 } | |
2314 | |
2308 bool SkPDFDevice::allowImageFilter(const SkImageFilter*) { | 2315 bool SkPDFDevice::allowImageFilter(const SkImageFilter*) { |
2309 return false; | 2316 return false; |
2310 } | 2317 } |
OLD | NEW |