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

Side by Side Diff: core/fpdfdoc/cpvt_generateap.cpp

Issue 2205543002: Generate default AP stream for underline annotation. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Generate default AP stream for underline annotation. Created 4 years, 4 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 | « core/fpdfdoc/cpvt_generateap.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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,
Lei Zhang 2016/08/02 01:22:57 Pass CFX_ByteStrings by const-ref?
jaepark 2016/08/02 20:31:34 Done.
447 FX_FLOAT fOpacity,
448 CFX_ByteString sBlendMode) {
449 CPDF_Dictionary* pGSDict = new CPDF_Dictionary;
450 pGSDict->SetAtString("Type", "ExtGState");
451 pGSDict->SetAtNumber("CA", fOpacity);
452 pGSDict->SetAtNumber("ca", fOpacity);
453 pGSDict->SetAtBoolean("AIS", false);
454 pGSDict->SetAtString("BM", sBlendMode);
455
456 CPDF_Dictionary* pExtGStateDict = new CPDF_Dictionary;
457 pExtGStateDict->SetAt(sName, pGSDict);
458
459 return pExtGStateDict;
460 }
461
446 } // namespace 462 } // namespace
447 463
448 bool FPDF_GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) { 464 bool FPDF_GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) {
449 if (!pAnnotDict || pAnnotDict->GetStringBy("Subtype") != "Widget") 465 if (!pAnnotDict || pAnnotDict->GetStringBy("Subtype") != "Widget")
450 return false; 466 return false;
451 467
452 CFX_ByteString field_type = FPDF_GetFieldAttr(pAnnotDict, "FT")->GetString(); 468 CFX_ByteString field_type = FPDF_GetFieldAttr(pAnnotDict, "FT")->GetString();
453 uint32_t flags = FPDF_GetFieldAttr(pAnnotDict, "Ff") 469 uint32_t flags = FPDF_GetFieldAttr(pAnnotDict, "Ff")
454 ? FPDF_GetFieldAttr(pAnnotDict, "Ff")->GetInteger() 470 ? FPDF_GetFieldAttr(pAnnotDict, "Ff")->GetInteger()
455 : 0; 471 : 0;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 } 510 }
495 511
496 bool CPVT_GenerateAP::GenerateHighlightAP(CPDF_Document* pDoc, 512 bool CPVT_GenerateAP::GenerateHighlightAP(CPDF_Document* pDoc,
497 CPDF_Dictionary* pAnnotDict) { 513 CPDF_Dictionary* pAnnotDict) {
498 // If AP dictionary exists, we use the appearance defined in the 514 // If AP dictionary exists, we use the appearance defined in the
499 // existing AP dictionary. 515 // existing AP dictionary.
500 if (pAnnotDict->KeyExist("AP")) 516 if (pAnnotDict->KeyExist("AP"))
501 return false; 517 return false;
502 518
503 CFX_ByteTextBuf sAppStream; 519 CFX_ByteTextBuf sAppStream;
504 sAppStream << "/GS gs "; 520 CFX_ByteString sExtGSDictName = "GS";
521 sAppStream << "/" << sExtGSDictName << " gs ";
505 522
506 if (pAnnotDict->KeyExist("C")) { 523 if (pAnnotDict->KeyExist("C")) {
507 CPDF_Array* pColor = pAnnotDict->GetArrayBy("C"); 524 CPDF_Array* pColor = pAnnotDict->GetArrayBy("C");
508 CPVT_Color color = CPVT_Color::ParseColor(*pColor); 525 CPVT_Color color = CPVT_Color::ParseColor(*pColor);
509 sAppStream << CPVT_GenerateAP::GenerateColorAP(color, TRUE); 526 sAppStream << CPVT_GenerateAP::GenerateColorAP(color, TRUE);
510 } else { 527 } else {
511 // Defaults to 0xFFFF00 color for highlight. 528 // Defaults to 0xFFFF00 color for highlight.
512 sAppStream << "1 1 0 rg \n"; 529 sAppStream << "1 1 0 rg \n";
513 } 530 }
514 531
(...skipping 14 matching lines...) Expand all
529 546
530 pNormalStream->SetData(reinterpret_cast<uint8_t*>(sAppStream.GetBuffer()), 547 pNormalStream->SetData(reinterpret_cast<uint8_t*>(sAppStream.GetBuffer()),
531 sAppStream.GetSize(), FALSE, FALSE); 548 sAppStream.GetSize(), FALSE, FALSE);
532 549
533 CPDF_Dictionary* pStreamDict = pNormalStream->GetDict(); 550 CPDF_Dictionary* pStreamDict = pNormalStream->GetDict();
534 pStreamDict->SetAtInteger("FormType", 1); 551 pStreamDict->SetAtInteger("FormType", 1);
535 pStreamDict->SetAtString("Subtype", "Form"); 552 pStreamDict->SetAtString("Subtype", "Form");
536 pStreamDict->SetAtMatrix("Matrix", CFX_Matrix()); 553 pStreamDict->SetAtMatrix("Matrix", CFX_Matrix());
537 pStreamDict->SetAtRect("BBox", rect); 554 pStreamDict->SetAtRect("BBox", rect);
538 555
539 CPDF_Dictionary* pGSDict = new CPDF_Dictionary; 556 CPDF_Dictionary* pResourceDict = new CPDF_Dictionary;
540 pGSDict->SetAtString("Type", "ExtGState");
541
542 FX_FLOAT fOpacity = 557 FX_FLOAT fOpacity =
543 pAnnotDict->KeyExist("CA") ? pAnnotDict->GetNumberBy("CA") : 1; 558 pAnnotDict->KeyExist("CA") ? pAnnotDict->GetNumberBy("CA") : 1;
544 pGSDict->SetAtNumber("ca", fOpacity); 559 pResourceDict->SetAt(
545 pGSDict->SetAtNumber("CA", fOpacity); 560 "ExtGState", GenerateExtGStateDict(sExtGSDictName, fOpacity, "Multiply"));
546 pGSDict->SetAtBoolean("AIS", false);
547 pGSDict->SetAtString("BM", "Multiply");
548
549 CPDF_Dictionary* pExtGStateDict = new CPDF_Dictionary;
550 pExtGStateDict->SetAt("GS", pGSDict);
551
552 CPDF_Dictionary* pResourceDict = new CPDF_Dictionary;
553 pResourceDict->SetAt("ExtGState", pExtGStateDict);
554 561
555 pStreamDict->SetAt("Resources", pResourceDict); 562 pStreamDict->SetAt("Resources", pResourceDict);
556 return true; 563 return true;
564 }
565
566 bool CPVT_GenerateAP::GenerateUnderlineAP(CPDF_Document* pDoc,
567 CPDF_Dictionary* pAnnotDict) {
568 // If AP dictionary exists, we use the appearance defined in the
569 // existing AP dictionary.
570 if (pAnnotDict->KeyExist("AP"))
571 return false;
572
573 CFX_ByteTextBuf sAppStream;
574 CFX_ByteString sExtGSDictName = "GS";
575 sAppStream << "/" << sExtGSDictName << " gs ";
576
577 if (pAnnotDict->KeyExist("C")) {
Lei Zhang 2016/08/02 01:22:57 Can this and the identical block in GenerateHighli
jaepark 2016/08/02 20:31:34 Done.
578 CPDF_Array* pColor = pAnnotDict->GetArrayBy("C");
579 CPVT_Color color = CPVT_Color::ParseColor(*pColor);
580 sAppStream << CPVT_GenerateAP::GenerateColorAP(color, FALSE);
581 } else {
582 // Defaults to 0x000000 color for underline.
583 sAppStream << "0 0 0 RG\n";
584 }
585
586 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect");
587 rect.Normalize();
588
589 FX_FLOAT fLineWidth = 1.0;
590 sAppStream << fLineWidth << " w " << rect.left << " "
591 << rect.bottom + fLineWidth << " m " << rect.right << " "
592 << rect.bottom + fLineWidth << " l S\n";
593
594 CPDF_Dictionary* pAPDict = new CPDF_Dictionary;
595 pAnnotDict->SetAt("AP", pAPDict);
596
597 CPDF_Stream* pNormalStream = new CPDF_Stream(nullptr, 0, nullptr);
598 int32_t objnum = pDoc->AddIndirectObject(pNormalStream);
599 pAnnotDict->GetDictBy("AP")->SetAtReference("N", pDoc, objnum);
600
601 pNormalStream->SetData(reinterpret_cast<uint8_t*>(sAppStream.GetBuffer()),
602 sAppStream.GetSize(), FALSE, FALSE);
603
604 CPDF_Dictionary* pStreamDict = pNormalStream->GetDict();
605 pStreamDict->SetAtInteger("FormType", 1);
606 pStreamDict->SetAtString("Subtype", "Form");
607 pStreamDict->SetAtMatrix("Matrix", CFX_Matrix());
608 pStreamDict->SetAtRect("BBox", rect);
609
610 CPDF_Dictionary* pResourceDict = new CPDF_Dictionary;
611 FX_FLOAT fOpacity =
612 pAnnotDict->KeyExist("CA") ? pAnnotDict->GetNumberBy("CA") : 1;
613 pResourceDict->SetAt(
614 "ExtGState", GenerateExtGStateDict(sExtGSDictName, fOpacity, "Normal"));
615
616 pStreamDict->SetAt("Resources", pResourceDict);
617 return true;
557 } 618 }
558 619
559 // Static. 620 // Static.
560 CFX_ByteString CPVT_GenerateAP::GenerateEditAP( 621 CFX_ByteString CPVT_GenerateAP::GenerateEditAP(
561 IPVT_FontMap* pFontMap, 622 IPVT_FontMap* pFontMap,
562 CPDF_VariableText::Iterator* pIterator, 623 CPDF_VariableText::Iterator* pIterator,
563 const CFX_FloatPoint& ptOffset, 624 const CFX_FloatPoint& ptOffset,
564 FX_BOOL bContinuous, 625 FX_BOOL bContinuous,
565 uint16_t SubWord) { 626 uint16_t SubWord) {
566 CFX_ByteTextBuf sEditStream; 627 CFX_ByteTextBuf sEditStream;
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 int32_t nFontIndex, 875 int32_t nFontIndex,
815 FX_FLOAT fFontSize) { 876 FX_FLOAT fFontSize) {
816 CFX_ByteTextBuf sRet; 877 CFX_ByteTextBuf sRet;
817 if (pFontMap) { 878 if (pFontMap) {
818 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); 879 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex);
819 if (sFontAlias.GetLength() > 0 && fFontSize > 0) 880 if (sFontAlias.GetLength() > 0 && fFontSize > 0)
820 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; 881 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n";
821 } 882 }
822 return sRet.MakeString(); 883 return sRet.MakeString();
823 } 884 }
OLDNEW
« no previous file with comments | « core/fpdfdoc/cpvt_generateap.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698