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