| 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 "SkAnnotationKeys.h" | 10 #include "SkAnnotationKeys.h" |
| (...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1031 SkPDFUtils::PaintPath(paint.getStyle(), pathPtr->getFillType(), | 1031 SkPDFUtils::PaintPath(paint.getStyle(), pathPtr->getFillType(), |
| 1032 &content.entry()->fContent); | 1032 &content.entry()->fContent); |
| 1033 } | 1033 } |
| 1034 | 1034 |
| 1035 void SkPDFDevice::drawBitmapRect(const SkDraw& draw, | 1035 void SkPDFDevice::drawBitmapRect(const SkDraw& draw, |
| 1036 const SkBitmap& bitmap, | 1036 const SkBitmap& bitmap, |
| 1037 const SkRect* src, | 1037 const SkRect* src, |
| 1038 const SkRect& dst, | 1038 const SkRect& dst, |
| 1039 const SkPaint& srcPaint, | 1039 const SkPaint& srcPaint, |
| 1040 SkCanvas::SrcRectConstraint constraint) { | 1040 SkCanvas::SrcRectConstraint constraint) { |
| 1041 const SkImage* image = fCanon->bitmapToImage(bitmap); | 1041 SkASSERT(false); |
| 1042 if (!image) { | |
| 1043 return; | |
| 1044 } | |
| 1045 // ownership of this image is retained by the canon. | |
| 1046 this->drawImageRect(draw, image, src, dst, srcPaint, constraint); | |
| 1047 } | 1042 } |
| 1048 | 1043 |
| 1049 void SkPDFDevice::drawBitmap(const SkDraw& d, | 1044 void SkPDFDevice::drawBitmap(const SkDraw& d, |
| 1050 const SkBitmap& bitmap, | 1045 const SkBitmap& bitmap, |
| 1051 const SkMatrix& matrix, | 1046 const SkMatrix& matrix, |
| 1052 const SkPaint& srcPaint) { | 1047 const SkPaint& srcPaint) { |
| 1053 SkPaint paint = srcPaint; | 1048 SkPaint paint = srcPaint; |
| 1054 if (bitmap.isOpaque()) { | 1049 if (bitmap.isOpaque()) { |
| 1055 replace_srcmode_on_opaque_paint(&paint); | 1050 replace_srcmode_on_opaque_paint(&paint); |
| 1056 } | 1051 } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1113 this->internalDrawImage(transform, draw.fClipStack, *draw.fClip, image, | 1108 this->internalDrawImage(transform, draw.fClipStack, *draw.fClip, image, |
| 1114 nullptr, paint); | 1109 nullptr, paint); |
| 1115 } | 1110 } |
| 1116 | 1111 |
| 1117 void SkPDFDevice::drawImageRect(const SkDraw& draw, | 1112 void SkPDFDevice::drawImageRect(const SkDraw& draw, |
| 1118 const SkImage* image, | 1113 const SkImage* image, |
| 1119 const SkRect* src, | 1114 const SkRect* src, |
| 1120 const SkRect& dst, | 1115 const SkRect& dst, |
| 1121 const SkPaint& srcPaint, | 1116 const SkPaint& srcPaint, |
| 1122 SkCanvas::SrcRectConstraint constraint) { | 1117 SkCanvas::SrcRectConstraint constraint) { |
| 1123 if (!image) { | 1118 SkASSERT(false); |
| 1124 return; | |
| 1125 } | |
| 1126 if (draw.fClip->isEmpty()) { | |
| 1127 return; | |
| 1128 } | |
| 1129 SkPaint paint = srcPaint; | |
| 1130 if (image->isOpaque()) { | |
| 1131 replace_srcmode_on_opaque_paint(&paint); | |
| 1132 } | |
| 1133 // TODO: this code path must be updated to respect the flags parameter | |
| 1134 SkMatrix matrix; | |
| 1135 SkRect tmpSrc, tmpDst; | |
| 1136 SkRect imageBounds = SkRect::Make(image->bounds()); | |
| 1137 | |
| 1138 // Compute matrix from the two rectangles | |
| 1139 if (src) { | |
| 1140 tmpSrc = *src; | |
| 1141 } else { | |
| 1142 tmpSrc = imageBounds; | |
| 1143 } | |
| 1144 matrix.setRectToRect(tmpSrc, dst, SkMatrix::kFill_ScaleToFit); | |
| 1145 | |
| 1146 // clip the tmpSrc to the bounds of the bitmap, and recompute dstRect if | |
| 1147 // needed (if the src was clipped). No check needed if src==null. | |
| 1148 sk_sp<const SkImage> autoImageUnref; | |
| 1149 if (src) { | |
| 1150 if (!imageBounds.contains(*src)) { | |
| 1151 if (!tmpSrc.intersect(imageBounds)) { | |
| 1152 return; // nothing to draw | |
| 1153 } | |
| 1154 // recompute dst, based on the smaller tmpSrc | |
| 1155 matrix.mapRect(&tmpDst, tmpSrc); | |
| 1156 } | |
| 1157 | |
| 1158 // since we may need to clamp to the borders of the src rect within | |
| 1159 // the bitmap, we extract a subset. | |
| 1160 SkIRect srcIR; | |
| 1161 tmpSrc.roundOut(&srcIR); | |
| 1162 | |
| 1163 autoImageUnref = image->makeSubset(srcIR); | |
| 1164 if (!autoImageUnref) { | |
| 1165 return; | |
| 1166 } | |
| 1167 image = autoImageUnref.get(); | |
| 1168 // Since we did an extract, we need to adjust the matrix accordingly | |
| 1169 SkScalar dx = 0, dy = 0; | |
| 1170 if (srcIR.fLeft > 0) { | |
| 1171 dx = SkIntToScalar(srcIR.fLeft); | |
| 1172 } | |
| 1173 if (srcIR.fTop > 0) { | |
| 1174 dy = SkIntToScalar(srcIR.fTop); | |
| 1175 } | |
| 1176 if (dx || dy) { | |
| 1177 matrix.preTranslate(dx, dy); | |
| 1178 } | |
| 1179 } | |
| 1180 matrix.postConcat(*draw.fMatrix); | |
| 1181 this->internalDrawImage(matrix, draw.fClipStack, *draw.fClip, image, | |
| 1182 nullptr, paint); | |
| 1183 } | 1119 } |
| 1184 | 1120 |
| 1185 // Create a PDF string. Maximum length (in bytes) is 65,535. | 1121 // Create a PDF string. Maximum length (in bytes) is 65,535. |
| 1186 // @param input A string value. | 1122 // @param input A string value. |
| 1187 // @param len The length of the input array. | 1123 // @param len The length of the input array. |
| 1188 // @param wideChars True iff the upper byte in each uint16_t is | 1124 // @param wideChars True iff the upper byte in each uint16_t is |
| 1189 // significant and should be encoded and not | 1125 // significant and should be encoded and not |
| 1190 // discarded. If true, the upper byte is encoded | 1126 // discarded. If true, the upper byte is encoded |
| 1191 // first. Otherwise, we assert the upper byte is | 1127 // first. Otherwise, we assert the upper byte is |
| 1192 // zero. | 1128 // zero. |
| (...skipping 1136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2329 pdfimage.reset(SkPDFCreateBitmapObject( | 2265 pdfimage.reset(SkPDFCreateBitmapObject( |
| 2330 image, fCanon->getPixelSerializer())); | 2266 image, fCanon->getPixelSerializer())); |
| 2331 if (!pdfimage) { | 2267 if (!pdfimage) { |
| 2332 return; | 2268 return; |
| 2333 } | 2269 } |
| 2334 fCanon->addPDFBitmap(image->uniqueID(), pdfimage.get()); | 2270 fCanon->addPDFBitmap(image->uniqueID(), pdfimage.get()); |
| 2335 } | 2271 } |
| 2336 SkPDFUtils::DrawFormXObject(this->addXObjectResource(pdfimage.get()), | 2272 SkPDFUtils::DrawFormXObject(this->addXObjectResource(pdfimage.get()), |
| 2337 &content.entry()->fContent); | 2273 &content.entry()->fContent); |
| 2338 } | 2274 } |
| OLD | NEW |