Skip to content

Commit 87048ca

Browse files
ars18wrwiText-CI
authored andcommitted
Update page boundary keys that are used for VIEW_CLIP, PRINT_AREA, PRINT_CLIP constants. Add some PdfViewerPreferences tests.
By mistake we used ViewArea for these cases. The problem has been identified and fixed during the fifth technical-debt session. DEVSIX-3193
1 parent b1281a4 commit 87048ca

File tree

2 files changed

+268
-3
lines changed

2 files changed

+268
-3
lines changed

kernel/src/main/java/com/itextpdf/kernel/pdf/PdfViewerPreferences.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,13 +331,13 @@ private PdfViewerPreferences setPageBoundary(PdfViewerPreferencesConstants viewe
331331
type = PdfName.ViewArea;
332332
break;
333333
case VIEW_CLIP :
334-
type = PdfName.ViewArea;
334+
type = PdfName.ViewClip;
335335
break;
336336
case PRINT_AREA :
337-
type = PdfName.ViewArea;
337+
type = PdfName.PrintArea;
338338
break;
339339
case PRINT_CLIP :
340-
type = PdfName.ViewArea;
340+
type = PdfName.PrintClip;
341341
break;
342342
default:
343343
}
Lines changed: 265 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,265 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2019 iText Group NV
4+
Authors: iText Software.
5+
6+
This program is free software; you can redistribute it and/or modify
7+
it under the terms of the GNU Affero General Public License version 3
8+
as published by the Free Software Foundation with the addition of the
9+
following permission added to Section 15 as permitted in Section 7(a):
10+
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
11+
ITEXT GROUP. ITEXT GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
12+
OF THIRD PARTY RIGHTS
13+
14+
This program is distributed in the hope that it will be useful, but
15+
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16+
or FITNESS FOR A PARTICULAR PURPOSE.
17+
See the GNU Affero General Public License for more details.
18+
You should have received a copy of the GNU Affero General Public License
19+
along with this program; if not, see http://www.gnu.org/licenses or write to
20+
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21+
Boston, MA, 02110-1301 USA, or download the license from the following URL:
22+
http://itextpdf.com/terms-of-use/
23+
24+
The interactive user interfaces in modified source and object code versions
25+
of this program must display Appropriate Legal Notices, as required under
26+
Section 5 of the GNU Affero General Public License.
27+
28+
In accordance with Section 7(b) of the GNU Affero General Public License,
29+
a covered work must retain the producer line in every PDF that is created
30+
or manipulated using iText.
31+
32+
You can be released from the requirements of the license by purchasing
33+
a commercial license. Buying such a license is mandatory as soon as you
34+
develop commercial activities involving the iText software without
35+
disclosing the source code of your own applications.
36+
These activities include: offering paid services to customers as an ASP,
37+
serving PDFs on the fly in a web application, shipping iText with a closed
38+
source product.
39+
40+
For more information, please contact iText Software Corp. at this
41+
42+
*/
43+
package com.itextpdf.kernel.pdf;
44+
45+
import com.itextpdf.test.ExtendedITextTest;
46+
import com.itextpdf.test.annotations.type.IntegrationTest;
47+
import org.junit.Assert;
48+
import org.junit.Test;
49+
import org.junit.experimental.categories.Category;
50+
51+
@Category(IntegrationTest.class)
52+
public class PdfViewerPreferencesTest extends ExtendedITextTest {
53+
54+
@Test
55+
public void printScalingTest() {
56+
PdfViewerPreferences preferences = new PdfViewerPreferences();
57+
PdfDictionary dictionary = preferences.getPdfObject();
58+
Assert.assertEquals(0, dictionary.size());
59+
60+
// Set non-appropriate value
61+
preferences.setPrintScaling(PdfViewerPreferences.PdfViewerPreferencesConstants.PRINT_AREA);
62+
Assert.assertEquals(0, dictionary.size());
63+
64+
preferences.setPrintScaling(PdfViewerPreferences.PdfViewerPreferencesConstants.NONE);
65+
Assert.assertEquals(1, dictionary.size());
66+
Assert.assertEquals(PdfName.None, dictionary.get(PdfName.PrintScaling));
67+
68+
preferences.setPrintScaling(PdfViewerPreferences.PdfViewerPreferencesConstants.APP_DEFAULT);
69+
Assert.assertEquals(1, dictionary.size());
70+
Assert.assertEquals(PdfName.AppDefault, dictionary.get(PdfName.PrintScaling));
71+
}
72+
73+
@Test
74+
public void duplexTest() {
75+
PdfViewerPreferences preferences = new PdfViewerPreferences();
76+
PdfDictionary dictionary = preferences.getPdfObject();
77+
Assert.assertEquals(0, dictionary.size());
78+
79+
// Set non-appropriate value
80+
preferences.setDuplex(PdfViewerPreferences.PdfViewerPreferencesConstants.PRINT_AREA);
81+
Assert.assertEquals(0, dictionary.size());
82+
83+
preferences.setDuplex(PdfViewerPreferences.PdfViewerPreferencesConstants.SIMPLEX);
84+
Assert.assertEquals(1, dictionary.size());
85+
Assert.assertEquals(PdfName.Simplex, dictionary.get(PdfName.Duplex));
86+
87+
preferences.setDuplex(PdfViewerPreferences.PdfViewerPreferencesConstants.DUPLEX_FLIP_LONG_EDGE);
88+
Assert.assertEquals(1, dictionary.size());
89+
Assert.assertEquals(PdfName.DuplexFlipLongEdge, dictionary.get(PdfName.Duplex));
90+
91+
preferences.setDuplex(PdfViewerPreferences.PdfViewerPreferencesConstants.DUPLEX_FLIP_SHORT_EDGE);
92+
Assert.assertEquals(1, dictionary.size());
93+
Assert.assertEquals(PdfName.DuplexFlipShortEdge, dictionary.get(PdfName.Duplex));
94+
}
95+
96+
@Test
97+
public void nonFullScreenPageModeTest() {
98+
PdfViewerPreferences preferences = new PdfViewerPreferences();
99+
PdfDictionary dictionary = preferences.getPdfObject();
100+
Assert.assertEquals(0, dictionary.size());
101+
102+
// Set non-appropriate value
103+
preferences.setNonFullScreenPageMode(PdfViewerPreferences.PdfViewerPreferencesConstants.PRINT_AREA);
104+
Assert.assertEquals(0, dictionary.size());
105+
106+
preferences.setNonFullScreenPageMode(PdfViewerPreferences.PdfViewerPreferencesConstants.USE_THUMBS);
107+
Assert.assertEquals(1, dictionary.size());
108+
Assert.assertEquals(PdfName.UseThumbs, dictionary.get(PdfName.NonFullScreenPageMode));
109+
110+
preferences.setNonFullScreenPageMode(PdfViewerPreferences.PdfViewerPreferencesConstants.USE_NONE);
111+
Assert.assertEquals(1, dictionary.size());
112+
Assert.assertEquals(PdfName.UseNone, dictionary.get(PdfName.NonFullScreenPageMode));
113+
114+
preferences.setNonFullScreenPageMode(PdfViewerPreferences.PdfViewerPreferencesConstants.USE_OC);
115+
Assert.assertEquals(1, dictionary.size());
116+
Assert.assertEquals(PdfName.UseOC, dictionary.get(PdfName.NonFullScreenPageMode));
117+
118+
preferences.setNonFullScreenPageMode(PdfViewerPreferences.PdfViewerPreferencesConstants.USE_OUTLINES);
119+
Assert.assertEquals(1, dictionary.size());
120+
Assert.assertEquals(PdfName.UseOutlines, dictionary.get(PdfName.NonFullScreenPageMode));
121+
}
122+
123+
@Test
124+
public void directionTest() {
125+
PdfViewerPreferences preferences = new PdfViewerPreferences();
126+
PdfDictionary dictionary = preferences.getPdfObject();
127+
Assert.assertEquals(0, dictionary.size());
128+
129+
// Set non-appropriate value
130+
preferences.setDirection(PdfViewerPreferences.PdfViewerPreferencesConstants.PRINT_AREA);
131+
Assert.assertEquals(0, dictionary.size());
132+
133+
preferences.setDirection(PdfViewerPreferences.PdfViewerPreferencesConstants.LEFT_TO_RIGHT);
134+
Assert.assertEquals(1, dictionary.size());
135+
Assert.assertEquals(PdfName.L2R, dictionary.get(PdfName.Direction));
136+
137+
preferences.setDirection(PdfViewerPreferences.PdfViewerPreferencesConstants.RIGHT_TO_LEFT);
138+
Assert.assertEquals(1, dictionary.size());
139+
Assert.assertEquals(PdfName.R2L, dictionary.get(PdfName.Direction));
140+
}
141+
142+
@Test
143+
public void viewAreaTest() {
144+
PdfViewerPreferences preferences = new PdfViewerPreferences();
145+
PdfDictionary dictionary = preferences.getPdfObject();
146+
Assert.assertEquals(0, dictionary.size());
147+
148+
// Set non-appropriate value
149+
preferences.setViewArea(PdfViewerPreferences.PdfViewerPreferencesConstants.PRINT_AREA);
150+
Assert.assertEquals(0, dictionary.size());
151+
152+
preferences.setViewArea(PdfViewerPreferences.PdfViewerPreferencesConstants.CROP_BOX);
153+
Assert.assertEquals(1, dictionary.size());
154+
Assert.assertEquals(PdfName.CropBox, dictionary.get(PdfName.ViewArea));
155+
156+
preferences.setViewArea(PdfViewerPreferences.PdfViewerPreferencesConstants.ART_BOX);
157+
Assert.assertEquals(1, dictionary.size());
158+
Assert.assertEquals(PdfName.ArtBox, dictionary.get(PdfName.ViewArea));
159+
160+
preferences.setViewArea(PdfViewerPreferences.PdfViewerPreferencesConstants.BLEED_BOX);
161+
Assert.assertEquals(1, dictionary.size());
162+
Assert.assertEquals(PdfName.BleedBox, dictionary.get(PdfName.ViewArea));
163+
164+
preferences.setViewArea(PdfViewerPreferences.PdfViewerPreferencesConstants.MEDIA_BOX);
165+
Assert.assertEquals(1, dictionary.size());
166+
Assert.assertEquals(PdfName.MediaBox, dictionary.get(PdfName.ViewArea));
167+
168+
preferences.setViewArea(PdfViewerPreferences.PdfViewerPreferencesConstants.TRIM_BOX);
169+
Assert.assertEquals(1, dictionary.size());
170+
Assert.assertEquals(PdfName.TrimBox, dictionary.get(PdfName.ViewArea));
171+
}
172+
173+
@Test
174+
public void viewClipTest() {
175+
PdfViewerPreferences preferences = new PdfViewerPreferences();
176+
PdfDictionary dictionary = preferences.getPdfObject();
177+
Assert.assertEquals(0, dictionary.size());
178+
179+
// Set non-appropriate value
180+
preferences.setViewClip(PdfViewerPreferences.PdfViewerPreferencesConstants.PRINT_AREA);
181+
Assert.assertEquals(0, dictionary.size());
182+
183+
preferences.setViewClip(PdfViewerPreferences.PdfViewerPreferencesConstants.CROP_BOX);
184+
Assert.assertEquals(1, dictionary.size());
185+
Assert.assertEquals(PdfName.CropBox, dictionary.get(PdfName.ViewClip));
186+
187+
preferences.setViewClip(PdfViewerPreferences.PdfViewerPreferencesConstants.ART_BOX);
188+
Assert.assertEquals(1, dictionary.size());
189+
Assert.assertEquals(PdfName.ArtBox, dictionary.get(PdfName.ViewClip));
190+
191+
preferences.setViewClip(PdfViewerPreferences.PdfViewerPreferencesConstants.BLEED_BOX);
192+
Assert.assertEquals(1, dictionary.size());
193+
Assert.assertEquals(PdfName.BleedBox, dictionary.get(PdfName.ViewClip));
194+
195+
preferences.setViewClip(PdfViewerPreferences.PdfViewerPreferencesConstants.MEDIA_BOX);
196+
Assert.assertEquals(1, dictionary.size());
197+
Assert.assertEquals(PdfName.MediaBox, dictionary.get(PdfName.ViewClip));
198+
199+
preferences.setViewClip(PdfViewerPreferences.PdfViewerPreferencesConstants.TRIM_BOX);
200+
Assert.assertEquals(1, dictionary.size());
201+
Assert.assertEquals(PdfName.TrimBox, dictionary.get(PdfName.ViewClip));
202+
}
203+
204+
@Test
205+
public void printAreaTest() {
206+
PdfViewerPreferences preferences = new PdfViewerPreferences();
207+
PdfDictionary dictionary = preferences.getPdfObject();
208+
Assert.assertEquals(0, dictionary.size());
209+
210+
// Set non-appropriate value
211+
preferences.setPrintArea(PdfViewerPreferences.PdfViewerPreferencesConstants.PRINT_AREA);
212+
Assert.assertEquals(0, dictionary.size());
213+
214+
preferences.setPrintArea(PdfViewerPreferences.PdfViewerPreferencesConstants.CROP_BOX);
215+
Assert.assertEquals(1, dictionary.size());
216+
Assert.assertEquals(PdfName.CropBox, dictionary.get(PdfName.PrintArea));
217+
218+
preferences.setPrintArea(PdfViewerPreferences.PdfViewerPreferencesConstants.ART_BOX);
219+
Assert.assertEquals(1, dictionary.size());
220+
Assert.assertEquals(PdfName.ArtBox, dictionary.get(PdfName.PrintArea));
221+
222+
preferences.setPrintArea(PdfViewerPreferences.PdfViewerPreferencesConstants.BLEED_BOX);
223+
Assert.assertEquals(1, dictionary.size());
224+
Assert.assertEquals(PdfName.BleedBox, dictionary.get(PdfName.PrintArea));
225+
226+
preferences.setPrintArea(PdfViewerPreferences.PdfViewerPreferencesConstants.MEDIA_BOX);
227+
Assert.assertEquals(1, dictionary.size());
228+
Assert.assertEquals(PdfName.MediaBox, dictionary.get(PdfName.PrintArea));
229+
230+
preferences.setPrintArea(PdfViewerPreferences.PdfViewerPreferencesConstants.TRIM_BOX);
231+
Assert.assertEquals(1, dictionary.size());
232+
Assert.assertEquals(PdfName.TrimBox, dictionary.get(PdfName.PrintArea));
233+
}
234+
235+
@Test
236+
public void printClipTest() {
237+
PdfViewerPreferences preferences = new PdfViewerPreferences();
238+
PdfDictionary dictionary = preferences.getPdfObject();
239+
Assert.assertEquals(0, dictionary.size());
240+
241+
// Set non-appropriate value
242+
preferences.setPrintClip(PdfViewerPreferences.PdfViewerPreferencesConstants.PRINT_AREA);
243+
Assert.assertEquals(0, dictionary.size());
244+
245+
preferences.setPrintClip(PdfViewerPreferences.PdfViewerPreferencesConstants.CROP_BOX);
246+
Assert.assertEquals(1, dictionary.size());
247+
Assert.assertEquals(PdfName.CropBox, dictionary.get(PdfName.PrintClip));
248+
249+
preferences.setPrintClip(PdfViewerPreferences.PdfViewerPreferencesConstants.ART_BOX);
250+
Assert.assertEquals(1, dictionary.size());
251+
Assert.assertEquals(PdfName.ArtBox, dictionary.get(PdfName.PrintClip));
252+
253+
preferences.setPrintClip(PdfViewerPreferences.PdfViewerPreferencesConstants.BLEED_BOX);
254+
Assert.assertEquals(1, dictionary.size());
255+
Assert.assertEquals(PdfName.BleedBox, dictionary.get(PdfName.PrintClip));
256+
257+
preferences.setPrintClip(PdfViewerPreferences.PdfViewerPreferencesConstants.MEDIA_BOX);
258+
Assert.assertEquals(1, dictionary.size());
259+
Assert.assertEquals(PdfName.MediaBox, dictionary.get(PdfName.PrintClip));
260+
261+
preferences.setPrintClip(PdfViewerPreferences.PdfViewerPreferencesConstants.TRIM_BOX);
262+
Assert.assertEquals(1, dictionary.size());
263+
Assert.assertEquals(PdfName.TrimBox, dictionary.get(PdfName.PrintClip));
264+
}
265+
}

0 commit comments

Comments
 (0)