OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "core/src/fpdfapi/fpdf_page/pageint.h" | 7 #include "core/src/fpdfapi/fpdf_page/pageint.h" |
8 | 8 |
9 #include "core/include/fpdfapi/fpdf_module.h" | 9 #include "core/include/fpdfapi/fpdf_module.h" |
10 #include "core/include/fpdfapi/fpdf_page.h" | 10 #include "core/include/fpdfapi/fpdf_page.h" |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 pObj->m_ColorState = m_pCurStates->m_ColorState; | 333 pObj->m_ColorState = m_pCurStates->m_ColorState; |
334 } | 334 } |
335 if (bGraph) { | 335 if (bGraph) { |
336 pObj->m_GraphState = m_pCurStates->m_GraphState; | 336 pObj->m_GraphState = m_pCurStates->m_GraphState; |
337 } | 337 } |
338 if (bText) { | 338 if (bText) { |
339 pObj->m_TextState = m_pCurStates->m_TextState; | 339 pObj->m_TextState = m_pCurStates->m_TextState; |
340 } | 340 } |
341 } | 341 } |
342 | 342 |
343 const CPDF_StreamContentParser::OpCodes CPDF_StreamContentParser::s_OpCodes = { | 343 // static |
344 {FXBSTR_ID('"', 0, 0, 0), | 344 CPDF_StreamContentParser::OpCodes |
345 &CPDF_StreamContentParser::Handle_NextLineShowText_Space}, | 345 CPDF_StreamContentParser::InitializeOpCodes() { |
346 {FXBSTR_ID('\'', 0, 0, 0), | 346 return OpCodes({ |
347 &CPDF_StreamContentParser::Handle_NextLineShowText}, | 347 {FXBSTR_ID('"', 0, 0, 0), |
348 {FXBSTR_ID('B', 0, 0, 0), &CPDF_StreamContentParser::Handle_FillStrokePath}, | 348 &CPDF_StreamContentParser::Handle_NextLineShowText_Space}, |
349 {FXBSTR_ID('B', '*', 0, 0), | 349 {FXBSTR_ID('\'', 0, 0, 0), |
350 &CPDF_StreamContentParser::Handle_EOFillStrokePath}, | 350 &CPDF_StreamContentParser::Handle_NextLineShowText}, |
351 {FXBSTR_ID('B', 'D', 'C', 0), | 351 {FXBSTR_ID('B', 0, 0, 0), |
352 &CPDF_StreamContentParser::Handle_BeginMarkedContent_Dictionary}, | 352 &CPDF_StreamContentParser::Handle_FillStrokePath}, |
353 {FXBSTR_ID('B', 'I', 0, 0), &CPDF_StreamContentParser::Handle_BeginImage}, | 353 {FXBSTR_ID('B', '*', 0, 0), |
354 {FXBSTR_ID('B', 'M', 'C', 0), | 354 &CPDF_StreamContentParser::Handle_EOFillStrokePath}, |
355 &CPDF_StreamContentParser::Handle_BeginMarkedContent}, | 355 {FXBSTR_ID('B', 'D', 'C', 0), |
356 {FXBSTR_ID('B', 'T', 0, 0), &CPDF_StreamContentParser::Handle_BeginText}, | 356 &CPDF_StreamContentParser::Handle_BeginMarkedContent_Dictionary}, |
357 {FXBSTR_ID('C', 'S', 0, 0), | 357 {FXBSTR_ID('B', 'I', 0, 0), &CPDF_StreamContentParser::Handle_BeginImage}, |
358 &CPDF_StreamContentParser::Handle_SetColorSpace_Stroke}, | 358 {FXBSTR_ID('B', 'M', 'C', 0), |
359 {FXBSTR_ID('D', 'P', 0, 0), | 359 &CPDF_StreamContentParser::Handle_BeginMarkedContent}, |
360 &CPDF_StreamContentParser::Handle_MarkPlace_Dictionary}, | 360 {FXBSTR_ID('B', 'T', 0, 0), &CPDF_StreamContentParser::Handle_BeginText}, |
361 {FXBSTR_ID('D', 'o', 0, 0), | 361 {FXBSTR_ID('C', 'S', 0, 0), |
362 &CPDF_StreamContentParser::Handle_ExecuteXObject}, | 362 &CPDF_StreamContentParser::Handle_SetColorSpace_Stroke}, |
363 {FXBSTR_ID('E', 'I', 0, 0), &CPDF_StreamContentParser::Handle_EndImage}, | 363 {FXBSTR_ID('D', 'P', 0, 0), |
364 {FXBSTR_ID('E', 'M', 'C', 0), | 364 &CPDF_StreamContentParser::Handle_MarkPlace_Dictionary}, |
365 &CPDF_StreamContentParser::Handle_EndMarkedContent}, | 365 {FXBSTR_ID('D', 'o', 0, 0), |
366 {FXBSTR_ID('E', 'T', 0, 0), &CPDF_StreamContentParser::Handle_EndText}, | 366 &CPDF_StreamContentParser::Handle_ExecuteXObject}, |
367 {FXBSTR_ID('F', 0, 0, 0), &CPDF_StreamContentParser::Handle_FillPathOld}, | 367 {FXBSTR_ID('E', 'I', 0, 0), &CPDF_StreamContentParser::Handle_EndImage}, |
368 {FXBSTR_ID('G', 0, 0, 0), &CPDF_StreamContentParser::Handle_SetGray_Stroke}, | 368 {FXBSTR_ID('E', 'M', 'C', 0), |
369 {FXBSTR_ID('I', 'D', 0, 0), | 369 &CPDF_StreamContentParser::Handle_EndMarkedContent}, |
370 &CPDF_StreamContentParser::Handle_BeginImageData}, | 370 {FXBSTR_ID('E', 'T', 0, 0), &CPDF_StreamContentParser::Handle_EndText}, |
371 {FXBSTR_ID('J', 0, 0, 0), &CPDF_StreamContentParser::Handle_SetLineCap}, | 371 {FXBSTR_ID('F', 0, 0, 0), &CPDF_StreamContentParser::Handle_FillPathOld}, |
372 {FXBSTR_ID('K', 0, 0, 0), | 372 {FXBSTR_ID('G', 0, 0, 0), |
373 &CPDF_StreamContentParser::Handle_SetCMYKColor_Stroke}, | 373 &CPDF_StreamContentParser::Handle_SetGray_Stroke}, |
374 {FXBSTR_ID('M', 0, 0, 0), &CPDF_StreamContentParser::Handle_SetMiterLimit}, | 374 {FXBSTR_ID('I', 'D', 0, 0), |
375 {FXBSTR_ID('M', 'P', 0, 0), &CPDF_StreamContentParser::Handle_MarkPlace}, | 375 &CPDF_StreamContentParser::Handle_BeginImageData}, |
376 {FXBSTR_ID('Q', 0, 0, 0), | 376 {FXBSTR_ID('J', 0, 0, 0), &CPDF_StreamContentParser::Handle_SetLineCap}, |
377 &CPDF_StreamContentParser::Handle_RestoreGraphState}, | 377 {FXBSTR_ID('K', 0, 0, 0), |
378 {FXBSTR_ID('R', 'G', 0, 0), | 378 &CPDF_StreamContentParser::Handle_SetCMYKColor_Stroke}, |
379 &CPDF_StreamContentParser::Handle_SetRGBColor_Stroke}, | 379 {FXBSTR_ID('M', 0, 0, 0), |
380 {FXBSTR_ID('S', 0, 0, 0), &CPDF_StreamContentParser::Handle_StrokePath}, | 380 &CPDF_StreamContentParser::Handle_SetMiterLimit}, |
381 {FXBSTR_ID('S', 'C', 0, 0), | 381 {FXBSTR_ID('M', 'P', 0, 0), &CPDF_StreamContentParser::Handle_MarkPlace}, |
382 &CPDF_StreamContentParser::Handle_SetColor_Stroke}, | 382 {FXBSTR_ID('Q', 0, 0, 0), |
383 {FXBSTR_ID('S', 'C', 'N', 0), | 383 &CPDF_StreamContentParser::Handle_RestoreGraphState}, |
384 &CPDF_StreamContentParser::Handle_SetColorPS_Stroke}, | 384 {FXBSTR_ID('R', 'G', 0, 0), |
385 {FXBSTR_ID('T', '*', 0, 0), | 385 &CPDF_StreamContentParser::Handle_SetRGBColor_Stroke}, |
386 &CPDF_StreamContentParser::Handle_MoveToNextLine}, | 386 {FXBSTR_ID('S', 0, 0, 0), &CPDF_StreamContentParser::Handle_StrokePath}, |
387 {FXBSTR_ID('T', 'D', 0, 0), | 387 {FXBSTR_ID('S', 'C', 0, 0), |
388 &CPDF_StreamContentParser::Handle_MoveTextPoint_SetLeading}, | 388 &CPDF_StreamContentParser::Handle_SetColor_Stroke}, |
389 {FXBSTR_ID('T', 'J', 0, 0), | 389 {FXBSTR_ID('S', 'C', 'N', 0), |
390 &CPDF_StreamContentParser::Handle_ShowText_Positioning}, | 390 &CPDF_StreamContentParser::Handle_SetColorPS_Stroke}, |
391 {FXBSTR_ID('T', 'L', 0, 0), | 391 {FXBSTR_ID('T', '*', 0, 0), |
392 &CPDF_StreamContentParser::Handle_SetTextLeading}, | 392 &CPDF_StreamContentParser::Handle_MoveToNextLine}, |
393 {FXBSTR_ID('T', 'c', 0, 0), &CPDF_StreamContentParser::Handle_SetCharSpace}, | 393 {FXBSTR_ID('T', 'D', 0, 0), |
394 {FXBSTR_ID('T', 'd', 0, 0), | 394 &CPDF_StreamContentParser::Handle_MoveTextPoint_SetLeading}, |
395 &CPDF_StreamContentParser::Handle_MoveTextPoint}, | 395 {FXBSTR_ID('T', 'J', 0, 0), |
396 {FXBSTR_ID('T', 'f', 0, 0), &CPDF_StreamContentParser::Handle_SetFont}, | 396 &CPDF_StreamContentParser::Handle_ShowText_Positioning}, |
397 {FXBSTR_ID('T', 'j', 0, 0), &CPDF_StreamContentParser::Handle_ShowText}, | 397 {FXBSTR_ID('T', 'L', 0, 0), |
398 {FXBSTR_ID('T', 'm', 0, 0), | 398 &CPDF_StreamContentParser::Handle_SetTextLeading}, |
399 &CPDF_StreamContentParser::Handle_SetTextMatrix}, | 399 {FXBSTR_ID('T', 'c', 0, 0), |
400 {FXBSTR_ID('T', 'r', 0, 0), | 400 &CPDF_StreamContentParser::Handle_SetCharSpace}, |
401 &CPDF_StreamContentParser::Handle_SetTextRenderMode}, | 401 {FXBSTR_ID('T', 'd', 0, 0), |
402 {FXBSTR_ID('T', 's', 0, 0), &CPDF_StreamContentParser::Handle_SetTextRise}, | 402 &CPDF_StreamContentParser::Handle_MoveTextPoint}, |
403 {FXBSTR_ID('T', 'w', 0, 0), &CPDF_StreamContentParser::Handle_SetWordSpace}, | 403 {FXBSTR_ID('T', 'f', 0, 0), &CPDF_StreamContentParser::Handle_SetFont}, |
404 {FXBSTR_ID('T', 'z', 0, 0), &CPDF_StreamContentParser::Handle_SetHorzScale}, | 404 {FXBSTR_ID('T', 'j', 0, 0), &CPDF_StreamContentParser::Handle_ShowText}, |
405 {FXBSTR_ID('W', 0, 0, 0), &CPDF_StreamContentParser::Handle_Clip}, | 405 {FXBSTR_ID('T', 'm', 0, 0), |
406 {FXBSTR_ID('W', '*', 0, 0), &CPDF_StreamContentParser::Handle_EOClip}, | 406 &CPDF_StreamContentParser::Handle_SetTextMatrix}, |
407 {FXBSTR_ID('b', 0, 0, 0), | 407 {FXBSTR_ID('T', 'r', 0, 0), |
408 &CPDF_StreamContentParser::Handle_CloseFillStrokePath}, | 408 &CPDF_StreamContentParser::Handle_SetTextRenderMode}, |
409 {FXBSTR_ID('b', '*', 0, 0), | 409 {FXBSTR_ID('T', 's', 0, 0), |
410 &CPDF_StreamContentParser::Handle_CloseEOFillStrokePath}, | 410 &CPDF_StreamContentParser::Handle_SetTextRise}, |
411 {FXBSTR_ID('c', 0, 0, 0), &CPDF_StreamContentParser::Handle_CurveTo_123}, | 411 {FXBSTR_ID('T', 'w', 0, 0), |
412 {FXBSTR_ID('c', 'm', 0, 0), &CPDF_StreamContentParser::Handle_ConcatMatrix}, | 412 &CPDF_StreamContentParser::Handle_SetWordSpace}, |
413 {FXBSTR_ID('c', 's', 0, 0), | 413 {FXBSTR_ID('T', 'z', 0, 0), |
414 &CPDF_StreamContentParser::Handle_SetColorSpace_Fill}, | 414 &CPDF_StreamContentParser::Handle_SetHorzScale}, |
415 {FXBSTR_ID('d', 0, 0, 0), &CPDF_StreamContentParser::Handle_SetDash}, | 415 {FXBSTR_ID('W', 0, 0, 0), &CPDF_StreamContentParser::Handle_Clip}, |
416 {FXBSTR_ID('d', '0', 0, 0), &CPDF_StreamContentParser::Handle_SetCharWidth}, | 416 {FXBSTR_ID('W', '*', 0, 0), &CPDF_StreamContentParser::Handle_EOClip}, |
417 {FXBSTR_ID('d', '1', 0, 0), | 417 {FXBSTR_ID('b', 0, 0, 0), |
418 &CPDF_StreamContentParser::Handle_SetCachedDevice}, | 418 &CPDF_StreamContentParser::Handle_CloseFillStrokePath}, |
419 {FXBSTR_ID('f', 0, 0, 0), &CPDF_StreamContentParser::Handle_FillPath}, | 419 {FXBSTR_ID('b', '*', 0, 0), |
420 {FXBSTR_ID('f', '*', 0, 0), &CPDF_StreamContentParser::Handle_EOFillPath}, | 420 &CPDF_StreamContentParser::Handle_CloseEOFillStrokePath}, |
421 {FXBSTR_ID('g', 0, 0, 0), &CPDF_StreamContentParser::Handle_SetGray_Fill}, | 421 {FXBSTR_ID('c', 0, 0, 0), &CPDF_StreamContentParser::Handle_CurveTo_123}, |
422 {FXBSTR_ID('g', 's', 0, 0), | 422 {FXBSTR_ID('c', 'm', 0, 0), |
423 &CPDF_StreamContentParser::Handle_SetExtendGraphState}, | 423 &CPDF_StreamContentParser::Handle_ConcatMatrix}, |
424 {FXBSTR_ID('h', 0, 0, 0), &CPDF_StreamContentParser::Handle_ClosePath}, | 424 {FXBSTR_ID('c', 's', 0, 0), |
425 {FXBSTR_ID('i', 0, 0, 0), &CPDF_StreamContentParser::Handle_SetFlat}, | 425 &CPDF_StreamContentParser::Handle_SetColorSpace_Fill}, |
426 {FXBSTR_ID('j', 0, 0, 0), &CPDF_StreamContentParser::Handle_SetLineJoin}, | 426 {FXBSTR_ID('d', 0, 0, 0), &CPDF_StreamContentParser::Handle_SetDash}, |
427 {FXBSTR_ID('k', 0, 0, 0), | 427 {FXBSTR_ID('d', '0', 0, 0), |
428 &CPDF_StreamContentParser::Handle_SetCMYKColor_Fill}, | 428 &CPDF_StreamContentParser::Handle_SetCharWidth}, |
429 {FXBSTR_ID('l', 0, 0, 0), &CPDF_StreamContentParser::Handle_LineTo}, | 429 {FXBSTR_ID('d', '1', 0, 0), |
430 {FXBSTR_ID('m', 0, 0, 0), &CPDF_StreamContentParser::Handle_MoveTo}, | 430 &CPDF_StreamContentParser::Handle_SetCachedDevice}, |
431 {FXBSTR_ID('n', 0, 0, 0), &CPDF_StreamContentParser::Handle_EndPath}, | 431 {FXBSTR_ID('f', 0, 0, 0), &CPDF_StreamContentParser::Handle_FillPath}, |
432 {FXBSTR_ID('q', 0, 0, 0), &CPDF_StreamContentParser::Handle_SaveGraphState}, | 432 {FXBSTR_ID('f', '*', 0, 0), &CPDF_StreamContentParser::Handle_EOFillPath}, |
433 {FXBSTR_ID('r', 'e', 0, 0), &CPDF_StreamContentParser::Handle_Rectangle}, | 433 {FXBSTR_ID('g', 0, 0, 0), &CPDF_StreamContentParser::Handle_SetGray_Fill}, |
434 {FXBSTR_ID('r', 'g', 0, 0), | 434 {FXBSTR_ID('g', 's', 0, 0), |
435 &CPDF_StreamContentParser::Handle_SetRGBColor_Fill}, | 435 &CPDF_StreamContentParser::Handle_SetExtendGraphState}, |
436 {FXBSTR_ID('r', 'i', 0, 0), | 436 {FXBSTR_ID('h', 0, 0, 0), &CPDF_StreamContentParser::Handle_ClosePath}, |
437 &CPDF_StreamContentParser::Handle_SetRenderIntent}, | 437 {FXBSTR_ID('i', 0, 0, 0), &CPDF_StreamContentParser::Handle_SetFlat}, |
438 {FXBSTR_ID('s', 0, 0, 0), | 438 {FXBSTR_ID('j', 0, 0, 0), &CPDF_StreamContentParser::Handle_SetLineJoin}, |
439 &CPDF_StreamContentParser::Handle_CloseStrokePath}, | 439 {FXBSTR_ID('k', 0, 0, 0), |
440 {FXBSTR_ID('s', 'c', 0, 0), | 440 &CPDF_StreamContentParser::Handle_SetCMYKColor_Fill}, |
441 &CPDF_StreamContentParser::Handle_SetColor_Fill}, | 441 {FXBSTR_ID('l', 0, 0, 0), &CPDF_StreamContentParser::Handle_LineTo}, |
442 {FXBSTR_ID('s', 'c', 'n', 0), | 442 {FXBSTR_ID('m', 0, 0, 0), &CPDF_StreamContentParser::Handle_MoveTo}, |
443 &CPDF_StreamContentParser::Handle_SetColorPS_Fill}, | 443 {FXBSTR_ID('n', 0, 0, 0), &CPDF_StreamContentParser::Handle_EndPath}, |
444 {FXBSTR_ID('s', 'h', 0, 0), &CPDF_StreamContentParser::Handle_ShadeFill}, | 444 {FXBSTR_ID('q', 0, 0, 0), |
445 {FXBSTR_ID('v', 0, 0, 0), &CPDF_StreamContentParser::Handle_CurveTo_23}, | 445 &CPDF_StreamContentParser::Handle_SaveGraphState}, |
446 {FXBSTR_ID('w', 0, 0, 0), &CPDF_StreamContentParser::Handle_SetLineWidth}, | 446 {FXBSTR_ID('r', 'e', 0, 0), &CPDF_StreamContentParser::Handle_Rectangle}, |
447 {FXBSTR_ID('y', 0, 0, 0), &CPDF_StreamContentParser::Handle_CurveTo_13}, | 447 {FXBSTR_ID('r', 'g', 0, 0), |
448 }; | 448 &CPDF_StreamContentParser::Handle_SetRGBColor_Fill}, |
| 449 {FXBSTR_ID('r', 'i', 0, 0), |
| 450 &CPDF_StreamContentParser::Handle_SetRenderIntent}, |
| 451 {FXBSTR_ID('s', 0, 0, 0), |
| 452 &CPDF_StreamContentParser::Handle_CloseStrokePath}, |
| 453 {FXBSTR_ID('s', 'c', 0, 0), |
| 454 &CPDF_StreamContentParser::Handle_SetColor_Fill}, |
| 455 {FXBSTR_ID('s', 'c', 'n', 0), |
| 456 &CPDF_StreamContentParser::Handle_SetColorPS_Fill}, |
| 457 {FXBSTR_ID('s', 'h', 0, 0), &CPDF_StreamContentParser::Handle_ShadeFill}, |
| 458 {FXBSTR_ID('v', 0, 0, 0), &CPDF_StreamContentParser::Handle_CurveTo_23}, |
| 459 {FXBSTR_ID('w', 0, 0, 0), &CPDF_StreamContentParser::Handle_SetLineWidth}, |
| 460 {FXBSTR_ID('y', 0, 0, 0), &CPDF_StreamContentParser::Handle_CurveTo_13}, |
| 461 }); |
| 462 } |
449 | 463 |
450 void CPDF_StreamContentParser::OnOperator(const FX_CHAR* op) { | 464 void CPDF_StreamContentParser::OnOperator(const FX_CHAR* op) { |
451 int i = 0; | 465 int i = 0; |
452 FX_DWORD opid = 0; | 466 FX_DWORD opid = 0; |
453 while (i < 4 && op[i]) { | 467 while (i < 4 && op[i]) { |
454 opid = (opid << 8) + op[i]; | 468 opid = (opid << 8) + op[i]; |
455 i++; | 469 i++; |
456 } | 470 } |
457 while (i < 4) { | 471 while (i < 4) { |
458 opid <<= 8; | 472 opid <<= 8; |
459 i++; | 473 i++; |
460 } | 474 } |
461 | 475 |
| 476 static const OpCodes s_OpCodes = InitializeOpCodes(); |
| 477 |
462 auto it = s_OpCodes.find(opid); | 478 auto it = s_OpCodes.find(opid); |
463 if (it != s_OpCodes.end()) | 479 if (it != s_OpCodes.end()) |
464 (this->*it->second)(); | 480 (this->*it->second)(); |
465 } | 481 } |
466 | 482 |
467 void CPDF_StreamContentParser::Handle_CloseFillStrokePath() { | 483 void CPDF_StreamContentParser::Handle_CloseFillStrokePath() { |
468 if (m_Options.m_bTextOnly) { | 484 if (m_Options.m_bTextOnly) { |
469 return; | 485 return; |
470 } | 486 } |
471 Handle_ClosePath(); | 487 Handle_ClosePath(); |
(...skipping 1313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1785 } else { | 1801 } else { |
1786 PDF_ReplaceAbbr(pElement); | 1802 PDF_ReplaceAbbr(pElement); |
1787 } | 1803 } |
1788 } | 1804 } |
1789 break; | 1805 break; |
1790 } | 1806 } |
1791 default: | 1807 default: |
1792 break; | 1808 break; |
1793 } | 1809 } |
1794 } | 1810 } |
OLD | NEW |