Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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/fpdfdoc/cpvt_generateap.h" | 7 #include "core/fpdfdoc/cpvt_generateap.h" |
| 8 | 8 |
| 9 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" | 9 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" |
| 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" | 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" |
| (...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 436 pStreamResFontList->SetAtReference(sFontName, pDoc, pFontDict); | 436 pStreamResFontList->SetAtReference(sFontName, pDoc, pFontDict); |
| 437 } else { | 437 } else { |
| 438 pStreamDict->SetAt("Resources", pFormDict->GetDictBy("DR")->Clone()); | 438 pStreamDict->SetAt("Resources", pFormDict->GetDictBy("DR")->Clone()); |
| 439 pStreamResList = pStreamDict->GetDictBy("Resources"); | 439 pStreamResList = pStreamDict->GetDictBy("Resources"); |
| 440 } | 440 } |
| 441 } | 441 } |
| 442 } | 442 } |
| 443 return true; | 443 return true; |
| 444 } | 444 } |
| 445 | 445 |
| 446 CPDF_Dictionary* GenerateExtGStateDict(CFX_ByteString sName, | |
| 447 FX_FLOAT fCAForStroke, | |
| 448 FX_FLOAT fCAForNonStroke, | |
| 449 CFX_ByteString sBlendMode) { | |
| 450 CPDF_Dictionary* pGSDict = new CPDF_Dictionary; | |
| 451 pGSDict->SetAtString("Type", "ExtGState"); | |
| 452 pGSDict->SetAtNumber("CA", fCAForStroke); | |
| 453 pGSDict->SetAtNumber("ca", fCAForNonStroke); | |
| 454 pGSDict->SetAtBoolean("AIS", false); | |
| 455 pGSDict->SetAtString("BM", sBlendMode); | |
| 456 | |
| 457 CPDF_Dictionary* pExtGStateDict = new CPDF_Dictionary; | |
| 458 pExtGStateDict->SetAt(sName, pGSDict); | |
| 459 | |
| 460 return pExtGStateDict; | |
| 461 } | |
| 462 | |
| 446 } // namespace | 463 } // namespace |
| 447 | 464 |
| 448 bool FPDF_GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) { | 465 bool FPDF_GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) { |
| 449 if (!pAnnotDict || pAnnotDict->GetStringBy("Subtype") != "Widget") | 466 if (!pAnnotDict || pAnnotDict->GetStringBy("Subtype") != "Widget") |
| 450 return false; | 467 return false; |
| 451 | 468 |
| 452 CFX_ByteString field_type = FPDF_GetFieldAttr(pAnnotDict, "FT")->GetString(); | 469 CFX_ByteString field_type = FPDF_GetFieldAttr(pAnnotDict, "FT")->GetString(); |
| 453 uint32_t flags = FPDF_GetFieldAttr(pAnnotDict, "Ff") | 470 uint32_t flags = FPDF_GetFieldAttr(pAnnotDict, "Ff") |
| 454 ? FPDF_GetFieldAttr(pAnnotDict, "Ff")->GetInteger() | 471 ? FPDF_GetFieldAttr(pAnnotDict, "Ff")->GetInteger() |
| 455 : 0; | 472 : 0; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 494 } | 511 } |
| 495 | 512 |
| 496 bool CPVT_GenerateAP::GenerateHighlightAP(CPDF_Document* pDoc, | 513 bool CPVT_GenerateAP::GenerateHighlightAP(CPDF_Document* pDoc, |
| 497 CPDF_Dictionary* pAnnotDict) { | 514 CPDF_Dictionary* pAnnotDict) { |
| 498 // If AP dictionary exists, we use the appearance defined in the | 515 // If AP dictionary exists, we use the appearance defined in the |
| 499 // existing AP dictionary. | 516 // existing AP dictionary. |
| 500 if (pAnnotDict->KeyExist("AP")) | 517 if (pAnnotDict->KeyExist("AP")) |
| 501 return false; | 518 return false; |
| 502 | 519 |
| 503 CFX_ByteTextBuf sAppStream; | 520 CFX_ByteTextBuf sAppStream; |
| 504 sAppStream << "/GS gs "; | 521 CFX_ByteString sExtGSDictName = "GS"; |
| 522 sAppStream << "/" << sExtGSDictName << " gs "; | |
| 505 | 523 |
| 506 if (pAnnotDict->KeyExist("C")) { | 524 if (pAnnotDict->KeyExist("C")) { |
| 507 CPDF_Array* pColor = pAnnotDict->GetArrayBy("C"); | 525 CPDF_Array* pColor = pAnnotDict->GetArrayBy("C"); |
| 508 CPVT_Color color = CPVT_Color::ParseColor(*pColor); | 526 CPVT_Color color = CPVT_Color::ParseColor(*pColor); |
| 509 sAppStream << CPVT_GenerateAP::GenerateColorAP(color, TRUE); | 527 sAppStream << CPVT_GenerateAP::GenerateColorAP(color, TRUE); |
| 510 } else { | 528 } else { |
| 511 // Defaults to 0xFFFF00 color for highlight. | 529 // Defaults to 0xFFFF00 color for highlight. |
| 512 sAppStream << "1 1 0 rg \n"; | 530 sAppStream << "1 1 0 rg \n"; |
| 513 } | 531 } |
| 514 | 532 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 529 | 547 |
| 530 pNormalStream->SetData(reinterpret_cast<uint8_t*>(sAppStream.GetBuffer()), | 548 pNormalStream->SetData(reinterpret_cast<uint8_t*>(sAppStream.GetBuffer()), |
| 531 sAppStream.GetSize(), FALSE, FALSE); | 549 sAppStream.GetSize(), FALSE, FALSE); |
| 532 | 550 |
| 533 CPDF_Dictionary* pStreamDict = pNormalStream->GetDict(); | 551 CPDF_Dictionary* pStreamDict = pNormalStream->GetDict(); |
| 534 pStreamDict->SetAtInteger("FormType", 1); | 552 pStreamDict->SetAtInteger("FormType", 1); |
| 535 pStreamDict->SetAtString("Subtype", "Form"); | 553 pStreamDict->SetAtString("Subtype", "Form"); |
| 536 pStreamDict->SetAtMatrix("Matrix", CFX_Matrix()); | 554 pStreamDict->SetAtMatrix("Matrix", CFX_Matrix()); |
| 537 pStreamDict->SetAtRect("BBox", rect); | 555 pStreamDict->SetAtRect("BBox", rect); |
| 538 | 556 |
| 539 CPDF_Dictionary* pGSDict = new CPDF_Dictionary; | |
| 540 pGSDict->SetAtString("Type", "ExtGState"); | |
| 541 pGSDict->SetAtNumber("ca", 1); | |
| 542 pGSDict->SetAtNumber("CA", 1); | |
| 543 pGSDict->SetAtBoolean("AIS", false); | |
| 544 pGSDict->SetAtString("BM", "Multiply"); | |
| 545 | |
| 546 CPDF_Dictionary* pExtGStateDict = new CPDF_Dictionary; | |
| 547 pExtGStateDict->SetAt("GS", pGSDict); | |
| 548 | |
| 549 CPDF_Dictionary* pResourceDict = new CPDF_Dictionary; | 557 CPDF_Dictionary* pResourceDict = new CPDF_Dictionary; |
| 550 pResourceDict->SetAt("ExtGState", pExtGStateDict); | 558 FX_FLOAT fCAForStroke = |
| 559 pAnnotDict->KeyExist("CA") ? pAnnotDict->GetNumberBy("CA") : 1.0; | |
| 560 FX_FLOAT fCAForNonStroke = | |
| 561 pAnnotDict->KeyExist("ca") ? pAnnotDict->GetNumberBy("ca") : 1.0; | |
|
jaepark
2016/08/01 23:10:52
Although I think this is correct implementation, o
Lei Zhang
2016/08/01 23:16:24
Have you considered adding more tests to exercise
| |
| 562 pResourceDict->SetAt("ExtGState", | |
| 563 GenerateExtGStateDict(sExtGSDictName, fCAForStroke, | |
| 564 fCAForNonStroke, "Multiply")); | |
| 551 | 565 |
| 552 pStreamDict->SetAt("Resources", pResourceDict); | 566 pStreamDict->SetAt("Resources", pResourceDict); |
| 553 return true; | 567 return true; |
| 568 } | |
| 569 | |
| 570 bool CPVT_GenerateAP::GenerateUnderlineAP(CPDF_Document* pDoc, | |
| 571 CPDF_Dictionary* pAnnotDict) { | |
| 572 // If AP dictionary exists, we use the appearance defined in the | |
| 573 // existing AP dictionary. | |
| 574 if (pAnnotDict->KeyExist("AP")) | |
| 575 return false; | |
| 576 | |
| 577 CFX_ByteTextBuf sAppStream; | |
| 578 CFX_ByteString sExtGSDictName = "GS"; | |
| 579 sAppStream << "/" << sExtGSDictName << " gs "; | |
| 580 | |
| 581 if (pAnnotDict->KeyExist("C")) { | |
| 582 CPDF_Array* pColor = pAnnotDict->GetArrayBy("C"); | |
| 583 CPVT_Color color = CPVT_Color::ParseColor(*pColor); | |
| 584 sAppStream << CPVT_GenerateAP::GenerateColorAP(color, FALSE); | |
| 585 } else { | |
| 586 // Defaults to 0x000000 color for underline. | |
| 587 sAppStream << "0 0 0 RG\n"; | |
| 588 } | |
| 589 | |
| 590 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); | |
| 591 rect.Normalize(); | |
| 592 | |
| 593 FX_FLOAT fLineWidth = 1.0; | |
| 594 sAppStream << fLineWidth << " w " << rect.left << " " | |
| 595 << rect.bottom + fLineWidth << " m " << rect.right << " " | |
| 596 << rect.bottom + fLineWidth << " l S\n"; | |
| 597 | |
| 598 CPDF_Dictionary* pAPDict = new CPDF_Dictionary; | |
| 599 pAnnotDict->SetAt("AP", pAPDict); | |
| 600 | |
| 601 CPDF_Stream* pNormalStream = new CPDF_Stream(nullptr, 0, nullptr); | |
| 602 int32_t objnum = pDoc->AddIndirectObject(pNormalStream); | |
| 603 pAnnotDict->GetDictBy("AP")->SetAtReference("N", pDoc, objnum); | |
| 604 | |
| 605 pNormalStream->SetData(reinterpret_cast<uint8_t*>(sAppStream.GetBuffer()), | |
| 606 sAppStream.GetSize(), FALSE, FALSE); | |
| 607 | |
| 608 CPDF_Dictionary* pStreamDict = pNormalStream->GetDict(); | |
| 609 pStreamDict->SetAtInteger("FormType", 1); | |
| 610 pStreamDict->SetAtString("Subtype", "Form"); | |
| 611 pStreamDict->SetAtMatrix("Matrix", CFX_Matrix()); | |
| 612 pStreamDict->SetAtRect("BBox", rect); | |
| 613 | |
| 614 CPDF_Dictionary* pResourceDict = new CPDF_Dictionary; | |
| 615 FX_FLOAT fCAForStroke = | |
| 616 pAnnotDict->KeyExist("CA") ? pAnnotDict->GetNumberBy("CA") : 1.0; | |
| 617 FX_FLOAT fCAForNonStroke = | |
| 618 pAnnotDict->KeyExist("ca") ? pAnnotDict->GetNumberBy("ca") : 1.0; | |
| 619 pResourceDict->SetAt("ExtGState", | |
| 620 GenerateExtGStateDict(sExtGSDictName, fCAForStroke, | |
| 621 fCAForNonStroke, "Normal")); | |
| 622 | |
| 623 pStreamDict->SetAt("Resources", pResourceDict); | |
| 624 return true; | |
| 554 } | 625 } |
| 555 | 626 |
| 556 // Static. | 627 // Static. |
| 557 CFX_ByteString CPVT_GenerateAP::GenerateEditAP( | 628 CFX_ByteString CPVT_GenerateAP::GenerateEditAP( |
| 558 IPVT_FontMap* pFontMap, | 629 IPVT_FontMap* pFontMap, |
| 559 CPDF_VariableText::Iterator* pIterator, | 630 CPDF_VariableText::Iterator* pIterator, |
| 560 const CFX_FloatPoint& ptOffset, | 631 const CFX_FloatPoint& ptOffset, |
| 561 FX_BOOL bContinuous, | 632 FX_BOOL bContinuous, |
| 562 uint16_t SubWord) { | 633 uint16_t SubWord) { |
| 563 CFX_ByteTextBuf sEditStream; | 634 CFX_ByteTextBuf sEditStream; |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 811 int32_t nFontIndex, | 882 int32_t nFontIndex, |
| 812 FX_FLOAT fFontSize) { | 883 FX_FLOAT fFontSize) { |
| 813 CFX_ByteTextBuf sRet; | 884 CFX_ByteTextBuf sRet; |
| 814 if (pFontMap) { | 885 if (pFontMap) { |
| 815 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); | 886 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); |
| 816 if (sFontAlias.GetLength() > 0 && fFontSize > 0) | 887 if (sFontAlias.GetLength() > 0 && fFontSize > 0) |
| 817 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; | 888 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; |
| 818 } | 889 } |
| 819 return sRet.MakeString(); | 890 return sRet.MakeString(); |
| 820 } | 891 } |
| OLD | NEW |