blob: 1ebd0f054c0fd67a6bdc668c9af210a9533c4ec7 [file] [log] [blame]
Lei Zhangd8a8f272018-06-08 18:03:38 +00001// Copyright 2018 PDFium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "public/fpdf_transformpage.h"
6#include "testing/embedder_test.h"
7
8class FPDFTransformEmbedderTest : public EmbedderTest {};
9
10TEST_F(FPDFTransformEmbedderTest, GetBoundingBoxes) {
11 ASSERT_TRUE(OpenDocument("cropped_text.pdf"));
12 ASSERT_EQ(4, FPDF_GetPageCount(document()));
13
14 {
15 FPDF_PAGE page = LoadPage(1);
16 ASSERT_TRUE(page);
17
18 float mediabox_left;
19 float mediabox_bottom;
20 float mediabox_right;
21 float mediabox_top;
22 EXPECT_TRUE(FPDFPage_GetMediaBox(page, &mediabox_left, &mediabox_bottom,
23 &mediabox_right, &mediabox_top));
24 EXPECT_EQ(-50, mediabox_left);
25 EXPECT_EQ(-50, mediabox_bottom);
26 EXPECT_EQ(200, mediabox_right);
27 EXPECT_EQ(200, mediabox_top);
28
29 float cropbox_left;
30 float cropbox_bottom;
31 float cropbox_right;
32 float cropbox_top;
33 EXPECT_TRUE(FPDFPage_GetCropBox(page, &cropbox_left, &cropbox_bottom,
34 &cropbox_right, &cropbox_top));
35 EXPECT_EQ(50, cropbox_left);
36 EXPECT_EQ(50, cropbox_bottom);
37 EXPECT_EQ(150, cropbox_right);
38 EXPECT_EQ(150, cropbox_top);
39
40 UnloadPage(page);
41 }
42
43 {
44 FPDF_PAGE page = LoadPage(3);
45 ASSERT_TRUE(page);
46
47 float mediabox_left;
48 float mediabox_bottom;
49 float mediabox_right;
50 float mediabox_top;
51 EXPECT_TRUE(FPDFPage_GetMediaBox(page, &mediabox_left, &mediabox_bottom,
52 &mediabox_right, &mediabox_top));
53 EXPECT_EQ(0, mediabox_left);
54 EXPECT_EQ(0, mediabox_bottom);
55 EXPECT_EQ(200, mediabox_right);
56 EXPECT_EQ(200, mediabox_top);
57
58 float cropbox_left;
59 float cropbox_bottom;
60 float cropbox_right;
61 float cropbox_top;
62 EXPECT_TRUE(FPDFPage_GetCropBox(page, &cropbox_left, &cropbox_bottom,
63 &cropbox_right, &cropbox_top));
64 EXPECT_EQ(150, cropbox_left);
65 EXPECT_EQ(150, cropbox_bottom);
66 EXPECT_EQ(60, cropbox_right);
67 EXPECT_EQ(60, cropbox_top);
68
Lei Zhang76d01fe2018-06-08 18:05:58 +000069 EXPECT_FALSE(FPDFPage_GetCropBox(page, nullptr, &cropbox_bottom,
70 &cropbox_right, &cropbox_top));
71 EXPECT_FALSE(FPDFPage_GetCropBox(page, &cropbox_left, nullptr,
72 &cropbox_right, &cropbox_top));
73 EXPECT_FALSE(FPDFPage_GetCropBox(page, &cropbox_left, &cropbox_bottom,
74 nullptr, &cropbox_top));
75 EXPECT_FALSE(FPDFPage_GetCropBox(page, &cropbox_left, &cropbox_bottom,
76 &cropbox_right, nullptr));
77 EXPECT_FALSE(FPDFPage_GetCropBox(page, nullptr, nullptr, nullptr, nullptr));
78
Lei Zhangd8a8f272018-06-08 18:03:38 +000079 UnloadPage(page);
80 }
81}
82
83TEST_F(FPDFTransformEmbedderTest, NoCropBox) {
84 ASSERT_TRUE(OpenDocument("hello_world.pdf"));
85 ASSERT_EQ(1, FPDF_GetPageCount(document()));
86
87 FPDF_PAGE page = LoadPage(0);
88 ASSERT_TRUE(page);
89
90 float left = -1.0f;
91 float bottom = -2.0f;
92 float right = 3.0f;
93 float top = 0.0f;
94 EXPECT_FALSE(FPDFPage_GetCropBox(page, &left, &bottom, &right, &top));
95 EXPECT_EQ(-1.0f, left);
96 EXPECT_EQ(-2.0f, bottom);
97 EXPECT_EQ(3.0f, right);
98 EXPECT_EQ(0.0f, top);
99
100 UnloadPage(page);
101}