Skip to content

Commit 8fd1cf7

Browse files
committed
Merge branch 'release/1.0.1'
2 parents d6cf523 + 471c766 commit 8fd1cf7

File tree

2,510 files changed

+72564
-8530
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,510 files changed

+72564
-8530
lines changed

itext.tests/itext.html2pdf.tests/Properties/AssemblyInfo.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515

1616
[assembly: Guid("ae4e5743-0665-4705-9a33-07ea57cdd269")]
1717

18-
[assembly: AssemblyVersion("1.0.0.2")]
19-
[assembly: AssemblyFileVersion("1.0.0.2")]
18+
[assembly: AssemblyVersion("1.0.1.0")]
19+
[assembly: AssemblyFileVersion("1.0.1.0")]
20+
[assembly: AssemblyInformationalVersion("1.0.1")]
2021

2122
#if !NETSTANDARD1_6
2223
[assembly: NUnit.Framework.Timeout(300000)]

itext.tests/itext.html2pdf.tests/itext/html2pdf/Html2ElementsTest.cs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ source product.
4949
using Versions.Attributes;
5050
using iText.Kernel;
5151
using iText.Test;
52-
using iText.Test.Attributes;
5352

5453
namespace iText.Html2pdf {
5554
public class Html2ElementsTest : ExtendedITextTest {
@@ -117,11 +116,32 @@ public virtual void HtmlToElementsTest04() {
117116

118117
/// <exception cref="System.IO.IOException"/>
119118
[NUnit.Framework.Test]
120-
[LogMessage(iText.Html2pdf.LogMessageConstant.TEXT_WAS_NOT_PROCESSED)]
121119
public virtual void HtmlToElementsTest05() {
122120
String html = "123";
123121
IList<IElement> lst = HtmlConverter.ConvertToElements(html);
124-
NUnit.Framework.Assert.IsTrue(lst.Count == 0);
122+
NUnit.Framework.Assert.IsTrue(lst.Count == 1);
123+
}
124+
125+
/// <exception cref="System.IO.IOException"/>
126+
[NUnit.Framework.Test]
127+
public virtual void HtmlElementsTest06() {
128+
String html = "<html>Lorem<p>Ipsum</p>Dolor<p>Sit</p></html>";
129+
IList<IElement> lst = HtmlConverter.ConvertToElements(html);
130+
NUnit.Framework.Assert.IsTrue(lst.Count == 4);
131+
for (int i = 0; i < lst.Count; i++) {
132+
NUnit.Framework.Assert.IsTrue(lst[i] is Paragraph);
133+
}
134+
}
135+
136+
/// <exception cref="System.IO.IOException"/>
137+
[NUnit.Framework.Test]
138+
public virtual void HtmlElementsTest07() {
139+
String html = "<html>Lorem<span>Dolor</span><p>Ipsum</p><p>Sit</p></html>";
140+
IList<IElement> lst = HtmlConverter.ConvertToElements(html);
141+
NUnit.Framework.Assert.IsTrue(lst.Count == 3);
142+
for (int i = 0; i < lst.Count; i++) {
143+
NUnit.Framework.Assert.IsTrue(lst[i] is Paragraph);
144+
}
125145
}
126146
}
127147
}

itext.tests/itext.html2pdf.tests/itext/html2pdf/Html2PdfTest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public virtual void HelloWorldParagraphTest() {
7979
/// <exception cref="System.Exception"/>
8080
[NUnit.Framework.Test]
8181
public virtual void HelloParagraphTableTest() {
82+
// TODO DEVSIX-1124
8283
HtmlConverter.ConvertToPdf(new FileInfo(sourceFolder + "hello_paragraph_table.html"), new FileInfo(destinationFolder
8384
+ "hello_paragraph_table.pdf"));
8485
System.Console.Out.WriteLine("html: file:///" + UrlUtil.ToNormalizedURI(sourceFolder + "hello_paragraph_table.html"
@@ -115,6 +116,7 @@ public virtual void HelloParagraphJunkSpacesDocumentTest() {
115116
/// <exception cref="System.Exception"/>
116117
[NUnit.Framework.Test]
117118
public virtual void HelloParagraphNestedInTableDocumentTest() {
119+
// TODO DEVSIX-1124
118120
HtmlConverter.ConvertToPdf(new FileInfo(sourceFolder + "hello_paragraph_nested_in_table.html"), new FileInfo
119121
(destinationFolder + "hello_paragraph_nested_in_table.pdf"));
120122
System.Console.Out.WriteLine("html: file:///" + UrlUtil.ToNormalizedURI(sourceFolder + "hello_paragraph_nested_in_table.html"

itext.tests/itext.html2pdf.tests/itext/html2pdf/ResourceResolverTest.cs

Lines changed: 22 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -59,91 +59,50 @@ public class ResourceResolverTest : ExtendedITextTest {
5959

6060
[NUnit.Framework.OneTimeSetUp]
6161
public static void BeforeClass() {
62-
);
6362
CreateOrClearDestinationFolder(destinationFolder);
6463
}
6564

66-
/// <exception cref="System.IO.IOException"/>
67-
/// <exception cref="System.Exception"/>
68-
[NUnit.Framework.Test]
69-
public virtual void ResourceResolverTest01() {
70-
String baseUri = sourceFolder + "resourceResolverTest01.html";
71-
String outPdf = destinationFolder + "resourceResolverTest01.pdf";
72-
String cmpPdf = sourceFolder + "cmp_resourceResolverTest01.pdf";
73-
HtmlConverter.ConvertToPdf(new FileStream(sourceFolder + "resourceResolverTest01.html", FileMode.Open, FileAccess.Read
74-
), new FileStream(outPdf, FileMode.Create), new ConverterProperties().SetBaseUri(baseUri));
75-
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder, "diff01_"
76-
));
77-
}
78-
79-
/// <exception cref="System.IO.IOException"/>
80-
/// <exception cref="System.Exception"/>
81-
[NUnit.Framework.Test]
82-
[LogMessage(iText.Html2pdf.LogMessageConstant.UNABLE_TO_RETRIEVE_IMAGE_WITH_GIVEN_BASE_URI)]
83-
[LogMessage(iText.Html2pdf.LogMessageConstant.UNABLE_TO_PROCESS_EXTERNAL_CSS_FILE)]
84-
public virtual void ResourceResolverTest02() {
85-
String baseUri = "/folderInDiskRoot";
86-
String outPdf = destinationFolder + "resourceResolverTest02.pdf";
87-
String cmpPdf = sourceFolder + "cmp_resourceResolverTest02.pdf";
88-
HtmlConverter.ConvertToPdf(new FileStream(sourceFolder + "resourceResolverTest01.html", FileMode.Open, FileAccess.Read
89-
), new FileStream(outPdf, FileMode.Create), new ConverterProperties().SetBaseUri(baseUri));
90-
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder, "diff02_"
91-
));
92-
}
93-
9465
/// <exception cref="System.IO.IOException"/>
9566
/// <exception cref="System.Exception"/>
9667
[NUnit.Framework.Test]
9768
public virtual void ResourceResolverTest03() {
9869
String baseUri = sourceFolder + "res";
9970
String outPdf = destinationFolder + "resourceResolverTest03.pdf";
10071
String cmpPdf = sourceFolder + "cmp_resourceResolverTest03.pdf";
101-
HtmlConverter.ConvertToPdf(new FileStream(sourceFolder + "resourceResolverTest03.html", FileMode.Open, FileAccess.Read
102-
), new FileStream(outPdf, FileMode.Create), new ConverterProperties().SetBaseUri(baseUri));
103-
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder, "diff03_"
104-
));
105-
}
10672

107-
/// <exception cref="System.IO.IOException"/>
108-
/// <exception cref="System.Exception"/>
109-
[NUnit.Framework.Test]
110-
public virtual void ResourceResolverTest04() {
111-
String invalidBaseUri = TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext.CurrentContext.TestDirectory) + "/resources/itext/html2pdf/ResourceResolverTest/"
112-
+ "res";
113-
String outPdf = destinationFolder + "resourceResolverTest04.pdf";
114-
String cmpPdf = sourceFolder + "cmp_resourceResolverTest04.pdf";
115-
HtmlConverter.ConvertToPdf(new FileStream(sourceFolder + "resourceResolverTest03.html", FileMode.Open, FileAccess.Read
116-
), new FileStream(outPdf, FileMode.Create), new ConverterProperties().SetBaseUri(invalidBaseUri));
117-
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder, "diff04_"
73+
using (FileStream fileInputStream = new FileStream(sourceFolder + "resourceResolverTest03.html", FileMode.Open, FileAccess.Read),
74+
fileOutputStream = new FileStream(outPdf, FileMode.Create)) {
75+
HtmlConverter.ConvertToPdf(fileInputStream, fileOutputStream, new ConverterProperties().SetBaseUri(baseUri));
76+
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder, "diff03_"
11877
));
78+
}
11979
}
120-
80+
12181
/// <exception cref="System.IO.IOException"/>
12282
/// <exception cref="System.Exception"/>
12383
[NUnit.Framework.Test]
124-
public virtual void ResourceResolverTest05() {
125-
// It is important to put a trailing slash in the end: if you specify base URI via absolute URI string,
126-
// you need to follow URI standards, in which a path without trailing slash is referring to a file.
127-
String baseUri = new Uri(TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext.CurrentContext.TestDirectory)).ToExternalForm() + "/resources/itext/html2pdf/ResourceResolverTest/res/";
128-
String outPdf = destinationFolder + "resourceResolverTest05.pdf";
129-
String cmpPdf = sourceFolder + "cmp_resourceResolverTest05.pdf";
130-
HtmlConverter.ConvertToPdf(new FileStream(sourceFolder + "resourceResolverTest03.html", FileMode.Open, FileAccess.Read
131-
), new FileStream(outPdf, FileMode.Create), new ConverterProperties().SetBaseUri(baseUri));
132-
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder, "diff05_"
133-
));
84+
public virtual void ResourceResolverTest07()
85+
{
86+
String outPdf = destinationFolder + "resourceResolverTest07.pdf";
87+
String cmpPdf = sourceFolder + "cmp_resourceResolverTest07.pdf";
88+
HtmlConverter.ConvertToPdf(new FileInfo(sourceFolder + "resourceResolverTest07.html"), new FileInfo(outPdf
89+
));
90+
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder, "diff07_"
91+
));
13492
}
13593

13694
/// <exception cref="System.IO.IOException"/>
13795
/// <exception cref="System.Exception"/>
13896
[NUnit.Framework.Test]
139-
public virtual void ResourceResolverTest06() {
140-
String outPdf = destinationFolder + "resourceResolverTest06.pdf";
141-
String cmpPdf = sourceFolder + "cmp_resourceResolverTest06.pdf";
142-
HtmlConverter.ConvertToPdf(new FileInfo(sourceFolder + "resourceResolverTest01.html"), new FileInfo(outPdf
143-
));
144-
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder, "diff06_"
145-
));
97+
public virtual void ResourceResolverTest08() {
98+
String outPdf = destinationFolder + "resourceResolverTest08.pdf";
99+
String cmpPdf = sourceFolder + "cmp_resourceResolverTest08.pdf";
100+
HtmlConverter.ConvertToPdf(new FileInfo(sourceFolder + "resourceResolverTest08.html"), new FileInfo(outPdf
101+
));
102+
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder, "diff08_"
103+
));
146104
}
105+
147106
// TODO test with absolute http links for resources?
148107
// TODO test with http base URI?
149108
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2017 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+
address: [email protected] */
42+
using System;
43+
using System.IO;
44+
using System.Text.RegularExpressions;
45+
using iText.Html2pdf.Css;
46+
using iText.Html2pdf.Css.Parse;
47+
using iText.IO.Util;
48+
using System.Collections.Generic;
49+
using System.Reflection;
50+
using System.IO;
51+
using Versions.Attributes;
52+
using iText.Kernel;
53+
using iText.Test;
54+
55+
namespace iText.Html2pdf.Attach.Impl {
56+
public class FontFaceSrcTest : ExtendedITextTest {
57+
private static readonly String sourceFolder = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
58+
.CurrentContext.TestDirectory) + "/resources/itext/html2pdf/attacher/impl/FontFaceSrcTest/";
59+
60+
[NUnit.Framework.OneTimeSetUp]
61+
public static void BeforeClass() {
62+
}
63+
64+
/// <exception cref="System.Exception"/>
65+
[NUnit.Framework.Test]
66+
public virtual void SrcPropertyTest() {
67+
String fontSrc = "web-fonts/droid-serif-invalid.";
68+
CssStyleSheet styleSheet = CssStyleSheetParser.Parse(new FileStream(sourceFolder + "srcs.css", FileMode.Open
69+
, FileAccess.Read));
70+
CssFontFaceRule fontFaceRule = (CssFontFaceRule)styleSheet.GetStatements()[0];
71+
CssDeclaration src = fontFaceRule.GetProperties()[0];
72+
NUnit.Framework.Assert.AreEqual("src", src.GetProperty(), "src expected");
73+
String[] sources = iText.IO.Util.StringUtil.Split(src.GetExpression(), ",");
74+
NUnit.Framework.Assert.AreEqual(27, sources.Length, "27 sources expected");
75+
for (int i = 0; i < sources.Length; i++) {
76+
Match m = iText.IO.Util.StringUtil.Match(FontFace.FontFaceSrc.UrlPattern, sources[i]);
77+
NUnit.Framework.Assert.IsTrue(m.Success, "Expression doesn't match pattern: " + sources[i]);
78+
String format = iText.IO.Util.StringUtil.Group(m, FontFace.FontFaceSrc.FormatGroup);
79+
String source2 = MessageFormatUtil.Format("{0}({1}){2}", iText.IO.Util.StringUtil.Group(m, FontFace.FontFaceSrc
80+
.TypeGroup), iText.IO.Util.StringUtil.Group(m, FontFace.FontFaceSrc.UrlGroup), format != null ? MessageFormatUtil
81+
.Format(" format({0})", format) : "");
82+
String url = FontFace.FontFaceSrc.Unquote(iText.IO.Util.StringUtil.Group(m, FontFace.FontFaceSrc.UrlGroup)
83+
);
84+
NUnit.Framework.Assert.IsTrue(url.StartsWith(fontSrc), "Invalid url: " + url);
85+
NUnit.Framework.Assert.IsTrue(format == null || FontFace.FontFaceSrc.ParseFormat(format) != FontFace.FontFormat
86+
.None, "Invalid format: " + format);
87+
NUnit.Framework.Assert.AreEqual(sources[i], source2, "Group check fails: ");
88+
FontFace.FontFaceSrc fontFaceSrc = FontFace.FontFaceSrc.Create(sources[i]);
89+
NUnit.Framework.Assert.IsTrue(fontFaceSrc.src.StartsWith(fontSrc), "Invalid url: " + fontSrc);
90+
String type = "url";
91+
if (fontFaceSrc.isLocal) {
92+
type = "local";
93+
}
94+
NUnit.Framework.Assert.IsTrue(sources[i].StartsWith(type), "Type '" + type + "' expected: " + sources[i]);
95+
switch (fontFaceSrc.format) {
96+
case FontFace.FontFormat.OpenType: {
97+
NUnit.Framework.Assert.IsTrue(sources[i].Contains("opentype"), "Format " + fontFaceSrc.format + " expected: "
98+
+ sources[i]);
99+
break;
100+
}
101+
102+
case FontFace.FontFormat.TrueType: {
103+
NUnit.Framework.Assert.IsTrue(sources[i].Contains("truetype"), "Format " + fontFaceSrc.format + " expected: "
104+
+ sources[i]);
105+
break;
106+
}
107+
108+
case FontFace.FontFormat.SVG: {
109+
NUnit.Framework.Assert.IsTrue(sources[i].Contains("svg"), "Format " + fontFaceSrc.format + " expected: " +
110+
sources[i]);
111+
break;
112+
}
113+
114+
case FontFace.FontFormat.None: {
115+
NUnit.Framework.Assert.IsFalse(sources[i].Contains("format("), "Format " + fontFaceSrc.format + " expected: "
116+
+ sources[i]);
117+
break;
118+
}
119+
}
120+
}
121+
}
122+
}
123+
}

0 commit comments

Comments
 (0)