Remove the prefix in BaseFont when trying to find a substitute font.

According to PDF 32000-1:2008 section 9.6.4, for a font subset, its
BaseFont will begin with an arbitrary prefix of 6 uppercase letters
followed by a plus sign(+). For example "YATXCX+Arial" is a subset font
of Arial family.

To find a better substitute font, we need to correctly extract the
standard font name or font family name instead of trying to find a
match for the arbitrary prefix.

This CL adds the step to remove the possible prefix in BaseFont in
CFX_FontMapper::FindSubstFont() and improves the rendering result.

Bug: pdfium:1475
Change-Id: Id3f88f83202fbf9811a2c4863c08d9776455caa8
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/65752
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Hui Yingst <nigi@chromium.org>
diff --git a/DEPS b/DEPS
index 910f365..9a12f0b 100644
--- a/DEPS
+++ b/DEPS
@@ -79,7 +79,7 @@
   # Three lines of non-changing comments so that
   # the commit queue can handle CLs rolling pdfium_tests
   # and whatever else without interference from each other.
-  'pdfium_tests_revision': 'd234e6bc3c42981c8d6861ff33e8a3f8c023a503',
+  'pdfium_tests_revision': 'b4e9a126d289b49002d0f0acac71d1fdc26953b3',
   # Three lines of non-changing comments so that
   # the commit queue can handle CLs rolling skia
   # and whatever else without interference from each other.
diff --git a/core/fxge/cfx_fontmapper.cpp b/core/fxge/cfx_fontmapper.cpp
index 3b0bcae..58ebaec 100644
--- a/core/fxge/cfx_fontmapper.cpp
+++ b/core/fxge/cfx_fontmapper.cpp
@@ -15,6 +15,7 @@
 
 #include "build/build_config.h"
 #include "core/fxcrt/fx_codepage.h"
+#include "core/fxcrt/fx_extension.h"
 #include "core/fxcrt/fx_memory_wrappers.h"
 #include "core/fxge/cfx_fontmgr.h"
 #include "core/fxge/cfx_substfont.h"
@@ -256,6 +257,24 @@
     *PitchFamily |= FXFONT_FF_FIXEDPITCH;
 }
 
+bool IsStrUpper(const ByteString& str) {
+  for (size_t i = 0; i < str.GetLength(); ++i) {
+    if (!FXSYS_iswupper(str[i]))
+      return false;
+  }
+  return true;
+}
+
+void RemoveSubsettedFontPrefix(ByteString* subst_name) {
+  constexpr size_t kPrefixLength = 6;
+  if (subst_name->GetLength() > kPrefixLength &&
+      (*subst_name)[kPrefixLength] == '+' &&
+      IsStrUpper(subst_name->First(kPrefixLength))) {
+    *subst_name =
+        subst_name->Last(subst_name->GetLength() - (kPrefixLength + 1));
+  }
+}
+
 }  // namespace
 
 CFX_FontMapper::CFX_FontMapper(CFX_FontMgr* mgr) : m_pFontMgr(mgr) {}
@@ -400,6 +419,7 @@
   SubstName.Remove(' ');
   if (bTrueType && name.GetLength() > 0 && name[0] == '@')
     SubstName = name.Last(name.GetLength() - 1);
+  RemoveSubsettedFontPrefix(&SubstName);
   GetStandardFontName(&SubstName);
   if (SubstName == "Symbol" && !bTrueType) {
     pSubstFont->m_Family = "Chrome Symbol";
@@ -417,7 +437,7 @@
   bool bHasComma = false;
   bool bHasHyphen = false;
   {
-    Optional<size_t> pos = SubstName.Find(",", 0);
+    Optional<size_t> pos = SubstName.Find(",");
     if (pos.has_value()) {
       family = SubstName.First(pos.value());
       GetStandardFontName(&family);
diff --git a/testing/resources/pixel/bug_601362_expected_win.pdf.0.png b/testing/resources/pixel/bug_601362_expected_win.pdf.0.png
new file mode 100644
index 0000000..8efa181
--- /dev/null
+++ b/testing/resources/pixel/bug_601362_expected_win.pdf.0.png
Binary files differ
diff --git a/testing/resources/pixel/bug_845697_expected_win.pdf.0.png b/testing/resources/pixel/bug_845697_expected_win.pdf.0.png
new file mode 100644
index 0000000..598275b
--- /dev/null
+++ b/testing/resources/pixel/bug_845697_expected_win.pdf.0.png
Binary files differ