Fixed an issue where the installed ComicSansMs font is substituted

During font mapping, in CFX_FolderFontInfo::FindFont(),
the 'Courier New' font is selected if present, in case of Ansi
encoding and Fixed pitch family.

In the Pdf attached to the bug, the `ComicSansMS` font is substituted
by 'Courier New' in the above check, because it has:
- flags value=41, first bit is set == FixedPitch
- WinAisiEncoding,

Since the 'Courier New' check seems like a fallback, I moved it after
inspecting the list of loaded fonts.

Bug: pdfium:1956
Change-Id: Ia3dde2ae932672b8ad22c0e5161c880b4005d547
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/102330
Reviewed-by: Nigi <nigi@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/AUTHORS b/AUTHORS
index b7e8252..a4c3f99 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -11,6 +11,7 @@
 # Please keep the list sorted.
 
 # BEGIN individuals section.
+Abdelkarim Sellamna <abdelkarim.se@gmail.com>
 Aleksei Skotnikov <fineaskotnikov@gmail.com>
 Antonio Gomes <tonikitoo@igalia.com>
 Chery Cherian <cherycherian@gmail.com>
diff --git a/core/fxge/cfx_folderfontinfo.cpp b/core/fxge/cfx_folderfontinfo.cpp
index 9657bba..af8691a 100644
--- a/core/fxge/cfx_folderfontinfo.cpp
+++ b/core/fxge/cfx_folderfontinfo.cpp
@@ -320,11 +320,6 @@
                                    const ByteString& family,
                                    bool bMatchName) {
   FontFaceInfo* pFind = nullptr;
-  if (charset == FX_Charset::kANSI && FontFamilyIsFixedPitch(pitch_family)) {
-    auto* courier_new = GetFont("Courier New");
-    if (courier_new)
-      return courier_new;
-  }
 
   ByteStringView bsFamily = family.AsStringView();
   uint32_t charset_flag = GetCharset(charset);
@@ -346,7 +341,18 @@
       pFind = pFont;
     }
   }
-  return pFind;
+
+  if (pFind) {
+    return pFind;
+  }
+
+  if (charset == FX_Charset::kANSI && FontFamilyIsFixedPitch(pitch_family)) {
+    auto* courier_new = GetFont("Courier New");
+    if (courier_new)
+      return courier_new;
+  }
+
+  return nullptr;
 }
 
 void* CFX_FolderFontInfo::MapFont(int weight,
diff --git a/core/fxge/cfx_folderfontinfo_unittest.cpp b/core/fxge/cfx_folderfontinfo_unittest.cpp
index 0fc4ecd..8cdb8b9 100644
--- a/core/fxge/cfx_folderfontinfo_unittest.cpp
+++ b/core/fxge/cfx_folderfontinfo_unittest.cpp
@@ -13,6 +13,7 @@
 namespace {
 
 constexpr char kArial[] = "Arial";
+constexpr char kCourierNew[] = "Courier New";
 constexpr char kTimesNewRoman[] = "TimesNewRoman";
 constexpr char kSymbol[] = "Symbol";
 constexpr char kBookshelfSymbol7[] = "Bookshelf Symbol 7";
@@ -26,6 +27,7 @@
 constexpr char kOxygenSansSansBold[] = "Oxygen-Sans Sans-Bold";
 constexpr char kOxygenSans[] = "Oxygen-Sans";
 constexpr char kOxygen[] = "Oxygen";
+constexpr char kComicSansMS[] = "Comic Sans MS";
 
 }  // namespace
 
@@ -33,12 +35,14 @@
  public:
   CFX_FolderFontInfoTest() {
     AddDummyFont(kArial, CHARSET_FLAG_ANSI);
+    AddDummyFont(kCourierNew, CHARSET_FLAG_ANSI);
     AddDummyFont(kTimesNewRoman, 0);
     AddDummyFont(kBookshelfSymbol7, CHARSET_FLAG_SYMBOL);
     AddDummyFont(kSymbol, CHARSET_FLAG_SYMBOL);
     AddDummyFont(kTofuBold, CHARSET_FLAG_SYMBOL);
     AddDummyFont(kLatoUltraBold, CHARSET_FLAG_ANSI);
     AddDummyFont(kOxygenSansSansBold, CHARSET_FLAG_ANSI);
+    AddDummyFont(kComicSansMS, CHARSET_FLAG_ANSI);
   }
 
   void* FindFont(int weight,
@@ -123,4 +127,9 @@
                   FXFONT_FF_ROMAN, kSymbol, /*bMatchName=*/false);
   ASSERT_TRUE(font);
   EXPECT_EQ(GetFaceName(font), kBookshelfSymbol7);
+
+  font = FindFont(700, false, FX_Charset::kANSI, FXFONT_FF_FIXEDPITCH,
+                  kComicSansMS, true);
+  ASSERT_TRUE(font);
+  EXPECT_EQ(GetFaceName(font), kComicSansMS);
 }