Filter out bad font base encodings when flattening

FPDFPage_Flatten() draws annotations into the content stream. From the
perspective of a PDF reader that only reads the content stream, the
flattened PDF potentially uses more fonts than the original PDF. If the
PDF reader is strict about validating fonts, it can then detect
malformed fonts and reject them.

Avoid a case of this by removing font encodings that are out-of-spec
during the flattening process. Then PDF readers that are strict about
validating font encodings can fallback to default values instead of
choking on the bad values.

Update FPDFFlattenEmbedderTest.FlatWithBadFont to reflect this change
and fulfill the TODO related to this issue.

Bug: 344775293
Change-Id: I1d01dd233caffcaecd6a9d1f391d1bf56da075bb
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/120851
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Thomas Sepez <tsepez@google.com>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/fpdfsdk/fpdf_flatten_embeddertest.cpp b/fpdfsdk/fpdf_flatten_embeddertest.cpp
index 5815912..2bbc75c 100644
--- a/fpdfsdk/fpdf_flatten_embeddertest.cpp
+++ b/fpdfsdk/fpdf_flatten_embeddertest.cpp
@@ -11,6 +11,7 @@
 #include "testing/gtest/include/gtest/gtest.h"
 
 using testing::HasSubstr;
+using testing::Not;
 
 namespace {
 
@@ -53,8 +54,7 @@
   EXPECT_EQ(FLATTEN_SUCCESS, FPDFPage_Flatten(page, FLAT_PRINT));
   EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
 
-  // TODO(crbug.com/344775293): HasSubstr() should be negated with Not().
-  EXPECT_THAT(GetString(), HasSubstr("/PDFDocEncoding"));
+  EXPECT_THAT(GetString(), Not(HasSubstr("/PDFDocEncoding")));
   UnloadPage(page);
 }