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

Side by Side Diff: experimental/PdfViewer/pdfparser/native/SkPdfNativeObject.h

Issue 23456022: pdfviewer: (part 1) store the offset of the location of object in file/stream. In order to use the … (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 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 #ifndef SkPdfNativeObject_DEFINED 8 #ifndef SkPdfNativeObject_DEFINED
9 #define SkPdfNativeObject_DEFINED 9 #define SkPdfNativeObject_DEFINED
10 10
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 SkTDArray<SkPdfNativeObject*>* fArray; 96 SkTDArray<SkPdfNativeObject*>* fArray;
97 Reference fRef; 97 Reference fRef;
98 }; 98 };
99 SkTDict<SkPdfNativeObject*>* fMap; 99 SkTDict<SkPdfNativeObject*>* fMap;
100 100
101 // TODO(edisonn): rename data with cache 101 // TODO(edisonn): rename data with cache
102 void* fData; 102 void* fData;
103 DataType fDataType; 103 DataType fDataType;
104 104
105 105
106 // Keep this the last entrys 106 // Keep this the last entries
107 #ifdef PDF_TRACK_OBJECT_USAGE 107 #ifdef PDF_TRACK_OBJECT_USAGE
108 mutable bool fUsed; 108 mutable bool fUsed;
109 #endif // PDF_TRACK_OBJECT_USAGE 109 #endif // PDF_TRACK_OBJECT_USAGE
110 110
111 #ifdef PDF_TRACK_STREAM_OFFSETS
111 public: 112 public:
113 int fStreamId;
114 int fOffsetStart;
115 int fOffsetEnd;
116 #endif // PDF_TRACK_STREAM_OFFSETS
117
118 public:
119
120 #ifdef PDF_TRACK_STREAM_OFFSETS
121 int streamId() const { return fStreamId; }
122 int offsetStart() const { return fOffsetStart; }
123 int offsetEnd() const { return fOffsetEnd; }
124 #endif // PDF_TRACK_STREAM_OFFSETS
125
112 126
113 SkPdfNativeObject() : fInRendering(0) 127 SkPdfNativeObject() : fInRendering(0)
114 , fObjectType(kInvalid_PdfObjectType) 128 , fObjectType(kInvalid_PdfObjectType)
115 , fMap(NULL) 129 , fMap(NULL)
116 , fData(NULL) 130 , fData(NULL)
117 , fDataType(kEmpty_Data) 131 , fDataType(kEmpty_Data)
118 #ifdef PDF_TRACK_OBJECT_USAGE 132 #ifdef PDF_TRACK_OBJECT_USAGE
119 , fUsed(false) 133 , fUsed(false)
120 #endif // PDF_TRACK_OBJECT_USAGE 134 #endif // PDF_TRACK_OBJECT_USAGE
135
136 #ifdef PDF_TRACK_STREAM_OFFSETS
137 , fStreamId(-1)
138 , fOffsetStart(-1)
139 , fOffsetEnd(-1)
140 #endif // PDF_TRACK_STREAM_OFFSETS
121 {} 141 {}
122 142
123 bool inRendering() const { return fInRendering != 0; } 143 bool inRendering() const { return fInRendering != 0; }
124 void startRendering() {fInRendering = 1;} 144 void startRendering() {fInRendering = 1;}
125 void doneRendering() {fInRendering = 0;} 145 void doneRendering() {fInRendering = 0;}
126 146
127 inline bool hasData(DataType type) { 147 inline bool hasData(DataType type) {
128 return type == fDataType; 148 return type == fDataType;
129 } 149 }
130 150
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 static SkPdfFileSpec nyi; 244 static SkPdfFileSpec nyi;
225 return nyi; 245 return nyi;
226 } 246 }
227 247
228 // TODO(edisonn): NYI 248 // TODO(edisonn): NYI
229 SkPdfTree& treeValue() const { 249 SkPdfTree& treeValue() const {
230 static SkPdfTree nyi; 250 static SkPdfTree nyi;
231 return nyi; 251 return nyi;
232 } 252 }
233 253
234 static void makeBoolean(bool value, SkPdfNativeObject* obj) { 254 static void makeBoolean(bool value, SkPdfNativeObject* obj GET_TRACK_PARAMET ERS) {
255 STORE_TRACK_PARAMETERS(obj);
256
235 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType); 257 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType);
236 258
237 obj->fObjectType = kBoolean_PdfObjectType; 259 obj->fObjectType = kBoolean_PdfObjectType;
238 obj->fBooleanValue = value; 260 obj->fBooleanValue = value;
239 } 261 }
240 262
241 static SkPdfNativeObject makeBoolean(bool value) { 263 static SkPdfNativeObject makeBoolean(bool value GET_TRACK_PARAMETERS) {
242 SkPdfNativeObject obj; 264 SkPdfNativeObject obj;
265
266 STORE_TRACK_PARAMETERS(&obj);
267
243 obj.fObjectType = kBoolean_PdfObjectType; 268 obj.fObjectType = kBoolean_PdfObjectType;
244 obj.fBooleanValue = value; 269 obj.fBooleanValue = value;
245 return obj; 270 return obj;
246 } 271 }
247 272
248 static void makeInteger(int64_t value, SkPdfNativeObject* obj) { 273 static void makeInteger(int64_t value, SkPdfNativeObject* obj GET_TRACK_PARA METERS) {
274 STORE_TRACK_PARAMETERS(obj);
275
249 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType); 276 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType);
250 277
251 obj->fObjectType = kInteger_PdfObjectType; 278 obj->fObjectType = kInteger_PdfObjectType;
252 obj->fIntegerValue = value; 279 obj->fIntegerValue = value;
253 } 280 }
254 281
255 static void makeReal(double value, SkPdfNativeObject* obj) { 282 static void makeReal(double value, SkPdfNativeObject* obj GET_TRACK_PARAMETE RS) {
283 STORE_TRACK_PARAMETERS(obj);
284
256 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType); 285 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType);
257 286
258 obj->fObjectType = kReal_PdfObjectType; 287 obj->fObjectType = kReal_PdfObjectType;
259 obj->fRealValue = value; 288 obj->fRealValue = value;
260 } 289 }
261 290
262 static void makeNull(SkPdfNativeObject* obj) { 291 static void makeNull(SkPdfNativeObject* obj GET_TRACK_PARAMETERS) {
292 STORE_TRACK_PARAMETERS(obj);
293
263 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType); 294 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType);
264 295
265 obj->fObjectType = kNull_PdfObjectType; 296 obj->fObjectType = kNull_PdfObjectType;
266 } 297 }
267 298
268 static SkPdfNativeObject makeNull() { 299 static SkPdfNativeObject makeNull(GET_TRACK_PARAMETERS0) {
269 SkPdfNativeObject obj; 300 SkPdfNativeObject obj;
301
302 STORE_TRACK_PARAMETERS(&obj);
303
270 obj.fObjectType = kNull_PdfObjectType; 304 obj.fObjectType = kNull_PdfObjectType;
271 return obj; 305 return obj;
272 } 306 }
273 307
274 static SkPdfNativeObject kNull; 308 static SkPdfNativeObject kNull;
275 309
276 static void makeNumeric(const unsigned char* start, const unsigned char* end , SkPdfNativeObject* obj) { 310 static void makeNumeric(const unsigned char* start, const unsigned char* end , SkPdfNativeObject* obj GET_TRACK_PARAMETERS) {
277 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType); 311 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType);
278 312
279 // TODO(edisonn): NYI properly 313 // TODO(edisonn): NYI properly
280 // if has dot (impl), or exceeds max int, is real, otherwise is int 314 // if has dot (impl), or exceeds max int, is real, otherwise is int
281 bool isInt = true; 315 bool isInt = true;
282 for (const unsigned char* current = start; current < end; current++) { 316 for (const unsigned char* current = start; current < end; current++) {
283 if (*current == '.') { 317 if (*current == '.') {
284 isInt = false; 318 isInt = false;
285 break; 319 break;
286 } 320 }
287 // TODO(edisonn): report parse issue with numbers like "24asdasd123" 321 // TODO(edisonn): report parse issue with numbers like "24asdasd123"
288 } 322 }
289 if (isInt) { 323 if (isInt) {
290 makeInteger(atol((const char*)start), obj); 324 makeInteger(atol((const char*)start), obj PUT_TRACK_PARAMETERS);
291 } else { 325 } else {
292 makeReal(atof((const char*)start), obj); 326 makeReal(atof((const char*)start), obj PUT_TRACK_PARAMETERS);
293 } 327 }
294 } 328 }
295 329
296 static void makeReference(unsigned int id, unsigned int gen, SkPdfNativeObje ct* obj) { 330 static void makeReference(unsigned int id, unsigned int gen, SkPdfNativeObje ct* obj GET_TRACK_PARAMETERS) {
331 STORE_TRACK_PARAMETERS(obj);
332
297 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType); 333 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType);
298 334
299 obj->fObjectType = kReference_PdfObjectType; 335 obj->fObjectType = kReference_PdfObjectType;
300 obj->fRef.fId = id; 336 obj->fRef.fId = id;
301 obj->fRef.fGen = gen; 337 obj->fRef.fGen = gen;
302 } 338 }
303 339
304 340 static void resetAndMakeReference(unsigned int id, unsigned int gen, SkPdfNa tiveObject* obj GET_TRACK_PARAMETERS) {
305 static void makeString(const unsigned char* start, SkPdfNativeObject* obj) { 341 obj->reset();
306 makeStringCore(start, strlen((const char*)start), obj, kString_PdfObject Type); 342 makeReference(id, gen, obj PUT_TRACK_PARAMETERS);
307 }
308
309 static void makeString(const unsigned char* start, const unsigned char* end, SkPdfNativeObject* obj) {
310 makeStringCore(start, end - start, obj, kString_PdfObjectType);
311 }
312
313 static void makeString(const unsigned char* start, size_t bytes, SkPdfNative Object* obj) {
314 makeStringCore(start, bytes, obj, kString_PdfObjectType);
315 } 343 }
316 344
317 345
318 static void makeHexString(const unsigned char* start, SkPdfNativeObject* obj ) { 346 static void makeString(const unsigned char* start, SkPdfNativeObject* obj GE T_TRACK_PARAMETERS) {
319 makeStringCore(start, strlen((const char*)start), obj, kHexString_PdfObj ectType); 347 makeStringCore(start, strlen((const char*)start), obj, kString_PdfObject Type PUT_TRACK_PARAMETERS);
320 } 348 }
321 349
322 static void makeHexString(const unsigned char* start, const unsigned char* e nd, SkPdfNativeObject* obj) { 350 static void makeString(const unsigned char* start, const unsigned char* end, SkPdfNativeObject* obj GET_TRACK_PARAMETERS) {
323 makeStringCore(start, end - start, obj, kHexString_PdfObjectType); 351 makeStringCore(start, end - start, obj, kString_PdfObjectType PUT_TRACK_ PARAMETERS);
324 } 352 }
325 353
326 static void makeHexString(const unsigned char* start, size_t bytes, SkPdfNat iveObject* obj) { 354 static void makeString(const unsigned char* start, size_t bytes, SkPdfNative Object* obj GET_TRACK_PARAMETERS) {
327 makeStringCore(start, bytes, obj, kHexString_PdfObjectType); 355 makeStringCore(start, bytes, obj, kString_PdfObjectType PUT_TRACK_PARAME TERS);
328 } 356 }
329 357
330 358
331 static void makeName(const unsigned char* start, SkPdfNativeObject* obj) { 359 static void makeHexString(const unsigned char* start, SkPdfNativeObject* obj GET_TRACK_PARAMETERS) {
332 makeStringCore(start, strlen((const char*)start), obj, kName_PdfObjectTy pe); 360 makeStringCore(start, strlen((const char*)start), obj, kHexString_PdfObj ectType PUT_TRACK_PARAMETERS);
333 } 361 }
334 362
335 static void makeName(const unsigned char* start, const unsigned char* end, S kPdfNativeObject* obj) { 363 static void makeHexString(const unsigned char* start, const unsigned char* e nd, SkPdfNativeObject* obj GET_TRACK_PARAMETERS) {
336 makeStringCore(start, end - start, obj, kName_PdfObjectType); 364 makeStringCore(start, end - start, obj, kHexString_PdfObjectType PUT_TRA CK_PARAMETERS);
337 } 365 }
338 366
339 static void makeName(const unsigned char* start, size_t bytes, SkPdfNativeOb ject* obj) { 367 static void makeHexString(const unsigned char* start, size_t bytes, SkPdfNat iveObject* obj GET_TRACK_PARAMETERS) {
340 makeStringCore(start, bytes, obj, kName_PdfObjectType); 368 makeStringCore(start, bytes, obj, kHexString_PdfObjectType PUT_TRACK_PAR AMETERS);
341 } 369 }
342 370
343 371
344 static void makeKeyword(const unsigned char* start, SkPdfNativeObject* obj) { 372 static void makeName(const unsigned char* start, SkPdfNativeObject* obj GET_ TRACK_PARAMETERS) {
345 makeStringCore(start, strlen((const char*)start), obj, kKeyword_PdfObjec tType); 373 makeStringCore(start, strlen((const char*)start), obj, kName_PdfObjectTy pe PUT_TRACK_PARAMETERS);
346 } 374 }
347 375
348 static void makeKeyword(const unsigned char* start, const unsigned char* end , SkPdfNativeObject* obj) { 376 static void makeName(const unsigned char* start, const unsigned char* end, S kPdfNativeObject* obj GET_TRACK_PARAMETERS) {
349 makeStringCore(start, end - start, obj, kKeyword_PdfObjectType); 377 makeStringCore(start, end - start, obj, kName_PdfObjectType PUT_TRACK_PA RAMETERS);
350 } 378 }
351 379
352 static void makeKeyword(const unsigned char* start, size_t bytes, SkPdfNativ eObject* obj) { 380 static void makeName(const unsigned char* start, size_t bytes, SkPdfNativeOb ject* obj GET_TRACK_PARAMETERS) {
353 makeStringCore(start, bytes, obj, kKeyword_PdfObjectType); 381 makeStringCore(start, bytes, obj, kName_PdfObjectType PUT_TRACK_PARAMETE RS);
382 }
383
384
385 static void makeKeyword(const unsigned char* start, SkPdfNativeObject* obj G ET_TRACK_PARAMETERS) {
386 makeStringCore(start, strlen((const char*)start), obj, kKeyword_PdfObjec tType PUT_TRACK_PARAMETERS);
387 }
388
389 static void makeKeyword(const unsigned char* start, const unsigned char* end , SkPdfNativeObject* obj GET_TRACK_PARAMETERS) {
390 makeStringCore(start, end - start, obj, kKeyword_PdfObjectType PUT_TRACK _PARAMETERS);
391 }
392
393 static void makeKeyword(const unsigned char* start, size_t bytes, SkPdfNativ eObject* obj GET_TRACK_PARAMETERS) {
394 makeStringCore(start, bytes, obj, kKeyword_PdfObjectType PUT_TRACK_PARAM ETERS);
354 } 395 }
355 396
356 397
357 398
358 // TODO(edisonn): make the functions to return SkPdfArray, move these functi ons in SkPdfArray 399 // TODO(edisonn): make the functions to return SkPdfArray, move these functi ons in SkPdfArray
359 static void makeEmptyArray(SkPdfNativeObject* obj) { 400 static void makeEmptyArray(SkPdfNativeObject* obj GET_TRACK_PARAMETERS) {
401 STORE_TRACK_PARAMETERS(obj);
402
360 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType); 403 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType);
361 404
362 obj->fObjectType = kArray_PdfObjectType; 405 obj->fObjectType = kArray_PdfObjectType;
363 obj->fArray = new SkTDArray<SkPdfNativeObject*>(); 406 obj->fArray = new SkTDArray<SkPdfNativeObject*>();
364 // return (SkPdfArray*)obj; 407 // return (SkPdfArray*)obj;
365 } 408 }
366 409
367 bool appendInArray(SkPdfNativeObject* obj) { 410 bool appendInArray(SkPdfNativeObject* obj) {
368 SkASSERT(fObjectType == kArray_PdfObjectType); 411 SkASSERT(fObjectType == kArray_PdfObjectType);
369 if (fObjectType != kArray_PdfObjectType) { 412 if (fObjectType != kArray_PdfObjectType) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 const SkPdfNativeObject* operator[](int i) const { 463 const SkPdfNativeObject* operator[](int i) const {
421 SkPdfMarkObjectUsed(); 464 SkPdfMarkObjectUsed();
422 465
423 SkASSERT(fObjectType == kArray_PdfObjectType); 466 SkASSERT(fObjectType == kArray_PdfObjectType);
424 467
425 return (*fArray)[i]; 468 return (*fArray)[i];
426 } 469 }
427 470
428 471
429 // TODO(edisonn): make the functions to return SkPdfDictionary, move these f unctions in SkPdfDictionary 472 // TODO(edisonn): make the functions to return SkPdfDictionary, move these f unctions in SkPdfDictionary
430 static void makeEmptyDictionary(SkPdfNativeObject* obj) { 473 static void makeEmptyDictionary(SkPdfNativeObject* obj GET_TRACK_PARAMETERS) {
474 STORE_TRACK_PARAMETERS(obj);
475
431 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType); 476 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType);
432 477
433 obj->fObjectType = kDictionary_PdfObjectType; 478 obj->fObjectType = kDictionary_PdfObjectType;
434 obj->fMap = new SkTDict<SkPdfNativeObject*>(1); 479 obj->fMap = new SkTDict<SkPdfNativeObject*>(1);
435 obj->fStr.fBuffer = NULL; 480 obj->fStr.fBuffer = NULL;
436 obj->fStr.fBytes = 0; 481 obj->fStr.fBytes = 0;
437 } 482 }
438 483
439 // TODO(edisonn): get all the possible names from spec, and compute a hash f unction 484 // TODO(edisonn): get all the possible names from spec, and compute a hash f unction
440 // that would create no overlaps in the same dictionary 485 // that would create no overlaps in the same dictionary
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after
1137 1182
1138 default: 1183 default:
1139 str = "Error"; 1184 str = "Error";
1140 break; 1185 break;
1141 } 1186 }
1142 1187
1143 return str; 1188 return str;
1144 } 1189 }
1145 1190
1146 private: 1191 private:
1147 static void makeStringCore(const unsigned char* start, SkPdfNativeObject* ob j, ObjectType type) { 1192 static void makeStringCore(const unsigned char* start, SkPdfNativeObject* ob j, ObjectType type GET_TRACK_PARAMETERS) {
1148 makeStringCore(start, strlen((const char*)start), obj, type); 1193 makeStringCore(start, strlen((const char*)start), obj, type PUT_TRACK_PA RAMETERS);
1149 } 1194 }
1150 1195
1151 static void makeStringCore(const unsigned char* start, const unsigned char* end, SkPdfNativeObject* obj, ObjectType type) { 1196 static void makeStringCore(const unsigned char* start, const unsigned char* end, SkPdfNativeObject* obj, ObjectType type GET_TRACK_PARAMETERS) {
1152 makeStringCore(start, end - start, obj, type); 1197 makeStringCore(start, end - start, obj, type PUT_TRACK_PARAMETERS);
1153 } 1198 }
1154 1199
1155 static void makeStringCore(const unsigned char* start, size_t bytes, SkPdfNa tiveObject* obj, ObjectType type) { 1200 static void makeStringCore(const unsigned char* start, size_t bytes, SkPdfNa tiveObject* obj, ObjectType type GET_TRACK_PARAMETERS) {
1201 STORE_TRACK_PARAMETERS(obj);
1202
1156 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType); 1203 SkASSERT(obj->fObjectType == kInvalid_PdfObjectType);
1157 1204
1158 obj->fObjectType = type; 1205 obj->fObjectType = type;
1159 obj->fStr.fBuffer = start; 1206 obj->fStr.fBuffer = start;
1160 obj->fStr.fBytes = bytes; 1207 obj->fStr.fBytes = bytes;
1161 } 1208 }
1162 1209
1163 bool applyFilter(const char* name); 1210 bool applyFilter(const char* name);
1164 bool applyFlateDecodeFilter(); 1211 bool applyFlateDecodeFilter();
1165 bool applyDCTDecodeFilter(); 1212 bool applyDCTDecodeFilter();
1166 }; 1213 };
1167 1214
1168 class SkPdfStream : public SkPdfNativeObject {}; 1215 class SkPdfStream : public SkPdfNativeObject {};
1169 class SkPdfArray : public SkPdfNativeObject {}; 1216 class SkPdfArray : public SkPdfNativeObject {};
1170 class SkPdfString : public SkPdfNativeObject {}; 1217 class SkPdfString : public SkPdfNativeObject {};
1171 class SkPdfHexString : public SkPdfNativeObject {}; 1218 class SkPdfHexString : public SkPdfNativeObject {};
1172 class SkPdfInteger : public SkPdfNativeObject {}; 1219 class SkPdfInteger : public SkPdfNativeObject {};
1173 class SkPdfReal : public SkPdfNativeObject {}; 1220 class SkPdfReal : public SkPdfNativeObject {};
1174 class SkPdfNumber : public SkPdfNativeObject {}; 1221 class SkPdfNumber : public SkPdfNativeObject {};
1175 1222
1176 class SkPdfName : public SkPdfNativeObject { 1223 class SkPdfName : public SkPdfNativeObject {
1177 SkPdfName() : SkPdfNativeObject() { 1224 SkPdfName() : SkPdfNativeObject() {
1178 SkPdfNativeObject::makeName((const unsigned char*)"", this); 1225 SkPdfNativeObject::makeName((const unsigned char*)"", this PUT_TRACK_PAR AMETERS_SRC);
1179 } 1226 }
1180 public: 1227 public:
1181 SkPdfName(char* name) : SkPdfNativeObject() { 1228 SkPdfName(char* name) : SkPdfNativeObject() {
1182 this->makeName((const unsigned char*)name, this); 1229 this->makeName((const unsigned char*)name, this PUT_TRACK_PARAMETERS_SRC );
1183 } 1230 }
1184 }; 1231 };
1185 1232
1186 #endif // SkPdfNativeObject 1233 #endif // SkPdfNativeObject
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698