1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
// Copyright 2018 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "public/fpdf_transformpage.h"
#include "testing/embedder_test.h"
class FPDFTransformEmbedderTest : public EmbedderTest {};
TEST_F(FPDFTransformEmbedderTest, GetBoundingBoxes) {
ASSERT_TRUE(OpenDocument("cropped_text.pdf"));
ASSERT_EQ(4, FPDF_GetPageCount(document()));
{
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);
UnloadPage(page);
}
{
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));
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);
UnloadPage(page);
}
}
TEST_F(FPDFTransformEmbedderTest, NoCropBox) {
ASSERT_TRUE(OpenDocument("hello_world.pdf"));
ASSERT_EQ(1, FPDF_GetPageCount(document()));
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);
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);
}
TEST_F(FPDFTransformEmbedderTest, NoArtBox) {
ASSERT_TRUE(OpenDocument("hello_world.pdf"));
ASSERT_EQ(1, FPDF_GetPageCount(document()));
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);
UnloadPage(page);
}
|