Add a helper function for creating text rendering options.

1. Move the process of creating text rendering options from CPDF_Font
   and CPDF_RenderOptions into a helper function
   GetTextRenderOptionsHelper().

2. Avoid setting option FXTEXT_CLEARTYPE (use LCD optimization) if flag
   FXTEXT_NOSMOOTH (disabling anti aliasing) is in use, since LCD
   optimization can only be used when anti aliasing is enabled.

Change-Id: I0cec1e6cd118a4772b6c4e9156e30b51448a37a5
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/70130
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Hui Yingst <nigi@chromium.org>
diff --git a/core/fpdfapi/render/cpdf_textrenderer.cpp b/core/fpdfapi/render/cpdf_textrenderer.cpp
index bc7622d..3f5be2b 100644
--- a/core/fpdfapi/render/cpdf_textrenderer.cpp
+++ b/core/fpdfapi/render/cpdf_textrenderer.cpp
@@ -24,6 +24,32 @@
   return position == -1 ? pFont->GetFont() : pFont->GetFontFallback(position);
 }
 
+int GetTextRenderOptionsHelper(const CPDF_Font* pFont,
+                               const CPDF_RenderOptions& options) {
+  int text_options = 0;
+  if (pFont->IsCIDFont())
+    text_options |= FXFONT_CIDFONT;
+
+  if (options.GetOptions().bClearType) {
+    text_options |= FXTEXT_CLEARTYPE;
+    if (options.GetOptions().bBGRStripe)
+      text_options |= FXTEXT_BGR_STRIPE;
+  }
+  if (options.GetOptions().bNoTextSmooth)
+    text_options |= FXTEXT_NOSMOOTH;
+  if (options.GetOptions().bNoNativeText)
+    text_options |= FXTEXT_NO_NATIVETEXT;
+
+  // TODO(crbug.com/pdfium/1535): Clean up or add code coverage for text
+  // rendering options |FXTEXT_PRINTGRAPHICTEXT| and |FXTEXT_PRINTIMAGETEXT|.
+  if (options.GetOptions().bPrintGraphicText)
+    text_options |= FXTEXT_PRINTGRAPHICTEXT;
+  if (options.GetOptions().bPrintImageText)
+    text_options |= FXTEXT_PRINTIMAGETEXT;
+
+  return text_options;
+}
+
 }  // namespace
 
 // static
@@ -121,24 +147,7 @@
   if (pos.empty())
     return true;
 
-  int fxge_flags = 0;
-  if (options.GetOptions().bClearType) {
-    fxge_flags |= FXTEXT_CLEARTYPE;
-    if (options.GetOptions().bBGRStripe)
-      fxge_flags |= FXTEXT_BGR_STRIPE;
-  }
-  if (options.GetOptions().bNoTextSmooth)
-    fxge_flags |= FXTEXT_NOSMOOTH;
-  if (options.GetOptions().bPrintGraphicText)
-    fxge_flags |= FXTEXT_PRINTGRAPHICTEXT;
-  if (options.GetOptions().bNoNativeText)
-    fxge_flags |= FXTEXT_NO_NATIVETEXT;
-  if (options.GetOptions().bPrintImageText)
-    fxge_flags |= FXTEXT_PRINTIMAGETEXT;
-
-  if (pFont->IsCIDFont())
-    fxge_flags |= FXFONT_CIDFONT;
-
+  int fxge_flags = GetTextRenderOptionsHelper(pFont, options);
   bool bDraw = true;
   int32_t fontPosition = pos[0].m_FallbackFontPosition;
   size_t startIndex = 0;