Change DrawDeviceText() call stack to pass matrix by reference.

Starting with RenderDeviceDriverIface, go in both directions and change
the DrawDeviceText() call stack to pass the matrix around by reference,
since no caller ever passes in nullptr. Along the way, fix nits and
remove checks for the CFX_Matrix* that are always true or always false.

Change-Id: I04ec934eeabd7e28b899f5bad79fed821b24db96
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/55718
Reviewed-by: Tom Sepez <tsepez@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 1e98ebe..f5fa718 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.cpp
+++ b/core/fpdfapi/render/cpdf_renderstatus.cpp
@@ -1776,7 +1776,7 @@
   text_matrix.Concat(mtObj2Device);
   return CPDF_TextRenderer::DrawNormalText(
       m_pDevice, textobj->GetCharCodes(), textobj->GetCharPositions(), pFont,
-      font_size, &text_matrix, fill_argb, &m_Options);
+      font_size, text_matrix, fill_argb, &m_Options);
 }
 
 RetainPtr<CPDF_Type3Cache> CPDF_RenderStatus::GetCachedType3(
diff --git a/core/fpdfapi/render/cpdf_textrenderer.cpp b/core/fpdfapi/render/cpdf_textrenderer.cpp
index ee93418..0e994bb 100644
--- a/core/fpdfapi/render/cpdf_textrenderer.cpp
+++ b/core/fpdfapi/render/cpdf_textrenderer.cpp
@@ -102,7 +102,7 @@
   CFX_Matrix new_matrix = matrix;
   new_matrix.e = origin_x;
   new_matrix.f = origin_y;
-  DrawNormalText(pDevice, codes, positions, pFont, font_size, &new_matrix,
+  DrawNormalText(pDevice, codes, positions, pFont, font_size, new_matrix,
                  fill_argb, pOptions);
 }
 
@@ -112,7 +112,7 @@
                                        const std::vector<float>& charPos,
                                        CPDF_Font* pFont,
                                        float font_size,
-                                       const CFX_Matrix* pText2Device,
+                                       const CFX_Matrix& mtText2Device,
                                        FX_ARGB fill_argb,
                                        const CPDF_RenderOptions* pOptions) {
   CPDF_CharPosList CharPosList(charCodes, charPos, pFont, font_size);
@@ -148,7 +148,7 @@
 
     CFX_Font* font = GetFont(pFont, fontPosition);
     if (!pDevice->DrawNormalText(i - startIndex, &CharPosList.GetAt(startIndex),
-                                 font, font_size, pText2Device, fill_argb,
+                                 font, font_size, mtText2Device, fill_argb,
                                  FXGE_flags)) {
       bDraw = false;
     }
@@ -158,7 +158,7 @@
   CFX_Font* font = GetFont(pFont, fontPosition);
   if (!pDevice->DrawNormalText(CharPosList.GetCount() - startIndex,
                                &CharPosList.GetAt(startIndex), font, font_size,
-                               pText2Device, fill_argb, FXGE_flags)) {
+                               mtText2Device, fill_argb, FXGE_flags)) {
     bDraw = false;
   }
   return bDraw;
diff --git a/core/fpdfapi/render/cpdf_textrenderer.h b/core/fpdfapi/render/cpdf_textrenderer.h
index d7a2f15..f4870a9 100644
--- a/core/fpdfapi/render/cpdf_textrenderer.h
+++ b/core/fpdfapi/render/cpdf_textrenderer.h
@@ -51,9 +51,13 @@
                              const std::vector<float>& charPos,
                              CPDF_Font* pFont,
                              float font_size,
-                             const CFX_Matrix* pText2Device,
+                             const CFX_Matrix& mtText2Device,
                              FX_ARGB fill_argb,
                              const CPDF_RenderOptions* pOptions);
+
+  CPDF_TextRenderer() = delete;
+  CPDF_TextRenderer(const CPDF_TextRenderer&) = delete;
+  CPDF_TextRenderer& operator=(const CPDF_TextRenderer&) = delete;
 };
 
 #endif  // CORE_FPDFAPI_RENDER_CPDF_TEXTRENDERER_H_
diff --git a/core/fxge/agg/fx_agg_driver.cpp b/core/fxge/agg/fx_agg_driver.cpp
index 913ab07..63504b0 100644
--- a/core/fxge/agg/fx_agg_driver.cpp
+++ b/core/fxge/agg/fx_agg_driver.cpp
@@ -1160,7 +1160,7 @@
 bool CFX_AggDeviceDriver::DrawDeviceText(int nChars,
                                          const TextCharPos* pCharPos,
                                          CFX_Font* pFont,
-                                         const CFX_Matrix* pObject2Device,
+                                         const CFX_Matrix& mtObject2Device,
                                          float font_size,
                                          uint32_t color) {
   return false;
diff --git a/core/fxge/agg/fx_agg_driver.h b/core/fxge/agg/fx_agg_driver.h
index 1aecc50..ecbf1d9 100644
--- a/core/fxge/agg/fx_agg_driver.h
+++ b/core/fxge/agg/fx_agg_driver.h
@@ -95,7 +95,7 @@
   bool DrawDeviceText(int nChars,
                       const TextCharPos* pCharPos,
                       CFX_Font* pFont,
-                      const CFX_Matrix* pObject2Device,
+                      const CFX_Matrix& mtObject2Device,
                       float font_size,
                       uint32_t color) override;
   int GetDriverType() const override;
diff --git a/core/fxge/apple/apple_int.h b/core/fxge/apple/apple_int.h
index cbf3464..5869421 100644
--- a/core/fxge/apple/apple_int.h
+++ b/core/fxge/apple/apple_int.h
@@ -24,7 +24,7 @@
 
   void* CreateFont(const uint8_t* pFontData, uint32_t dwFontSize);
   void DestroyFont(void* pFont);
-  void setGraphicsTextMatrix(void* graphics, CFX_Matrix* matrix);
+  void SetGraphicsTextMatrix(void* graphics, const CFX_Matrix& matrix);
   bool drawGraphicsString(void* graphics,
                           void* font,
                           float fontSize,
diff --git a/core/fxge/apple/fx_apple_platform.cpp b/core/fxge/apple/fx_apple_platform.cpp
index c8c55a8..b3a0214 100644
--- a/core/fxge/apple/fx_apple_platform.cpp
+++ b/core/fxge/apple/fx_apple_platform.cpp
@@ -35,7 +35,7 @@
                     int nChars,
                     const TextCharPos* pCharPos,
                     CFX_Font* pFont,
-                    const CFX_Matrix* pObject2Device,
+                    const CFX_Matrix& mtObject2Device,
                     float font_size,
                     uint32_t argb) {
   if (nChars == 0)
@@ -45,10 +45,7 @@
   if (bNegSize)
     font_size = -font_size;
 
-  CFX_Matrix new_matrix;
-  if (pObject2Device)
-    new_matrix.Concat(*pObject2Device);
-
+  CFX_Matrix new_matrix = mtObject2Device;
   CQuartz2D& quartz2d =
       static_cast<CApplePlatform*>(CFX_GEModule::Get()->GetPlatform())
           ->m_quartz2d;
@@ -79,7 +76,7 @@
     new_matrix.b = -new_matrix.b;
     new_matrix.d = -new_matrix.d;
   }
-  quartz2d.setGraphicsTextMatrix(pContext, &new_matrix);
+  quartz2d.SetGraphicsTextMatrix(pContext, new_matrix);
   return quartz2d.drawGraphicsString(pContext, pFont->GetPlatformFont(),
                                      font_size, glyph_indices.data(),
                                      glyph_positions.data(), nChars, argb);
@@ -107,7 +104,7 @@
 bool CFX_AggDeviceDriver::DrawDeviceText(int nChars,
                                          const TextCharPos* pCharPos,
                                          CFX_Font* pFont,
-                                         const CFX_Matrix* pObject2Device,
+                                         const CFX_Matrix& mtObject2Device,
                                          float font_size,
                                          uint32_t argb) {
   if (!pFont)
@@ -155,7 +152,7 @@
   else
     CGContextClipToRect(ctx, rect_cg);
 
-  bool ret = CGDrawGlyphRun(ctx, nChars, pCharPos, pFont, pObject2Device,
+  bool ret = CGDrawGlyphRun(ctx, nChars, pCharPos, pFont, mtObject2Device,
                             font_size, argb);
   if (pImageCG)
     CGImageRelease(pImageCG);
diff --git a/core/fxge/apple/fx_quartz_device.cpp b/core/fxge/apple/fx_quartz_device.cpp
index 52008e9a..6a8d6bd 100644
--- a/core/fxge/apple/fx_quartz_device.cpp
+++ b/core/fxge/apple/fx_quartz_device.cpp
@@ -61,14 +61,15 @@
   CGFontRelease((CGFontRef)pFont);
 }
 
-void CQuartz2D::setGraphicsTextMatrix(void* graphics, CFX_Matrix* matrix) {
-  if (!graphics || !matrix)
+void CQuartz2D::SetGraphicsTextMatrix(void* graphics,
+                                      const CFX_Matrix& matrix) {
+  if (!graphics)
     return;
-  CGContextRef context = (CGContextRef)graphics;
-  CGFloat ty = CGBitmapContextGetHeight(context) - matrix->f;
+  CGContextRef context = reinterpret_cast<CGContextRef>(graphics);
+  CGFloat ty = CGBitmapContextGetHeight(context) - matrix.f;
   CGContextSetTextMatrix(
-      context, CGAffineTransformMake(matrix->a, matrix->b, matrix->c, matrix->d,
-                                     matrix->e, ty));
+      context, CGAffineTransformMake(matrix.a, matrix.b, matrix.c, matrix.d,
+                                     matrix.e, ty));
 }
 
 bool CQuartz2D::drawGraphicsString(void* graphics,
diff --git a/core/fxge/cfx_renderdevice.cpp b/core/fxge/cfx_renderdevice.cpp
index f529068..da73a0c 100644
--- a/core/fxge/cfx_renderdevice.cpp
+++ b/core/fxge/cfx_renderdevice.cpp
@@ -863,15 +863,15 @@
                                       const TextCharPos* pCharPos,
                                       CFX_Font* pFont,
                                       float font_size,
-                                      const CFX_Matrix* pText2Device,
+                                      const CFX_Matrix& mtText2Device,
                                       uint32_t fill_color,
                                       uint32_t text_flags) {
   int nativetext_flags = text_flags;
   if (m_DeviceClass != FXDC_DISPLAY) {
     if (!(text_flags & FXTEXT_PRINTGRAPHICTEXT)) {
       if (ShouldDrawDeviceText(pFont, text_flags) &&
-          m_pDeviceDriver->DrawDeviceText(nChars, pCharPos, pFont, pText2Device,
-                                          font_size, fill_color)) {
+          m_pDeviceDriver->DrawDeviceText(
+              nChars, pCharPos, pFont, mtText2Device, font_size, fill_color)) {
         return true;
       }
     }
@@ -879,18 +879,13 @@
       return false;
   } else if (!(text_flags & FXTEXT_NO_NATIVETEXT)) {
     if (ShouldDrawDeviceText(pFont, text_flags) &&
-        m_pDeviceDriver->DrawDeviceText(nChars, pCharPos, pFont, pText2Device,
+        m_pDeviceDriver->DrawDeviceText(nChars, pCharPos, pFont, mtText2Device,
                                         font_size, fill_color)) {
       return true;
     }
   }
-  CFX_Matrix char2device;
-  CFX_Matrix text2Device;
-  if (pText2Device) {
-    char2device = *pText2Device;
-    text2Device = *pText2Device;
-  }
-
+  CFX_Matrix char2device = mtText2Device;
+  CFX_Matrix text2Device = mtText2Device;
   char2device.Scale(font_size, -font_size);
   if (fabs(char2device.a) + fabs(char2device.b) > 50 * 1.0f ||
       ((m_DeviceClass == FXDC_PRINTER) &&
@@ -898,7 +893,7 @@
     if (pFont->GetFace()) {
       int nPathFlags =
           (text_flags & FXTEXT_NOSMOOTH) == 0 ? 0 : FXFILL_NOPATHSMOOTH;
-      return DrawTextPath(nChars, pCharPos, pFont, font_size, pText2Device,
+      return DrawTextPath(nChars, pCharPos, pFont, font_size, &mtText2Device,
                           nullptr, nullptr, fill_color, 0, nullptr, nPathFlags);
     }
   }
diff --git a/core/fxge/cfx_renderdevice.h b/core/fxge/cfx_renderdevice.h
index 11d8337..ad3ec87 100644
--- a/core/fxge/cfx_renderdevice.h
+++ b/core/fxge/cfx_renderdevice.h
@@ -222,7 +222,7 @@
                       const TextCharPos* pCharPos,
                       CFX_Font* pFont,
                       float font_size,
-                      const CFX_Matrix* pText2Device,
+                      const CFX_Matrix& mtText2Device,
                       uint32_t fill_color,
                       uint32_t text_flags);
   bool DrawTextPath(int nChars,
diff --git a/core/fxge/renderdevicedriver_iface.cpp b/core/fxge/renderdevicedriver_iface.cpp
index 26b8e1d..acb81d6 100644
--- a/core/fxge/renderdevicedriver_iface.cpp
+++ b/core/fxge/renderdevicedriver_iface.cpp
@@ -60,7 +60,7 @@
 bool RenderDeviceDriverIface::DrawDeviceText(int nChars,
                                              const TextCharPos* pCharPos,
                                              CFX_Font* pFont,
-                                             const CFX_Matrix* pObject2Device,
+                                             const CFX_Matrix& mtObject2Device,
                                              float font_size,
                                              uint32_t color) {
   return false;
diff --git a/core/fxge/renderdevicedriver_iface.h b/core/fxge/renderdevicedriver_iface.h
index f63cca8..0360074 100644
--- a/core/fxge/renderdevicedriver_iface.h
+++ b/core/fxge/renderdevicedriver_iface.h
@@ -91,7 +91,7 @@
   virtual bool DrawDeviceText(int nChars,
                               const TextCharPos* pCharPos,
                               CFX_Font* pFont,
-                              const CFX_Matrix* pObject2Device,
+                              const CFX_Matrix& mtObject2Device,
                               float font_size,
                               uint32_t color);
   virtual int GetDriverType() const;
diff --git a/core/fxge/skia/fx_skia_device.cpp b/core/fxge/skia/fx_skia_device.cpp
index e64862a..68ce0d8 100644
--- a/core/fxge/skia/fx_skia_device.cpp
+++ b/core/fxge/skia/fx_skia_device.cpp
@@ -829,7 +829,7 @@
   bool DrawText(int nChars,
                 const TextCharPos* pCharPos,
                 CFX_Font* pFont,
-                const CFX_Matrix* pMatrix,
+                const CFX_Matrix& matrix,
                 float font_size,
                 uint32_t color) {
     if (m_debugDisable)
@@ -845,7 +845,7 @@
     int drawIndex = SkTMin(m_drawIndex, m_commands.count());
     if (Accumulator::kPath == m_type || drawIndex != m_commandIndex ||
         (Accumulator::kText == m_type &&
-         (FontChanged(pFont, pMatrix, font_size, scaleX, color) ||
+         (FontChanged(pFont, matrix, font_size, scaleX, color) ||
           hasRSX == m_rsxform.isEmpty()))) {
       Flush();
     }
@@ -856,7 +856,7 @@
       m_fontSize = font_size;
       m_scaleX = scaleX;
       m_fillColor = color;
-      m_drawMatrix = *pMatrix;
+      m_drawMatrix = matrix;
       m_drawIndex = m_commandIndex;
       m_type = Accumulator::kText;
     }
@@ -884,7 +884,7 @@
 #endif
     }
     SkPoint delta;
-    if (MatrixOffset(pMatrix, &delta)) {
+    if (MatrixOffset(&matrix, &delta)) {
       for (int index = 0; index < nChars; ++index)
         m_positions[index + count].offset(delta.fX * flip, -delta.fY * flip);
     }
@@ -1104,13 +1104,13 @@
   }
 
   bool FontChanged(CFX_Font* pFont,
-                   const CFX_Matrix* pMatrix,
+                   const CFX_Matrix& matrix,
                    float font_size,
                    float scaleX,
                    uint32_t color) const {
     CFX_TypeFace* typeface =
         pFont->GetFace() ? pFont->GetDeviceCache() : nullptr;
-    return typeface != m_pTypeFace || MatrixChanged(pMatrix) ||
+    return typeface != m_pTypeFace || MatrixChanged(&matrix) ||
            font_size != m_fontSize || scaleX != m_scaleX ||
            color != m_fillColor;
   }
@@ -1557,10 +1557,10 @@
 bool CFX_SkiaDeviceDriver::DrawDeviceText(int nChars,
                                           const TextCharPos* pCharPos,
                                           CFX_Font* pFont,
-                                          const CFX_Matrix* pObject2Device,
+                                          const CFX_Matrix& mtObject2Device,
                                           float font_size,
                                           uint32_t color) {
-  if (m_pCache->DrawText(nChars, pCharPos, pFont, pObject2Device, font_size,
+  if (m_pCache->DrawText(nChars, pCharPos, pFont, mtObject2Device, font_size,
                          color)) {
     return true;
   }
@@ -1580,7 +1580,7 @@
   SkScalar vFlip = flip;
   if (pFont->IsVertical())
     vFlip *= -1;
-  SkMatrix skMatrix = ToFlippedSkMatrix(*pObject2Device, flip);
+  SkMatrix skMatrix = ToFlippedSkMatrix(mtObject2Device, flip);
   m_pCanvas->concat(skMatrix);
   SkTDArray<SkPoint> positions;
   positions.setCount(nChars);
diff --git a/core/fxge/skia/fx_skia_device.h b/core/fxge/skia/fx_skia_device.h
index 72f91ca..e9b2472 100644
--- a/core/fxge/skia/fx_skia_device.h
+++ b/core/fxge/skia/fx_skia_device.h
@@ -133,7 +133,7 @@
   bool DrawDeviceText(int nChars,
                       const TextCharPos* pCharPos,
                       CFX_Font* pFont,
-                      const CFX_Matrix* pObject2Device,
+                      const CFX_Matrix& mtObject2Device,
                       float font_size,
                       uint32_t color) override;
 
diff --git a/core/fxge/skia/fx_skia_device_embeddertest.cpp b/core/fxge/skia/fx_skia_device_embeddertest.cpp
index 26ab239..6daea67 100644
--- a/core/fxge/skia/fx_skia_device_embeddertest.cpp
+++ b/core/fxge/skia/fx_skia_device_embeddertest.cpp
@@ -63,7 +63,7 @@
     driver->DrawPath(&path1, &matrix, &graphState, 0xFF112233, 0,
                      FXFILL_WINDING, BlendMode::kNormal);
   } else if (state.m_graphic == State::Graphic::kText) {
-    driver->DrawDeviceText(SK_ARRAY_COUNT(charPos), charPos, &font, &matrix,
+    driver->DrawDeviceText(SK_ARRAY_COUNT(charPos), charPos, &font, matrix,
                            fontSize, 0xFF445566);
   }
   if (state.m_save == State::Save::kYes)
@@ -86,7 +86,7 @@
     driver->DrawPath(&path2, &matrix2, &graphState, 0xFF112233, 0,
                      FXFILL_WINDING, BlendMode::kNormal);
   } else if (state.m_graphic == State::Graphic::kText) {
-    driver->DrawDeviceText(SK_ARRAY_COUNT(charPos), charPos, &font, &matrix2,
+    driver->DrawDeviceText(SK_ARRAY_COUNT(charPos), charPos, &font, matrix2,
                            fontSize, 0xFF445566);
   }
   if (state.m_save == State::Save::kYes)
diff --git a/core/fxge/win32/cfx_psrenderer.cpp b/core/fxge/win32/cfx_psrenderer.cpp
index 3ae1df6..6705437 100644
--- a/core/fxge/win32/cfx_psrenderer.cpp
+++ b/core/fxge/win32/cfx_psrenderer.cpp
@@ -573,18 +573,18 @@
 bool CFX_PSRenderer::DrawText(int nChars,
                               const TextCharPos* pCharPos,
                               CFX_Font* pFont,
-                              const CFX_Matrix* pObject2Device,
+                              const CFX_Matrix& mtObject2Device,
                               float font_size,
                               uint32_t color) {
   // Check object to device matrix first, since it can scale the font size.
-  if ((pObject2Device->a == 0 && pObject2Device->b == 0) ||
-      (pObject2Device->c == 0 && pObject2Device->d == 0)) {
+  if ((mtObject2Device.a == 0 && mtObject2Device.b == 0) ||
+      (mtObject2Device.c == 0 && mtObject2Device.d == 0)) {
     return true;
   }
 
   // Do not send near zero font sizes to printers. See crbug.com/767343.
   float scale =
-      std::min(pObject2Device->GetXUnit(), pObject2Device->GetYUnit());
+      std::min(mtObject2Device.GetXUnit(), mtObject2Device.GetYUnit());
   static constexpr float kEpsilon = 0.01f;
   if (std::fabs(font_size * scale) < kEpsilon)
     return true;
@@ -596,9 +596,9 @@
 
   SetColor(color);
   std::ostringstream buf;
-  buf << "q[" << pObject2Device->a << " " << pObject2Device->b << " "
-      << pObject2Device->c << " " << pObject2Device->d << " "
-      << pObject2Device->e << " " << pObject2Device->f << "]cm\n";
+  buf << "q[" << mtObject2Device.a << " " << mtObject2Device.b << " "
+      << mtObject2Device.c << " " << mtObject2Device.d << " "
+      << mtObject2Device.e << " " << mtObject2Device.f << "]cm\n";
 
   CFX_FontCache* pCache = CFX_GEModule::Get()->GetFontCache();
   RetainPtr<CFX_GlyphCache> pGlyphCache = pCache->GetGlyphCache(pFont);
diff --git a/core/fxge/win32/cfx_psrenderer.h b/core/fxge/win32/cfx_psrenderer.h
index 55dad2f..a5ca321 100644
--- a/core/fxge/win32/cfx_psrenderer.h
+++ b/core/fxge/win32/cfx_psrenderer.h
@@ -92,7 +92,7 @@
   bool DrawText(int nChars,
                 const TextCharPos* pCharPos,
                 CFX_Font* pFont,
-                const CFX_Matrix* pObject2Device,
+                const CFX_Matrix& mtObject2Device,
                 float font_size,
                 uint32_t color);
 
diff --git a/core/fxge/win32/fx_win32_print.cpp b/core/fxge/win32/fx_win32_print.cpp
index 8ebcec1..8746ebe 100644
--- a/core/fxge/win32/fx_win32_print.cpp
+++ b/core/fxge/win32/fx_win32_print.cpp
@@ -200,7 +200,7 @@
 bool CGdiPrinterDriver::DrawDeviceText(int nChars,
                                        const TextCharPos* pCharPos,
                                        CFX_Font* pFont,
-                                       const CFX_Matrix* pObject2Device,
+                                       const CFX_Matrix& mtObject2Device,
                                        float font_size,
                                        uint32_t color) {
 #if defined(PDFIUM_PRINT_TEXT_WITH_GDI)
@@ -273,12 +273,12 @@
   // Transforms
   SetGraphicsMode(m_hDC, GM_ADVANCED);
   XFORM xform;
-  xform.eM11 = pObject2Device->a / kScaleFactor;
-  xform.eM12 = pObject2Device->b / kScaleFactor;
-  xform.eM21 = -pObject2Device->c / kScaleFactor;
-  xform.eM22 = -pObject2Device->d / kScaleFactor;
-  xform.eDx = pObject2Device->e;
-  xform.eDy = pObject2Device->f;
+  xform.eM11 = mtObject2Device.a / kScaleFactor;
+  xform.eM12 = mtObject2Device.b / kScaleFactor;
+  xform.eM21 = -mtObject2Device.c / kScaleFactor;
+  xform.eM22 = -mtObject2Device.d / kScaleFactor;
+  xform.eDx = mtObject2Device.e;
+  xform.eDy = mtObject2Device.f;
   ModifyWorldTransform(m_hDC, &xform, MWT_LEFTMULTIPLY);
 
   // Color
@@ -503,10 +503,10 @@
 bool CPSPrinterDriver::DrawDeviceText(int nChars,
                                       const TextCharPos* pCharPos,
                                       CFX_Font* pFont,
-                                      const CFX_Matrix* pObject2Device,
+                                      const CFX_Matrix& mtObject2Device,
                                       float font_size,
                                       uint32_t color) {
-  return m_PSRenderer.DrawText(nChars, pCharPos, pFont, pObject2Device,
+  return m_PSRenderer.DrawText(nChars, pCharPos, pFont, mtObject2Device,
                                font_size, color);
 }
 
@@ -612,7 +612,7 @@
 bool CTextOnlyPrinterDriver::DrawDeviceText(int nChars,
                                             const TextCharPos* pCharPos,
                                             CFX_Font* pFont,
-                                            const CFX_Matrix* pObject2Device,
+                                            const CFX_Matrix& mtObject2Device,
                                             float font_size,
                                             uint32_t color) {
   if (g_pdfium_print_mode != 1)
@@ -631,12 +631,12 @@
   // These characters are removed by SkPDF, but the new line information is
   // preserved in the text location. clrf characters seem to be ignored by
   // label printers that use this driver.
-  if (m_SetOrigin &&
-      FXSYS_round(m_OriginY) != FXSYS_round(pObject2Device->f * kScaleFactor)) {
+  float fOffsetY = mtObject2Device.f * kScaleFactor;
+  if (m_SetOrigin && FXSYS_round(m_OriginY) != FXSYS_round(fOffsetY)) {
     wsText += L"\r\n";
     totalLength += 2;
   }
-  m_OriginY = pObject2Device->f * kScaleFactor;
+  m_OriginY = fOffsetY;
   m_SetOrigin = true;
 
   // Text
diff --git a/core/fxge/win32/win32_int.h b/core/fxge/win32/win32_int.h
index a021677..144ee59 100644
--- a/core/fxge/win32/win32_int.h
+++ b/core/fxge/win32/win32_int.h
@@ -203,7 +203,7 @@
   bool DrawDeviceText(int nChars,
                       const TextCharPos* pCharPos,
                       CFX_Font* pFont,
-                      const CFX_Matrix* pObject2Device,
+                      const CFX_Matrix& mtObject2Device,
                       float font_size,
                       uint32_t color) override;
 
@@ -265,7 +265,7 @@
   bool DrawDeviceText(int nChars,
                       const TextCharPos* pCharPos,
                       CFX_Font* pFont,
-                      const CFX_Matrix* pObject2Device,
+                      const CFX_Matrix& mtObject2Device,
                       float font_size,
                       uint32_t color) override;
 
@@ -328,7 +328,7 @@
   bool DrawDeviceText(int nChars,
                       const TextCharPos* pCharPos,
                       CFX_Font* pFont,
-                      const CFX_Matrix* pObject2Device,
+                      const CFX_Matrix& mtObject2Device,
                       float font_size,
                       uint32_t color) override;
 
diff --git a/fxbarcode/oned/BC_OneDimWriter.cpp b/fxbarcode/oned/BC_OneDimWriter.cpp
index 9349a1c..5655393 100644
--- a/fxbarcode/oned/BC_OneDimWriter.cpp
+++ b/fxbarcode/oned/BC_OneDimWriter.cpp
@@ -172,7 +172,7 @@
     affine_matrix.Concat(*matrix);
   }
   device->DrawNormalText(str.GetLength(), pCharPos, m_pFont.Get(),
-                         static_cast<float>(iFontSize), &affine_matrix,
+                         static_cast<float>(iFontSize), affine_matrix,
                          m_fontColor, FXTEXT_CLEARTYPE);
 }
 
diff --git a/fxbarcode/oned/BC_OnedEAN13Writer.cpp b/fxbarcode/oned/BC_OnedEAN13Writer.cpp
index 71b2b50..1da7854 100644
--- a/fxbarcode/oned/BC_OnedEAN13Writer.cpp
+++ b/fxbarcode/oned/BC_OnedEAN13Writer.cpp
@@ -176,7 +176,7 @@
     if (matrix)
       affine_matrix1.Concat(*matrix);
     device->DrawNormalText(length, &charpos[1], m_pFont.Get(),
-                           static_cast<float>(iFontSize), &affine_matrix1,
+                           static_cast<float>(iFontSize), affine_matrix1,
                            m_fontColor, FXTEXT_CLEARTYPE);
   }
   tempStr = str.Mid(7, 6);
@@ -191,7 +191,7 @@
     if (matrix)
       affine_matrix1.Concat(*matrix);
     device->DrawNormalText(length, &charpos[7], m_pFont.Get(),
-                           static_cast<float>(iFontSize), &affine_matrix1,
+                           static_cast<float>(iFontSize), affine_matrix1,
                            m_fontColor, FXTEXT_CLEARTYPE);
   }
   tempStr = str.Left(1);
@@ -207,7 +207,7 @@
     if (matrix)
       affine_matrix1.Concat(*matrix);
     device->DrawNormalText(length, charpos.data(), m_pFont.Get(),
-                           static_cast<float>(iFontSize), &affine_matrix1,
+                           static_cast<float>(iFontSize), affine_matrix1,
                            m_fontColor, FXTEXT_CLEARTYPE);
   }
   return true;
diff --git a/fxbarcode/oned/BC_OnedEAN8Writer.cpp b/fxbarcode/oned/BC_OnedEAN8Writer.cpp
index b7b253a..0185e05 100644
--- a/fxbarcode/oned/BC_OnedEAN8Writer.cpp
+++ b/fxbarcode/oned/BC_OnedEAN8Writer.cpp
@@ -167,7 +167,7 @@
                               (float)(m_Height - iTextHeight + iFontSize));
     affine_matrix1.Concat(*matrix);
     device->DrawNormalText(iLen, charpos.data(), m_pFont.Get(),
-                           static_cast<float>(iFontSize), &affine_matrix1,
+                           static_cast<float>(iFontSize), affine_matrix1,
                            m_fontColor, FXTEXT_CLEARTYPE);
   }
   tempStr = str.Mid(4, 4);
@@ -182,7 +182,7 @@
     if (matrix)
       affine_matrix1.Concat(*matrix);
     device->DrawNormalText(iLen, &charpos[4], m_pFont.Get(),
-                           static_cast<float>(iFontSize), &affine_matrix1,
+                           static_cast<float>(iFontSize), affine_matrix1,
                            m_fontColor, FXTEXT_CLEARTYPE);
   }
   return true;
diff --git a/fxbarcode/oned/BC_OnedUPCAWriter.cpp b/fxbarcode/oned/BC_OnedUPCAWriter.cpp
index 049f981..d2668ca 100644
--- a/fxbarcode/oned/BC_OnedUPCAWriter.cpp
+++ b/fxbarcode/oned/BC_OnedUPCAWriter.cpp
@@ -162,7 +162,7 @@
     if (matrix)
       affine_matrix1.Concat(*matrix);
     device->DrawNormalText(length, &charpos[1], m_pFont.Get(),
-                           static_cast<float>(iFontSize), &affine_matrix1,
+                           static_cast<float>(iFontSize), affine_matrix1,
                            m_fontColor, FXTEXT_CLEARTYPE);
   }
   tempStr = str.Mid(6, 5);
@@ -176,7 +176,7 @@
     if (matrix)
       affine_matrix1.Concat(*matrix);
     device->DrawNormalText(length, &charpos[6], m_pFont.Get(),
-                           static_cast<float>(iFontSize), &affine_matrix1,
+                           static_cast<float>(iFontSize), affine_matrix1,
                            m_fontColor, FXTEXT_CLEARTYPE);
   }
   tempStr = str.Left(1);
@@ -192,7 +192,7 @@
     if (matrix)
       affine_matrix1.Concat(*matrix);
     device->DrawNormalText(length, charpos.data(), m_pFont.Get(),
-                           static_cast<float>(iFontSize), &affine_matrix1,
+                           static_cast<float>(iFontSize), affine_matrix1,
                            m_fontColor, FXTEXT_CLEARTYPE);
   }
   tempStr = str.Mid(11, 1);
@@ -207,7 +207,7 @@
     if (matrix)
       affine_matrix1.Concat(*matrix);
     device->DrawNormalText(length, &charpos[11], m_pFont.Get(),
-                           static_cast<float>(iFontSize), &affine_matrix1,
+                           static_cast<float>(iFontSize), affine_matrix1,
                            m_fontColor, FXTEXT_CLEARTYPE);
   }
   return true;
diff --git a/xfa/fde/cfde_textout.cpp b/xfa/fde/cfde_textout.cpp
index 3015fe8..eb21c93 100644
--- a/xfa/fde/cfde_textout.cpp
+++ b/xfa/fde/cfde_textout.cpp
@@ -41,7 +41,7 @@
                               const RetainPtr<CFGAS_GEFont>& pFont,
                               pdfium::span<TextCharPos> pCharPos,
                               float fFontSize,
-                              const CFX_Matrix* pMatrix) {
+                              const CFX_Matrix& matrix) {
   ASSERT(pFont);
   ASSERT(!pCharPos.empty());
 
@@ -85,7 +85,7 @@
         font = pFxFont;
 #endif
 
-        device->DrawNormalText(iCurCount, pCurCP, font, -fFontSize, pMatrix,
+        device->DrawNormalText(iCurCount, pCurCP, font, -fFontSize, matrix,
                                color, FXTEXT_CLEARTYPE);
       }
       pCurFont = pSTFont;
@@ -107,7 +107,7 @@
     font = pFxFont;
 #endif
 
-    bRet = device->DrawNormalText(iCurCount, pCurCP, font, -fFontSize, pMatrix,
+    bRet = device->DrawNormalText(iCurCount, pCurCP, font, -fFontSize, matrix,
                                   color, FXTEXT_CLEARTYPE);
   }
 
@@ -306,7 +306,7 @@
       if (szCount > 0) {
         CFDE_TextOut::DrawString(device, m_TxtColor, m_pFont,
                                  {m_CharPos.data(), szCount}, m_fFontSize,
-                                 &m_Matrix);
+                                 m_Matrix);
       }
     }
   }
diff --git a/xfa/fde/cfde_textout.h b/xfa/fde/cfde_textout.h
index 9a386b7..07403ca 100644
--- a/xfa/fde/cfde_textout.h
+++ b/xfa/fde/cfde_textout.h
@@ -40,7 +40,7 @@
                          const RetainPtr<CFGAS_GEFont>& pFont,
                          pdfium::span<TextCharPos> pCharPos,
                          float fFontSize,
-                         const CFX_Matrix* pMatrix);
+                         const CFX_Matrix& matrix);
 
   CFDE_TextOut();
   ~CFDE_TextOut();
diff --git a/xfa/fwl/cfwl_edit.cpp b/xfa/fwl/cfwl_edit.cpp
index 70428d7..c879783 100644
--- a/xfa/fwl/cfwl_edit.cpp
+++ b/xfa/fwl/cfwl_edit.cpp
@@ -464,7 +464,7 @@
       continue;
 
     CFDE_TextOut::DrawString(pRenderDev, m_EdtEngine.GetFontColor(), font,
-                             char_pos, m_EdtEngine.GetFontSize(), &mt);
+                             char_pos, m_EdtEngine.GetFontSize(), mt);
   }
 }
 
diff --git a/xfa/fxfa/cxfa_textlayout.cpp b/xfa/fxfa/cxfa_textlayout.cpp
index cf565a6..85d2db3 100644
--- a/xfa/fxfa/cxfa_textlayout.cpp
+++ b/xfa/fxfa/cxfa_textlayout.cpp
@@ -562,7 +562,7 @@
 }
 
 bool CXFA_TextLayout::DrawString(CFX_RenderDevice* pFxDevice,
-                                 const CFX_Matrix& tmDoc2Device,
+                                 const CFX_Matrix& mtDoc2Device,
                                  const CFX_RectF& rtClip,
                                  size_t szBlockIndex) {
   if (!pFxDevice)
@@ -599,10 +599,10 @@
       int32_t iChars = pPiece->iChars;
       if (pdfium::CollectionSize<int32_t>(char_pos) < iChars)
         char_pos.resize(iChars);
-      RenderString(pFxDevice, pPieceLine, j, &char_pos, tmDoc2Device);
+      RenderString(pFxDevice, pPieceLine, j, &char_pos, mtDoc2Device);
     }
     for (size_t j = 0; j < pPieceLine->m_textPieces.size(); ++j)
-      RenderPath(pFxDevice, pPieceLine, j, &char_pos, tmDoc2Device);
+      RenderPath(pFxDevice, pPieceLine, j, &char_pos, mtDoc2Device);
   }
   pFxDevice->RestoreState(false);
   return szPieceLines > 0;
@@ -1118,13 +1118,13 @@
                                    CXFA_PieceLine* pPieceLine,
                                    size_t szPiece,
                                    std::vector<TextCharPos>* pCharPos,
-                                   const CFX_Matrix& tmDoc2Device) {
+                                   const CFX_Matrix& mtDoc2Device) {
   const CXFA_TextPiece* pPiece = pPieceLine->m_textPieces[szPiece].get();
   size_t szCount = GetDisplayPos(pPiece, pCharPos);
   if (szCount > 0) {
     auto span = pdfium::make_span(pCharPos->data(), szCount);
     CFDE_TextOut::DrawString(pDevice, pPiece->dwColor, pPiece->pFont, span,
-                             pPiece->fFontSize, &tmDoc2Device);
+                             pPiece->fFontSize, mtDoc2Device);
   }
   pPieceLine->m_charCounts.push_back(szCount);
 }
@@ -1133,7 +1133,7 @@
                                  CXFA_PieceLine* pPieceLine,
                                  size_t szPiece,
                                  std::vector<TextCharPos>* pCharPos,
-                                 const CFX_Matrix& tmDoc2Device) {
+                                 const CFX_Matrix& mtDoc2Device) {
   CXFA_TextPiece* pPiece = pPieceLine->m_textPieces[szPiece].get();
   bool bNoUnderline = pPiece->iUnderline < 1 || pPiece->iUnderline > 2;
   bool bNoLineThrough = pPiece->iLineThrough < 1 || pPiece->iLineThrough > 2;
@@ -1249,7 +1249,7 @@
   graphState.m_LineWidth = 1;
   graphState.m_MiterLimit = 10;
   graphState.m_DashPhase = 0;
-  pDevice->DrawPath(&path, &tmDoc2Device, &graphState, 0, pPiece->dwColor, 0);
+  pDevice->DrawPath(&path, &mtDoc2Device, &graphState, 0, pPiece->dwColor, 0);
 }
 
 size_t CXFA_TextLayout::GetDisplayPos(const CXFA_TextPiece* pPiece,
diff --git a/xfa/fxfa/cxfa_textlayout.h b/xfa/fxfa/cxfa_textlayout.h
index 4d739d6..e47475a 100644
--- a/xfa/fxfa/cxfa_textlayout.h
+++ b/xfa/fxfa/cxfa_textlayout.h
@@ -47,7 +47,7 @@
   CFX_SizeF CalcSize(const CFX_SizeF& minSize, const CFX_SizeF& maxSize);
   void ItemBlocks(const CFX_RectF& rtText, size_t szBlockIndex);
   bool DrawString(CFX_RenderDevice* pFxDevice,
-                  const CFX_Matrix& tmDoc2Device,
+                  const CFX_Matrix& mtDoc2Device,
                   const CFX_RectF& rtClip,
                   size_t szBlockIndex);
   bool IsLoaded() const { return !m_pieceLines.empty(); }
@@ -105,12 +105,12 @@
                     CXFA_PieceLine* pPieceLine,
                     size_t szPiece,
                     std::vector<TextCharPos>* pCharPos,
-                    const CFX_Matrix& tmDoc2Device);
+                    const CFX_Matrix& mtDoc2Device);
   void RenderPath(CFX_RenderDevice* pDevice,
                   CXFA_PieceLine* pPieceLine,
                   size_t szPiece,
                   std::vector<TextCharPos>* pCharPos,
-                  const CFX_Matrix& tmDoc2Device);
+                  const CFX_Matrix& mtDoc2Device);
   size_t GetDisplayPos(const CXFA_TextPiece* pPiece,
                        std::vector<TextCharPos>* pCharPos);
   void DoTabstops(CFX_CSSComputedStyle* pStyle, CXFA_PieceLine* pPieceLine);