Add CFX_PSRenderer::WriteString().

Minimize direct `m_pStream` access. Funnel all writes through helper
functions for consistency. This may be helpful in the future if
CFX_PSRenderer has to write a header and a body, but the content of the
header may not arrive first.

Change-Id: I667830fb7eb4eee2579b292fcd87e21a171ceec1
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/83961
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fxge/win32/cfx_psrenderer.cpp b/core/fxge/win32/cfx_psrenderer.cpp
index 1557453..b82d19b 100644
--- a/core/fxge/win32/cfx_psrenderer.cpp
+++ b/core/fxge/win32/cfx_psrenderer.cpp
@@ -74,7 +74,7 @@
       "load def\n"
       "/cm/concat load def/Cm/currentmatrix load def/mx/matrix load "
       "def/sm/setmatrix load def\n";
-  m_pStream->WriteString(kInitStr);
+  WriteString(kInitStr);
   m_bInited = true;
 }
 
@@ -82,21 +82,21 @@
   if (!m_bInited)
     return;
 
-  m_pStream->WriteString("\nrestore\n");
+  WriteString("\nrestore\n");
   m_bInited = false;
 }
 
 void CFX_PSRenderer::SaveState() {
   StartRendering();
-  m_pStream->WriteString("q\n");
+  WriteString("q\n");
   m_ClipBoxStack.push_back(m_ClipBox);
 }
 
 void CFX_PSRenderer::RestoreState(bool bKeepSaved) {
   StartRendering();
-  m_pStream->WriteString("Q\n");
+  WriteString("Q\n");
   if (bKeepSaved)
-    m_pStream->WriteString("q\n");
+    WriteString("q\n");
 
   m_bColorSet = false;
   m_bGraphStateSet = false;
@@ -165,10 +165,10 @@
   m_ClipBox.top = static_cast<int>(rect.top + rect.bottom);
   m_ClipBox.bottom = static_cast<int>(rect.bottom);
 
-  m_pStream->WriteString("W");
+  WriteString("W");
   if (fill_options.fill_type != CFX_FillRenderOptions::FillType::kWinding)
-    m_pStream->WriteString("*");
-  m_pStream->WriteString(" n\n");
+    WriteString("*");
+  WriteString(" n\n");
 }
 
 void CFX_PSRenderer::SetClip_PathStroke(const CFX_Path* pPath,
@@ -188,7 +188,7 @@
       pGraphState->m_LineWidth, pGraphState->m_MiterLimit);
   m_ClipBox.Intersect(pObject2Device->TransformRect(rect).GetOuterRect());
 
-  m_pStream->WriteString("strokepath W n sm\n");
+  WriteString("strokepath W n sm\n");
 }
 
 bool CFX_PSRenderer::DrawPath(const CFX_Path* pPath,
@@ -224,26 +224,26 @@
     SetColor(fill_color);
     if (fill_options.fill_type == CFX_FillRenderOptions::FillType::kWinding) {
       if (stroke_alpha)
-        m_pStream->WriteString("q f Q ");
+        WriteString("q f Q ");
       else
-        m_pStream->WriteString("f");
+        WriteString("f");
     } else if (fill_options.fill_type ==
                CFX_FillRenderOptions::FillType::kEvenOdd) {
       if (stroke_alpha)
-        m_pStream->WriteString("q F Q ");
+        WriteString("q F Q ");
       else
-        m_pStream->WriteString("F");
+        WriteString("F");
     }
   }
 
   if (stroke_alpha) {
     SetColor(stroke_color);
-    m_pStream->WriteString("s");
+    WriteString("s");
     if (pObject2Device)
-      m_pStream->WriteString(" sm");
+      WriteString(" sm");
   }
 
-  m_pStream->WriteString("\n");
+  WriteString("\n");
   return true;
 }
 
@@ -315,7 +315,7 @@
   if (pSource->IsMaskFormat() && (alpha < 255 || pSource->GetBPP() != 1))
     return false;
 
-  m_pStream->WriteString("q\n");
+  WriteString("q\n");
 
   std::ostringstream buf;
   buf << "[" << matrix.a << " " << matrix.b << " " << matrix.c << " "
@@ -378,7 +378,7 @@
         break;
     }
     if (!pConverted) {
-      m_pStream->WriteString("\nQ\n");
+      WriteString("\nQ\n");
       return false;
     }
 
@@ -432,7 +432,7 @@
     WritePSBinary({output_buf, output_size});
     FX_Free(output_buf);
   }
-  m_pStream->WriteString("\nQ\n");
+  WriteString("\nQ\n");
   return true;
 }
 
@@ -673,3 +673,7 @@
   if (stream.tellp() > 0)
     m_pStream->WriteBlock(stream.str().c_str(), stream.tellp());
 }
+
+void CFX_PSRenderer::WriteString(ByteStringView str) {
+  m_pStream->WriteString(str);
+}
diff --git a/core/fxge/win32/cfx_psrenderer.h b/core/fxge/win32/cfx_psrenderer.h
index 2703714..0402aca 100644
--- a/core/fxge/win32/cfx_psrenderer.h
+++ b/core/fxge/win32/cfx_psrenderer.h
@@ -122,6 +122,7 @@
                       const char** filter) const;
   void WritePSBinary(pdfium::span<const uint8_t> data);
   void WriteStream(std::ostringstream& stream);
+  void WriteString(ByteStringView str);
 
   bool m_bInited = false;
   bool m_bGraphStateSet = false;