diff options
author | Lei Zhang <thestig@chromium.org> | 2018-08-20 19:01:20 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-08-20 19:01:20 +0000 |
commit | 4a14a8d6cb4775383eca5daabac26d6e9ad99747 (patch) | |
tree | 2df7bd0e636fb2b80d49c599924c96d6a892d4e1 /core | |
parent | 79d8cfb7848c05bc34c2c0a10276c9919a9b4e96 (diff) | |
download | pdfium-4a14a8d6cb4775383eca5daabac26d6e9ad99747.tar.xz |
Simplify CPDF_InterForm::GenerateNewResourceName().
It only has one caller, so remove all the checks that will never be true
for this caller. Also make it an anonymous function.
Change-Id: I06e6a04e2f6b8741b6beb83534502a626564b592
Reviewed-on: https://pdfium-review.googlesource.com/37410
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'core')
-rw-r--r-- | core/fpdfdoc/cpdf_interform.cpp | 93 | ||||
-rw-r--r-- | core/fpdfdoc/cpdf_interform.h | 4 |
2 files changed, 37 insertions, 60 deletions
diff --git a/core/fpdfdoc/cpdf_interform.cpp b/core/fpdfdoc/cpdf_interform.cpp index 97d22a2a93..bacf6fd426 100644 --- a/core/fpdfdoc/cpdf_interform.cpp +++ b/core/fpdfdoc/cpdf_interform.cpp @@ -32,6 +32,42 @@ namespace { const int nMaxRecursion = 32; +ByteString GenerateNewFontResourceName(const CPDF_Dictionary* pResDict, + const ByteString& csPrefix) { + static const char kDummyFontName[] = "ZiTi"; + ByteString csStr = csPrefix; + if (csStr.IsEmpty()) + csStr = kDummyFontName; + + const size_t szCount = csStr.GetLength(); + size_t m = 0; + ByteString csTmp; + while (m < strlen(kDummyFontName) && m < szCount) + csTmp += csStr[m++]; + while (m < strlen(kDummyFontName)) { + csTmp += '0' + m % 10; + m++; + } + + const CPDF_Dictionary* pDict = pResDict->GetDictFor("Font"); + ASSERT(pDict); + + int num = 0; + ByteString bsNum; + while (true) { + ByteString csKey = csTmp + bsNum; + if (!pDict->KeyExist(csKey)) + return csKey; + if (m < szCount) + csTmp += csStr[m++]; + else + bsNum = ByteString::Format("%d", num++); + + m++; + } + return csTmp; +} + void AddFont(CPDF_Dictionary*& pFormDict, CPDF_Document* pDocument, const CPDF_Font* pFont, @@ -245,8 +281,7 @@ void AddFont(CPDF_Dictionary*& pFormDict, *csNameTag = pFont->GetBaseFont(); csNameTag->Remove(' '); - *csNameTag = CPDF_InterForm::GenerateNewResourceName(pDR, "Font", 4, - csNameTag->c_str()); + *csNameTag = GenerateNewFontResourceName(pDR, *csNameTag); pFonts->SetFor(*csNameTag, pFont->GetFontDict()->MakeReference(pDocument)); } @@ -573,60 +608,6 @@ void CPDF_InterForm::SetUpdateAP(bool bUpdateAP) { s_bUpdateAP = bUpdateAP; } -ByteString CPDF_InterForm::GenerateNewResourceName( - const CPDF_Dictionary* pResDict, - const char* csType, - int iMinLen, - const char* csPrefix) { - ByteString csStr = csPrefix; - ByteString csBType = csType; - if (csStr.IsEmpty()) { - if (csBType == "ExtGState") - csStr = "GS"; - else if (csBType == "ColorSpace") - csStr = "CS"; - else if (csBType == "Font") - csStr = "ZiTi"; - else - csStr = "Res"; - } - ByteString csTmp = csStr; - int iCount = csStr.GetLength(); - int m = 0; - if (iMinLen > 0) { - csTmp.clear(); - while (m < iMinLen && m < iCount) - csTmp += csStr[m++]; - while (m < iMinLen) { - csTmp += '0' + m % 10; - m++; - } - } else { - m = iCount; - } - if (!pResDict) - return csTmp; - - const CPDF_Dictionary* pDict = pResDict->GetDictFor(csType); - if (!pDict) - return csTmp; - - int num = 0; - ByteString bsNum; - while (true) { - ByteString csKey = csTmp + bsNum; - if (!pDict->KeyExist(csKey)) - return csKey; - if (m < iCount) - csTmp += csStr[m++]; - else - bsNum = ByteString::Format("%d", num++); - - m++; - } - return csTmp; -} - CPDF_Font* CPDF_InterForm::AddStandardFont(CPDF_Document* pDocument, ByteString csFontName) { if (!pDocument || csFontName.IsEmpty()) diff --git a/core/fpdfdoc/cpdf_interform.h b/core/fpdfdoc/cpdf_interform.h index c5da15d48a..97d8ac1e72 100644 --- a/core/fpdfdoc/cpdf_interform.h +++ b/core/fpdfdoc/cpdf_interform.h @@ -39,10 +39,6 @@ class CPDF_InterForm { static void SetUpdateAP(bool bUpdateAP); static bool IsUpdateAPEnabled(); - static ByteString GenerateNewResourceName(const CPDF_Dictionary* pResDict, - const char* csType, - int iMinLen, - const char* csPrefix); static CPDF_Font* AddStandardFont(CPDF_Document* pDocument, ByteString csFontName); static ByteString GetNativeFont(uint8_t iCharSet, void* pLogFont); |