Fix incorrect font dictionary usage in GeneratePopupAP()

When GeneratePopupAP() calls CPDF_DocPageData::GetFont(), GetFont()
expects a font dictionary. GeneratePopupAP() is incorrectly passing in
the resource dictionary for all fonts. This ultimately causes the font
mapping code to ask the PDFium embedder for a font with no font name.
Fix this by generating the font dictionary and the font resources
dictionary separately. Thus making it easy to call GetFont() with the
correct dictionary.

Update corpus tests to match the new behavior. In FPDFAnnotEmbedderTest,
the generated content stream is slightly different because the font
metrics are different. This then compresses differently, which is why
the expected PDF size has changed. This change is OK, because the test
case is checking for size differences.

Change-Id: I313411864f993e096cbd41f440791bdf821bf268
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/113113
Reviewed-by: Nigi <nigi@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/DEPS b/DEPS
index 4336bab..10200f4 100644
--- a/DEPS
+++ b/DEPS
@@ -166,7 +166,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': 'e5b2404351705d43a2cc811db4bd482b9aedd6f7',
+  'pdfium_tests_revision': '7c9db8d1674758d3b48b0647e3d0ad5f7667a2c6',
   # Three lines of non-changing comments so that
   # the commit queue can handle CLs rolling resultdb
   # and whatever else without interference from each other.
diff --git a/core/fpdfdoc/cpdf_generateap.cpp b/core/fpdfdoc/cpdf_generateap.cpp
index 3b0f7d9..e7f7256 100644
--- a/core/fpdfdoc/cpdf_generateap.cpp
+++ b/core/fpdfdoc/cpdf_generateap.cpp
@@ -404,13 +404,13 @@
 }
 
 RetainPtr<CPDF_Dictionary> GenerateResourceFontDict(
-    CPDF_Document* pDoc,
-    const ByteString& sFontDictName) {
-  auto pFontDict = GenerateFallbackFontDict(pDoc);
-  auto pResourceFontDict = pDoc->New<CPDF_Dictionary>();
-  pResourceFontDict->SetNewFor<CPDF_Reference>(sFontDictName, pDoc,
-                                               pFontDict->GetObjNum());
-  return pResourceFontDict;
+    CPDF_Document* doc,
+    const ByteString& font_name,
+    uint32_t font_dict_obj_num) {
+  auto resource_font_dict = doc->New<CPDF_Dictionary>();
+  resource_font_dict->SetNewFor<CPDF_Reference>(font_name, doc,
+                                                font_dict_obj_num);
+  return resource_font_dict;
 }
 
 ByteString GetPaintOperatorString(bool bIsStrokeRect, bool bIsFillRect) {
@@ -755,22 +755,22 @@
   sAppStream << rect.left << " " << rect.bottom << " " << rect.Width() << " "
              << rect.Height() << " re b\n";
 
-  ByteString sFontName = "FONT";
-  RetainPtr<CPDF_Dictionary> pResourceFontDict =
-      GenerateResourceFontDict(pDoc, sFontName);
-
+  RetainPtr<CPDF_Dictionary> font_dict = GenerateFallbackFontDict(pDoc);
   auto* pData = CPDF_DocPageData::FromDocument(pDoc);
-  RetainPtr<CPDF_Font> pDefFont = pData->GetFont(pResourceFontDict);
+  RetainPtr<CPDF_Font> pDefFont = pData->GetFont(font_dict);
   if (!pDefFont)
     return false;
 
+  const ByteString font_name = "FONT";
+  RetainPtr<CPDF_Dictionary> resource_font_dict =
+      GenerateResourceFontDict(pDoc, font_name, font_dict->GetObjNum());
   RetainPtr<CPDF_Dictionary> pExtGStateDict =
       GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
   RetainPtr<CPDF_Dictionary> pResourceDict = GenerateResourceDict(
-      pDoc, std::move(pExtGStateDict), std::move(pResourceFontDict));
+      pDoc, std::move(pExtGStateDict), std::move(resource_font_dict));
 
   sAppStream << GetPopupContentsString(pDoc, *pAnnotDict, std::move(pDefFont),
-                                       sFontName);
+                                       font_name);
   GenerateAndSetAPDict(pDoc, pAnnotDict, &sAppStream, std::move(pResourceDict),
                        false /*IsTextMarkupAnnotation*/);
   return true;
diff --git a/fpdfsdk/fpdf_annot_embeddertest.cpp b/fpdfsdk/fpdf_annot_embeddertest.cpp
index 8ddba6a..bc66814 100644
--- a/fpdfsdk/fpdf_annot_embeddertest.cpp
+++ b/fpdfsdk/fpdf_annot_embeddertest.cpp
@@ -2195,14 +2195,14 @@
   UnloadPage(page);
 }
 
-TEST_F(FPDFAnnotEmbedderTest, BUG_1206) {
+TEST_F(FPDFAnnotEmbedderTest, Bug1206) {
   const char* expected_bitmap = []() {
     if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
       return "a1ea1ceebb26922fae576cb79ce63af0";
     }
     return "0d9fc05c6762fd788bd23fd87a4967bc";
   }();
-  static constexpr size_t kExpectedSize = 1593;
+  static constexpr size_t kExpectedSize = 1601;
 
   ASSERT_TRUE(OpenDocument("bug_1206.pdf"));