summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-10-16 13:20:32 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-10-16 19:35:56 +0000
commit9df8033a5c78719517a0351c14f6af4349bb160d (patch)
tree291f6c72600efdd6f6e12618ebaa7562b7e656c4 /core
parent72b82a8e863da1b369e9f37a9db48103024faf1b (diff)
downloadpdfium-9df8033a5c78719517a0351c14f6af4349bb160d.tar.xz
Cleanup CPVT_GenerateAP
This CL moves FPDF_GenerateAP into the anonymous namespace of CPDF_AnnotList. Several methods are moved into the anonymous namespace of CPVT_GenerateAP which are only used internally. Change-Id: I6e8fef54ba3757cc9873ed5ac370dec7eaca5d8b Reviewed-on: https://pdfium-review.googlesource.com/16070 Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core')
-rw-r--r--core/fpdfdoc/cpdf_annotlist.cpp40
-rw-r--r--core/fpdfdoc/cpvt_generateap.cpp129
-rw-r--r--core/fpdfdoc/cpvt_generateap.h19
3 files changed, 87 insertions, 101 deletions
diff --git a/core/fpdfdoc/cpdf_annotlist.cpp b/core/fpdfdoc/cpdf_annotlist.cpp
index c0f7ae2f23..c7da676b98 100644
--- a/core/fpdfdoc/cpdf_annotlist.cpp
+++ b/core/fpdfdoc/cpdf_annotlist.cpp
@@ -75,6 +75,44 @@ std::unique_ptr<CPDF_Annot> CreatePopupAnnot(CPDF_Annot* pAnnot,
return pPopupAnnot;
}
+void GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) {
+ if (!pAnnotDict || pAnnotDict->GetStringFor("Subtype") != "Widget")
+ return;
+
+ CPDF_Object* pFieldTypeObj = FPDF_GetFieldAttr(pAnnotDict, "FT");
+ if (!pFieldTypeObj)
+ return;
+
+ ByteString field_type = pFieldTypeObj->GetString();
+ if (field_type == "Tx") {
+ CPVT_GenerateAP::GenerateTextFieldAP(pDoc, pAnnotDict);
+ return;
+ }
+
+ CPDF_Object* pFieldFlagsObj = FPDF_GetFieldAttr(pAnnotDict, "Ff");
+ uint32_t flags = pFieldFlagsObj ? pFieldFlagsObj->GetInteger() : 0;
+ if (field_type == "Ch") {
+ (flags & (1 << 17)) ? CPVT_GenerateAP::GenerateComboBoxAP(pDoc, pAnnotDict)
+ : CPVT_GenerateAP::GenerateListBoxAP(pDoc, pAnnotDict);
+ return;
+ }
+
+ if (field_type != "Btn")
+ return;
+ if (flags & (1 << 16))
+ return;
+ if (pAnnotDict->KeyExist("AS"))
+ return;
+
+ CPDF_Dictionary* pParentDict = pAnnotDict->GetDictFor("Parent");
+ if (!pParentDict || !pParentDict->KeyExist("AS"))
+ return;
+
+ pAnnotDict->SetNewFor<CPDF_String>("AS", pParentDict->GetStringFor("AS"),
+ false);
+ return;
+}
+
} // namespace
CPDF_AnnotList::CPDF_AnnotList(CPDF_Page* pPage)
@@ -103,7 +141,7 @@ CPDF_AnnotList::CPDF_AnnotList(CPDF_Page* pPage)
m_AnnotList.push_back(pdfium::MakeUnique<CPDF_Annot>(pDict, m_pDocument));
if (bRegenerateAP && subtype == "Widget" &&
CPDF_InterForm::IsUpdateAPEnabled() && !pDict->GetDictFor("AP")) {
- FPDF_GenerateAP(m_pDocument, pDict);
+ GenerateAP(m_pDocument, pDict);
}
}
diff --git a/core/fpdfdoc/cpvt_generateap.cpp b/core/fpdfdoc/cpvt_generateap.cpp
index 34edd0e088..b6e89e019a 100644
--- a/core/fpdfdoc/cpvt_generateap.cpp
+++ b/core/fpdfdoc/cpvt_generateap.cpp
@@ -631,60 +631,68 @@ ByteString GenerateTextSymbolAP(const CFX_FloatRect& rect) {
return ByteString(sAppStream);
}
-} // namespace
-
-bool FPDF_GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) {
- if (!pAnnotDict || pAnnotDict->GetStringFor("Subtype") != "Widget")
- return false;
-
- CPDF_Object* pFieldTypeObj = FPDF_GetFieldAttr(pAnnotDict, "FT");
- if (!pFieldTypeObj)
- return false;
-
- ByteString field_type = pFieldTypeObj->GetString();
- if (field_type == "Tx")
- return CPVT_GenerateAP::GenerateTextFieldAP(pDoc, pAnnotDict);
-
- CPDF_Object* pFieldFlagsObj = FPDF_GetFieldAttr(pAnnotDict, "Ff");
- uint32_t flags = pFieldFlagsObj ? pFieldFlagsObj->GetInteger() : 0;
- if (field_type == "Ch") {
- return (flags & (1 << 17))
- ? CPVT_GenerateAP::GenerateComboBoxAP(pDoc, pAnnotDict)
- : CPVT_GenerateAP::GenerateListBoxAP(pDoc, pAnnotDict);
+ByteString GetPDFWordString(IPVT_FontMap* pFontMap,
+ int32_t nFontIndex,
+ uint16_t Word,
+ uint16_t SubWord) {
+ ByteString sWord;
+ if (SubWord > 0) {
+ sWord.Format("%c", SubWord);
+ return sWord;
}
- if (field_type == "Btn") {
- if (!(flags & (1 << 16))) {
- if (!pAnnotDict->KeyExist("AS")) {
- if (CPDF_Dictionary* pParentDict = pAnnotDict->GetDictFor("Parent")) {
- if (pParentDict->KeyExist("AS")) {
- pAnnotDict->SetNewFor<CPDF_String>(
- "AS", pParentDict->GetStringFor("AS"), false);
- }
- }
- }
+ if (!pFontMap)
+ return sWord;
+
+ if (CPDF_Font* pPDFFont = pFontMap->GetPDFFont(nFontIndex)) {
+ if (pPDFFont->GetBaseFont().Compare("Symbol") == 0 ||
+ pPDFFont->GetBaseFont().Compare("ZapfDingbats") == 0) {
+ sWord.Format("%c", Word);
+ } else {
+ uint32_t dwCharCode = pPDFFont->CharCodeFromUnicode(Word);
+ if (dwCharCode != CPDF_Font::kInvalidCharCode)
+ pPDFFont->AppendChar(&sWord, dwCharCode);
}
}
+ return sWord;
+}
+
+ByteString GetWordRenderString(const ByteString& strWords) {
+ if (strWords.GetLength() > 0)
+ return PDF_EncodeString(strWords, false) + " Tj\n";
+ return "";
+}
- return false;
+ByteString GetFontSetString(IPVT_FontMap* pFontMap,
+ int32_t nFontIndex,
+ float fFontSize) {
+ std::ostringstream sRet;
+ if (pFontMap) {
+ ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex);
+ if (sFontAlias.GetLength() > 0 && fFontSize > 0)
+ sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n";
+ }
+ return ByteString(sRet);
}
+} // namespace
+
// Static.
-bool CPVT_GenerateAP::GenerateComboBoxAP(CPDF_Document* pDoc,
+void CPVT_GenerateAP::GenerateComboBoxAP(CPDF_Document* pDoc,
CPDF_Dictionary* pAnnotDict) {
- return GenerateWidgetAP(pDoc, pAnnotDict, 1);
+ GenerateWidgetAP(pDoc, pAnnotDict, 1);
}
// Static.
-bool CPVT_GenerateAP::GenerateListBoxAP(CPDF_Document* pDoc,
+void CPVT_GenerateAP::GenerateListBoxAP(CPDF_Document* pDoc,
CPDF_Dictionary* pAnnotDict) {
- return GenerateWidgetAP(pDoc, pAnnotDict, 2);
+ GenerateWidgetAP(pDoc, pAnnotDict, 2);
}
// Static.
-bool CPVT_GenerateAP::GenerateTextFieldAP(CPDF_Document* pDoc,
+void CPVT_GenerateAP::GenerateTextFieldAP(CPDF_Document* pDoc,
CPDF_Dictionary* pAnnotDict) {
- return GenerateWidgetAP(pDoc, pAnnotDict, 0);
+ GenerateWidgetAP(pDoc, pAnnotDict, 0);
}
bool CPVT_GenerateAP::GenerateCircleAP(CPDF_Document* pDoc,
@@ -1335,50 +1343,3 @@ void CPVT_GenerateAP::GenerateAndSetAPDict(
pStreamDict->SetRectFor("BBox", rect);
pStreamDict->SetFor("Resources", std::move(pResourceDict));
}
-
-// Static.
-ByteString CPVT_GenerateAP::GetPDFWordString(IPVT_FontMap* pFontMap,
- int32_t nFontIndex,
- uint16_t Word,
- uint16_t SubWord) {
- ByteString sWord;
- if (SubWord > 0) {
- sWord.Format("%c", SubWord);
- return sWord;
- }
-
- if (!pFontMap)
- return sWord;
-
- if (CPDF_Font* pPDFFont = pFontMap->GetPDFFont(nFontIndex)) {
- if (pPDFFont->GetBaseFont().Compare("Symbol") == 0 ||
- pPDFFont->GetBaseFont().Compare("ZapfDingbats") == 0) {
- sWord.Format("%c", Word);
- } else {
- uint32_t dwCharCode = pPDFFont->CharCodeFromUnicode(Word);
- if (dwCharCode != CPDF_Font::kInvalidCharCode)
- pPDFFont->AppendChar(&sWord, dwCharCode);
- }
- }
- return sWord;
-}
-
-// Static.
-ByteString CPVT_GenerateAP::GetWordRenderString(const ByteString& strWords) {
- if (strWords.GetLength() > 0)
- return PDF_EncodeString(strWords, false) + " Tj\n";
- return "";
-}
-
-// Static.
-ByteString CPVT_GenerateAP::GetFontSetString(IPVT_FontMap* pFontMap,
- int32_t nFontIndex,
- float fFontSize) {
- std::ostringstream sRet;
- if (pFontMap) {
- ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex);
- if (sFontAlias.GetLength() > 0 && fFontSize > 0)
- sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n";
- }
- return ByteString(sRet);
-}
diff --git a/core/fpdfdoc/cpvt_generateap.h b/core/fpdfdoc/cpvt_generateap.h
index 6f63b10fbc..42ff33981c 100644
--- a/core/fpdfdoc/cpvt_generateap.h
+++ b/core/fpdfdoc/cpvt_generateap.h
@@ -21,20 +21,16 @@ class CPDF_Document;
struct CPVT_Dash;
class IPVT_FontMap;
-struct CPVT_WordRange;
-
-bool FPDF_GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict);
-
class CPVT_GenerateAP {
public:
static bool GenerateCircleAP(CPDF_Document* pDoc,
CPDF_Dictionary* pAnnotDict);
- static bool GenerateComboBoxAP(CPDF_Document* pDoc,
+ static void GenerateComboBoxAP(CPDF_Document* pDoc,
CPDF_Dictionary* pAnnotDict);
static bool GenerateHighlightAP(CPDF_Document* pDoc,
CPDF_Dictionary* pAnnotDict);
static bool GenerateInkAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict);
- static bool GenerateListBoxAP(CPDF_Document* pDoc,
+ static void GenerateListBoxAP(CPDF_Document* pDoc,
CPDF_Dictionary* pAnnotDict);
static bool GeneratePopupAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict);
static bool GenerateSquareAP(CPDF_Document* pDoc,
@@ -44,7 +40,7 @@ class CPVT_GenerateAP {
static bool GenerateStrikeOutAP(CPDF_Document* pDoc,
CPDF_Dictionary* pAnnotDict);
static bool GenerateTextAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict);
- static bool GenerateTextFieldAP(CPDF_Document* pDoc,
+ static void GenerateTextFieldAP(CPDF_Document* pDoc,
CPDF_Dictionary* pAnnotDict);
static bool GenerateUnderlineAP(CPDF_Document* pDoc,
CPDF_Dictionary* pAnnotDict);
@@ -76,15 +72,6 @@ class CPVT_GenerateAP {
std::ostringstream* psAppStream,
std::unique_ptr<CPDF_Dictionary> pResourceDict,
bool bIsTextMarkupAnnotation);
-
- static ByteString GetPDFWordString(IPVT_FontMap* pFontMap,
- int32_t nFontIndex,
- uint16_t Word,
- uint16_t SubWord);
- static ByteString GetWordRenderString(const ByteString& strWords);
- static ByteString GetFontSetString(IPVT_FontMap* pFontMap,
- int32_t nFontIndex,
- float fFontSize);
};
#endif // CORE_FPDFDOC_CPVT_GENERATEAP_H_