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

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

Issue 2193983002: Generate default AP stream for highlight annotation. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: 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
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 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 CPDF_Dictionary* pAnnotDict) { 486 CPDF_Dictionary* pAnnotDict) {
487 return GenerateWidgetAP(pDoc, pAnnotDict, 1); 487 return GenerateWidgetAP(pDoc, pAnnotDict, 1);
488 } 488 }
489 489
490 // Static. 490 // Static.
491 FX_BOOL CPVT_GenerateAP::GenerateListBoxAP(CPDF_Document* pDoc, 491 FX_BOOL CPVT_GenerateAP::GenerateListBoxAP(CPDF_Document* pDoc,
492 CPDF_Dictionary* pAnnotDict) { 492 CPDF_Dictionary* pAnnotDict) {
493 return GenerateWidgetAP(pDoc, pAnnotDict, 2); 493 return GenerateWidgetAP(pDoc, pAnnotDict, 2);
494 } 494 }
495 495
496 FX_BOOL CPVT_GenerateAP::GenerateHighlightAP(CPDF_Document* pDoc,
497 CPDF_Dictionary* pAnnotDict) {
498 // If AP dictionary exists, we use the appearance defined in the
499 // existing AP dictionary.
500 if (pAnnotDict->KeyExist("AP"))
501 return FALSE;
502
503 CFX_ByteTextBuf sAppStream;
504 sAppStream << "/TransGs gs ";
505
506 if (pAnnotDict->KeyExist("C")) {
507 CPDF_Array* pColor = pAnnotDict->GetArrayBy("C");
508 CPVT_Color color = CPVT_Color::ParseColor(*pColor);
509 sAppStream << CPVT_GenerateAP::GenerateColorAP(color, TRUE);
510 } else {
511 // Defaults to 0xFFFF0 color for highlight.
Lei Zhang 2016/07/29 22:20:50 0xFFFF00 ?
jaepark 2016/07/29 23:32:26 Done.
512 sAppStream << "1 1 0 rg \n";
513 }
514
515 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect");
516 rect.Normalize();
517
518 sAppStream << rect.left << " " << rect.top << " m " << rect.right << " "
519 << rect.top << " l " << rect.right << " " << rect.bottom << " l "
520 << rect.left << " " << rect.bottom << " l "
521 << "h f\n";
522
523 CPDF_Dictionary* pAPDict = new CPDF_Dictionary;
524 pAnnotDict->SetAt("AP", pAPDict);
525
526 CPDF_Stream* pNormalStream = new CPDF_Stream(nullptr, 0, nullptr);
527 int32_t objnum = pDoc->AddIndirectObject(pNormalStream);
528 pAnnotDict->GetDictBy("AP")->SetAtReference("N", pDoc, objnum);
529
530 pNormalStream->SetData((uint8_t*)sAppStream.GetBuffer(), sAppStream.GetSize(),
Lei Zhang 2016/07/29 22:20:50 No C-style casting. Use static_cast or reinterpret
jaepark 2016/07/29 23:32:26 Done.
531 FALSE, FALSE);
532
533 CPDF_Dictionary* pStreamDict = pNormalStream->GetDict();
534 pStreamDict->SetAtInteger("FormType", 1);
535 pStreamDict->SetAtString("Subtype", "Form");
536 pStreamDict->SetAtMatrix("Matrix", CFX_Matrix());
537 pStreamDict->SetAtRect("BBox", rect);
538
539 CPDF_Dictionary* pTransGsDict = new CPDF_Dictionary;
540 pTransGsDict->SetAtString("Type", "ExtGState");
541 pTransGsDict->SetAtInteger("ca", 1);
542 pTransGsDict->SetAtString("CA", 1);
543 pTransGsDict->SetAtBoolean("AIS", false);
544 pTransGsDict->SetAtString("BM", "Multiply");
545
546 CPDF_Dictionary* pExtGStateDict = new CPDF_Dictionary;
547 pExtGStateDict->SetAt("TransGs", pTransGsDict);
Lei Zhang 2016/07/29 22:20:50 So if we have multiple highlight annotations, can
jaepark 2016/07/29 23:32:26 We can reuse "TransGs" because the scope of a name
Lei Zhang 2016/07/30 00:56:44 How about just "GS" then?
jaepark 2016/07/30 01:28:27 Done.
548
549 CPDF_Dictionary* pResourceDict = new CPDF_Dictionary;
550 pResourceDict->SetAt("ExtGState", pExtGStateDict);
551
552 pStreamDict->SetAt("Resources", pResourceDict);
553 return TRUE;
554 }
555
496 // Static. 556 // Static.
497 CFX_ByteString CPVT_GenerateAP::GenerateEditAP( 557 CFX_ByteString CPVT_GenerateAP::GenerateEditAP(
498 IPVT_FontMap* pFontMap, 558 IPVT_FontMap* pFontMap,
499 CPDF_VariableText::Iterator* pIterator, 559 CPDF_VariableText::Iterator* pIterator,
500 const CFX_FloatPoint& ptOffset, 560 const CFX_FloatPoint& ptOffset,
501 FX_BOOL bContinuous, 561 FX_BOOL bContinuous,
502 uint16_t SubWord) { 562 uint16_t SubWord) {
503 CFX_ByteTextBuf sEditStream; 563 CFX_ByteTextBuf sEditStream;
504 CFX_ByteTextBuf sLineStream; 564 CFX_ByteTextBuf sLineStream;
505 CFX_ByteTextBuf sWords; 565 CFX_ByteTextBuf sWords;
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 int32_t nFontIndex, 811 int32_t nFontIndex,
752 FX_FLOAT fFontSize) { 812 FX_FLOAT fFontSize) {
753 CFX_ByteTextBuf sRet; 813 CFX_ByteTextBuf sRet;
754 if (pFontMap) { 814 if (pFontMap) {
755 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); 815 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex);
756 if (sFontAlias.GetLength() > 0 && fFontSize > 0) 816 if (sFontAlias.GetLength() > 0 && fFontSize > 0)
757 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; 817 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n";
758 } 818 }
759 return sRet.MakeString(); 819 return sRet.MakeString();
760 } 820 }
OLDNEW
« core/fpdfdoc/cpvt_generateap.h ('K') | « core/fpdfdoc/cpvt_generateap.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698