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 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
589 if (pResourceFontDict) | 589 if (pResourceFontDict) |
590 pResourceDict->SetAt("Font", pResourceFontDict); | 590 pResourceDict->SetAt("Font", pResourceFontDict); |
591 | 591 |
592 return pResourceDict; | 592 return pResourceDict; |
593 } | 593 } |
594 | 594 |
595 // Takes ownership of |pResourceDict|. | 595 // Takes ownership of |pResourceDict|. |
596 void GenerateAndSetAPDict(CPDF_Document* pDoc, | 596 void GenerateAndSetAPDict(CPDF_Document* pDoc, |
597 CPDF_Dictionary* pAnnotDict, | 597 CPDF_Dictionary* pAnnotDict, |
598 const CFX_ByteTextBuf& sAppStream, | 598 const CFX_ByteTextBuf& sAppStream, |
599 CPDF_Dictionary* pResourceDict) { | 599 CPDF_Dictionary* pResourceDict, |
600 bool bIsTextAnnotation = false) { | |
Lei Zhang
2016/09/06 21:27:03
I would highly prefer we don't have default argume
| |
600 CPDF_Dictionary* pAPDict = new CPDF_Dictionary; | 601 CPDF_Dictionary* pAPDict = new CPDF_Dictionary; |
601 pAnnotDict->SetAt("AP", pAPDict); | 602 pAnnotDict->SetAt("AP", pAPDict); |
602 | 603 |
603 CPDF_Stream* pNormalStream = new CPDF_Stream(nullptr, 0, nullptr); | 604 CPDF_Stream* pNormalStream = new CPDF_Stream(nullptr, 0, nullptr); |
604 int32_t objnum = pDoc->AddIndirectObject(pNormalStream); | 605 int32_t objnum = pDoc->AddIndirectObject(pNormalStream); |
605 pAnnotDict->GetDictBy("AP")->SetAtReference("N", pDoc, objnum); | 606 pAnnotDict->GetDictBy("AP")->SetAtReference("N", pDoc, objnum); |
606 | 607 |
607 pNormalStream->SetData(sAppStream.GetBuffer(), sAppStream.GetSize(), FALSE, | 608 pNormalStream->SetData(sAppStream.GetBuffer(), sAppStream.GetSize(), FALSE, |
608 FALSE); | 609 FALSE); |
609 | 610 |
610 CPDF_Dictionary* pStreamDict = pNormalStream->GetDict(); | 611 CPDF_Dictionary* pStreamDict = pNormalStream->GetDict(); |
611 pStreamDict->SetAtInteger("FormType", 1); | 612 pStreamDict->SetAtInteger("FormType", 1); |
612 pStreamDict->SetAtString("Subtype", "Form"); | 613 pStreamDict->SetAtString("Subtype", "Form"); |
613 pStreamDict->SetAtMatrix("Matrix", CFX_Matrix()); | 614 pStreamDict->SetAtMatrix("Matrix", CFX_Matrix()); |
614 | 615 |
615 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); | 616 CFX_FloatRect rect = bIsTextAnnotation ? CPDF_Annot::RectFromQuads(pAnnotDict) |
617 : pAnnotDict->GetRectBy("Rect"); | |
616 pStreamDict->SetAtRect("BBox", rect); | 618 pStreamDict->SetAtRect("BBox", rect); |
617 | 619 |
618 pStreamDict->SetAt("Resources", pResourceDict); | 620 pStreamDict->SetAt("Resources", pResourceDict); |
619 } | 621 } |
620 | 622 |
621 CFX_ByteString GetPaintOperatorString(bool bIsStrokeRect, bool bIsFillRect) { | 623 CFX_ByteString GetPaintOperatorString(bool bIsStrokeRect, bool bIsFillRect) { |
622 if (bIsStrokeRect) | 624 if (bIsStrokeRect) |
623 return bIsFillRect ? "b" : "s"; | 625 return bIsFillRect ? "b" : "s"; |
624 return bIsFillRect ? "f" : "n"; | 626 return bIsFillRect ? "f" : "n"; |
625 } | 627 } |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
800 bool CPVT_GenerateAP::GenerateHighlightAP(CPDF_Document* pDoc, | 802 bool CPVT_GenerateAP::GenerateHighlightAP(CPDF_Document* pDoc, |
801 CPDF_Dictionary* pAnnotDict) { | 803 CPDF_Dictionary* pAnnotDict) { |
802 CFX_ByteTextBuf sAppStream; | 804 CFX_ByteTextBuf sAppStream; |
803 CFX_ByteString sExtGSDictName = "GS"; | 805 CFX_ByteString sExtGSDictName = "GS"; |
804 sAppStream << "/" << sExtGSDictName << " gs "; | 806 sAppStream << "/" << sExtGSDictName << " gs "; |
805 | 807 |
806 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), | 808 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), |
807 CPVT_Color(CPVT_Color::kRGB, 1, 1, 0), | 809 CPVT_Color(CPVT_Color::kRGB, 1, 1, 0), |
808 PaintOperation::FILL); | 810 PaintOperation::FILL); |
809 | 811 |
810 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); | 812 CFX_FloatRect rect = CPDF_Annot::RectFromQuads(pAnnotDict); |
811 rect.Normalize(); | 813 rect.Normalize(); |
812 | 814 |
813 sAppStream << rect.left << " " << rect.top << " m " << rect.right << " " | 815 sAppStream << rect.left << " " << rect.top << " m " << rect.right << " " |
814 << rect.top << " l " << rect.right << " " << rect.bottom << " l " | 816 << rect.top << " l " << rect.right << " " << rect.bottom << " l " |
815 << rect.left << " " << rect.bottom << " l " | 817 << rect.left << " " << rect.bottom << " l " |
816 << "h f\n"; | 818 << "h f\n"; |
817 | 819 |
818 CPDF_Dictionary* pExtGStateDict = | 820 CPDF_Dictionary* pExtGStateDict = |
819 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Multiply"); | 821 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Multiply"); |
820 CPDF_Dictionary* pResourceDict = | 822 CPDF_Dictionary* pResourceDict = |
821 GenerateResourceDict(pExtGStateDict, nullptr); | 823 GenerateResourceDict(pExtGStateDict, nullptr); |
822 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict); | 824 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict, |
825 true /*IsTextMarkupAnnotation*/); | |
823 | 826 |
824 return true; | 827 return true; |
825 } | 828 } |
826 | 829 |
827 bool CPVT_GenerateAP::GenerateInkAP(CPDF_Document* pDoc, | 830 bool CPVT_GenerateAP::GenerateInkAP(CPDF_Document* pDoc, |
828 CPDF_Dictionary* pAnnotDict) { | 831 CPDF_Dictionary* pAnnotDict) { |
829 FX_FLOAT fBorderWidth = GetBorderWidth(*pAnnotDict); | 832 FX_FLOAT fBorderWidth = GetBorderWidth(*pAnnotDict); |
830 bool bIsStroke = fBorderWidth > 0; | 833 bool bIsStroke = fBorderWidth > 0; |
831 | 834 |
832 if (!bIsStroke) | 835 if (!bIsStroke) |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
902 bool CPVT_GenerateAP::GenerateUnderlineAP(CPDF_Document* pDoc, | 905 bool CPVT_GenerateAP::GenerateUnderlineAP(CPDF_Document* pDoc, |
903 CPDF_Dictionary* pAnnotDict) { | 906 CPDF_Dictionary* pAnnotDict) { |
904 CFX_ByteTextBuf sAppStream; | 907 CFX_ByteTextBuf sAppStream; |
905 CFX_ByteString sExtGSDictName = "GS"; | 908 CFX_ByteString sExtGSDictName = "GS"; |
906 sAppStream << "/" << sExtGSDictName << " gs "; | 909 sAppStream << "/" << sExtGSDictName << " gs "; |
907 | 910 |
908 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), | 911 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), |
909 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), | 912 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), |
910 PaintOperation::STROKE); | 913 PaintOperation::STROKE); |
911 | 914 |
912 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); | 915 CFX_FloatRect rect = CPDF_Annot::RectFromQuads(pAnnotDict); |
913 rect.Normalize(); | 916 rect.Normalize(); |
914 | 917 |
915 FX_FLOAT fLineWidth = 1.0; | 918 FX_FLOAT fLineWidth = 1.0; |
916 sAppStream << fLineWidth << " w " << rect.left << " " | 919 sAppStream << fLineWidth << " w " << rect.left << " " |
917 << rect.bottom + fLineWidth << " m " << rect.right << " " | 920 << rect.bottom + fLineWidth << " m " << rect.right << " " |
918 << rect.bottom + fLineWidth << " l S\n"; | 921 << rect.bottom + fLineWidth << " l S\n"; |
919 | 922 |
920 CPDF_Dictionary* pExtGStateDict = | 923 CPDF_Dictionary* pExtGStateDict = |
921 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); | 924 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); |
922 CPDF_Dictionary* pResourceDict = | 925 CPDF_Dictionary* pResourceDict = |
923 GenerateResourceDict(pExtGStateDict, nullptr); | 926 GenerateResourceDict(pExtGStateDict, nullptr); |
924 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict); | 927 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict, |
928 true /*IsTextMarkupAnnotation*/); | |
925 return true; | 929 return true; |
926 } | 930 } |
927 | 931 |
928 bool CPVT_GenerateAP::GeneratePopupAP(CPDF_Document* pDoc, | 932 bool CPVT_GenerateAP::GeneratePopupAP(CPDF_Document* pDoc, |
929 CPDF_Dictionary* pAnnotDict) { | 933 CPDF_Dictionary* pAnnotDict) { |
930 CFX_ByteTextBuf sAppStream; | 934 CFX_ByteTextBuf sAppStream; |
931 CFX_ByteString sExtGSDictName = "GS"; | 935 CFX_ByteString sExtGSDictName = "GS"; |
932 sAppStream << "/" << sExtGSDictName << " gs\n"; | 936 sAppStream << "/" << sExtGSDictName << " gs\n"; |
933 | 937 |
934 sAppStream << GenerateColorAP(CPVT_Color(CPVT_Color::kRGB, 1, 1, 0), | 938 sAppStream << GenerateColorAP(CPVT_Color(CPVT_Color::kRGB, 1, 1, 0), |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1013 bool CPVT_GenerateAP::GenerateSquigglyAP(CPDF_Document* pDoc, | 1017 bool CPVT_GenerateAP::GenerateSquigglyAP(CPDF_Document* pDoc, |
1014 CPDF_Dictionary* pAnnotDict) { | 1018 CPDF_Dictionary* pAnnotDict) { |
1015 CFX_ByteTextBuf sAppStream; | 1019 CFX_ByteTextBuf sAppStream; |
1016 CFX_ByteString sExtGSDictName = "GS"; | 1020 CFX_ByteString sExtGSDictName = "GS"; |
1017 sAppStream << "/" << sExtGSDictName << " gs "; | 1021 sAppStream << "/" << sExtGSDictName << " gs "; |
1018 | 1022 |
1019 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), | 1023 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), |
1020 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), | 1024 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), |
1021 PaintOperation::STROKE); | 1025 PaintOperation::STROKE); |
1022 | 1026 |
1023 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); | 1027 CFX_FloatRect rect = CPDF_Annot::RectFromQuads(pAnnotDict); |
1024 rect.Normalize(); | 1028 rect.Normalize(); |
1025 | 1029 |
1026 FX_FLOAT fLineWidth = 1.0; | 1030 FX_FLOAT fLineWidth = 1.0; |
1027 sAppStream << fLineWidth << " w "; | 1031 sAppStream << fLineWidth << " w "; |
1028 | 1032 |
1029 const FX_FLOAT fDelta = 2.0; | 1033 const FX_FLOAT fDelta = 2.0; |
1030 const FX_FLOAT fTop = rect.bottom + fDelta; | 1034 const FX_FLOAT fTop = rect.bottom + fDelta; |
1031 const FX_FLOAT fBottom = rect.bottom; | 1035 const FX_FLOAT fBottom = rect.bottom; |
1032 | 1036 |
1033 sAppStream << rect.left << " " << fTop << " m "; | 1037 sAppStream << rect.left << " " << fTop << " m "; |
(...skipping 13 matching lines...) Expand all Loading... | |
1047 sAppStream << rect.right << " " << fBottom + fRemainder << " l "; | 1051 sAppStream << rect.right << " " << fBottom + fRemainder << " l "; |
1048 else | 1052 else |
1049 sAppStream << rect.right << " " << fTop - fRemainder << " l "; | 1053 sAppStream << rect.right << " " << fTop - fRemainder << " l "; |
1050 | 1054 |
1051 sAppStream << "S\n"; | 1055 sAppStream << "S\n"; |
1052 | 1056 |
1053 CPDF_Dictionary* pExtGStateDict = | 1057 CPDF_Dictionary* pExtGStateDict = |
1054 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); | 1058 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); |
1055 CPDF_Dictionary* pResourceDict = | 1059 CPDF_Dictionary* pResourceDict = |
1056 GenerateResourceDict(pExtGStateDict, nullptr); | 1060 GenerateResourceDict(pExtGStateDict, nullptr); |
1057 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict); | 1061 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict, |
1062 true /*IsTextMarkupAnnotation*/); | |
1058 return true; | 1063 return true; |
1059 } | 1064 } |
1060 | 1065 |
1061 bool CPVT_GenerateAP::GenerateStrikeOutAP(CPDF_Document* pDoc, | 1066 bool CPVT_GenerateAP::GenerateStrikeOutAP(CPDF_Document* pDoc, |
1062 CPDF_Dictionary* pAnnotDict) { | 1067 CPDF_Dictionary* pAnnotDict) { |
1063 CFX_ByteTextBuf sAppStream; | 1068 CFX_ByteTextBuf sAppStream; |
1064 CFX_ByteString sExtGSDictName = "GS"; | 1069 CFX_ByteString sExtGSDictName = "GS"; |
1065 sAppStream << "/" << sExtGSDictName << " gs "; | 1070 sAppStream << "/" << sExtGSDictName << " gs "; |
1066 | 1071 |
1067 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), | 1072 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), |
1068 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), | 1073 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), |
1069 PaintOperation::STROKE); | 1074 PaintOperation::STROKE); |
1070 | 1075 |
1071 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); | 1076 CFX_FloatRect rect = CPDF_Annot::RectFromQuads(pAnnotDict); |
1072 rect.Normalize(); | 1077 rect.Normalize(); |
1073 | 1078 |
1074 FX_FLOAT fLineWidth = 1.0; | 1079 FX_FLOAT fLineWidth = 1.0; |
1075 FX_FLOAT fY = (rect.top + rect.bottom) / 2; | 1080 FX_FLOAT fY = (rect.top + rect.bottom) / 2; |
1076 sAppStream << fLineWidth << " w " << rect.left << " " << fY << " m " | 1081 sAppStream << fLineWidth << " w " << rect.left << " " << fY << " m " |
1077 << rect.right << " " << fY << " l S\n"; | 1082 << rect.right << " " << fY << " l S\n"; |
1078 | 1083 |
1079 CPDF_Dictionary* pExtGStateDict = | 1084 CPDF_Dictionary* pExtGStateDict = |
1080 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); | 1085 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); |
1081 CPDF_Dictionary* pResourceDict = | 1086 CPDF_Dictionary* pResourceDict = |
1082 GenerateResourceDict(pExtGStateDict, nullptr); | 1087 GenerateResourceDict(pExtGStateDict, nullptr); |
1083 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict); | 1088 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict, |
1089 true /*IsTextMarkupAnnotation*/); | |
1084 return true; | 1090 return true; |
1085 } | 1091 } |
1086 | 1092 |
1087 // Static. | 1093 // Static. |
1088 CFX_ByteString CPVT_GenerateAP::GenerateEditAP( | 1094 CFX_ByteString CPVT_GenerateAP::GenerateEditAP( |
1089 IPVT_FontMap* pFontMap, | 1095 IPVT_FontMap* pFontMap, |
1090 CPDF_VariableText::Iterator* pIterator, | 1096 CPDF_VariableText::Iterator* pIterator, |
1091 const CFX_FloatPoint& ptOffset, | 1097 const CFX_FloatPoint& ptOffset, |
1092 FX_BOOL bContinuous, | 1098 FX_BOOL bContinuous, |
1093 uint16_t SubWord) { | 1099 uint16_t SubWord) { |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1345 int32_t nFontIndex, | 1351 int32_t nFontIndex, |
1346 FX_FLOAT fFontSize) { | 1352 FX_FLOAT fFontSize) { |
1347 CFX_ByteTextBuf sRet; | 1353 CFX_ByteTextBuf sRet; |
1348 if (pFontMap) { | 1354 if (pFontMap) { |
1349 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); | 1355 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); |
1350 if (sFontAlias.GetLength() > 0 && fFontSize > 0) | 1356 if (sFontAlias.GetLength() > 0 && fFontSize > 0) |
1351 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; | 1357 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; |
1352 } | 1358 } |
1353 return sRet.MakeString(); | 1359 return sRet.MakeString(); |
1354 } | 1360 } |
OLD | NEW |