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

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

Issue 2232553002: Generate default AP stream for ink annotation. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Generate default AP stream for ink 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 700 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 << rect.left << " " << rect.bottom << " l " 711 << rect.left << " " << rect.bottom << " l "
712 << "h f\n"; 712 << "h f\n";
713 713
714 CPDF_Dictionary* pExtGStateDict = 714 CPDF_Dictionary* pExtGStateDict =
715 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Multiply"); 715 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Multiply");
716 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict); 716 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict);
717 717
718 return true; 718 return true;
719 } 719 }
720 720
721 bool CPVT_GenerateAP::GenerateInkAP(CPDF_Document* pDoc,
722 CPDF_Dictionary* pAnnotDict) {
723 // If AP dictionary exists, we use the appearance defined in the
724 // existing AP dictionary.
725 if (pAnnotDict->KeyExist("AP"))
726 return false;
727
728 FX_FLOAT fBorderWidth = GetBorderWidth(*pAnnotDict);
729 bool bIsStroke = fBorderWidth > 0;
730
731 if (!bIsStroke)
732 return false;
733
734 CPDF_Array* pInkList = pAnnotDict->GetArrayBy("InkList");
735 if (!pInkList || pInkList->IsEmpty())
736 return false;
737
738 CFX_ByteTextBuf sAppStream;
739 CFX_ByteString sExtGSDictName = "GS";
740 sAppStream << "/" << sExtGSDictName << " gs ";
741
742 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"),
743 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0),
744 PaintOperation::STROKE);
745
746 sAppStream << fBorderWidth << " w ";
747 sAppStream << GetDashPatternString(*pAnnotDict);
748
749 // Set inflated rect as a new rect because paths near the border with large
750 // width should not be clipped to the original rect.
751 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect");
752 rect.Inflate(fBorderWidth / 2, fBorderWidth / 2);
753 pAnnotDict->SetAtRect("Rect", rect);
754
755 for (size_t i = 0; i < pInkList->GetCount(); i++) {
756 CPDF_Array* pInkCoordList = pInkList->GetArrayAt(i);
757 if (!pInkCoordList || pInkCoordList->GetCount() < 2)
758 continue;
759
760 sAppStream << pInkCoordList->GetNumberAt(0) << " "
761 << pInkCoordList->GetNumberAt(1) << " m ";
762
763 for (size_t j = 0; j < pInkCoordList->GetCount() - 1; j += 2) {
764 sAppStream << pInkCoordList->GetNumberAt(j) << " "
765 << pInkCoordList->GetNumberAt(j + 1) << " l ";
766 }
767
768 sAppStream << "S\n";
769 }
770
771 CPDF_Dictionary* pExtGStateDict =
772 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
773 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict);
774 return true;
775 }
776
721 bool CPVT_GenerateAP::GenerateUnderlineAP(CPDF_Document* pDoc, 777 bool CPVT_GenerateAP::GenerateUnderlineAP(CPDF_Document* pDoc,
722 CPDF_Dictionary* pAnnotDict) { 778 CPDF_Dictionary* pAnnotDict) {
723 // If AP dictionary exists, we use the appearance defined in the 779 // If AP dictionary exists, we use the appearance defined in the
724 // existing AP dictionary. 780 // existing AP dictionary.
725 if (pAnnotDict->KeyExist("AP")) 781 if (pAnnotDict->KeyExist("AP"))
726 return false; 782 return false;
727 783
728 CFX_ByteTextBuf sAppStream; 784 CFX_ByteTextBuf sAppStream;
729 CFX_ByteString sExtGSDictName = "GS"; 785 CFX_ByteString sExtGSDictName = "GS";
730 sAppStream << "/" << sExtGSDictName << " gs "; 786 sAppStream << "/" << sExtGSDictName << " gs ";
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
1138 int32_t nFontIndex, 1194 int32_t nFontIndex,
1139 FX_FLOAT fFontSize) { 1195 FX_FLOAT fFontSize) {
1140 CFX_ByteTextBuf sRet; 1196 CFX_ByteTextBuf sRet;
1141 if (pFontMap) { 1197 if (pFontMap) {
1142 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); 1198 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex);
1143 if (sFontAlias.GetLength() > 0 && fFontSize > 0) 1199 if (sFontAlias.GetLength() > 0 && fFontSize > 0)
1144 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; 1200 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n";
1145 } 1201 }
1146 return sRet.MakeString(); 1202 return sRet.MakeString();
1147 } 1203 }
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