Cleanup string passing in core/fpdf*
Return strings where possible.
Add missing consts to strings passed by ref.
Convert non-const cases to pointers.
Rename a few methods to be clearer.
Change-Id: I86569bc1744f539e6dd67fc73649b272c016328c
Reviewed-on: https://pdfium-review.googlesource.com/3951
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Nicolás Peña <npm@chromium.org>
diff --git a/core/fpdfapi/page/cpdf_streamparser.cpp b/core/fpdfapi/page/cpdf_streamparser.cpp
index 3c4e534..e0c6e25 100644
--- a/core/fpdfapi/page/cpdf_streamparser.cpp
+++ b/core/fpdfapi/page/cpdf_streamparser.cpp
@@ -62,7 +62,7 @@
uint32_t limit,
int width,
int height,
- CFX_ByteString& decoder,
+ const CFX_ByteString& decoder,
CPDF_Dictionary* pParam,
uint8_t*& dest_buf,
uint32_t& dest_size) {
diff --git a/core/fpdfapi/parser/cpdf_crypto_handler.cpp b/core/fpdfapi/parser/cpdf_crypto_handler.cpp
index 4fc7b30..ea09601 100644
--- a/core/fpdfapi/parser/cpdf_crypto_handler.cpp
+++ b/core/fpdfapi/parser/cpdf_crypto_handler.cpp
@@ -227,14 +227,14 @@
return true;
}
-void CPDF_CryptoHandler::Decrypt(uint32_t objnum,
- uint32_t gennum,
- CFX_ByteString& str) {
+CFX_ByteString CPDF_CryptoHandler::Decrypt(uint32_t objnum,
+ uint32_t gennum,
+ const CFX_ByteString& str) {
CFX_BinaryBuf dest_buf;
void* context = DecryptStart(objnum, gennum);
DecryptStream(context, str.raw_str(), str.GetLength(), dest_buf);
DecryptFinish(context, dest_buf);
- str = CFX_ByteString(dest_buf.GetBuffer(), dest_buf.GetSize());
+ return CFX_ByteString(dest_buf.GetBuffer(), dest_buf.GetSize());
}
void* CPDF_CryptoHandler::DecryptStart(uint32_t objnum, uint32_t gennum) {
diff --git a/core/fpdfapi/parser/cpdf_crypto_handler.h b/core/fpdfapi/parser/cpdf_crypto_handler.h
index 63a2590..1e3890a 100644
--- a/core/fpdfapi/parser/cpdf_crypto_handler.h
+++ b/core/fpdfapi/parser/cpdf_crypto_handler.h
@@ -23,7 +23,9 @@
CPDF_SecurityHandler* pSecurityHandler);
uint32_t DecryptGetSize(uint32_t src_size);
void* DecryptStart(uint32_t objnum, uint32_t gennum);
- void Decrypt(uint32_t objnum, uint32_t gennum, CFX_ByteString& str);
+ CFX_ByteString Decrypt(uint32_t objnum,
+ uint32_t gennum,
+ const CFX_ByteString& str);
bool DecryptStream(void* context,
const uint8_t* src_buf,
uint32_t src_size,
diff --git a/core/fpdfapi/parser/cpdf_data_avail.cpp b/core/fpdfapi/parser/cpdf_data_avail.cpp
index 5a2db88..aa0b4fd 100644
--- a/core/fpdfapi/parser/cpdf_data_avail.cpp
+++ b/core/fpdfapi/parser/cpdf_data_avail.cpp
@@ -837,7 +837,7 @@
m_Pos = dwOffset;
}
-bool CPDF_DataAvail::GetNextToken(CFX_ByteString& token) {
+bool CPDF_DataAvail::GetNextToken(CFX_ByteString* token) {
uint8_t ch;
if (!GetNextChar(ch))
return false;
@@ -870,11 +870,9 @@
if (!PDFCharIsOther(ch) && !PDFCharIsNumeric(ch)) {
m_Pos--;
- CFX_ByteString ret(buffer, index);
- token = ret;
+ *token = CFX_ByteString(buffer, index);
return true;
}
-
if (index < sizeof(buffer))
buffer[index++] = ch;
}
@@ -895,9 +893,7 @@
else
m_Pos--;
}
-
- CFX_ByteString ret(buffer, index);
- token = ret;
+ *token = CFX_ByteString(buffer, index);
return true;
}
@@ -914,7 +910,7 @@
}
}
- token = CFX_ByteString(buffer, index);
+ *token = CFX_ByteString(buffer, index);
return true;
}
@@ -948,8 +944,9 @@
int32_t iSize = 0;
CFX_ByteString token;
while (1) {
- if (!GetNextToken(token)) {
- iSize = (int32_t)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos : 512);
+ if (!GetNextToken(&token)) {
+ iSize = static_cast<int32_t>(
+ m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos : 512);
pHints->AddSegment(m_Pos, iSize);
return false;
}
@@ -983,8 +980,9 @@
bool CPDF_DataAvail::CheckCrossRef(DownloadHints* pHints) {
int32_t iSize = 0;
CFX_ByteString token;
- if (!GetNextToken(token)) {
- iSize = (int32_t)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos : 512);
+ if (!GetNextToken(&token)) {
+ iSize = static_cast<int32_t>(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos
+ : 512);
pHints->AddSegment(m_Pos, iSize);
return false;
}
@@ -995,8 +993,9 @@
}
while (1) {
- if (!GetNextToken(token)) {
- iSize = (int32_t)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos : 512);
+ if (!GetNextToken(&token)) {
+ iSize = static_cast<int32_t>(
+ m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos : 512);
pHints->AddSegment(m_Pos, iSize);
m_docStatus = PDF_DATAAVAIL_CROSSREF_ITEM;
return false;
diff --git a/core/fpdfapi/parser/cpdf_data_avail.h b/core/fpdfapi/parser/cpdf_data_avail.h
index 65638cf..62c5d49 100644
--- a/core/fpdfapi/parser/cpdf_data_avail.h
+++ b/core/fpdfapi/parser/cpdf_data_avail.h
@@ -156,7 +156,7 @@
int32_t CheckCrossRefStream(DownloadHints* pHints, FX_FILESIZE& xref_offset);
bool IsLinearizedFile(uint8_t* pData, uint32_t dwLen);
void SetStartOffset(FX_FILESIZE dwOffset);
- bool GetNextToken(CFX_ByteString& token);
+ bool GetNextToken(CFX_ByteString* token);
bool GetNextChar(uint8_t& ch);
std::unique_ptr<CPDF_Object> ParseIndirectObjectAt(
FX_FILESIZE pos,
diff --git a/core/fpdfapi/parser/cpdf_stream_acc.cpp b/core/fpdfapi/parser/cpdf_stream_acc.cpp
index 77ef2ff..fe333e4 100644
--- a/core/fpdfapi/parser/cpdf_stream_acc.cpp
+++ b/core/fpdfapi/parser/cpdf_stream_acc.cpp
@@ -43,7 +43,7 @@
m_pData = pSrcData;
m_dwSize = dwSrcSize;
} else if (!PDF_DataDecode(pSrcData, dwSrcSize, m_pStream->GetDict(), m_pData,
- m_dwSize, m_ImageDecoder, m_pImageParam,
+ m_dwSize, &m_ImageDecoder, m_pImageParam,
estimated_size, bImageAcc)) {
m_pData = pSrcData;
m_dwSize = dwSrcSize;
diff --git a/core/fpdfapi/parser/cpdf_syntax_parser.cpp b/core/fpdfapi/parser/cpdf_syntax_parser.cpp
index 73bf56d..1c84b85 100644
--- a/core/fpdfapi/parser/cpdf_syntax_parser.cpp
+++ b/core/fpdfapi/parser/cpdf_syntax_parser.cpp
@@ -405,13 +405,13 @@
if (word == "(") {
CFX_ByteString str = ReadString();
if (m_pCryptoHandler && bDecrypt)
- m_pCryptoHandler->Decrypt(objnum, gennum, str);
+ str = m_pCryptoHandler->Decrypt(objnum, gennum, str);
return pdfium::MakeUnique<CPDF_String>(m_pPool, str, false);
}
if (word == "<") {
CFX_ByteString str = ReadHexString();
if (m_pCryptoHandler && bDecrypt)
- m_pCryptoHandler->Decrypt(objnum, gennum, str);
+ str = m_pCryptoHandler->Decrypt(objnum, gennum, str);
return pdfium::MakeUnique<CPDF_String>(m_pPool, str, true);
}
if (word == "[") {
@@ -526,17 +526,17 @@
if (word == "(") {
CFX_ByteString str = ReadString();
if (m_pCryptoHandler)
- m_pCryptoHandler->Decrypt(objnum, gennum, str);
+ str = m_pCryptoHandler->Decrypt(objnum, gennum, str);
return pdfium::MakeUnique<CPDF_String>(m_pPool, str, false);
}
if (word == "<") {
CFX_ByteString str = ReadHexString();
if (m_pCryptoHandler)
- m_pCryptoHandler->Decrypt(objnum, gennum, str);
+ str = m_pCryptoHandler->Decrypt(objnum, gennum, str);
return pdfium::MakeUnique<CPDF_String>(m_pPool, str, true);
}
if (word == "[") {
- std::unique_ptr<CPDF_Array> pArray = pdfium::MakeUnique<CPDF_Array>();
+ auto pArray = pdfium::MakeUnique<CPDF_Array>();
while (std::unique_ptr<CPDF_Object> pObj =
GetObject(pObjList, objnum, gennum, true)) {
pArray->Add(std::move(pObj));
diff --git a/core/fpdfapi/parser/fpdf_parser_decode.cpp b/core/fpdfapi/parser/fpdf_parser_decode.cpp
index a1698ae..cc8b507 100644
--- a/core/fpdfapi/parser/fpdf_parser_decode.cpp
+++ b/core/fpdfapi/parser/fpdf_parser_decode.cpp
@@ -327,7 +327,7 @@
const CPDF_Dictionary* pDict,
uint8_t*& dest_buf,
uint32_t& dest_size,
- CFX_ByteString& ImageEncoding,
+ CFX_ByteString* ImageEncoding,
CPDF_Dictionary*& pImageParms,
uint32_t last_estimated_size,
bool bImageAcc) {
@@ -362,8 +362,8 @@
int offset = -1;
if (decoder == "FlateDecode" || decoder == "Fl") {
if (bImageAcc && i == nSize - 1) {
- ImageEncoding = "FlateDecode";
- dest_buf = (uint8_t*)last_buf;
+ *ImageEncoding = "FlateDecode";
+ dest_buf = last_buf;
dest_size = last_size;
pImageParms = pParam;
return true;
@@ -379,8 +379,8 @@
offset = HexDecode(last_buf, last_size, new_buf, new_size);
} else if (decoder == "RunLengthDecode" || decoder == "RL") {
if (bImageAcc && i == nSize - 1) {
- ImageEncoding = "RunLengthDecode";
- dest_buf = (uint8_t*)last_buf;
+ *ImageEncoding = "RunLengthDecode";
+ dest_buf = last_buf;
dest_size = last_size;
pImageParms = pParam;
return true;
@@ -395,9 +395,9 @@
} else if (decoder == "CCF") {
decoder = "CCITTFaxDecode";
}
- ImageEncoding = decoder;
+ *ImageEncoding = decoder;
pImageParms = pParam;
- dest_buf = (uint8_t*)last_buf;
+ dest_buf = last_buf;
dest_size = last_size;
if (CPDF_Array* pDecoders = pDecoder->AsArray())
pDecoders->RemoveAt(i + 1, pDecoders->GetCount() - i - 1);
@@ -413,7 +413,7 @@
last_buf = new_buf;
last_size = new_size;
}
- ImageEncoding = "";
+ *ImageEncoding = "";
pImageParms = nullptr;
dest_buf = last_buf;
dest_size = last_size;
diff --git a/core/fpdfapi/parser/fpdf_parser_decode.h b/core/fpdfapi/parser/fpdf_parser_decode.h
index 0c74e41..955a8cf 100644
--- a/core/fpdfapi/parser/fpdf_parser_decode.h
+++ b/core/fpdfapi/parser/fpdf_parser_decode.h
@@ -87,7 +87,7 @@
const CPDF_Dictionary* pDict,
uint8_t*& dest_buf,
uint32_t& dest_size,
- CFX_ByteString& ImageEncoding,
+ CFX_ByteString* ImageEncoding,
CPDF_Dictionary*& pImageParms,
uint32_t estimated_size,
bool bImageAcc);
diff --git a/core/fpdfdoc/cpdf_defaultappearance.cpp b/core/fpdfdoc/cpdf_defaultappearance.cpp
index 1873c1a..28213aa 100644
--- a/core/fpdfdoc/cpdf_defaultappearance.cpp
+++ b/core/fpdfdoc/cpdf_defaultappearance.cpp
@@ -36,20 +36,19 @@
return csFont;
}
-void CPDF_DefaultAppearance::GetFont(CFX_ByteString& csFontNameTag,
- float& fFontSize) {
- csFontNameTag = "";
- fFontSize = 0;
+CFX_ByteString CPDF_DefaultAppearance::GetFont(float* fFontSize) {
+ *fFontSize = 0.0f;
if (m_csDA.IsEmpty())
- return;
+ return CFX_ByteString();
+ CFX_ByteString csFontNameTag;
CPDF_SimpleParser syntax(m_csDA.AsStringC());
if (syntax.FindTagParamFromStart("Tf", 2)) {
csFontNameTag = CFX_ByteString(syntax.GetWord());
csFontNameTag.Delete(0, 1);
- fFontSize = FX_atof(syntax.GetWord());
+ *fFontSize = FX_atof(syntax.GetWord());
}
- csFontNameTag = PDF_NameDecode(csFontNameTag);
+ return PDF_NameDecode(csFontNameTag);
}
bool CPDF_DefaultAppearance::HasColor(PaintOperation nOperation) {
diff --git a/core/fpdfdoc/cpdf_defaultappearance.h b/core/fpdfdoc/cpdf_defaultappearance.h
index 0edc18c..3be06e2 100644
--- a/core/fpdfdoc/cpdf_defaultappearance.h
+++ b/core/fpdfdoc/cpdf_defaultappearance.h
@@ -29,7 +29,7 @@
bool HasFont();
CFX_ByteString GetFontString();
- void GetFont(CFX_ByteString& csFontNameTag, float& fFontSize);
+ CFX_ByteString GetFont(float* fFontSize);
bool HasColor(PaintOperation nOperation = PaintOperation::FILL);
CFX_ByteString GetColorString(
diff --git a/core/fpdfdoc/cpdf_docjsactions.cpp b/core/fpdfdoc/cpdf_docjsactions.cpp
index a7fcdfd..c0e7a78 100644
--- a/core/fpdfdoc/cpdf_docjsactions.cpp
+++ b/core/fpdfdoc/cpdf_docjsactions.cpp
@@ -16,11 +16,12 @@
return name_tree.GetCount();
}
-CPDF_Action CPDF_DocJSActions::GetJSAction(int index,
- CFX_ByteString& csName) const {
+CPDF_Action CPDF_DocJSActions::GetJSActionAndName(
+ int index,
+ CFX_ByteString* csName) const {
ASSERT(m_pDocument);
CPDF_NameTree name_tree(m_pDocument, "JavaScript");
- CPDF_Object* pAction = name_tree.LookupValue(index, csName);
+ CPDF_Object* pAction = name_tree.LookupValueAndName(index, csName);
return ToDictionary(pAction) ? CPDF_Action(pAction->GetDict())
: CPDF_Action();
}
diff --git a/core/fpdfdoc/cpdf_docjsactions.h b/core/fpdfdoc/cpdf_docjsactions.h
index 8a8d03d..16b6be3 100644
--- a/core/fpdfdoc/cpdf_docjsactions.h
+++ b/core/fpdfdoc/cpdf_docjsactions.h
@@ -17,7 +17,7 @@
explicit CPDF_DocJSActions(CPDF_Document* pDoc);
int CountJSActions() const;
- CPDF_Action GetJSAction(int index, CFX_ByteString& csName) const;
+ CPDF_Action GetJSActionAndName(int index, CFX_ByteString* csName) const;
CPDF_Action GetJSAction(const CFX_ByteString& csName) const;
int FindJSAction(const CFX_ByteString& csName) const;
CPDF_Document* GetDocument() const { return m_pDocument; }
diff --git a/core/fpdfdoc/cpdf_formcontrol.cpp b/core/fpdfdoc/cpdf_formcontrol.cpp
index b8a11cc..d8d6854 100644
--- a/core/fpdfdoc/cpdf_formcontrol.cpp
+++ b/core/fpdfdoc/cpdf_formcontrol.cpp
@@ -280,10 +280,9 @@
}
CPDF_Font* CPDF_FormControl::GetDefaultControlFont() {
- CPDF_DefaultAppearance cDA = GetDefaultAppearance();
- CFX_ByteString csFontNameTag;
float fFontSize;
- cDA.GetFont(csFontNameTag, fFontSize);
+ CPDF_DefaultAppearance cDA = GetDefaultAppearance();
+ CFX_ByteString csFontNameTag = cDA.GetFont(&fFontSize);
if (csFontNameTag.IsEmpty())
return nullptr;
diff --git a/core/fpdfdoc/cpdf_interform.cpp b/core/fpdfdoc/cpdf_interform.cpp
index 1192e6e..ebe5079 100644
--- a/core/fpdfdoc/cpdf_interform.cpp
+++ b/core/fpdfdoc/cpdf_interform.cpp
@@ -55,7 +55,7 @@
void AddFont(CPDF_Dictionary*& pFormDict,
CPDF_Document* pDocument,
const CPDF_Font* pFont,
- CFX_ByteString& csNameTag);
+ CFX_ByteString* csNameTag);
void InitDict(CPDF_Dictionary*& pFormDict, CPDF_Document* pDocument) {
if (!pDocument)
@@ -70,27 +70,24 @@
CFX_ByteString csDA;
if (!pFormDict->KeyExist("DR")) {
CFX_ByteString csBaseName;
- CFX_ByteString csDefault;
uint8_t charSet = CPDF_InterForm::GetNativeCharSet();
CPDF_Font* pFont = CPDF_InterForm::AddStandardFont(pDocument, "Helvetica");
- if (pFont) {
- AddFont(pFormDict, pDocument, pFont, csBaseName);
- csDefault = csBaseName;
- }
+ if (pFont)
+ AddFont(pFormDict, pDocument, pFont, &csBaseName);
+
if (charSet != FXFONT_ANSI_CHARSET) {
CFX_ByteString csFontName =
CPDF_InterForm::GetNativeFont(charSet, nullptr);
if (!pFont || csFontName != "Helvetica") {
pFont = CPDF_InterForm::AddNativeFont(pDocument);
if (pFont) {
- csBaseName = "";
- AddFont(pFormDict, pDocument, pFont, csBaseName);
- csDefault = csBaseName;
+ csBaseName.clear();
+ AddFont(pFormDict, pDocument, pFont, &csBaseName);
}
}
}
if (pFont)
- csDA = "/" + PDF_NameEncode(csDefault) + " 0 Tf";
+ csDA = "/" + PDF_NameEncode(csBaseName) + " 0 Tf";
}
if (!csDA.IsEmpty())
csDA += " ";
@@ -102,7 +99,7 @@
CPDF_Font* GetFont(CPDF_Dictionary* pFormDict,
CPDF_Document* pDocument,
- CFX_ByteString csNameTag) {
+ const CFX_ByteString& csNameTag) {
CFX_ByteString csAlias = PDF_NameDecode(csNameTag);
if (!pFormDict || csAlias.IsEmpty())
return nullptr;
@@ -127,7 +124,7 @@
CPDF_Font* GetNativeFont(CPDF_Dictionary* pFormDict,
CPDF_Document* pDocument,
uint8_t charSet,
- CFX_ByteString& csNameTag) {
+ CFX_ByteString* csNameTag) {
if (!pFormDict)
return nullptr;
@@ -157,8 +154,8 @@
if (!pSubst)
continue;
- if (pSubst->m_Charset == (int)charSet) {
- csNameTag = csKey;
+ if (pSubst->m_Charset == static_cast<int>(charSet)) {
+ *csNameTag = csKey;
return pFind;
}
}
@@ -167,7 +164,7 @@
bool FindFont(CPDF_Dictionary* pFormDict,
const CPDF_Font* pFont,
- CFX_ByteString& csNameTag) {
+ CFX_ByteString* csNameTag) {
if (!pFormDict || !pFont)
return false;
@@ -189,7 +186,7 @@
if (pElement->GetStringFor("Type") != "Font")
continue;
if (pFont->GetFontDict() == pElement) {
- csNameTag = csKey;
+ *csNameTag = csKey;
return true;
}
}
@@ -200,7 +197,7 @@
CPDF_Document* pDocument,
CFX_ByteString csFontName,
CPDF_Font*& pFont,
- CFX_ByteString& csNameTag) {
+ CFX_ByteString* csNameTag) {
if (!pFormDict)
return false;
@@ -211,6 +208,7 @@
CPDF_Dictionary* pFonts = pDR->GetDictFor("Font");
if (!pFonts)
return false;
+
if (csFontName.GetLength() > 0)
csFontName.Remove(' ');
@@ -232,7 +230,7 @@
csBaseFont = pFont->GetBaseFont();
csBaseFont.Remove(' ');
if (csBaseFont == csFontName) {
- csNameTag = csKey;
+ *csNameTag = csKey;
return true;
}
}
@@ -242,15 +240,15 @@
void AddFont(CPDF_Dictionary*& pFormDict,
CPDF_Document* pDocument,
const CPDF_Font* pFont,
- CFX_ByteString& csNameTag) {
+ CFX_ByteString* csNameTag) {
if (!pFont)
return;
if (!pFormDict)
InitDict(pFormDict, pDocument);
CFX_ByteString csTag;
- if (FindFont(pFormDict, pFont, csTag)) {
- csNameTag = csTag;
+ if (FindFont(pFormDict, pFont, &csTag)) {
+ *csNameTag = csTag;
return;
}
if (!pFormDict)
@@ -264,27 +262,27 @@
if (!pFonts)
pFonts = pDR->SetNewFor<CPDF_Dictionary>("Font");
- if (csNameTag.IsEmpty())
- csNameTag = pFont->GetBaseFont();
+ if (csNameTag->IsEmpty())
+ *csNameTag = pFont->GetBaseFont();
- csNameTag.Remove(' ');
- csNameTag = CPDF_InterForm::GenerateNewResourceName(pDR, "Font", 4,
- csNameTag.c_str());
- pFonts->SetNewFor<CPDF_Reference>(csNameTag, pDocument,
+ csNameTag->Remove(' ');
+ *csNameTag = CPDF_InterForm::GenerateNewResourceName(pDR, "Font", 4,
+ csNameTag->c_str());
+ pFonts->SetNewFor<CPDF_Reference>(*csNameTag, pDocument,
pFont->GetFontDict()->GetObjNum());
}
CPDF_Font* AddNativeFont(CPDF_Dictionary*& pFormDict,
CPDF_Document* pDocument,
uint8_t charSet,
- CFX_ByteString& csNameTag) {
+ CFX_ByteString* csNameTag) {
if (!pFormDict)
InitDict(pFormDict, pDocument);
CFX_ByteString csTemp;
- CPDF_Font* pFont = GetNativeFont(pFormDict, pDocument, charSet, csTemp);
+ CPDF_Font* pFont = GetNativeFont(pFormDict, pDocument, charSet, &csTemp);
if (pFont) {
- csNameTag = csTemp;
+ *csNameTag = csTemp;
return pFont;
}
CFX_ByteString csFontName = CPDF_InterForm::GetNativeFont(charSet, nullptr);
@@ -565,7 +563,7 @@
CPDF_Font* AddNativeInterFormFont(CPDF_Dictionary*& pFormDict,
CPDF_Document* pDocument,
- CFX_ByteString& csNameTag) {
+ CFX_ByteString* csNameTag) {
uint8_t charSet = CPDF_InterForm::GetNativeCharSet();
return AddNativeFont(pFormDict, pDocument, charSet, csNameTag);
}
diff --git a/core/fpdfdoc/cpdf_interform.h b/core/fpdfdoc/cpdf_interform.h
index 6c464f0..74e5b10 100644
--- a/core/fpdfdoc/cpdf_interform.h
+++ b/core/fpdfdoc/cpdf_interform.h
@@ -29,7 +29,7 @@
CPDF_Font* AddNativeInterFormFont(CPDF_Dictionary*& pFormDict,
CPDF_Document* pDocument,
- CFX_ByteString& csNameTag);
+ CFX_ByteString* csNameTag);
class CPDF_InterForm {
public:
diff --git a/core/fpdfdoc/cpdf_nametree.cpp b/core/fpdfdoc/cpdf_nametree.cpp
index b8d1eb0..5ecdb48 100644
--- a/core/fpdfdoc/cpdf_nametree.cpp
+++ b/core/fpdfdoc/cpdf_nametree.cpp
@@ -78,7 +78,7 @@
CPDF_Object* SearchNameNode(CPDF_Dictionary* pNode,
size_t nIndex,
size_t& nCurIndex,
- CFX_ByteString& csName,
+ CFX_ByteString* csName,
CPDF_Array** ppFind,
int nLevel = 0) {
if (nLevel > nMaxRecursion)
@@ -93,7 +93,7 @@
}
if (ppFind)
*ppFind = pNames;
- csName = pNames->GetStringAt((nIndex - nCurIndex) * 2);
+ *csName = pNames->GetStringAt((nIndex - nCurIndex) * 2);
return pNames->GetDirectObjectAt((nIndex - nCurIndex) * 2 + 1);
}
CPDF_Array* pKids = pNode->GetArrayFor("Kids");
@@ -164,10 +164,12 @@
return nIndex;
}
-CPDF_Object* CPDF_NameTree::LookupValue(int nIndex,
- CFX_ByteString& csName) const {
+CPDF_Object* CPDF_NameTree::LookupValueAndName(int nIndex,
+ CFX_ByteString* csName) const {
+ *csName = CFX_ByteString();
if (!m_pRoot)
return nullptr;
+
size_t nCurIndex = 0;
return SearchNameNode(m_pRoot, nIndex, nCurIndex, csName, nullptr);
}
@@ -175,6 +177,7 @@
CPDF_Object* CPDF_NameTree::LookupValue(const CFX_ByteString& csName) const {
if (!m_pRoot)
return nullptr;
+
size_t nIndex = 0;
return SearchNameNode(m_pRoot, csName, nIndex, nullptr);
}
diff --git a/core/fpdfdoc/cpdf_nametree.h b/core/fpdfdoc/cpdf_nametree.h
index d6763ad..7a792ae 100644
--- a/core/fpdfdoc/cpdf_nametree.h
+++ b/core/fpdfdoc/cpdf_nametree.h
@@ -19,7 +19,7 @@
explicit CPDF_NameTree(CPDF_Dictionary* pRoot) : m_pRoot(pRoot) {}
CPDF_NameTree(CPDF_Document* pDoc, const CFX_ByteString& category);
- CPDF_Object* LookupValue(int nIndex, CFX_ByteString& csName) const;
+ CPDF_Object* LookupValueAndName(int nIndex, CFX_ByteString* csName) const;
CPDF_Object* LookupValue(const CFX_ByteString& csName) const;
CPDF_Array* LookupNamedDest(CPDF_Document* pDoc, const CFX_ByteString& sName);
diff --git a/core/fpdfdoc/cpvt_fontmap.cpp b/core/fpdfdoc/cpvt_fontmap.cpp
index 283f600..17ce673 100644
--- a/core/fpdfdoc/cpvt_fontmap.cpp
+++ b/core/fpdfdoc/cpvt_fontmap.cpp
@@ -25,25 +25,23 @@
CPVT_FontMap::~CPVT_FontMap() {}
-void CPVT_FontMap::GetAnnotSysPDFFont(CPDF_Document* pDoc,
- const CPDF_Dictionary* pResDict,
- CPDF_Font*& pSysFont,
- CFX_ByteString& sSysFontAlias) {
+CPDF_Font* CPVT_FontMap::GetAnnotSysPDFFont(CPDF_Document* pDoc,
+ const CPDF_Dictionary* pResDict,
+ CFX_ByteString* sSysFontAlias) {
if (!pDoc || !pResDict)
- return;
+ return nullptr;
- CFX_ByteString sFontAlias;
CPDF_Dictionary* pFormDict = pDoc->GetRoot()->GetDictFor("AcroForm");
CPDF_Font* pPDFFont = AddNativeInterFormFont(pFormDict, pDoc, sSysFontAlias);
if (!pPDFFont)
- return;
+ return nullptr;
CPDF_Dictionary* pFontList = pResDict->GetDictFor("Font");
- if (pFontList && !pFontList->KeyExist(sSysFontAlias)) {
- pFontList->SetNewFor<CPDF_Reference>(sSysFontAlias, pDoc,
+ if (pFontList && !pFontList->KeyExist(*sSysFontAlias)) {
+ pFontList->SetNewFor<CPDF_Reference>(*sSysFontAlias, pDoc,
pPDFFont->GetFontDict()->GetObjNum());
}
- pSysFont = pPDFFont;
+ return pPDFFont;
}
CPDF_Font* CPVT_FontMap::GetPDFFont(int32_t nFontIndex) {
@@ -52,8 +50,8 @@
return m_pDefFont;
case 1:
if (!m_pSysFont) {
- GetAnnotSysPDFFont(m_pDocument, m_pResDict, m_pSysFont,
- m_sSysFontAlias);
+ m_pSysFont =
+ GetAnnotSysPDFFont(m_pDocument, m_pResDict, &m_sSysFontAlias);
}
return m_pSysFont;
default:
@@ -67,12 +65,12 @@
return m_sDefFontAlias;
case 1:
if (!m_pSysFont) {
- GetAnnotSysPDFFont(m_pDocument, m_pResDict, m_pSysFont,
- m_sSysFontAlias);
+ m_pSysFont =
+ GetAnnotSysPDFFont(m_pDocument, m_pResDict, &m_sSysFontAlias);
}
return m_sSysFontAlias;
default:
- return "";
+ return CFX_ByteString();
}
}
diff --git a/core/fpdfdoc/cpvt_fontmap.h b/core/fpdfdoc/cpvt_fontmap.h
index 98e390f..6080010 100644
--- a/core/fpdfdoc/cpvt_fontmap.h
+++ b/core/fpdfdoc/cpvt_fontmap.h
@@ -33,10 +33,9 @@
int32_t CharCodeFromUnicode(int32_t nFontIndex, uint16_t word) override;
int32_t CharSetFromUnicode(uint16_t word, int32_t nOldCharset) override;
- static void GetAnnotSysPDFFont(CPDF_Document* pDoc,
- const CPDF_Dictionary* pResDict,
- CPDF_Font*& pSysFont,
- CFX_ByteString& sSysFontAlias);
+ static CPDF_Font* GetAnnotSysPDFFont(CPDF_Document* pDoc,
+ const CPDF_Dictionary* pResDict,
+ CFX_ByteString* sSysFontAlias);
private:
CPDF_Document* const m_pDocument;
diff --git a/fpdfsdk/cpdfsdk_formfillenvironment.cpp b/fpdfsdk/cpdfsdk_formfillenvironment.cpp
index 680cd25..6c6e367 100644
--- a/fpdfsdk/cpdfsdk_formfillenvironment.cpp
+++ b/fpdfsdk/cpdfsdk_formfillenvironment.cpp
@@ -609,7 +609,7 @@
return;
for (int i = 0; i < iCount; i++) {
CFX_ByteString csJSName;
- CPDF_Action jsAction = docJS.GetJSAction(i, csJSName);
+ CPDF_Action jsAction = docJS.GetJSActionAndName(i, &csJSName);
if (GetActionHander()) {
GetActionHander()->DoAction_JavaScript(
jsAction, CFX_WideString::FromLocal(csJSName.AsStringC()), this);
diff --git a/fpdfsdk/cpdfsdk_widget.cpp b/fpdfsdk/cpdfsdk_widget.cpp
index e65a94b..5f0bf1d 100644
--- a/fpdfsdk/cpdfsdk_widget.cpp
+++ b/fpdfsdk/cpdfsdk_widget.cpp
@@ -588,10 +588,8 @@
float CPDFSDK_Widget::GetFontSize() const {
CPDF_FormControl* pFormCtrl = GetFormControl();
CPDF_DefaultAppearance pDa = pFormCtrl->GetDefaultAppearance();
- CFX_ByteString csFont = "";
- float fFontSize = 0.0f;
- pDa.GetFont(csFont, fFontSize);
-
+ float fFontSize;
+ pDa.GetFont(&fFontSize);
return fFontSize;
}
@@ -930,21 +928,20 @@
CPWL_Color crText(COLORTYPE_GRAY, 0);
- float fFontSize = 12.0f;
CFX_ByteString csNameTag;
-
CPDF_DefaultAppearance da = pControl->GetDefaultAppearance();
if (da.HasColor()) {
da.GetColor(iColorType, fc);
crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
}
-
+ float fFontSize = 12.0f;
if (da.HasFont())
- da.GetFont(csNameTag, fFontSize);
+ csNameTag = da.GetFont(&fFontSize);
CFX_WideString csWCaption;
- CFX_WideString csNormalCaption, csRolloverCaption, csDownCaption;
-
+ CFX_WideString csNormalCaption;
+ CFX_WideString csRolloverCaption;
+ CFX_WideString csDownCaption;
if (pControl->HasMKEntry("CA"))
csNormalCaption = pControl->GetNormalCaption();
@@ -957,7 +954,6 @@
CPDF_Stream* pNormalIcon = nullptr;
CPDF_Stream* pRolloverIcon = nullptr;
CPDF_Stream* pDownIcon = nullptr;
-
if (pControl->HasMKEntry("I"))
pNormalIcon = pControl->GetNormalIcon();
diff --git a/fpdfsdk/fpdfview.cpp b/fpdfsdk/fpdfview.cpp
index 454f80f..5010c17 100644
--- a/fpdfsdk/fpdfview.cpp
+++ b/fpdfsdk/fpdfview.cpp
@@ -1249,7 +1249,7 @@
i++;
}
} else {
- pDestObj = nameTree.LookupValue(index, bsName);
+ pDestObj = nameTree.LookupValueAndName(index, &bsName);
}
if (!pDestObj)
return nullptr;
diff --git a/fpdfsdk/javascript/Field.cpp b/fpdfsdk/javascript/Field.cpp
index 12c3508..c7dc260 100644
--- a/fpdfsdk/javascript/Field.cpp
+++ b/fpdfsdk/javascript/Field.cpp
@@ -2482,12 +2482,10 @@
if (!pFormControl)
return false;
- CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance();
-
- CFX_ByteString csFontNameTag;
float fFontSize;
- FieldAppearance.GetFont(csFontNameTag, fFontSize);
- vp << (int)fFontSize;
+ CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance();
+ FieldAppearance.GetFont(&fFontSize);
+ vp << static_cast<int>(fFontSize);
return true;
}
diff --git a/xfa/fxfa/cxfa_ffdoc.cpp b/xfa/fxfa/cxfa_ffdoc.cpp
index 47f089e..4b6a1e2 100644
--- a/xfa/fxfa/cxfa_ffdoc.cpp
+++ b/xfa/fxfa/cxfa_ffdoc.cpp
@@ -373,7 +373,7 @@
if (!pObject) {
for (size_t i = 0; i < nametree.GetCount(); i++) {
CFX_ByteString bsTemp;
- CPDF_Object* pTempObject = nametree.LookupValue(i, bsTemp);
+ CPDF_Object* pTempObject = nametree.LookupValueAndName(i, &bsTemp);
if (bsTemp == bsName) {
pObject = pTempObject;
break;