summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
authorNicolas Pena <npm@chromium.org>2018-06-13 18:23:46 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-06-13 18:23:46 +0000
commit4c48b107c6d1e3d3029910062368d8d954e8f28a (patch)
tree18d0c3c14cab579431dd6cd765ad0e405527f0e8 /fpdfsdk
parentfb6b382bea56ca22bacce1379230680d17cf5896 (diff)
downloadpdfium-4c48b107c6d1e3d3029910062368d8d954e8f28a.tar.xz
Add FPDFText_LoadStandardFont to public API
Bug: pdfium:978 Change-Id: I0dcffdfd1b19b83e5234da7791cb3f3e52cc257b Reviewed-on: https://pdfium-review.googlesource.com/35110 Commit-Queue: Nicolás Peña Moreno <npm@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/fpdf_edit_embeddertest.cpp68
-rw-r--r--fpdfsdk/fpdf_edittext.cpp10
-rw-r--r--fpdfsdk/fpdf_view_c_api_test.c1
3 files changed, 79 insertions, 0 deletions
diff --git a/fpdfsdk/fpdf_edit_embeddertest.cpp b/fpdfsdk/fpdf_edit_embeddertest.cpp
index 3d2e090a36..0a119b9577 100644
--- a/fpdfsdk/fpdf_edit_embeddertest.cpp
+++ b/fpdfsdk/fpdf_edit_embeddertest.cpp
@@ -931,6 +931,7 @@ TEST_F(FPDFEditEmbeddertest, AddStrokedPaths) {
FPDF_ClosePage(page);
}
+// Tests adding text from standard font using FPDFPageObj_NewTextObj.
TEST_F(FPDFEditEmbeddertest, AddStandardFontText) {
// Start with a blank page
FPDF_PAGE page = FPDFPage_New(CreateNewDocument(), 0, 612, 792);
@@ -1001,6 +1002,73 @@ TEST_F(FPDFEditEmbeddertest, AddStandardFontText) {
FPDF_ClosePage(page);
}
+// Tests adding text from standard font using FPDFText_LoadStandardFont.
+TEST_F(FPDFEditEmbeddertest, AddStandardFontText2) {
+ // Start with a blank page
+ ScopedFPDFPage page(FPDFPage_New(CreateNewDocument(), 0, 612, 792));
+
+ // Load a standard font.
+ FPDF_FONT font = FPDFText_LoadStandardFont(document(), "Helvetica");
+ ASSERT_TRUE(font);
+
+ // Add some text to the page.
+ FPDF_PAGEOBJECT text_object =
+ FPDFPageObj_CreateTextObj(document(), font, 12.0f);
+ EXPECT_TRUE(text_object);
+ std::unique_ptr<unsigned short, pdfium::FreeDeleter> text =
+ GetFPDFWideString(L"I'm at the bottom of the page");
+ EXPECT_TRUE(FPDFText_SetText(text_object, text.get()));
+ FPDFPageObj_Transform(text_object, 1, 0, 0, 1, 20, 20);
+ FPDFPage_InsertObject(page.get(), text_object);
+ ScopedFPDFBitmap page_bitmap = RenderPageWithFlags(page.get(), nullptr, 0);
+#if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
+ const char md5[] = "a4dddc1a3930fa694bbff9789dab4161";
+#else
+ const char md5[] = "eacaa24573b8ce997b3882595f096f00";
+#endif
+ CompareBitmap(page_bitmap.get(), 612, 792, md5);
+}
+
+TEST_F(FPDFEditEmbeddertest, LoadStandardFonts) {
+ CreateNewDocument();
+ const char* standard_font_names[] = {"Arial",
+ "Arial-Bold",
+ "Arial-BoldItalic",
+ "Arial-Italic",
+ "Courier",
+ "Courier-BoldOblique",
+ "Courier-Oblique",
+ "Courier-Bold",
+ "CourierNew",
+ "CourierNew-Bold",
+ "CourierNew-BoldItalic",
+ "CourierNew-Italic",
+ "Helvetica",
+ "Helvetica-Bold",
+ "Helvetica-BoldOblique",
+ "Helvetica-Oblique",
+ "Symbol",
+ "TimesNewRoman",
+ "TimesNewRoman-Bold",
+ "TimesNewRoman-BoldItalic",
+ "TimesNewRoman-Italic",
+ "ZapfDingbats"};
+ for (auto* const font_name : standard_font_names) {
+ FPDF_FONT font = FPDFText_LoadStandardFont(document(), font_name);
+ EXPECT_TRUE(font) << font_name << " should be considered a standard font.";
+ }
+ const char* not_standard_font_names[] = {
+ "Abcdefg", "ArialB", "Arial-Style",
+ "Font Name", "FontArial", "NotAStandardFontName",
+ "TestFontName", "Quack", "Symbol-Italic",
+ "Zapf"};
+ for (auto* const font_name : not_standard_font_names) {
+ FPDF_FONT font = FPDFText_LoadStandardFont(document(), font_name);
+ EXPECT_FALSE(font) << font_name
+ << " should not be considered a standard font.";
+ }
+}
+
TEST_F(FPDFEditEmbeddertest, GraphicsData) {
// New page
ScopedFPDFPage page(FPDFPage_New(CreateNewDocument(), 0, 612, 792));
diff --git a/fpdfsdk/fpdf_edittext.cpp b/fpdfsdk/fpdf_edittext.cpp
index 2ead789204..8186d8d894 100644
--- a/fpdfsdk/fpdf_edittext.cpp
+++ b/fpdfsdk/fpdf_edittext.cpp
@@ -462,6 +462,16 @@ FPDF_EXPORT FPDF_FONT FPDF_CALLCONV FPDFText_LoadFont(FPDF_DOCUMENT document,
: LoadSimpleFont(pDoc, std::move(pFont), data, size, font_type));
}
+FPDF_EXPORT FPDF_FONT FPDF_CALLCONV
+FPDFText_LoadStandardFont(FPDF_DOCUMENT document, FPDF_BYTESTRING font) {
+ CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
+ if (!pDoc)
+ return nullptr;
+
+ return FPDFFontFromCPDFFont(
+ CPDF_Font::GetStockFont(pDoc, ByteStringView(font)));
+}
+
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
FPDFText_SetFillColor(FPDF_PAGEOBJECT text_object,
unsigned int R,
diff --git a/fpdfsdk/fpdf_view_c_api_test.c b/fpdfsdk/fpdf_view_c_api_test.c
index 34ac5518a3..543a7d1a78 100644
--- a/fpdfsdk/fpdf_view_c_api_test.c
+++ b/fpdfsdk/fpdf_view_c_api_test.c
@@ -196,6 +196,7 @@ int CheckPDFiumCApi() {
CHK(FPDFPath_SetStrokeColor);
CHK(FPDFPath_SetStrokeWidth);
CHK(FPDFText_LoadFont);
+ CHK(FPDFText_LoadStandardFont);
CHK(FPDFText_SetFillColor);
CHK(FPDFText_SetText);
CHK(FPDF_CreateNewDocument);