Consolidate matrix calculations into TextCharPos::GetEffectiveMatrix().

Merge repeated code that read `TextCharPos::m_AdjustMatrix` together.

Change-Id: I9997890b07b36e59bc97ade2e23c4456fb4a67d9
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/91834
Reviewed-by: Daniel Hosseinian <dhoss@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp
index a27f2ad..61f91ef 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.cpp
+++ b/core/fpdfapi/render/cpdf_renderstatus.cpp
@@ -1118,14 +1118,8 @@
     path.m_GraphState = textobj->m_GraphState;
     path.m_ColorState = textobj->m_ColorState;
 
-    CFX_Matrix matrix;
-    if (charpos.m_bGlyphAdjust) {
-      matrix = CFX_Matrix(charpos.m_AdjustMatrix[0], charpos.m_AdjustMatrix[1],
-                          charpos.m_AdjustMatrix[2], charpos.m_AdjustMatrix[3],
-                          0, 0);
-    }
-    matrix.Concat(CFX_Matrix(font_size, 0, 0, font_size, charpos.m_Origin.x,
-                             charpos.m_Origin.y));
+    CFX_Matrix matrix = charpos.GetEffectiveMatrix(CFX_Matrix(
+        font_size, 0, 0, font_size, charpos.m_Origin.x, charpos.m_Origin.y));
     matrix.Concat(mtTextMatrix);
     path.set_stroke(stroke);
     path.set_filltype(fill ? CFX_FillRenderOptions::FillType::kWinding
diff --git a/core/fxge/cfx_renderdevice.cpp b/core/fxge/cfx_renderdevice.cpp
index 0539fbe..b6d116f 100644
--- a/core/fxge/cfx_renderdevice.cpp
+++ b/core/fxge/cfx_renderdevice.cpp
@@ -1089,8 +1089,6 @@
     }
   }
   std::vector<TextGlyphPos> glyphs(pCharPos.size());
-  CFX_Matrix deviceCtm = char2device;
-
   for (size_t i = 0; i < glyphs.size(); ++i) {
     TextGlyphPos& glyph = glyphs[i];
     const TextCharPos& charpos = pCharPos[i];
@@ -1102,19 +1100,10 @@
       glyph.m_Origin.x = static_cast<int>(floor(glyph.m_fDeviceOrigin.x));
     glyph.m_Origin.y = FXSYS_roundf(glyph.m_fDeviceOrigin.y);
 
-    if (charpos.m_bGlyphAdjust) {
-      CFX_Matrix new_matrix(
-          charpos.m_AdjustMatrix[0], charpos.m_AdjustMatrix[1],
-          charpos.m_AdjustMatrix[2], charpos.m_AdjustMatrix[3], 0, 0);
-      new_matrix.Concat(deviceCtm);
-      glyph.m_pGlyph = pFont->LoadGlyphBitmap(
-          charpos.m_GlyphIndex, charpos.m_bFontStyle, new_matrix,
-          charpos.m_FontCharWidth, anti_alias, &text_options);
-    } else {
-      glyph.m_pGlyph = pFont->LoadGlyphBitmap(
-          charpos.m_GlyphIndex, charpos.m_bFontStyle, deviceCtm,
-          charpos.m_FontCharWidth, anti_alias, &text_options);
-    }
+    CFX_Matrix matrix = charpos.GetEffectiveMatrix(char2device);
+    glyph.m_pGlyph = pFont->LoadGlyphBitmap(
+        charpos.m_GlyphIndex, charpos.m_bFontStyle, matrix,
+        charpos.m_FontCharWidth, anti_alias, &text_options);
   }
   if (anti_alias < FT_RENDER_MODE_LCD && glyphs.size() > 1)
     AdjustGlyphSpace(&glyphs);
@@ -1234,19 +1223,14 @@
                                     CFX_Path* pClippingPath,
                                     const CFX_FillRenderOptions& fill_options) {
   for (const auto& charpos : pCharPos) {
-    CFX_Matrix matrix;
-    if (charpos.m_bGlyphAdjust) {
-      matrix = CFX_Matrix(charpos.m_AdjustMatrix[0], charpos.m_AdjustMatrix[1],
-                          charpos.m_AdjustMatrix[2], charpos.m_AdjustMatrix[3],
-                          0, 0);
-    }
-    matrix.Concat(CFX_Matrix(font_size, 0, 0, font_size, charpos.m_Origin.x,
-                             charpos.m_Origin.y));
     const CFX_Path* pPath =
         pFont->LoadGlyphPath(charpos.m_GlyphIndex, charpos.m_FontCharWidth);
     if (!pPath)
       continue;
 
+    CFX_Matrix matrix(font_size, 0, 0, font_size, charpos.m_Origin.x,
+                      charpos.m_Origin.y);
+    matrix = charpos.GetEffectiveMatrix(matrix);
     matrix.Concat(mtText2User);
 
     CFX_Path transformed_path(*pPath);
diff --git a/core/fxge/text_char_pos.cpp b/core/fxge/text_char_pos.cpp
index cf88b96..4eaeceb 100644
--- a/core/fxge/text_char_pos.cpp
+++ b/core/fxge/text_char_pos.cpp
@@ -11,3 +11,13 @@
 TextCharPos::TextCharPos(const TextCharPos&) = default;
 
 TextCharPos::~TextCharPos() = default;
+
+CFX_Matrix TextCharPos::GetEffectiveMatrix(const CFX_Matrix& matrix) const {
+  CFX_Matrix new_matrix;
+  if (m_bGlyphAdjust) {
+    new_matrix = CFX_Matrix(m_AdjustMatrix[0], m_AdjustMatrix[1],
+                            m_AdjustMatrix[2], m_AdjustMatrix[3], 0, 0);
+  }
+  new_matrix.Concat(matrix);
+  return new_matrix;
+}
diff --git a/core/fxge/text_char_pos.h b/core/fxge/text_char_pos.h
index 6be2671..3800f45 100644
--- a/core/fxge/text_char_pos.h
+++ b/core/fxge/text_char_pos.h
@@ -16,6 +16,8 @@
   TextCharPos(const TextCharPos&);
   ~TextCharPos();
 
+  CFX_Matrix GetEffectiveMatrix(const CFX_Matrix& matrix) const;
+
   CFX_PointF m_Origin;
   uint32_t m_Unicode = 0;
   uint32_t m_GlyphIndex = 0;