Skip to content

Commit 6c0ffdb

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 Autoported commit. Original commit hash: [87048ca30]
1 parent e081e17 commit 6c0ffdb

File tree

3 files changed

+224
-4
lines changed

3 files changed

+224
-4
lines changed
Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
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+
using iText.Test;
44+
45+
namespace iText.Kernel.Pdf {
46+
public class PdfViewerPreferencesTest : ExtendedITextTest {
47+
[NUnit.Framework.Test]
48+
public virtual void PrintScalingTest() {
49+
PdfViewerPreferences preferences = new PdfViewerPreferences();
50+
PdfDictionary dictionary = preferences.GetPdfObject();
51+
NUnit.Framework.Assert.AreEqual(0, dictionary.Size());
52+
// Set non-appropriate value
53+
preferences.SetPrintScaling(PdfViewerPreferences.PdfViewerPreferencesConstants.PRINT_AREA);
54+
NUnit.Framework.Assert.AreEqual(0, dictionary.Size());
55+
preferences.SetPrintScaling(PdfViewerPreferences.PdfViewerPreferencesConstants.NONE);
56+
NUnit.Framework.Assert.AreEqual(1, dictionary.Size());
57+
NUnit.Framework.Assert.AreEqual(PdfName.None, dictionary.Get(PdfName.PrintScaling));
58+
preferences.SetPrintScaling(PdfViewerPreferences.PdfViewerPreferencesConstants.APP_DEFAULT);
59+
NUnit.Framework.Assert.AreEqual(1, dictionary.Size());
60+
NUnit.Framework.Assert.AreEqual(PdfName.AppDefault, dictionary.Get(PdfName.PrintScaling));
61+
}
62+
63+
[NUnit.Framework.Test]
64+
public virtual void DuplexTest() {
65+
PdfViewerPreferences preferences = new PdfViewerPreferences();
66+
PdfDictionary dictionary = preferences.GetPdfObject();
67+
NUnit.Framework.Assert.AreEqual(0, dictionary.Size());
68+
// Set non-appropriate value
69+
preferences.SetDuplex(PdfViewerPreferences.PdfViewerPreferencesConstants.PRINT_AREA);
70+
NUnit.Framework.Assert.AreEqual(0, dictionary.Size());
71+
preferences.SetDuplex(PdfViewerPreferences.PdfViewerPreferencesConstants.SIMPLEX);
72+
NUnit.Framework.Assert.AreEqual(1, dictionary.Size());
73+
NUnit.Framework.Assert.AreEqual(PdfName.Simplex, dictionary.Get(PdfName.Duplex));
74+
preferences.SetDuplex(PdfViewerPreferences.PdfViewerPreferencesConstants.DUPLEX_FLIP_LONG_EDGE);
75+
NUnit.Framework.Assert.AreEqual(1, dictionary.Size());
76+
NUnit.Framework.Assert.AreEqual(PdfName.DuplexFlipLongEdge, dictionary.Get(PdfName.Duplex));
77+
preferences.SetDuplex(PdfViewerPreferences.PdfViewerPreferencesConstants.DUPLEX_FLIP_SHORT_EDGE);
78+
NUnit.Framework.Assert.AreEqual(1, dictionary.Size());
79+
NUnit.Framework.Assert.AreEqual(PdfName.DuplexFlipShortEdge, dictionary.Get(PdfName.Duplex));
80+
}
81+
82+
[NUnit.Framework.Test]
83+
public virtual void NonFullScreenPageModeTest() {
84+
PdfViewerPreferences preferences = new PdfViewerPreferences();
85+
PdfDictionary dictionary = preferences.GetPdfObject();
86+
NUnit.Framework.Assert.AreEqual(0, dictionary.Size());
87+
// Set non-appropriate value
88+
preferences.SetNonFullScreenPageMode(PdfViewerPreferences.PdfViewerPreferencesConstants.PRINT_AREA);
89+
NUnit.Framework.Assert.AreEqual(0, dictionary.Size());
90+
preferences.SetNonFullScreenPageMode(PdfViewerPreferences.PdfViewerPreferencesConstants.USE_THUMBS);
91+
NUnit.Framework.Assert.AreEqual(1, dictionary.Size());
92+
NUnit.Framework.Assert.AreEqual(PdfName.UseThumbs, dictionary.Get(PdfName.NonFullScreenPageMode));
93+
preferences.SetNonFullScreenPageMode(PdfViewerPreferences.PdfViewerPreferencesConstants.USE_NONE);
94+
NUnit.Framework.Assert.AreEqual(1, dictionary.Size());
95+
NUnit.Framework.Assert.AreEqual(PdfName.UseNone, dictionary.Get(PdfName.NonFullScreenPageMode));
96+
preferences.SetNonFullScreenPageMode(PdfViewerPreferences.PdfViewerPreferencesConstants.USE_OC);
97+
NUnit.Framework.Assert.AreEqual(1, dictionary.Size());
98+
NUnit.Framework.Assert.AreEqual(PdfName.UseOC, dictionary.Get(PdfName.NonFullScreenPageMode));
99+
preferences.SetNonFullScreenPageMode(PdfViewerPreferences.PdfViewerPreferencesConstants.USE_OUTLINES);
100+
NUnit.Framework.Assert.AreEqual(1, dictionary.Size());
101+
NUnit.Framework.Assert.AreEqual(PdfName.UseOutlines, dictionary.Get(PdfName.NonFullScreenPageMode));
102+
}
103+
104+
[NUnit.Framework.Test]
105+
public virtual void DirectionTest() {
106+
PdfViewerPreferences preferences = new PdfViewerPreferences();
107+
PdfDictionary dictionary = preferences.GetPdfObject();
108+
NUnit.Framework.Assert.AreEqual(0, dictionary.Size());
109+
// Set non-appropriate value
110+
preferences.SetDirection(PdfViewerPreferences.PdfViewerPreferencesConstants.PRINT_AREA);
111+
NUnit.Framework.Assert.AreEqual(0, dictionary.Size());
112+
preferences.SetDirection(PdfViewerPreferences.PdfViewerPreferencesConstants.LEFT_TO_RIGHT);
113+
NUnit.Framework.Assert.AreEqual(1, dictionary.Size());
114+
NUnit.Framework.Assert.AreEqual(PdfName.L2R, dictionary.Get(PdfName.Direction));
115+
preferences.SetDirection(PdfViewerPreferences.PdfViewerPreferencesConstants.RIGHT_TO_LEFT);
116+
NUnit.Framework.Assert.AreEqual(1, dictionary.Size());
117+
NUnit.Framework.Assert.AreEqual(PdfName.R2L, dictionary.Get(PdfName.Direction));
118+
}
119+
120+
[NUnit.Framework.Test]
121+
public virtual void ViewAreaTest() {
122+
PdfViewerPreferences preferences = new PdfViewerPreferences();
123+
PdfDictionary dictionary = preferences.GetPdfObject();
124+
NUnit.Framework.Assert.AreEqual(0, dictionary.Size());
125+
// Set non-appropriate value
126+
preferences.SetViewArea(PdfViewerPreferences.PdfViewerPreferencesConstants.PRINT_AREA);
127+
NUnit.Framework.Assert.AreEqual(0, dictionary.Size());
128+
preferences.SetViewArea(PdfViewerPreferences.PdfViewerPreferencesConstants.CROP_BOX);
129+
NUnit.Framework.Assert.AreEqual(1, dictionary.Size());
130+
NUnit.Framework.Assert.AreEqual(PdfName.CropBox, dictionary.Get(PdfName.ViewArea));
131+
preferences.SetViewArea(PdfViewerPreferences.PdfViewerPreferencesConstants.ART_BOX);
132+
NUnit.Framework.Assert.AreEqual(1, dictionary.Size());
133+
NUnit.Framework.Assert.AreEqual(PdfName.ArtBox, dictionary.Get(PdfName.ViewArea));
134+
preferences.SetViewArea(PdfViewerPreferences.PdfViewerPreferencesConstants.BLEED_BOX);
135+
NUnit.Framework.Assert.AreEqual(1, dictionary.Size());
136+
NUnit.Framework.Assert.AreEqual(PdfName.BleedBox, dictionary.Get(PdfName.ViewArea));
137+
preferences.SetViewArea(PdfViewerPreferences.PdfViewerPreferencesConstants.MEDIA_BOX);
138+
NUnit.Framework.Assert.AreEqual(1, dictionary.Size());
139+
NUnit.Framework.Assert.AreEqual(PdfName.MediaBox, dictionary.Get(PdfName.ViewArea));
140+
preferences.SetViewArea(PdfViewerPreferences.PdfViewerPreferencesConstants.TRIM_BOX);
141+
NUnit.Framework.Assert.AreEqual(1, dictionary.Size());
142+
NUnit.Framework.Assert.AreEqual(PdfName.TrimBox, dictionary.Get(PdfName.ViewArea));
143+
}
144+
145+
[NUnit.Framework.Test]
146+
public virtual void ViewClipTest() {
147+
PdfViewerPreferences preferences = new PdfViewerPreferences();
148+
PdfDictionary dictionary = preferences.GetPdfObject();
149+
NUnit.Framework.Assert.AreEqual(0, dictionary.Size());
150+
// Set non-appropriate value
151+
preferences.SetViewClip(PdfViewerPreferences.PdfViewerPreferencesConstants.PRINT_AREA);
152+
NUnit.Framework.Assert.AreEqual(0, dictionary.Size());
153+
preferences.SetViewClip(PdfViewerPreferences.PdfViewerPreferencesConstants.CROP_BOX);
154+
NUnit.Framework.Assert.AreEqual(1, dictionary.Size());
155+
NUnit.Framework.Assert.AreEqual(PdfName.CropBox, dictionary.Get(PdfName.ViewClip));
156+
preferences.SetViewClip(PdfViewerPreferences.PdfViewerPreferencesConstants.ART_BOX);
157+
NUnit.Framework.Assert.AreEqual(1, dictionary.Size());
158+
NUnit.Framework.Assert.AreEqual(PdfName.ArtBox, dictionary.Get(PdfName.ViewClip));
159+
preferences.SetViewClip(PdfViewerPreferences.PdfViewerPreferencesConstants.BLEED_BOX);
160+
NUnit.Framework.Assert.AreEqual(1, dictionary.Size());
161+
NUnit.Framework.Assert.AreEqual(PdfName.BleedBox, dictionary.Get(PdfName.ViewClip));
162+
preferences.SetViewClip(PdfViewerPreferences.PdfViewerPreferencesConstants.MEDIA_BOX);
163+
NUnit.Framework.Assert.AreEqual(1, dictionary.Size());
164+
NUnit.Framework.Assert.AreEqual(PdfName.MediaBox, dictionary.Get(PdfName.ViewClip));
165+
preferences.SetViewClip(PdfViewerPreferences.PdfViewerPreferencesConstants.TRIM_BOX);
166+
NUnit.Framework.Assert.AreEqual(1, dictionary.Size());
167+
NUnit.Framework.Assert.AreEqual(PdfName.TrimBox, dictionary.Get(PdfName.ViewClip));
168+
}
169+
170+
[NUnit.Framework.Test]
171+
public virtual void PrintAreaTest() {
172+
PdfViewerPreferences preferences = new PdfViewerPreferences();
173+
PdfDictionary dictionary = preferences.GetPdfObject();
174+
NUnit.Framework.Assert.AreEqual(0, dictionary.Size());
175+
// Set non-appropriate value
176+
preferences.SetPrintArea(PdfViewerPreferences.PdfViewerPreferencesConstants.PRINT_AREA);
177+
NUnit.Framework.Assert.AreEqual(0, dictionary.Size());
178+
preferences.SetPrintArea(PdfViewerPreferences.PdfViewerPreferencesConstants.CROP_BOX);
179+
NUnit.Framework.Assert.AreEqual(1, dictionary.Size());
180+
NUnit.Framework.Assert.AreEqual(PdfName.CropBox, dictionary.Get(PdfName.PrintArea));
181+
preferences.SetPrintArea(PdfViewerPreferences.PdfViewerPreferencesConstants.ART_BOX);
182+
NUnit.Framework.Assert.AreEqual(1, dictionary.Size());
183+
NUnit.Framework.Assert.AreEqual(PdfName.ArtBox, dictionary.Get(PdfName.PrintArea));
184+
preferences.SetPrintArea(PdfViewerPreferences.PdfViewerPreferencesConstants.BLEED_BOX);
185+
NUnit.Framework.Assert.AreEqual(1, dictionary.Size());
186+
NUnit.Framework.Assert.AreEqual(PdfName.BleedBox, dictionary.Get(PdfName.PrintArea));
187+
preferences.SetPrintArea(PdfViewerPreferences.PdfViewerPreferencesConstants.MEDIA_BOX);
188+
NUnit.Framework.Assert.AreEqual(1, dictionary.Size());
189+
NUnit.Framework.Assert.AreEqual(PdfName.MediaBox, dictionary.Get(PdfName.PrintArea));
190+
preferences.SetPrintArea(PdfViewerPreferences.PdfViewerPreferencesConstants.TRIM_BOX);
191+
NUnit.Framework.Assert.AreEqual(1, dictionary.Size());
192+
NUnit.Framework.Assert.AreEqual(PdfName.TrimBox, dictionary.Get(PdfName.PrintArea));
193+
}
194+
195+
[NUnit.Framework.Test]
196+
public virtual void PrintClipTest() {
197+
PdfViewerPreferences preferences = new PdfViewerPreferences();
198+
PdfDictionary dictionary = preferences.GetPdfObject();
199+
NUnit.Framework.Assert.AreEqual(0, dictionary.Size());
200+
// Set non-appropriate value
201+
preferences.SetPrintClip(PdfViewerPreferences.PdfViewerPreferencesConstants.PRINT_AREA);
202+
NUnit.Framework.Assert.AreEqual(0, dictionary.Size());
203+
preferences.SetPrintClip(PdfViewerPreferences.PdfViewerPreferencesConstants.CROP_BOX);
204+
NUnit.Framework.Assert.AreEqual(1, dictionary.Size());
205+
NUnit.Framework.Assert.AreEqual(PdfName.CropBox, dictionary.Get(PdfName.PrintClip));
206+
preferences.SetPrintClip(PdfViewerPreferences.PdfViewerPreferencesConstants.ART_BOX);
207+
NUnit.Framework.Assert.AreEqual(1, dictionary.Size());
208+
NUnit.Framework.Assert.AreEqual(PdfName.ArtBox, dictionary.Get(PdfName.PrintClip));
209+
preferences.SetPrintClip(PdfViewerPreferences.PdfViewerPreferencesConstants.BLEED_BOX);
210+
NUnit.Framework.Assert.AreEqual(1, dictionary.Size());
211+
NUnit.Framework.Assert.AreEqual(PdfName.BleedBox, dictionary.Get(PdfName.PrintClip));
212+
preferences.SetPrintClip(PdfViewerPreferences.PdfViewerPreferencesConstants.MEDIA_BOX);
213+
NUnit.Framework.Assert.AreEqual(1, dictionary.Size());
214+
NUnit.Framework.Assert.AreEqual(PdfName.MediaBox, dictionary.Get(PdfName.PrintClip));
215+
preferences.SetPrintClip(PdfViewerPreferences.PdfViewerPreferencesConstants.TRIM_BOX);
216+
NUnit.Framework.Assert.AreEqual(1, dictionary.Size());
217+
NUnit.Framework.Assert.AreEqual(PdfName.TrimBox, dictionary.Get(PdfName.PrintClip));
218+
}
219+
}
220+
}

itext/itext.kernel/itext/kernel/pdf/PdfViewerPreferences.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,17 +375,17 @@ private iText.Kernel.Pdf.PdfViewerPreferences SetPageBoundary(PdfViewerPreferenc
375375
}
376376

377377
case PdfViewerPreferences.PdfViewerPreferencesConstants.VIEW_CLIP: {
378-
type = PdfName.ViewArea;
378+
type = PdfName.ViewClip;
379379
break;
380380
}
381381

382382
case PdfViewerPreferences.PdfViewerPreferencesConstants.PRINT_AREA: {
383-
type = PdfName.ViewArea;
383+
type = PdfName.PrintArea;
384384
break;
385385
}
386386

387387
case PdfViewerPreferences.PdfViewerPreferencesConstants.PRINT_CLIP: {
388-
type = PdfName.ViewArea;
388+
type = PdfName.PrintClip;
389389
break;
390390
}
391391

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
b1281a42c0cbeba0db22049a125ab6d52aa22504
1+
87048ca30a421065f3b954328509dc2c0fe6e3eb

0 commit comments

Comments
 (0)