vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2011 Google Inc. |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 3 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include "SkPDFDevice.h" |
| 9 | |
vandebo@chromium.org | 238be8c | 2012-07-13 20:06:02 +0000 | [diff] [blame] | 10 | #include "SkAnnotation.h" |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 11 | #include "SkColor.h" |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 12 | #include "SkClipStack.h" |
reed@google.com | 8a85d0c | 2011-06-24 19:12:12 +0000 | [diff] [blame] | 13 | #include "SkData.h" |
vandebo@chromium.org | fb0b0ed | 2011-04-15 20:01:17 +0000 | [diff] [blame] | 14 | #include "SkDraw.h" |
vandebo@chromium.org | 4e1cc6a | 2013-01-25 19:27:23 +0000 | [diff] [blame] | 15 | #include "SkFontHost.h" |
vandebo@chromium.org | 28be72b | 2010-11-11 21:37:00 +0000 | [diff] [blame] | 16 | #include "SkGlyphCache.h" |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 17 | #include "SkPaint.h" |
vandebo@chromium.org | a518086 | 2010-10-26 19:48:49 +0000 | [diff] [blame] | 18 | #include "SkPath.h" |
commit-bot@chromium.org | 92ffe7d | 2013-07-31 22:54:31 +0000 | [diff] [blame] | 19 | #include "SkPathOps.h" |
vandebo@chromium.org | 28be72b | 2010-11-11 21:37:00 +0000 | [diff] [blame] | 20 | #include "SkPDFFont.h" |
vandebo@chromium.org | eb6c759 | 2010-10-26 19:54:45 +0000 | [diff] [blame] | 21 | #include "SkPDFFormXObject.h" |
vandebo@chromium.org | 77bcaa3 | 2011-04-15 20:57:37 +0000 | [diff] [blame] | 22 | #include "SkPDFGraphicState.h" |
| 23 | #include "SkPDFImage.h" |
commit-bot@chromium.org | 4740135 | 2013-07-23 21:49:29 +0000 | [diff] [blame] | 24 | #include "SkPDFResourceDict.h" |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 25 | #include "SkPDFShader.h" |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 26 | #include "SkPDFStream.h" |
vandebo@chromium.org | 77bcaa3 | 2011-04-15 20:57:37 +0000 | [diff] [blame] | 27 | #include "SkPDFTypes.h" |
ctguil@chromium.org | 9db86bb | 2011-03-04 21:43:27 +0000 | [diff] [blame] | 28 | #include "SkPDFUtils.h" |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 29 | #include "SkRect.h" |
| 30 | #include "SkString.h" |
vandebo@chromium.org | 28be72b | 2010-11-11 21:37:00 +0000 | [diff] [blame] | 31 | #include "SkTextFormatParams.h" |
vandebo@chromium.org | 4e1cc6a | 2013-01-25 19:27:23 +0000 | [diff] [blame] | 32 | #include "SkTemplates.h" |
reed@google.com | fed86bd | 2013-03-14 15:04:57 +0000 | [diff] [blame] | 33 | #include "SkTypefacePriv.h" |
edisonn@google.com | 6addb19 | 2013-04-02 15:33:08 +0000 | [diff] [blame] | 34 | #include "SkTSet.h" |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 35 | |
| 36 | // Utility functions |
| 37 | |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 38 | static void emit_pdf_color(SkColor color, SkWStream* result) { |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 39 | SkASSERT(SkColorGetA(color) == 0xFF); // We handle alpha elsewhere. |
| 40 | SkScalar colorMax = SkIntToScalar(0xFF); |
vandebo@chromium.org | 094316b | 2011-03-04 03:15:13 +0000 | [diff] [blame] | 41 | SkPDFScalar::Append( |
vandebo@chromium.org | cae5fba | 2011-03-28 19:03:50 +0000 | [diff] [blame] | 42 | SkScalarDiv(SkIntToScalar(SkColorGetR(color)), colorMax), result); |
| 43 | result->writeText(" "); |
vandebo@chromium.org | 094316b | 2011-03-04 03:15:13 +0000 | [diff] [blame] | 44 | SkPDFScalar::Append( |
vandebo@chromium.org | cae5fba | 2011-03-28 19:03:50 +0000 | [diff] [blame] | 45 | SkScalarDiv(SkIntToScalar(SkColorGetG(color)), colorMax), result); |
| 46 | result->writeText(" "); |
vandebo@chromium.org | 094316b | 2011-03-04 03:15:13 +0000 | [diff] [blame] | 47 | SkPDFScalar::Append( |
vandebo@chromium.org | cae5fba | 2011-03-28 19:03:50 +0000 | [diff] [blame] | 48 | SkScalarDiv(SkIntToScalar(SkColorGetB(color)), colorMax), result); |
| 49 | result->writeText(" "); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 50 | } |
| 51 | |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 52 | static SkPaint calculate_text_paint(const SkPaint& paint) { |
vandebo@chromium.org | 28be72b | 2010-11-11 21:37:00 +0000 | [diff] [blame] | 53 | SkPaint result = paint; |
| 54 | if (result.isFakeBoldText()) { |
| 55 | SkScalar fakeBoldScale = SkScalarInterpFunc(result.getTextSize(), |
| 56 | kStdFakeBoldInterpKeys, |
| 57 | kStdFakeBoldInterpValues, |
| 58 | kStdFakeBoldInterpLength); |
| 59 | SkScalar width = SkScalarMul(result.getTextSize(), fakeBoldScale); |
ctguil@chromium.org | 769fa6a | 2011-08-20 00:36:18 +0000 | [diff] [blame] | 60 | if (result.getStyle() == SkPaint::kFill_Style) { |
vandebo@chromium.org | 28be72b | 2010-11-11 21:37:00 +0000 | [diff] [blame] | 61 | result.setStyle(SkPaint::kStrokeAndFill_Style); |
ctguil@chromium.org | 769fa6a | 2011-08-20 00:36:18 +0000 | [diff] [blame] | 62 | } else { |
vandebo@chromium.org | 28be72b | 2010-11-11 21:37:00 +0000 | [diff] [blame] | 63 | width += result.getStrokeWidth(); |
ctguil@chromium.org | 769fa6a | 2011-08-20 00:36:18 +0000 | [diff] [blame] | 64 | } |
vandebo@chromium.org | 28be72b | 2010-11-11 21:37:00 +0000 | [diff] [blame] | 65 | result.setStrokeWidth(width); |
| 66 | } |
| 67 | return result; |
| 68 | } |
| 69 | |
| 70 | // Stolen from measure_text in SkDraw.cpp and then tweaked. |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 71 | static void align_text(SkDrawCacheProc glyphCacheProc, const SkPaint& paint, |
bungeman@google.com | 9a87cee | 2011-08-23 17:02:18 +0000 | [diff] [blame] | 72 | const uint16_t* glyphs, size_t len, |
| 73 | SkScalar* x, SkScalar* y) { |
| 74 | if (paint.getTextAlign() == SkPaint::kLeft_Align) { |
vandebo@chromium.org | 28be72b | 2010-11-11 21:37:00 +0000 | [diff] [blame] | 75 | return; |
ctguil@chromium.org | 769fa6a | 2011-08-20 00:36:18 +0000 | [diff] [blame] | 76 | } |
vandebo@chromium.org | 28be72b | 2010-11-11 21:37:00 +0000 | [diff] [blame] | 77 | |
| 78 | SkMatrix ident; |
| 79 | ident.reset(); |
bungeman@google.com | 532470f | 2013-01-22 19:25:14 +0000 | [diff] [blame] | 80 | SkAutoGlyphCache autoCache(paint, NULL, &ident); |
vandebo@chromium.org | 28be72b | 2010-11-11 21:37:00 +0000 | [diff] [blame] | 81 | SkGlyphCache* cache = autoCache.getCache(); |
| 82 | |
ctguil@chromium.org | 9510ccc | 2011-07-27 00:10:51 +0000 | [diff] [blame] | 83 | const char* start = reinterpret_cast<const char*>(glyphs); |
| 84 | const char* stop = reinterpret_cast<const char*>(glyphs + len); |
vandebo@chromium.org | 28be72b | 2010-11-11 21:37:00 +0000 | [diff] [blame] | 85 | SkFixed xAdv = 0, yAdv = 0; |
| 86 | |
ctguil@chromium.org | 769fa6a | 2011-08-20 00:36:18 +0000 | [diff] [blame] | 87 | // TODO(vandebo): This probably needs to take kerning into account. |
vandebo@chromium.org | 28be72b | 2010-11-11 21:37:00 +0000 | [diff] [blame] | 88 | while (start < stop) { |
| 89 | const SkGlyph& glyph = glyphCacheProc(cache, &start, 0, 0); |
| 90 | xAdv += glyph.fAdvanceX; |
| 91 | yAdv += glyph.fAdvanceY; |
| 92 | }; |
ctguil@chromium.org | 769fa6a | 2011-08-20 00:36:18 +0000 | [diff] [blame] | 93 | if (paint.getTextAlign() == SkPaint::kLeft_Align) { |
vandebo@chromium.org | 28be72b | 2010-11-11 21:37:00 +0000 | [diff] [blame] | 94 | return; |
ctguil@chromium.org | 769fa6a | 2011-08-20 00:36:18 +0000 | [diff] [blame] | 95 | } |
vandebo@chromium.org | 28be72b | 2010-11-11 21:37:00 +0000 | [diff] [blame] | 96 | |
| 97 | SkScalar xAdj = SkFixedToScalar(xAdv); |
| 98 | SkScalar yAdj = SkFixedToScalar(yAdv); |
| 99 | if (paint.getTextAlign() == SkPaint::kCenter_Align) { |
| 100 | xAdj = SkScalarHalf(xAdj); |
| 101 | yAdj = SkScalarHalf(yAdj); |
| 102 | } |
| 103 | *x = *x - xAdj; |
| 104 | *y = *y - yAdj; |
| 105 | } |
| 106 | |
reed@google.com | fed86bd | 2013-03-14 15:04:57 +0000 | [diff] [blame] | 107 | static size_t max_glyphid_for_typeface(SkTypeface* typeface) { |
| 108 | SkAutoResolveDefaultTypeface autoResolve(typeface); |
| 109 | typeface = autoResolve.get(); |
commit-bot@chromium.org | 6a4ba5b | 2013-07-17 21:55:08 +0000 | [diff] [blame] | 110 | return typeface->countGlyphs() - 1; |
vandebo@chromium.org | 4e1cc6a | 2013-01-25 19:27:23 +0000 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | typedef SkAutoSTMalloc<128, uint16_t> SkGlyphStorage; |
| 114 | |
| 115 | static size_t force_glyph_encoding(const SkPaint& paint, const void* text, |
| 116 | size_t len, SkGlyphStorage* storage, |
| 117 | uint16_t** glyphIDs) { |
| 118 | // Make sure we have a glyph id encoding. |
| 119 | if (paint.getTextEncoding() != SkPaint::kGlyphID_TextEncoding) { |
| 120 | size_t numGlyphs = paint.textToGlyphs(text, len, NULL); |
| 121 | storage->reset(numGlyphs); |
| 122 | paint.textToGlyphs(text, len, storage->get()); |
| 123 | *glyphIDs = storage->get(); |
| 124 | return numGlyphs; |
| 125 | } |
| 126 | |
| 127 | // For user supplied glyph ids we need to validate them. |
| 128 | SkASSERT((len & 1) == 0); |
| 129 | size_t numGlyphs = len / 2; |
| 130 | const uint16_t* input = |
| 131 | reinterpret_cast<uint16_t*>(const_cast<void*>((text))); |
| 132 | |
| 133 | int maxGlyphID = max_glyphid_for_typeface(paint.getTypeface()); |
| 134 | size_t validated; |
| 135 | for (validated = 0; validated < numGlyphs; ++validated) { |
| 136 | if (input[validated] > maxGlyphID) { |
| 137 | break; |
| 138 | } |
| 139 | } |
| 140 | if (validated >= numGlyphs) { |
| 141 | *glyphIDs = reinterpret_cast<uint16_t*>(const_cast<void*>((text))); |
| 142 | return numGlyphs; |
| 143 | } |
| 144 | |
| 145 | // Silently drop anything out of range. |
| 146 | storage->reset(numGlyphs); |
| 147 | if (validated > 0) { |
| 148 | memcpy(storage->get(), input, validated * sizeof(uint16_t)); |
| 149 | } |
| 150 | |
| 151 | for (size_t i = validated; i < numGlyphs; ++i) { |
| 152 | storage->get()[i] = input[i]; |
| 153 | if (input[i] > maxGlyphID) { |
| 154 | storage->get()[i] = 0; |
| 155 | } |
| 156 | } |
| 157 | *glyphIDs = storage->get(); |
| 158 | return numGlyphs; |
| 159 | } |
| 160 | |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 161 | static void set_text_transform(SkScalar x, SkScalar y, SkScalar textSkewX, |
| 162 | SkWStream* content) { |
| 163 | // Flip the text about the x-axis to account for origin swap and include |
| 164 | // the passed parameters. |
| 165 | content->writeText("1 0 "); |
| 166 | SkPDFScalar::Append(0 - textSkewX, content); |
| 167 | content->writeText(" -1 "); |
| 168 | SkPDFScalar::Append(x, content); |
| 169 | content->writeText(" "); |
| 170 | SkPDFScalar::Append(y, content); |
| 171 | content->writeText(" Tm\n"); |
| 172 | } |
| 173 | |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 174 | // It is important to not confuse GraphicStateEntry with SkPDFGraphicState, the |
| 175 | // later being our representation of an object in the PDF file. |
| 176 | struct GraphicStateEntry { |
| 177 | GraphicStateEntry(); |
| 178 | |
| 179 | // Compare the fields we care about when setting up a new content entry. |
| 180 | bool compareInitialState(const GraphicStateEntry& b); |
| 181 | |
| 182 | SkMatrix fMatrix; |
| 183 | // We can't do set operations on Paths, though PDF natively supports |
| 184 | // intersect. If the clip stack does anything other than intersect, |
| 185 | // we have to fall back to the region. Treat fClipStack as authoritative. |
| 186 | // See http://code.google.com/p/skia/issues/detail?id=221 |
| 187 | SkClipStack fClipStack; |
| 188 | SkRegion fClipRegion; |
| 189 | |
| 190 | // When emitting the content entry, we will ensure the graphic state |
| 191 | // is set to these values first. |
| 192 | SkColor fColor; |
| 193 | SkScalar fTextScaleX; // Zero means we don't care what the value is. |
| 194 | SkPaint::Style fTextFill; // Only if TextScaleX is non-zero. |
| 195 | int fShaderIndex; |
| 196 | int fGraphicStateIndex; |
| 197 | |
| 198 | // We may change the font (i.e. for Type1 support) within a |
| 199 | // ContentEntry. This is the one currently in effect, or NULL if none. |
| 200 | SkPDFFont* fFont; |
| 201 | // In PDF, text size has no default value. It is only valid if fFont is |
| 202 | // not NULL. |
| 203 | SkScalar fTextSize; |
| 204 | }; |
| 205 | |
| 206 | GraphicStateEntry::GraphicStateEntry() : fColor(SK_ColorBLACK), |
| 207 | fTextScaleX(SK_Scalar1), |
| 208 | fTextFill(SkPaint::kFill_Style), |
| 209 | fShaderIndex(-1), |
| 210 | fGraphicStateIndex(-1), |
| 211 | fFont(NULL), |
| 212 | fTextSize(SK_ScalarNaN) { |
| 213 | fMatrix.reset(); |
| 214 | } |
| 215 | |
| 216 | bool GraphicStateEntry::compareInitialState(const GraphicStateEntry& b) { |
| 217 | return fColor == b.fColor && |
| 218 | fShaderIndex == b.fShaderIndex && |
| 219 | fGraphicStateIndex == b.fGraphicStateIndex && |
| 220 | fMatrix == b.fMatrix && |
| 221 | fClipStack == b.fClipStack && |
| 222 | (fTextScaleX == 0 || |
| 223 | b.fTextScaleX == 0 || |
| 224 | (fTextScaleX == b.fTextScaleX && fTextFill == b.fTextFill)); |
| 225 | } |
| 226 | |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 227 | class GraphicStackState { |
| 228 | public: |
| 229 | GraphicStackState(const SkClipStack& existingClipStack, |
| 230 | const SkRegion& existingClipRegion, |
| 231 | SkWStream* contentStream) |
| 232 | : fStackDepth(0), |
| 233 | fContentStream(contentStream) { |
| 234 | fEntries[0].fClipStack = existingClipStack; |
| 235 | fEntries[0].fClipRegion = existingClipRegion; |
| 236 | } |
| 237 | |
| 238 | void updateClip(const SkClipStack& clipStack, const SkRegion& clipRegion, |
vandebo@chromium.org | 663515b | 2012-01-05 18:45:27 +0000 | [diff] [blame] | 239 | const SkPoint& translation); |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 240 | void updateMatrix(const SkMatrix& matrix); |
| 241 | void updateDrawingState(const GraphicStateEntry& state); |
| 242 | |
| 243 | void drainStack(); |
| 244 | |
| 245 | private: |
| 246 | void push(); |
| 247 | void pop(); |
| 248 | GraphicStateEntry* currentEntry() { return &fEntries[fStackDepth]; } |
| 249 | |
| 250 | // Conservative limit on save depth, see impl. notes in PDF 1.4 spec. |
| 251 | static const int kMaxStackDepth = 12; |
| 252 | GraphicStateEntry fEntries[kMaxStackDepth + 1]; |
| 253 | int fStackDepth; |
| 254 | SkWStream* fContentStream; |
| 255 | }; |
| 256 | |
| 257 | void GraphicStackState::drainStack() { |
| 258 | while (fStackDepth) { |
| 259 | pop(); |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | void GraphicStackState::push() { |
| 264 | SkASSERT(fStackDepth < kMaxStackDepth); |
| 265 | fContentStream->writeText("q\n"); |
| 266 | fStackDepth++; |
| 267 | fEntries[fStackDepth] = fEntries[fStackDepth - 1]; |
| 268 | } |
| 269 | |
| 270 | void GraphicStackState::pop() { |
| 271 | SkASSERT(fStackDepth > 0); |
| 272 | fContentStream->writeText("Q\n"); |
| 273 | fStackDepth--; |
| 274 | } |
| 275 | |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 276 | // This function initializes iter to be an iterator on the "stack" argument |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 277 | // and then skips over the leading entries as specified in prefix. It requires |
| 278 | // and asserts that "prefix" will be a prefix to "stack." |
| 279 | static void skip_clip_stack_prefix(const SkClipStack& prefix, |
| 280 | const SkClipStack& stack, |
robertphillips@google.com | c029062 | 2012-07-16 21:20:03 +0000 | [diff] [blame] | 281 | SkClipStack::Iter* iter) { |
robertphillips@google.com | 80214e2 | 2012-07-20 15:33:18 +0000 | [diff] [blame] | 282 | SkClipStack::B2TIter prefixIter(prefix); |
| 283 | iter->reset(stack, SkClipStack::Iter::kBottom_IterStart); |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 284 | |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 285 | const SkClipStack::Element* prefixEntry; |
| 286 | const SkClipStack::Element* iterEntry; |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 287 | |
| 288 | for (prefixEntry = prefixIter.next(); prefixEntry; |
robertphillips@google.com | c029062 | 2012-07-16 21:20:03 +0000 | [diff] [blame] | 289 | prefixEntry = prefixIter.next()) { |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 290 | iterEntry = iter->next(); |
| 291 | SkASSERT(iterEntry); |
vandebo@chromium.org | 8887ede | 2011-05-25 01:27:52 +0000 | [diff] [blame] | 292 | // Because of SkClipStack does internal intersection, the last clip |
| 293 | // entry may differ. |
ctguil@chromium.org | 9510ccc | 2011-07-27 00:10:51 +0000 | [diff] [blame] | 294 | if (*prefixEntry != *iterEntry) { |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 295 | SkASSERT(prefixEntry->getOp() == SkRegion::kIntersect_Op); |
| 296 | SkASSERT(iterEntry->getOp() == SkRegion::kIntersect_Op); |
| 297 | SkASSERT(iterEntry->getType() == prefixEntry->getType()); |
robertphillips@google.com | c029062 | 2012-07-16 21:20:03 +0000 | [diff] [blame] | 298 | // back up the iterator by one |
| 299 | iter->prev(); |
vandebo@chromium.org | 8887ede | 2011-05-25 01:27:52 +0000 | [diff] [blame] | 300 | prefixEntry = prefixIter.next(); |
| 301 | break; |
| 302 | } |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | SkASSERT(prefixEntry == NULL); |
| 306 | } |
| 307 | |
| 308 | static void emit_clip(SkPath* clipPath, SkRect* clipRect, |
| 309 | SkWStream* contentStream) { |
| 310 | SkASSERT(clipPath || clipRect); |
| 311 | |
| 312 | SkPath::FillType clipFill; |
| 313 | if (clipPath) { |
vandebo@chromium.org | 683001c | 2012-05-09 17:17:51 +0000 | [diff] [blame] | 314 | SkPDFUtils::EmitPath(*clipPath, SkPaint::kFill_Style, contentStream); |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 315 | clipFill = clipPath->getFillType(); |
vandebo@chromium.org | 3e7b280 | 2011-06-27 18:12:31 +0000 | [diff] [blame] | 316 | } else { |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 317 | SkPDFUtils::AppendRectangle(*clipRect, contentStream); |
| 318 | clipFill = SkPath::kWinding_FillType; |
| 319 | } |
| 320 | |
| 321 | NOT_IMPLEMENTED(clipFill == SkPath::kInverseEvenOdd_FillType, false); |
| 322 | NOT_IMPLEMENTED(clipFill == SkPath::kInverseWinding_FillType, false); |
| 323 | if (clipFill == SkPath::kEvenOdd_FillType) { |
| 324 | contentStream->writeText("W* n\n"); |
| 325 | } else { |
| 326 | contentStream->writeText("W n\n"); |
| 327 | } |
| 328 | } |
| 329 | |
commit-bot@chromium.org | d2623a1 | 2013-08-08 02:52:05 +0000 | [diff] [blame] | 330 | #ifdef SK_PDF_USE_PATHOPS |
| 331 | /* Calculate an inverted path's equivalent non-inverted path, given the |
| 332 | * canvas bounds. |
| 333 | * outPath may alias with invPath (since this is supported by PathOps). |
| 334 | */ |
| 335 | static bool calculate_inverse_path(const SkRect& bounds, const SkPath& invPath, |
| 336 | SkPath* outPath) { |
| 337 | SkASSERT(invPath.isInverseFillType()); |
| 338 | |
| 339 | SkPath clipPath; |
| 340 | clipPath.addRect(bounds); |
| 341 | |
| 342 | return Op(clipPath, invPath, kIntersect_PathOp, outPath); |
| 343 | } |
| 344 | |
| 345 | // Sanity check the numerical values of the SkRegion ops and PathOps ops |
| 346 | // enums so region_op_to_pathops_op can do a straight passthrough cast. |
| 347 | // If these are failing, it may be necessary to make region_op_to_pathops_op |
| 348 | // do more. |
| 349 | SK_COMPILE_ASSERT(SkRegion::kDifference_Op == (int)kDifference_PathOp, |
| 350 | region_pathop_mismatch); |
| 351 | SK_COMPILE_ASSERT(SkRegion::kIntersect_Op == (int)kIntersect_PathOp, |
| 352 | region_pathop_mismatch); |
| 353 | SK_COMPILE_ASSERT(SkRegion::kUnion_Op == (int)kUnion_PathOp, |
| 354 | region_pathop_mismatch); |
| 355 | SK_COMPILE_ASSERT(SkRegion::kXOR_Op == (int)kXOR_PathOp, |
| 356 | region_pathop_mismatch); |
| 357 | SK_COMPILE_ASSERT(SkRegion::kReverseDifference_Op == |
| 358 | (int)kReverseDifference_PathOp, |
| 359 | region_pathop_mismatch); |
| 360 | |
| 361 | static SkPathOp region_op_to_pathops_op(SkRegion::Op op) { |
| 362 | SkASSERT(op >= 0); |
| 363 | SkASSERT(op <= SkRegion::kReverseDifference_Op); |
| 364 | return (SkPathOp)op; |
| 365 | } |
| 366 | |
| 367 | /* Uses Path Ops to calculate a vector SkPath clip from a clip stack. |
| 368 | * Returns true if successful, or false if not successful. |
| 369 | * If successful, the resulting clip is stored in outClipPath. |
| 370 | * If not successful, outClipPath is undefined, and a fallback method |
| 371 | * should be used. |
| 372 | */ |
| 373 | static bool get_clip_stack_path(const SkMatrix& transform, |
| 374 | const SkClipStack& clipStack, |
| 375 | const SkRegion& clipRegion, |
| 376 | SkPath* outClipPath) { |
| 377 | outClipPath->reset(); |
| 378 | outClipPath->setFillType(SkPath::kInverseWinding_FillType); |
| 379 | |
| 380 | const SkClipStack::Element* clipEntry; |
| 381 | SkClipStack::Iter iter; |
| 382 | iter.reset(clipStack, SkClipStack::Iter::kBottom_IterStart); |
| 383 | for (clipEntry = iter.next(); clipEntry; clipEntry = iter.next()) { |
| 384 | SkPath entryPath; |
| 385 | if (SkClipStack::Element::kEmpty_Type == clipEntry->getType()) { |
| 386 | outClipPath->reset(); |
| 387 | outClipPath->setFillType(SkPath::kInverseWinding_FillType); |
| 388 | continue; |
| 389 | } else if (SkClipStack::Element::kRect_Type == clipEntry->getType()) { |
| 390 | entryPath.addRect(clipEntry->getRect()); |
| 391 | } else if (SkClipStack::Element::kPath_Type == clipEntry->getType()) { |
| 392 | entryPath = clipEntry->getPath(); |
| 393 | } |
| 394 | entryPath.transform(transform); |
| 395 | |
| 396 | if (SkRegion::kReplace_Op == clipEntry->getOp()) { |
| 397 | *outClipPath = entryPath; |
| 398 | } else { |
| 399 | SkPathOp op = region_op_to_pathops_op(clipEntry->getOp()); |
| 400 | if (!Op(*outClipPath, entryPath, op, outClipPath)) { |
| 401 | return false; |
| 402 | } |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | if (outClipPath->isInverseFillType()) { |
| 407 | // The bounds are slightly outset to ensure this is correct in the |
| 408 | // face of floating-point accuracy and possible SkRegion bitmap |
| 409 | // approximations. |
| 410 | SkRect clipBounds = SkRect::Make(clipRegion.getBounds()); |
| 411 | clipBounds.outset(SK_Scalar1, SK_Scalar1); |
| 412 | if (!calculate_inverse_path(clipBounds, *outClipPath, outClipPath)) { |
| 413 | return false; |
| 414 | } |
| 415 | } |
| 416 | return true; |
| 417 | } |
| 418 | #endif |
| 419 | |
ctguil@chromium.org | 769fa6a | 2011-08-20 00:36:18 +0000 | [diff] [blame] | 420 | // TODO(vandebo): Take advantage of SkClipStack::getSaveCount(), the PDF |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 421 | // graphic state stack, and the fact that we can know all the clips used |
| 422 | // on the page to optimize this. |
| 423 | void GraphicStackState::updateClip(const SkClipStack& clipStack, |
| 424 | const SkRegion& clipRegion, |
vandebo@chromium.org | 663515b | 2012-01-05 18:45:27 +0000 | [diff] [blame] | 425 | const SkPoint& translation) { |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 426 | if (clipStack == currentEntry()->fClipStack) { |
| 427 | return; |
| 428 | } |
| 429 | |
| 430 | while (fStackDepth > 0) { |
| 431 | pop(); |
| 432 | if (clipStack == currentEntry()->fClipStack) { |
| 433 | return; |
| 434 | } |
| 435 | } |
| 436 | push(); |
| 437 | |
commit-bot@chromium.org | d2623a1 | 2013-08-08 02:52:05 +0000 | [diff] [blame] | 438 | currentEntry()->fClipStack = clipStack; |
| 439 | currentEntry()->fClipRegion = clipRegion; |
| 440 | |
| 441 | SkMatrix transform; |
| 442 | transform.setTranslate(translation.fX, translation.fY); |
| 443 | |
| 444 | #ifdef SK_PDF_USE_PATHOPS |
| 445 | SkPath clipPath; |
| 446 | if (get_clip_stack_path(transform, clipStack, clipRegion, &clipPath)) { |
| 447 | emit_clip(&clipPath, NULL, fContentStream); |
| 448 | return; |
| 449 | } |
| 450 | #endif |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 451 | // gsState->initialEntry()->fClipStack/Region specifies the clip that has |
| 452 | // already been applied. (If this is a top level device, then it specifies |
| 453 | // a clip to the content area. If this is a layer, then it specifies |
| 454 | // the clip in effect when the layer was created.) There's no need to |
| 455 | // reapply that clip; SKCanvas's SkDrawIter will draw anything outside the |
| 456 | // initial clip on the parent layer. (This means there's a bug if the user |
| 457 | // expands the clip and then uses any xfer mode that uses dst: |
| 458 | // http://code.google.com/p/skia/issues/detail?id=228 ) |
robertphillips@google.com | c029062 | 2012-07-16 21:20:03 +0000 | [diff] [blame] | 459 | SkClipStack::Iter iter; |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 460 | skip_clip_stack_prefix(fEntries[0].fClipStack, clipStack, &iter); |
| 461 | |
| 462 | // If the clip stack does anything other than intersect or if it uses |
| 463 | // an inverse fill type, we have to fall back to the clip region. |
| 464 | bool needRegion = false; |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 465 | const SkClipStack::Element* clipEntry; |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 466 | for (clipEntry = iter.next(); clipEntry; clipEntry = iter.next()) { |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 467 | if (clipEntry->getOp() != SkRegion::kIntersect_Op || clipEntry->isInverseFilled()) { |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 468 | needRegion = true; |
| 469 | break; |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | if (needRegion) { |
| 474 | SkPath clipPath; |
| 475 | SkAssertResult(clipRegion.getBoundaryPath(&clipPath)); |
| 476 | emit_clip(&clipPath, NULL, fContentStream); |
| 477 | } else { |
| 478 | skip_clip_stack_prefix(fEntries[0].fClipStack, clipStack, &iter); |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 479 | const SkClipStack::Element* clipEntry; |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 480 | for (clipEntry = iter.next(); clipEntry; clipEntry = iter.next()) { |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 481 | SkASSERT(clipEntry->getOp() == SkRegion::kIntersect_Op); |
| 482 | switch (clipEntry->getType()) { |
| 483 | case SkClipStack::Element::kRect_Type: { |
| 484 | SkRect translatedClip; |
| 485 | transform.mapRect(&translatedClip, clipEntry->getRect()); |
| 486 | emit_clip(NULL, &translatedClip, fContentStream); |
| 487 | break; |
| 488 | } |
| 489 | case SkClipStack::Element::kPath_Type: { |
| 490 | SkPath translatedPath; |
| 491 | clipEntry->getPath().transform(transform, &translatedPath); |
| 492 | emit_clip(&translatedPath, NULL, fContentStream); |
| 493 | break; |
| 494 | } |
| 495 | default: |
| 496 | SkASSERT(false); |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 497 | } |
| 498 | } |
| 499 | } |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | void GraphicStackState::updateMatrix(const SkMatrix& matrix) { |
| 503 | if (matrix == currentEntry()->fMatrix) { |
| 504 | return; |
| 505 | } |
| 506 | |
| 507 | if (currentEntry()->fMatrix.getType() != SkMatrix::kIdentity_Mask) { |
| 508 | SkASSERT(fStackDepth > 0); |
| 509 | SkASSERT(fEntries[fStackDepth].fClipStack == |
| 510 | fEntries[fStackDepth -1].fClipStack); |
| 511 | pop(); |
| 512 | |
| 513 | SkASSERT(currentEntry()->fMatrix.getType() == SkMatrix::kIdentity_Mask); |
| 514 | } |
| 515 | if (matrix.getType() == SkMatrix::kIdentity_Mask) { |
| 516 | return; |
| 517 | } |
| 518 | |
| 519 | push(); |
| 520 | SkPDFUtils::AppendTransform(matrix, fContentStream); |
| 521 | currentEntry()->fMatrix = matrix; |
| 522 | } |
| 523 | |
| 524 | void GraphicStackState::updateDrawingState(const GraphicStateEntry& state) { |
| 525 | // PDF treats a shader as a color, so we only set one or the other. |
| 526 | if (state.fShaderIndex >= 0) { |
| 527 | if (state.fShaderIndex != currentEntry()->fShaderIndex) { |
commit-bot@chromium.org | 93a2e21 | 2013-07-23 23:16:03 +0000 | [diff] [blame] | 528 | SkPDFUtils::ApplyPattern(state.fShaderIndex, fContentStream); |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 529 | currentEntry()->fShaderIndex = state.fShaderIndex; |
| 530 | } |
| 531 | } else { |
| 532 | if (state.fColor != currentEntry()->fColor || |
| 533 | currentEntry()->fShaderIndex >= 0) { |
| 534 | emit_pdf_color(state.fColor, fContentStream); |
| 535 | fContentStream->writeText("RG "); |
| 536 | emit_pdf_color(state.fColor, fContentStream); |
| 537 | fContentStream->writeText("rg\n"); |
| 538 | currentEntry()->fColor = state.fColor; |
| 539 | currentEntry()->fShaderIndex = -1; |
| 540 | } |
| 541 | } |
| 542 | |
| 543 | if (state.fGraphicStateIndex != currentEntry()->fGraphicStateIndex) { |
vandebo@chromium.org | 6112c21 | 2011-05-13 03:50:38 +0000 | [diff] [blame] | 544 | SkPDFUtils::ApplyGraphicState(state.fGraphicStateIndex, fContentStream); |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 545 | currentEntry()->fGraphicStateIndex = state.fGraphicStateIndex; |
| 546 | } |
| 547 | |
| 548 | if (state.fTextScaleX) { |
| 549 | if (state.fTextScaleX != currentEntry()->fTextScaleX) { |
| 550 | SkScalar pdfScale = SkScalarMul(state.fTextScaleX, |
| 551 | SkIntToScalar(100)); |
| 552 | SkPDFScalar::Append(pdfScale, fContentStream); |
| 553 | fContentStream->writeText(" Tz\n"); |
| 554 | currentEntry()->fTextScaleX = state.fTextScaleX; |
| 555 | } |
| 556 | if (state.fTextFill != currentEntry()->fTextFill) { |
| 557 | SK_COMPILE_ASSERT(SkPaint::kFill_Style == 0, enum_must_match_value); |
| 558 | SK_COMPILE_ASSERT(SkPaint::kStroke_Style == 1, |
| 559 | enum_must_match_value); |
| 560 | SK_COMPILE_ASSERT(SkPaint::kStrokeAndFill_Style == 2, |
| 561 | enum_must_match_value); |
| 562 | fContentStream->writeDecAsText(state.fTextFill); |
| 563 | fContentStream->writeText(" Tr\n"); |
| 564 | currentEntry()->fTextFill = state.fTextFill; |
| 565 | } |
| 566 | } |
| 567 | } |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 568 | |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 569 | SkBaseDevice* SkPDFDevice::onCreateCompatibleDevice(SkBitmap::Config config, |
| 570 | int width, int height, |
| 571 | bool isOpaque, |
| 572 | Usage usage) { |
bsalomon@google.com | e97f085 | 2011-06-17 13:10:25 +0000 | [diff] [blame] | 573 | SkMatrix initialTransform; |
| 574 | initialTransform.reset(); |
| 575 | SkISize size = SkISize::Make(width, height); |
| 576 | return SkNEW_ARGS(SkPDFDevice, (size, size, initialTransform)); |
| 577 | } |
| 578 | |
| 579 | |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 580 | struct ContentEntry { |
| 581 | GraphicStateEntry fState; |
| 582 | SkDynamicMemoryWStream fContent; |
commit-bot@chromium.org | e029440 | 2013-08-29 22:14:04 +0000 | [diff] [blame] | 583 | SkAutoTDelete<ContentEntry> fNext; |
edisonn@google.com | 2e6a69b | 2013-02-05 23:13:39 +0000 | [diff] [blame] | 584 | |
| 585 | // If the stack is too deep we could get Stack Overflow. |
| 586 | // So we manually destruct the object. |
| 587 | ~ContentEntry() { |
commit-bot@chromium.org | e029440 | 2013-08-29 22:14:04 +0000 | [diff] [blame] | 588 | ContentEntry* val = fNext.detach(); |
edisonn@google.com | 2e6a69b | 2013-02-05 23:13:39 +0000 | [diff] [blame] | 589 | while (val != NULL) { |
commit-bot@chromium.org | e029440 | 2013-08-29 22:14:04 +0000 | [diff] [blame] | 590 | ContentEntry* valNext = val->fNext.detach(); |
edisonn@google.com | 2e6a69b | 2013-02-05 23:13:39 +0000 | [diff] [blame] | 591 | // When the destructor is called, fNext is NULL and exits. |
| 592 | delete val; |
| 593 | val = valNext; |
| 594 | } |
| 595 | } |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 596 | }; |
| 597 | |
| 598 | // A helper class to automatically finish a ContentEntry at the end of a |
| 599 | // drawing method and maintain the state needed between set up and finish. |
vandebo@chromium.org | 13d14a9 | 2011-05-24 23:12:41 +0000 | [diff] [blame] | 600 | class ScopedContentEntry { |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 601 | public: |
vandebo@chromium.org | 13d14a9 | 2011-05-24 23:12:41 +0000 | [diff] [blame] | 602 | ScopedContentEntry(SkPDFDevice* device, const SkDraw& draw, |
| 603 | const SkPaint& paint, bool hasText = false) |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 604 | : fDevice(device), |
| 605 | fContentEntry(NULL), |
| 606 | fXfermode(SkXfermode::kSrcOver_Mode) { |
| 607 | init(draw.fClipStack, *draw.fClip, *draw.fMatrix, paint, hasText); |
| 608 | } |
vandebo@chromium.org | 13d14a9 | 2011-05-24 23:12:41 +0000 | [diff] [blame] | 609 | ScopedContentEntry(SkPDFDevice* device, const SkClipStack* clipStack, |
| 610 | const SkRegion& clipRegion, const SkMatrix& matrix, |
| 611 | const SkPaint& paint, bool hasText = false) |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 612 | : fDevice(device), |
| 613 | fContentEntry(NULL), |
| 614 | fXfermode(SkXfermode::kSrcOver_Mode) { |
| 615 | init(clipStack, clipRegion, matrix, paint, hasText); |
| 616 | } |
| 617 | |
vandebo@chromium.org | 13d14a9 | 2011-05-24 23:12:41 +0000 | [diff] [blame] | 618 | ~ScopedContentEntry() { |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 619 | if (fContentEntry) { |
reed@google.com | fc641d0 | 2012-09-20 17:52:20 +0000 | [diff] [blame] | 620 | fDevice->finishContentEntry(fXfermode, fDstFormXObject); |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 621 | } |
reed@google.com | fc641d0 | 2012-09-20 17:52:20 +0000 | [diff] [blame] | 622 | SkSafeUnref(fDstFormXObject); |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | ContentEntry* entry() { return fContentEntry; } |
| 626 | private: |
| 627 | SkPDFDevice* fDevice; |
| 628 | ContentEntry* fContentEntry; |
| 629 | SkXfermode::Mode fXfermode; |
reed@google.com | fc641d0 | 2012-09-20 17:52:20 +0000 | [diff] [blame] | 630 | SkPDFFormXObject* fDstFormXObject; |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 631 | |
| 632 | void init(const SkClipStack* clipStack, const SkRegion& clipRegion, |
| 633 | const SkMatrix& matrix, const SkPaint& paint, bool hasText) { |
reed@google.com | fc641d0 | 2012-09-20 17:52:20 +0000 | [diff] [blame] | 634 | fDstFormXObject = NULL; |
edisonn@google.com | aa6c4d2 | 2013-09-19 17:36:47 +0000 | [diff] [blame^] | 635 | if (matrix.hasPerspective() || |
| 636 | (paint.getShader() && |
| 637 | paint.getShader()->getLocalMatrix().hasPerspective())) { |
| 638 | // Just report that PDF does not supports perspective |
| 639 | // TODO(edisonn): update the shape when possible |
| 640 | // or dump in an image otherwise |
| 641 | NOT_IMPLEMENTED(true, false); |
| 642 | return; |
| 643 | } |
| 644 | |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 645 | if (paint.getXfermode()) { |
| 646 | paint.getXfermode()->asMode(&fXfermode); |
| 647 | } |
| 648 | fContentEntry = fDevice->setUpContentEntry(clipStack, clipRegion, |
| 649 | matrix, paint, hasText, |
| 650 | &fDstFormXObject); |
| 651 | } |
| 652 | }; |
| 653 | |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 654 | //////////////////////////////////////////////////////////////////////////////// |
| 655 | |
ctguil@chromium.org | 1526129 | 2011-04-29 17:54:16 +0000 | [diff] [blame] | 656 | static inline SkBitmap makeContentBitmap(const SkISize& contentSize, |
vandebo@chromium.org | a0c7edb | 2011-05-09 07:58:08 +0000 | [diff] [blame] | 657 | const SkMatrix* initialTransform) { |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 658 | SkBitmap bitmap; |
vandebo@chromium.org | a0c7edb | 2011-05-09 07:58:08 +0000 | [diff] [blame] | 659 | if (initialTransform) { |
| 660 | // Compute the size of the drawing area. |
| 661 | SkVector drawingSize; |
| 662 | SkMatrix inverse; |
vandebo@chromium.org | 663515b | 2012-01-05 18:45:27 +0000 | [diff] [blame] | 663 | drawingSize.set(SkIntToScalar(contentSize.fWidth), |
| 664 | SkIntToScalar(contentSize.fHeight)); |
vandebo@chromium.org | b054990 | 2012-04-13 20:45:46 +0000 | [diff] [blame] | 665 | if (!initialTransform->invert(&inverse)) { |
vandebo@chromium.org | 386dfc0 | 2012-04-17 22:31:52 +0000 | [diff] [blame] | 666 | // This shouldn't happen, initial transform should be invertible. |
| 667 | SkASSERT(false); |
vandebo@chromium.org | b054990 | 2012-04-13 20:45:46 +0000 | [diff] [blame] | 668 | inverse.reset(); |
| 669 | } |
vandebo@chromium.org | a0c7edb | 2011-05-09 07:58:08 +0000 | [diff] [blame] | 670 | inverse.mapVectors(&drawingSize, 1); |
| 671 | SkISize size = SkSize::Make(drawingSize.fX, drawingSize.fY).toRound(); |
| 672 | bitmap.setConfig(SkBitmap::kNo_Config, abs(size.fWidth), |
| 673 | abs(size.fHeight)); |
| 674 | } else { |
| 675 | bitmap.setConfig(SkBitmap::kNo_Config, abs(contentSize.fWidth), |
| 676 | abs(contentSize.fHeight)); |
| 677 | } |
| 678 | |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 679 | return bitmap; |
| 680 | } |
| 681 | |
vandebo@chromium.org | 663515b | 2012-01-05 18:45:27 +0000 | [diff] [blame] | 682 | // TODO(vandebo) change pageSize to SkSize. |
ctguil@chromium.org | 1526129 | 2011-04-29 17:54:16 +0000 | [diff] [blame] | 683 | SkPDFDevice::SkPDFDevice(const SkISize& pageSize, const SkISize& contentSize, |
vandebo@chromium.org | 75f97e4 | 2011-04-11 23:24:18 +0000 | [diff] [blame] | 684 | const SkMatrix& initialTransform) |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 685 | : SkBitmapDevice(makeContentBitmap(contentSize, &initialTransform)), |
ctguil@chromium.org | 1526129 | 2011-04-29 17:54:16 +0000 | [diff] [blame] | 686 | fPageSize(pageSize), |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 687 | fContentSize(contentSize), |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 688 | fLastContentEntry(NULL), |
robertphillips@google.com | 40a1ae4 | 2012-07-13 15:36:15 +0000 | [diff] [blame] | 689 | fLastMarginContentEntry(NULL), |
edisonn@google.com | d9dfa18 | 2013-04-24 13:01:01 +0000 | [diff] [blame] | 690 | fClipStack(NULL), |
| 691 | fEncoder(NULL) { |
edisonn@google.com | aa6c4d2 | 2013-09-19 17:36:47 +0000 | [diff] [blame^] | 692 | // just report that PDF does not supports perspective |
| 693 | // TODO(edisonn): update the shape when possible |
| 694 | // or dump in an image otherwise |
| 695 | NOT_IMPLEMENTED(initialTransform.hasPerspective(), true); |
| 696 | |
vandebo@chromium.org | 77bcaa3 | 2011-04-15 20:57:37 +0000 | [diff] [blame] | 697 | // Skia generally uses the top left as the origin but PDF natively has the |
vandebo@chromium.org | a0c7edb | 2011-05-09 07:58:08 +0000 | [diff] [blame] | 698 | // origin at the bottom left. This matrix corrects for that. But that only |
| 699 | // needs to be done once, we don't do it when layering. |
vandebo@chromium.org | 663515b | 2012-01-05 18:45:27 +0000 | [diff] [blame] | 700 | fInitialTransform.setTranslate(0, SkIntToScalar(pageSize.fHeight)); |
| 701 | fInitialTransform.preScale(SK_Scalar1, -SK_Scalar1); |
vandebo@chromium.org | 77bcaa3 | 2011-04-15 20:57:37 +0000 | [diff] [blame] | 702 | fInitialTransform.preConcat(initialTransform); |
| 703 | |
vandebo@chromium.org | a0c7edb | 2011-05-09 07:58:08 +0000 | [diff] [blame] | 704 | SkIRect existingClip = SkIRect::MakeWH(this->width(), this->height()); |
vandebo@chromium.org | a0c7edb | 2011-05-09 07:58:08 +0000 | [diff] [blame] | 705 | fExistingClipRegion.setRect(existingClip); |
| 706 | |
| 707 | this->init(); |
| 708 | } |
| 709 | |
vandebo@chromium.org | 663515b | 2012-01-05 18:45:27 +0000 | [diff] [blame] | 710 | // TODO(vandebo) change layerSize to SkSize. |
vandebo@chromium.org | a0c7edb | 2011-05-09 07:58:08 +0000 | [diff] [blame] | 711 | SkPDFDevice::SkPDFDevice(const SkISize& layerSize, |
| 712 | const SkClipStack& existingClipStack, |
| 713 | const SkRegion& existingClipRegion) |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 714 | : SkBitmapDevice(makeContentBitmap(layerSize, NULL)), |
vandebo@chromium.org | a0c7edb | 2011-05-09 07:58:08 +0000 | [diff] [blame] | 715 | fPageSize(layerSize), |
| 716 | fContentSize(layerSize), |
| 717 | fExistingClipStack(existingClipStack), |
| 718 | fExistingClipRegion(existingClipRegion), |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 719 | fLastContentEntry(NULL), |
robertphillips@google.com | 40a1ae4 | 2012-07-13 15:36:15 +0000 | [diff] [blame] | 720 | fLastMarginContentEntry(NULL), |
| 721 | fClipStack(NULL) { |
vandebo@chromium.org | a0c7edb | 2011-05-09 07:58:08 +0000 | [diff] [blame] | 722 | fInitialTransform.reset(); |
vandebo@chromium.org | 77bcaa3 | 2011-04-15 20:57:37 +0000 | [diff] [blame] | 723 | this->init(); |
| 724 | } |
| 725 | |
| 726 | SkPDFDevice::~SkPDFDevice() { |
vandebo@chromium.org | 9859428 | 2011-07-25 22:34:12 +0000 | [diff] [blame] | 727 | this->cleanUp(true); |
vandebo@chromium.org | 77bcaa3 | 2011-04-15 20:57:37 +0000 | [diff] [blame] | 728 | } |
| 729 | |
| 730 | void SkPDFDevice::init() { |
reed@google.com | 2a006c1 | 2012-09-19 17:05:55 +0000 | [diff] [blame] | 731 | fAnnotations = NULL; |
vandebo@chromium.org | 77bcaa3 | 2011-04-15 20:57:37 +0000 | [diff] [blame] | 732 | fResourceDict = NULL; |
commit-bot@chromium.org | e029440 | 2013-08-29 22:14:04 +0000 | [diff] [blame] | 733 | fContentEntries.free(); |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 734 | fLastContentEntry = NULL; |
commit-bot@chromium.org | e029440 | 2013-08-29 22:14:04 +0000 | [diff] [blame] | 735 | fMarginContentEntries.free(); |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 736 | fLastMarginContentEntry = NULL; |
vandebo@chromium.org | 9859428 | 2011-07-25 22:34:12 +0000 | [diff] [blame] | 737 | fDrawingArea = kContent_DrawingArea; |
commit-bot@chromium.org | e029440 | 2013-08-29 22:14:04 +0000 | [diff] [blame] | 738 | if (fFontGlyphUsage.get() == NULL) { |
vandebo@chromium.org | 9859428 | 2011-07-25 22:34:12 +0000 | [diff] [blame] | 739 | fFontGlyphUsage.reset(new SkPDFGlyphSetMap()); |
| 740 | } |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 741 | } |
| 742 | |
vandebo@chromium.org | 9859428 | 2011-07-25 22:34:12 +0000 | [diff] [blame] | 743 | void SkPDFDevice::cleanUp(bool clearFontUsage) { |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 744 | fGraphicStateResources.unrefAll(); |
| 745 | fXObjectResources.unrefAll(); |
vandebo@chromium.org | 28be72b | 2010-11-11 21:37:00 +0000 | [diff] [blame] | 746 | fFontResources.unrefAll(); |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 747 | fShaderResources.unrefAll(); |
reed@google.com | 2a006c1 | 2012-09-19 17:05:55 +0000 | [diff] [blame] | 748 | SkSafeUnref(fAnnotations); |
reed@google.com | fc641d0 | 2012-09-20 17:52:20 +0000 | [diff] [blame] | 749 | SkSafeUnref(fResourceDict); |
epoger@google.com | b58772f | 2013-03-08 09:09:10 +0000 | [diff] [blame] | 750 | fNamedDestinations.deleteAll(); |
reed@google.com | 2a006c1 | 2012-09-19 17:05:55 +0000 | [diff] [blame] | 751 | |
vandebo@chromium.org | 9859428 | 2011-07-25 22:34:12 +0000 | [diff] [blame] | 752 | if (clearFontUsage) { |
| 753 | fFontGlyphUsage->reset(); |
| 754 | } |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 755 | } |
| 756 | |
reed@google.com | 982cb87 | 2011-12-07 18:34:08 +0000 | [diff] [blame] | 757 | uint32_t SkPDFDevice::getDeviceCapabilities() { |
| 758 | return kVector_Capability; |
| 759 | } |
| 760 | |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 761 | void SkPDFDevice::clear(SkColor color) { |
vandebo@chromium.org | 9859428 | 2011-07-25 22:34:12 +0000 | [diff] [blame] | 762 | this->cleanUp(true); |
vandebo@chromium.org | 77bcaa3 | 2011-04-15 20:57:37 +0000 | [diff] [blame] | 763 | this->init(); |
| 764 | |
| 765 | SkPaint paint; |
| 766 | paint.setColor(color); |
| 767 | paint.setStyle(SkPaint::kFill_Style); |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 768 | SkMatrix identity; |
| 769 | identity.reset(); |
vandebo@chromium.org | 13d14a9 | 2011-05-24 23:12:41 +0000 | [diff] [blame] | 770 | ScopedContentEntry content(this, &fExistingClipStack, fExistingClipRegion, |
| 771 | identity, paint); |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 772 | internalDrawPaint(paint, content.entry()); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | void SkPDFDevice::drawPaint(const SkDraw& d, const SkPaint& paint) { |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 776 | SkPaint newPaint = paint; |
| 777 | newPaint.setStyle(SkPaint::kFill_Style); |
vandebo@chromium.org | 13d14a9 | 2011-05-24 23:12:41 +0000 | [diff] [blame] | 778 | ScopedContentEntry content(this, d, newPaint); |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 779 | internalDrawPaint(newPaint, content.entry()); |
vandebo@chromium.org | 77bcaa3 | 2011-04-15 20:57:37 +0000 | [diff] [blame] | 780 | } |
| 781 | |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 782 | void SkPDFDevice::internalDrawPaint(const SkPaint& paint, |
| 783 | ContentEntry* contentEntry) { |
| 784 | if (!contentEntry) { |
| 785 | return; |
| 786 | } |
vandebo@chromium.org | 77bcaa3 | 2011-04-15 20:57:37 +0000 | [diff] [blame] | 787 | SkRect bbox = SkRect::MakeWH(SkIntToScalar(this->width()), |
| 788 | SkIntToScalar(this->height())); |
| 789 | SkMatrix totalTransform = fInitialTransform; |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 790 | totalTransform.preConcat(contentEntry->fState.fMatrix); |
vandebo@chromium.org | 77bcaa3 | 2011-04-15 20:57:37 +0000 | [diff] [blame] | 791 | SkMatrix inverse; |
vandebo@chromium.org | b054990 | 2012-04-13 20:45:46 +0000 | [diff] [blame] | 792 | if (!totalTransform.invert(&inverse)) { |
vandebo@chromium.org | 386dfc0 | 2012-04-17 22:31:52 +0000 | [diff] [blame] | 793 | return; |
vandebo@chromium.org | b054990 | 2012-04-13 20:45:46 +0000 | [diff] [blame] | 794 | } |
vandebo@chromium.org | 77bcaa3 | 2011-04-15 20:57:37 +0000 | [diff] [blame] | 795 | inverse.mapRect(&bbox); |
| 796 | |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 797 | SkPDFUtils::AppendRectangle(bbox, &contentEntry->fContent); |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 798 | SkPDFUtils::PaintPath(paint.getStyle(), SkPath::kWinding_FillType, |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 799 | &contentEntry->fContent); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | void SkPDFDevice::drawPoints(const SkDraw& d, SkCanvas::PointMode mode, |
| 803 | size_t count, const SkPoint* points, |
vandebo@chromium.org | 25adce8 | 2011-05-09 08:05:01 +0000 | [diff] [blame] | 804 | const SkPaint& passedPaint) { |
| 805 | if (count == 0) { |
| 806 | return; |
| 807 | } |
| 808 | |
epoger@google.com | b58772f | 2013-03-08 09:09:10 +0000 | [diff] [blame] | 809 | if (handlePointAnnotation(points, count, *d.fMatrix, passedPaint)) { |
| 810 | return; |
| 811 | } |
| 812 | |
vandebo@chromium.org | ff39032 | 2011-05-17 18:58:44 +0000 | [diff] [blame] | 813 | // SkDraw::drawPoints converts to multiple calls to fDevice->drawPath. |
| 814 | // We only use this when there's a path effect because of the overhead |
| 815 | // of multiple calls to setUpContentEntry it causes. |
| 816 | if (passedPaint.getPathEffect()) { |
| 817 | if (d.fClip->isEmpty()) { |
| 818 | return; |
| 819 | } |
| 820 | SkDraw pointDraw(d); |
| 821 | pointDraw.fDevice = this; |
| 822 | pointDraw.drawPoints(mode, count, points, passedPaint, true); |
| 823 | return; |
| 824 | } |
| 825 | |
vandebo@chromium.org | 25adce8 | 2011-05-09 08:05:01 +0000 | [diff] [blame] | 826 | const SkPaint* paint = &passedPaint; |
| 827 | SkPaint modifiedPaint; |
| 828 | |
| 829 | if (mode == SkCanvas::kPoints_PointMode && |
| 830 | paint->getStrokeCap() != SkPaint::kRound_Cap) { |
| 831 | modifiedPaint = *paint; |
| 832 | paint = &modifiedPaint; |
| 833 | if (paint->getStrokeWidth()) { |
| 834 | // PDF won't draw a single point with square/butt caps because the |
| 835 | // orientation is ambiguous. Draw a rectangle instead. |
| 836 | modifiedPaint.setStyle(SkPaint::kFill_Style); |
| 837 | SkScalar strokeWidth = paint->getStrokeWidth(); |
| 838 | SkScalar halfStroke = SkScalarHalf(strokeWidth); |
| 839 | for (size_t i = 0; i < count; i++) { |
| 840 | SkRect r = SkRect::MakeXYWH(points[i].fX, points[i].fY, 0, 0); |
| 841 | r.inset(-halfStroke, -halfStroke); |
| 842 | drawRect(d, r, modifiedPaint); |
| 843 | } |
| 844 | return; |
| 845 | } else { |
| 846 | modifiedPaint.setStrokeCap(SkPaint::kRound_Cap); |
| 847 | } |
| 848 | } |
| 849 | |
vandebo@chromium.org | 13d14a9 | 2011-05-24 23:12:41 +0000 | [diff] [blame] | 850 | ScopedContentEntry content(this, d, *paint); |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 851 | if (!content.entry()) { |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 852 | return; |
vandebo@chromium.org | fb0b0ed | 2011-04-15 20:01:17 +0000 | [diff] [blame] | 853 | } |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 854 | |
| 855 | switch (mode) { |
| 856 | case SkCanvas::kPolygon_PointMode: |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 857 | SkPDFUtils::MoveTo(points[0].fX, points[0].fY, |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 858 | &content.entry()->fContent); |
ctguil@chromium.org | 9db86bb | 2011-03-04 21:43:27 +0000 | [diff] [blame] | 859 | for (size_t i = 1; i < count; i++) { |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 860 | SkPDFUtils::AppendLine(points[i].fX, points[i].fY, |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 861 | &content.entry()->fContent); |
ctguil@chromium.org | 9db86bb | 2011-03-04 21:43:27 +0000 | [diff] [blame] | 862 | } |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 863 | SkPDFUtils::StrokePath(&content.entry()->fContent); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 864 | break; |
| 865 | case SkCanvas::kLines_PointMode: |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 866 | for (size_t i = 0; i < count/2; i++) { |
ctguil@chromium.org | 9db86bb | 2011-03-04 21:43:27 +0000 | [diff] [blame] | 867 | SkPDFUtils::MoveTo(points[i * 2].fX, points[i * 2].fY, |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 868 | &content.entry()->fContent); |
ctguil@chromium.org | 9db86bb | 2011-03-04 21:43:27 +0000 | [diff] [blame] | 869 | SkPDFUtils::AppendLine(points[i * 2 + 1].fX, |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 870 | points[i * 2 + 1].fY, |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 871 | &content.entry()->fContent); |
| 872 | SkPDFUtils::StrokePath(&content.entry()->fContent); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 873 | } |
| 874 | break; |
| 875 | case SkCanvas::kPoints_PointMode: |
vandebo@chromium.org | 25adce8 | 2011-05-09 08:05:01 +0000 | [diff] [blame] | 876 | SkASSERT(paint->getStrokeCap() == SkPaint::kRound_Cap); |
| 877 | for (size_t i = 0; i < count; i++) { |
| 878 | SkPDFUtils::MoveTo(points[i].fX, points[i].fY, |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 879 | &content.entry()->fContent); |
| 880 | SkPDFUtils::ClosePath(&content.entry()->fContent); |
| 881 | SkPDFUtils::StrokePath(&content.entry()->fContent); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 882 | } |
| 883 | break; |
| 884 | default: |
| 885 | SkASSERT(false); |
| 886 | } |
| 887 | } |
| 888 | |
commit-bot@chromium.org | 969fd6a | 2013-05-14 18:16:40 +0000 | [diff] [blame] | 889 | void SkPDFDevice::drawRect(const SkDraw& d, const SkRect& rect, |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 890 | const SkPaint& paint) { |
commit-bot@chromium.org | 969fd6a | 2013-05-14 18:16:40 +0000 | [diff] [blame] | 891 | SkRect r = rect; |
| 892 | r.sort(); |
| 893 | |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 894 | if (paint.getPathEffect()) { |
vandebo@chromium.org | 25adce8 | 2011-05-09 08:05:01 +0000 | [diff] [blame] | 895 | if (d.fClip->isEmpty()) { |
| 896 | return; |
| 897 | } |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 898 | SkPath path; |
| 899 | path.addRect(r); |
vandebo@chromium.org | ff39032 | 2011-05-17 18:58:44 +0000 | [diff] [blame] | 900 | drawPath(d, path, paint, NULL, true); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 901 | return; |
| 902 | } |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 903 | |
epoger@google.com | b58772f | 2013-03-08 09:09:10 +0000 | [diff] [blame] | 904 | if (handleRectAnnotation(r, *d.fMatrix, paint)) { |
vandebo@chromium.org | 238be8c | 2012-07-13 20:06:02 +0000 | [diff] [blame] | 905 | return; |
| 906 | } |
| 907 | |
vandebo@chromium.org | 13d14a9 | 2011-05-24 23:12:41 +0000 | [diff] [blame] | 908 | ScopedContentEntry content(this, d, paint); |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 909 | if (!content.entry()) { |
vandebo@chromium.org | 25adce8 | 2011-05-09 08:05:01 +0000 | [diff] [blame] | 910 | return; |
| 911 | } |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 912 | SkPDFUtils::AppendRectangle(r, &content.entry()->fContent); |
ctguil@chromium.org | 9db86bb | 2011-03-04 21:43:27 +0000 | [diff] [blame] | 913 | SkPDFUtils::PaintPath(paint.getStyle(), SkPath::kWinding_FillType, |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 914 | &content.entry()->fContent); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 915 | } |
| 916 | |
vandebo@chromium.org | ff39032 | 2011-05-17 18:58:44 +0000 | [diff] [blame] | 917 | void SkPDFDevice::drawPath(const SkDraw& d, const SkPath& origPath, |
vandebo@chromium.org | 02cc5aa | 2011-01-25 22:06:29 +0000 | [diff] [blame] | 918 | const SkPaint& paint, const SkMatrix* prePathMatrix, |
| 919 | bool pathIsMutable) { |
vandebo@chromium.org | ff39032 | 2011-05-17 18:58:44 +0000 | [diff] [blame] | 920 | SkPath modifiedPath; |
| 921 | SkPath* pathPtr = const_cast<SkPath*>(&origPath); |
| 922 | |
| 923 | SkMatrix matrix = *d.fMatrix; |
| 924 | if (prePathMatrix) { |
| 925 | if (paint.getPathEffect() || paint.getStyle() != SkPaint::kFill_Style) { |
| 926 | if (!pathIsMutable) { |
| 927 | pathPtr = &modifiedPath; |
| 928 | pathIsMutable = true; |
| 929 | } |
| 930 | origPath.transform(*prePathMatrix, pathPtr); |
| 931 | } else { |
| 932 | if (!matrix.preConcat(*prePathMatrix)) { |
edisonn@google.com | aa6c4d2 | 2013-09-19 17:36:47 +0000 | [diff] [blame^] | 933 | // TODO(edisonn): report somehow why we failed? |
vandebo@chromium.org | ff39032 | 2011-05-17 18:58:44 +0000 | [diff] [blame] | 934 | return; |
| 935 | } |
| 936 | } |
| 937 | } |
vandebo@chromium.org | 02cc5aa | 2011-01-25 22:06:29 +0000 | [diff] [blame] | 938 | |
vandebo@chromium.org | 7d71f7f | 2010-10-26 19:51:44 +0000 | [diff] [blame] | 939 | if (paint.getPathEffect()) { |
vandebo@chromium.org | 25adce8 | 2011-05-09 08:05:01 +0000 | [diff] [blame] | 940 | if (d.fClip->isEmpty()) { |
| 941 | return; |
| 942 | } |
vandebo@chromium.org | ff39032 | 2011-05-17 18:58:44 +0000 | [diff] [blame] | 943 | if (!pathIsMutable) { |
| 944 | pathPtr = &modifiedPath; |
| 945 | pathIsMutable = true; |
| 946 | } |
| 947 | bool fill = paint.getFillPath(origPath, pathPtr); |
vandebo@chromium.org | 7d71f7f | 2010-10-26 19:51:44 +0000 | [diff] [blame] | 948 | |
vandebo@chromium.org | 7e2ff7c | 2010-11-03 23:55:28 +0000 | [diff] [blame] | 949 | SkPaint noEffectPaint(paint); |
vandebo@chromium.org | ff39032 | 2011-05-17 18:58:44 +0000 | [diff] [blame] | 950 | noEffectPaint.setPathEffect(NULL); |
| 951 | if (fill) { |
| 952 | noEffectPaint.setStyle(SkPaint::kFill_Style); |
| 953 | } else { |
| 954 | noEffectPaint.setStyle(SkPaint::kStroke_Style); |
| 955 | noEffectPaint.setStrokeWidth(0); |
| 956 | } |
| 957 | drawPath(d, *pathPtr, noEffectPaint, NULL, true); |
vandebo@chromium.org | 7d71f7f | 2010-10-26 19:51:44 +0000 | [diff] [blame] | 958 | return; |
| 959 | } |
vandebo@chromium.org | ff39032 | 2011-05-17 18:58:44 +0000 | [diff] [blame] | 960 | |
commit-bot@chromium.org | 92ffe7d | 2013-07-31 22:54:31 +0000 | [diff] [blame] | 961 | #ifdef SK_PDF_USE_PATHOPS |
| 962 | if (handleInversePath(d, origPath, paint, pathIsMutable)) { |
| 963 | return; |
| 964 | } |
| 965 | #endif |
| 966 | |
epoger@google.com | b58772f | 2013-03-08 09:09:10 +0000 | [diff] [blame] | 967 | if (handleRectAnnotation(pathPtr->getBounds(), *d.fMatrix, paint)) { |
vandebo@chromium.org | 238be8c | 2012-07-13 20:06:02 +0000 | [diff] [blame] | 968 | return; |
| 969 | } |
| 970 | |
vandebo@chromium.org | 13d14a9 | 2011-05-24 23:12:41 +0000 | [diff] [blame] | 971 | ScopedContentEntry content(this, d, paint); |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 972 | if (!content.entry()) { |
vandebo@chromium.org | 25adce8 | 2011-05-09 08:05:01 +0000 | [diff] [blame] | 973 | return; |
| 974 | } |
vandebo@chromium.org | 683001c | 2012-05-09 17:17:51 +0000 | [diff] [blame] | 975 | SkPDFUtils::EmitPath(*pathPtr, paint.getStyle(), |
| 976 | &content.entry()->fContent); |
vandebo@chromium.org | ff39032 | 2011-05-17 18:58:44 +0000 | [diff] [blame] | 977 | SkPDFUtils::PaintPath(paint.getStyle(), pathPtr->getFillType(), |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 978 | &content.entry()->fContent); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 979 | } |
| 980 | |
edisonn@google.com | 2ae67e7 | 2013-02-12 01:06:38 +0000 | [diff] [blame] | 981 | void SkPDFDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap, |
| 982 | const SkRect* src, const SkRect& dst, |
commit-bot@chromium.org | eed779d | 2013-08-16 10:24:37 +0000 | [diff] [blame] | 983 | const SkPaint& paint, |
| 984 | SkCanvas::DrawBitmapRectFlags flags) { |
| 985 | // TODO: this code path must be updated to respect the flags parameter |
edisonn@google.com | 2ae67e7 | 2013-02-12 01:06:38 +0000 | [diff] [blame] | 986 | SkMatrix matrix; |
| 987 | SkRect bitmapBounds, tmpSrc, tmpDst; |
| 988 | SkBitmap tmpBitmap; |
| 989 | |
| 990 | bitmapBounds.isetWH(bitmap.width(), bitmap.height()); |
| 991 | |
| 992 | // Compute matrix from the two rectangles |
| 993 | if (src) { |
| 994 | tmpSrc = *src; |
| 995 | } else { |
| 996 | tmpSrc = bitmapBounds; |
| 997 | } |
| 998 | matrix.setRectToRect(tmpSrc, dst, SkMatrix::kFill_ScaleToFit); |
| 999 | |
| 1000 | const SkBitmap* bitmapPtr = &bitmap; |
| 1001 | |
| 1002 | // clip the tmpSrc to the bounds of the bitmap, and recompute dstRect if |
| 1003 | // needed (if the src was clipped). No check needed if src==null. |
| 1004 | if (src) { |
| 1005 | if (!bitmapBounds.contains(*src)) { |
| 1006 | if (!tmpSrc.intersect(bitmapBounds)) { |
| 1007 | return; // nothing to draw |
| 1008 | } |
| 1009 | // recompute dst, based on the smaller tmpSrc |
| 1010 | matrix.mapRect(&tmpDst, tmpSrc); |
| 1011 | } |
| 1012 | |
| 1013 | // since we may need to clamp to the borders of the src rect within |
| 1014 | // the bitmap, we extract a subset. |
| 1015 | // TODO: make sure this is handled in drawBitmap and remove from here. |
| 1016 | SkIRect srcIR; |
| 1017 | tmpSrc.roundOut(&srcIR); |
| 1018 | if (!bitmap.extractSubset(&tmpBitmap, srcIR)) { |
| 1019 | return; |
| 1020 | } |
| 1021 | bitmapPtr = &tmpBitmap; |
| 1022 | |
| 1023 | // Since we did an extract, we need to adjust the matrix accordingly |
| 1024 | SkScalar dx = 0, dy = 0; |
| 1025 | if (srcIR.fLeft > 0) { |
| 1026 | dx = SkIntToScalar(srcIR.fLeft); |
| 1027 | } |
| 1028 | if (srcIR.fTop > 0) { |
| 1029 | dy = SkIntToScalar(srcIR.fTop); |
| 1030 | } |
| 1031 | if (dx || dy) { |
| 1032 | matrix.preTranslate(dx, dy); |
| 1033 | } |
| 1034 | } |
robertphillips@google.com | 9bf380c | 2013-07-25 12:10:42 +0000 | [diff] [blame] | 1035 | this->drawBitmap(draw, *bitmapPtr, matrix, paint); |
edisonn@google.com | 2ae67e7 | 2013-02-12 01:06:38 +0000 | [diff] [blame] | 1036 | } |
| 1037 | |
vandebo@chromium.org | fb0b0ed | 2011-04-15 20:01:17 +0000 | [diff] [blame] | 1038 | void SkPDFDevice::drawBitmap(const SkDraw& d, const SkBitmap& bitmap, |
robertphillips@google.com | 9bf380c | 2013-07-25 12:10:42 +0000 | [diff] [blame] | 1039 | const SkMatrix& matrix, const SkPaint& paint) { |
vandebo@chromium.org | fb0b0ed | 2011-04-15 20:01:17 +0000 | [diff] [blame] | 1040 | if (d.fClip->isEmpty()) { |
| 1041 | return; |
| 1042 | } |
| 1043 | |
vandebo@chromium.org | 7e2ff7c | 2010-11-03 23:55:28 +0000 | [diff] [blame] | 1044 | SkMatrix transform = matrix; |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 1045 | transform.postConcat(*d.fMatrix); |
robertphillips@google.com | 9bf380c | 2013-07-25 12:10:42 +0000 | [diff] [blame] | 1046 | this->internalDrawBitmap(transform, d.fClipStack, *d.fClip, bitmap, NULL, paint); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 1047 | } |
| 1048 | |
vandebo@chromium.org | fb0b0ed | 2011-04-15 20:01:17 +0000 | [diff] [blame] | 1049 | void SkPDFDevice::drawSprite(const SkDraw& d, const SkBitmap& bitmap, |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 1050 | int x, int y, const SkPaint& paint) { |
vandebo@chromium.org | fb0b0ed | 2011-04-15 20:01:17 +0000 | [diff] [blame] | 1051 | if (d.fClip->isEmpty()) { |
| 1052 | return; |
| 1053 | } |
| 1054 | |
vandebo@chromium.org | 7e2ff7c | 2010-11-03 23:55:28 +0000 | [diff] [blame] | 1055 | SkMatrix matrix; |
reed@google.com | a6d59f6 | 2011-03-07 21:29:21 +0000 | [diff] [blame] | 1056 | matrix.setTranslate(SkIntToScalar(x), SkIntToScalar(y)); |
robertphillips@google.com | 9bf380c | 2013-07-25 12:10:42 +0000 | [diff] [blame] | 1057 | this->internalDrawBitmap(matrix, d.fClipStack, *d.fClip, bitmap, NULL, paint); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 1058 | } |
| 1059 | |
vandebo@chromium.org | 28be72b | 2010-11-11 21:37:00 +0000 | [diff] [blame] | 1060 | void SkPDFDevice::drawText(const SkDraw& d, const void* text, size_t len, |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 1061 | SkScalar x, SkScalar y, const SkPaint& paint) { |
edisonn@google.com | b62f93f | 2013-03-24 18:05:10 +0000 | [diff] [blame] | 1062 | NOT_IMPLEMENTED(paint.getMaskFilter() != NULL, false); |
| 1063 | if (paint.getMaskFilter() != NULL) { |
| 1064 | // Don't pretend we support drawing MaskFilters, it makes for artifacts |
| 1065 | // making text unreadable (e.g. same text twice when using CSS shadows). |
| 1066 | return; |
| 1067 | } |
vandebo@chromium.org | 25adce8 | 2011-05-09 08:05:01 +0000 | [diff] [blame] | 1068 | SkPaint textPaint = calculate_text_paint(paint); |
vandebo@chromium.org | 13d14a9 | 2011-05-24 23:12:41 +0000 | [diff] [blame] | 1069 | ScopedContentEntry content(this, d, textPaint, true); |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 1070 | if (!content.entry()) { |
vandebo@chromium.org | fb0b0ed | 2011-04-15 20:01:17 +0000 | [diff] [blame] | 1071 | return; |
| 1072 | } |
| 1073 | |
vandebo@chromium.org | 4e1cc6a | 2013-01-25 19:27:23 +0000 | [diff] [blame] | 1074 | SkGlyphStorage storage(0); |
| 1075 | uint16_t* glyphIDs = NULL; |
| 1076 | size_t numGlyphs = force_glyph_encoding(paint, text, len, &storage, |
| 1077 | &glyphIDs); |
| 1078 | textPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
vandebo@chromium.org | 28be72b | 2010-11-11 21:37:00 +0000 | [diff] [blame] | 1079 | |
vandebo@chromium.org | 28be72b | 2010-11-11 21:37:00 +0000 | [diff] [blame] | 1080 | SkDrawCacheProc glyphCacheProc = textPaint.getDrawCacheProc(); |
bungeman@google.com | 9a87cee | 2011-08-23 17:02:18 +0000 | [diff] [blame] | 1081 | align_text(glyphCacheProc, textPaint, glyphIDs, numGlyphs, &x, &y); |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 1082 | content.entry()->fContent.writeText("BT\n"); |
| 1083 | set_text_transform(x, y, textPaint.getTextSkewX(), |
| 1084 | &content.entry()->fContent); |
vandebo@chromium.org | 2a22e10 | 2011-01-25 21:01:34 +0000 | [diff] [blame] | 1085 | size_t consumedGlyphCount = 0; |
| 1086 | while (numGlyphs > consumedGlyphCount) { |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 1087 | updateFont(textPaint, glyphIDs[consumedGlyphCount], content.entry()); |
| 1088 | SkPDFFont* font = content.entry()->fState.fFont; |
vandebo@chromium.org | 0129410 | 2011-02-28 19:52:18 +0000 | [diff] [blame] | 1089 | size_t availableGlyphs = |
| 1090 | font->glyphsToPDFFontEncoding(glyphIDs + consumedGlyphCount, |
| 1091 | numGlyphs - consumedGlyphCount); |
vandebo@chromium.org | 9859428 | 2011-07-25 22:34:12 +0000 | [diff] [blame] | 1092 | fFontGlyphUsage->noteGlyphUsage(font, glyphIDs + consumedGlyphCount, |
| 1093 | availableGlyphs); |
vandebo@chromium.org | cae5fba | 2011-03-28 19:03:50 +0000 | [diff] [blame] | 1094 | SkString encodedString = |
reed@google.com | f6c3ebd | 2011-07-20 17:20:28 +0000 | [diff] [blame] | 1095 | SkPDFString::FormatString(glyphIDs + consumedGlyphCount, |
vandebo@chromium.org | cae5fba | 2011-03-28 19:03:50 +0000 | [diff] [blame] | 1096 | availableGlyphs, font->multiByteGlyphs()); |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 1097 | content.entry()->fContent.writeText(encodedString.c_str()); |
vandebo@chromium.org | 0129410 | 2011-02-28 19:52:18 +0000 | [diff] [blame] | 1098 | consumedGlyphCount += availableGlyphs; |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 1099 | content.entry()->fContent.writeText(" Tj\n"); |
vandebo@chromium.org | 2a22e10 | 2011-01-25 21:01:34 +0000 | [diff] [blame] | 1100 | } |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 1101 | content.entry()->fContent.writeText("ET\n"); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 1102 | } |
| 1103 | |
vandebo@chromium.org | fb0b0ed | 2011-04-15 20:01:17 +0000 | [diff] [blame] | 1104 | void SkPDFDevice::drawPosText(const SkDraw& d, const void* text, size_t len, |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 1105 | const SkScalar pos[], SkScalar constY, |
| 1106 | int scalarsPerPos, const SkPaint& paint) { |
edisonn@google.com | b62f93f | 2013-03-24 18:05:10 +0000 | [diff] [blame] | 1107 | NOT_IMPLEMENTED(paint.getMaskFilter() != NULL, false); |
| 1108 | if (paint.getMaskFilter() != NULL) { |
| 1109 | // Don't pretend we support drawing MaskFilters, it makes for artifacts |
| 1110 | // making text unreadable (e.g. same text twice when using CSS shadows). |
| 1111 | return; |
| 1112 | } |
vandebo@chromium.org | 28be72b | 2010-11-11 21:37:00 +0000 | [diff] [blame] | 1113 | SkASSERT(1 == scalarsPerPos || 2 == scalarsPerPos); |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 1114 | SkPaint textPaint = calculate_text_paint(paint); |
vandebo@chromium.org | 13d14a9 | 2011-05-24 23:12:41 +0000 | [diff] [blame] | 1115 | ScopedContentEntry content(this, d, textPaint, true); |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 1116 | if (!content.entry()) { |
vandebo@chromium.org | 25adce8 | 2011-05-09 08:05:01 +0000 | [diff] [blame] | 1117 | return; |
| 1118 | } |
vandebo@chromium.org | 28be72b | 2010-11-11 21:37:00 +0000 | [diff] [blame] | 1119 | |
vandebo@chromium.org | 4e1cc6a | 2013-01-25 19:27:23 +0000 | [diff] [blame] | 1120 | SkGlyphStorage storage(0); |
| 1121 | uint16_t* glyphIDs = NULL; |
| 1122 | size_t numGlyphs = force_glyph_encoding(paint, text, len, &storage, |
| 1123 | &glyphIDs); |
| 1124 | textPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
vandebo@chromium.org | 28be72b | 2010-11-11 21:37:00 +0000 | [diff] [blame] | 1125 | |
| 1126 | SkDrawCacheProc glyphCacheProc = textPaint.getDrawCacheProc(); |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 1127 | content.entry()->fContent.writeText("BT\n"); |
| 1128 | updateFont(textPaint, glyphIDs[0], content.entry()); |
vandebo@chromium.org | 2a22e10 | 2011-01-25 21:01:34 +0000 | [diff] [blame] | 1129 | for (size_t i = 0; i < numGlyphs; i++) { |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 1130 | SkPDFFont* font = content.entry()->fState.fFont; |
vandebo@chromium.org | 0129410 | 2011-02-28 19:52:18 +0000 | [diff] [blame] | 1131 | uint16_t encodedValue = glyphIDs[i]; |
| 1132 | if (font->glyphsToPDFFontEncoding(&encodedValue, 1) != 1) { |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 1133 | updateFont(textPaint, glyphIDs[i], content.entry()); |
vandebo@chromium.org | 2a22e10 | 2011-01-25 21:01:34 +0000 | [diff] [blame] | 1134 | i--; |
| 1135 | continue; |
| 1136 | } |
vandebo@chromium.org | 9859428 | 2011-07-25 22:34:12 +0000 | [diff] [blame] | 1137 | fFontGlyphUsage->noteGlyphUsage(font, &encodedValue, 1); |
vandebo@chromium.org | 28be72b | 2010-11-11 21:37:00 +0000 | [diff] [blame] | 1138 | SkScalar x = pos[i * scalarsPerPos]; |
| 1139 | SkScalar y = scalarsPerPos == 1 ? constY : pos[i * scalarsPerPos + 1]; |
bungeman@google.com | 9a87cee | 2011-08-23 17:02:18 +0000 | [diff] [blame] | 1140 | align_text(glyphCacheProc, textPaint, glyphIDs + i, 1, &x, &y); |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 1141 | set_text_transform(x, y, textPaint.getTextSkewX(), |
| 1142 | &content.entry()->fContent); |
vandebo@chromium.org | cae5fba | 2011-03-28 19:03:50 +0000 | [diff] [blame] | 1143 | SkString encodedString = |
reed@google.com | f6c3ebd | 2011-07-20 17:20:28 +0000 | [diff] [blame] | 1144 | SkPDFString::FormatString(&encodedValue, 1, |
vandebo@chromium.org | cae5fba | 2011-03-28 19:03:50 +0000 | [diff] [blame] | 1145 | font->multiByteGlyphs()); |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 1146 | content.entry()->fContent.writeText(encodedString.c_str()); |
| 1147 | content.entry()->fContent.writeText(" Tj\n"); |
vandebo@chromium.org | 28be72b | 2010-11-11 21:37:00 +0000 | [diff] [blame] | 1148 | } |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 1149 | content.entry()->fContent.writeText("ET\n"); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 1150 | } |
| 1151 | |
vandebo@chromium.org | fb0b0ed | 2011-04-15 20:01:17 +0000 | [diff] [blame] | 1152 | void SkPDFDevice::drawTextOnPath(const SkDraw& d, const void* text, size_t len, |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 1153 | const SkPath& path, const SkMatrix* matrix, |
| 1154 | const SkPaint& paint) { |
vandebo@chromium.org | fb0b0ed | 2011-04-15 20:01:17 +0000 | [diff] [blame] | 1155 | if (d.fClip->isEmpty()) { |
| 1156 | return; |
| 1157 | } |
vandebo@chromium.org | 290e3bb | 2011-11-08 23:42:53 +0000 | [diff] [blame] | 1158 | d.drawTextOnPath((const char*)text, len, path, matrix, paint); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 1159 | } |
| 1160 | |
vandebo@chromium.org | fb0b0ed | 2011-04-15 20:01:17 +0000 | [diff] [blame] | 1161 | void SkPDFDevice::drawVertices(const SkDraw& d, SkCanvas::VertexMode, |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 1162 | int vertexCount, const SkPoint verts[], |
| 1163 | const SkPoint texs[], const SkColor colors[], |
| 1164 | SkXfermode* xmode, const uint16_t indices[], |
| 1165 | int indexCount, const SkPaint& paint) { |
vandebo@chromium.org | fb0b0ed | 2011-04-15 20:01:17 +0000 | [diff] [blame] | 1166 | if (d.fClip->isEmpty()) { |
| 1167 | return; |
| 1168 | } |
vandebo@chromium.org | a518086 | 2010-10-26 19:48:49 +0000 | [diff] [blame] | 1169 | NOT_IMPLEMENTED("drawVerticies", true); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 1170 | } |
| 1171 | |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 1172 | void SkPDFDevice::drawDevice(const SkDraw& d, SkBaseDevice* device, int x, int y, |
vandebo@chromium.org | eb6c759 | 2010-10-26 19:54:45 +0000 | [diff] [blame] | 1173 | const SkPaint& paint) { |
| 1174 | if ((device->getDeviceCapabilities() & kVector_Capability) == 0) { |
| 1175 | // If we somehow get a raster device, do what our parent would do. |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 1176 | INHERITED::drawDevice(d, device, x, y, paint); |
vandebo@chromium.org | eb6c759 | 2010-10-26 19:54:45 +0000 | [diff] [blame] | 1177 | return; |
| 1178 | } |
vandebo@chromium.org | eb6c759 | 2010-10-26 19:54:45 +0000 | [diff] [blame] | 1179 | |
vandebo@chromium.org | ee7a956 | 2011-05-24 17:38:01 +0000 | [diff] [blame] | 1180 | // Assume that a vector capable device means that it's a PDF Device. |
| 1181 | SkPDFDevice* pdfDevice = static_cast<SkPDFDevice*>(device); |
ctguil@chromium.org | f4ff39c | 2011-05-24 19:55:05 +0000 | [diff] [blame] | 1182 | if (pdfDevice->isContentEmpty()) { |
vandebo@chromium.org | ee7a956 | 2011-05-24 17:38:01 +0000 | [diff] [blame] | 1183 | return; |
| 1184 | } |
| 1185 | |
vandebo@chromium.org | 1aef2ed | 2011-02-03 21:46:10 +0000 | [diff] [blame] | 1186 | SkMatrix matrix; |
reed@google.com | a6d59f6 | 2011-03-07 21:29:21 +0000 | [diff] [blame] | 1187 | matrix.setTranslate(SkIntToScalar(x), SkIntToScalar(y)); |
vandebo@chromium.org | 13d14a9 | 2011-05-24 23:12:41 +0000 | [diff] [blame] | 1188 | ScopedContentEntry content(this, d.fClipStack, *d.fClip, matrix, paint); |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 1189 | if (!content.entry()) { |
vandebo@chromium.org | 25adce8 | 2011-05-09 08:05:01 +0000 | [diff] [blame] | 1190 | return; |
| 1191 | } |
vandebo@chromium.org | 1aef2ed | 2011-02-03 21:46:10 +0000 | [diff] [blame] | 1192 | |
| 1193 | SkPDFFormXObject* xobject = new SkPDFFormXObject(pdfDevice); |
vandebo@chromium.org | eb6c759 | 2010-10-26 19:54:45 +0000 | [diff] [blame] | 1194 | fXObjectResources.push(xobject); // Transfer reference. |
vandebo@chromium.org | 6112c21 | 2011-05-13 03:50:38 +0000 | [diff] [blame] | 1195 | SkPDFUtils::DrawFormXObject(fXObjectResources.count() - 1, |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 1196 | &content.entry()->fContent); |
vandebo@chromium.org | 9859428 | 2011-07-25 22:34:12 +0000 | [diff] [blame] | 1197 | |
| 1198 | // Merge glyph sets from the drawn device. |
| 1199 | fFontGlyphUsage->merge(pdfDevice->getFontGlyphUsage()); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 1200 | } |
| 1201 | |
robertphillips@google.com | 40a1ae4 | 2012-07-13 15:36:15 +0000 | [diff] [blame] | 1202 | void SkPDFDevice::onAttachToCanvas(SkCanvas* canvas) { |
| 1203 | INHERITED::onAttachToCanvas(canvas); |
| 1204 | |
| 1205 | // Canvas promises that this ptr is valid until onDetachFromCanvas is called |
| 1206 | fClipStack = canvas->getClipStack(); |
| 1207 | } |
| 1208 | |
| 1209 | void SkPDFDevice::onDetachFromCanvas() { |
| 1210 | INHERITED::onDetachFromCanvas(); |
| 1211 | |
| 1212 | fClipStack = NULL; |
| 1213 | } |
| 1214 | |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 1215 | ContentEntry* SkPDFDevice::getLastContentEntry() { |
| 1216 | if (fDrawingArea == kContent_DrawingArea) { |
| 1217 | return fLastContentEntry; |
| 1218 | } else { |
| 1219 | return fLastMarginContentEntry; |
| 1220 | } |
| 1221 | } |
| 1222 | |
commit-bot@chromium.org | e029440 | 2013-08-29 22:14:04 +0000 | [diff] [blame] | 1223 | SkAutoTDelete<ContentEntry>* SkPDFDevice::getContentEntries() { |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 1224 | if (fDrawingArea == kContent_DrawingArea) { |
ctguil@chromium.org | 9510ccc | 2011-07-27 00:10:51 +0000 | [diff] [blame] | 1225 | return &fContentEntries; |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 1226 | } else { |
ctguil@chromium.org | 9510ccc | 2011-07-27 00:10:51 +0000 | [diff] [blame] | 1227 | return &fMarginContentEntries; |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 1228 | } |
| 1229 | } |
| 1230 | |
| 1231 | void SkPDFDevice::setLastContentEntry(ContentEntry* contentEntry) { |
| 1232 | if (fDrawingArea == kContent_DrawingArea) { |
| 1233 | fLastContentEntry = contentEntry; |
| 1234 | } else { |
| 1235 | fLastMarginContentEntry = contentEntry; |
| 1236 | } |
| 1237 | } |
| 1238 | |
| 1239 | void SkPDFDevice::setDrawingArea(DrawingArea drawingArea) { |
ctguil@chromium.org | 9510ccc | 2011-07-27 00:10:51 +0000 | [diff] [blame] | 1240 | // A ScopedContentEntry only exists during the course of a draw call, so |
| 1241 | // this can't be called while a ScopedContentEntry exists. |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 1242 | fDrawingArea = drawingArea; |
| 1243 | } |
| 1244 | |
commit-bot@chromium.org | 4740135 | 2013-07-23 21:49:29 +0000 | [diff] [blame] | 1245 | SkPDFResourceDict* SkPDFDevice::getResourceDict() { |
reed@google.com | fc641d0 | 2012-09-20 17:52:20 +0000 | [diff] [blame] | 1246 | if (NULL == fResourceDict) { |
commit-bot@chromium.org | 4740135 | 2013-07-23 21:49:29 +0000 | [diff] [blame] | 1247 | fResourceDict = SkNEW(SkPDFResourceDict); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 1248 | |
| 1249 | if (fGraphicStateResources.count()) { |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 1250 | for (int i = 0; i < fGraphicStateResources.count(); i++) { |
commit-bot@chromium.org | 4740135 | 2013-07-23 21:49:29 +0000 | [diff] [blame] | 1251 | fResourceDict->insertResourceAsReference( |
| 1252 | SkPDFResourceDict::kExtGState_ResourceType, |
| 1253 | i, fGraphicStateResources[i]); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 1254 | } |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 1255 | } |
| 1256 | |
| 1257 | if (fXObjectResources.count()) { |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 1258 | for (int i = 0; i < fXObjectResources.count(); i++) { |
commit-bot@chromium.org | 4740135 | 2013-07-23 21:49:29 +0000 | [diff] [blame] | 1259 | fResourceDict->insertResourceAsReference( |
| 1260 | SkPDFResourceDict::kXObject_ResourceType, |
| 1261 | i, fXObjectResources[i]); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 1262 | } |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 1263 | } |
vandebo@chromium.org | 28be72b | 2010-11-11 21:37:00 +0000 | [diff] [blame] | 1264 | |
| 1265 | if (fFontResources.count()) { |
vandebo@chromium.org | 28be72b | 2010-11-11 21:37:00 +0000 | [diff] [blame] | 1266 | for (int i = 0; i < fFontResources.count(); i++) { |
commit-bot@chromium.org | 4740135 | 2013-07-23 21:49:29 +0000 | [diff] [blame] | 1267 | fResourceDict->insertResourceAsReference( |
| 1268 | SkPDFResourceDict::kFont_ResourceType, |
| 1269 | i, fFontResources[i]); |
vandebo@chromium.org | 28be72b | 2010-11-11 21:37:00 +0000 | [diff] [blame] | 1270 | } |
vandebo@chromium.org | 28be72b | 2010-11-11 21:37:00 +0000 | [diff] [blame] | 1271 | } |
| 1272 | |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 1273 | if (fShaderResources.count()) { |
vandebo@chromium.org | d96d17b | 2013-01-04 19:31:24 +0000 | [diff] [blame] | 1274 | SkAutoTUnref<SkPDFDict> patterns(new SkPDFDict()); |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 1275 | for (int i = 0; i < fShaderResources.count(); i++) { |
commit-bot@chromium.org | 4740135 | 2013-07-23 21:49:29 +0000 | [diff] [blame] | 1276 | fResourceDict->insertResourceAsReference( |
| 1277 | SkPDFResourceDict::kPattern_ResourceType, |
| 1278 | i, fShaderResources[i]); |
vandebo@chromium.org | fc16667 | 2013-07-22 18:31:24 +0000 | [diff] [blame] | 1279 | } |
vandebo@chromium.org | fc16667 | 2013-07-22 18:31:24 +0000 | [diff] [blame] | 1280 | } |
vandebo@chromium.org | fc16667 | 2013-07-22 18:31:24 +0000 | [diff] [blame] | 1281 | } |
| 1282 | return fResourceDict; |
| 1283 | } |
| 1284 | |
vandebo@chromium.org | f0ec266 | 2011-05-29 05:55:42 +0000 | [diff] [blame] | 1285 | const SkTDArray<SkPDFFont*>& SkPDFDevice::getFontResources() const { |
| 1286 | return fFontResources; |
| 1287 | } |
| 1288 | |
reed@google.com | 2a006c1 | 2012-09-19 17:05:55 +0000 | [diff] [blame] | 1289 | SkPDFArray* SkPDFDevice::copyMediaBox() const { |
| 1290 | // should this be a singleton? |
| 1291 | SkAutoTUnref<SkPDFInt> zero(SkNEW_ARGS(SkPDFInt, (0))); |
vandebo@chromium.org | f7c1576 | 2011-02-01 22:19:44 +0000 | [diff] [blame] | 1292 | |
reed@google.com | 2a006c1 | 2012-09-19 17:05:55 +0000 | [diff] [blame] | 1293 | SkPDFArray* mediaBox = SkNEW(SkPDFArray); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 1294 | mediaBox->reserve(4); |
| 1295 | mediaBox->append(zero.get()); |
| 1296 | mediaBox->append(zero.get()); |
reed@google.com | c789cf1 | 2011-07-20 12:14:33 +0000 | [diff] [blame] | 1297 | mediaBox->appendInt(fPageSize.fWidth); |
| 1298 | mediaBox->appendInt(fPageSize.fHeight); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 1299 | return mediaBox; |
| 1300 | } |
| 1301 | |
vandebo@chromium.org | c2a9b7f | 2011-02-24 23:22:30 +0000 | [diff] [blame] | 1302 | SkStream* SkPDFDevice::content() const { |
reed@google.com | 5667afc | 2011-06-27 14:42:15 +0000 | [diff] [blame] | 1303 | SkMemoryStream* result = new SkMemoryStream; |
| 1304 | result->setData(this->copyContentToData())->unref(); |
| 1305 | return result; |
| 1306 | } |
| 1307 | |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 1308 | void SkPDFDevice::copyContentEntriesToData(ContentEntry* entry, |
| 1309 | SkWStream* data) const { |
ctguil@chromium.org | 9510ccc | 2011-07-27 00:10:51 +0000 | [diff] [blame] | 1310 | // TODO(ctguil): For margins, I'm not sure fExistingClipStack/Region is the |
| 1311 | // right thing to pass here. |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 1312 | GraphicStackState gsState(fExistingClipStack, fExistingClipRegion, data); |
ctguil@chromium.org | 9510ccc | 2011-07-27 00:10:51 +0000 | [diff] [blame] | 1313 | while (entry != NULL) { |
vandebo@chromium.org | 663515b | 2012-01-05 18:45:27 +0000 | [diff] [blame] | 1314 | SkPoint translation; |
| 1315 | translation.iset(this->getOrigin()); |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 1316 | translation.negate(); |
| 1317 | gsState.updateClip(entry->fState.fClipStack, entry->fState.fClipRegion, |
| 1318 | translation); |
| 1319 | gsState.updateMatrix(entry->fState.fMatrix); |
| 1320 | gsState.updateDrawingState(entry->fState); |
ctguil@chromium.org | 9510ccc | 2011-07-27 00:10:51 +0000 | [diff] [blame] | 1321 | |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 1322 | SkAutoDataUnref copy(entry->fContent.copyToData()); |
robertphillips@google.com | 59f46b8 | 2012-07-10 17:30:58 +0000 | [diff] [blame] | 1323 | data->write(copy->data(), copy->size()); |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 1324 | entry = entry->fNext.get(); |
| 1325 | } |
| 1326 | gsState.drainStack(); |
| 1327 | } |
| 1328 | |
reed@google.com | 5667afc | 2011-06-27 14:42:15 +0000 | [diff] [blame] | 1329 | SkData* SkPDFDevice::copyContentToData() const { |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 1330 | SkDynamicMemoryWStream data; |
| 1331 | if (fInitialTransform.getType() != SkMatrix::kIdentity_Mask) { |
| 1332 | SkPDFUtils::AppendTransform(fInitialTransform, &data); |
vandebo@chromium.org | c2a9b7f | 2011-02-24 23:22:30 +0000 | [diff] [blame] | 1333 | } |
ctguil@chromium.org | 9510ccc | 2011-07-27 00:10:51 +0000 | [diff] [blame] | 1334 | |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 1335 | // TODO(aayushkumar): Apply clip along the margins. Currently, webkit |
| 1336 | // colors the contentArea white before it starts drawing into it and |
| 1337 | // that currently acts as our clip. |
| 1338 | // Also, think about adding a transform here (or assume that the values |
| 1339 | // sent across account for that) |
| 1340 | SkPDFDevice::copyContentEntriesToData(fMarginContentEntries.get(), &data); |
ctguil@chromium.org | 9510ccc | 2011-07-27 00:10:51 +0000 | [diff] [blame] | 1341 | |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 1342 | // If the content area is the entire page, then we don't need to clip |
| 1343 | // the content area (PDF area clips to the page size). Otherwise, |
| 1344 | // we have to clip to the content area; we've already applied the |
| 1345 | // initial transform, so just clip to the device size. |
| 1346 | if (fPageSize != fContentSize) { |
robertphillips@google.com | 8637a36 | 2012-04-10 18:32:35 +0000 | [diff] [blame] | 1347 | SkRect r = SkRect::MakeWH(SkIntToScalar(this->width()), |
| 1348 | SkIntToScalar(this->height())); |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 1349 | emit_clip(NULL, &r, &data); |
| 1350 | } |
vandebo@chromium.org | 9859428 | 2011-07-25 22:34:12 +0000 | [diff] [blame] | 1351 | |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 1352 | SkPDFDevice::copyContentEntriesToData(fContentEntries.get(), &data); |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 1353 | |
reed@google.com | 5667afc | 2011-06-27 14:42:15 +0000 | [diff] [blame] | 1354 | // potentially we could cache this SkData, and only rebuild it if we |
| 1355 | // see that our state has changed. |
| 1356 | return data.copyToData(); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 1357 | } |
| 1358 | |
commit-bot@chromium.org | d2623a1 | 2013-08-08 02:52:05 +0000 | [diff] [blame] | 1359 | #ifdef SK_PDF_USE_PATHOPS |
commit-bot@chromium.org | 92ffe7d | 2013-07-31 22:54:31 +0000 | [diff] [blame] | 1360 | /* Draws an inverse filled path by using Path Ops to compute the positive |
| 1361 | * inverse using the current clip as the inverse bounds. |
| 1362 | * Return true if this was an inverse path and was properly handled, |
| 1363 | * otherwise returns false and the normal drawing routine should continue, |
| 1364 | * either as a (incorrect) fallback or because the path was not inverse |
| 1365 | * in the first place. |
| 1366 | */ |
| 1367 | bool SkPDFDevice::handleInversePath(const SkDraw& d, const SkPath& origPath, |
| 1368 | const SkPaint& paint, bool pathIsMutable) { |
| 1369 | if (!origPath.isInverseFillType()) { |
| 1370 | return false; |
| 1371 | } |
| 1372 | |
| 1373 | if (d.fClip->isEmpty()) { |
| 1374 | return false; |
| 1375 | } |
| 1376 | |
| 1377 | SkPath modifiedPath; |
| 1378 | SkPath* pathPtr = const_cast<SkPath*>(&origPath); |
| 1379 | SkPaint noInversePaint(paint); |
| 1380 | |
| 1381 | // Merge stroking operations into final path. |
| 1382 | if (SkPaint::kStroke_Style == paint.getStyle() || |
| 1383 | SkPaint::kStrokeAndFill_Style == paint.getStyle()) { |
| 1384 | bool doFillPath = paint.getFillPath(origPath, &modifiedPath); |
| 1385 | if (doFillPath) { |
| 1386 | noInversePaint.setStyle(SkPaint::kFill_Style); |
| 1387 | noInversePaint.setStrokeWidth(0); |
| 1388 | pathPtr = &modifiedPath; |
| 1389 | } else { |
| 1390 | // To be consistent with the raster output, hairline strokes |
| 1391 | // are rendered as non-inverted. |
| 1392 | modifiedPath.toggleInverseFillType(); |
| 1393 | drawPath(d, modifiedPath, paint, NULL, true); |
| 1394 | return true; |
| 1395 | } |
| 1396 | } |
| 1397 | |
| 1398 | // Get bounds of clip in current transform space |
| 1399 | // (clip bounds are given in device space). |
| 1400 | SkRect bounds; |
| 1401 | SkMatrix transformInverse; |
| 1402 | if (!d.fMatrix->invert(&transformInverse)) { |
| 1403 | return false; |
| 1404 | } |
| 1405 | bounds.set(d.fClip->getBounds()); |
| 1406 | transformInverse.mapRect(&bounds); |
| 1407 | |
| 1408 | // Extend the bounds by the line width (plus some padding) |
| 1409 | // so the edge doesn't cause a visible stroke. |
| 1410 | bounds.outset(paint.getStrokeWidth() + SK_Scalar1, |
| 1411 | paint.getStrokeWidth() + SK_Scalar1); |
| 1412 | |
| 1413 | if (!calculate_inverse_path(bounds, *pathPtr, &modifiedPath)) { |
| 1414 | return false; |
| 1415 | } |
| 1416 | |
| 1417 | drawPath(d, modifiedPath, noInversePaint, NULL, true); |
| 1418 | return true; |
| 1419 | } |
commit-bot@chromium.org | d2623a1 | 2013-08-08 02:52:05 +0000 | [diff] [blame] | 1420 | #endif |
commit-bot@chromium.org | 92ffe7d | 2013-07-31 22:54:31 +0000 | [diff] [blame] | 1421 | |
epoger@google.com | b58772f | 2013-03-08 09:09:10 +0000 | [diff] [blame] | 1422 | bool SkPDFDevice::handleRectAnnotation(const SkRect& r, const SkMatrix& matrix, |
| 1423 | const SkPaint& p) { |
vandebo@chromium.org | 238be8c | 2012-07-13 20:06:02 +0000 | [diff] [blame] | 1424 | SkAnnotation* annotationInfo = p.getAnnotation(); |
| 1425 | if (!annotationInfo) { |
| 1426 | return false; |
| 1427 | } |
| 1428 | SkData* urlData = annotationInfo->find(SkAnnotationKeys::URL_Key()); |
epoger@google.com | b58772f | 2013-03-08 09:09:10 +0000 | [diff] [blame] | 1429 | if (urlData) { |
| 1430 | handleLinkToURL(urlData, r, matrix); |
| 1431 | return p.isNoDrawAnnotation(); |
| 1432 | } |
| 1433 | SkData* linkToName = annotationInfo->find(SkAnnotationKeys::Link_Named_Dest_Key()); |
| 1434 | if (linkToName) { |
| 1435 | handleLinkToNamedDest(linkToName, r, matrix); |
| 1436 | return p.isNoDrawAnnotation(); |
| 1437 | } |
| 1438 | return false; |
| 1439 | } |
| 1440 | |
| 1441 | bool SkPDFDevice::handlePointAnnotation(const SkPoint* points, size_t count, |
| 1442 | const SkMatrix& matrix, |
| 1443 | const SkPaint& paint) { |
| 1444 | SkAnnotation* annotationInfo = paint.getAnnotation(); |
| 1445 | if (!annotationInfo) { |
vandebo@chromium.org | 238be8c | 2012-07-13 20:06:02 +0000 | [diff] [blame] | 1446 | return false; |
| 1447 | } |
epoger@google.com | b58772f | 2013-03-08 09:09:10 +0000 | [diff] [blame] | 1448 | SkData* nameData = annotationInfo->find(SkAnnotationKeys::Define_Named_Dest_Key()); |
| 1449 | if (nameData) { |
| 1450 | for (size_t i = 0; i < count; i++) { |
| 1451 | defineNamedDestination(nameData, points[i], matrix); |
| 1452 | } |
| 1453 | return paint.isNoDrawAnnotation(); |
| 1454 | } |
| 1455 | return false; |
| 1456 | } |
vandebo@chromium.org | 238be8c | 2012-07-13 20:06:02 +0000 | [diff] [blame] | 1457 | |
epoger@google.com | b58772f | 2013-03-08 09:09:10 +0000 | [diff] [blame] | 1458 | SkPDFDict* SkPDFDevice::createLinkAnnotation(const SkRect& r, const SkMatrix& matrix) { |
vandebo@chromium.org | 238be8c | 2012-07-13 20:06:02 +0000 | [diff] [blame] | 1459 | SkMatrix transform = matrix; |
| 1460 | transform.postConcat(fInitialTransform); |
| 1461 | SkRect translatedRect; |
| 1462 | transform.mapRect(&translatedRect, r); |
| 1463 | |
reed@google.com | 2a006c1 | 2012-09-19 17:05:55 +0000 | [diff] [blame] | 1464 | if (NULL == fAnnotations) { |
| 1465 | fAnnotations = SkNEW(SkPDFArray); |
vandebo@chromium.org | 238be8c | 2012-07-13 20:06:02 +0000 | [diff] [blame] | 1466 | } |
epoger@google.com | b58772f | 2013-03-08 09:09:10 +0000 | [diff] [blame] | 1467 | SkPDFDict* annotation(SkNEW_ARGS(SkPDFDict, ("Annot"))); |
vandebo@chromium.org | 238be8c | 2012-07-13 20:06:02 +0000 | [diff] [blame] | 1468 | annotation->insertName("Subtype", "Link"); |
epoger@google.com | b58772f | 2013-03-08 09:09:10 +0000 | [diff] [blame] | 1469 | fAnnotations->append(annotation); |
vandebo@chromium.org | 238be8c | 2012-07-13 20:06:02 +0000 | [diff] [blame] | 1470 | |
epoger@google.com | b58772f | 2013-03-08 09:09:10 +0000 | [diff] [blame] | 1471 | SkAutoTUnref<SkPDFArray> border(SkNEW(SkPDFArray)); |
vandebo@chromium.org | 238be8c | 2012-07-13 20:06:02 +0000 | [diff] [blame] | 1472 | border->reserve(3); |
| 1473 | border->appendInt(0); // Horizontal corner radius. |
| 1474 | border->appendInt(0); // Vertical corner radius. |
| 1475 | border->appendInt(0); // Width, 0 = no border. |
| 1476 | annotation->insert("Border", border.get()); |
| 1477 | |
epoger@google.com | b58772f | 2013-03-08 09:09:10 +0000 | [diff] [blame] | 1478 | SkAutoTUnref<SkPDFArray> rect(SkNEW(SkPDFArray)); |
vandebo@chromium.org | 238be8c | 2012-07-13 20:06:02 +0000 | [diff] [blame] | 1479 | rect->reserve(4); |
| 1480 | rect->appendScalar(translatedRect.fLeft); |
| 1481 | rect->appendScalar(translatedRect.fTop); |
| 1482 | rect->appendScalar(translatedRect.fRight); |
| 1483 | rect->appendScalar(translatedRect.fBottom); |
| 1484 | annotation->insert("Rect", rect.get()); |
| 1485 | |
epoger@google.com | b58772f | 2013-03-08 09:09:10 +0000 | [diff] [blame] | 1486 | return annotation; |
| 1487 | } |
epoger@google.com | 1cad898 | 2013-03-06 00:05:13 +0000 | [diff] [blame] | 1488 | |
epoger@google.com | b58772f | 2013-03-08 09:09:10 +0000 | [diff] [blame] | 1489 | void SkPDFDevice::handleLinkToURL(SkData* urlData, const SkRect& r, |
| 1490 | const SkMatrix& matrix) { |
| 1491 | SkAutoTUnref<SkPDFDict> annotation(createLinkAnnotation(r, matrix)); |
| 1492 | |
| 1493 | SkString url(static_cast<const char *>(urlData->data()), |
| 1494 | urlData->size() - 1); |
| 1495 | SkAutoTUnref<SkPDFDict> action(SkNEW_ARGS(SkPDFDict, ("Action"))); |
| 1496 | action->insertName("S", "URI"); |
| 1497 | action->insert("URI", SkNEW_ARGS(SkPDFString, (url)))->unref(); |
| 1498 | annotation->insert("A", action.get()); |
| 1499 | } |
| 1500 | |
| 1501 | void SkPDFDevice::handleLinkToNamedDest(SkData* nameData, const SkRect& r, |
| 1502 | const SkMatrix& matrix) { |
| 1503 | SkAutoTUnref<SkPDFDict> annotation(createLinkAnnotation(r, matrix)); |
| 1504 | SkString name(static_cast<const char *>(nameData->data()), |
| 1505 | nameData->size() - 1); |
| 1506 | annotation->insert("Dest", SkNEW_ARGS(SkPDFName, (name)))->unref(); |
| 1507 | } |
| 1508 | |
| 1509 | struct NamedDestination { |
| 1510 | const SkData* nameData; |
| 1511 | SkPoint point; |
| 1512 | |
| 1513 | NamedDestination(const SkData* nameData, const SkPoint& point) |
| 1514 | : nameData(nameData), point(point) { |
| 1515 | nameData->ref(); |
| 1516 | } |
| 1517 | |
| 1518 | ~NamedDestination() { |
| 1519 | nameData->unref(); |
| 1520 | } |
| 1521 | }; |
| 1522 | |
| 1523 | void SkPDFDevice::defineNamedDestination(SkData* nameData, const SkPoint& point, |
| 1524 | const SkMatrix& matrix) { |
| 1525 | SkMatrix transform = matrix; |
| 1526 | transform.postConcat(fInitialTransform); |
| 1527 | SkPoint translatedPoint; |
| 1528 | transform.mapXY(point.x(), point.y(), &translatedPoint); |
| 1529 | fNamedDestinations.push( |
| 1530 | SkNEW_ARGS(NamedDestination, (nameData, translatedPoint))); |
| 1531 | } |
| 1532 | |
| 1533 | void SkPDFDevice::appendDestinations(SkPDFDict* dict, SkPDFObject* page) { |
| 1534 | int nDest = fNamedDestinations.count(); |
| 1535 | for (int i = 0; i < nDest; i++) { |
| 1536 | NamedDestination* dest = fNamedDestinations[i]; |
| 1537 | SkAutoTUnref<SkPDFArray> pdfDest(SkNEW(SkPDFArray)); |
| 1538 | pdfDest->reserve(5); |
| 1539 | pdfDest->append(SkNEW_ARGS(SkPDFObjRef, (page)))->unref(); |
| 1540 | pdfDest->appendName("XYZ"); |
| 1541 | pdfDest->appendScalar(dest->point.x()); |
| 1542 | pdfDest->appendScalar(dest->point.y()); |
| 1543 | pdfDest->appendInt(0); // Leave zoom unchanged |
| 1544 | dict->insert(static_cast<const char *>(dest->nameData->data()), pdfDest); |
| 1545 | } |
vandebo@chromium.org | 238be8c | 2012-07-13 20:06:02 +0000 | [diff] [blame] | 1546 | } |
| 1547 | |
reed@google.com | fc641d0 | 2012-09-20 17:52:20 +0000 | [diff] [blame] | 1548 | SkPDFFormXObject* SkPDFDevice::createFormXObjectFromDevice() { |
| 1549 | SkPDFFormXObject* xobject = SkNEW_ARGS(SkPDFFormXObject, (this)); |
vandebo@chromium.org | 9859428 | 2011-07-25 22:34:12 +0000 | [diff] [blame] | 1550 | // We always draw the form xobjects that we create back into the device, so |
| 1551 | // we simply preserve the font usage instead of pulling it out and merging |
| 1552 | // it back in later. |
| 1553 | cleanUp(false); // Reset this device to have no content. |
vandebo@chromium.org | 6112c21 | 2011-05-13 03:50:38 +0000 | [diff] [blame] | 1554 | init(); |
reed@google.com | fc641d0 | 2012-09-20 17:52:20 +0000 | [diff] [blame] | 1555 | return xobject; |
vandebo@chromium.org | 6112c21 | 2011-05-13 03:50:38 +0000 | [diff] [blame] | 1556 | } |
| 1557 | |
vandebo@chromium.org | 466f3d6 | 2011-05-18 23:06:29 +0000 | [diff] [blame] | 1558 | void SkPDFDevice::clearClipFromContent(const SkClipStack* clipStack, |
| 1559 | const SkRegion& clipRegion) { |
vandebo@chromium.org | 481aef6 | 2011-05-24 16:39:05 +0000 | [diff] [blame] | 1560 | if (clipRegion.isEmpty() || isContentEmpty()) { |
| 1561 | return; |
| 1562 | } |
reed@google.com | fc641d0 | 2012-09-20 17:52:20 +0000 | [diff] [blame] | 1563 | SkAutoTUnref<SkPDFFormXObject> curContent(createFormXObjectFromDevice()); |
vandebo@chromium.org | 466f3d6 | 2011-05-18 23:06:29 +0000 | [diff] [blame] | 1564 | |
vandebo@chromium.org | 481aef6 | 2011-05-24 16:39:05 +0000 | [diff] [blame] | 1565 | // Redraw what we already had, but with the clip as a mask. |
reed@google.com | fc641d0 | 2012-09-20 17:52:20 +0000 | [diff] [blame] | 1566 | drawFormXObjectWithClip(curContent, clipStack, clipRegion, true); |
vandebo@chromium.org | 481aef6 | 2011-05-24 16:39:05 +0000 | [diff] [blame] | 1567 | } |
| 1568 | |
| 1569 | void SkPDFDevice::drawFormXObjectWithClip(SkPDFFormXObject* xobject, |
| 1570 | const SkClipStack* clipStack, |
| 1571 | const SkRegion& clipRegion, |
| 1572 | bool invertClip) { |
| 1573 | if (clipRegion.isEmpty() && !invertClip) { |
| 1574 | return; |
| 1575 | } |
| 1576 | |
vandebo@chromium.org | 466f3d6 | 2011-05-18 23:06:29 +0000 | [diff] [blame] | 1577 | // Create the mask. |
| 1578 | SkMatrix identity; |
| 1579 | identity.reset(); |
| 1580 | SkDraw draw; |
| 1581 | draw.fMatrix = &identity; |
| 1582 | draw.fClip = &clipRegion; |
| 1583 | draw.fClipStack = clipStack; |
| 1584 | SkPaint stockPaint; |
| 1585 | this->drawPaint(draw, stockPaint); |
reed@google.com | fc641d0 | 2012-09-20 17:52:20 +0000 | [diff] [blame] | 1586 | SkAutoTUnref<SkPDFFormXObject> maskFormXObject(createFormXObjectFromDevice()); |
vandebo@chromium.org | d96d17b | 2013-01-04 19:31:24 +0000 | [diff] [blame] | 1587 | SkAutoTUnref<SkPDFGraphicState> sMaskGS( |
commit-bot@chromium.org | 93a2e21 | 2013-07-23 23:16:03 +0000 | [diff] [blame] | 1588 | SkPDFGraphicState::GetSMaskGraphicState(maskFormXObject, invertClip, |
| 1589 | SkPDFGraphicState::kAlpha_SMaskMode)); |
vandebo@chromium.org | 466f3d6 | 2011-05-18 23:06:29 +0000 | [diff] [blame] | 1590 | |
vandebo@chromium.org | 481aef6 | 2011-05-24 16:39:05 +0000 | [diff] [blame] | 1591 | // Draw the xobject with the clip as a mask. |
vandebo@chromium.org | 13d14a9 | 2011-05-24 23:12:41 +0000 | [diff] [blame] | 1592 | ScopedContentEntry content(this, &fExistingClipStack, fExistingClipRegion, |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 1593 | identity, stockPaint); |
| 1594 | if (!content.entry()) { |
| 1595 | return; |
| 1596 | } |
vandebo@chromium.org | 466f3d6 | 2011-05-18 23:06:29 +0000 | [diff] [blame] | 1597 | SkPDFUtils::ApplyGraphicState(addGraphicStateResource(sMaskGS.get()), |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 1598 | &content.entry()->fContent); |
vandebo@chromium.org | 466f3d6 | 2011-05-18 23:06:29 +0000 | [diff] [blame] | 1599 | SkPDFUtils::DrawFormXObject(fXObjectResources.count(), |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 1600 | &content.entry()->fContent); |
vandebo@chromium.org | 481aef6 | 2011-05-24 16:39:05 +0000 | [diff] [blame] | 1601 | fXObjectResources.push(xobject); |
| 1602 | xobject->ref(); |
vandebo@chromium.org | 466f3d6 | 2011-05-18 23:06:29 +0000 | [diff] [blame] | 1603 | |
vandebo@chromium.org | d96d17b | 2013-01-04 19:31:24 +0000 | [diff] [blame] | 1604 | sMaskGS.reset(SkPDFGraphicState::GetNoSMaskGraphicState()); |
vandebo@chromium.org | 466f3d6 | 2011-05-18 23:06:29 +0000 | [diff] [blame] | 1605 | SkPDFUtils::ApplyGraphicState(addGraphicStateResource(sMaskGS.get()), |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 1606 | &content.entry()->fContent); |
vandebo@chromium.org | 466f3d6 | 2011-05-18 23:06:29 +0000 | [diff] [blame] | 1607 | } |
| 1608 | |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 1609 | ContentEntry* SkPDFDevice::setUpContentEntry(const SkClipStack* clipStack, |
| 1610 | const SkRegion& clipRegion, |
| 1611 | const SkMatrix& matrix, |
| 1612 | const SkPaint& paint, |
| 1613 | bool hasText, |
reed@google.com | fc641d0 | 2012-09-20 17:52:20 +0000 | [diff] [blame] | 1614 | SkPDFFormXObject** dst) { |
| 1615 | *dst = NULL; |
vandebo@chromium.org | 25adce8 | 2011-05-09 08:05:01 +0000 | [diff] [blame] | 1616 | if (clipRegion.isEmpty()) { |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 1617 | return NULL; |
vandebo@chromium.org | 25adce8 | 2011-05-09 08:05:01 +0000 | [diff] [blame] | 1618 | } |
| 1619 | |
vandebo@chromium.org | 78dad54 | 2011-05-11 18:46:03 +0000 | [diff] [blame] | 1620 | // The clip stack can come from an SkDraw where it is technically optional. |
| 1621 | SkClipStack synthesizedClipStack; |
| 1622 | if (clipStack == NULL) { |
| 1623 | if (clipRegion == fExistingClipRegion) { |
| 1624 | clipStack = &fExistingClipStack; |
| 1625 | } else { |
| 1626 | // GraphicStackState::updateClip expects the clip stack to have |
| 1627 | // fExistingClip as a prefix, so start there, then set the clip |
| 1628 | // to the passed region. |
| 1629 | synthesizedClipStack = fExistingClipStack; |
| 1630 | SkPath clipPath; |
| 1631 | clipRegion.getBoundaryPath(&clipPath); |
reed@google.com | 0017708 | 2011-10-12 14:34:30 +0000 | [diff] [blame] | 1632 | synthesizedClipStack.clipDevPath(clipPath, SkRegion::kReplace_Op, |
| 1633 | false); |
vandebo@chromium.org | 78dad54 | 2011-05-11 18:46:03 +0000 | [diff] [blame] | 1634 | clipStack = &synthesizedClipStack; |
| 1635 | } |
| 1636 | } |
| 1637 | |
vandebo@chromium.org | 25adce8 | 2011-05-09 08:05:01 +0000 | [diff] [blame] | 1638 | SkXfermode::Mode xfermode = SkXfermode::kSrcOver_Mode; |
| 1639 | if (paint.getXfermode()) { |
| 1640 | paint.getXfermode()->asMode(&xfermode); |
| 1641 | } |
| 1642 | |
vandebo@chromium.org | 25adce8 | 2011-05-09 08:05:01 +0000 | [diff] [blame] | 1643 | if (xfermode == SkXfermode::kClear_Mode || |
| 1644 | xfermode == SkXfermode::kSrc_Mode) { |
vandebo@chromium.org | 466f3d6 | 2011-05-18 23:06:29 +0000 | [diff] [blame] | 1645 | this->clearClipFromContent(clipStack, clipRegion); |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 1646 | } else if (xfermode == SkXfermode::kSrcIn_Mode || |
| 1647 | xfermode == SkXfermode::kDstIn_Mode || |
| 1648 | xfermode == SkXfermode::kSrcOut_Mode || |
| 1649 | xfermode == SkXfermode::kDstOut_Mode) { |
| 1650 | // For the following modes, we use both source and destination, but |
| 1651 | // we use one as a smask for the other, so we have to make form xobjects |
| 1652 | // out of both of them: SrcIn, DstIn, SrcOut, DstOut. |
vandebo@chromium.org | 481aef6 | 2011-05-24 16:39:05 +0000 | [diff] [blame] | 1653 | if (isContentEmpty()) { |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 1654 | return NULL; |
vandebo@chromium.org | 481aef6 | 2011-05-24 16:39:05 +0000 | [diff] [blame] | 1655 | } else { |
reed@google.com | fc641d0 | 2012-09-20 17:52:20 +0000 | [diff] [blame] | 1656 | *dst = createFormXObjectFromDevice(); |
vandebo@chromium.org | 481aef6 | 2011-05-24 16:39:05 +0000 | [diff] [blame] | 1657 | } |
vandebo@chromium.org | 6112c21 | 2011-05-13 03:50:38 +0000 | [diff] [blame] | 1658 | } |
ctguil@chromium.org | 769fa6a | 2011-08-20 00:36:18 +0000 | [diff] [blame] | 1659 | // TODO(vandebo): Figure out how/if we can handle the following modes: |
vandebo@chromium.org | 481aef6 | 2011-05-24 16:39:05 +0000 | [diff] [blame] | 1660 | // SrcAtop, DestAtop, Xor, Plus. |
vandebo@chromium.org | 25adce8 | 2011-05-09 08:05:01 +0000 | [diff] [blame] | 1661 | |
| 1662 | // These xfer modes don't draw source at all. |
| 1663 | if (xfermode == SkXfermode::kClear_Mode || |
| 1664 | xfermode == SkXfermode::kDst_Mode) { |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 1665 | return NULL; |
vandebo@chromium.org | 25adce8 | 2011-05-09 08:05:01 +0000 | [diff] [blame] | 1666 | } |
| 1667 | |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 1668 | ContentEntry* entry; |
commit-bot@chromium.org | e029440 | 2013-08-29 22:14:04 +0000 | [diff] [blame] | 1669 | SkAutoTDelete<ContentEntry> newEntry; |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 1670 | |
| 1671 | ContentEntry* lastContentEntry = getLastContentEntry(); |
| 1672 | if (lastContentEntry && lastContentEntry->fContent.getOffset() == 0) { |
| 1673 | entry = lastContentEntry; |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 1674 | } else { |
| 1675 | newEntry.reset(new ContentEntry); |
| 1676 | entry = newEntry.get(); |
| 1677 | } |
| 1678 | |
vandebo@chromium.org | 78dad54 | 2011-05-11 18:46:03 +0000 | [diff] [blame] | 1679 | populateGraphicStateEntryFromPaint(matrix, *clipStack, clipRegion, paint, |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 1680 | hasText, &entry->fState); |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 1681 | if (lastContentEntry && xfermode != SkXfermode::kDstOver_Mode && |
| 1682 | entry->fState.compareInitialState(lastContentEntry->fState)) { |
| 1683 | return lastContentEntry; |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 1684 | } |
| 1685 | |
commit-bot@chromium.org | e029440 | 2013-08-29 22:14:04 +0000 | [diff] [blame] | 1686 | SkAutoTDelete<ContentEntry>* contentEntries = getContentEntries(); |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 1687 | if (!lastContentEntry) { |
ctguil@chromium.org | 9510ccc | 2011-07-27 00:10:51 +0000 | [diff] [blame] | 1688 | contentEntries->reset(entry); |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 1689 | setLastContentEntry(entry); |
vandebo@chromium.org | 25adce8 | 2011-05-09 08:05:01 +0000 | [diff] [blame] | 1690 | } else if (xfermode == SkXfermode::kDstOver_Mode) { |
commit-bot@chromium.org | e029440 | 2013-08-29 22:14:04 +0000 | [diff] [blame] | 1691 | entry->fNext.reset(contentEntries->detach()); |
ctguil@chromium.org | 9510ccc | 2011-07-27 00:10:51 +0000 | [diff] [blame] | 1692 | contentEntries->reset(entry); |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 1693 | } else { |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 1694 | lastContentEntry->fNext.reset(entry); |
| 1695 | setLastContentEntry(entry); |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 1696 | } |
commit-bot@chromium.org | e029440 | 2013-08-29 22:14:04 +0000 | [diff] [blame] | 1697 | newEntry.detach(); |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 1698 | return entry; |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 1699 | } |
| 1700 | |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 1701 | void SkPDFDevice::finishContentEntry(const SkXfermode::Mode xfermode, |
| 1702 | SkPDFFormXObject* dst) { |
vandebo@chromium.org | 6112c21 | 2011-05-13 03:50:38 +0000 | [diff] [blame] | 1703 | if (xfermode != SkXfermode::kSrcIn_Mode && |
| 1704 | xfermode != SkXfermode::kDstIn_Mode && |
| 1705 | xfermode != SkXfermode::kSrcOut_Mode && |
| 1706 | xfermode != SkXfermode::kDstOut_Mode) { |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 1707 | SkASSERT(!dst); |
vandebo@chromium.org | 6112c21 | 2011-05-13 03:50:38 +0000 | [diff] [blame] | 1708 | return; |
| 1709 | } |
ctguil@chromium.org | 9510ccc | 2011-07-27 00:10:51 +0000 | [diff] [blame] | 1710 | |
| 1711 | ContentEntry* contentEntries = getContentEntries()->get(); |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 1712 | SkASSERT(dst); |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 1713 | SkASSERT(!contentEntries->fNext.get()); |
vandebo@chromium.org | 481aef6 | 2011-05-24 16:39:05 +0000 | [diff] [blame] | 1714 | // We have to make a copy of these here because changing the current |
| 1715 | // content into a form xobject will destroy them. |
ctguil@chromium.org | 8dcf74f | 2011-07-12 21:56:27 +0000 | [diff] [blame] | 1716 | SkClipStack clipStack = contentEntries->fState.fClipStack; |
| 1717 | SkRegion clipRegion = contentEntries->fState.fClipRegion; |
vandebo@chromium.org | 481aef6 | 2011-05-24 16:39:05 +0000 | [diff] [blame] | 1718 | |
reed@google.com | fc641d0 | 2012-09-20 17:52:20 +0000 | [diff] [blame] | 1719 | SkAutoTUnref<SkPDFFormXObject> srcFormXObject; |
vandebo@chromium.org | 481aef6 | 2011-05-24 16:39:05 +0000 | [diff] [blame] | 1720 | if (!isContentEmpty()) { |
reed@google.com | fc641d0 | 2012-09-20 17:52:20 +0000 | [diff] [blame] | 1721 | srcFormXObject.reset(createFormXObjectFromDevice()); |
vandebo@chromium.org | 481aef6 | 2011-05-24 16:39:05 +0000 | [diff] [blame] | 1722 | } |
| 1723 | |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 1724 | drawFormXObjectWithClip(dst, &clipStack, clipRegion, true); |
vandebo@chromium.org | 481aef6 | 2011-05-24 16:39:05 +0000 | [diff] [blame] | 1725 | |
| 1726 | // We've redrawn dst minus the clip area, if there's no src, we're done. |
| 1727 | if (!srcFormXObject.get()) { |
vandebo@chromium.org | 481aef6 | 2011-05-24 16:39:05 +0000 | [diff] [blame] | 1728 | return; |
| 1729 | } |
vandebo@chromium.org | 6112c21 | 2011-05-13 03:50:38 +0000 | [diff] [blame] | 1730 | |
| 1731 | SkMatrix identity; |
| 1732 | identity.reset(); |
| 1733 | SkPaint stockPaint; |
vandebo@chromium.org | 13d14a9 | 2011-05-24 23:12:41 +0000 | [diff] [blame] | 1734 | ScopedContentEntry inClipContentEntry(this, &fExistingClipStack, |
| 1735 | fExistingClipRegion, identity, |
| 1736 | stockPaint); |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 1737 | if (!inClipContentEntry.entry()) { |
| 1738 | return; |
| 1739 | } |
vandebo@chromium.org | 6112c21 | 2011-05-13 03:50:38 +0000 | [diff] [blame] | 1740 | |
vandebo@chromium.org | d96d17b | 2013-01-04 19:31:24 +0000 | [diff] [blame] | 1741 | SkAutoTUnref<SkPDFGraphicState> sMaskGS; |
vandebo@chromium.org | 6112c21 | 2011-05-13 03:50:38 +0000 | [diff] [blame] | 1742 | if (xfermode == SkXfermode::kSrcIn_Mode || |
| 1743 | xfermode == SkXfermode::kSrcOut_Mode) { |
vandebo@chromium.org | d96d17b | 2013-01-04 19:31:24 +0000 | [diff] [blame] | 1744 | sMaskGS.reset(SkPDFGraphicState::GetSMaskGraphicState( |
commit-bot@chromium.org | 93a2e21 | 2013-07-23 23:16:03 +0000 | [diff] [blame] | 1745 | dst, |
| 1746 | xfermode == SkXfermode::kSrcOut_Mode, |
| 1747 | SkPDFGraphicState::kAlpha_SMaskMode)); |
vandebo@chromium.org | 6112c21 | 2011-05-13 03:50:38 +0000 | [diff] [blame] | 1748 | fXObjectResources.push(srcFormXObject.get()); |
reed@google.com | fc641d0 | 2012-09-20 17:52:20 +0000 | [diff] [blame] | 1749 | srcFormXObject.get()->ref(); |
vandebo@chromium.org | 6112c21 | 2011-05-13 03:50:38 +0000 | [diff] [blame] | 1750 | } else { |
vandebo@chromium.org | d96d17b | 2013-01-04 19:31:24 +0000 | [diff] [blame] | 1751 | sMaskGS.reset(SkPDFGraphicState::GetSMaskGraphicState( |
commit-bot@chromium.org | 93a2e21 | 2013-07-23 23:16:03 +0000 | [diff] [blame] | 1752 | srcFormXObject.get(), |
| 1753 | xfermode == SkXfermode::kDstOut_Mode, |
| 1754 | SkPDFGraphicState::kAlpha_SMaskMode)); |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 1755 | // dst already added to fXObjectResources in drawFormXObjectWithClip. |
vandebo@chromium.org | 6112c21 | 2011-05-13 03:50:38 +0000 | [diff] [blame] | 1756 | } |
vandebo@chromium.org | 6112c21 | 2011-05-13 03:50:38 +0000 | [diff] [blame] | 1757 | SkPDFUtils::ApplyGraphicState(addGraphicStateResource(sMaskGS.get()), |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 1758 | &inClipContentEntry.entry()->fContent); |
vandebo@chromium.org | 6112c21 | 2011-05-13 03:50:38 +0000 | [diff] [blame] | 1759 | |
| 1760 | SkPDFUtils::DrawFormXObject(fXObjectResources.count() - 1, |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 1761 | &inClipContentEntry.entry()->fContent); |
vandebo@chromium.org | 6112c21 | 2011-05-13 03:50:38 +0000 | [diff] [blame] | 1762 | |
vandebo@chromium.org | d96d17b | 2013-01-04 19:31:24 +0000 | [diff] [blame] | 1763 | sMaskGS.reset(SkPDFGraphicState::GetNoSMaskGraphicState()); |
vandebo@chromium.org | 6112c21 | 2011-05-13 03:50:38 +0000 | [diff] [blame] | 1764 | SkPDFUtils::ApplyGraphicState(addGraphicStateResource(sMaskGS.get()), |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 1765 | &inClipContentEntry.entry()->fContent); |
vandebo@chromium.org | 6112c21 | 2011-05-13 03:50:38 +0000 | [diff] [blame] | 1766 | } |
| 1767 | |
vandebo@chromium.org | 481aef6 | 2011-05-24 16:39:05 +0000 | [diff] [blame] | 1768 | bool SkPDFDevice::isContentEmpty() { |
ctguil@chromium.org | 9510ccc | 2011-07-27 00:10:51 +0000 | [diff] [blame] | 1769 | ContentEntry* contentEntries = getContentEntries()->get(); |
| 1770 | if (!contentEntries || contentEntries->fContent.getOffset() == 0) { |
| 1771 | SkASSERT(!contentEntries || !contentEntries->fNext.get()); |
vandebo@chromium.org | 481aef6 | 2011-05-24 16:39:05 +0000 | [diff] [blame] | 1772 | return true; |
| 1773 | } |
| 1774 | return false; |
| 1775 | } |
| 1776 | |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 1777 | void SkPDFDevice::populateGraphicStateEntryFromPaint( |
| 1778 | const SkMatrix& matrix, |
| 1779 | const SkClipStack& clipStack, |
| 1780 | const SkRegion& clipRegion, |
| 1781 | const SkPaint& paint, |
| 1782 | bool hasText, |
| 1783 | GraphicStateEntry* entry) { |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 1784 | SkASSERT(paint.getPathEffect() == NULL); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 1785 | |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 1786 | NOT_IMPLEMENTED(paint.getMaskFilter() != NULL, false); |
| 1787 | NOT_IMPLEMENTED(paint.getColorFilter() != NULL, false); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 1788 | |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 1789 | entry->fMatrix = matrix; |
| 1790 | entry->fClipStack = clipStack; |
| 1791 | entry->fClipRegion = clipRegion; |
vandebo@chromium.org | da6c569 | 2012-06-28 21:37:20 +0000 | [diff] [blame] | 1792 | entry->fColor = SkColorSetA(paint.getColor(), 0xFF); |
| 1793 | entry->fShaderIndex = -1; |
vandebo@chromium.org | 4854327 | 2011-02-08 19:28:07 +0000 | [diff] [blame] | 1794 | |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 1795 | // PDF treats a shader as a color, so we only set one or the other. |
vandebo@chromium.org | d96d17b | 2013-01-04 19:31:24 +0000 | [diff] [blame] | 1796 | SkAutoTUnref<SkPDFObject> pdfShader; |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 1797 | const SkShader* shader = paint.getShader(); |
| 1798 | SkColor color = paint.getColor(); |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 1799 | if (shader) { |
| 1800 | // PDF positions patterns relative to the initial transform, so |
| 1801 | // we need to apply the current transform to the shader parameters. |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 1802 | SkMatrix transform = matrix; |
vandebo@chromium.org | 75f97e4 | 2011-04-11 23:24:18 +0000 | [diff] [blame] | 1803 | transform.postConcat(fInitialTransform); |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 1804 | |
| 1805 | // PDF doesn't support kClamp_TileMode, so we simulate it by making |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 1806 | // a pattern the size of the current clip. |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 1807 | SkIRect bounds = clipRegion.getBounds(); |
vandebo@chromium.org | 293a758 | 2012-03-16 19:50:37 +0000 | [diff] [blame] | 1808 | |
| 1809 | // We need to apply the initial transform to bounds in order to get |
| 1810 | // bounds in a consistent coordinate system. |
| 1811 | SkRect boundsTemp; |
| 1812 | boundsTemp.set(bounds); |
| 1813 | fInitialTransform.mapRect(&boundsTemp); |
| 1814 | boundsTemp.roundOut(&bounds); |
| 1815 | |
vandebo@chromium.org | d96d17b | 2013-01-04 19:31:24 +0000 | [diff] [blame] | 1816 | pdfShader.reset(SkPDFShader::GetPDFShader(*shader, transform, bounds)); |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 1817 | |
vandebo@chromium.org | b88cfe5 | 2011-07-18 18:40:32 +0000 | [diff] [blame] | 1818 | if (pdfShader.get()) { |
| 1819 | // pdfShader has been canonicalized so we can directly compare |
| 1820 | // pointers. |
| 1821 | int resourceIndex = fShaderResources.find(pdfShader.get()); |
| 1822 | if (resourceIndex < 0) { |
| 1823 | resourceIndex = fShaderResources.count(); |
| 1824 | fShaderResources.push(pdfShader.get()); |
vandebo@chromium.org | d96d17b | 2013-01-04 19:31:24 +0000 | [diff] [blame] | 1825 | pdfShader.get()->ref(); |
vandebo@chromium.org | b88cfe5 | 2011-07-18 18:40:32 +0000 | [diff] [blame] | 1826 | } |
| 1827 | entry->fShaderIndex = resourceIndex; |
| 1828 | } else { |
| 1829 | // A color shader is treated as an invalid shader so we don't have |
| 1830 | // to set a shader just for a color. |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 1831 | SkShader::GradientInfo gradientInfo; |
| 1832 | SkColor gradientColor; |
| 1833 | gradientInfo.fColors = &gradientColor; |
| 1834 | gradientInfo.fColorOffsets = NULL; |
| 1835 | gradientInfo.fColorCount = 1; |
| 1836 | if (shader->asAGradient(&gradientInfo) == |
| 1837 | SkShader::kColor_GradientType) { |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 1838 | entry->fColor = SkColorSetA(gradientColor, 0xFF); |
| 1839 | color = gradientColor; |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 1840 | } |
| 1841 | } |
vandebo@chromium.org | da912d6 | 2011-03-08 18:31:02 +0000 | [diff] [blame] | 1842 | } |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 1843 | |
vandebo@chromium.org | d96d17b | 2013-01-04 19:31:24 +0000 | [diff] [blame] | 1844 | SkAutoTUnref<SkPDFGraphicState> newGraphicState; |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 1845 | if (color == paint.getColor()) { |
vandebo@chromium.org | d96d17b | 2013-01-04 19:31:24 +0000 | [diff] [blame] | 1846 | newGraphicState.reset( |
| 1847 | SkPDFGraphicState::GetGraphicStateForPaint(paint)); |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 1848 | } else { |
| 1849 | SkPaint newPaint = paint; |
| 1850 | newPaint.setColor(color); |
vandebo@chromium.org | d96d17b | 2013-01-04 19:31:24 +0000 | [diff] [blame] | 1851 | newGraphicState.reset( |
| 1852 | SkPDFGraphicState::GetGraphicStateForPaint(newPaint)); |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 1853 | } |
vandebo@chromium.org | 6112c21 | 2011-05-13 03:50:38 +0000 | [diff] [blame] | 1854 | int resourceIndex = addGraphicStateResource(newGraphicState.get()); |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 1855 | entry->fGraphicStateIndex = resourceIndex; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 1856 | |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 1857 | if (hasText) { |
| 1858 | entry->fTextScaleX = paint.getTextScaleX(); |
| 1859 | entry->fTextFill = paint.getStyle(); |
| 1860 | } else { |
| 1861 | entry->fTextScaleX = 0; |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 1862 | } |
| 1863 | } |
| 1864 | |
vandebo@chromium.org | 6112c21 | 2011-05-13 03:50:38 +0000 | [diff] [blame] | 1865 | int SkPDFDevice::addGraphicStateResource(SkPDFGraphicState* gs) { |
| 1866 | // Assumes that gs has been canonicalized (so we can directly compare |
| 1867 | // pointers). |
| 1868 | int result = fGraphicStateResources.find(gs); |
| 1869 | if (result < 0) { |
| 1870 | result = fGraphicStateResources.count(); |
| 1871 | fGraphicStateResources.push(gs); |
| 1872 | gs->ref(); |
| 1873 | } |
| 1874 | return result; |
| 1875 | } |
| 1876 | |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 1877 | void SkPDFDevice::updateFont(const SkPaint& paint, uint16_t glyphID, |
| 1878 | ContentEntry* contentEntry) { |
ctguil@chromium.org | 9db86bb | 2011-03-04 21:43:27 +0000 | [diff] [blame] | 1879 | SkTypeface* typeface = paint.getTypeface(); |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 1880 | if (contentEntry->fState.fFont == NULL || |
| 1881 | contentEntry->fState.fTextSize != paint.getTextSize() || |
| 1882 | !contentEntry->fState.fFont->hasGlyph(glyphID)) { |
ctguil@chromium.org | 9db86bb | 2011-03-04 21:43:27 +0000 | [diff] [blame] | 1883 | int fontIndex = getFontResourceIndex(typeface, glyphID); |
commit-bot@chromium.org | 4740135 | 2013-07-23 21:49:29 +0000 | [diff] [blame] | 1884 | contentEntry->fContent.writeText("/"); |
| 1885 | contentEntry->fContent.writeText(SkPDFResourceDict::getResourceName( |
| 1886 | SkPDFResourceDict::kFont_ResourceType, |
| 1887 | fontIndex).c_str()); |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 1888 | contentEntry->fContent.writeText(" "); |
| 1889 | SkPDFScalar::Append(paint.getTextSize(), &contentEntry->fContent); |
| 1890 | contentEntry->fContent.writeText(" Tf\n"); |
| 1891 | contentEntry->fState.fFont = fFontResources[fontIndex]; |
vandebo@chromium.org | 2a22e10 | 2011-01-25 21:01:34 +0000 | [diff] [blame] | 1892 | } |
| 1893 | } |
| 1894 | |
ctguil@chromium.org | 9db86bb | 2011-03-04 21:43:27 +0000 | [diff] [blame] | 1895 | int SkPDFDevice::getFontResourceIndex(SkTypeface* typeface, uint16_t glyphID) { |
vandebo@chromium.org | d96d17b | 2013-01-04 19:31:24 +0000 | [diff] [blame] | 1896 | SkAutoTUnref<SkPDFFont> newFont(SkPDFFont::GetFontResource(typeface, glyphID)); |
vandebo@chromium.org | 28be72b | 2010-11-11 21:37:00 +0000 | [diff] [blame] | 1897 | int resourceIndex = fFontResources.find(newFont.get()); |
| 1898 | if (resourceIndex < 0) { |
| 1899 | resourceIndex = fFontResources.count(); |
| 1900 | fFontResources.push(newFont.get()); |
vandebo@chromium.org | d96d17b | 2013-01-04 19:31:24 +0000 | [diff] [blame] | 1901 | newFont.get()->ref(); |
vandebo@chromium.org | 28be72b | 2010-11-11 21:37:00 +0000 | [diff] [blame] | 1902 | } |
| 1903 | return resourceIndex; |
| 1904 | } |
| 1905 | |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 1906 | void SkPDFDevice::internalDrawBitmap(const SkMatrix& matrix, |
vandebo@chromium.org | 78dad54 | 2011-05-11 18:46:03 +0000 | [diff] [blame] | 1907 | const SkClipStack* clipStack, |
vandebo@chromium.org | 9fbdf87 | 2011-05-09 07:55:58 +0000 | [diff] [blame] | 1908 | const SkRegion& clipRegion, |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 1909 | const SkBitmap& bitmap, |
vandebo@chromium.org | befebb8 | 2011-01-29 01:38:50 +0000 | [diff] [blame] | 1910 | const SkIRect* srcRect, |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 1911 | const SkPaint& paint) { |
vandebo@chromium.org | 7e2ff7c | 2010-11-03 23:55:28 +0000 | [diff] [blame] | 1912 | SkMatrix scaled; |
| 1913 | // Adjust for origin flip. |
vandebo@chromium.org | 663515b | 2012-01-05 18:45:27 +0000 | [diff] [blame] | 1914 | scaled.setScale(SK_Scalar1, -SK_Scalar1); |
| 1915 | scaled.postTranslate(0, SK_Scalar1); |
vandebo@chromium.org | 7e2ff7c | 2010-11-03 23:55:28 +0000 | [diff] [blame] | 1916 | // Scale the image up from 1x1 to WxH. |
vandebo@chromium.org | 25adce8 | 2011-05-09 08:05:01 +0000 | [diff] [blame] | 1917 | SkIRect subset = SkIRect::MakeWH(bitmap.width(), bitmap.height()); |
reed@google.com | a6d59f6 | 2011-03-07 21:29:21 +0000 | [diff] [blame] | 1918 | scaled.postScale(SkIntToScalar(subset.width()), |
| 1919 | SkIntToScalar(subset.height())); |
vandebo@chromium.org | 7e2ff7c | 2010-11-03 23:55:28 +0000 | [diff] [blame] | 1920 | scaled.postConcat(matrix); |
vandebo@chromium.org | 13d14a9 | 2011-05-24 23:12:41 +0000 | [diff] [blame] | 1921 | ScopedContentEntry content(this, clipStack, clipRegion, scaled, paint); |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 1922 | if (!content.entry()) { |
vandebo@chromium.org | 25adce8 | 2011-05-09 08:05:01 +0000 | [diff] [blame] | 1923 | return; |
| 1924 | } |
| 1925 | |
| 1926 | if (srcRect && !subset.intersect(*srcRect)) { |
| 1927 | return; |
| 1928 | } |
| 1929 | |
edisonn@google.com | d9dfa18 | 2013-04-24 13:01:01 +0000 | [diff] [blame] | 1930 | SkPDFImage* image = SkPDFImage::CreateImage(bitmap, subset, fEncoder); |
vandebo@chromium.org | 25adce8 | 2011-05-09 08:05:01 +0000 | [diff] [blame] | 1931 | if (!image) { |
| 1932 | return; |
| 1933 | } |
vandebo@chromium.org | 7e2ff7c | 2010-11-03 23:55:28 +0000 | [diff] [blame] | 1934 | |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 1935 | fXObjectResources.push(image); // Transfer reference. |
vandebo@chromium.org | 6112c21 | 2011-05-13 03:50:38 +0000 | [diff] [blame] | 1936 | SkPDFUtils::DrawFormXObject(fXObjectResources.count() - 1, |
vandebo@chromium.org | b069c8c | 2011-05-24 17:19:38 +0000 | [diff] [blame] | 1937 | &content.entry()->fContent); |
vandebo@chromium.org | 9b49dc0 | 2010-10-20 22:23:29 +0000 | [diff] [blame] | 1938 | } |
reed@google.com | 982cb87 | 2011-12-07 18:34:08 +0000 | [diff] [blame] | 1939 | |
| 1940 | bool SkPDFDevice::onReadPixels(const SkBitmap& bitmap, int x, int y, |
| 1941 | SkCanvas::Config8888) { |
| 1942 | return false; |
| 1943 | } |
reed@google.com | b55deeb | 2012-01-06 14:43:09 +0000 | [diff] [blame] | 1944 | |
| 1945 | bool SkPDFDevice::allowImageFilter(SkImageFilter*) { |
| 1946 | return false; |
| 1947 | } |