summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdfedit_embeddertest.cpp
diff options
context:
space:
mode:
authorNicolas Pena <npm@chromium.org>2017-02-14 18:26:20 -0500
committerChromium commit bot <commit-bot@chromium.org>2017-02-15 15:05:06 +0000
commit49058400ea8ddf753010dc73e7d381b7a35993ae (patch)
treedc6739a113c88129f6082f7f5ae7d10f99dde727 /fpdfsdk/fpdfedit_embeddertest.cpp
parent1c467fd5145e7f61ab03b608cf9e9581022b4428 (diff)
downloadpdfium-49058400ea8ddf753010dc73e7d381b7a35993ae.tar.xz
Add public API for adding text with standard fonts
BUG=pdfium:667 Change-Id: I05e301385a7af4b6ce27dc0b885e23646abf3dd9 Reviewed-on: https://pdfium-review.googlesource.com/2711 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fpdfsdk/fpdfedit_embeddertest.cpp')
-rw-r--r--fpdfsdk/fpdfedit_embeddertest.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/fpdfsdk/fpdfedit_embeddertest.cpp b/fpdfsdk/fpdfedit_embeddertest.cpp
index 83d26312fc..fb561967ec 100644
--- a/fpdfsdk/fpdfedit_embeddertest.cpp
+++ b/fpdfsdk/fpdfedit_embeddertest.cpp
@@ -318,3 +318,63 @@ TEST_F(FPDFEditEmbeddertest, AddStrokedPaths) {
FPDF_ClosePage(page);
FPDF_CloseDocument(doc);
}
+
+TEST_F(FPDFEditEmbeddertest, AddStandardFontText) {
+ // Start with a blank page
+ FPDF_DOCUMENT doc = FPDF_CreateNewDocument();
+ FPDF_PAGE page = FPDFPage_New(doc, 0, 612, 792);
+
+ // Add some text to the page
+ FPDF_PAGEOBJECT text1 = FPDFPageObj_NewTextObj(doc, "Arial", 12.0f);
+ EXPECT_TRUE(text1);
+ EXPECT_TRUE(FPDFText_SetText(text1, "I'm at the bottom of the page"));
+ FPDFPageObj_Transform(text1, 1, 0, 0, 1, 20, 20);
+ FPDFPage_InsertObject(page, text1);
+ EXPECT_TRUE(FPDFPage_GenerateContent(page));
+ FPDF_BITMAP page_bitmap = RenderPage(page);
+#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
+ const char md5[] = "e19c90395d73cb9f37a6c3b0e8b18a9e";
+#else
+ const char md5[] = "7c3a36ba7cec01688a16a14bfed9ecfc";
+#endif
+ CompareBitmap(page_bitmap, 612, 792, md5);
+ FPDFBitmap_Destroy(page_bitmap);
+
+ // Try another font
+ FPDF_PAGEOBJECT text2 =
+ FPDFPageObj_NewTextObj(doc, "TimesNewRomanBold", 15.0f);
+ EXPECT_TRUE(text2);
+ EXPECT_TRUE(FPDFText_SetText(text2, "Hi, I'm Bold. Times New Roman Bold."));
+ FPDFPageObj_Transform(text2, 1, 0, 0, 1, 100, 600);
+ FPDFPage_InsertObject(page, text2);
+ EXPECT_TRUE(FPDFPage_GenerateContent(page));
+ page_bitmap = RenderPage(page);
+#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
+ const char md5_2[] = "8e1c43dca6be68d364dbc283f5521041";
+#else
+ const char md5_2[] = "e0e0873e3a2634a6394a431a51ce90ff";
+#endif
+ CompareBitmap(page_bitmap, 612, 792, md5_2);
+ FPDFBitmap_Destroy(page_bitmap);
+
+ // And some randomly transformed text
+ FPDF_PAGEOBJECT text3 = FPDFPageObj_NewTextObj(doc, "Courier-Bold", 20.0f);
+ EXPECT_TRUE(text3);
+ EXPECT_TRUE(FPDFText_SetText(text3, "Can you read me? <:)>"));
+ FPDFPageObj_Transform(text3, 1, 1.5, 2, 0.5, 200, 200);
+ FPDFPage_InsertObject(page, text3);
+ EXPECT_TRUE(FPDFPage_GenerateContent(page));
+ page_bitmap = RenderPage(page);
+#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
+ const char md5_3[] = "c6e5df448428793c7e4b0c820bd8c85e";
+#else
+ const char md5_3[] = "903ee10b6a9f0be51ecad0a1a0eeb171";
+#endif
+ CompareBitmap(page_bitmap, 612, 792, md5_3);
+ FPDFBitmap_Destroy(page_bitmap);
+
+ // TODO(npm): Why are there issues with text rotated by 90 degrees?
+ // TODO(npm): FPDF_SaveAsCopy not giving the desired result after this.
+ FPDF_ClosePage(page);
+ FPDF_CloseDocument(doc);
+}