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

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

Issue 2270493002: Generate default AP stream for text 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
« 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 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 556
557 pStreamDict->SetAt("Resources", pResourceDict); 557 pStreamDict->SetAt("Resources", pResourceDict);
558 } 558 }
559 559
560 CFX_ByteString GetPaintOperatorString(bool bIsStrokeRect, bool bIsFillRect) { 560 CFX_ByteString GetPaintOperatorString(bool bIsStrokeRect, bool bIsFillRect) {
561 if (bIsStrokeRect) 561 if (bIsStrokeRect)
562 return bIsFillRect ? "b" : "s"; 562 return bIsFillRect ? "b" : "s";
563 return bIsFillRect ? "f" : "n"; 563 return bIsFillRect ? "f" : "n";
564 } 564 }
565 565
566 CFX_ByteString GenerateTextSymbolAP(const CFX_FloatRect& rect) {
567 CFX_ByteTextBuf sAppStream;
568 sAppStream << CPVT_GenerateAP::GenerateColorAP(
569 CPVT_Color(CPVT_Color::kRGB, 1, 1, 0), PaintOperation::FILL);
570 sAppStream << CPVT_GenerateAP::GenerateColorAP(
571 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), PaintOperation::STROKE);
572
573 const FX_FLOAT fBorderWidth = 1;
574 sAppStream << fBorderWidth << " w\n";
575
576 const FX_FLOAT fHalfWidth = fBorderWidth / 2;
577 const FX_FLOAT fTipDelta = 4;
578
579 const FX_FLOAT fLeftBound = rect.left + fHalfWidth;
Lei Zhang 2016/08/22 22:53:38 Can we create a new FloatRect, Inflate() it, and u
jaepark 2016/08/22 23:19:51 Done.
580 const FX_FLOAT fRightBound = rect.right - fHalfWidth;
581 const FX_FLOAT fBottomBound = rect.bottom + fHalfWidth;
582 const FX_FLOAT fTopBound = rect.top - fHalfWidth;
583
584 // Draw outer box.
585 sAppStream << fLeftBound << " " << fBottomBound + fTipDelta << " m\n"
586 << fLeftBound << " " << fTopBound << " l\n"
587 << fRightBound << " " << fTopBound << " l\n"
588 << fRightBound << " " << fBottomBound + fTipDelta << " l\n"
589 << fLeftBound + (2 * fTipDelta) << " " << fBottomBound + fTipDelta
590 << " l\n"
591 << fLeftBound + fTipDelta + (fTipDelta / 2) << " " << fBottomBound
592 << " l\n"
593 << fLeftBound + fTipDelta << " " << fBottomBound + fTipDelta
594 << " l\n"
595 << fLeftBound + fTipDelta << " " << fBottomBound + fTipDelta
596 << " l\n"
597 << fLeftBound << " " << fBottomBound + fTipDelta << " l\n";
598
599 // Draw inner lines.
600 const FX_FLOAT fXDelta = 2;
601 const FX_FLOAT fYDelta = (fTopBound - (fBottomBound + fTipDelta)) / 4;
602 sAppStream << fLeftBound + fXDelta << " " << fTopBound - fYDelta << " m\n"
603 << fRightBound - fXDelta << " " << fTopBound - fYDelta << " l\n"
604 << fLeftBound + fXDelta << " " << fTopBound - (2 * fYDelta)
605 << " m\n"
606 << fRightBound - fXDelta << " " << fTopBound - (2 * fYDelta)
607 << " l\n"
608 << fLeftBound + fXDelta << " " << fTopBound - (3 * fYDelta)
609 << " m\n"
610 << fRightBound - fXDelta << " " << fTopBound - (3 * fYDelta)
611 << " l\n"
612 << "B*\n";
613
614 return sAppStream.MakeString();
615 }
616
566 bool ShouldGenerateAPForAnnotation(CPDF_Dictionary* pAnnotDict) { 617 bool ShouldGenerateAPForAnnotation(CPDF_Dictionary* pAnnotDict) {
567 // If AP dictionary exists, we use the appearance defined in the 618 // If AP dictionary exists, we use the appearance defined in the
568 // existing AP dictionary. 619 // existing AP dictionary.
569 if (pAnnotDict->KeyExist("AP")) 620 if (pAnnotDict->KeyExist("AP"))
570 return false; 621 return false;
571 622
572 return !CPDF_Annot::IsAnnotationHidden(pAnnotDict); 623 return !CPDF_Annot::IsAnnotationHidden(pAnnotDict);
573 } 624 }
574 625
575 } // namespace 626 } // namespace
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 822
772 sAppStream << "S\n"; 823 sAppStream << "S\n";
773 } 824 }
774 825
775 CPDF_Dictionary* pExtGStateDict = 826 CPDF_Dictionary* pExtGStateDict =
776 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); 827 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
777 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict); 828 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict);
778 return true; 829 return true;
779 } 830 }
780 831
832 bool CPVT_GenerateAP::GenerateTextAP(CPDF_Document* pDoc,
833 CPDF_Dictionary* pAnnotDict) {
834 if (!ShouldGenerateAPForAnnotation(pAnnotDict))
835 return false;
836
837 CFX_ByteTextBuf sAppStream;
838 CFX_ByteString sExtGSDictName = "GS";
839 sAppStream << "/" << sExtGSDictName << " gs ";
840
841 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect");
842 const FX_FLOAT fNoteLength = 20;
843 CFX_FloatRect noteRect(rect.left, rect.bottom, rect.left + fNoteLength,
844 rect.bottom + fNoteLength);
845 pAnnotDict->SetAtRect("Rect", noteRect);
846
847 sAppStream << GenerateTextSymbolAP(noteRect);
848
849 CPDF_Dictionary* pExtGStateDict =
850 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
851 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict);
852
853 return true;
854 }
855
781 bool CPVT_GenerateAP::GenerateUnderlineAP(CPDF_Document* pDoc, 856 bool CPVT_GenerateAP::GenerateUnderlineAP(CPDF_Document* pDoc,
782 CPDF_Dictionary* pAnnotDict) { 857 CPDF_Dictionary* pAnnotDict) {
783 if (!ShouldGenerateAPForAnnotation(pAnnotDict)) 858 if (!ShouldGenerateAPForAnnotation(pAnnotDict))
784 return false; 859 return false;
785 860
786 CFX_ByteTextBuf sAppStream; 861 CFX_ByteTextBuf sAppStream;
787 CFX_ByteString sExtGSDictName = "GS"; 862 CFX_ByteString sExtGSDictName = "GS";
788 sAppStream << "/" << sExtGSDictName << " gs "; 863 sAppStream << "/" << sExtGSDictName << " gs ";
789 864
790 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), 865 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"),
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
1190 int32_t nFontIndex, 1265 int32_t nFontIndex,
1191 FX_FLOAT fFontSize) { 1266 FX_FLOAT fFontSize) {
1192 CFX_ByteTextBuf sRet; 1267 CFX_ByteTextBuf sRet;
1193 if (pFontMap) { 1268 if (pFontMap) {
1194 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); 1269 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex);
1195 if (sFontAlias.GetLength() > 0 && fFontSize > 0) 1270 if (sFontAlias.GetLength() > 0 && fFontSize > 0)
1196 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; 1271 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n";
1197 } 1272 }
1198 return sRet.MakeString(); 1273 return sRet.MakeString();
1199 } 1274 }
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