summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdf_transformpage_embeddertest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'fpdfsdk/fpdf_transformpage_embeddertest.cpp')
-rw-r--r--fpdfsdk/fpdf_transformpage_embeddertest.cpp244
1 files changed, 145 insertions, 99 deletions
diff --git a/fpdfsdk/fpdf_transformpage_embeddertest.cpp b/fpdfsdk/fpdf_transformpage_embeddertest.cpp
index 3904b0c321..8fa33704c7 100644
--- a/fpdfsdk/fpdf_transformpage_embeddertest.cpp
+++ b/fpdfsdk/fpdf_transformpage_embeddertest.cpp
@@ -15,38 +15,45 @@ TEST_F(FPDFTransformEmbedderTest, GetBoundingBoxes) {
FPDF_PAGE page = LoadPage(1);
ASSERT_TRUE(page);
- float mediabox_left;
- float mediabox_bottom;
- float mediabox_right;
- float mediabox_top;
- EXPECT_TRUE(FPDFPage_GetMediaBox(page, &mediabox_left, &mediabox_bottom,
- &mediabox_right, &mediabox_top));
- EXPECT_EQ(-50, mediabox_left);
- EXPECT_EQ(-50, mediabox_bottom);
- EXPECT_EQ(200, mediabox_right);
- EXPECT_EQ(200, mediabox_top);
-
- float cropbox_left;
- float cropbox_bottom;
- float cropbox_right;
- float cropbox_top;
- EXPECT_TRUE(FPDFPage_GetCropBox(page, &cropbox_left, &cropbox_bottom,
- &cropbox_right, &cropbox_top));
- EXPECT_EQ(50, cropbox_left);
- EXPECT_EQ(50, cropbox_bottom);
- EXPECT_EQ(150, cropbox_right);
- EXPECT_EQ(150, cropbox_top);
-
- float artbox_left;
- float artbox_bottom;
- float artbox_right;
- float artbox_top;
- EXPECT_TRUE(FPDFPage_GetArtBox(page, &artbox_left, &artbox_bottom,
- &artbox_right, &artbox_top));
- EXPECT_EQ(50, artbox_left);
- EXPECT_EQ(60, artbox_bottom);
- EXPECT_EQ(135, artbox_right);
- EXPECT_EQ(140, artbox_top);
+ FS_RECTF mediabox;
+ EXPECT_TRUE(FPDFPage_GetMediaBox(page, &mediabox.left, &mediabox.bottom,
+ &mediabox.right, &mediabox.top));
+ EXPECT_EQ(-50, mediabox.left);
+ EXPECT_EQ(-50, mediabox.bottom);
+ EXPECT_EQ(200, mediabox.right);
+ EXPECT_EQ(200, mediabox.top);
+
+ FS_RECTF cropbox;
+ EXPECT_TRUE(FPDFPage_GetCropBox(page, &cropbox.left, &cropbox.bottom,
+ &cropbox.right, &cropbox.top));
+ EXPECT_EQ(50, cropbox.left);
+ EXPECT_EQ(50, cropbox.bottom);
+ EXPECT_EQ(150, cropbox.right);
+ EXPECT_EQ(150, cropbox.top);
+
+ FS_RECTF bleedbox;
+ EXPECT_TRUE(FPDFPage_GetBleedBox(page, &bleedbox.left, &bleedbox.bottom,
+ &bleedbox.right, &bleedbox.top));
+ EXPECT_EQ(0, bleedbox.left);
+ EXPECT_EQ(10, bleedbox.bottom);
+ EXPECT_EQ(150, bleedbox.right);
+ EXPECT_EQ(145, bleedbox.top);
+
+ FS_RECTF trimbox;
+ EXPECT_TRUE(FPDFPage_GetTrimBox(page, &trimbox.left, &trimbox.bottom,
+ &trimbox.right, &trimbox.top));
+ EXPECT_EQ(25, trimbox.left);
+ EXPECT_EQ(30, trimbox.bottom);
+ EXPECT_EQ(140, trimbox.right);
+ EXPECT_EQ(145, trimbox.top);
+
+ FS_RECTF artbox;
+ EXPECT_TRUE(FPDFPage_GetArtBox(page, &artbox.left, &artbox.bottom,
+ &artbox.right, &artbox.top));
+ EXPECT_EQ(50, artbox.left);
+ EXPECT_EQ(60, artbox.bottom);
+ EXPECT_EQ(135, artbox.right);
+ EXPECT_EQ(140, artbox.top);
UnloadPage(page);
}
@@ -55,48 +62,55 @@ TEST_F(FPDFTransformEmbedderTest, GetBoundingBoxes) {
FPDF_PAGE page = LoadPage(3);
ASSERT_TRUE(page);
- float mediabox_left;
- float mediabox_bottom;
- float mediabox_right;
- float mediabox_top;
- EXPECT_TRUE(FPDFPage_GetMediaBox(page, &mediabox_left, &mediabox_bottom,
- &mediabox_right, &mediabox_top));
- EXPECT_EQ(0, mediabox_left);
- EXPECT_EQ(0, mediabox_bottom);
- EXPECT_EQ(200, mediabox_right);
- EXPECT_EQ(200, mediabox_top);
-
- float cropbox_left;
- float cropbox_bottom;
- float cropbox_right;
- float cropbox_top;
- EXPECT_TRUE(FPDFPage_GetCropBox(page, &cropbox_left, &cropbox_bottom,
- &cropbox_right, &cropbox_top));
- EXPECT_EQ(150, cropbox_left);
- EXPECT_EQ(150, cropbox_bottom);
- EXPECT_EQ(60, cropbox_right);
- EXPECT_EQ(60, cropbox_top);
-
- EXPECT_FALSE(FPDFPage_GetCropBox(page, nullptr, &cropbox_bottom,
- &cropbox_right, &cropbox_top));
- EXPECT_FALSE(FPDFPage_GetCropBox(page, &cropbox_left, nullptr,
- &cropbox_right, &cropbox_top));
- EXPECT_FALSE(FPDFPage_GetCropBox(page, &cropbox_left, &cropbox_bottom,
- nullptr, &cropbox_top));
- EXPECT_FALSE(FPDFPage_GetCropBox(page, &cropbox_left, &cropbox_bottom,
- &cropbox_right, nullptr));
+ FS_RECTF mediabox;
+ EXPECT_TRUE(FPDFPage_GetMediaBox(page, &mediabox.left, &mediabox.bottom,
+ &mediabox.right, &mediabox.top));
+ EXPECT_EQ(0, mediabox.left);
+ EXPECT_EQ(0, mediabox.bottom);
+ EXPECT_EQ(200, mediabox.right);
+ EXPECT_EQ(200, mediabox.top);
+
+ FS_RECTF cropbox;
+ EXPECT_TRUE(FPDFPage_GetCropBox(page, &cropbox.left, &cropbox.bottom,
+ &cropbox.right, &cropbox.top));
+ EXPECT_EQ(150, cropbox.left);
+ EXPECT_EQ(150, cropbox.bottom);
+ EXPECT_EQ(60, cropbox.right);
+ EXPECT_EQ(60, cropbox.top);
+
+ EXPECT_FALSE(FPDFPage_GetCropBox(page, nullptr, &cropbox.bottom,
+ &cropbox.right, &cropbox.top));
+ EXPECT_FALSE(FPDFPage_GetCropBox(page, &cropbox.left, nullptr,
+ &cropbox.right, &cropbox.top));
+ EXPECT_FALSE(FPDFPage_GetCropBox(page, &cropbox.left, &cropbox.bottom,
+ nullptr, &cropbox.top));
+ EXPECT_FALSE(FPDFPage_GetCropBox(page, &cropbox.left, &cropbox.bottom,
+ &cropbox.right, nullptr));
EXPECT_FALSE(FPDFPage_GetCropBox(page, nullptr, nullptr, nullptr, nullptr));
- float artbox_left;
- float artbox_bottom;
- float artbox_right;
- float artbox_top;
- EXPECT_TRUE(FPDFPage_GetArtBox(page, &artbox_left, &artbox_bottom,
- &artbox_right, &artbox_top));
- EXPECT_EQ(140, artbox_left);
- EXPECT_EQ(145, artbox_bottom);
- EXPECT_EQ(65, artbox_right);
- EXPECT_EQ(70, artbox_top);
+ FS_RECTF bleedbox;
+ EXPECT_TRUE(FPDFPage_GetBleedBox(page, &bleedbox.left, &bleedbox.bottom,
+ &bleedbox.right, &bleedbox.top));
+ EXPECT_EQ(160, bleedbox.left);
+ EXPECT_EQ(165, bleedbox.bottom);
+ EXPECT_EQ(0, bleedbox.right);
+ EXPECT_EQ(10, bleedbox.top);
+
+ FS_RECTF trimbox;
+ EXPECT_TRUE(FPDFPage_GetTrimBox(page, &trimbox.left, &trimbox.bottom,
+ &trimbox.right, &trimbox.top));
+ EXPECT_EQ(155, trimbox.left);
+ EXPECT_EQ(165, trimbox.bottom);
+ EXPECT_EQ(25, trimbox.right);
+ EXPECT_EQ(30, trimbox.top);
+
+ FS_RECTF artbox;
+ EXPECT_TRUE(FPDFPage_GetArtBox(page, &artbox.left, &artbox.bottom,
+ &artbox.right, &artbox.top));
+ EXPECT_EQ(140, artbox.left);
+ EXPECT_EQ(145, artbox.bottom);
+ EXPECT_EQ(65, artbox.right);
+ EXPECT_EQ(70, artbox.top);
UnloadPage(page);
}
@@ -109,37 +123,50 @@ TEST_F(FPDFTransformEmbedderTest, NoCropBox) {
FPDF_PAGE page = LoadPage(0);
ASSERT_TRUE(page);
- float left = -1.0f;
- float bottom = -2.0f;
- float right = 3.0f;
- float top = 0.0f;
- EXPECT_FALSE(FPDFPage_GetCropBox(page, &left, &bottom, &right, &top));
- EXPECT_EQ(-1.0f, left);
- EXPECT_EQ(-2.0f, bottom);
- EXPECT_EQ(3.0f, right);
- EXPECT_EQ(0.0f, top);
+ FS_RECTF cropbox = {-1.0f, 0.0f, 3.0f, -2.0f};
+ EXPECT_FALSE(FPDFPage_GetCropBox(page, &cropbox.left, &cropbox.bottom,
+ &cropbox.right, &cropbox.top));
+ EXPECT_EQ(-1.0f, cropbox.left);
+ EXPECT_EQ(-2.0f, cropbox.bottom);
+ EXPECT_EQ(3.0f, cropbox.right);
+ EXPECT_EQ(0.0f, cropbox.top);
UnloadPage(page);
}
-TEST_F(FPDFTransformEmbedderTest, ClipPath) {
+TEST_F(FPDFTransformEmbedderTest, NoBleedBox) {
ASSERT_TRUE(OpenDocument("hello_world.pdf"));
+ ASSERT_EQ(1, FPDF_GetPageCount(document()));
FPDF_PAGE page = LoadPage(0);
ASSERT_TRUE(page);
- FPDF_CLIPPATH clip = FPDF_CreateClipPath(10.0f, 10.0f, 90.0f, 90.0f);
- EXPECT_TRUE(clip);
+ FS_RECTF bleedbox = {-1.0f, 10.f, 3.0f, -1.0f};
+ EXPECT_FALSE(FPDFPage_GetBleedBox(page, &bleedbox.left, &bleedbox.bottom,
+ &bleedbox.right, &bleedbox.top));
+ EXPECT_EQ(-1.0f, bleedbox.left);
+ EXPECT_EQ(-1.0f, bleedbox.bottom);
+ EXPECT_EQ(3.0f, bleedbox.right);
+ EXPECT_EQ(10.0f, bleedbox.top);
- // NULL arg call is a no-op.
- FPDFPage_InsertClipPath(nullptr, clip);
+ UnloadPage(page);
+}
- // Do actual work.
- FPDFPage_InsertClipPath(page, clip);
+TEST_F(FPDFTransformEmbedderTest, NoTrimBox) {
+ ASSERT_TRUE(OpenDocument("hello_world.pdf"));
+ ASSERT_EQ(1, FPDF_GetPageCount(document()));
- // TODO(tsepez): test how inserting path affects page rendering.
+ FPDF_PAGE page = LoadPage(0);
+ ASSERT_TRUE(page);
+
+ FS_RECTF trimbox = {-11.0f, 0.0f, 3.0f, -10.0f};
+ EXPECT_FALSE(FPDFPage_GetTrimBox(page, &trimbox.left, &trimbox.bottom,
+ &trimbox.right, &trimbox.top));
+ EXPECT_EQ(-11.0f, trimbox.left);
+ EXPECT_EQ(-10.0f, trimbox.bottom);
+ EXPECT_EQ(3.0f, trimbox.right);
+ EXPECT_EQ(0.0f, trimbox.top);
- FPDF_DestroyClipPath(clip);
UnloadPage(page);
}
@@ -150,15 +177,34 @@ TEST_F(FPDFTransformEmbedderTest, NoArtBox) {
FPDF_PAGE page = LoadPage(0);
ASSERT_TRUE(page);
- float left = -1.0f;
- float bottom = -1.0f;
- float right = 3.0f;
- float top = 0.0f;
- EXPECT_FALSE(FPDFPage_GetArtBox(page, &left, &bottom, &right, &top));
- EXPECT_EQ(-1.0f, left);
- EXPECT_EQ(-1.0f, bottom);
- EXPECT_EQ(3.0f, right);
- EXPECT_EQ(0.0f, top);
+ FS_RECTF artbox = {-1.0f, 0.0f, 3.0f, -1.0f};
+ EXPECT_FALSE(FPDFPage_GetArtBox(page, &artbox.left, &artbox.bottom,
+ &artbox.right, &artbox.top));
+ EXPECT_EQ(-1.0f, artbox.left);
+ EXPECT_EQ(-1.0f, artbox.bottom);
+ EXPECT_EQ(3.0f, artbox.right);
+ EXPECT_EQ(0.0f, artbox.top);
+
+ UnloadPage(page);
+}
+
+TEST_F(FPDFTransformEmbedderTest, ClipPath) {
+ ASSERT_TRUE(OpenDocument("hello_world.pdf"));
+
+ FPDF_PAGE page = LoadPage(0);
+ ASSERT_TRUE(page);
+
+ FPDF_CLIPPATH clip = FPDF_CreateClipPath(10.0f, 10.0f, 90.0f, 90.0f);
+ EXPECT_TRUE(clip);
+ // NULL arg call is a no-op.
+ FPDFPage_InsertClipPath(nullptr, clip);
+
+ // Do actual work.
+ FPDFPage_InsertClipPath(page, clip);
+
+ // TODO(tsepez): test how inserting path affects page rendering.
+
+ FPDF_DestroyClipPath(clip);
UnloadPage(page);
}