Index: core/fpdfdoc/cpvt_generateap.cpp |
diff --git a/core/fpdfdoc/doc_ap.cpp b/core/fpdfdoc/cpvt_generateap.cpp |
similarity index 74% |
copy from core/fpdfdoc/doc_ap.cpp |
copy to core/fpdfdoc/cpvt_generateap.cpp |
index e87b21b8ecbb279c5f91673d1985e789438984a5..f9d6e9630b6f95da771572094e79e92fe8746ef1 100644 |
--- a/core/fpdfdoc/doc_ap.cpp |
+++ b/core/fpdfdoc/cpvt_generateap.cpp |
@@ -1,305 +1,52 @@ |
-// Copyright 2014 PDFium Authors. All rights reserved. |
+// Copyright 2016 PDFium Authors. All rights reserved. |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
+#include "core/fpdfdoc/cpvt_generateap.h" |
+ |
#include "core/fpdfapi/fpdf_font/include/cpdf_font.h" |
-#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
+#include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" |
#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
#include "core/fpdfapi/fpdf_parser/include/cpdf_simple_parser.h" |
#include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" |
-#include "core/fpdfdoc/doc_utils.h" |
+#include "core/fpdfdoc/cpvt_color.h" |
+#include "core/fpdfdoc/cpvt_fontmap.h" |
+#include "core/fpdfdoc/cpvt_provider.h" |
#include "core/fpdfdoc/pdf_vt.h" |
-#include "core/include/fpdfdoc/fpdf_ap.h" |
#include "core/include/fpdfdoc/fpdf_doc.h" |
-#include "core/include/fpdfdoc/fpdf_vt.h" |
- |
-#define PBS_SOLID 0 |
-#define PBS_DASH 1 |
-#define PBS_BEVELED 2 |
-#define PBS_INSET 3 |
-#define PBS_UNDERLINED 4 |
-FX_BOOL FPDF_GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) { |
- if (!pAnnotDict || pAnnotDict->GetConstStringBy("Subtype") != "Widget") { |
- return FALSE; |
- } |
- CFX_ByteString field_type = FPDF_GetFieldAttr(pAnnotDict, "FT")->GetString(); |
- uint32_t flags = FPDF_GetFieldAttr(pAnnotDict, "Ff") |
- ? FPDF_GetFieldAttr(pAnnotDict, "Ff")->GetInteger() |
- : 0; |
- if (field_type == "Tx") { |
- return CPVT_GenerateAP::GenerateTextFieldAP(pDoc, pAnnotDict); |
- } |
- if (field_type == "Ch") { |
- return (flags & (1 << 17)) |
- ? CPVT_GenerateAP::GenerateComboBoxAP(pDoc, pAnnotDict) |
- : CPVT_GenerateAP::GenerateListBoxAP(pDoc, pAnnotDict); |
- } |
- if (field_type == "Btn") { |
- if (!(flags & (1 << 16))) { |
- if (!pAnnotDict->KeyExist("AS")) { |
- if (CPDF_Dictionary* pParentDict = pAnnotDict->GetDictBy("Parent")) { |
- if (pParentDict->KeyExist("AS")) { |
- pAnnotDict->SetAtString("AS", pParentDict->GetStringBy("AS")); |
- } |
- } |
- } |
- } |
- } |
- return FALSE; |
-} |
+namespace { |
-class CPVT_FontMap : public IPVT_FontMap { |
- public: |
- CPVT_FontMap(CPDF_Document* pDoc, |
- CPDF_Dictionary* pResDict, |
- CPDF_Font* pDefFont, |
- const CFX_ByteString& sDefFontAlias); |
- ~CPVT_FontMap() override; |
- |
- // IPVT_FontMap |
- CPDF_Font* GetPDFFont(int32_t nFontIndex) override; |
- CFX_ByteString GetPDFFontAlias(int32_t nFontIndex) override; |
- |
- static void GetAnnotSysPDFFont(CPDF_Document* pDoc, |
- CPDF_Dictionary* pResDict, |
- CPDF_Font*& pSysFont, |
- CFX_ByteString& sSysFontAlias); |
- |
- private: |
- CPDF_Document* m_pDocument; |
- CPDF_Dictionary* m_pResDict; |
- CPDF_Font* m_pDefFont; |
- CFX_ByteString m_sDefFontAlias; |
- CPDF_Font* m_pSysFont; |
- CFX_ByteString m_sSysFontAlias; |
-}; |
- |
-CPVT_FontMap::CPVT_FontMap(CPDF_Document* pDoc, |
- CPDF_Dictionary* pResDict, |
- CPDF_Font* pDefFont, |
- const CFX_ByteString& sDefFontAlias) |
- : m_pDocument(pDoc), |
- m_pResDict(pResDict), |
- m_pDefFont(pDefFont), |
- m_sDefFontAlias(sDefFontAlias), |
- m_pSysFont(NULL), |
- m_sSysFontAlias() {} |
-CPVT_FontMap::~CPVT_FontMap() {} |
-void CPVT_FontMap::GetAnnotSysPDFFont(CPDF_Document* pDoc, |
- CPDF_Dictionary* pResDict, |
- CPDF_Font*& pSysFont, |
- CFX_ByteString& sSysFontAlias) { |
- if (pDoc && pResDict) { |
- CFX_ByteString sFontAlias; |
- CPDF_Dictionary* pFormDict = pDoc->GetRoot()->GetDictBy("AcroForm"); |
- if (CPDF_Font* pPDFFont = |
- AddNativeInterFormFont(pFormDict, pDoc, sSysFontAlias)) { |
- if (CPDF_Dictionary* pFontList = pResDict->GetDictBy("Font")) { |
- if (!pFontList->KeyExist(sSysFontAlias)) { |
- pFontList->SetAtReference(sSysFontAlias, pDoc, |
- pPDFFont->GetFontDict()); |
- } |
- } |
- pSysFont = pPDFFont; |
- } |
- } |
-} |
-CPDF_Font* CPVT_FontMap::GetPDFFont(int32_t nFontIndex) { |
- switch (nFontIndex) { |
- case 0: |
- return m_pDefFont; |
- case 1: |
- if (!m_pSysFont) { |
- GetAnnotSysPDFFont(m_pDocument, m_pResDict, m_pSysFont, |
- m_sSysFontAlias); |
- } |
- return m_pSysFont; |
- } |
- return NULL; |
-} |
-CFX_ByteString CPVT_FontMap::GetPDFFontAlias(int32_t nFontIndex) { |
- switch (nFontIndex) { |
- case 0: |
- return m_sDefFontAlias; |
- case 1: |
- if (!m_pSysFont) { |
- GetAnnotSysPDFFont(m_pDocument, m_pResDict, m_pSysFont, |
- m_sSysFontAlias); |
- } |
- return m_sSysFontAlias; |
- } |
- return ""; |
-} |
-CPVT_Provider::CPVT_Provider(IPVT_FontMap* pFontMap) : m_pFontMap(pFontMap) { |
- ASSERT(m_pFontMap); |
-} |
-CPVT_Provider::~CPVT_Provider() {} |
-int32_t CPVT_Provider::GetCharWidth(int32_t nFontIndex, |
- uint16_t word, |
- int32_t nWordStyle) { |
- if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex)) { |
- uint32_t charcode = pPDFFont->CharCodeFromUnicode(word); |
- if (charcode != CPDF_Font::kInvalidCharCode) { |
- return pPDFFont->GetCharWidthF(charcode); |
- } |
- } |
- return 0; |
-} |
-int32_t CPVT_Provider::GetTypeAscent(int32_t nFontIndex) { |
- if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex)) { |
- return pPDFFont->GetTypeAscent(); |
- } |
- return 0; |
-} |
-int32_t CPVT_Provider::GetTypeDescent(int32_t nFontIndex) { |
- if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex)) { |
- return pPDFFont->GetTypeDescent(); |
- } |
- return 0; |
-} |
-int32_t CPVT_Provider::GetWordFontIndex(uint16_t word, |
- int32_t charset, |
- int32_t nFontIndex) { |
- if (CPDF_Font* pDefFont = m_pFontMap->GetPDFFont(0)) { |
- if (pDefFont->CharCodeFromUnicode(word) != CPDF_Font::kInvalidCharCode) { |
- return 0; |
- } |
- } |
- if (CPDF_Font* pSysFont = m_pFontMap->GetPDFFont(1)) { |
- if (pSysFont->CharCodeFromUnicode(word) != CPDF_Font::kInvalidCharCode) { |
- return 1; |
- } |
- } |
- return -1; |
-} |
-FX_BOOL CPVT_Provider::IsLatinWord(uint16_t word) { |
- if ((word >= 0x61 && word <= 0x7A) || (word >= 0x41 && word <= 0x5A) || |
- word == 0x2D || word == 0x27) { |
- return TRUE; |
- } |
- return FALSE; |
-} |
-int32_t CPVT_Provider::GetDefaultFontIndex() { |
- return 0; |
-} |
- |
-static CFX_ByteString GetPDFWordString(IPVT_FontMap* pFontMap, |
- int32_t nFontIndex, |
- uint16_t Word, |
- uint16_t SubWord) { |
- CFX_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 CFX_ByteString GetWordRenderString(const CFX_ByteString& strWords) { |
- if (strWords.GetLength() > 0) { |
- return PDF_EncodeString(strWords) + " Tj\n"; |
- } |
- return ""; |
-} |
-static CFX_ByteString GetFontSetString(IPVT_FontMap* pFontMap, |
- int32_t nFontIndex, |
- FX_FLOAT fFontSize) { |
- CFX_ByteTextBuf sRet; |
- if (pFontMap) { |
- CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); |
- if (sFontAlias.GetLength() > 0 && fFontSize > 0) { |
- sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; |
- } |
- } |
- return sRet.GetByteString(); |
-} |
-static CPVT_Color ParseColor(const CFX_ByteString& str) { |
- CPDF_SimpleParser syntax(str); |
- if (syntax.FindTagParamFromStart("g", 1)) { |
- return CPVT_Color(CPVT_Color::kGray, FX_atof(syntax.GetWord())); |
- } |
- if (syntax.FindTagParamFromStart("rg", 3)) { |
- FX_FLOAT f1 = FX_atof(syntax.GetWord()); |
- FX_FLOAT f2 = FX_atof(syntax.GetWord()); |
- FX_FLOAT f3 = FX_atof(syntax.GetWord()); |
- return CPVT_Color(CPVT_Color::kRGB, f1, f2, f3); |
- } |
- if (syntax.FindTagParamFromStart("k", 4)) { |
- FX_FLOAT f1 = FX_atof(syntax.GetWord()); |
- FX_FLOAT f2 = FX_atof(syntax.GetWord()); |
- FX_FLOAT f3 = FX_atof(syntax.GetWord()); |
- FX_FLOAT f4 = FX_atof(syntax.GetWord()); |
- return CPVT_Color(CPVT_Color::kCMYK, f1, f2, f3, f4); |
- } |
- return CPVT_Color(CPVT_Color::kTransparent); |
-} |
-static CPVT_Color ParseColor(const CPDF_Array& array) { |
- CPVT_Color rt; |
- switch (array.GetCount()) { |
- case 1: |
- rt = CPVT_Color(CPVT_Color::kGray, array.GetFloatAt(0)); |
- break; |
- case 3: |
- rt = CPVT_Color(CPVT_Color::kRGB, array.GetFloatAt(0), |
- array.GetFloatAt(1), array.GetFloatAt(2)); |
- break; |
- case 4: |
- rt = CPVT_Color(CPVT_Color::kCMYK, array.GetFloatAt(0), |
- array.GetFloatAt(1), array.GetFloatAt(2), |
- array.GetFloatAt(3)); |
- break; |
- } |
- return rt; |
-} |
-static FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc, |
- CPDF_Dictionary* pAnnotDict, |
- const int32_t& nWidgetType) { |
- CPDF_Dictionary* pFormDict = NULL; |
- if (CPDF_Dictionary* pRootDict = pDoc->GetRoot()) { |
+FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc, |
+ CPDF_Dictionary* pAnnotDict, |
+ const int32_t& nWidgetType) { |
+ CPDF_Dictionary* pFormDict = nullptr; |
+ if (CPDF_Dictionary* pRootDict = pDoc->GetRoot()) |
pFormDict = pRootDict->GetDictBy("AcroForm"); |
- } |
- if (!pFormDict) { |
+ if (!pFormDict) |
return FALSE; |
- } |
+ |
CFX_ByteString DA; |
- if (CPDF_Object* pDAObj = FPDF_GetFieldAttr(pAnnotDict, "DA")) { |
+ if (CPDF_Object* pDAObj = FPDF_GetFieldAttr(pAnnotDict, "DA")) |
DA = pDAObj->GetString(); |
- } |
- if (DA.IsEmpty()) { |
+ if (DA.IsEmpty()) |
DA = pFormDict->GetStringBy("DA"); |
- } |
- if (DA.IsEmpty()) { |
+ if (DA.IsEmpty()) |
return FALSE; |
- } |
+ |
CPDF_SimpleParser syntax(DA); |
syntax.FindTagParamFromStart("Tf", 2); |
CFX_ByteString sFontName = syntax.GetWord(); |
sFontName = PDF_NameDecode(sFontName); |
- if (sFontName.IsEmpty()) { |
+ if (sFontName.IsEmpty()) |
return FALSE; |
- } |
+ |
FX_FLOAT fFontSize = FX_atof(syntax.GetWord()); |
- CPVT_Color crText = ParseColor(DA); |
+ CPVT_Color crText = CPVT_Color::ParseColor(DA); |
FX_BOOL bUseFormRes = FALSE; |
- CPDF_Dictionary* pFontDict = NULL; |
+ CPDF_Dictionary* pFontDict = nullptr; |
CPDF_Dictionary* pDRDict = pAnnotDict->GetDictBy("DR"); |
if (!pDRDict) { |
pDRDict = pFormDict->GetDictBy("DR"); |
@@ -311,14 +58,13 @@ static FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc, |
if (!pFontDict && !bUseFormRes) { |
pDRDict = pFormDict->GetDictBy("DR"); |
pDRFontDict = pDRDict->GetDictBy("Font"); |
- if (pDRFontDict) { |
+ if (pDRFontDict) |
pFontDict = pDRFontDict->GetDictBy(sFontName.Mid(1)); |
- } |
} |
} |
- if (!pDRFontDict) { |
+ if (!pDRFontDict) |
return FALSE; |
- } |
+ |
if (!pFontDict) { |
pFontDict = new CPDF_Dictionary; |
pFontDict->SetAtName("Type", "Font"); |
@@ -329,14 +75,14 @@ static FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc, |
pDRFontDict->SetAtReference(sFontName.Mid(1), pDoc, pFontDict); |
} |
CPDF_Font* pDefFont = pDoc->LoadFont(pFontDict); |
- if (!pDefFont) { |
+ if (!pDefFont) |
return FALSE; |
- } |
+ |
CFX_FloatRect rcAnnot = pAnnotDict->GetRectBy("Rect"); |
int32_t nRotate = 0; |
- if (CPDF_Dictionary* pMKDict = pAnnotDict->GetDictBy("MK")) { |
+ if (CPDF_Dictionary* pMKDict = pAnnotDict->GetDictBy("MK")) |
nRotate = pMKDict->GetIntegerBy("R"); |
- } |
+ |
CFX_FloatRect rcBBox; |
CFX_Matrix matrix; |
switch (nRotate % 360) { |
@@ -366,9 +112,9 @@ static FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc, |
CPVT_Dash dsBorder(3, 0, 0); |
CPVT_Color crLeftTop, crRightBottom; |
if (CPDF_Dictionary* pBSDict = pAnnotDict->GetDictBy("BS")) { |
- if (pBSDict->KeyExist("W")) { |
+ if (pBSDict->KeyExist("W")) |
fBorderWidth = pBSDict->GetNumberBy("W"); |
- } |
+ |
if (CPDF_Array* pArray = pBSDict->GetArrayBy("D")) { |
dsBorder = CPVT_Dash(pArray->GetIntegerAt(0), pArray->GetIntegerAt(1), |
pArray->GetIntegerAt(2)); |
@@ -399,12 +145,10 @@ static FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc, |
} |
CPVT_Color crBorder, crBG; |
if (CPDF_Dictionary* pMKDict = pAnnotDict->GetDictBy("MK")) { |
- if (CPDF_Array* pArray = pMKDict->GetArrayBy("BC")) { |
- crBorder = ParseColor(*pArray); |
- } |
- if (CPDF_Array* pArray = pMKDict->GetArrayBy("BG")) { |
- crBG = ParseColor(*pArray); |
- } |
+ if (CPDF_Array* pArray = pMKDict->GetArrayBy("BC")) |
+ crBorder = CPVT_Color::ParseColor(*pArray); |
+ if (CPDF_Array* pArray = pMKDict->GetArrayBy("BG")) |
+ crBG = CPVT_Color::ParseColor(*pArray); |
} |
CFX_ByteTextBuf sAppStream; |
CFX_ByteString sBG = CPVT_GenerateAP::GenerateColorAP(crBG, TRUE); |
@@ -416,9 +160,9 @@ static FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc, |
CFX_ByteString sBorderStream = CPVT_GenerateAP::GenerateBorderAP( |
rcBBox, fBorderWidth, crBorder, crLeftTop, crRightBottom, nBorderStyle, |
dsBorder); |
- if (sBorderStream.GetLength() > 0) { |
+ if (sBorderStream.GetLength() > 0) |
sAppStream << "q\n" << sBorderStream << "Q\n"; |
- } |
+ |
CFX_FloatRect rcBody = |
CFX_FloatRect(rcBBox.left + fBorderWidth, rcBBox.bottom + fBorderWidth, |
rcBBox.right - fBorderWidth, rcBBox.top - fBorderWidth); |
@@ -445,9 +189,8 @@ static FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc, |
pStreamResFontList = new CPDF_Dictionary; |
pStreamResList->SetAt("Font", pStreamResFontList); |
} |
- if (!pStreamResFontList->KeyExist(sFontName)) { |
+ if (!pStreamResFontList->KeyExist(sFontName)) |
pStreamResFontList->SetAtReference(sFontName, pDoc, pFontDict); |
- } |
} else { |
pStreamDict->SetAt("Resources", pFormDict->GetDictBy("DR")->Clone()); |
pStreamResList = pStreamDict->GetDictBy("Resources"); |
@@ -469,19 +212,19 @@ static FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc, |
FPDF_GetFieldAttr(pAnnotDict, "MaxLen") |
? FPDF_GetFieldAttr(pAnnotDict, "MaxLen")->GetInteger() |
: 0; |
- CPVT_FontMap map(pDoc, |
- pStreamDict ? pStreamDict->GetDictBy("Resources") : NULL, |
- pDefFont, sFontName.Right(sFontName.GetLength() - 1)); |
+ CPVT_FontMap map( |
+ pDoc, pStreamDict ? pStreamDict->GetDictBy("Resources") : nullptr, |
+ pDefFont, sFontName.Right(sFontName.GetLength() - 1)); |
CPVT_Provider prd(&map); |
CPDF_VariableText vt; |
vt.SetProvider(&prd); |
vt.SetPlateRect(rcBody); |
vt.SetAlignment(nAlign); |
- if (IsFloatZero(fFontSize)) { |
+ if (IsFloatZero(fFontSize)) |
vt.SetAutoFontSize(TRUE); |
- } else { |
+ else |
vt.SetFontSize(fFontSize); |
- } |
+ |
FX_BOOL bMultiLine = (dwFlags >> 12) & 1; |
if (bMultiLine) { |
vt.SetMultiLine(TRUE); |
@@ -493,11 +236,11 @@ static FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc, |
vt.SetPasswordChar(subWord); |
} |
FX_BOOL bCharArray = (dwFlags >> 24) & 1; |
- if (bCharArray) { |
+ if (bCharArray) |
vt.SetCharArray(dwMaxLen); |
- } else { |
+ else |
vt.SetLimitChar(dwMaxLen); |
- } |
+ |
vt.Initialize(); |
vt.SetText(swValue.c_str()); |
vt.RearrangeAll(); |
@@ -528,9 +271,9 @@ static FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc, |
FPDF_GetFieldAttr(pAnnotDict, "V") |
? FPDF_GetFieldAttr(pAnnotDict, "V")->GetUnicodeText() |
: CFX_WideString(); |
- CPVT_FontMap map(pDoc, |
- pStreamDict ? pStreamDict->GetDictBy("Resources") : NULL, |
- pDefFont, sFontName.Right(sFontName.GetLength() - 1)); |
+ CPVT_FontMap map( |
+ pDoc, pStreamDict ? pStreamDict->GetDictBy("Resources") : nullptr, |
+ pDefFont, sFontName.Right(sFontName.GetLength() - 1)); |
CPVT_Provider prd(&map); |
CPDF_VariableText vt; |
vt.SetProvider(&prd); |
@@ -541,11 +284,11 @@ static FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc, |
rcEdit.right = rcButton.left; |
rcEdit.Normalize(); |
vt.SetPlateRect(rcEdit); |
- if (IsFloatZero(fFontSize)) { |
+ if (IsFloatZero(fFontSize)) |
vt.SetAutoFontSize(TRUE); |
- } else { |
+ else |
vt.SetFontSize(fFontSize); |
- } |
+ |
vt.Initialize(); |
vt.SetText(swValue.c_str()); |
vt.RearrangeAll(); |
@@ -577,9 +320,9 @@ static FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc, |
CPVT_Color(CPVT_Color::kGray, 1), |
CPVT_Color(CPVT_Color::kGray, 0.5), PBS_BEVELED, |
CPVT_Dash(3, 0, 0)); |
- if (sButtonBorder.GetLength() > 0) { |
+ if (sButtonBorder.GetLength() > 0) |
sAppStream << "q\n" << sButtonBorder << "Q\n"; |
- } |
+ |
CFX_FloatPoint ptCenter = |
CFX_FloatPoint((rcButton.left + rcButton.right) / 2, |
(rcButton.top + rcButton.bottom) / 2); |
@@ -596,16 +339,16 @@ static FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc, |
} |
} break; |
case 2: { |
- CPVT_FontMap map(pDoc, |
- pStreamDict ? pStreamDict->GetDictBy("Resources") : NULL, |
- pDefFont, sFontName.Right(sFontName.GetLength() - 1)); |
+ CPVT_FontMap map( |
+ pDoc, pStreamDict ? pStreamDict->GetDictBy("Resources") : nullptr, |
+ pDefFont, sFontName.Right(sFontName.GetLength() - 1)); |
CPVT_Provider prd(&map); |
CPDF_Array* pOpts = FPDF_GetFieldAttr(pAnnotDict, "Opt") |
? FPDF_GetFieldAttr(pAnnotDict, "Opt")->GetArray() |
- : NULL; |
+ : nullptr; |
CPDF_Array* pSels = FPDF_GetFieldAttr(pAnnotDict, "I") |
? FPDF_GetFieldAttr(pAnnotDict, "I")->GetArray() |
- : NULL; |
+ : nullptr; |
int32_t nTop = FPDF_GetFieldAttr(pAnnotDict, "TI") |
? FPDF_GetFieldAttr(pAnnotDict, "TI")->GetInteger() |
: 0; |
@@ -613,9 +356,9 @@ static FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc, |
if (pOpts) { |
FX_FLOAT fy = rcBody.top; |
for (int32_t i = nTop, sz = pOpts->GetCount(); i < sz; i++) { |
- if (IsFloatSmaller(fy, rcBody.bottom)) { |
+ if (IsFloatSmaller(fy, rcBody.bottom)) |
break; |
- } |
+ |
if (CPDF_Object* pOpt = pOpts->GetDirectObjectAt(i)) { |
CFX_WideString swItem; |
if (pOpt->IsString()) |
@@ -636,11 +379,8 @@ static FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc, |
vt.SetProvider(&prd); |
vt.SetPlateRect( |
CFX_FloatRect(rcBody.left, 0.0f, rcBody.right, 0.0f)); |
- if (IsFloatZero(fFontSize)) { |
- vt.SetFontSize(12.0f); |
- } else { |
- vt.SetFontSize(fFontSize); |
- } |
+ vt.SetFontSize(IsFloatZero(fFontSize) ? 12.0f : fFontSize); |
+ |
vt.Initialize(); |
vt.SetText(swItem.c_str()); |
vt.RearrangeAll(); |
@@ -695,9 +435,8 @@ static FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc, |
pStreamResFontList = new CPDF_Dictionary; |
pStreamResList->SetAt("Font", pStreamResFontList); |
} |
- if (!pStreamResFontList->KeyExist(sFontName)) { |
+ if (!pStreamResFontList->KeyExist(sFontName)) |
pStreamResFontList->SetAtReference(sFontName, pDoc, pFontDict); |
- } |
} else { |
pStreamDict->SetAt("Resources", pFormDict->GetDictBy("DR")->Clone()); |
pStreamResList = pStreamDict->GetDictBy("Resources"); |
@@ -706,18 +445,58 @@ static FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc, |
} |
return TRUE; |
} |
+ |
+} // namespace |
+ |
+FX_BOOL FPDF_GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) { |
+ if (!pAnnotDict || pAnnotDict->GetConstStringBy("Subtype") != "Widget") { |
+ return FALSE; |
+ } |
+ CFX_ByteString field_type = FPDF_GetFieldAttr(pAnnotDict, "FT")->GetString(); |
+ uint32_t flags = FPDF_GetFieldAttr(pAnnotDict, "Ff") |
+ ? FPDF_GetFieldAttr(pAnnotDict, "Ff")->GetInteger() |
+ : 0; |
+ if (field_type == "Tx") { |
+ return CPVT_GenerateAP::GenerateTextFieldAP(pDoc, pAnnotDict); |
+ } |
+ if (field_type == "Ch") { |
+ return (flags & (1 << 17)) |
+ ? CPVT_GenerateAP::GenerateComboBoxAP(pDoc, pAnnotDict) |
+ : CPVT_GenerateAP::GenerateListBoxAP(pDoc, pAnnotDict); |
+ } |
+ if (field_type == "Btn") { |
+ if (!(flags & (1 << 16))) { |
+ if (!pAnnotDict->KeyExist("AS")) { |
+ if (CPDF_Dictionary* pParentDict = pAnnotDict->GetDictBy("Parent")) { |
+ if (pParentDict->KeyExist("AS")) { |
+ pAnnotDict->SetAtString("AS", pParentDict->GetStringBy("AS")); |
+ } |
+ } |
+ } |
+ } |
+ } |
+ return FALSE; |
+} |
+ |
+// Static. |
FX_BOOL CPVT_GenerateAP::GenerateTextFieldAP(CPDF_Document* pDoc, |
CPDF_Dictionary* pAnnotDict) { |
return GenerateWidgetAP(pDoc, pAnnotDict, 0); |
} |
+ |
+// Static. |
FX_BOOL CPVT_GenerateAP::GenerateComboBoxAP(CPDF_Document* pDoc, |
CPDF_Dictionary* pAnnotDict) { |
return GenerateWidgetAP(pDoc, pAnnotDict, 1); |
} |
+ |
+// Static. |
FX_BOOL CPVT_GenerateAP::GenerateListBoxAP(CPDF_Document* pDoc, |
CPDF_Dictionary* pAnnotDict) { |
return GenerateWidgetAP(pDoc, pAnnotDict, 2); |
} |
+ |
+// Static. |
CFX_ByteString CPVT_GenerateAP::GenerateEditAP( |
IPVT_FontMap* pFontMap, |
IPDF_VariableText_Iterator* pIterator, |
@@ -729,17 +508,17 @@ CFX_ByteString CPVT_GenerateAP::GenerateEditAP( |
CFX_FloatPoint ptOld(0.0f, 0.0f), ptNew(0.0f, 0.0f); |
int32_t nCurFontIndex = -1; |
if (pIterator) { |
- if (pVisible) { |
+ if (pVisible) |
pIterator->SetAt(pVisible->BeginPos); |
- } else { |
+ else |
pIterator->SetAt(0); |
- } |
+ |
CPVT_WordPlace oldplace; |
while (pIterator->NextWord()) { |
CPVT_WordPlace place = pIterator->GetAt(); |
- if (pVisible && place.WordCmp(pVisible->EndPos) > 0) { |
+ if (pVisible && place.WordCmp(pVisible->EndPos) > 0) |
break; |
- } |
+ |
if (bContinuous) { |
if (place.LineCmp(oldplace) != 0) { |
if (sWords.GetSize() > 0) { |
@@ -807,6 +586,8 @@ CFX_ByteString CPVT_GenerateAP::GenerateEditAP( |
} |
return sEditStream.GetByteString(); |
} |
+ |
+// Static. |
CFX_ByteString CPVT_GenerateAP::GenerateBorderAP( |
const CFX_FloatRect& rect, |
FX_FLOAT fWidth, |
@@ -913,6 +694,8 @@ CFX_ByteString CPVT_GenerateAP::GenerateBorderAP( |
} |
return sAppStream.GetByteString(); |
} |
+ |
+// Static. |
CFX_ByteString CPVT_GenerateAP::GenerateColorAP(const CPVT_Color& color, |
const FX_BOOL& bFillOrStroke) { |
CFX_ByteTextBuf sColorStream; |
@@ -936,3 +719,51 @@ CFX_ByteString CPVT_GenerateAP::GenerateColorAP(const CPVT_Color& color, |
} |
return sColorStream.GetByteString(); |
} |
+ |
+// Static. |
+CFX_ByteString CPVT_GenerateAP::GetPDFWordString(IPVT_FontMap* pFontMap, |
+ int32_t nFontIndex, |
+ uint16_t Word, |
+ uint16_t SubWord) { |
+ CFX_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. |
+CFX_ByteString CPVT_GenerateAP::GetWordRenderString( |
+ const CFX_ByteString& strWords) { |
+ if (strWords.GetLength() > 0) |
+ return PDF_EncodeString(strWords) + " Tj\n"; |
+ return ""; |
+} |
+ |
+// Static. |
+CFX_ByteString CPVT_GenerateAP::GetFontSetString(IPVT_FontMap* pFontMap, |
+ int32_t nFontIndex, |
+ FX_FLOAT fFontSize) { |
+ CFX_ByteTextBuf sRet; |
+ if (pFontMap) { |
+ CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); |
+ if (sFontAlias.GetLength() > 0 && fFontSize > 0) |
+ sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; |
+ } |
+ return sRet.GetByteString(); |
+} |