Simplify access to |CPDF_CharPosList::m_CharPos|.
Instead of having GetCount() and GetAt(), just provide a getter for the
entire vector. It is much easier for the caller to access the vector
using well known STL conventions.
Change-Id: I2e9a9eca3d76b3ba5c5ce5965fe02f11f860a373
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/60930
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: dsinclair <dsinclair@chromium.org>
diff --git a/core/fpdfapi/render/cpdf_charposlist.cpp b/core/fpdfapi/render/cpdf_charposlist.cpp
index 13ef124..b8d0cf2 100644
--- a/core/fpdfapi/render/cpdf_charposlist.cpp
+++ b/core/fpdfapi/render/cpdf_charposlist.cpp
@@ -138,11 +138,3 @@
}
CPDF_CharPosList::~CPDF_CharPosList() = default;
-
-uint32_t CPDF_CharPosList::GetCount() const {
- return pdfium::CollectionSize<uint32_t>(m_CharPos);
-}
-
-const TextCharPos& CPDF_CharPosList::GetAt(size_t index) const {
- return m_CharPos[index];
-}
diff --git a/core/fpdfapi/render/cpdf_charposlist.h b/core/fpdfapi/render/cpdf_charposlist.h
index 9635f1b..b06fcfc 100644
--- a/core/fpdfapi/render/cpdf_charposlist.h
+++ b/core/fpdfapi/render/cpdf_charposlist.h
@@ -22,9 +22,7 @@
float font_size);
~CPDF_CharPosList();
- uint32_t empty() const { return m_CharPos.empty(); }
- uint32_t GetCount() const;
- const TextCharPos& GetAt(size_t index) const;
+ const std::vector<TextCharPos>& Get() const { return m_CharPos; }
private:
std::vector<TextCharPos> m_CharPos;
diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp
index 217ad71..fce4392 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.cpp
+++ b/core/fpdfapi/render/cpdf_renderstatus.cpp
@@ -1137,10 +1137,9 @@
RenderSingleObject(&path, mtObj2Device);
return;
}
- CPDF_CharPosList CharPosList(textobj->GetCharCodes(),
- textobj->GetCharPositions(), pFont, font_size);
- for (uint32_t i = 0; i < CharPosList.GetCount(); ++i) {
- const TextCharPos& charpos = CharPosList.GetAt(i);
+ const CPDF_CharPosList CharPosList(
+ textobj->GetCharCodes(), textobj->GetCharPositions(), pFont, font_size);
+ for (const TextCharPos& charpos : CharPosList.Get()) {
auto* font = charpos.m_FallbackFontPosition == -1
? pFont->GetFont()
: pFont->GetFontFallback(charpos.m_FallbackFontPosition);
diff --git a/core/fpdfapi/render/cpdf_textrenderer.cpp b/core/fpdfapi/render/cpdf_textrenderer.cpp
index 29e2221..fe1d258 100644
--- a/core/fpdfapi/render/cpdf_textrenderer.cpp
+++ b/core/fpdfapi/render/cpdf_textrenderer.cpp
@@ -38,21 +38,22 @@
FX_ARGB stroke_argb,
CFX_PathData* pClippingPath,
int nFlag) {
- CPDF_CharPosList CharPosList(charCodes, charPos, pFont, font_size);
- if (CharPosList.empty())
+ const CPDF_CharPosList CharPosList(charCodes, charPos, pFont, font_size);
+ const std::vector<TextCharPos>& pos = CharPosList.Get();
+ if (pos.empty())
return true;
bool bDraw = true;
- int32_t fontPosition = CharPosList.GetAt(0).m_FallbackFontPosition;
- uint32_t startIndex = 0;
- for (uint32_t i = 0; i < CharPosList.GetCount(); ++i) {
- int32_t curFontPosition = CharPosList.GetAt(i).m_FallbackFontPosition;
+ int32_t fontPosition = pos[0].m_FallbackFontPosition;
+ size_t startIndex = 0;
+ for (size_t i = 0; i < pos.size(); ++i) {
+ int32_t curFontPosition = pos[i].m_FallbackFontPosition;
if (fontPosition == curFontPosition)
continue;
CFX_Font* font = GetFont(pFont, fontPosition);
- if (!pDevice->DrawTextPath(i - startIndex, &CharPosList.GetAt(startIndex),
- font, font_size, mtText2User, pUser2Device,
+ if (!pDevice->DrawTextPath(i - startIndex, &pos[startIndex], font,
+ font_size, mtText2User, pUser2Device,
pGraphState, fill_argb, stroke_argb,
pClippingPath, nFlag)) {
bDraw = false;
@@ -61,10 +62,9 @@
startIndex = i;
}
CFX_Font* font = GetFont(pFont, fontPosition);
- if (!pDevice->DrawTextPath(CharPosList.GetCount() - startIndex,
- &CharPosList.GetAt(startIndex), font, font_size,
- mtText2User, pUser2Device, pGraphState, fill_argb,
- stroke_argb, pClippingPath, nFlag)) {
+ if (!pDevice->DrawTextPath(pos.size() - startIndex, &pos[startIndex], font,
+ font_size, mtText2User, pUser2Device, pGraphState,
+ fill_argb, stroke_argb, pClippingPath, nFlag)) {
bDraw = false;
}
return bDraw;
@@ -115,9 +115,11 @@
const CFX_Matrix& mtText2Device,
FX_ARGB fill_argb,
const CPDF_RenderOptions& options) {
- CPDF_CharPosList CharPosList(charCodes, charPos, pFont, font_size);
- if (CharPosList.empty())
+ const CPDF_CharPosList CharPosList(charCodes, charPos, pFont, font_size);
+ const std::vector<TextCharPos>& pos = CharPosList.Get();
+ if (pos.empty())
return true;
+
int fxge_flags = 0;
if (options.GetOptions().bClearType) {
fxge_flags |= FXTEXT_CLEARTYPE;
@@ -135,17 +137,18 @@
if (pFont->IsCIDFont())
fxge_flags |= FXFONT_CIDFONT;
+
bool bDraw = true;
- int32_t fontPosition = CharPosList.GetAt(0).m_FallbackFontPosition;
- uint32_t startIndex = 0;
- for (uint32_t i = 0; i < CharPosList.GetCount(); ++i) {
- int32_t curFontPosition = CharPosList.GetAt(i).m_FallbackFontPosition;
+ int32_t fontPosition = pos[0].m_FallbackFontPosition;
+ size_t startIndex = 0;
+ for (size_t i = 0; i < pos.size(); ++i) {
+ int32_t curFontPosition = pos[i].m_FallbackFontPosition;
if (fontPosition == curFontPosition)
continue;
CFX_Font* font = GetFont(pFont, fontPosition);
- if (!pDevice->DrawNormalText(i - startIndex, &CharPosList.GetAt(startIndex),
- font, font_size, mtText2Device, fill_argb,
+ if (!pDevice->DrawNormalText(i - startIndex, &pos[startIndex], font,
+ font_size, mtText2Device, fill_argb,
fxge_flags)) {
bDraw = false;
}
@@ -153,9 +156,9 @@
startIndex = i;
}
CFX_Font* font = GetFont(pFont, fontPosition);
- if (!pDevice->DrawNormalText(CharPosList.GetCount() - startIndex,
- &CharPosList.GetAt(startIndex), font, font_size,
- mtText2Device, fill_argb, fxge_flags)) {
+ if (!pDevice->DrawNormalText(pos.size() - startIndex, &pos[startIndex], font,
+ font_size, mtText2Device, fill_argb,
+ fxge_flags)) {
bDraw = false;
}
return bDraw;