| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkData.h" |
| 8 #include "SkPDFFormXObject.h" | 9 #include "SkPDFFormXObject.h" |
| 9 #include "SkPDFGraphicState.h" | 10 #include "SkPDFGraphicState.h" |
| 10 #include "SkPDFUtils.h" | 11 #include "SkPDFUtils.h" |
| 11 #include "SkStream.h" | |
| 12 #include "SkTypes.h" | 12 #include "SkTypes.h" |
| 13 | 13 |
| 14 static const char* blend_mode_from_xfermode(SkXfermode::Mode mode) { | 14 static const char* blend_mode_from_xfermode(SkXfermode::Mode mode) { |
| 15 switch (mode) { | 15 switch (mode) { |
| 16 case SkXfermode::kSrcOver_Mode: return "Normal"; | 16 case SkXfermode::kSrcOver_Mode: return "Normal"; |
| 17 case SkXfermode::kMultiply_Mode: return "Multiply"; | 17 case SkXfermode::kMultiply_Mode: return "Multiply"; |
| 18 case SkXfermode::kScreen_Mode: return "Screen"; | 18 case SkXfermode::kScreen_Mode: return "Screen"; |
| 19 case SkXfermode::kOverlay_Mode: return "Overlay"; | 19 case SkXfermode::kOverlay_Mode: return "Overlay"; |
| 20 case SkXfermode::kDarken_Mode: return "Darken"; | 20 case SkXfermode::kDarken_Mode: return "Darken"; |
| 21 case SkXfermode::kLighten_Mode: return "Lighten"; | 21 case SkXfermode::kLighten_Mode: return "Lighten"; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 static SkPDFStream* invertFunction = NULL; | 114 static SkPDFStream* invertFunction = NULL; |
| 115 if (!invertFunction) { | 115 if (!invertFunction) { |
| 116 // Acrobat crashes if we use a type 0 function, kpdf crashes if we use | 116 // Acrobat crashes if we use a type 0 function, kpdf crashes if we use |
| 117 // a type 2 function, so we use a type 4 function. | 117 // a type 2 function, so we use a type 4 function. |
| 118 SkAutoTUnref<SkPDFArray> domainAndRange(new SkPDFArray); | 118 SkAutoTUnref<SkPDFArray> domainAndRange(new SkPDFArray); |
| 119 domainAndRange->reserve(2); | 119 domainAndRange->reserve(2); |
| 120 domainAndRange->appendInt(0); | 120 domainAndRange->appendInt(0); |
| 121 domainAndRange->appendInt(1); | 121 domainAndRange->appendInt(1); |
| 122 | 122 |
| 123 static const char psInvert[] = "{1 exch sub}"; | 123 static const char psInvert[] = "{1 exch sub}"; |
| 124 SkAutoTUnref<SkMemoryStream> psInvertStream( | 124 // Do not copy the trailing '\0' into the SkData. |
| 125 new SkMemoryStream(&psInvert, strlen(psInvert), true)); | 125 SkAutoTUnref<SkData> psInvertStream( |
| 126 SkData::NewWithCopy(psInvert, strlen(psInvert))); |
| 126 | 127 |
| 127 invertFunction = new SkPDFStream(psInvertStream.get()); | 128 invertFunction = new SkPDFStream(psInvertStream.get()); |
| 128 invertFunction->insertInt("FunctionType", 4); | 129 invertFunction->insertInt("FunctionType", 4); |
| 129 invertFunction->insert("Domain", domainAndRange.get()); | 130 invertFunction->insert("Domain", domainAndRange.get()); |
| 130 invertFunction->insert("Range", domainAndRange.get()); | 131 invertFunction->insert("Range", domainAndRange.get()); |
| 131 } | 132 } |
| 132 return invertFunction; | 133 return invertFunction; |
| 133 } | 134 } |
| 134 | 135 |
| 135 // static | 136 // static |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 } | 278 } |
| 278 if (bXfermodeName < 0 || bXfermodeName > SkXfermode::kLastMode || | 279 if (bXfermodeName < 0 || bXfermodeName > SkXfermode::kLastMode || |
| 279 blend_mode_from_xfermode(bXfermodeName) == NULL) { | 280 blend_mode_from_xfermode(bXfermodeName) == NULL) { |
| 280 bXfermodeName = SkXfermode::kSrcOver_Mode; | 281 bXfermodeName = SkXfermode::kSrcOver_Mode; |
| 281 } | 282 } |
| 282 const char* bXfermodeString = blend_mode_from_xfermode(bXfermodeName); | 283 const char* bXfermodeString = blend_mode_from_xfermode(bXfermodeName); |
| 283 SkASSERT(bXfermodeString != NULL); | 284 SkASSERT(bXfermodeString != NULL); |
| 284 | 285 |
| 285 return strcmp(aXfermodeString, bXfermodeString) == 0; | 286 return strcmp(aXfermodeString, bXfermodeString) == 0; |
| 286 } | 287 } |
| OLD | NEW |