Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: src/pdf/SkPDFGraphicState.cpp

Issue 1107923002: SkPDF: clean up uses of deprecated calls in other SkPDF classes (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-04-27 (Monday) 09:04:15 EDT Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pdf/SkPDFFormXObject.cpp ('k') | src/pdf/SkPDFShader.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "SkLazyPtr.h" 9 #include "SkLazyPtr.h"
10 #include "SkPDFCanon.h" 10 #include "SkPDFCanon.h"
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 domainAndRange->appendInt(1); 136 domainAndRange->appendInt(1);
137 137
138 static const char psInvert[] = "{1 exch sub}"; 138 static const char psInvert[] = "{1 exch sub}";
139 // Do not copy the trailing '\0' into the SkData. 139 // Do not copy the trailing '\0' into the SkData.
140 SkAutoTUnref<SkData> psInvertStream( 140 SkAutoTUnref<SkData> psInvertStream(
141 SkData::NewWithoutCopy(psInvert, strlen(psInvert))); 141 SkData::NewWithoutCopy(psInvert, strlen(psInvert)));
142 142
143 SkPDFStream* invertFunction = SkNEW_ARGS( 143 SkPDFStream* invertFunction = SkNEW_ARGS(
144 SkPDFStream, (psInvertStream.get())); 144 SkPDFStream, (psInvertStream.get()));
145 invertFunction->insertInt("FunctionType", 4); 145 invertFunction->insertInt("FunctionType", 4);
146 invertFunction->insert("Domain", domainAndRange.get()); 146 invertFunction->insertObject("Domain", SkRef(domainAndRange.get()));
147 invertFunction->insert("Range", domainAndRange.get()); 147 invertFunction->insertObject("Range", domainAndRange.detach());
148 return invertFunction; 148 return invertFunction;
149 } 149 }
150 150
151 template <typename T> void unref(T* ptr) { ptr->unref(); } 151 template <typename T> void unref(T* ptr) { ptr->unref(); }
152 } // namespace 152 } // namespace
153 153
154 SK_DECLARE_STATIC_LAZY_PTR(SkPDFObject, 154 SK_DECLARE_STATIC_LAZY_PTR(SkPDFObject,
155 invertFunction, 155 invertFunction,
156 create_invert_function, 156 create_invert_function,
157 unref<SkPDFObject>); 157 unref<SkPDFObject>);
158 158
159 // static 159 // static
160 SkPDFDict* SkPDFGraphicState::GetSMaskGraphicState(SkPDFFormXObject* sMask, 160 SkPDFDict* SkPDFGraphicState::GetSMaskGraphicState(SkPDFFormXObject* sMask,
161 bool invert, 161 bool invert,
162 SkPDFSMaskMode sMaskMode) { 162 SkPDFSMaskMode sMaskMode) {
163 // The practical chances of using the same mask more than once are unlikely 163 // The practical chances of using the same mask more than once are unlikely
164 // enough that it's not worth canonicalizing. 164 // enough that it's not worth canonicalizing.
165 SkAutoTUnref<SkPDFDict> sMaskDict(new SkPDFDict("Mask")); 165 SkAutoTUnref<SkPDFDict> sMaskDict(new SkPDFDict("Mask"));
166 if (sMaskMode == kAlpha_SMaskMode) { 166 if (sMaskMode == kAlpha_SMaskMode) {
167 sMaskDict->insertName("S", "Alpha"); 167 sMaskDict->insertName("S", "Alpha");
168 } else if (sMaskMode == kLuminosity_SMaskMode) { 168 } else if (sMaskMode == kLuminosity_SMaskMode) {
169 sMaskDict->insertName("S", "Luminosity"); 169 sMaskDict->insertName("S", "Luminosity");
170 } 170 }
171 sMaskDict->insert("G", new SkPDFObjRef(sMask))->unref(); 171 sMaskDict->insertObjRef("G", SkRef(sMask));
172 if (invert) { 172 if (invert) {
173 sMaskDict->insert("TR", new SkPDFObjRef(invertFunction.get()))->unref(); 173 sMaskDict->insertObjRef("TR", SkRef(invertFunction.get()));
174 } 174 }
175 175
176 SkPDFDict* result = new SkPDFDict("ExtGState"); 176 SkPDFDict* result = new SkPDFDict("ExtGState");
177 result->insert("SMask", sMaskDict.get()); 177 result->insertObject("SMask", sMaskDict.detach());
178 return result; 178 return result;
179 } 179 }
180 180
181 namespace { 181 namespace {
182 SkPDFDict* create_no_smask_graphic_state() { 182 SkPDFDict* create_no_smask_graphic_state() {
183 SkPDFDict* noSMaskGS = new SkPDFDict("ExtGState"); 183 SkPDFDict* noSMaskGS = new SkPDFDict("ExtGState");
184 noSMaskGS->insertName("SMask", "None"); 184 noSMaskGS->insertName("SMask", "None");
185 return noSMaskGS; 185 return noSMaskGS;
186 } 186 }
187 } // namespace 187 } // namespace
188 SK_DECLARE_STATIC_LAZY_PTR(SkPDFDict, 188 SK_DECLARE_STATIC_LAZY_PTR(SkPDFDict,
189 noSMaskGraphicState, 189 noSMaskGraphicState,
190 create_no_smask_graphic_state, 190 create_no_smask_graphic_state,
191 unref<SkPDFDict>); 191 unref<SkPDFDict>);
192 192
193 // static 193 // static
194 SkPDFDict* SkPDFGraphicState::GetNoSMaskGraphicState() { 194 SkPDFDict* SkPDFGraphicState::GetNoSMaskGraphicState() {
195 return SkRef(noSMaskGraphicState.get()); 195 return SkRef(noSMaskGraphicState.get());
196 } 196 }
197 197
198 void SkPDFGraphicState::emitObject(SkWStream* stream, 198 void SkPDFGraphicState::emitObject(SkWStream* stream,
199 const SkPDFObjNumMap& objNumMap, 199 const SkPDFObjNumMap& objNumMap,
200 const SkPDFSubstituteMap& substitutes) { 200 const SkPDFSubstituteMap& substitutes) {
201 SkAutoTUnref<SkPDFDict> dict(SkNEW_ARGS(SkPDFDict, ("ExtGState"))); 201 SkAutoTUnref<SkPDFDict> dict(SkNEW_ARGS(SkPDFDict, ("ExtGState")));
202 dict->insertName("Type", "ExtGState"); 202 dict->insertName("Type", "ExtGState");
203 203
204 SkAutoTUnref<SkPDFScalar> alpha(new SkPDFScalar(SkScalarDiv(fAlpha, 0xFF))); 204 SkScalar alpha = SkScalarDiv(fAlpha, 0xFF);
205 dict->insert("CA", alpha.get()); 205 dict->insertScalar("CA", alpha);
206 dict->insert("ca", alpha.get()); 206 dict->insertScalar("ca", alpha);
207 207
208 SkPaint::Cap strokeCap = (SkPaint::Cap)fStrokeCap; 208 SkPaint::Cap strokeCap = (SkPaint::Cap)fStrokeCap;
209 SkPaint::Join strokeJoin = (SkPaint::Join)fStrokeJoin; 209 SkPaint::Join strokeJoin = (SkPaint::Join)fStrokeJoin;
210 SkXfermode::Mode xferMode = (SkXfermode::Mode)fMode; 210 SkXfermode::Mode xferMode = (SkXfermode::Mode)fMode;
211 211
212 SK_COMPILE_ASSERT(SkPaint::kButt_Cap == 0, paint_cap_mismatch); 212 SK_COMPILE_ASSERT(SkPaint::kButt_Cap == 0, paint_cap_mismatch);
213 SK_COMPILE_ASSERT(SkPaint::kRound_Cap == 1, paint_cap_mismatch); 213 SK_COMPILE_ASSERT(SkPaint::kRound_Cap == 1, paint_cap_mismatch);
214 SK_COMPILE_ASSERT(SkPaint::kSquare_Cap == 2, paint_cap_mismatch); 214 SK_COMPILE_ASSERT(SkPaint::kSquare_Cap == 2, paint_cap_mismatch);
215 SK_COMPILE_ASSERT(SkPaint::kCapCount == 3, paint_cap_mismatch); 215 SK_COMPILE_ASSERT(SkPaint::kCapCount == 3, paint_cap_mismatch);
216 SkASSERT(strokeCap >= 0 && strokeCap <= 2); 216 SkASSERT(strokeCap >= 0 && strokeCap <= 2);
217 dict->insertInt("LC", strokeCap); 217 dict->insertInt("LC", strokeCap);
218 218
219 SK_COMPILE_ASSERT(SkPaint::kMiter_Join == 0, paint_join_mismatch); 219 SK_COMPILE_ASSERT(SkPaint::kMiter_Join == 0, paint_join_mismatch);
220 SK_COMPILE_ASSERT(SkPaint::kRound_Join == 1, paint_join_mismatch); 220 SK_COMPILE_ASSERT(SkPaint::kRound_Join == 1, paint_join_mismatch);
221 SK_COMPILE_ASSERT(SkPaint::kBevel_Join == 2, paint_join_mismatch); 221 SK_COMPILE_ASSERT(SkPaint::kBevel_Join == 2, paint_join_mismatch);
222 SK_COMPILE_ASSERT(SkPaint::kJoinCount == 3, paint_join_mismatch); 222 SK_COMPILE_ASSERT(SkPaint::kJoinCount == 3, paint_join_mismatch);
223 SkASSERT(strokeJoin >= 0 && strokeJoin <= 2); 223 SkASSERT(strokeJoin >= 0 && strokeJoin <= 2);
224 dict->insertInt("LJ", strokeJoin); 224 dict->insertInt("LJ", strokeJoin);
225 225
226 dict->insertScalar("LW", fStrokeWidth); 226 dict->insertScalar("LW", fStrokeWidth);
227 dict->insertScalar("ML", fStrokeMiter); 227 dict->insertScalar("ML", fStrokeMiter);
228 // SA = Auto stroke adjustment. 228 dict->insertBool("SA", true); // SA = Auto stroke adjustment.
229 dict->insert("SA", new SkPDFBool(true))->unref();
230 dict->insertName("BM", as_blend_mode(xferMode)); 229 dict->insertName("BM", as_blend_mode(xferMode));
231 dict->emitObject(stream, objNumMap, substitutes); 230 dict->emitObject(stream, objNumMap, substitutes);
232 } 231 }
OLDNEW
« no previous file with comments | « src/pdf/SkPDFFormXObject.cpp ('k') | src/pdf/SkPDFShader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698