Add new FPDFFont_GetIsEmbedded() API.

This API complements FPDFFont_GetFontData() and tells the caller where a
given font is embedded in the PDF or not.

Bug: pdfium:1833
Change-Id: I0b401a6e6ece9f84aab58d1dd11f4ce605fb83e8
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/93572
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Nigi <nigi@chromium.org>
diff --git a/fpdfsdk/fpdf_edit_embeddertest.cpp b/fpdfsdk/fpdf_edit_embeddertest.cpp
index e819ffc..155fe3b 100644
--- a/fpdfsdk/fpdf_edit_embeddertest.cpp
+++ b/fpdfsdk/fpdf_edit_embeddertest.cpp
@@ -2541,6 +2541,10 @@
                                       &buf_bytes_required));
     EXPECT_EQ(345u, buf_bytes_required);
   }
+  {
+    ASSERT_EQ(1, FPDFFont_GetIsEmbedded(font));
+    ASSERT_EQ(-1, FPDFFont_GetIsEmbedded(nullptr));
+  }
 
   UnloadPage(page);
 }
@@ -2566,6 +2570,7 @@
       FPDFFont_GetFontData(font, buf.data(), buf.size(), &buf_bytes_required));
   EXPECT_EQ(kTinosRegularSize, buf_bytes_required);
   EXPECT_EQ("2b019558f2c2de0b7cbc0a6e64b20599", GenerateMD5Base16(buf));
+  EXPECT_EQ(0, FPDFFont_GetIsEmbedded(font));
 
   // Similarly, the second object consistently maps to Arimo-Regular.ttf.
   constexpr size_t kArimoRegularSize = 436180;
@@ -2578,6 +2583,7 @@
       FPDFFont_GetFontData(font, buf.data(), buf.size(), &buf_bytes_required));
   EXPECT_EQ(kArimoRegularSize, buf_bytes_required);
   EXPECT_EQ("7ac02a544211773d9636e056e9da6c35", GenerateMD5Base16(buf));
+  EXPECT_EQ(0, FPDFFont_GetIsEmbedded(font));
 
   UnloadPage(page);
 }
diff --git a/fpdfsdk/fpdf_edittext.cpp b/fpdfsdk/fpdf_edittext.cpp
index edb9ca2..04c242c 100644
--- a/fpdfsdk/fpdf_edittext.cpp
+++ b/fpdfsdk/fpdf_edittext.cpp
@@ -668,6 +668,13 @@
   return true;
 }
 
+FPDF_EXPORT int FPDF_CALLCONV FPDFFont_GetIsEmbedded(FPDF_FONT font) {
+  auto* cfont = CPDFFontFromFPDFFont(font);
+  if (!cfont)
+    return -1;
+  return cfont->IsEmbedded() ? 1 : 0;
+}
+
 FPDF_EXPORT int FPDF_CALLCONV FPDFFont_GetFlags(FPDF_FONT font) {
   auto* pFont = CPDFFontFromFPDFFont(font);
   if (!pFont)
diff --git a/fpdfsdk/fpdf_view_c_api_test.c b/fpdfsdk/fpdf_view_c_api_test.c
index 3eb4a39..696d3a6 100644
--- a/fpdfsdk/fpdf_view_c_api_test.c
+++ b/fpdfsdk/fpdf_view_c_api_test.c
@@ -163,6 +163,7 @@
     CHK(FPDFFont_GetFontName);
     CHK(FPDFFont_GetGlyphPath);
     CHK(FPDFFont_GetGlyphWidth);
+    CHK(FPDFFont_GetIsEmbedded);
     CHK(FPDFFont_GetItalicAngle);
     CHK(FPDFFont_GetWeight);
     CHK(FPDFFormObj_CountObjects);
diff --git a/public/fpdf_edit.h b/public/fpdf_edit.h
index c606e40..b68b7c9 100644
--- a/public/fpdf_edit.h
+++ b/public/fpdf_edit.h
@@ -1267,6 +1267,14 @@
                                                          size_t* out_buflen);
 
 // Experimental API.
+// Get whether |font| is embedded or not.
+//
+// font - the handle to the font object.
+//
+// Returns 1 if the font is embedded, 0 if it not, and -1 on failure.
+FPDF_EXPORT int FPDF_CALLCONV FPDFFont_GetIsEmbedded(FPDF_FONT font);
+
+// Experimental API.
 // Get the descriptor flags of a font.
 //
 // font - the handle to the font object.