blob: d946f48197d55bc091f6ef967d725978060eeecd [file] [log] [blame]
halcanary66be6262016-03-21 13:01:34 -07001/*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
msarettc573a402016-08-02 08:05:56 -07008#include "SkLatticeIter.h"
halcanary66be6262016-03-21 13:01:34 -07009#include "SkPDFCanvas.h"
10#include "SkPDFDevice.h"
11
12SkPDFCanvas::SkPDFCanvas(const sk_sp<SkPDFDevice>& dev)
13 : SkCanvas(dev.get()) {}
14
15SkPDFCanvas::~SkPDFCanvas() {}
16
reed1e7f5e72016-04-27 07:49:17 -070017/*
18 * PDF's impl sometimes wants to access the raster clip as a SkRegion. To keep this valid,
19 * we intercept all clip calls to ensure that the clip stays BW (i.e. never antialiased), since
20 * an antialiased clip won't build a SkRegion (it builds SkAAClip).
21 */
Mike Reedc1f77742016-12-09 09:00:50 -050022void SkPDFCanvas::onClipRect(const SkRect& rect, SkClipOp op, ClipEdgeStyle edgeStyle) {
reed1e7f5e72016-04-27 07:49:17 -070023 this->INHERITED::onClipRect(rect, op, kHard_ClipEdgeStyle);
24}
25
Mike Reedc1f77742016-12-09 09:00:50 -050026void SkPDFCanvas::onClipRRect(const SkRRect& rrect, SkClipOp op, ClipEdgeStyle edgeStyle) {
reed1e7f5e72016-04-27 07:49:17 -070027 this->INHERITED::onClipRRect(rrect, op, kHard_ClipEdgeStyle);
28}
29
Mike Reedc1f77742016-12-09 09:00:50 -050030void SkPDFCanvas::onClipPath(const SkPath& path, SkClipOp op, ClipEdgeStyle edgeStyle) {
reed1e7f5e72016-04-27 07:49:17 -070031 this->INHERITED::onClipPath(path, op, kHard_ClipEdgeStyle);
32}
33
halcanary66be6262016-03-21 13:01:34 -070034void SkPDFCanvas::onDrawBitmapNine(const SkBitmap& bitmap,
35 const SkIRect& center,
36 const SkRect& dst,
37 const SkPaint* paint) {
msarettc573a402016-08-02 08:05:56 -070038 SkLatticeIter iter(bitmap.width(), bitmap.height(), center, dst);
halcanary66be6262016-03-21 13:01:34 -070039 SkRect srcR, dstR;
40 while (iter.next(&srcR, &dstR)) {
41 this->drawBitmapRect(bitmap, srcR, dstR, paint);
42 }
43}
44
45void SkPDFCanvas::onDrawImageNine(const SkImage* image,
46 const SkIRect& center,
47 const SkRect& dst,
48 const SkPaint* paint) {
msarettc573a402016-08-02 08:05:56 -070049 SkLatticeIter iter(image->width(), image->height(), center, dst);
halcanary66be6262016-03-21 13:01:34 -070050 SkRect srcR, dstR;
51 while (iter.next(&srcR, &dstR)) {
52 this->drawImageRect(image, srcR, dstR, paint);
53 }
54}
55
56void SkPDFCanvas::onDrawImageRect(const SkImage* image,
Hal Canaryf50ff392016-09-30 10:25:39 -040057 const SkRect* src,
halcanary66be6262016-03-21 13:01:34 -070058 const SkRect& dst,
59 const SkPaint* paint,
60 SkCanvas::SrcRectConstraint constraint) {
halcanary66be6262016-03-21 13:01:34 -070061 SkAutoCanvasRestore autoCanvasRestore(this, true);
Hal Canaryf50ff392016-09-30 10:25:39 -040062 this->clipRect(dst);
63 this->SkCanvas::onDrawImageRect(image, src, dst, paint, constraint);
halcanary66be6262016-03-21 13:01:34 -070064}
65
66void SkPDFCanvas::onDrawBitmapRect(const SkBitmap& bitmap,
Hal Canaryf50ff392016-09-30 10:25:39 -040067 const SkRect* src,
halcanary66be6262016-03-21 13:01:34 -070068 const SkRect& dst,
69 const SkPaint* paint,
70 SkCanvas::SrcRectConstraint constraint) {
halcanary66be6262016-03-21 13:01:34 -070071 SkAutoCanvasRestore autoCanvasRestore(this, true);
Hal Canaryf50ff392016-09-30 10:25:39 -040072 this->clipRect(dst);
73 this->SkCanvas::onDrawBitmapRect(bitmap, src, dst, paint, constraint);
halcanary66be6262016-03-21 13:01:34 -070074}
msarettc573a402016-08-02 08:05:56 -070075
76void SkPDFCanvas::onDrawImageLattice(const SkImage* image,
77 const Lattice& lattice,
78 const SkRect& dst,
79 const SkPaint* paint) {
msarett71df2d72016-09-30 12:41:42 -070080 SkLatticeIter iter(lattice, dst);
msarettc573a402016-08-02 08:05:56 -070081 SkRect srcR, dstR;
82 while (iter.next(&srcR, &dstR)) {
83 this->drawImageRect(image, srcR, dstR, paint);
84 }
85}
msarett16882062016-08-16 09:31:08 -070086
87void SkPDFCanvas::onDrawBitmapLattice(const SkBitmap& bitmap,
88 const Lattice& lattice,
89 const SkRect& dst,
90 const SkPaint* paint) {
msarett71df2d72016-09-30 12:41:42 -070091 SkLatticeIter iter(lattice, dst);
msarett16882062016-08-16 09:31:08 -070092 SkRect srcR, dstR;
93 while (iter.next(&srcR, &dstR)) {
94 this->drawBitmapRect(bitmap, srcR, dstR, paint);
95 }
96}
97