diff options
author | Tom Sepez <tsepez@chromium.org> | 2017-04-07 13:56:13 -0700 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-04-07 21:16:15 +0000 |
commit | c4a2b7518949df00651aa3513c93079f1968441e (patch) | |
tree | 6befb2de2d0b8222cbc68f3c1cee99a20bea1cd0 /core/fpdfdoc | |
parent | 1835a6fb98286817cdf656f4d1e223bd85ee378f (diff) | |
download | pdfium-c4a2b7518949df00651aa3513c93079f1968441e.tar.xz |
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>
Diffstat (limited to 'core/fpdfdoc')
-rw-r--r-- | core/fpdfdoc/cpdf_defaultappearance.cpp | 13 | ||||
-rw-r--r-- | core/fpdfdoc/cpdf_defaultappearance.h | 2 | ||||
-rw-r--r-- | core/fpdfdoc/cpdf_docjsactions.cpp | 7 | ||||
-rw-r--r-- | core/fpdfdoc/cpdf_docjsactions.h | 2 | ||||
-rw-r--r-- | core/fpdfdoc/cpdf_formcontrol.cpp | 5 | ||||
-rw-r--r-- | core/fpdfdoc/cpdf_interform.cpp | 60 | ||||
-rw-r--r-- | core/fpdfdoc/cpdf_interform.h | 2 | ||||
-rw-r--r-- | core/fpdfdoc/cpdf_nametree.cpp | 11 | ||||
-rw-r--r-- | core/fpdfdoc/cpdf_nametree.h | 2 | ||||
-rw-r--r-- | core/fpdfdoc/cpvt_fontmap.cpp | 28 | ||||
-rw-r--r-- | core/fpdfdoc/cpvt_fontmap.h | 7 |
11 files changed, 68 insertions, 71 deletions
diff --git a/core/fpdfdoc/cpdf_defaultappearance.cpp b/core/fpdfdoc/cpdf_defaultappearance.cpp index 1873c1ae58..28213aa33b 100644 --- a/core/fpdfdoc/cpdf_defaultappearance.cpp +++ b/core/fpdfdoc/cpdf_defaultappearance.cpp @@ -36,20 +36,19 @@ CFX_ByteString CPDF_DefaultAppearance::GetFontString() { 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 0edc18c31f..3be06e294d 100644 --- a/core/fpdfdoc/cpdf_defaultappearance.h +++ b/core/fpdfdoc/cpdf_defaultappearance.h @@ -29,7 +29,7 @@ class CPDF_DefaultAppearance { 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 a7fcdfd071..c0e7a78fd6 100644 --- a/core/fpdfdoc/cpdf_docjsactions.cpp +++ b/core/fpdfdoc/cpdf_docjsactions.cpp @@ -16,11 +16,12 @@ int CPDF_DocJSActions::CountJSActions() const { 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 8a8d03d364..16b6be3d69 100644 --- a/core/fpdfdoc/cpdf_docjsactions.h +++ b/core/fpdfdoc/cpdf_docjsactions.h @@ -17,7 +17,7 @@ class CPDF_DocJSActions { 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 b8a11cc204..d8d6854b82 100644 --- a/core/fpdfdoc/cpdf_formcontrol.cpp +++ b/core/fpdfdoc/cpdf_formcontrol.cpp @@ -280,10 +280,9 @@ CPDF_DefaultAppearance CPDF_FormControl::GetDefaultAppearance() { } 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 1192e6e556..ebe5079f3b 100644 --- a/core/fpdfdoc/cpdf_interform.cpp +++ b/core/fpdfdoc/cpdf_interform.cpp @@ -55,7 +55,7 @@ CFX_WideString GetFieldValue(const CPDF_Dictionary& pFieldDict, 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 @@ void InitDict(CPDF_Dictionary*& pFormDict, CPDF_Document* pDocument) { 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 @@ void InitDict(CPDF_Dictionary*& pFormDict, CPDF_Document* pDocument) { 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* GetFont(CPDF_Dictionary* pFormDict, 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 @@ CPDF_Font* GetNativeFont(CPDF_Dictionary* pFormDict, 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 @@ CPDF_Font* GetNativeFont(CPDF_Dictionary* pFormDict, bool FindFont(CPDF_Dictionary* pFormDict, const CPDF_Font* pFont, - CFX_ByteString& csNameTag) { + CFX_ByteString* csNameTag) { if (!pFormDict || !pFont) return false; @@ -189,7 +186,7 @@ bool FindFont(CPDF_Dictionary* pFormDict, if (pElement->GetStringFor("Type") != "Font") continue; if (pFont->GetFontDict() == pElement) { - csNameTag = csKey; + *csNameTag = csKey; return true; } } @@ -200,7 +197,7 @@ bool FindFont(CPDF_Dictionary* pFormDict, CPDF_Document* pDocument, CFX_ByteString csFontName, CPDF_Font*& pFont, - CFX_ByteString& csNameTag) { + CFX_ByteString* csNameTag) { if (!pFormDict) return false; @@ -211,6 +208,7 @@ bool FindFont(CPDF_Dictionary* pFormDict, CPDF_Dictionary* pFonts = pDR->GetDictFor("Font"); if (!pFonts) return false; + if (csFontName.GetLength() > 0) csFontName.Remove(' '); @@ -232,7 +230,7 @@ bool FindFont(CPDF_Dictionary* pFormDict, csBaseFont = pFont->GetBaseFont(); csBaseFont.Remove(' '); if (csBaseFont == csFontName) { - csNameTag = csKey; + *csNameTag = csKey; return true; } } @@ -242,15 +240,15 @@ bool FindFont(CPDF_Dictionary* pFormDict, 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 @@ void AddFont(CPDF_Dictionary*& pFormDict, 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 @@ CFieldTree::Node* CFieldTree::FindNode(const CFX_WideString& full_name) { 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 6c464f023d..74e5b10864 100644 --- a/core/fpdfdoc/cpdf_interform.h +++ b/core/fpdfdoc/cpdf_interform.h @@ -29,7 +29,7 @@ class IPDF_FormNotify; 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 b8d1eb0ab1..5ecdb4863b 100644 --- a/core/fpdfdoc/cpdf_nametree.cpp +++ b/core/fpdfdoc/cpdf_nametree.cpp @@ -78,7 +78,7 @@ CPDF_Object* SearchNameNode(CPDF_Dictionary* pNode, 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 @@ CPDF_Object* SearchNameNode(CPDF_Dictionary* pNode, } 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 @@ int CPDF_NameTree::GetIndex(const CFX_ByteString& csName) const { 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(int nIndex, 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 d6763ad987..7a792aef59 100644 --- a/core/fpdfdoc/cpdf_nametree.h +++ b/core/fpdfdoc/cpdf_nametree.h @@ -19,7 +19,7 @@ class CPDF_NameTree { 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 283f60011b..17ce673fde 100644 --- a/core/fpdfdoc/cpvt_fontmap.cpp +++ b/core/fpdfdoc/cpvt_fontmap.cpp @@ -25,25 +25,23 @@ CPVT_FontMap::CPVT_FontMap(CPDF_Document* pDoc, 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 @@ CPDF_Font* CPVT_FontMap::GetPDFFont(int32_t nFontIndex) { 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 @@ CFX_ByteString CPVT_FontMap::GetPDFFontAlias(int32_t nFontIndex) { 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 98e390f409..6080010cac 100644 --- a/core/fpdfdoc/cpvt_fontmap.h +++ b/core/fpdfdoc/cpvt_fontmap.h @@ -33,10 +33,9 @@ class CPVT_FontMap : public IPVT_FontMap { 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; |