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 727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
738 NOT_IMPLEMENTED(initialTransform.hasPerspective(), true); | 738 NOT_IMPLEMENTED(initialTransform.hasPerspective(), true); |
739 | 739 |
740 // Skia generally uses the top left as the origin but PDF natively has the | 740 // Skia generally uses the top left as the origin but PDF natively has the |
741 // origin at the bottom left. This matrix corrects for that. But that only | 741 // origin at the bottom left. This matrix corrects for that. But that only |
742 // needs to be done once, we don't do it when layering. | 742 // needs to be done once, we don't do it when layering. |
743 fInitialTransform.setTranslate(0, SkIntToScalar(pageSize.fHeight)); | 743 fInitialTransform.setTranslate(0, SkIntToScalar(pageSize.fHeight)); |
744 fInitialTransform.preScale(SK_Scalar1, -SK_Scalar1); | 744 fInitialTransform.preScale(SK_Scalar1, -SK_Scalar1); |
745 fInitialTransform.preConcat(initialTransform); | 745 fInitialTransform.preConcat(initialTransform); |
746 fLegacyBitmap.setInfo(info); | 746 fLegacyBitmap.setInfo(info); |
747 | 747 |
748 SkIRect existingClip = SkIRect::MakeWH(info.width(), info.height()); | 748 SkIRect existingClip = info.bounds(); |
749 fExistingClipRegion.setRect(existingClip); | 749 fExistingClipRegion.setRect(existingClip); |
750 this->init(); | 750 this->init(); |
751 } | 751 } |
752 | 752 |
753 // TODO(vandebo) change layerSize to SkSize. | 753 // TODO(vandebo) change layerSize to SkSize. |
754 SkPDFDevice::SkPDFDevice(const SkISize& layerSize, | 754 SkPDFDevice::SkPDFDevice(const SkISize& layerSize, |
755 const SkClipStack& existingClipStack, | 755 const SkClipStack& existingClipStack, |
756 const SkRegion& existingClipRegion) | 756 const SkRegion& existingClipRegion) |
757 : fPageSize(layerSize) | 757 : fPageSize(layerSize) |
758 , fContentSize(layerSize) | 758 , fContentSize(layerSize) |
(...skipping 1415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2174 clipRegion = &perspectiveBounds; | 2174 clipRegion = &perspectiveBounds; |
2175 srcRect = NULL; | 2175 srcRect = NULL; |
2176 bitmap = &perspectiveBitmap; | 2176 bitmap = &perspectiveBitmap; |
2177 } | 2177 } |
2178 | 2178 |
2179 SkMatrix scaled; | 2179 SkMatrix scaled; |
2180 // Adjust for origin flip. | 2180 // Adjust for origin flip. |
2181 scaled.setScale(SK_Scalar1, -SK_Scalar1); | 2181 scaled.setScale(SK_Scalar1, -SK_Scalar1); |
2182 scaled.postTranslate(0, SK_Scalar1); | 2182 scaled.postTranslate(0, SK_Scalar1); |
2183 // Scale the image up from 1x1 to WxH. | 2183 // Scale the image up from 1x1 to WxH. |
2184 SkIRect subset = SkIRect::MakeWH(bitmap->width(), bitmap->height()); | 2184 SkIRect subset = bitmap->bounds(); |
2185 scaled.postScale(SkIntToScalar(subset.width()), | 2185 scaled.postScale(SkIntToScalar(subset.width()), |
2186 SkIntToScalar(subset.height())); | 2186 SkIntToScalar(subset.height())); |
2187 scaled.postConcat(matrix); | 2187 scaled.postConcat(matrix); |
2188 ScopedContentEntry content(this, clipStack, *clipRegion, scaled, paint); | 2188 ScopedContentEntry content(this, clipStack, *clipRegion, scaled, paint); |
2189 if (!content.entry() || (srcRect && !subset.intersect(*srcRect))) { | 2189 if (!content.entry() || (srcRect && !subset.intersect(*srcRect))) { |
2190 return; | 2190 return; |
2191 } | 2191 } |
2192 if (content.needShape()) { | 2192 if (content.needShape()) { |
2193 SkPath shape; | 2193 SkPath shape; |
2194 shape.addRect(SkRect::MakeWH(SkIntToScalar(subset.width()), | 2194 shape.addRect(SkRect::MakeWH(SkIntToScalar(subset.width()), |
2195 SkIntToScalar( subset.height()))); | 2195 SkIntToScalar( subset.height()))); |
2196 shape.transform(matrix); | 2196 shape.transform(matrix); |
2197 content.setShape(shape); | 2197 content.setShape(shape); |
2198 } | 2198 } |
2199 if (!content.needSource()) { | 2199 if (!content.needSource()) { |
2200 return; | 2200 return; |
2201 } | 2201 } |
2202 | 2202 |
2203 SkAutoTUnref<SkPDFObject> image( | 2203 SkAutoTUnref<SkPDFObject> image( |
2204 SkPDFCreateImageObject(*bitmap, subset, fEncoder)); | 2204 SkPDFCreateImageObject(*bitmap, subset, fEncoder)); |
2205 if (!image) { | 2205 if (!image) { |
2206 return; | 2206 return; |
2207 } | 2207 } |
2208 | 2208 |
2209 SkPDFUtils::DrawFormXObject(this->addXObjectResource(image.get()), | 2209 SkPDFUtils::DrawFormXObject(this->addXObjectResource(image.get()), |
2210 &content.entry()->fContent); | 2210 &content.entry()->fContent); |
2211 } | 2211 } |
2212 | 2212 |
OLD | NEW |