Move CPDF_CIDFont::LoadMetricsArray() into an anonymous namespace. LoadMetricsArray() doesn't depend on CPDF_CIDFont. Change-Id: I5db6c9ebb4c97017eaa96c7bf80cd7ae8c0af6c6 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/72211 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/font/cpdf_cidfont.cpp b/core/fpdfapi/font/cpdf_cidfont.cpp index 221c438..f9b1e7a 100644 --- a/core/fpdfapi/font/cpdf_cidfont.cpp +++ b/core/fpdfapi/font/cpdf_cidfont.cpp
@@ -205,6 +205,58 @@ return pEntry[0] <= cid && pEntry[1] >= cid; } +void LoadMetricsArray(const CPDF_Array* pArray, + std::vector<uint32_t>* result, + int nElements) { + int width_status = 0; + int iCurElement = 0; + uint32_t first_code = 0; + uint32_t last_code = 0; + for (size_t i = 0; i < pArray->size(); i++) { + const CPDF_Object* pObj = pArray->GetDirectObjectAt(i); + if (!pObj) + continue; + + const CPDF_Array* pObjArray = pObj->AsArray(); + if (pObjArray) { + if (width_status != 1) + return; + if (first_code > + std::numeric_limits<uint32_t>::max() - pObjArray->size()) { + width_status = 0; + continue; + } + + for (size_t j = 0; j < pObjArray->size(); j += nElements) { + result->push_back(first_code); + result->push_back(first_code); + for (int k = 0; k < nElements; k++) + result->push_back(pObjArray->GetIntegerAt(j + k)); + first_code++; + } + width_status = 0; + } else { + if (width_status == 0) { + first_code = pObj->GetInteger(); + width_status = 1; + } else if (width_status == 1) { + last_code = pObj->GetInteger(); + width_status = 2; + iCurElement = 0; + } else { + if (!iCurElement) { + result->push_back(first_code); + result->push_back(last_code); + } + result->push_back(pObj->GetInteger()); + iCurElement++; + if (iCurElement == nElements) + width_status = 0; + } + } + } +} + } // namespace CPDF_CIDFont::CPDF_CIDFont(CPDF_Document* pDocument, CPDF_Dictionary* pFontDict) @@ -763,58 +815,6 @@ g_CharsetCPs[m_Charset], IsVertWriting()); } -void CPDF_CIDFont::LoadMetricsArray(const CPDF_Array* pArray, - std::vector<uint32_t>* result, - int nElements) { - int width_status = 0; - int iCurElement = 0; - uint32_t first_code = 0; - uint32_t last_code = 0; - for (size_t i = 0; i < pArray->size(); i++) { - const CPDF_Object* pObj = pArray->GetDirectObjectAt(i); - if (!pObj) - continue; - - const CPDF_Array* pObjArray = pObj->AsArray(); - if (pObjArray) { - if (width_status != 1) - return; - if (first_code > - std::numeric_limits<uint32_t>::max() - pObjArray->size()) { - width_status = 0; - continue; - } - - for (size_t j = 0; j < pObjArray->size(); j += nElements) { - result->push_back(first_code); - result->push_back(first_code); - for (int k = 0; k < nElements; k++) - result->push_back(pObjArray->GetIntegerAt(j + k)); - first_code++; - } - width_status = 0; - } else { - if (width_status == 0) { - first_code = pObj->GetInteger(); - width_status = 1; - } else if (width_status == 1) { - last_code = pObj->GetInteger(); - width_status = 2; - iCurElement = 0; - } else { - if (!iCurElement) { - result->push_back(first_code); - result->push_back(last_code); - } - result->push_back(pObj->GetInteger()); - iCurElement++; - if (iCurElement == nElements) - width_status = 0; - } - } - } -} - // static float CPDF_CIDFont::CIDTransformToFloat(uint8_t ch) { return (ch < 128 ? ch : ch - 255) * (1.0f / 127);
diff --git a/core/fpdfapi/font/cpdf_cidfont.h b/core/fpdfapi/font/cpdf_cidfont.h index 8cb065c..7935999 100644 --- a/core/fpdfapi/font/cpdf_cidfont.h +++ b/core/fpdfapi/font/cpdf_cidfont.h
@@ -68,9 +68,6 @@ void LoadGB2312(); int GetGlyphIndex(uint32_t unicodeb, bool* pVertGlyph); int GetVerticalGlyph(int index, bool* pVertGlyph); - void LoadMetricsArray(const CPDF_Array* pArray, - std::vector<uint32_t>* result, - int nElements); void LoadSubstFont(); wchar_t GetUnicodeFromCharCode(uint32_t charcode) const;