Skip to content

Commit f569813

Browse files
committed
Add support of background-clip and background-origin
DEVSIX-2105 Autoported commit. Original commit hash: [9ce424824]
1 parent 083848c commit f569813

File tree

10 files changed

+605
-177
lines changed

10 files changed

+605
-177
lines changed

itext.tests/itext.layout.tests/itext/layout/properties/BackgroundImageTest.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ source product.
4343
using System;
4444
using System.Collections.Generic;
4545
using System.IO;
46+
using System.Reflection;
4647
using iText.IO.Image;
4748
using iText.IO.Util;
4849
using iText.Kernel.Colors;
@@ -82,6 +83,41 @@ public virtual void BackgroundImage() {
8283
BackgroundImageGenericTest("backgroundImage", backgroundImage);
8384
}
8485

86+
[NUnit.Framework.Test]
87+
public virtual void CopyConstructorTest() {
88+
PdfImageXObject xObject = new PdfImageXObject(ImageDataFactory.Create(SOURCE_FOLDER + "itis.jpg"));
89+
iText.Layout.Properties.BackgroundImage image = new BackgroundImage.Builder().SetImage(xObject).Build();
90+
FieldInfo[] imageFields = image.GetType().GetFields();
91+
iText.Layout.Properties.BackgroundImage copyImage = new iText.Layout.Properties.BackgroundImage(image);
92+
FieldInfo[] copyImageFields = copyImage.GetType().GetFields();
93+
NUnit.Framework.Assert.AreEqual(imageFields.Length, copyImageFields.Length);
94+
for (int i = 0; i < imageFields.Length; i++) {
95+
FieldInfo imageField = imageFields[i];
96+
FieldInfo copyImageField = copyImageFields[i];
97+
NUnit.Framework.Assert.AreEqual(imageField, copyImageField);
98+
}
99+
}
100+
101+
[NUnit.Framework.Test]
102+
public virtual void BackgroundImageClipOriginDefaultsTest() {
103+
PdfImageXObject xObject = new PdfImageXObject(ImageDataFactory.Create(SOURCE_FOLDER + "itis.jpg"));
104+
iText.Layout.Properties.BackgroundImage backgroundImage = new BackgroundImage.Builder().SetImage(xObject).
105+
Build();
106+
NUnit.Framework.Assert.AreEqual(BackgroundBox.BORDER_BOX, backgroundImage.GetBackgroundClip());
107+
NUnit.Framework.Assert.AreEqual(BackgroundBox.PADDING_BOX, backgroundImage.GetBackgroundOrigin());
108+
BackgroundImageGenericTest("backgroundImage", backgroundImage);
109+
}
110+
111+
[NUnit.Framework.Test]
112+
public virtual void BackgroundImageClipOriginTest() {
113+
PdfImageXObject xObject = new PdfImageXObject(ImageDataFactory.Create(SOURCE_FOLDER + "itis.jpg"));
114+
iText.Layout.Properties.BackgroundImage backgroundImage = new BackgroundImage.Builder().SetImage(xObject).
115+
SetBackgroundClip(BackgroundBox.CONTENT_BOX).SetBackgroundOrigin(BackgroundBox.CONTENT_BOX).Build();
116+
NUnit.Framework.Assert.AreEqual(BackgroundBox.CONTENT_BOX, backgroundImage.GetBackgroundClip());
117+
NUnit.Framework.Assert.AreEqual(BackgroundBox.CONTENT_BOX, backgroundImage.GetBackgroundOrigin());
118+
BackgroundImageGenericTest("backgroundImage", backgroundImage);
119+
}
120+
85121
[NUnit.Framework.Test]
86122
public virtual void BackgroundMultipleImagesTest() {
87123
IList<iText.Layout.Properties.BackgroundImage> images = JavaUtil.ArraysAsList(new BackgroundImage.Builder(
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2020 iText Group NV
4+
Authors: iText Software.
5+
6+
This program is offered under a commercial and under the AGPL license.
7+
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
8+
9+
AGPL licensing:
10+
This program is free software: you can redistribute it and/or modify
11+
it under the terms of the GNU Affero General Public License as published by
12+
the Free Software Foundation, either version 3 of the License, or
13+
(at your option) any later version.
14+
15+
This program is distributed in the hope that it will be useful,
16+
but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
GNU Affero General Public License for more details.
19+
20+
You should have received a copy of the GNU Affero General Public License
21+
along with this program. If not, see <https://www.gnu.org/licenses/>.
22+
*/
23+
using iText.Kernel.Colors;
24+
using iText.Test;
25+
26+
namespace iText.Layout.Properties {
27+
public class BackgroundUnitTest : ExtendedITextTest {
28+
internal const float EPS = 0.00001f;
29+
30+
[NUnit.Framework.Test]
31+
public virtual void BackgroundConstructorWithClipTest() {
32+
DeviceRgb deviceRgbColor = new DeviceRgb();
33+
float opacity = 10f;
34+
BackgroundBox backgroundClip = BackgroundBox.BORDER_BOX;
35+
Background background = new Background(deviceRgbColor, opacity, backgroundClip);
36+
NUnit.Framework.Assert.AreEqual(deviceRgbColor, background.GetColor());
37+
NUnit.Framework.Assert.AreEqual(opacity, background.GetOpacity(), EPS);
38+
NUnit.Framework.Assert.AreEqual(backgroundClip, background.GetBackgroundClip());
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)