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 "SkData.h" |
9 #include "SkOncePtr.h" | 9 #include "SkOncePtr.h" |
10 #include "SkPDFCanon.h" | 10 #include "SkPDFCanon.h" |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 // since the emitObject() interface is non-const. But We | 119 // since the emitObject() interface is non-const. But We |
120 // promise that there is no way to mutate this object from | 120 // promise that there is no way to mutate this object from |
121 // here on out. | 121 // here on out. |
122 return SkRef(const_cast<SkPDFGraphicState*>(canonGS)); | 122 return SkRef(const_cast<SkPDFGraphicState*>(canonGS)); |
123 } | 123 } |
124 SkPDFGraphicState* pdfGraphicState = new SkPDFGraphicState(paint); | 124 SkPDFGraphicState* pdfGraphicState = new SkPDFGraphicState(paint); |
125 canon->addGraphicState(pdfGraphicState); | 125 canon->addGraphicState(pdfGraphicState); |
126 return pdfGraphicState; | 126 return pdfGraphicState; |
127 } | 127 } |
128 | 128 |
129 static SkPDFObject* create_invert_function() { | 129 static SkPDFStream* create_invert_function() { |
130 // Acrobat crashes if we use a type 0 function, kpdf crashes if we use | 130 // Acrobat crashes if we use a type 0 function, kpdf crashes if we use |
131 // a type 2 function, so we use a type 4 function. | 131 // a type 2 function, so we use a type 4 function. |
132 auto domainAndRange = sk_make_sp<SkPDFArray>(); | 132 auto domainAndRange = sk_make_sp<SkPDFArray>(); |
133 domainAndRange->reserve(2); | 133 domainAndRange->reserve(2); |
134 domainAndRange->appendInt(0); | 134 domainAndRange->appendInt(0); |
135 domainAndRange->appendInt(1); | 135 domainAndRange->appendInt(1); |
136 | 136 |
137 static const char psInvert[] = "{1 exch sub}"; | 137 static const char psInvert[] = "{1 exch sub}"; |
138 // Do not copy the trailing '\0' into the SkData. | 138 // Do not copy the trailing '\0' into the SkData. |
139 sk_sp<SkData> psInvertStream( | 139 sk_sp<SkData> psInvertStream( |
140 SkData::NewWithoutCopy(psInvert, strlen(psInvert))); | 140 SkData::NewWithoutCopy(psInvert, strlen(psInvert))); |
141 | 141 |
142 auto invertFunction = sk_make_sp<SkPDFStream>(psInvertStream.get()); | 142 auto invertFunction = sk_make_sp<SkPDFStream>(psInvertStream.get()); |
143 invertFunction->insertInt("FunctionType", 4); | 143 invertFunction->insertInt("FunctionType", 4); |
144 invertFunction->insertObject("Domain", SkRef(domainAndRange.get())); | 144 invertFunction->insertObject("Domain", domainAndRange); |
145 invertFunction->insertObject("Range", domainAndRange.release()); | 145 invertFunction->insertObject("Range", std::move(domainAndRange)); |
146 return invertFunction.release(); | 146 return invertFunction.release(); |
147 } | 147 } |
148 | 148 |
149 SK_DECLARE_STATIC_ONCE_PTR(SkPDFObject, invertFunction); | 149 SK_DECLARE_STATIC_ONCE_PTR(SkPDFStream, invertFunction); |
| 150 |
| 151 static sk_sp<SkPDFStream> make_invert_function() { |
| 152 return sk_sp<SkPDFStream>( |
| 153 SkRef(invertFunction.get(create_invert_function))); |
| 154 } |
150 | 155 |
151 // static | 156 // static |
152 SkPDFDict* SkPDFGraphicState::GetSMaskGraphicState(SkPDFFormXObject* sMask, | 157 SkPDFDict* SkPDFGraphicState::GetSMaskGraphicState(SkPDFFormXObject* sMask, |
153 bool invert, | 158 bool invert, |
154 SkPDFSMaskMode sMaskMode) { | 159 SkPDFSMaskMode sMaskMode) { |
155 // The practical chances of using the same mask more than once are unlikely | 160 // The practical chances of using the same mask more than once are unlikely |
156 // enough that it's not worth canonicalizing. | 161 // enough that it's not worth canonicalizing. |
157 auto sMaskDict = sk_make_sp<SkPDFDict>("Mask"); | 162 auto sMaskDict = sk_make_sp<SkPDFDict>("Mask"); |
158 if (sMaskMode == kAlpha_SMaskMode) { | 163 if (sMaskMode == kAlpha_SMaskMode) { |
159 sMaskDict->insertName("S", "Alpha"); | 164 sMaskDict->insertName("S", "Alpha"); |
160 } else if (sMaskMode == kLuminosity_SMaskMode) { | 165 } else if (sMaskMode == kLuminosity_SMaskMode) { |
161 sMaskDict->insertName("S", "Luminosity"); | 166 sMaskDict->insertName("S", "Luminosity"); |
162 } | 167 } |
163 sMaskDict->insertObjRef("G", SkRef(sMask)); | 168 sMaskDict->insertObjRef("G", sk_sp<SkPDFFormXObject>(SkRef(sMask))); |
164 if (invert) { | 169 if (invert) { |
165 sMaskDict->insertObjRef("TR", SkRef(invertFunction.get(create_invert_fun
ction))); | 170 sMaskDict->insertObjRef("TR", make_invert_function()); |
166 } | 171 } |
167 | 172 |
168 auto result = sk_make_sp<SkPDFDict>("ExtGState"); | 173 auto result = sk_make_sp<SkPDFDict>("ExtGState"); |
169 result->insertObject("SMask", sMaskDict.release()); | 174 result->insertObject("SMask", std::move(sMaskDict)); |
170 return result.release(); | 175 return result.release(); |
171 } | 176 } |
172 | 177 |
173 static SkPDFDict* create_no_smask_graphic_state() { | 178 static SkPDFDict* create_no_smask_graphic_state() { |
174 SkPDFDict* noSMaskGS = new SkPDFDict("ExtGState"); | 179 SkPDFDict* noSMaskGS = new SkPDFDict("ExtGState"); |
175 noSMaskGS->insertName("SMask", "None"); | 180 noSMaskGS->insertName("SMask", "None"); |
176 return noSMaskGS; | 181 return noSMaskGS; |
177 } | 182 } |
178 SK_DECLARE_STATIC_ONCE_PTR(SkPDFDict, noSMaskGraphicState); | 183 SK_DECLARE_STATIC_ONCE_PTR(SkPDFDict, noSMaskGraphicState); |
179 | 184 |
(...skipping 30 matching lines...) Expand all Loading... |
210 static_assert(SkPaint::kJoinCount == 3, "paint_join_mismatch"); | 215 static_assert(SkPaint::kJoinCount == 3, "paint_join_mismatch"); |
211 SkASSERT(strokeJoin >= 0 && strokeJoin <= 2); | 216 SkASSERT(strokeJoin >= 0 && strokeJoin <= 2); |
212 dict->insertInt("LJ", strokeJoin); | 217 dict->insertInt("LJ", strokeJoin); |
213 | 218 |
214 dict->insertScalar("LW", fStrokeWidth); | 219 dict->insertScalar("LW", fStrokeWidth); |
215 dict->insertScalar("ML", fStrokeMiter); | 220 dict->insertScalar("ML", fStrokeMiter); |
216 dict->insertBool("SA", true); // SA = Auto stroke adjustment. | 221 dict->insertBool("SA", true); // SA = Auto stroke adjustment. |
217 dict->insertName("BM", as_blend_mode(xferMode)); | 222 dict->insertName("BM", as_blend_mode(xferMode)); |
218 dict->emitObject(stream, objNumMap, substitutes); | 223 dict->emitObject(stream, objNumMap, substitutes); |
219 } | 224 } |
OLD | NEW |