Replace CPDF_CharPosList class with a standalone function.

Implementing the code as a class is unnecessary given the work it has to
do. Change it to a function instead.

Change-Id: I0679dc7b7af82a820a9fcd900ad2b30987dc1863
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/68450
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/render/BUILD.gn b/core/fpdfapi/render/BUILD.gn
index ddce77a..51750ea 100644
--- a/core/fpdfapi/render/BUILD.gn
+++ b/core/fpdfapi/render/BUILD.gn
@@ -7,8 +7,8 @@
 
 source_set("render") {
   sources = [
-    "cpdf_charposlist.cpp",
-    "cpdf_charposlist.h",
+    "charposlist.cpp",
+    "charposlist.h",
     "cpdf_devicebuffer.cpp",
     "cpdf_devicebuffer.h",
     "cpdf_docrenderdata.cpp",
diff --git a/core/fpdfapi/render/cpdf_charposlist.cpp b/core/fpdfapi/render/charposlist.cpp
similarity index 91%
rename from core/fpdfapi/render/cpdf_charposlist.cpp
rename to core/fpdfapi/render/charposlist.cpp
index b8d0cf2..a8fbf68 100644
--- a/core/fpdfapi/render/cpdf_charposlist.cpp
+++ b/core/fpdfapi/render/charposlist.cpp
@@ -4,7 +4,7 @@
 
 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
 
-#include "core/fpdfapi/render/cpdf_charposlist.h"
+#include "core/fpdfapi/render/charposlist.h"
 
 #include "build/build_config.h"
 #include "core/fpdfapi/font/cpdf_cidfont.h"
@@ -12,11 +12,13 @@
 #include "core/fxge/cfx_substfont.h"
 #include "core/fxge/text_char_pos.h"
 
-CPDF_CharPosList::CPDF_CharPosList(const std::vector<uint32_t>& charCodes,
-                                   const std::vector<float>& charPos,
-                                   CPDF_Font* pFont,
-                                   float font_size) {
-  m_CharPos.reserve(charCodes.size());
+std::vector<TextCharPos> GetCharPosList(const std::vector<uint32_t>& charCodes,
+                                        const std::vector<float>& charPos,
+                                        CPDF_Font* pFont,
+                                        float font_size) {
+  std::vector<TextCharPos> results;
+  results.reserve(charCodes.size());
+
   CPDF_CIDFont* pCIDFont = pFont->AsCIDFont();
   bool bVertWriting = pCIDFont && pCIDFont->IsVertWriting();
   bool bToUnicode = !!pFont->GetFontDict()->GetStreamFor("ToUnicode");
@@ -26,8 +28,8 @@
       continue;
 
     bool bVert = false;
-    m_CharPos.emplace_back();
-    TextCharPos& charpos = m_CharPos.back();
+    results.emplace_back();
+    TextCharPos& charpos = results.back();
     if (pCIDFont)
       charpos.m_bFontStyle = true;
     WideString unicode = pFont->UnicodeFromCharCode(CharCode);
@@ -135,6 +137,6 @@
       charpos.m_bGlyphAdjust = true;
     }
   }
-}
 
-CPDF_CharPosList::~CPDF_CharPosList() = default;
+  return results;
+}
diff --git a/core/fpdfapi/render/charposlist.h b/core/fpdfapi/render/charposlist.h
new file mode 100644
index 0000000..f759232
--- /dev/null
+++ b/core/fpdfapi/render/charposlist.h
@@ -0,0 +1,22 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef CORE_FPDFAPI_RENDER_CPDF_CHARPOSLIST_H_
+#define CORE_FPDFAPI_RENDER_CPDF_CHARPOSLIST_H_
+
+#include <vector>
+
+#include "core/fxcrt/fx_system.h"
+
+class CPDF_Font;
+class TextCharPos;
+
+std::vector<TextCharPos> GetCharPosList(const std::vector<uint32_t>& charCodes,
+                                        const std::vector<float>& charPos,
+                                        CPDF_Font* pFont,
+                                        float font_size);
+
+#endif  // CORE_FPDFAPI_RENDER_CPDF_CHARPOSLIST_H_
diff --git a/core/fpdfapi/render/cpdf_charposlist.h b/core/fpdfapi/render/cpdf_charposlist.h
deleted file mode 100644
index b06fcfc..0000000
--- a/core/fpdfapi/render/cpdf_charposlist.h
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef CORE_FPDFAPI_RENDER_CPDF_CHARPOSLIST_H_
-#define CORE_FPDFAPI_RENDER_CPDF_CHARPOSLIST_H_
-
-#include <vector>
-
-#include "core/fxcrt/fx_system.h"
-
-class CPDF_Font;
-class TextCharPos;
-
-class CPDF_CharPosList {
- public:
-  CPDF_CharPosList(const std::vector<uint32_t>& charCodes,
-                   const std::vector<float>& charPos,
-                   CPDF_Font* pFont,
-                   float font_size);
-  ~CPDF_CharPosList();
-
-  const std::vector<TextCharPos>& Get() const { return m_CharPos; }
-
- private:
-  std::vector<TextCharPos> m_CharPos;
-};
-
-#endif  // CORE_FPDFAPI_RENDER_CPDF_CHARPOSLIST_H_
diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp
index 17af93b..b9294ff 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.cpp
+++ b/core/fpdfapi/render/cpdf_renderstatus.cpp
@@ -40,7 +40,7 @@
 #include "core/fpdfapi/parser/cpdf_document.h"
 #include "core/fpdfapi/parser/cpdf_stream.h"
 #include "core/fpdfapi/parser/fpdf_parser_utility.h"
-#include "core/fpdfapi/render/cpdf_charposlist.h"
+#include "core/fpdfapi/render/charposlist.h"
 #include "core/fpdfapi/render/cpdf_docrenderdata.h"
 #include "core/fpdfapi/render/cpdf_imagerenderer.h"
 #include "core/fpdfapi/render/cpdf_pagerendercache.h"
@@ -1138,9 +1138,10 @@
     RenderSingleObject(&path, mtObj2Device);
     return;
   }
-  const CPDF_CharPosList CharPosList(
+
+  std::vector<TextCharPos> char_pos_list = GetCharPosList(
       textobj->GetCharCodes(), textobj->GetCharPositions(), pFont, font_size);
-  for (const TextCharPos& charpos : CharPosList.Get()) {
+  for (const TextCharPos& charpos : char_pos_list) {
     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 fe1d258..68bfc97 100644
--- a/core/fpdfapi/render/cpdf_textrenderer.cpp
+++ b/core/fpdfapi/render/cpdf_textrenderer.cpp
@@ -9,7 +9,7 @@
 #include <algorithm>
 
 #include "core/fpdfapi/font/cpdf_font.h"
-#include "core/fpdfapi/render/cpdf_charposlist.h"
+#include "core/fpdfapi/render/charposlist.h"
 #include "core/fpdfapi/render/cpdf_renderoptions.h"
 #include "core/fxge/cfx_graphstatedata.h"
 #include "core/fxge/cfx_pathdata.h"
@@ -38,8 +38,8 @@
                                      FX_ARGB stroke_argb,
                                      CFX_PathData* pClippingPath,
                                      int nFlag) {
-  const CPDF_CharPosList CharPosList(charCodes, charPos, pFont, font_size);
-  const std::vector<TextCharPos>& pos = CharPosList.Get();
+  std::vector<TextCharPos> pos =
+      GetCharPosList(charCodes, charPos, pFont, font_size);
   if (pos.empty())
     return true;
 
@@ -115,8 +115,8 @@
                                        const CFX_Matrix& mtText2Device,
                                        FX_ARGB fill_argb,
                                        const CPDF_RenderOptions& options) {
-  const CPDF_CharPosList CharPosList(charCodes, charPos, pFont, font_size);
-  const std::vector<TextCharPos>& pos = CharPosList.Get();
+  std::vector<TextCharPos> pos =
+      GetCharPosList(charCodes, charPos, pFont, font_size);
   if (pos.empty())
     return true;