Use a stable sort to rank XFA font candidates

Uses std::stable_sort instead of std::sort to rank font candidates
within CFGAS_FontMgr::MatchFonts(). Using a non-stable sort leads to the
"best" candidate being selected non-deterministically, which interferes
with pixel tests, among other things.

This requires new Mac-specific expectations for xfa_node_caption.pdf, as
the matched font changes on this platform with stable sort; however,
future std::sort behavior changes shouldn't require additional updates.

Fixed: pdfium:1982
Change-Id: I458bd713521869b0ea8d4da8fbd3832cf1d57e4c
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/103590
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: K. Moon <kmoon@chromium.org>
diff --git a/testing/resources/pixel/xfa_specific/xfa_node_caption_expected_mac.pdf.0.png b/testing/resources/pixel/xfa_specific/xfa_node_caption_expected_mac.pdf.0.png
new file mode 100644
index 0000000..4912da0
--- /dev/null
+++ b/testing/resources/pixel/xfa_specific/xfa_node_caption_expected_mac.pdf.0.png
Binary files differ
diff --git a/testing/resources/pixel/xfa_specific/xfa_node_caption_expected_mac.pdf.1.png b/testing/resources/pixel/xfa_specific/xfa_node_caption_expected_mac.pdf.1.png
new file mode 100644
index 0000000..427b5b3
--- /dev/null
+++ b/testing/resources/pixel/xfa_specific/xfa_node_caption_expected_mac.pdf.1.png
Binary files differ
diff --git a/testing/resources/pixel/xfa_specific/xfa_node_caption_expected_skia_mac.pdf.0.png b/testing/resources/pixel/xfa_specific/xfa_node_caption_expected_skia_mac.pdf.0.png
new file mode 100644
index 0000000..3d26771a
--- /dev/null
+++ b/testing/resources/pixel/xfa_specific/xfa_node_caption_expected_skia_mac.pdf.0.png
Binary files differ
diff --git a/testing/resources/pixel/xfa_specific/xfa_node_caption_expected_skia_mac.pdf.1.png b/testing/resources/pixel/xfa_specific/xfa_node_caption_expected_skia_mac.pdf.1.png
new file mode 100644
index 0000000..ff8f6b9
--- /dev/null
+++ b/testing/resources/pixel/xfa_specific/xfa_node_caption_expected_skia_mac.pdf.1.png
Binary files differ
diff --git a/xfa/fgas/font/cfgas_fontmgr.cpp b/xfa/fgas/font/cfgas_fontmgr.cpp
index ff6e39e..ec0eeea 100644
--- a/xfa/fgas/font/cfgas_fontmgr.cpp
+++ b/xfa/fgas/font/cfgas_fontmgr.cpp
@@ -720,7 +720,7 @@
     if (matched_fonts.size() == 0xffff)
       break;
   }
-  std::sort(matched_fonts.begin(), matched_fonts.end());
+  std::stable_sort(matched_fonts.begin(), matched_fonts.end());
   return matched_fonts;
 }