summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdf_edit_embeddertest.cpp
diff options
context:
space:
mode:
authorHenrique Nakashima <hnakashima@chromium.org>2018-07-10 21:04:05 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-07-10 21:04:05 +0000
commit144107d3ca6ddd2724a460c4da4a20e6e1b7f1b7 (patch)
tree7fc11c898c7d5397f8b910d447eccfd04680f288 /fpdfsdk/fpdf_edit_embeddertest.cpp
parent416cbeab1d93b1261dfb4584e0c8e47d9cd4720f (diff)
downloadpdfium-144107d3ca6ddd2724a460c4da4a20e6e1b7f1b7.tar.xz
Create API for adding content marks and setting their params.chromium/3488
This CL creates the following new functions in the public API: - FPDFPageObj_AddMark - FPDFPageObjMark_SetIntParam - FPDFPageObjMark_SetStringParam Bug: pdfium:1037 Change-Id: Icabf3fdd8e8153b9156bab807a3708d38a9365d8 Reviewed-on: https://pdfium-review.googlesource.com/37330 Commit-Queue: Henrique Nakashima <hnakashima@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'fpdfsdk/fpdf_edit_embeddertest.cpp')
-rw-r--r--fpdfsdk/fpdf_edit_embeddertest.cpp77
1 files changed, 77 insertions, 0 deletions
diff --git a/fpdfsdk/fpdf_edit_embeddertest.cpp b/fpdfsdk/fpdf_edit_embeddertest.cpp
index a490162e15..a9eca92a4e 100644
--- a/fpdfsdk/fpdf_edit_embeddertest.cpp
+++ b/fpdfsdk/fpdf_edit_embeddertest.cpp
@@ -2021,6 +2021,83 @@ TEST_F(FPDFEditEmbeddertest, SaveAndRender) {
VerifySavedDocument(612, 792, md5);
}
+TEST_F(FPDFEditEmbeddertest, AddMarkedText) {
+ // Start with a blank page.
+ FPDF_PAGE page = FPDFPage_New(CreateNewDocument(), 0, 612, 792);
+
+ const CPDF_Font* stock_font = CPDF_Font::GetStockFont(cpdf_doc(), "Arial");
+ const uint8_t* data = stock_font->GetFont()->GetFontData();
+ const uint32_t size = stock_font->GetFont()->GetSize();
+ ScopedFPDFFont font(
+ FPDFText_LoadFont(document(), data, size, FPDF_FONT_TRUETYPE, 0));
+ ASSERT_TRUE(font.get());
+
+ // Add some text to the page.
+ FPDF_PAGEOBJECT text_object =
+ FPDFPageObj_CreateTextObj(document(), font.get(), 12.0f);
+
+ EXPECT_TRUE(text_object);
+ std::unique_ptr<unsigned short, pdfium::FreeDeleter> text1 =
+ GetFPDFWideString(L"I am testing my loaded font, WEE.");
+ EXPECT_TRUE(FPDFText_SetText(text_object, text1.get()));
+ FPDFPageObj_Transform(text_object, 1, 0, 0, 1, 400, 400);
+ FPDFPage_InsertObject(page, text_object);
+
+ // Add a mark with the tag "TestMarkName" to that text.
+ EXPECT_EQ(0, FPDFPageObj_CountMarks(text_object));
+ FPDF_PAGEOBJECTMARK mark = FPDFPageObj_AddMark(text_object, "TestMarkName");
+ EXPECT_TRUE(mark);
+ EXPECT_EQ(1, FPDFPageObj_CountMarks(text_object));
+ EXPECT_EQ(mark, FPDFPageObj_GetMark(text_object, 0));
+ char buffer[256];
+ EXPECT_GT(FPDFPageObjMark_GetName(mark, buffer, 256), 0u);
+ std::wstring name =
+ GetPlatformWString(reinterpret_cast<unsigned short*>(buffer));
+ EXPECT_EQ(L"TestMarkName", name);
+
+ // Add parameters:
+ // - int "IntKey" : 42
+ // - string "StringKey": "StringValue"
+ EXPECT_EQ(0, FPDFPageObjMark_CountParams(mark));
+ EXPECT_TRUE(FPDFPageObjMark_SetIntParam(document(), mark, "IntKey", 42));
+ EXPECT_TRUE(FPDFPageObjMark_SetStringParam(document(), mark, "StringKey",
+ "StringValue"));
+ EXPECT_EQ(2, FPDFPageObjMark_CountParams(mark));
+
+ // Check the two parameters can be retrieved.
+ EXPECT_EQ(FPDF_OBJECT_NUMBER,
+ FPDFPageObjMark_GetParamValueTypeByKey(mark, "IntKey"));
+ int int_value;
+ EXPECT_TRUE(
+ FPDFPageObjMark_GetParamIntValueByKey(mark, "IntKey", &int_value));
+ EXPECT_EQ(42, int_value);
+
+ EXPECT_EQ(FPDF_OBJECT_STRING,
+ FPDFPageObjMark_GetParamValueTypeByKey(mark, "StringKey"));
+ unsigned long out_buffer_len;
+ EXPECT_TRUE(FPDFPageObjMark_GetParamStringValueByKey(
+ mark, "StringKey", buffer, 256, &out_buffer_len));
+ EXPECT_GT(out_buffer_len, 0u);
+ name = GetPlatformWString(reinterpret_cast<unsigned short*>(buffer));
+ EXPECT_EQ(L"StringValue", name);
+
+// Render and check the bitmap is the expected one.
+#if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
+ const char md5[] = "17d2b6cd574cf66170b09c8927529a94";
+#else
+ const char md5[] = "70592859010ffbf532a2237b8118bcc4";
+#endif
+ {
+ ScopedFPDFBitmap page_bitmap = RenderPageWithFlags(page, nullptr, 0);
+ CompareBitmap(page_bitmap.get(), 612, 792, md5);
+ }
+
+ FPDF_ClosePage(page);
+
+ // TODO(pdfium:1118): Save, then re-open the file and check the changes were
+ // kept in the saved .pdf.
+}
+
TEST_F(FPDFEditEmbeddertest, ExtractImageBitmap) {
ASSERT_TRUE(OpenDocument("embedded_images.pdf"));
FPDF_PAGE page = LoadPage(0);