OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2010 The Android Open Source Project | 2 * Copyright 2010 The Android Open Source Project |
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 | 8 |
9 #ifndef SkPDFTypes_DEFINED | 9 #ifndef SkPDFTypes_DEFINED |
10 #define SkPDFTypes_DEFINED | 10 #define SkPDFTypes_DEFINED |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
153 SkPDFUnion(Type); | 153 SkPDFUnion(Type); |
154 // We do not now need copy constructor and copy assignment, so we | 154 // We do not now need copy constructor and copy assignment, so we |
155 // will disable this functionality. | 155 // will disable this functionality. |
156 SkPDFUnion& operator=(const SkPDFUnion&) = delete; | 156 SkPDFUnion& operator=(const SkPDFUnion&) = delete; |
157 SkPDFUnion(const SkPDFUnion&) = delete; | 157 SkPDFUnion(const SkPDFUnion&) = delete; |
158 }; | 158 }; |
159 SK_COMPILE_ASSERT(sizeof(SkString) == sizeof(void*), SkString_size); | 159 SK_COMPILE_ASSERT(sizeof(SkString) == sizeof(void*), SkString_size); |
160 | 160 |
161 //////////////////////////////////////////////////////////////////////////////// | 161 //////////////////////////////////////////////////////////////////////////////// |
162 | 162 |
163 /** This class is a SkPDFUnion with SkPDFObject virtuals attached. */ | 163 #if 0 // Enable if needed. |
tomhudson
2015/05/04 18:31:54
... because you're trying to deprecate? *why*?
| |
164 // TODO(halcanary): 99% of the uses of this class should be | 164 /** This class is a SkPDFUnion with SkPDFObject virtuals attached. |
165 // transitioned to using a bare SkPDFUnion inside an array or dict. | 165 The only use case of this is when a non-compound PDF object is |
166 referenced indirectly. */ | |
166 class SkPDFAtom : public SkPDFObject { | 167 class SkPDFAtom : public SkPDFObject { |
167 public: | 168 public: |
168 void emitObject(SkWStream* stream, | 169 void emitObject(SkWStream* stream, |
169 const SkPDFObjNumMap& objNumMap, | 170 const SkPDFObjNumMap& objNumMap, |
170 const SkPDFSubstituteMap& substitutes) final; | 171 const SkPDFSubstituteMap& substitutes) final; |
171 void addResources(SkPDFObjNumMap*, const SkPDFSubstituteMap&) const final; | 172 void addResources(SkPDFObjNumMap*, const SkPDFSubstituteMap&) const final; |
172 | |
173 protected: | |
174 SkPDFAtom(SkPDFUnion&& v) : fValue(v.move()) {} | 173 SkPDFAtom(SkPDFUnion&& v) : fValue(v.move()) {} |
175 | 174 |
176 private: | 175 private: |
177 const SkPDFUnion fValue; | 176 const SkPDFUnion fValue; |
178 typedef SkPDFObject INHERITED; | 177 typedef SkPDFObject INHERITED; |
179 }; | 178 }; |
179 #endif // 0 | |
180 | 180 |
181 /** The following six classes exist only to ease transition to SkPDFUnion. */ | 181 class SkPDFScalar { |
tomhudson
2015/05/04 18:31:55
Now that you've gotten rid of the idea of objects
hal.canary
2015/05/04 18:48:44
I'll move them to SkPDFUtils at a later date.
| |
182 class SkPDFObjRef : public SkPDFAtom { | |
183 public: | 182 public: |
184 SK_DECLARE_INST_COUNT(SkPDFObjRef); | 183 static void Append(SkScalar value, SkWStream* stream); |
185 explicit SkPDFObjRef(SkPDFObject* obj) | |
186 : INHERITED(SkPDFUnion::ObjRef(SkRef(obj))) {} | |
187 typedef SkPDFAtom INHERITED; | |
188 }; | 184 }; |
189 | 185 |
190 class SkPDFInt : public SkPDFAtom { | 186 class SkPDFString { |
191 public: | 187 public: |
192 SK_DECLARE_INST_COUNT(SkPDFInt); | 188 static SkString FormatString(const char* input, size_t len); |
193 explicit SkPDFInt(int32_t value) : INHERITED(SkPDFUnion::Int(value)) {} | 189 static const size_t kMaxLen = 65535; |
194 typedef SkPDFAtom INHERITED; | |
195 }; | 190 }; |
196 | 191 |
197 class SkPDFBool : public SkPDFAtom { | |
198 public: | |
199 SK_DECLARE_INST_COUNT(SkPDFBool); | |
200 explicit SkPDFBool(bool value) : INHERITED(SkPDFUnion::Bool(value)) {} | |
201 typedef SkPDFAtom INHERITED; | |
202 }; | |
203 | |
204 class SkPDFScalar : public SkPDFAtom { | |
205 public: | |
206 SK_DECLARE_INST_COUNT(SkPDFScalar); | |
207 explicit SkPDFScalar(SkScalar value) | |
208 : INHERITED(SkPDFUnion::Scalar(value)) {} | |
209 static void Append(SkScalar value, SkWStream* stream); | |
210 typedef SkPDFAtom INHERITED; | |
211 }; | |
212 | |
213 class SkPDFString : public SkPDFAtom { | |
214 public: | |
215 SK_DECLARE_INST_COUNT(SkPDFString); | |
216 explicit SkPDFString(const char value[]) | |
217 : INHERITED(SkPDFUnion::String(value)) {} | |
218 explicit SkPDFString(const SkString& value) | |
219 : INHERITED(SkPDFUnion::String(value)) {} | |
220 | |
221 static SkString FormatString(const char* input, size_t len); | |
222 | |
223 static const size_t kMaxLen = 65535; | |
224 | |
225 private: | |
226 typedef SkPDFAtom INHERITED; | |
227 }; | |
228 | |
229 class SkPDFName : public SkPDFAtom { | |
230 public: | |
231 SK_DECLARE_INST_COUNT(SkPDFName); | |
232 /** Create a PDF name object. Maximum length is 127 bytes. */ | |
233 explicit SkPDFName(const char name[]) | |
234 : INHERITED(SkPDFUnion::Name(SkString(name))) {} | |
235 explicit SkPDFName(const SkString& name) | |
236 : INHERITED(SkPDFUnion::Name(name)) {} | |
237 | |
238 static const size_t kMaxLen = 127; | |
239 | |
240 private: | |
241 typedef SkPDFAtom INHERITED; | |
242 }; | |
243 | 192 |
244 /** \class SkPDFArray | 193 /** \class SkPDFArray |
245 | 194 |
246 An array object in a PDF. | 195 An array object in a PDF. |
247 */ | 196 */ |
248 class SkPDFArray : public SkPDFObject { | 197 class SkPDFArray : public SkPDFObject { |
249 public: | 198 public: |
250 SK_DECLARE_INST_COUNT(SkPDFArray) | 199 SK_DECLARE_INST_COUNT(SkPDFArray) |
251 | 200 |
252 static const int kMaxLen = 8191; | 201 static const int kMaxLen = 8191; |
(...skipping 12 matching lines...) Expand all Loading... | |
265 | 214 |
266 /** The size of the array. | 215 /** The size of the array. |
267 */ | 216 */ |
268 int size() const; | 217 int size() const; |
269 | 218 |
270 /** Preallocate space for the given number of entries. | 219 /** Preallocate space for the given number of entries. |
271 * @param length The number of array slots to preallocate. | 220 * @param length The number of array slots to preallocate. |
272 */ | 221 */ |
273 void reserve(int length); | 222 void reserve(int length); |
274 | 223 |
275 /** Append the object to the end of the array and increments its ref count. | |
276 * @param value The value to add to the array. | |
277 * @return The value argument is returned. | |
278 */ | |
279 // DEPRECATED | |
280 SkPDFObject* append(SkPDFObject* value); | |
281 | |
282 /** Appends a value to the end of the array. | 224 /** Appends a value to the end of the array. |
283 * @param value The value to add to the array. | 225 * @param value The value to add to the array. |
284 */ | 226 */ |
285 void appendInt(int32_t); | 227 void appendInt(int32_t); |
286 void appendBool(bool); | 228 void appendBool(bool); |
287 void appendScalar(SkScalar); | 229 void appendScalar(SkScalar); |
288 void appendName(const char[]); | 230 void appendName(const char[]); |
289 void appendName(const SkString&); | 231 void appendName(const SkString&); |
290 void appendString(const char[]); | 232 void appendString(const char[]); |
291 void appendString(const SkString&); | 233 void appendString(const SkString&); |
(...skipping 30 matching lines...) Expand all Loading... | |
322 void emitObject(SkWStream* stream, | 264 void emitObject(SkWStream* stream, |
323 const SkPDFObjNumMap& objNumMap, | 265 const SkPDFObjNumMap& objNumMap, |
324 const SkPDFSubstituteMap& substitutes) override; | 266 const SkPDFSubstituteMap& substitutes) override; |
325 void addResources(SkPDFObjNumMap*, | 267 void addResources(SkPDFObjNumMap*, |
326 const SkPDFSubstituteMap&) const override; | 268 const SkPDFSubstituteMap&) const override; |
327 | 269 |
328 /** The size of the dictionary. | 270 /** The size of the dictionary. |
329 */ | 271 */ |
330 int size() const; | 272 int size() const; |
331 | 273 |
332 /** Add the value to the dictionary with the given key. Refs value. | |
333 * @param key The key for this dictionary entry. | |
334 * @param value The value for this dictionary entry. | |
335 * @return The value argument is returned. | |
336 */ | |
337 // DEPRECATED | |
338 SkPDFObject* insert(SkPDFName* key, SkPDFObject* value); | |
339 // DEPRECATED | |
340 SkPDFObject* insert(const char key[], SkPDFObject* value); | |
341 | |
342 /** Add the value to the dictionary with the given key. Takes | 274 /** Add the value to the dictionary with the given key. Takes |
343 * ownership of the object. | 275 * ownership of the object. |
344 * @param key The text of the key for this dictionary entry. | 276 * @param key The text of the key for this dictionary entry. |
345 * @param value The value for this dictionary entry. | 277 * @param value The value for this dictionary entry. |
346 */ | 278 */ |
347 void insertObject(const char key[], SkPDFObject* value); | 279 void insertObject(const char key[], SkPDFObject* value); |
348 void insertObject(const SkString& key, SkPDFObject* value); | 280 void insertObject(const SkString& key, SkPDFObject* value); |
349 void insertObjRef(const char key[], SkPDFObject* value); | 281 void insertObjRef(const char key[], SkPDFObject* value); |
350 void insertObjRef(const SkString& key, SkPDFObject* value); | 282 void insertObjRef(const SkString& key, SkPDFObject* value); |
351 | 283 |
(...skipping 15 matching lines...) Expand all Loading... | |
367 void clear(); | 299 void clear(); |
368 | 300 |
369 private: | 301 private: |
370 struct Record { | 302 struct Record { |
371 SkPDFUnion fKey; | 303 SkPDFUnion fKey; |
372 SkPDFUnion fValue; | 304 SkPDFUnion fValue; |
373 }; | 305 }; |
374 SkTDArray<Record> fRecords; | 306 SkTDArray<Record> fRecords; |
375 static const int kMaxLen = 4095; | 307 static const int kMaxLen = 4095; |
376 | 308 |
377 void set(const SkPDFUnion& name, const SkPDFUnion& value); | |
378 void set(SkPDFUnion&& name, SkPDFUnion&& value); | 309 void set(SkPDFUnion&& name, SkPDFUnion&& value); |
379 | 310 |
380 typedef SkPDFObject INHERITED; | 311 typedef SkPDFObject INHERITED; |
381 }; | 312 }; |
382 | 313 |
383 //////////////////////////////////////////////////////////////////////////////// | 314 //////////////////////////////////////////////////////////////////////////////// |
384 | 315 |
385 /** \class SkPDFObjNumMap | 316 /** \class SkPDFObjNumMap |
386 | 317 |
387 The PDF Object Number Map manages object numbers. It is used to | 318 The PDF Object Number Map manages object numbers. It is used to |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
429 | 360 |
430 SkPDFObject* operator()(SkPDFObject* o) const { | 361 SkPDFObject* operator()(SkPDFObject* o) const { |
431 return this->getSubstitute(o); | 362 return this->getSubstitute(o); |
432 } | 363 } |
433 | 364 |
434 private: | 365 private: |
435 SkTHashMap<SkPDFObject*, SkPDFObject*> fSubstituteMap; | 366 SkTHashMap<SkPDFObject*, SkPDFObject*> fSubstituteMap; |
436 }; | 367 }; |
437 | 368 |
438 #endif | 369 #endif |
OLD | NEW |