Agregar archivos de proyecto.

This commit is contained in:
2026-05-27 17:09:59 +02:00
parent 73b30b7de7
commit 03813aff5a
9144 changed files with 4026729 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<uri>
<schemeSettings>
<add name="http" genericUriParserOptions="DontUnescapePathDotsAndSlashes"/>
<add name="https" genericUriParserOptions="DontUnescapePathDotsAndSlashes"/>
</schemeSettings>
</uri>
</configuration>

View File

@@ -0,0 +1,24 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("TSpdf.Svg.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("TSpdf")]
[assembly: AssemblyProduct("TSpdf")]
[assembly: AssemblyCopyright("Copyright (c) 1987-2023 TSpdf")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("ae4e5743-0665-4705-9a33-07ea57cdd269")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0.0")]
#if !NETSTANDARD2_0
[assembly: NUnit.Framework.Timeout(300000)]
#endif

Binary file not shown.

View File

@@ -0,0 +1,65 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<PropertyGroup Label="Globals">
<SccProjectName>SAK</SccProjectName>
<SccProvider>SAK</SccProvider>
<SccAuxPath>SAK</SccAuxPath>
<SccLocalPath>SAK</SccLocalPath>
</PropertyGroup>
<PropertyGroup Label="Configuration">
<SignAssembly>True</SignAssembly>
<DelaySign>False</DelaySign>
<RootNamespace />
</PropertyGroup>
<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net461;net48</TargetFrameworks>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'net461' ">
<OutputType>library</OutputType>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">
<OutputType>Library</OutputType>
<DefineConstants>NETSTANDARD2_0</DefineConstants>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>TSpdf.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<ApplicationIcon />
<OutputTypeEx>library</OutputTypeEx>
<StartupObject />
<AssemblyName>TSpdf.svg.tests</AssemblyName>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="TeamCity.VSTest.TestAdapter" Version="1.0.0" />
<PackageReference Include="NUnit" Version="3.7.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.10.0" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="TSpdf.snk" />
<None Include="packages.config" />
</ItemGroup>
<PropertyGroup>
<NoWarn>1701;1702;1591;1570;1572;1573;1574;1580;1584;1658</NoWarn>
</PropertyGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
<Reference Include="System" />
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\TSpdf\TSpdf.io\TSpdf.io.csproj" />
<ProjectReference Include="..\..\TSpdf\TSpdf.kernel\TSpdf.kernel.csproj" />
<ProjectReference Include="..\..\TSpdf\TSpdf.layout\TSpdf.layout.csproj" />
<ProjectReference Include="..\..\TSpdf\TSpdf.styledxmlparser\TSpdf.styledxmlparser.csproj" />
<ProjectReference Include="..\..\TSpdf\TSpdf.svg\TSpdf.svg.csproj" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<PackageReference Include="Microsoft.NET.Test.Sdk">
<Version>15.0.0</Version>
</PackageReference>
<PackageReference Include="System.Runtime.InteropServices.RuntimeInformation">
<Version>4.3.0</Version>
</PackageReference>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,550 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using System.Collections.Generic;
using System.IO;
using TSpdf.Commons.Utils;
using TSpdf.Kernel.Geom;
using TSpdf.Kernel.Pdf;
using TSpdf.Kernel.Pdf.Canvas;
using TSpdf.Kernel.Pdf.Xobject;
using TSpdf.Kernel.Utils;
using TSpdf.Layout;
using TSpdf.Layout.Element;
using TSpdf.Svg.Dummy.Sdk;
using TSpdf.Svg.Exceptions;
using TSpdf.Svg.Logs;
using TSpdf.Svg.Processors;
using TSpdf.Svg.Processors.Impl;
using TSpdf.Svg.Renderers;
using TSpdf.Svg.Renderers.Impl;
using TSpdf.Test;
using TSpdf.Test.Attributes;
namespace TSpdf.Svg.Converter {
[NUnit.Framework.Category("IntegrationTest")]
public class SvgConverterIntegrationTest : SvgIntegrationTest {
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/converter/SvgConverterTest/";
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/converter/SvgConverterTest/";
private const String ECLIPSESVGSTRING = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" +
"<svg\n" + " xmlns=\"http://www.w3.org/2000/svg\"\n" + " width=\"200pt\"\n" + " height=\"200pt\"\n"
+ " viewBox=\"0 0 100 100\"\n" + " version=\"1.1\">\n" + " <circle\n" + " style=\"opacity:1;fill:none;fill-opacity:1;stroke:#ffcc00;stroke-width:4.13364887;stroke-miterlimit:4;stroke-opacity:1\"\n"
+ " cx=\"35.277779\"\n" + " cy=\"35.277779\"\n" + " r=\"33.210953\" />\n" + " <circle\n"
+ " style=\"opacity:1;fill:#ffcc00;fill-opacity:1;stroke:#ffcc00;stroke-width:1.42177439;stroke-miterlimit:4;stroke-dashoffset:0;stroke-opacity:1\"\n"
+ " id=\"path923\"\n" + " cx=\"35.277779\"\n" + " cy=\"35.277779\"\n" + " r=\"16.928001\" />\n"
+ "</svg>\n";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateDestinationFolder(destinationFolder);
}
[NUnit.Framework.Test]
public virtual void UnusedXObjectIntegrationTest() {
// This method tests that making an XObject does not, in itself, influence the document it's for.
PdfDocument doc1 = new PdfDocument(new PdfWriter(destinationFolder + "unusedXObjectIntegrationTest1.pdf"));
PdfDocument doc2 = new PdfDocument(new PdfWriter(destinationFolder + "unusedXObjectIntegrationTest2.pdf"));
doc1.AddNewPage();
doc2.AddNewPage();
SvgConverter.ConvertToXObject("<svg width='100pt' height='100pt' />", doc1);
doc1.Close();
doc2.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "unusedXObjectIntegrationTest1.pdf"
, destinationFolder + "unusedXObjectIntegrationTest2.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void BasicIntegrationTest() {
String filename = "basicIntegrationTest.pdf";
PdfDocument doc = new PdfDocument(new PdfWriter(destinationFolder + filename));
doc.AddNewPage();
PdfFormXObject form = SvgConverter.ConvertToXObject(ECLIPSESVGSTRING, doc);
new PdfCanvas(doc.GetPage(1)).AddXObjectFittedIntoRectangle(form, new Rectangle(100, 100, 100, 100));
doc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + filename, sourceFolder
+ "cmp_" + filename, destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
[LogMessage(SvgLogMessageConstant.UNMAPPED_TAG)]
public virtual void NonExistingTagIntegrationTest() {
String contents = "<svg width='100pt' height='100pt'> <nonExistingTag/> </svg>";
PdfDocument doc = new PdfDocument(new PdfWriter(new MemoryStream()));
doc.AddNewPage();
SvgConverter.ConvertToXObject(contents, doc);
doc.Close();
}
/// <summary>Convert a SVG file defining all ignored tags currently defined in the project.</summary>
/// <result>There will be no <c>Exception</c> during the process and PDF output is generated.</result>
[NUnit.Framework.Test]
[LogMessage(SvgLogMessageConstant.UNMAPPED_TAG)]
public virtual void ConvertFileWithAllIgnoredTags() {
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "ignored_tags");
}
/// <summary>Convert a SVG file of a chart which contains some currently ignored tags.</summary>
/// <result>There will be no <c>Exception</c> during the process and PDF output is generated.</result>
[NUnit.Framework.Test]
public virtual void ConvertChartWithSomeIgnoredTags() {
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "chart_snippet");
}
[NUnit.Framework.Test]
[LogMessage(SvgLogMessageConstant.UNMAPPED_TAG, Count = 7)]
public virtual void CaseSensitiveTagTest() {
String contents = "<svg width='100pt' height='100pt'>" + "<altGlyph /><altglyph />" + "<feMergeNode /><femergeNode /><feMergenode /><femergenode />"
+ "<foreignObject /><foreignobject />" + "<glyphRef /><glyphref />" + "<linearGradient /><lineargradient />"
+ "<radialGradient /><radialgradient />" + "</svg>";
PdfDocument doc = new PdfDocument(new PdfWriter(new MemoryStream()));
doc.AddNewPage();
SvgConverter.ConvertToXObject(contents, doc);
doc.Close();
}
[NUnit.Framework.Test]
public virtual void PdfFromSvgString() {
PdfWriter writer = new PdfWriter(destinationFolder + "pdfFromSvgString.pdf");
PdfDocument pdfDoc = new PdfDocument(writer);
pdfDoc.AddNewPage();
String svg = "<?xml version=\"1.0\" standalone=\"no\"?>\n" + "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n"
+ " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n" + "<svg width=\"500\" height=\"400\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n"
+ " <rect width=\"500\" height=\"400\" fill=\"none\" stroke=\"black\"/>\n" + " <line x1=\"0\" y1=\"0\" x2=\"20\" y2=\"135\" stroke=\"black\"/>\n"
+ " <circle cx=\"20\" cy=\"135\" r=\"5\" fill=\"none\" stroke=\"black\"/>\n" + " <text x=\"20\" y=\"135\" font-family=\"Verdana\" font-size=\"35\">\n"
+ " Hello world\n" + " </text>\n" + "</svg>";
int pagenr = 1;
SvgConverter.DrawOnDocument(svg, pdfDoc, pagenr);
String output = destinationFolder + "pdfFromSvgString.pdf";
String cmp_file = sourceFolder + "cmp_pdfFromSvgString.pdf";
pdfDoc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(output, cmp_file, destinationFolder, "diff_"
));
}
[NUnit.Framework.Test]
public virtual void FromFile() {
PdfWriter writer = new PdfWriter(destinationFolder + "pdfFromSvgFile.pdf");
PdfDocument pdfDoc = new PdfDocument(writer);
pdfDoc.AddNewPage();
String svg = "eclipse.svg";
String output = destinationFolder + "pdfFromSvgFile.pdf";
String cmp_file = sourceFolder + "cmp_pdfFromSvgFile.pdf";
int pagenr = 1;
FileStream fis = new FileStream(sourceFolder + svg, FileMode.Open, FileAccess.Read);
SvgConverter.DrawOnDocument(fis, pdfDoc, pagenr);
pdfDoc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(output, cmp_file, destinationFolder, "diff_"
));
}
[NUnit.Framework.Test]
public virtual void AddToExistingDoc() {
PdfReader reader = new PdfReader(sourceFolder + "cmp_eclipse.pdf");
PdfWriter writer = new PdfWriter(destinationFolder + "addToExistingDoc.pdf");
PdfDocument pdfDoc = new PdfDocument(reader, writer);
pdfDoc.AddNewPage();
String output = destinationFolder + "addToExistingDoc.pdf";
String cmp_file = sourceFolder + "cmp_addToExistingDoc.pdf";
int pagenr = 1;
FileStream fis = new FileStream(sourceFolder + "minimal.svg", FileMode.Open, FileAccess.Read);
SvgConverter.DrawOnDocument(fis, pdfDoc, pagenr);
pdfDoc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(output, cmp_file, destinationFolder, "diff_"
));
}
[NUnit.Framework.Test]
public virtual void SinglePageHelloWorldTest() {
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "hello_world");
}
[NUnit.Framework.Test]
public virtual void TwoArgTest() {
String name = "hello_world";
FileStream fis = new FileStream(sourceFolder + name + ".svg", FileMode.Open, FileAccess.Read);
FileStream fos = new FileStream(destinationFolder + name + ".pdf", FileMode.Create);
SvgConverter.CreatePdf(fis, fos);
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + name + ".pdf", sourceFolder
+ "cmp_" + name + ".pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void DrawOnSpecifiedPositionX() {
String name = "eclipse";
int x = 50;
int y = 0;
String destName = MessageFormatUtil.Format("{0}_{1}_{2}", name, x, y);
FileStream fis = new FileStream(sourceFolder + name + ".svg", FileMode.Open, FileAccess.Read);
DrawOnSpecifiedPositionDocument(fis, destinationFolder + destName + ".pdf", x, y);
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + destName + ".pdf", sourceFolder
+ "cmp_" + destName + ".pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void DrawOnSpecifiedPositionY() {
String name = "eclipse";
int x = 0;
int y = 100;
String destName = MessageFormatUtil.Format("{0}_{1}_{2}", name, x, y);
FileStream fis = new FileStream(sourceFolder + name + ".svg", FileMode.Open, FileAccess.Read);
DrawOnSpecifiedPositionDocument(fis, destinationFolder + destName + ".pdf", x, y);
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + destName + ".pdf", sourceFolder
+ "cmp_" + destName + ".pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void DrawOnSpecifiedPositionXY() {
String name = "eclipse";
int x = 50;
int y = 100;
String destName = MessageFormatUtil.Format("{0}_{1}_{2}", name, x, y);
FileStream fis = new FileStream(sourceFolder + name + ".svg", FileMode.Open, FileAccess.Read);
DrawOnSpecifiedPositionDocument(fis, destinationFolder + destName + ".pdf", x, y);
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + destName + ".pdf", sourceFolder
+ "cmp_" + destName + ".pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void DrawOnSpecifiedPositionNegativeX() {
String name = "eclipse";
int x = -50;
int y = 0;
String destName = MessageFormatUtil.Format("{0}_{1}_{2}", name, x, y);
FileStream fis = new FileStream(sourceFolder + name + ".svg", FileMode.Open, FileAccess.Read);
DrawOnSpecifiedPositionDocument(fis, destinationFolder + destName + ".pdf", x, y);
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + destName + ".pdf", sourceFolder
+ "cmp_" + destName + ".pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void DrawOnSpecifiedPositionNegativeY() {
String name = "eclipse";
int x = 0;
int y = -100;
String destName = MessageFormatUtil.Format("{0}_{1}_{2}", name, x, y);
FileStream fis = new FileStream(sourceFolder + name + ".svg", FileMode.Open, FileAccess.Read);
DrawOnSpecifiedPositionDocument(fis, destinationFolder + destName + ".pdf", x, y);
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + destName + ".pdf", sourceFolder
+ "cmp_" + destName + ".pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void DrawOnSpecifiedPositionNegativeXY() {
String name = "eclipse";
int x = -50;
int y = -100;
String destName = MessageFormatUtil.Format("{0}_{1}_{2}", name, x, y);
FileStream fis = new FileStream(sourceFolder + name + ".svg", FileMode.Open, FileAccess.Read);
DrawOnSpecifiedPositionDocument(fis, destinationFolder + destName + ".pdf", x, y);
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + destName + ".pdf", sourceFolder
+ "cmp_" + destName + ".pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void DrawOnSpecifiedPositionPartialOnPage() {
String name = "eclipse";
int x = -50;
int y = -50;
String destName = MessageFormatUtil.Format("{0}_{1}_{2}", name, x, y);
FileStream fis = new FileStream(sourceFolder + name + ".svg", FileMode.Open, FileAccess.Read);
DrawOnSpecifiedPositionDocument(fis, destinationFolder + destName + ".pdf", x, y);
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + destName + ".pdf", sourceFolder
+ "cmp_" + destName + ".pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void ConvertToXObjectStringPdfDocumentConverterProps() {
String name = "eclipse";
String destName = "CTXO_" + name + "_StringDocProps";
PdfDocument doc = new PdfDocument(new PdfWriter(destinationFolder + destName + ".pdf"));
PdfPage page = doc.AddNewPage();
ISvgConverterProperties props = new SvgConverterProperties();
PdfXObject xObj = SvgConverter.ConvertToXObject(ECLIPSESVGSTRING, doc, props);
PdfCanvas canv = new PdfCanvas(page);
canv.AddXObjectAt(xObj, 0, 0);
doc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + destName + ".pdf", sourceFolder
+ "cmp_" + destName + ".pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void ConvertToXObjectStreamPdfDocumentConverterProps() {
String name = "eclipse";
String destName = "CTXO_" + name + "_StreamDocProps";
FileStream fis = new FileStream(sourceFolder + name + ".svg", FileMode.Open, FileAccess.Read);
PdfDocument doc = new PdfDocument(new PdfWriter(destinationFolder + destName + ".pdf"));
PdfPage page = doc.AddNewPage();
ISvgConverterProperties props = new SvgConverterProperties();
PdfXObject xObj = SvgConverter.ConvertToXObject(fis, doc, props);
PdfCanvas canv = new PdfCanvas(page);
canv.AddXObjectAt(xObj, 0, 0);
doc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + destName + ".pdf", sourceFolder
+ "cmp_" + destName + ".pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void ConvertToImageStreamDocument() {
String name = "eclipse";
FileStream fis = new FileStream(sourceFolder + name + ".svg", FileMode.Open, FileAccess.Read);
String destName = "CTI_" + name + "_StreamDocument";
FileStream fos = new FileStream(destinationFolder + destName + ".pdf", FileMode.Create);
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(fos, new WriterProperties().SetCompressionLevel(0)
));
Image image = SvgConverter.ConvertToImage(fis, pdfDocument);
Document doc = new Document(pdfDocument);
doc.Add(image);
doc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + destName + ".pdf", sourceFolder
+ "cmp_" + name + ".pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void ConvertToImageStreamDocumentConverterProperties() {
String name = "eclipse";
FileStream fis = new FileStream(sourceFolder + name + ".svg", FileMode.Open, FileAccess.Read);
String destName = "CTI_" + name + "_StreamDocumentProps";
FileStream fos = new FileStream(destinationFolder + destName + ".pdf", FileMode.Create);
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(fos, new WriterProperties().SetCompressionLevel(0)
));
ISvgConverterProperties props = new SvgConverterProperties();
Image image = SvgConverter.ConvertToImage(fis, pdfDocument, props);
Document doc = new Document(pdfDocument);
doc.Add(image);
doc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + destName + ".pdf", sourceFolder
+ "cmp_" + name + ".pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void DrawOnPageStringPage() {
String name = "eclipse";
String destName = "DOP_" + name + "_StringPdfPage";
PdfDocument doc = new PdfDocument(new PdfWriter(destinationFolder + destName + ".pdf"));
PdfPage page = doc.AddNewPage();
SvgConverter.DrawOnPage(ECLIPSESVGSTRING, page);
doc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + destName + ".pdf", sourceFolder
+ "cmp_" + destName + ".pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void DrawOnPageStringPageConverterProps() {
String name = "eclipse";
String destName = "DOP_" + name + "_StringPdfPageConverterProps";
PdfDocument doc = new PdfDocument(new PdfWriter(destinationFolder + destName + ".pdf"));
PdfPage page = doc.AddNewPage();
ISvgConverterProperties props = new SvgConverterProperties();
SvgConverter.DrawOnPage(ECLIPSESVGSTRING, page, props);
doc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + destName + ".pdf", sourceFolder
+ "cmp_" + destName + ".pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void DrawOnPageStreamPage() {
String name = "eclipse";
String destName = "DOP_" + name + "_StreamPdfPage";
FileStream fis = new FileStream(sourceFolder + name + ".svg", FileMode.Open, FileAccess.Read);
PdfDocument doc = new PdfDocument(new PdfWriter(destinationFolder + destName + ".pdf"));
PdfPage page = doc.AddNewPage();
SvgConverter.DrawOnPage(fis, page);
doc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + destName + ".pdf", sourceFolder
+ "cmp_" + destName + ".pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void DrawOnPageStreamPageConverterProperties() {
String name = "eclipse";
String destName = "DOP_" + name + "_StreamPdfPageConverterProperties";
FileStream fis = new FileStream(sourceFolder + name + ".svg", FileMode.Open, FileAccess.Read);
PdfDocument doc = new PdfDocument(new PdfWriter(destinationFolder + destName + ".pdf"));
PdfPage page = doc.AddNewPage();
ISvgConverterProperties props = new SvgConverterProperties();
SvgConverter.DrawOnPage(fis, page, props);
doc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + destName + ".pdf", sourceFolder
+ "cmp_" + destName + ".pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void DrawOnDocumentStringPdfDocumentInt() {
String name = "eclipse";
String destName = "DOD_" + name + "_StringPdfDocumentInt";
PdfDocument doc = new PdfDocument(new PdfWriter(destinationFolder + destName + ".pdf"));
doc.AddNewPage();
SvgConverter.DrawOnDocument(ECLIPSESVGSTRING, doc, 1);
doc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + destName + ".pdf", sourceFolder
+ "cmp_" + destName + ".pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void DrawOnDocumentStringPdfDocumentIntConverterProperties() {
String name = "eclipse";
String destName = "DOD_" + name + "_StringPdfDocumentIntProps";
FileStream fis = new FileStream(sourceFolder + name + ".svg", FileMode.Open, FileAccess.Read);
PdfDocument doc = new PdfDocument(new PdfWriter(destinationFolder + destName + ".pdf"));
doc.AddNewPage();
ISvgConverterProperties props = new SvgConverterProperties();
SvgConverter.DrawOnDocument(fis, doc, 1, props);
doc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + destName + ".pdf", sourceFolder
+ "cmp_" + destName + ".pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void DrawOnDocumentStreamPdfDocumentIntConverterProperties() {
String name = "eclipse";
String destName = "DOD_" + name + "_StreamPdfDocumentIntProps";
PdfDocument doc = new PdfDocument(new PdfWriter(destinationFolder + destName + ".pdf"));
doc.AddNewPage();
ISvgConverterProperties props = new SvgConverterProperties();
SvgConverter.DrawOnDocument(ECLIPSESVGSTRING, doc, 1, props);
doc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + destName + ".pdf", sourceFolder
+ "cmp_" + destName + ".pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void DrawOnCanvasStringPdfCanvasConverter() {
String name = "eclipse";
String destName = "DOC_" + name + "_StringCanvas";
PdfDocument doc = new PdfDocument(new PdfWriter(destinationFolder + destName + ".pdf"));
PdfCanvas canvas = new PdfCanvas(doc.AddNewPage());
SvgConverter.DrawOnCanvas(ECLIPSESVGSTRING, canvas);
doc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + destName + ".pdf", sourceFolder
+ "cmp_" + destName + ".pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void DrawOnCanvasStringPdfCanvasConverterProps() {
String name = "eclipse";
String destName = "DOC_" + name + "_StringCanvasProps";
PdfDocument doc = new PdfDocument(new PdfWriter(destinationFolder + destName + ".pdf"));
PdfCanvas canvas = new PdfCanvas(doc.AddNewPage());
ISvgConverterProperties props = new SvgConverterProperties();
SvgConverter.DrawOnCanvas(ECLIPSESVGSTRING, canvas, props);
doc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + destName + ".pdf", sourceFolder
+ "cmp_" + destName + ".pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void DrawOnCanvasStreamPdfCanvas() {
String name = "eclipse";
String destName = "DOC_" + name + "_StreamCanvas";
PdfDocument doc = new PdfDocument(new PdfWriter(destinationFolder + destName + ".pdf"));
FileStream fis = new FileStream(sourceFolder + name + ".svg", FileMode.Open, FileAccess.Read);
PdfCanvas canvas = new PdfCanvas(doc.AddNewPage());
SvgConverter.DrawOnCanvas(fis, canvas);
doc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + destName + ".pdf", sourceFolder
+ "cmp_" + destName + ".pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void DrawOnCanvasStreamPdfCanvasConverterProps() {
String name = "eclipse";
String destName = "DOC_" + name + "_StreamCanvasProps";
PdfDocument doc = new PdfDocument(new PdfWriter(destinationFolder + destName + ".pdf"));
FileStream fis = new FileStream(sourceFolder + name + ".svg", FileMode.Open, FileAccess.Read);
PdfCanvas canvas = new PdfCanvas(doc.AddNewPage());
ISvgConverterProperties props = new SvgConverterProperties();
SvgConverter.DrawOnCanvas(fis, canvas, props);
doc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + destName + ".pdf", sourceFolder
+ "cmp_" + destName + ".pdf", destinationFolder, "diff_"));
}
private static void DrawOnSpecifiedPositionDocument(Stream svg, String dest, int x, int y) {
PdfDocument document = new PdfDocument(new PdfWriter(dest, new WriterProperties().SetCompressionLevel(0)));
document.AddNewPage();
SvgConverter.DrawOnDocument(svg, document, 1, x, y);
document.Close();
}
[NUnit.Framework.Test]
public virtual void ParseAndProcessSuccessTest() {
IDictionary<String, ISvgNodeRenderer> map = new Dictionary<String, ISvgNodeRenderer>();
RectangleSvgNodeRenderer rect = new RectangleSvgNodeRenderer();
rect.SetAttribute("fill", "none");
rect.SetAttribute("stroke", "black");
rect.SetAttribute("width", "500");
rect.SetAttribute("height", "400");
ISvgNodeRenderer root = new SvgTagSvgNodeRenderer();
root.SetAttribute("xmlns", "http://www.w3.org/2000/svg");
root.SetAttribute("version", "1.1");
root.SetAttribute("width", "500");
root.SetAttribute("height", "400");
root.SetAttribute("font-size", "12pt");
ISvgProcessorResult expected = new SvgProcessorResult(map, root, new SvgProcessorContext(new SvgConverterProperties
()));
String name = "minimal";
using (FileStream fis = new FileStream(sourceFolder + name + ".svg", FileMode.Open, FileAccess.Read)) {
ISvgProcessorResult actual = SvgConverter.ParseAndProcess(fis);
NUnit.Framework.Assert.AreEqual(expected.GetRootRenderer().GetAttributeMapCopy(), actual.GetRootRenderer()
.GetAttributeMapCopy());
}
}
[NUnit.Framework.Test]
public virtual void ParseAndProcessIOExceptionTest() {
Stream fis = new ExceptionInputStream();
NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => SvgConverter.ParseAndProcess(fis));
}
[NUnit.Framework.Test]
public virtual void ParseDoubleValues() {
// Before the changes have been implemented this test had been produced different result in Java and .NET.
// So this test checks if there are any differences
ConvertAndCompare(sourceFolder, destinationFolder, "svgStackOver");
}
}
}

View File

@@ -0,0 +1,312 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using System.IO;
using TSpdf.Kernel.Pdf;
using TSpdf.Kernel.Pdf.Canvas;
using TSpdf.StyledXmlParser.Node;
using TSpdf.StyledXmlParser.Node.Impl.Jsoup.Node;
using TSpdf.Svg.Exceptions;
using TSpdf.Svg.Renderers;
using TSpdf.Test;
namespace TSpdf.Svg.Converter {
/// <summary>
/// These tests will make sure that a NullPointerException is never thrown: if a
/// null check is made, an SVG-specific exception should tell the user where the
/// null check failed.
/// </summary>
/// <remarks>
/// These tests will make sure that a NullPointerException is never thrown: if a
/// null check is made, an SVG-specific exception should tell the user where the
/// null check failed.
/// If the (optional)
/// <see cref="TSpdf.Svg.Processors.ISvgConverterProperties"/>
/// parameter is null, this
/// should NOT throw an exception as this is caught in the library.
/// </remarks>
[NUnit.Framework.Category("UnitTest")]
public class SvgConverterUnitNullTest : ExtendedTSpdfTest {
// we cannot easily mock the PdfDocument, so we make do with as close to unit testing as we can
private PdfDocument doc;
private readonly String content = "<svg width=\"10\" height=\"10\"/>";
private Stream @is;
[NUnit.Framework.SetUp]
public virtual void Setup() {
doc = new PdfDocument(new PdfWriter(new MemoryStream()));
doc.AddNewPage();
@is = new MemoryStream(content.GetBytes(System.Text.Encoding.UTF8));
}
[NUnit.Framework.TearDown]
public virtual void Teardown() {
doc.Close();
}
[NUnit.Framework.Test]
public virtual void DrawOnDocumentStringNullTest() {
NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => SvgConverter.DrawOnDocument((String)null
, doc, 1));
}
[NUnit.Framework.Test]
public virtual void DrawOnDocumentInputStreamNullTest() {
NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => SvgConverter.DrawOnDocument((Stream)null
, doc, 1));
}
[NUnit.Framework.Test]
public virtual void DrawOnDocumentDocNullTest() {
NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => SvgConverter.DrawOnDocument(@is, null,
1));
}
[NUnit.Framework.Test]
public virtual void DrawOnDocumentAllNullTest() {
NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => SvgConverter.DrawOnDocument((String)null
, null, 1));
}
[NUnit.Framework.Test]
public virtual void DrawOnDocumentAllNullTest2() {
NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => SvgConverter.DrawOnDocument((Stream)null
, null, 1));
}
[NUnit.Framework.Test]
public virtual void DrawOnDocumentStringPropsNullTest() {
SvgConverter.DrawOnDocument(content, doc, 1, null);
}
[NUnit.Framework.Test]
public virtual void DrawOnDocumentInputStreamPropsNullTest() {
SvgConverter.DrawOnDocument(@is, doc, 1, null);
}
[NUnit.Framework.Test]
public virtual void DrawOnPageStringNullTest() {
PdfPage page = doc.GetFirstPage();
NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => SvgConverter.DrawOnPage((String)null, page
));
}
[NUnit.Framework.Test]
public virtual void DrawOnPageInputStreamNullTest() {
PdfPage page = doc.GetFirstPage();
NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => SvgConverter.DrawOnPage((Stream)null, page
));
}
[NUnit.Framework.Test]
public virtual void DrawOnPageDocNullTest() {
NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => SvgConverter.DrawOnPage(@is, null));
}
[NUnit.Framework.Test]
public virtual void DrawOnPageAllNullTest() {
NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => SvgConverter.DrawOnPage((String)null, null
));
}
[NUnit.Framework.Test]
public virtual void DrawOnPageAllNullTest2() {
NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => SvgConverter.DrawOnPage((Stream)null, null
));
}
[NUnit.Framework.Test]
public virtual void DrawOnPageStringPropsNullTest() {
PdfPage page = doc.GetFirstPage();
SvgConverter.DrawOnPage(content, page, null);
}
[NUnit.Framework.Test]
public virtual void DrawOnPageInputStreamPropsNullTest() {
PdfPage page = doc.GetFirstPage();
SvgConverter.DrawOnPage(@is, page, null);
}
[NUnit.Framework.Test]
public virtual void DrawOnCanvasStringNullTest() {
PdfCanvas canvas = new PdfCanvas(doc.GetLastPage());
NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => SvgConverter.DrawOnDocument((String)null
, doc, 1));
}
[NUnit.Framework.Test]
public virtual void DrawOnCanvasInputStreamNullTest() {
PdfCanvas canvas = new PdfCanvas(doc.GetLastPage());
NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => SvgConverter.DrawOnCanvas((Stream)null,
canvas));
}
[NUnit.Framework.Test]
public virtual void DrawOnCanvasDocNullTest() {
NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => SvgConverter.DrawOnCanvas(@is, null));
}
[NUnit.Framework.Test]
public virtual void DrawOnCanvasAllNullTest() {
NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => SvgConverter.DrawOnCanvas((String)null,
null));
}
[NUnit.Framework.Test]
public virtual void DrawOnCanvasAllNullTest2() {
NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => SvgConverter.DrawOnCanvas((Stream)null,
null));
}
[NUnit.Framework.Test]
public virtual void DrawOnCanvasStringPropsNullTest() {
PdfCanvas canvas = new PdfCanvas(doc.GetLastPage());
SvgConverter.DrawOnCanvas(content, canvas, null);
}
[NUnit.Framework.Test]
public virtual void DrawOnCanvasInputStreamPropsNullTest() {
PdfCanvas canvas = new PdfCanvas(doc.GetLastPage());
SvgConverter.DrawOnCanvas(@is, canvas, null);
}
[NUnit.Framework.Test]
public virtual void ConvertToXObjectStringNullTest() {
NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => SvgConverter.ConvertToXObject((String)null
, doc));
}
[NUnit.Framework.Test]
public virtual void ConvertToXObjectInputStreamNullTest() {
NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => SvgConverter.ConvertToXObject((Stream)null
, doc));
}
[NUnit.Framework.Test]
public virtual void ConvertToXObjectRendererNullTest() {
NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => SvgConverter.ConvertToXObject((ISvgNodeRenderer
)null, doc));
}
[NUnit.Framework.Test]
public virtual void ConvertToXObjectDocWithStringNullTest() {
NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => SvgConverter.ConvertToXObject(@is, null
));
}
[NUnit.Framework.Test]
public virtual void ConvertToXObjectDocWithStreamNullTest() {
NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => SvgConverter.ConvertToXObject(@is, null
));
}
[NUnit.Framework.Test]
public virtual void ConvertToXObjectDocWithRendererNullTest() {
ISvgNodeRenderer renderer = SvgConverter.Process(SvgConverter.Parse(@is), null).GetRootRenderer();
NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => SvgConverter.ConvertToXObject(renderer,
null));
}
[NUnit.Framework.Test]
public virtual void ConvertToXObjectAllWithStringNullTest() {
NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => SvgConverter.ConvertToXObject((String)null
, null));
}
[NUnit.Framework.Test]
public virtual void ConvertToXObjectAllWithStreamNullTest() {
NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => SvgConverter.ConvertToXObject((Stream)null
, null));
}
[NUnit.Framework.Test]
public virtual void ConvertToXObjectAllWithRendererNullTest() {
NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => SvgConverter.ConvertToXObject((ISvgNodeRenderer
)null, null));
}
[NUnit.Framework.Test]
public virtual void ConvertToXObjectStringPropsNullTest() {
SvgConverter.ConvertToXObject(content, doc, null);
}
[NUnit.Framework.Test]
public virtual void ConvertToXObjectInputStreamPropsNullTest() {
SvgConverter.ConvertToXObject(@is, doc, null);
}
[NUnit.Framework.Test]
public virtual void ParseStringNullTest() {
NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => SvgConverter.Parse((String)null));
}
[NUnit.Framework.Test]
public virtual void ParseStreamNullTest() {
NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => SvgConverter.Parse((Stream)null));
}
[NUnit.Framework.Test]
public virtual void ParseStreamPropsNullTest() {
SvgConverter.Parse(@is, null);
}
[NUnit.Framework.Test]
public virtual void ParseStringPropsNullTest() {
NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => SvgConverter.Parse(null, null));
}
[NUnit.Framework.Test]
public virtual void ProcessAllNullTest() {
NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => SvgConverter.Process(null, null));
}
[NUnit.Framework.Test]
public virtual void ProcessPropsNullTest() {
INode svg = new JsoupElementNode(new TSpdf.StyledXmlParser.Jsoup.Nodes.Element(TSpdf.StyledXmlParser.Jsoup.Parser.Tag
.ValueOf("svg"), ""));
SvgConverter.Process(svg, null);
}
}
}

View File

@@ -0,0 +1,364 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using System.Collections.Generic;
using System.IO;
using TSpdf.Kernel.Exceptions;
using TSpdf.Kernel.Pdf;
using TSpdf.Kernel.Pdf.Canvas;
using TSpdf.Kernel.Pdf.Xobject;
using TSpdf.Layout.Font;
using TSpdf.StyledXmlParser.Node;
using TSpdf.StyledXmlParser.Node.Impl.Jsoup.Node;
using TSpdf.StyledXmlParser.Resolver.Resource;
using TSpdf.Svg.Dummy.Processors.Impl;
using TSpdf.Svg.Dummy.Renderers.Impl;
using TSpdf.Svg.Exceptions;
using TSpdf.Svg.Processors;
using TSpdf.Svg.Processors.Impl;
using TSpdf.Svg.Renderers;
using TSpdf.Svg.Renderers.Impl;
using TSpdf.Test;
namespace TSpdf.Svg.Converter {
[NUnit.Framework.Category("UnitTest")]
public class SvgConverterUnitTest : ExtendedTSpdfTest {
// we cannot easily mock the PdfDocument, so we make do with as close to unit testing as we can
private PdfDocument doc;
private readonly String content = "<svg width=\"10\" height=\"10\"/>";
private Stream @is;
[NUnit.Framework.SetUp]
public virtual void Setup() {
doc = new PdfDocument(new PdfWriter(new MemoryStream()));
doc.AddNewPage();
@is = new MemoryStream(content.GetBytes(System.Text.Encoding.UTF8));
}
[NUnit.Framework.TearDown]
public virtual void Teardown() {
doc.Close();
}
private void TestResourceCreated(PdfDocument doc, int pageNo) {
PdfResources res = doc.GetPage(pageNo).GetResources();
NUnit.Framework.Assert.AreEqual(1, res.GetPdfObject().Size());
foreach (PdfName name in res.GetResourceNames()) {
PdfObject obj = res.GetResourceObject(PdfName.XObject, name);
NUnit.Framework.Assert.IsTrue(obj.IsStream());
}
}
[NUnit.Framework.Test]
public virtual void DrawStringOnDocumentCreatesResourceTest() {
SvgConverter.DrawOnDocument(content, doc, 1);
TestResourceCreated(doc, 1);
}
[NUnit.Framework.Test]
public virtual void DrawStringOnDocumentWithPropsCreatesResourceTest() {
SvgConverter.DrawOnDocument(content, doc, 1, new DummySvgConverterProperties());
TestResourceCreated(doc, 1);
}
[NUnit.Framework.Test]
public virtual void DrawStreamOnDocumentCreatesResourceTest() {
SvgConverter.DrawOnDocument(@is, doc, 1);
TestResourceCreated(doc, 1);
}
[NUnit.Framework.Test]
public virtual void DrawStreamOnDocumentWithPropsCreatesResourceTest() {
SvgConverter.DrawOnDocument(@is, doc, 1, new DummySvgConverterProperties());
TestResourceCreated(doc, 1);
}
[NUnit.Framework.Test]
public virtual void DrawStringOnPageCreatesResourceTest() {
PdfPage page = doc.AddNewPage();
SvgConverter.DrawOnPage(content, page);
NUnit.Framework.Assert.AreEqual(0, doc.GetFirstPage().GetResources().GetPdfObject().Size());
TestResourceCreated(doc, 2);
}
[NUnit.Framework.Test]
public virtual void DrawStringOnPageWithPropsCreatesResourceTest() {
PdfPage page = doc.AddNewPage();
SvgConverter.DrawOnPage(content, page, new DummySvgConverterProperties());
NUnit.Framework.Assert.AreEqual(0, doc.GetFirstPage().GetResources().GetPdfObject().Size());
TestResourceCreated(doc, 2);
}
[NUnit.Framework.Test]
public virtual void DrawStreamOnPageCreatesResourceTest() {
PdfPage page = doc.AddNewPage();
SvgConverter.DrawOnPage(@is, page);
NUnit.Framework.Assert.AreEqual(0, doc.GetFirstPage().GetResources().GetPdfObject().Size());
TestResourceCreated(doc, 2);
}
[NUnit.Framework.Test]
public virtual void DrawStreamOnPageWithPropsCreatesResourceTest() {
PdfPage page = doc.AddNewPage();
SvgConverter.DrawOnPage(@is, page, new DummySvgConverterProperties());
NUnit.Framework.Assert.AreEqual(0, doc.GetFirstPage().GetResources().GetPdfObject().Size());
TestResourceCreated(doc, 2);
}
[NUnit.Framework.Test]
public virtual void DrawStringOnCanvasCreatesResourceTest() {
PdfPage page = doc.AddNewPage();
PdfCanvas canvas = new PdfCanvas(page);
SvgConverter.DrawOnCanvas(content, canvas);
NUnit.Framework.Assert.AreEqual(0, doc.GetFirstPage().GetResources().GetPdfObject().Size());
TestResourceCreated(doc, 2);
}
[NUnit.Framework.Test]
public virtual void DrawStringOnCanvasWithPropsCreatesResourceTest() {
PdfPage page = doc.AddNewPage();
PdfCanvas canvas = new PdfCanvas(page);
SvgConverter.DrawOnCanvas(content, canvas, new DummySvgConverterProperties());
NUnit.Framework.Assert.AreEqual(0, doc.GetFirstPage().GetResources().GetPdfObject().Size());
TestResourceCreated(doc, 2);
}
[NUnit.Framework.Test]
public virtual void DrawStreamOnCanvasCreatesResourceTest() {
PdfPage page = doc.AddNewPage();
PdfCanvas canvas = new PdfCanvas(page);
SvgConverter.DrawOnCanvas(@is, canvas);
NUnit.Framework.Assert.AreEqual(0, doc.GetFirstPage().GetResources().GetPdfObject().Size());
TestResourceCreated(doc, 2);
}
[NUnit.Framework.Test]
public virtual void DrawStreamOnCanvasWithPropsCreatesResourceTest() {
PdfPage page = doc.AddNewPage();
PdfCanvas canvas = new PdfCanvas(page);
SvgConverter.DrawOnCanvas(@is, canvas, new DummySvgConverterProperties());
NUnit.Framework.Assert.AreEqual(0, doc.GetFirstPage().GetResources().GetPdfObject().Size());
TestResourceCreated(doc, 2);
}
[NUnit.Framework.Test]
public virtual void ConvertStringToXObjectCreatesNoResourceTest() {
SvgConverter.ConvertToXObject(content, doc);
NUnit.Framework.Assert.AreEqual(0, doc.GetLastPage().GetResources().GetPdfObject().Size());
}
[NUnit.Framework.Test]
public virtual void ConvertStringToXObjectWithPropsCreatesNoResourceTest() {
SvgConverter.ConvertToXObject(content, doc, new DummySvgConverterProperties());
NUnit.Framework.Assert.AreEqual(0, doc.GetLastPage().GetResources().GetPdfObject().Size());
}
[NUnit.Framework.Test]
public virtual void ConvertStreamToXObjectCreatesNoResourceTest() {
SvgConverter.ConvertToXObject(@is, doc);
NUnit.Framework.Assert.AreEqual(0, doc.GetLastPage().GetResources().GetPdfObject().Size());
}
[NUnit.Framework.Test]
public virtual void ConvertStreamToXObjectWithPropsCreatesNoResourceTest() {
SvgConverter.ConvertToXObject(@is, doc, new DummySvgConverterProperties());
NUnit.Framework.Assert.AreEqual(0, doc.GetLastPage().GetResources().GetPdfObject().Size());
}
[NUnit.Framework.Test]
public virtual void ProcessNodeWithCustomFactory() {
INode svg = new JsoupElementNode(new TSpdf.StyledXmlParser.Jsoup.Nodes.Element(TSpdf.StyledXmlParser.Jsoup.Parser.Tag
.ValueOf("svg"), ""));
DummySvgConverterProperties props = new DummySvgConverterProperties();
IBranchSvgNodeRenderer node = (IBranchSvgNodeRenderer)SvgConverter.Process(svg, props).GetRootRenderer();
NUnit.Framework.Assert.IsTrue(node is DummySvgNodeRenderer);
NUnit.Framework.Assert.AreEqual(0, node.GetChildren().Count);
NUnit.Framework.Assert.IsNull(node.GetParent());
}
[NUnit.Framework.Test]
public virtual void ProcessNode() {
INode svg = new JsoupElementNode(new TSpdf.StyledXmlParser.Jsoup.Nodes.Element(TSpdf.StyledXmlParser.Jsoup.Parser.Tag
.ValueOf("svg"), ""));
IBranchSvgNodeRenderer node = (IBranchSvgNodeRenderer)SvgConverter.Process(svg, null).GetRootRenderer();
NUnit.Framework.Assert.IsTrue(node is SvgTagSvgNodeRenderer);
NUnit.Framework.Assert.AreEqual(0, node.GetChildren().Count);
NUnit.Framework.Assert.IsNull(node.GetParent());
}
[NUnit.Framework.Test]
public virtual void ParseString() {
INode actual = SvgConverter.Parse(content);
NUnit.Framework.Assert.AreEqual(1, actual.ChildNodes().Count);
JsoupElementNode node = (JsoupElementNode)actual.ChildNodes()[0];
NUnit.Framework.Assert.AreEqual("svg", node.Name());
NUnit.Framework.Assert.AreEqual(0, node.ChildNodes().Count);
}
[NUnit.Framework.Test]
public virtual void ParseStream() {
INode actual = SvgConverter.Parse(@is);
NUnit.Framework.Assert.AreEqual(1, actual.ChildNodes().Count);
JsoupElementNode node = (JsoupElementNode)actual.ChildNodes()[0];
NUnit.Framework.Assert.AreEqual("svg", node.Name());
NUnit.Framework.Assert.AreEqual(0, node.ChildNodes().Count);
}
[NUnit.Framework.Test]
public virtual void ParseStreamWithProps() {
INode actual = SvgConverter.Parse(@is, new DummySvgConverterProperties());
NUnit.Framework.Assert.AreEqual(1, actual.ChildNodes().Count);
JsoupElementNode node = (JsoupElementNode)actual.ChildNodes()[0];
NUnit.Framework.Assert.AreEqual("svg", node.Name());
NUnit.Framework.Assert.AreEqual(0, node.ChildNodes().Count);
}
[NUnit.Framework.Test]
public virtual void ParseStreamErrorEncodingTooBig() {
@is = new MemoryStream(content.GetBytes(System.Text.Encoding.Unicode));
INode actual = SvgConverter.Parse(@is, new DummySvgConverterProperties());
// defaults to UTF-8
NUnit.Framework.Assert.AreEqual(1, actual.ChildNodes().Count);
// Does not throw an exception, but produces gibberish output that gets fed into a Text element, which is not a JsoupElementNode
NUnit.Framework.Assert.IsFalse(actual.ChildNodes()[0] is JsoupElementNode);
}
private class OtherCharsetDummySvgConverterProperties : DummySvgConverterProperties {
public override String GetCharset() {
return "UTF-16LE";
}
}
[NUnit.Framework.Test]
public virtual void ParseStreamWithOtherEncoding() {
@is = new MemoryStream(content.GetBytes(System.Text.Encoding.Unicode));
INode actual = SvgConverter.Parse(@is, new SvgConverterUnitTest.OtherCharsetDummySvgConverterProperties());
NUnit.Framework.Assert.AreEqual(1, actual.ChildNodes().Count);
JsoupElementNode node = (JsoupElementNode)actual.ChildNodes()[0];
NUnit.Framework.Assert.AreEqual("svg", node.Name());
NUnit.Framework.Assert.AreEqual(0, node.ChildNodes().Count);
}
[NUnit.Framework.Test]
public virtual void ParseStreamErrorOtherCharset() {
INode actual = SvgConverter.Parse(@is, new SvgConverterUnitTest.OtherCharsetDummySvgConverterProperties());
NUnit.Framework.Assert.AreEqual(1, actual.ChildNodes().Count);
// Does not throw an exception, but produces gibberish output that gets fed into a Text element, which is not a JsoupElementNode
NUnit.Framework.Assert.IsFalse(actual.ChildNodes()[0] is JsoupElementNode);
}
[NUnit.Framework.Test]
public virtual void CheckNullTest() {
Exception e = NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => SvgConverter.DrawOnDocument
("test", null, 1));
NUnit.Framework.Assert.AreEqual(SvgExceptionMessageConstant.PARAMETER_CANNOT_BE_NULL, e.Message);
}
[NUnit.Framework.Test]
public virtual void ResourceResolverInstanceTest() {
DummySvgConverterProperties properties = new DummySvgConverterProperties();
SvgProcessorContext context = new SvgProcessorContext(properties);
ResourceResolver initialResolver = context.GetResourceResolver();
SvgProcessorResult svgProcessorResult = new SvgProcessorResult(new Dictionary<String, ISvgNodeRenderer>(),
new SvgTagSvgNodeRenderer(), context);
ResourceResolver currentResolver = SvgConverter.GetResourceResolver(svgProcessorResult, properties);
NUnit.Framework.Assert.AreEqual(initialResolver, currentResolver);
}
[NUnit.Framework.Test]
public virtual void CreateResourceResolverWithoutProcessorResultTest() {
ISvgConverterProperties props = new SvgConverterProperties();
NUnit.Framework.Assert.IsNotNull(SvgConverter.GetResourceResolver(null, props));
}
[NUnit.Framework.Test]
public virtual void ResourceResolverInstanceCustomResolverTest() {
DummySvgConverterProperties properties = new DummySvgConverterProperties();
SvgConverterUnitTest.TestSvgProcessorResult testSvgProcessorResult = new SvgConverterUnitTest.TestSvgProcessorResult
();
ResourceResolver currentResolver = SvgConverter.GetResourceResolver(testSvgProcessorResult, properties);
NUnit.Framework.Assert.IsNotNull(currentResolver);
}
[NUnit.Framework.Test]
public virtual void ResourceResolverInstanceCustomResolverNullPropsTest() {
SvgConverterUnitTest.TestSvgProcessorResult testSvgProcessorResult = new SvgConverterUnitTest.TestSvgProcessorResult
();
ResourceResolver currentResolver = SvgConverter.GetResourceResolver(testSvgProcessorResult, null);
NUnit.Framework.Assert.IsNotNull(currentResolver);
}
[NUnit.Framework.Test]
public virtual void NullBBoxInDrawTest() {
NUnit.Framework.Assert.Catch(typeof(PdfException), () => {
PdfFormXObject @object = SvgConverter.ConvertToXObject(content, doc);
((PdfDictionary)@object.GetPdfObject()).Remove(PdfName.BBox);
SvgConverter.Draw(@object, new PdfCanvas(doc, 1), 0, 0);
}
);
}
private class TestSvgProcessorResult : ISvgProcessorResult {
public TestSvgProcessorResult() {
}
public virtual IDictionary<String, ISvgNodeRenderer> GetNamedObjects() {
return null;
}
public virtual ISvgNodeRenderer GetRootRenderer() {
return null;
}
public virtual FontProvider GetFontProvider() {
return null;
}
public virtual FontSet GetTempFonts() {
return null;
}
}
}
}

View File

@@ -0,0 +1,89 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://TSpdfpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System;
using TSpdf.Svg.Renderers;
using TSpdf.Test;
using TSpdf.Test.Attributes;
namespace TSpdf.Svg.Css {
public class AttributesRelativeUnitTest : SvgIntegrationTest {
public static readonly String SOURCE_FOLDER = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/css/AttributesRelativeUnitTest/";
public static readonly String DESTINATION_FOLDER = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/css/AttributesRelativeUnitTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateDestinationFolder(DESTINATION_FOLDER);
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.StyledXmlParser.Logs.StyledXmlParserLogMessageConstant.UNKNOWN_ABSOLUTE_METRIC_LENGTH_PARSED
, Count = 4)]
public virtual void RectangleAttributesEmUnitsTest() {
// TODO DEVSIX-4834 support relative units in attributes of svg elements. Remove log message at this test
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "rectangleAttributesEmUnits");
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.StyledXmlParser.Logs.StyledXmlParserLogMessageConstant.UNKNOWN_ABSOLUTE_METRIC_LENGTH_PARSED
, Count = 4)]
public virtual void RectangleAttributesExUnitsTest() {
// TODO DEVSIX-4834 support relative units in attributes of svg elements. Remove log message at this test
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "rectangleAttributesExUnits");
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.StyledXmlParser.Logs.StyledXmlParserLogMessageConstant.UNKNOWN_ABSOLUTE_METRIC_LENGTH_PARSED
, Count = 4)]
public virtual void RectangleAttributesPercentUnitsTest() {
// TODO DEVSIX-4834 support relative units in attributes of svg elements. Remove log message at this test
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "rectangleAttributesPercentUnits");
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.StyledXmlParser.Logs.StyledXmlParserLogMessageConstant.UNKNOWN_ABSOLUTE_METRIC_LENGTH_PARSED
, Count = 4)]
public virtual void ImageAttributesEmUnitsTest() {
// TODO DEVSIX-4834 support relative units in attributes of svg elements. Remove log message at this test
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "imageAttributesEmUnits");
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.StyledXmlParser.Logs.StyledXmlParserLogMessageConstant.UNKNOWN_ABSOLUTE_METRIC_LENGTH_PARSED
, Count = 4)]
public virtual void ImageAttributesExUnitsTest() {
// TODO DEVSIX-4834 support relative units in attributes of svg elements. Remove log message at this test
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "imageAttributesExUnits");
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.StyledXmlParser.Logs.StyledXmlParserLogMessageConstant.UNKNOWN_ABSOLUTE_METRIC_LENGTH_PARSED
, Count = 4)]
public virtual void ImageAttributesPercentUnitsTest() {
// TODO DEVSIX-4834 support relative units in attributes of svg elements. Remove log message at this test
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "imageAttributesPercentUnits");
}
}
}

View File

@@ -0,0 +1,84 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using TSpdf.Svg.Renderers;
using TSpdf.Test;
namespace TSpdf.Svg.Css {
[NUnit.Framework.Category("IntegrationTest")]
public class DefaultStyleInheritanceIntegrationTest : SvgIntegrationTest {
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/css/DefaultInheritance/";
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/css/DefaultInheritance/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateDestinationFolder(destinationFolder);
}
//Css inheritance
[NUnit.Framework.Test]
public virtual void SimpleGroupInheritanceTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "simpleGroupInheritance");
}
//Inheritance in use tags
[NUnit.Framework.Test]
public virtual void UseFillInheritanceTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "useFillInheritance");
}
//Inheritance and g-tags
[NUnit.Framework.Test]
public virtual void GroupInheritanceTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "groupInheritance");
}
[NUnit.Framework.Test]
public virtual void UseInheritanceNotOverridingTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "useInheritanceNotOverriding");
}
}
}

View File

@@ -0,0 +1,119 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using System.Collections.Generic;
using System.IO;
using TSpdf.StyledXmlParser.Css;
using TSpdf.StyledXmlParser.Node;
using TSpdf.StyledXmlParser.Node.Impl.Jsoup.Node;
using TSpdf.Svg;
using TSpdf.Svg.Css.Impl;
using TSpdf.Svg.Dummy.Sdk;
using TSpdf.Svg.Processors.Impl;
using TSpdf.Test;
namespace TSpdf.Svg.Css {
[NUnit.Framework.Category("UnitTest")]
public class DefaultStylesTest : ExtendedTSpdfTest {
[NUnit.Framework.Test]
public virtual void CheckDefaultStrokeValuesTest() {
ICssResolver styleResolver = new SvgStyleResolver(new SvgProcessorContext(new SvgConverterProperties()));
TSpdf.StyledXmlParser.Jsoup.Nodes.Element svg = new TSpdf.StyledXmlParser.Jsoup.Nodes.Element(TSpdf.StyledXmlParser.Jsoup.Parser.Tag
.ValueOf("svg"), "");
INode svgNode = new JsoupElementNode(svg);
IDictionary<String, String> resolvedStyles = styleResolver.ResolveStyles(svgNode, new SvgCssContext());
NUnit.Framework.Assert.AreEqual("1", resolvedStyles.Get(SvgConstants.Attributes.STROKE_OPACITY));
NUnit.Framework.Assert.AreEqual("1px", resolvedStyles.Get(SvgConstants.Attributes.STROKE_WIDTH));
NUnit.Framework.Assert.AreEqual(SvgConstants.Values.NONE, resolvedStyles.Get(SvgConstants.Attributes.STROKE
));
NUnit.Framework.Assert.AreEqual(SvgConstants.Values.BUTT, resolvedStyles.Get(SvgConstants.Attributes.STROKE_LINECAP
));
NUnit.Framework.Assert.AreEqual("0", resolvedStyles.Get(SvgConstants.Attributes.STROKE_DASHOFFSET));
NUnit.Framework.Assert.AreEqual(SvgConstants.Values.NONE, resolvedStyles.Get(SvgConstants.Attributes.STROKE_DASHARRAY
));
NUnit.Framework.Assert.AreEqual("4", resolvedStyles.Get(SvgConstants.Attributes.STROKE_MITERLIMIT));
}
[NUnit.Framework.Test]
public virtual void CheckDefaultFillValuesTest() {
ICssResolver styleResolver = new SvgStyleResolver(new SvgProcessorContext(new SvgConverterProperties()));
TSpdf.StyledXmlParser.Jsoup.Nodes.Element svg = new TSpdf.StyledXmlParser.Jsoup.Nodes.Element(TSpdf.StyledXmlParser.Jsoup.Parser.Tag
.ValueOf("svg"), "");
INode svgNode = new JsoupElementNode(svg);
IDictionary<String, String> resolvedStyles = styleResolver.ResolveStyles(svgNode, new SvgCssContext());
NUnit.Framework.Assert.AreEqual("black", resolvedStyles.Get(SvgConstants.Attributes.FILL));
NUnit.Framework.Assert.AreEqual(SvgConstants.Values.FILL_RULE_NONZERO, resolvedStyles.Get(SvgConstants.Attributes
.FILL_RULE));
NUnit.Framework.Assert.AreEqual("1", resolvedStyles.Get(SvgConstants.Attributes.FILL_OPACITY));
}
[NUnit.Framework.Test]
public virtual void CheckDefaultFontValuesTest() {
ICssResolver styleResolver = new SvgStyleResolver(new SvgProcessorContext(new SvgConverterProperties()));
TSpdf.StyledXmlParser.Jsoup.Nodes.Element svg = new TSpdf.StyledXmlParser.Jsoup.Nodes.Element(TSpdf.StyledXmlParser.Jsoup.Parser.Tag
.ValueOf("svg"), "");
INode svgNode = new JsoupElementNode(svg);
IDictionary<String, String> resolvedStyles = styleResolver.ResolveStyles(svgNode, new SvgCssContext());
NUnit.Framework.Assert.AreEqual("helvetica", resolvedStyles.Get(SvgConstants.Attributes.FONT_FAMILY));
NUnit.Framework.Assert.AreEqual("9pt", resolvedStyles.Get(SvgConstants.Attributes.FONT_SIZE));
}
[NUnit.Framework.Test]
public virtual void EmptyStreamTest() {
ICssResolver styleResolver = new SvgStyleResolver(new MemoryStream(new byte[] { }), new SvgProcessorContext
(new SvgConverterProperties()));
TSpdf.StyledXmlParser.Jsoup.Nodes.Element svg = new TSpdf.StyledXmlParser.Jsoup.Nodes.Element(TSpdf.StyledXmlParser.Jsoup.Parser.Tag
.ValueOf("svg"), "");
INode svgNode = new JsoupElementNode(svg);
IDictionary<String, String> resolvedStyles = styleResolver.ResolveStyles(svgNode, new SvgCssContext());
NUnit.Framework.Assert.AreEqual(1, resolvedStyles.Count);
NUnit.Framework.Assert.AreEqual("12pt", resolvedStyles.Get(SvgConstants.Attributes.FONT_SIZE));
}
[NUnit.Framework.Test]
public virtual void EmptyStylesFallbackTest() {
NUnit.Framework.Assert.Catch(typeof(System.IO.IOException), () => new SvgStyleResolver(new ExceptionInputStream
(), new SvgProcessorContext(new SvgConverterProperties())));
}
}
}

View File

@@ -0,0 +1,136 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://TSpdfpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System;
using TSpdf.Svg.Renderers;
using TSpdf.Test;
using TSpdf.Test.Attributes;
namespace TSpdf.Svg.Css {
[NUnit.Framework.Category("IntegrationTest")]
public class FontRelativeUnitTest : SvgIntegrationTest {
public static readonly String SOURCE_FOLDER = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/css/FontRelativeUnitTest/";
public static readonly String DESTINATION_FOLDER = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/css/FontRelativeUnitTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateDestinationFolder(DESTINATION_FOLDER);
}
// Text tests block
[NUnit.Framework.Test]
public virtual void TextFontSizeRemUnitTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "textFontSizeRemUnitTest");
}
[NUnit.Framework.Test]
public virtual void TextFontSizeEmUnitTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "textFontSizeEmUnitTest");
}
[NUnit.Framework.Test]
public virtual void TextNegativeFontSizeRemUnitTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "textNegativeFontSizeRemUnitTest");
}
[NUnit.Framework.Test]
public virtual void TextNegativeFontSizeEmUnitTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "textNegativeFontSizeEmUnitTest");
}
[NUnit.Framework.Test]
public virtual void TextFontSizeFromParentTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "textFontSizeFromParentTest");
}
[NUnit.Framework.Test]
public virtual void TextFontSizeHierarchyEmAndRemUnitTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "textFontSizeHierarchyEmAndRemUnitTest");
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.StyledXmlParser.Logs.StyledXmlParserLogMessageConstant.UNKNOWN_ABSOLUTE_METRIC_LENGTH_PARSED
, Count = 4)]
public virtual void TextFontSizeInheritanceFromUseTest() {
// TODO DEVSIX-2607 relative font-size value is not supported for tspan element
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "textFontSizeInheritanceFromUseTest");
}
[NUnit.Framework.Test]
public virtual void TextFontSizeFromUseTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "textFontSizeFromUseTest");
}
// Linear gradient tests block
[NUnit.Framework.Test]
public virtual void LnrGrdntObjectBoundingBoxEmUnitTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "lnrGrdntObjectBoundingBoxEmUnitTest");
}
[NUnit.Framework.Test]
public virtual void LnrGrdntUserSpaceOnUseEmUnitTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "lnrGrdntUserSpaceOnUseEmUnitTest");
}
[NUnit.Framework.Test]
public virtual void LnrGrdntObjectBoundingBoxRemUnitTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "lnrGrdntObjectBoundingBoxRemUnitTest");
}
[NUnit.Framework.Test]
public virtual void LnrGrdntUserSpaceOnUseRemUnitTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "lnrGrdntUserSpaceOnUseRemUnitTest");
}
[NUnit.Framework.Test]
public virtual void LnrGrdntObjectBoundingBoxEmUnitFromDirectParentTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "lnrGrdntObjectBoundingBoxEmUnitFromDirectParentTest"
);
}
[NUnit.Framework.Test]
public virtual void LnrGrdntUserSpaceOnUseEmUnitFromDirectParentTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "lnrGrdntUserSpaceOnUseEmUnitFromDirectParentTest"
);
}
[NUnit.Framework.Test]
public virtual void LnrGrdntFontSizeFromDefsFillTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "lnrGrdntFontSizeFromDefsFillTest");
}
// Symbol tests block
[NUnit.Framework.Test]
public virtual void SymbolFontSizeInheritanceFromUseTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "symbolFontSizeInheritanceFromUseTest");
}
// Marker tests block
[NUnit.Framework.Test]
public virtual void MarkerFontSizeInheritanceFromDifsTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "markerFontSizeInheritanceFromDifsTest");
}
}
}

View File

@@ -0,0 +1,217 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using System.Collections.Generic;
using TSpdf.Kernel.Geom;
using TSpdf.StyledXmlParser.Node;
using TSpdf.StyledXmlParser.Node.Impl.Jsoup;
using TSpdf.Svg.Logs;
using TSpdf.Svg.Processors.Impl;
using TSpdf.Svg.Renderers;
using TSpdf.Svg.Renderers.Impl;
using TSpdf.Test;
using TSpdf.Test.Attributes;
namespace TSpdf.Svg.Css {
[NUnit.Framework.Category("IntegrationTest")]
public class SvgStyleResolverIntegrationTest : SvgIntegrationTest {
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/css/SvgStyleResolver/";
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/css/SvgStyleResolver/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateDestinationFolder(destinationFolder);
}
[NUnit.Framework.Test]
public virtual void RedCirleTest() {
String svg = "<svg\n" + " width=\"210mm\"\n" + " height=\"297mm\"\n" + " viewBox=\"0 0 210 297\"\n"
+ " version=\"1.1\"\n" + " <title id=\"title4508\">Red Circle</title>\n" + " <ellipse\n" + " id=\"path3699\"\n"
+ " cx=\"96.005951\"\n" + " cy=\"110.65774\"\n" + " rx=\"53.672619\"\n" + " ry=\"53.294643\"\n"
+ " style=\"stroke-width:1.76388889;stroke:#da0000;stroke-opacity:1;fill:none;stroke-miterlimit:4;stroke-dasharray:none\" />\n"
+ "</svg>\n";
JsoupXmlParser xmlParser = new JsoupXmlParser();
IDocumentNode root = xmlParser.Parse(svg);
IBranchSvgNodeRenderer nodeRenderer = (IBranchSvgNodeRenderer)new DefaultSvgProcessor().Process(root, null
).GetRootRenderer();
IDictionary<String, String> actual = new Dictionary<String, String>();
//Traverse to ellipse
ISvgNodeRenderer ellipse = nodeRenderer.GetChildren()[0];
actual.Put("stroke", ellipse.GetAttribute("stroke"));
actual.Put("stroke-width", ellipse.GetAttribute("stroke-width"));
actual.Put("stroke-opacity", ellipse.GetAttribute("stroke-opacity"));
IDictionary<String, String> expected = new Dictionary<String, String>();
expected.Put("stroke-width", "1.76388889");
expected.Put("stroke", "#da0000");
expected.Put("stroke-opacity", "1");
NUnit.Framework.Assert.AreEqual(expected, actual);
}
[NUnit.Framework.Test]
public virtual void StyleTagProcessingTest() {
String svg = "<svg\n" + " width=\"210mm\"\n" + " height=\"297mm\"\n" + " viewBox=\"0 0 210 297\"\n"
+ " version=\"1.1\"\n" + " id=\"svg8\"\n" + " >\n" + " <style>\n" + "\tellipse{\n" + "\t\tstroke-width:1.76388889;\n"
+ "\t\tstroke:#da0000;\n" + "\t\tstroke-opacity:1;\n" + "\t}\n" + " </style>\n" + " <ellipse\n" +
" id=\"path3699\"\n" + " cx=\"96.005951\"\n" + " cy=\"110.65774\"\n" + " rx=\"53.672619\"\n"
+ " ry=\"53.294643\"\n" + " style=\"fill:none;stroke-miterlimit:4;stroke-dasharray:none\" />\n"
+ "</svg>\n";
JsoupXmlParser xmlParser = new JsoupXmlParser();
IDocumentNode root = xmlParser.Parse(svg);
IBranchSvgNodeRenderer nodeRenderer = (IBranchSvgNodeRenderer)new DefaultSvgProcessor().Process(root, null
).GetRootRenderer();
IDictionary<String, String> actual = new Dictionary<String, String>();
//Traverse to ellipse
ISvgNodeRenderer ellipse = nodeRenderer.GetChildren()[0];
actual.Put("stroke", ellipse.GetAttribute("stroke"));
actual.Put("stroke-width", ellipse.GetAttribute("stroke-width"));
actual.Put("stroke-opacity", ellipse.GetAttribute("stroke-opacity"));
IDictionary<String, String> expected = new Dictionary<String, String>();
expected.Put("stroke-width", "1.76388889");
expected.Put("stroke", "#da0000");
expected.Put("stroke-opacity", "1");
NUnit.Framework.Assert.AreEqual(expected, actual);
}
[NUnit.Framework.Test]
public virtual void StylesOfSvgTagProcessingTest() {
String svg = "<?xml version=\"1.0\" standalone=\"no\"?>\n" + "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n"
+ " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n" + "<svg width=\"400\" height=\"200\"\n"
+ " viewBox=\"0 0 400 200\" version=\"1.1\"\n" + " xmlns=\"http://www.w3.org/2000/svg\"\n" +
" xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n" + " xmlns:v=\"http://schemas.microsoft.com/visio/2003/SVGExtensions/\"\n"
+ " class=\"st11\">\n" + " <style type=\"text/css\">\n" + " .st11 {fill:none;stroke:black;stroke-width:6}\n"
+ " </style>\n" + " <g >\n" + " <path d=\"M0 100 L0 50 L70 50\"/>\n" + " </g>\n" + "</svg>";
JsoupXmlParser xmlParser = new JsoupXmlParser();
IDocumentNode root = xmlParser.Parse(svg);
IBranchSvgNodeRenderer nodeRenderer = (IBranchSvgNodeRenderer)new DefaultSvgProcessor().Process(root, null
).GetRootRenderer();
PathSvgNodeRenderer pathSvgNodeRenderer = (PathSvgNodeRenderer)((IBranchSvgNodeRenderer)nodeRenderer.GetChildren
()[0]).GetChildren()[0];
IDictionary<String, String> actual = new Dictionary<String, String>();
actual.Put("stroke", pathSvgNodeRenderer.GetAttribute("stroke"));
actual.Put("fill", pathSvgNodeRenderer.GetAttribute("fill"));
actual.Put("d", pathSvgNodeRenderer.GetAttribute("d"));
IDictionary<String, String> expected = new Dictionary<String, String>();
expected.Put("stroke", "black");
expected.Put("fill", "none");
expected.Put("d", "M0 100 L0 50 L70 50");
NUnit.Framework.Assert.AreEqual(expected, actual);
}
[NUnit.Framework.Test]
public virtual void FontResolverIntegrationTest() {
//TODO DEVSIX-2058
ConvertAndCompare(sourceFolder, destinationFolder, "fontssvg");
}
[NUnit.Framework.Test]
public virtual void ValidLocalFontTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "validLocalFontTest");
}
[NUnit.Framework.Test]
public virtual void FontWeightTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "fontWeightTest");
}
[NUnit.Framework.Test]
[LogMessage(SvgLogMessageConstant.UNMAPPED_TAG, LogLevel = LogLevelConstants.WARN)]
public virtual void ExternalStyleSheetWithFillStyleTest() {
// TODO DEVSIX-4275 investigate why fill style not processed
ConvertAndCompare(sourceFolder, destinationFolder, "externalStyleSheetWithFillStyleTest");
}
[NUnit.Framework.Test]
[LogMessage(SvgLogMessageConstant.UNMAPPED_TAG, LogLevel = LogLevelConstants.WARN)]
public virtual void ExternalStyleSheetWithStrokeStyleTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "externalStyleSheetWithStrokeStyleTest");
}
[NUnit.Framework.Test]
public virtual void GoogleFontsTest() {
//TODO DEVSIX-2264: that test shall fail after the fix.
ConvertAndCompare(sourceFolder, destinationFolder, "googleFontsTest");
}
[NUnit.Framework.Test]
public virtual void SvgWithExternalCSStoSingleDefaultPage() {
// TODO: update cmp files when DEVSIX-2286 resolved
ConvertAndCompare(sourceFolder, destinationFolder, "externalCss");
}
[NUnit.Framework.Test]
public virtual void SvgWithInternalCSStoSingleDefaultPage() {
// TODO: update cmp files when DEVSIX-2286 resolved
ConvertAndCompare(sourceFolder, destinationFolder, "internalCss");
}
[NUnit.Framework.Test]
public virtual void SvgWithExternalCSStoCustomPage() {
// TODO: update cmp files when DEVSIX-2286 resolved
// Take a note this method differs from the one used in Default Page test
ConvertAndCompare(sourceFolder, destinationFolder, "externalCss_custom", PageSize.A3.Rotate());
}
[NUnit.Framework.Test]
public virtual void SvgWithInternalCSStoCustomPage() {
// TODO: update cmp files when DEVSIX-2286 resolved
ConvertAndCompare(sourceFolder, destinationFolder, "internalCss_custom", PageSize.A3.Rotate());
}
[NUnit.Framework.Test]
public virtual void MultipleSVGtagsWithDiffStylesFromExternalCSS() {
// TODO: update cmp files when DEVSIX-2286 resolved
ConvertAndCompare(sourceFolder, destinationFolder, "externalCss_palette", PageSize.A3.Rotate());
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.StyledXmlParser.Logs.StyledXmlParserLogMessageConstant.UNKNOWN_ABSOLUTE_METRIC_LENGTH_PARSED
)]
public virtual void RelativeStyleInheritanceTest() {
// TODO DEVSIX-4140 font-relative values doesn't support
ConvertAndCompare(sourceFolder, destinationFolder, "relativeStyleInheritanceTest");
}
}
}

View File

@@ -0,0 +1,248 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using System.Collections.Generic;
using TSpdf.IO.Util;
using TSpdf.StyledXmlParser.Css;
using TSpdf.StyledXmlParser.Css.Resolve;
using TSpdf.StyledXmlParser.Jsoup.Nodes;
using TSpdf.StyledXmlParser.Node;
using TSpdf.StyledXmlParser.Node.Impl.Jsoup.Node;
using TSpdf.Svg;
using TSpdf.Svg.Css.Impl;
using TSpdf.Svg.Processors.Impl;
using TSpdf.Test;
using TSpdf.Test.Attributes;
namespace TSpdf.Svg.Css {
[NUnit.Framework.Category("UnitTest")]
public class SvgStyleResolverTest : ExtendedTSpdfTest {
private static readonly String baseUri = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/css/SvgStyleResolver/";
//Single element test
//Inherits values from parent?
//Calculates values from parent
[NUnit.Framework.Test]
public virtual void SvgCssResolverBasicAttributeTest() {
TSpdf.StyledXmlParser.Jsoup.Nodes.Element jsoupCircle = new TSpdf.StyledXmlParser.Jsoup.Nodes.Element(TSpdf.StyledXmlParser.Jsoup.Parser.Tag
.ValueOf("circle"), "");
Attributes circleAttributes = jsoupCircle.Attributes();
circleAttributes.Put(new TSpdf.StyledXmlParser.Jsoup.Nodes.Attribute("id", "circle1"));
circleAttributes.Put(new TSpdf.StyledXmlParser.Jsoup.Nodes.Attribute("cx", "95"));
circleAttributes.Put(new TSpdf.StyledXmlParser.Jsoup.Nodes.Attribute("cy", "95"));
circleAttributes.Put(new TSpdf.StyledXmlParser.Jsoup.Nodes.Attribute("rx", "53"));
circleAttributes.Put(new TSpdf.StyledXmlParser.Jsoup.Nodes.Attribute("ry", "53"));
circleAttributes.Put(new TSpdf.StyledXmlParser.Jsoup.Nodes.Attribute("style", "stroke-width:1.5;stroke:#da0000;"
));
AbstractCssContext cssContext = new SvgCssContext();
INode circle = new JsoupElementNode(jsoupCircle);
SvgProcessorContext context = new SvgProcessorContext(new SvgConverterProperties());
ICssResolver resolver = new SvgStyleResolver(circle, context);
IDictionary<String, String> actual = resolver.ResolveStyles(circle, cssContext);
IDictionary<String, String> expected = new Dictionary<String, String>();
expected.Put("id", "circle1");
expected.Put("cx", "95");
expected.Put("cy", "95");
expected.Put("rx", "53");
expected.Put("ry", "53");
expected.Put("stroke-width", "1.5");
expected.Put("stroke", "#da0000");
expected.Put("font-size", "12pt");
NUnit.Framework.Assert.AreEqual(expected, actual);
}
[NUnit.Framework.Test]
public virtual void SvgCssResolverStylesheetTest() {
TSpdf.StyledXmlParser.Jsoup.Nodes.Element jsoupLink = new TSpdf.StyledXmlParser.Jsoup.Nodes.Element(TSpdf.StyledXmlParser.Jsoup.Parser.Tag
.ValueOf(SvgConstants.Tags.LINK), "");
Attributes linkAttributes = jsoupLink.Attributes();
linkAttributes.Put(new TSpdf.StyledXmlParser.Jsoup.Nodes.Attribute(SvgConstants.Attributes.XMLNS, "http://www.w3.org/1999/xhtml"
));
linkAttributes.Put(new TSpdf.StyledXmlParser.Jsoup.Nodes.Attribute(SvgConstants.Attributes.REL, SvgConstants.Attributes
.STYLESHEET));
linkAttributes.Put(new TSpdf.StyledXmlParser.Jsoup.Nodes.Attribute(SvgConstants.Attributes.HREF, "styleSheetWithLinkStyle.css"
));
linkAttributes.Put(new TSpdf.StyledXmlParser.Jsoup.Nodes.Attribute("type", "text/css"));
JsoupElementNode node = new JsoupElementNode(jsoupLink);
SvgConverterProperties scp = new SvgConverterProperties();
scp.SetBaseUri(baseUri);
SvgProcessorContext processorContext = new SvgProcessorContext(scp);
SvgStyleResolver sr = new SvgStyleResolver(node, processorContext);
IDictionary<String, String> attr = sr.ResolveStyles(node, new SvgCssContext());
IDictionary<String, String> expectedAttr = new Dictionary<String, String>();
expectedAttr.Put(SvgConstants.Attributes.XMLNS, "http://www.w3.org/1999/xhtml");
expectedAttr.Put(SvgConstants.Attributes.REL, SvgConstants.Attributes.STYLESHEET);
expectedAttr.Put(SvgConstants.Attributes.HREF, "styleSheetWithLinkStyle.css");
expectedAttr.Put(SvgConstants.Attributes.FONT_SIZE, "12pt");
expectedAttr.Put("type", "text/css");
// Attribute from external stylesheet
expectedAttr.Put(SvgConstants.Attributes.FILL, "black");
NUnit.Framework.Assert.AreEqual(expectedAttr, attr);
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.StyledXmlParser.Logs.StyledXmlParserLogMessageConstant.UNABLE_TO_RETRIEVE_STREAM_WITH_GIVEN_BASE_URI
, LogLevel = LogLevelConstants.ERROR)]
public virtual void SvgCssResolverInvalidNameStylesheetTest() {
TSpdf.StyledXmlParser.Jsoup.Nodes.Element jsoupLink = new TSpdf.StyledXmlParser.Jsoup.Nodes.Element(TSpdf.StyledXmlParser.Jsoup.Parser.Tag
.ValueOf(SvgConstants.Tags.LINK), "");
TSpdf.StyledXmlParser.Jsoup.Nodes.Attributes linkAttributes = jsoupLink.Attributes();
linkAttributes.Put(new TSpdf.StyledXmlParser.Jsoup.Nodes.Attribute(SvgConstants.Attributes.XMLNS, "http://www.w3.org/1999/xhtml"
));
linkAttributes.Put(new TSpdf.StyledXmlParser.Jsoup.Nodes.Attribute(SvgConstants.Attributes.REL, SvgConstants.Attributes
.STYLESHEET));
linkAttributes.Put(new TSpdf.StyledXmlParser.Jsoup.Nodes.Attribute(SvgConstants.Attributes.HREF, "!invalid name!externalSheet.css"
));
linkAttributes.Put(new TSpdf.StyledXmlParser.Jsoup.Nodes.Attribute("type", "text/css"));
JsoupElementNode node = new JsoupElementNode(jsoupLink);
SvgConverterProperties scp = new SvgConverterProperties();
scp.SetBaseUri(baseUri);
SvgProcessorContext processorContext = new SvgProcessorContext(scp);
SvgStyleResolver sr = new SvgStyleResolver(node, processorContext);
IDictionary<String, String> attr = sr.ResolveStyles(node, new SvgCssContext());
IDictionary<String, String> expectedAttr = new Dictionary<String, String>();
expectedAttr.Put(SvgConstants.Attributes.XMLNS, "http://www.w3.org/1999/xhtml");
expectedAttr.Put(SvgConstants.Attributes.REL, SvgConstants.Attributes.STYLESHEET);
expectedAttr.Put(SvgConstants.Attributes.HREF, "!invalid name!externalSheet.css");
expectedAttr.Put(SvgConstants.Attributes.FONT_SIZE, "12pt");
expectedAttr.Put("type", "text/css");
NUnit.Framework.Assert.AreEqual(expectedAttr, attr);
}
[NUnit.Framework.Test]
public virtual void SvgCssResolverXlinkTest() {
TSpdf.StyledXmlParser.Jsoup.Nodes.Element jsoupImage = new TSpdf.StyledXmlParser.Jsoup.Nodes.Element(TSpdf.StyledXmlParser.Jsoup.Parser.Tag
.ValueOf("image"), "");
TSpdf.StyledXmlParser.Jsoup.Nodes.Attributes imageAttributes = jsoupImage.Attributes();
imageAttributes.Put(new TSpdf.StyledXmlParser.Jsoup.Nodes.Attribute("xlink:href", "itis.jpg"));
JsoupElementNode node = new JsoupElementNode(jsoupImage);
SvgConverterProperties scp = new SvgConverterProperties();
scp.SetBaseUri(baseUri);
SvgProcessorContext processorContext = new SvgProcessorContext(scp);
SvgStyleResolver sr = new SvgStyleResolver(node, processorContext);
IDictionary<String, String> attr = sr.ResolveStyles(node, new SvgCssContext());
String fileName = baseUri + "itis.jpg";
String expectedUrl = UrlUtil.ToNormalizedURI(fileName).ToString();
String expectedUrlAnotherValidVersion;
if (expectedUrl.StartsWith("file:///")) {
expectedUrlAnotherValidVersion = "file:/" + expectedUrl.Substring("file:///".Length);
}
else {
if (expectedUrl.StartsWith("file:/")) {
expectedUrlAnotherValidVersion = "file:///" + expectedUrl.Substring("file:/".Length);
}
else {
expectedUrlAnotherValidVersion = expectedUrl;
}
}
String url = attr.Get("xlink:href");
// Both variants(namely with triple and single slashes) are valid.
NUnit.Framework.Assert.IsTrue(expectedUrl.Equals(url) || expectedUrlAnotherValidVersion.Equals(url));
}
[NUnit.Framework.Test]
public virtual void SvgCssResolveHashXlinkTest() {
TSpdf.StyledXmlParser.Jsoup.Nodes.Element jsoupImage = new TSpdf.StyledXmlParser.Jsoup.Nodes.Element(TSpdf.StyledXmlParser.Jsoup.Parser.Tag
.ValueOf("image"), "");
TSpdf.StyledXmlParser.Jsoup.Nodes.Attributes imageAttributes = jsoupImage.Attributes();
imageAttributes.Put(new TSpdf.StyledXmlParser.Jsoup.Nodes.Attribute("xlink:href", "#testid"));
JsoupElementNode node = new JsoupElementNode(jsoupImage);
SvgConverterProperties scp = new SvgConverterProperties();
scp.SetBaseUri(baseUri);
SvgProcessorContext processorContext = new SvgProcessorContext(scp);
SvgStyleResolver sr = new SvgStyleResolver(node, processorContext);
IDictionary<String, String> attr = sr.ResolveStyles(node, new SvgCssContext());
NUnit.Framework.Assert.AreEqual("#testid", attr.Get("xlink:href"));
}
[NUnit.Framework.Test]
public virtual void OverrideDefaultStyleTest() {
ICssResolver styleResolver = new SvgStyleResolver(new SvgProcessorContext(new SvgConverterProperties()));
TSpdf.StyledXmlParser.Jsoup.Nodes.Element svg = new TSpdf.StyledXmlParser.Jsoup.Nodes.Element(TSpdf.StyledXmlParser.Jsoup.Parser.Tag
.ValueOf("svg"), "");
svg.Attributes().Put(SvgConstants.Attributes.STROKE, "white");
INode svgNode = new JsoupElementNode(svg);
IDictionary<String, String> resolvedStyles = styleResolver.ResolveStyles(svgNode, new SvgCssContext());
NUnit.Framework.Assert.AreEqual("white", resolvedStyles.Get(SvgConstants.Attributes.STROKE));
}
[NUnit.Framework.Test]
public virtual void SvgCssResolverStyleTagTest() {
TSpdf.StyledXmlParser.Jsoup.Nodes.Element styleTag = new TSpdf.StyledXmlParser.Jsoup.Nodes.Element(TSpdf.StyledXmlParser.Jsoup.Parser.Tag
.ValueOf("style"), "");
TextNode styleContents = new TextNode("\n" + "\tellipse{\n" + "\t\tstroke-width:1.76388889;\n" + "\t\tstroke:#da0000;\n"
+ "\t\tstroke-opacity:1;\n" + "\t}\n" + " ");
JsoupElementNode jSoupStyle = new JsoupElementNode(styleTag);
jSoupStyle.AddChild(new JsoupTextNode(styleContents));
TSpdf.StyledXmlParser.Jsoup.Nodes.Element ellipse = new TSpdf.StyledXmlParser.Jsoup.Nodes.Element(TSpdf.StyledXmlParser.Jsoup.Parser.Tag
.ValueOf("ellipse"), "");
JsoupElementNode jSoupEllipse = new JsoupElementNode(ellipse);
SvgProcessorContext context = new SvgProcessorContext(new SvgConverterProperties());
SvgStyleResolver resolver = new SvgStyleResolver(jSoupStyle, context);
AbstractCssContext svgContext = new SvgCssContext();
IDictionary<String, String> actual = resolver.ResolveStyles(jSoupEllipse, svgContext);
IDictionary<String, String> expected = new Dictionary<String, String>();
expected.Put("stroke-width", "1.76388889");
expected.Put("stroke", "#da0000");
expected.Put("stroke-opacity", "1");
expected.Put("font-size", "12pt");
NUnit.Framework.Assert.AreEqual(expected, actual);
}
[NUnit.Framework.Test]
public virtual void FontsResolverTagTest() {
TSpdf.StyledXmlParser.Jsoup.Nodes.Element styleTag = new TSpdf.StyledXmlParser.Jsoup.Nodes.Element(TSpdf.StyledXmlParser.Jsoup.Parser.Tag
.ValueOf("style"), "");
TextNode styleContents = new TextNode("\n" + "\t@font-face{\n" + "\t\tfont-family:Courier;\n" + "\t\tsrc:url(#Super Sans);\n"
+ "\t}\n" + " ");
JsoupElementNode jSoupStyle = new JsoupElementNode(styleTag);
jSoupStyle.AddChild(new JsoupTextNode(styleContents));
SvgProcessorContext context = new SvgProcessorContext(new SvgConverterProperties());
SvgStyleResolver resolver = new SvgStyleResolver(jSoupStyle, context);
IList<CssFontFaceRule> fontFaceRuleList = resolver.GetFonts();
NUnit.Framework.Assert.AreEqual(1, fontFaceRuleList.Count);
NUnit.Framework.Assert.AreEqual(2, fontFaceRuleList[0].GetProperties().Count);
}
}
}

View File

@@ -0,0 +1,92 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using System.Collections.Generic;
using TSpdf.StyledXmlParser.Node.Impl.Jsoup.Node;
using TSpdf.Svg;
using TSpdf.Svg.Css.Impl;
using TSpdf.Svg.Processors.Impl;
using TSpdf.Test;
using TSpdf.Test.Attributes;
namespace TSpdf.Svg.Css {
[NUnit.Framework.Category("UnitTest")]
public class XLinkTest : ExtendedTSpdfTest {
[NUnit.Framework.Test]
[LogMessage(TSpdf.StyledXmlParser.Logs.StyledXmlParserLogMessageConstant.UNABLE_TO_RESOLVE_IMAGE_URL)]
public virtual void SvgCssResolveMalformedXlinkTest() {
TSpdf.StyledXmlParser.Jsoup.Nodes.Element jsoupImage = new TSpdf.StyledXmlParser.Jsoup.Nodes.Element(TSpdf.StyledXmlParser.Jsoup.Parser.Tag
.ValueOf("image"), "");
TSpdf.StyledXmlParser.Jsoup.Nodes.Attributes imageAttributes = jsoupImage.Attributes();
String value = "http://are::";
imageAttributes.Put(new TSpdf.StyledXmlParser.Jsoup.Nodes.Attribute("xlink:href", value));
JsoupElementNode node = new JsoupElementNode(jsoupImage);
SvgStyleResolver sr = new SvgStyleResolver(new SvgProcessorContext(new SvgConverterProperties()));
IDictionary<String, String> attr = sr.ResolveStyles(node, new SvgCssContext());
NUnit.Framework.Assert.AreEqual(value, attr.Get("xlink:href"));
}
[NUnit.Framework.Test]
public virtual void SvgCssResolveDataXlinkTest() {
TSpdf.StyledXmlParser.Jsoup.Nodes.Element jsoupImage = new TSpdf.StyledXmlParser.Jsoup.Nodes.Element(TSpdf.StyledXmlParser.Jsoup.Parser.Tag
.ValueOf(SvgConstants.Tags.IMAGE), "");
TSpdf.StyledXmlParser.Jsoup.Nodes.Attributes imageAttributes = jsoupImage.Attributes();
JsoupElementNode node = new JsoupElementNode(jsoupImage);
String value1 = "data:image/png;base64,iVBORw0KGgoAAAANSU";
imageAttributes.Put(new TSpdf.StyledXmlParser.Jsoup.Nodes.Attribute("xlink:href", value1));
SvgStyleResolver sr = new SvgStyleResolver(new SvgProcessorContext(new SvgConverterProperties()));
IDictionary<String, String> attr = sr.ResolveStyles(node, new SvgCssContext());
NUnit.Framework.Assert.AreEqual(value1, attr.Get("xlink:href"));
String value2 = "data:...,.";
imageAttributes.Put(new TSpdf.StyledXmlParser.Jsoup.Nodes.Attribute("xlink:href", value2));
sr = new SvgStyleResolver(new SvgProcessorContext(new SvgConverterProperties()));
attr = sr.ResolveStyles(node, new SvgCssContext());
NUnit.Framework.Assert.AreEqual(value2, attr.Get("xlink:href"));
String value3 = "dAtA:...,.";
imageAttributes.Put(new TSpdf.StyledXmlParser.Jsoup.Nodes.Attribute("xlink:href", value3));
sr = new SvgStyleResolver(new SvgProcessorContext(new SvgConverterProperties()));
attr = sr.ResolveStyles(node, new SvgCssContext());
NUnit.Framework.Assert.AreEqual(value3, attr.Get("xlink:href"));
}
}
}

View File

@@ -0,0 +1,67 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using TSpdf.Svg;
using TSpdf.Svg.Renderers.Impl;
using TSpdf.Test;
namespace TSpdf.Svg.Css.Impl {
[NUnit.Framework.Category("UnitTest")]
public class SvgNodeRendererInheritanceResolverUnitTest : ExtendedTSpdfTest {
[NUnit.Framework.Test]
public virtual void ApplyInheritanceToSubTreeFillTest() {
String expectedFillAttribute = "blue";
UseSvgNodeRenderer newRoot = new UseSvgNodeRenderer();
newRoot.SetAttribute(SvgConstants.Attributes.FILL, expectedFillAttribute);
GroupSvgNodeRenderer subTree = new GroupSvgNodeRenderer();
RectangleSvgNodeRenderer rect = new RectangleSvgNodeRenderer();
CircleSvgNodeRenderer circle = new CircleSvgNodeRenderer();
subTree.AddChild(rect);
subTree.AddChild(circle);
SvgNodeRendererInheritanceResolver.ApplyInheritanceToSubTree(newRoot, subTree, null);
NUnit.Framework.Assert.AreEqual(expectedFillAttribute, subTree.GetAttribute(SvgConstants.Attributes.FILL));
NUnit.Framework.Assert.AreEqual(expectedFillAttribute, rect.GetAttribute(SvgConstants.Attributes.FILL));
NUnit.Framework.Assert.AreEqual(expectedFillAttribute, circle.GetAttribute(SvgConstants.Attributes.FILL));
}
}
}

View File

@@ -0,0 +1,101 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://TSpdfpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System;
using TSpdf.Kernel.Colors;
using TSpdf.Kernel.Geom;
using TSpdf.Kernel.Pdf;
using TSpdf.Kernel.Pdf.Canvas;
using TSpdf.Kernel.Pdf.Xobject;
using TSpdf.Kernel.Utils;
using TSpdf.StyledXmlParser.Node;
using TSpdf.Svg;
using TSpdf.Svg.Converter;
using TSpdf.Svg.Processors.Impl;
using TSpdf.Svg.Renderers;
using TSpdf.Svg.Renderers.Factories;
using TSpdf.Svg.Renderers.Impl;
using TSpdf.Test;
namespace TSpdf.Svg.Customization {
public class CustomizeTextLeafSvgNodeRendererTest : SvgIntegrationTest {
public static readonly String SOURCE_FOLDER = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/customization/CustomizeTextLeafSvgNodeRendererTest/";
public static readonly String DESTINATION_FOLDER = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/customization/CustomizeTextLeafSvgNodeRendererTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateDestinationFolder(DESTINATION_FOLDER);
}
[NUnit.Framework.Test]
public virtual void TestCustomizeTextLeafSvgNodeRenderer() {
String pdfFilename = "customizeTextLeafSvgNodeRenderer.pdf";
PdfDocument doc = new PdfDocument(new PdfWriter(DESTINATION_FOLDER + pdfFilename));
doc.AddNewPage();
SvgConverterProperties properties = new SvgConverterProperties();
properties.SetRendererFactory(new CustomizeTextLeafSvgNodeRendererTest.CustomTextLeafOverridingSvgNodeRendererFactory
());
String svg = "<svg viewBox=\"0 0 240 80\" xmlns=\"http://www.w3.org/2000/svg\">\n" + " <text x=\"20\" y=\"35\" class=\"small\">Hello world</text>\n"
+ "</svg>";
PdfFormXObject form = SvgConverter.ConvertToXObject(svg, doc, properties);
new PdfCanvas(doc.GetPage(1)).AddXObjectFittedIntoRectangle(form, new Rectangle(100, 100, 240, 80));
doc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(DESTINATION_FOLDER + pdfFilename, SOURCE_FOLDER
+ "cmp_" + pdfFilename, DESTINATION_FOLDER, "diff_"));
}
private class CustomTextLeafOverridingSvgNodeRendererFactory : DefaultSvgNodeRendererFactory {
public override ISvgNodeRenderer CreateSvgNodeRendererForTag(IElementNode tag, ISvgNodeRenderer parent) {
if (SvgConstants.Tags.TEXT_LEAF.Equals(tag.Name())) {
return new CustomizeTextLeafSvgNodeRendererTest.CustomTextLeafSvgNodeRenderer();
}
else {
return base.CreateSvgNodeRendererForTag(tag, parent);
}
}
}
private class CustomTextLeafSvgNodeRenderer : TextLeafSvgNodeRenderer {
public override ISvgNodeRenderer CreateDeepCopy() {
CustomizeTextLeafSvgNodeRendererTest.CustomTextLeafSvgNodeRenderer copy = new CustomizeTextLeafSvgNodeRendererTest.CustomTextLeafSvgNodeRenderer
();
DeepCopyAttributesAndStyles(copy);
return copy;
}
protected internal override void DoDraw(SvgDrawContext context) {
if (this.attributesAndStyles != null && this.attributesAndStyles.ContainsKey(SvgConstants.Attributes.TEXT_CONTENT
)) {
PdfCanvas currentCanvas = context.GetCurrentCanvas();
currentCanvas.SetFillColor(ColorConstants.RED);
currentCanvas.MoveText(context.GetTextMove()[0], context.GetTextMove()[1]);
String initialText = this.attributesAndStyles.Get(SvgConstants.Attributes.TEXT_CONTENT);
String amendedText = "_" + initialText + "_";
currentCanvas.ShowText(amendedText);
}
}
}
}
}

View File

@@ -0,0 +1,62 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using System.Collections.Generic;
using TSpdf.StyledXmlParser.Css;
using TSpdf.StyledXmlParser.Css.Resolve;
using TSpdf.StyledXmlParser.Node;
namespace TSpdf.Svg.Dummy.Css.Impl {
public class DummyCssResolver : ICssResolver {
public virtual IDictionary<String, String> ResolveStyles(INode node, AbstractCssContext context) {
IDictionary<String, String> styles = new Dictionary<String, String>();
if (node is IElementNode) {
IElementNode eNode = (IElementNode)node;
foreach (IAttribute attr in eNode.GetAttributes()) {
styles.Put(attr.GetKey(), attr.GetValue());
}
}
return styles;
}
}
}

View File

@@ -0,0 +1,81 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using TSpdf.StyledXmlParser.Node;
using TSpdf.Svg.Dummy.Renderers.Impl;
using TSpdf.Svg.Renderers;
using TSpdf.Svg.Renderers.Factories;
namespace TSpdf.Svg.Dummy.Factories {
/// <summary>
/// A dummy implementation of
/// <see cref="TSpdf.Svg.Renderers.Factories.ISvgNodeRendererFactory"/>
/// for testing purposes
/// </summary>
public class DummySvgNodeFactory : ISvgNodeRendererFactory {
public virtual ISvgNodeRenderer CreateSvgNodeRendererForTag(IElementNode tag, ISvgNodeRenderer parent) {
ISvgNodeRenderer result;
if ("svg".Equals(tag.Name())) {
result = new DummyBranchSvgNodeRenderer(tag.Name());
}
else {
if ("processable".Equals(tag.Name())) {
result = new DummyProcessableSvgNodeRenderer();
}
else {
if ("argumented".Equals(tag.Name())) {
result = new DummyArgumentedConstructorSvgNodeRenderer(15);
}
else {
result = new DummySvgNodeRenderer(tag.Name());
}
}
}
result.SetParent(parent);
return result;
}
public virtual bool IsTagIgnored(IElementNode tag) {
return false;
}
}
}

View File

@@ -0,0 +1,106 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using TSpdf.Layout.Font;
using TSpdf.StyledXmlParser.Css.Media;
using TSpdf.StyledXmlParser.Resolver.Resource;
using TSpdf.Svg.Dummy.Factories;
using TSpdf.Svg.Processors;
using TSpdf.Svg.Renderers.Factories;
namespace TSpdf.Svg.Dummy.Processors.Impl {
public class DummySvgConverterProperties : ISvgConverterProperties {
internal ISvgNodeRendererFactory rendererFactory;
internal String baseUri;
internal MediaDeviceDescription mediaDeviceDescription;
internal IResourceRetriever resourceRetriever;
public DummySvgConverterProperties() {
rendererFactory = new DummySvgNodeFactory();
mediaDeviceDescription = new MediaDeviceDescription("");
baseUri = "";
resourceRetriever = new DefaultResourceRetriever();
}
public virtual ISvgNodeRendererFactory GetRendererFactory() {
return rendererFactory;
}
public virtual FontProvider GetFontProvider() {
return null;
}
public virtual String GetCharset() {
return null;
}
public virtual String GetBaseUri() {
return baseUri;
}
public virtual TSpdf.Svg.Dummy.Processors.Impl.DummySvgConverterProperties SetBaseUri(String baseUri) {
return this;
}
public virtual MediaDeviceDescription GetMediaDeviceDescription() {
return mediaDeviceDescription;
}
public virtual IResourceRetriever GetResourceRetriever() {
return resourceRetriever;
}
public virtual TSpdf.Svg.Dummy.Processors.Impl.DummySvgConverterProperties SetMediaDeviceDescription(MediaDeviceDescription
mediaDeviceDescription) {
return this;
}
public virtual TSpdf.Svg.Dummy.Processors.Impl.DummySvgConverterProperties SetFontProvider(FontProvider fontProvider
) {
return this;
}
}
}

View File

@@ -0,0 +1,51 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
namespace TSpdf.Svg.Dummy.Renderers.Impl {
public class DummyArgumentedConstructorSvgNodeRenderer : DummySvgNodeRenderer {
public int number;
public DummyArgumentedConstructorSvgNodeRenderer(int arg) {
number = arg;
}
}
}

View File

@@ -0,0 +1,98 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using System.Collections.Generic;
using TSpdf.Kernel.Geom;
using TSpdf.Svg.Renderers;
namespace TSpdf.Svg.Dummy.Renderers.Impl {
public class DummyBranchSvgNodeRenderer : DummySvgNodeRenderer, IBranchSvgNodeRenderer {
internal IList<ISvgNodeRenderer> children = new List<ISvgNodeRenderer>();
public DummyBranchSvgNodeRenderer(String name)
: base(name) {
}
public virtual void AddChild(ISvgNodeRenderer child) {
children.Add(child);
}
public virtual IList<ISvgNodeRenderer> GetChildren() {
return children;
}
public override void Draw(SvgDrawContext context) {
System.Console.Out.WriteLine(name + ": Drawing in dummy node, children left: " + children.Count);
}
public override bool Equals(Object o) {
if (!(o is TSpdf.Svg.Dummy.Renderers.Impl.DummyBranchSvgNodeRenderer)) {
return false;
}
//Name
TSpdf.Svg.Dummy.Renderers.Impl.DummyBranchSvgNodeRenderer otherDummy = (TSpdf.Svg.Dummy.Renderers.Impl.DummyBranchSvgNodeRenderer
)o;
if (!this.name.Equals(otherDummy.name)) {
return false;
}
//children
if (!(this.children.IsEmpty() && otherDummy.children.IsEmpty())) {
if (this.children.Count != otherDummy.children.Count) {
return false;
}
bool iterationResult = true;
for (int i = 0; i < this.children.Count; i++) {
iterationResult &= this.children[i].Equals(otherDummy.GetChildren()[i]);
}
if (!iterationResult) {
return false;
}
}
return true;
}
public override Rectangle GetObjectBoundingBox(SvgDrawContext context) {
return null;
}
}
}

View File

@@ -0,0 +1,61 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using TSpdf.Svg.Exceptions;
using TSpdf.Svg.Renderers;
namespace TSpdf.Svg.Dummy.Renderers.Impl {
public class DummyProcessableSvgNodeRenderer : DummySvgNodeRenderer {
private bool processed = false;
public override void Draw(SvgDrawContext context) {
if (processed) {
throw new SvgProcessingException("Cannot process svg renderer twice");
}
processed = true;
}
public virtual bool IsProcessed() {
return processed;
}
}
}

View File

@@ -0,0 +1,136 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using System.Collections.Generic;
using TSpdf.Kernel.Geom;
using TSpdf.Svg;
using TSpdf.Svg.Renderers;
namespace TSpdf.Svg.Dummy.Renderers.Impl {
/// <summary>
/// A dummy implementation of
/// <see cref="TSpdf.Svg.Renderers.ISvgNodeRenderer"/>
/// for testing purposes
/// </summary>
public class DummySvgNodeRenderer : ISvgNodeRenderer {
internal IDictionary<String, String> attributes;
internal ISvgNodeRenderer parent;
internal String name;
internal bool drawn = false;
public DummySvgNodeRenderer()
: this("dummy") {
}
public DummySvgNodeRenderer(String name)
: this(name, new Dictionary<String, String>()) {
}
public DummySvgNodeRenderer(String name, IDictionary<String, String> attr) {
this.name = name;
this.attributes = attr;
}
public virtual void SetParent(ISvgNodeRenderer parent) {
this.parent = parent;
}
public virtual ISvgNodeRenderer GetParent() {
return parent;
}
public virtual void Draw(SvgDrawContext context) {
System.Console.Out.WriteLine(name + ": Drawing in dummy node");
this.drawn = true;
}
public virtual void SetAttributesAndStyles(IDictionary<String, String> attributesAndStyles) {
this.attributes = attributesAndStyles;
}
public virtual String GetAttribute(String key) {
if (SvgConstants.Attributes.WIDTH.EqualsIgnoreCase(key) || SvgConstants.Attributes.HEIGHT.EqualsIgnoreCase
(key)) {
return "10";
}
return this.attributes.Get(key);
}
public virtual void SetAttribute(String key, String value) {
this.attributes.Put(key, value);
}
public virtual IDictionary<String, String> GetAttributeMapCopy() {
return null;
}
public virtual ISvgNodeRenderer CreateDeepCopy() {
return new TSpdf.Svg.Dummy.Renderers.Impl.DummySvgNodeRenderer(name);
}
public override String ToString() {
return name;
}
public override bool Equals(Object o) {
if (!(o is TSpdf.Svg.Dummy.Renderers.Impl.DummySvgNodeRenderer)) {
return false;
}
//Name
TSpdf.Svg.Dummy.Renderers.Impl.DummySvgNodeRenderer otherDummy = (TSpdf.Svg.Dummy.Renderers.Impl.DummySvgNodeRenderer
)o;
return this.name.Equals(otherDummy.name);
}
public virtual Rectangle GetObjectBoundingBox(SvgDrawContext context) {
return null;
}
public virtual bool IsDrawn() {
return this.drawn;
}
}
}

View File

@@ -0,0 +1,105 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: Bruno Lowagie, Paulo Soares, et al.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace TSpdf.Svg.Dummy.Sdk
{
public class ExceptionInputStream : Stream
{
public ExceptionInputStream()
{
}
public override bool CanRead
{
get { return true; }
}
public override bool CanSeek
{
get { return true; }
}
public override bool CanWrite
{
get { return true; }
}
public override long Length
{
get { return 0; }
}
public override long Position { get; set; }
public override void Flush()
{
throw new IOException();
}
public override int Read(byte[] buffer, int offset, int count)
{
throw new IOException();
}
public override long Seek(long offset, SeekOrigin origin)
{
throw new IOException();
}
public override void SetLength(long value)
{
throw new IOException();
}
public override void Write(byte[] buffer, int offset, int count)
{
throw new IOException();
}
}
}

View File

@@ -0,0 +1,76 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using TSpdf.Svg.Renderers;
using TSpdf.Test;
namespace TSpdf.Svg.Googlecharts {
[NUnit.Framework.Category("IntegrationTest")]
public class ColumnChartsTest : SvgIntegrationTest {
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/googlecharts/ColumnChartsTest/";
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/googlecharts/ColumnChartsTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateDestinationFolder(destinationFolder);
}
[NUnit.Framework.Test]
public virtual void ColumnDualYChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "columnDualYChart");
}
[NUnit.Framework.Test]
public virtual void ColumnMaterialChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "columnMaterialChart");
}
[NUnit.Framework.Test]
public virtual void ColumnTopXChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "columnTopXChart");
}
}
}

View File

@@ -0,0 +1,100 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using TSpdf.Kernel.Geom;
using TSpdf.Kernel.Utils;
using TSpdf.Svg.Renderers;
using TSpdf.Svg.Utils;
using TSpdf.Test;
namespace TSpdf.Svg.Googlecharts {
[NUnit.Framework.Category("IntegrationTest")]
public class GanttChartsTest : SvgIntegrationTest {
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/googlecharts/GanttChartsTest/";
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/googlecharts/GanttChartsTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateDestinationFolder(destinationFolder);
}
[NUnit.Framework.Test]
public virtual void GanttChart() {
PageSize pageSize = PageSize.A4;
TestUtils.ConvertSVGtoPDF(destinationFolder + "ganttChart.pdf", sourceFolder + "ganttChart.svg", 1, pageSize
);
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "ganttChart.pdf", sourceFolder
+ "cmp_ganttChart.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void Gantt2Chart() {
PageSize pageSize = PageSize.A4;
TestUtils.ConvertSVGtoPDF(destinationFolder + "gantt2Chart.pdf", sourceFolder + "gantt2Chart.svg", 1, pageSize
);
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "gantt2Chart.pdf", sourceFolder
+ "cmp_gantt2Chart.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void Gantt3Chart() {
PageSize pageSize = PageSize.A4;
TestUtils.ConvertSVGtoPDF(destinationFolder + "gantt3Chart.pdf", sourceFolder + "gantt3Chart.svg", 1, pageSize
);
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "gantt3Chart.pdf", sourceFolder
+ "cmp_gantt3Chart.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void Gantt4Chart() {
PageSize pageSize = PageSize.A4;
TestUtils.ConvertSVGtoPDF(destinationFolder + "gantt4Chart.pdf", sourceFolder + "gantt4Chart.svg", 1, pageSize
);
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "gantt4Chart.pdf", sourceFolder
+ "cmp_gantt4Chart.pdf", destinationFolder, "diff_"));
}
}
}

View File

@@ -0,0 +1,76 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using TSpdf.Svg.Renderers;
using TSpdf.Test;
namespace TSpdf.Svg.Googlecharts {
[NUnit.Framework.Category("IntegrationTest")]
public class GaugeChartsTest : SvgIntegrationTest {
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/googlecharts/GaugeChartsTest/";
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/googlecharts/GaugeChartsTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateDestinationFolder(destinationFolder);
}
[NUnit.Framework.Test]
public virtual void GaugeCharts() {
ConvertAndCompare(sourceFolder, destinationFolder, "gaugeChart");
}
[NUnit.Framework.Test]
public virtual void Gauge2Charts() {
ConvertAndCompare(sourceFolder, destinationFolder, "gauge2Chart");
}
[NUnit.Framework.Test]
public virtual void Gauge3Charts() {
ConvertAndCompare(sourceFolder, destinationFolder, "gauge3Chart");
}
}
}

View File

@@ -0,0 +1,86 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using TSpdf.Svg.Renderers;
using TSpdf.Test;
namespace TSpdf.Svg.Googlecharts {
[NUnit.Framework.Category("IntegrationTest")]
public class GeoChartsTest : SvgIntegrationTest {
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/googlecharts/GeoChartsTest/";
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/googlecharts/GeoChartsTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateDestinationFolder(destinationFolder);
}
[NUnit.Framework.Test]
public virtual void GeoChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "geoChart");
}
[NUnit.Framework.Test]
public virtual void GeoColoredChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "geoColoredChart");
}
[NUnit.Framework.Test]
public virtual void GeoMarkerChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "geoMarkerChart");
}
[NUnit.Framework.Test]
public virtual void GeoPropontionalChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "geoPropontionalChart");
}
[NUnit.Framework.Test]
public virtual void GeoTextChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "geoTextChart");
}
}
}

View File

@@ -0,0 +1,136 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using TSpdf.Kernel.Geom;
using TSpdf.Kernel.Utils;
using TSpdf.Svg.Renderers;
using TSpdf.Svg.Utils;
using TSpdf.Test;
namespace TSpdf.Svg.Googlecharts {
[NUnit.Framework.Category("IntegrationTest")]
public class GoogleChartsTest : SvgIntegrationTest {
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/googlecharts/GoogleChartsTest/";
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/googlecharts/GoogleChartsTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateDestinationFolder(destinationFolder);
}
[NUnit.Framework.Test]
public virtual void BarChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "barChart");
}
[NUnit.Framework.Test]
public virtual void AnnotationChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "annotationChart");
}
[NUnit.Framework.Test]
public virtual void AreaChart() {
PageSize pageSize = PageSize.A4;
TestUtils.ConvertSVGtoPDF(destinationFolder + "areaChart.pdf", sourceFolder + "areaChart.svg", 1, pageSize
);
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "areaChart.pdf", sourceFolder
+ "cmp_areaChart.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void BubbleChart() {
PageSize pageSize = PageSize.A4;
TestUtils.ConvertSVGtoPDF(destinationFolder + "bubbleChart.pdf", sourceFolder + "bubbleChart.svg", 1, pageSize
);
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "bubbleChart.pdf", sourceFolder
+ "cmp_bubbleChart.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void CalendarChart() {
//TODO DEVSIX-4857 support stroke-linecap attribute
PageSize pageSize = PageSize.A4;
TestUtils.ConvertSVGtoPDF(destinationFolder + "calendarChart.pdf", sourceFolder + "calendarChart.svg", 1,
pageSize);
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "calendarChart.pdf",
sourceFolder + "cmp_calendarChart.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void CandlestickChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "candlestickChart");
}
[NUnit.Framework.Test]
public virtual void ComboChart() {
PageSize pageSize = PageSize.A4;
TestUtils.ConvertSVGtoPDF(destinationFolder + "comboChart.pdf", sourceFolder + "comboChart.svg", 1, pageSize
);
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "comboChart.pdf", sourceFolder
+ "cmp_comboChart.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void DiffChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "diffChart");
}
[NUnit.Framework.Test]
public virtual void DonutChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "donutChart");
}
[NUnit.Framework.Test]
public virtual void WaterfallChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "waterfallChart");
}
[NUnit.Framework.Test]
public virtual void HistogramChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "histogramChart");
}
}
}

View File

@@ -0,0 +1,121 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using TSpdf.Svg.Renderers;
using TSpdf.Test;
namespace TSpdf.Svg.Googlecharts {
[NUnit.Framework.Category("IntegrationTest")]
public class IntervalsChartsTest : SvgIntegrationTest {
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/googlecharts/IntervalsChartsTest/";
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/googlecharts/IntervalsChartsTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateDestinationFolder(destinationFolder);
}
[NUnit.Framework.Test]
public virtual void IntervalsAreaChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "intervalsAreaChart");
}
[NUnit.Framework.Test]
public virtual void IntervalsBackgroundBoxChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "intervalsBackgroundBoxChart");
}
[NUnit.Framework.Test]
public virtual void IntervalsBoxChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "intervalsBoxChart");
}
[NUnit.Framework.Test]
public virtual void IntervalsBoxPlotChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "intervalsBoxPlotChart");
}
[NUnit.Framework.Test]
public virtual void IntervalsBoxThickChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "intervalsBoxThickChart");
}
[NUnit.Framework.Test]
public virtual void IntervalsCombiningChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "intervalsCombiningChart");
}
[NUnit.Framework.Test]
public virtual void IntervalsLineChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "intervalsLineChart");
}
[NUnit.Framework.Test]
public virtual void IntervalsPointsChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "intervalsPointsChart");
}
[NUnit.Framework.Test]
public virtual void IntervalsPointsWhiskersChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "intervalsPointsWhiskersChart");
}
[NUnit.Framework.Test]
public virtual void IntervalsStickChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "intervalsStickChart");
}
[NUnit.Framework.Test]
public virtual void IntervalsSticksHorizontalChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "intervalsSticksHorizontalChart");
}
[NUnit.Framework.Test]
public virtual void IntervalsTailoredChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "intervalsTailoredChart");
}
}
}

View File

@@ -0,0 +1,81 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using TSpdf.Svg.Renderers;
using TSpdf.Test;
namespace TSpdf.Svg.Googlecharts {
[NUnit.Framework.Category("IntegrationTest")]
public class LineChartsTest : SvgIntegrationTest {
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/googlecharts/LineChartsTest/";
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/googlecharts/LineChartsTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateDestinationFolder(destinationFolder);
}
[NUnit.Framework.Test]
public virtual void LineChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "lineChart");
}
[NUnit.Framework.Test]
public virtual void LineClassicChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "lineClassicChart");
}
[NUnit.Framework.Test]
public virtual void LineMaterialChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "lineMaterialChart");
}
[NUnit.Framework.Test]
public virtual void LineTopXChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "lineTopXChart");
}
}
}

View File

@@ -0,0 +1,86 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using TSpdf.Svg.Renderers;
using TSpdf.Test;
namespace TSpdf.Svg.Googlecharts {
[NUnit.Framework.Category("IntegrationTest")]
public class PieChartsTest : SvgIntegrationTest {
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/googlecharts/PieChartsTest/";
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/googlecharts/PieChartsTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateDestinationFolder(destinationFolder);
}
[NUnit.Framework.Test]
public virtual void PieChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "pieChart");
}
[NUnit.Framework.Test]
public virtual void Pie3DChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "pie3DChart");
}
[NUnit.Framework.Test]
public virtual void PieHoleChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "pieHoleChart");
}
[NUnit.Framework.Test]
public virtual void RotatingPieChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "rotatingPieChart");
}
[NUnit.Framework.Test]
public virtual void Pie1Chart() {
ConvertAndCompare(sourceFolder, destinationFolder, "pie1Chart");
}
}
}

View File

@@ -0,0 +1,92 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using TSpdf.Svg.Renderers;
using TSpdf.Test;
namespace TSpdf.Svg.Googlecharts {
[NUnit.Framework.Category("IntegrationTest")]
public class SankeyChartsTest : SvgIntegrationTest {
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/googlecharts/SankeyChartsTest/";
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/googlecharts/SankeyChartsTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateDestinationFolder(destinationFolder);
}
[NUnit.Framework.Test]
public virtual void SankeyBordersChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "sankeyBordersChart");
}
[NUnit.Framework.Test]
public virtual void SankeyChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "sankeyChart");
}
[NUnit.Framework.Test]
public virtual void SankeyColoredChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "sankeyColoredChart");
}
[NUnit.Framework.Test]
public virtual void SankeyFontsChart() {
// TODO DEVSIX-2905
ConvertAndCompare(sourceFolder, destinationFolder, "sankeyFontsChart");
}
[NUnit.Framework.Test]
public virtual void SankeyMultilevelChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "sankeyMultilevelChart");
}
[NUnit.Framework.Test]
public virtual void SankeyNodesChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "sankeyNodesChart");
}
}
}

View File

@@ -0,0 +1,86 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using TSpdf.Svg.Renderers;
using TSpdf.Test;
namespace TSpdf.Svg.Googlecharts {
[NUnit.Framework.Category("IntegrationTest")]
public class ScatterChartsTest : SvgIntegrationTest {
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/googlecharts/ScatterChartsTest/";
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/googlecharts/ScatterChartsTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateDestinationFolder(destinationFolder);
}
[NUnit.Framework.Test]
public virtual void ScatterCharts() {
ConvertAndCompare(sourceFolder, destinationFolder, "scatterCharts");
}
[NUnit.Framework.Test]
public virtual void ScatterDualYChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "scatterDualYChart");
}
[NUnit.Framework.Test]
public virtual void ScatterMaterialChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "scatterMaterialChart");
}
[NUnit.Framework.Test]
public virtual void ScatterStarsChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "scatterStarsChart");
}
[NUnit.Framework.Test]
public virtual void ScatterTopXChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "scatterTopXChart");
}
}
}

View File

@@ -0,0 +1,71 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using TSpdf.Svg.Renderers;
using TSpdf.Test;
namespace TSpdf.Svg.Googlecharts {
[NUnit.Framework.Category("IntegrationTest")]
public class SliceChartsTest : SvgIntegrationTest {
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/googlecharts/SliceChartsTest/";
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/googlecharts/SliceChartsTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateDestinationFolder(destinationFolder);
}
[NUnit.Framework.Test]
public virtual void ExplodingSliceChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "explodingSliceChart");
}
[NUnit.Framework.Test]
public virtual void RemovingSliceChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "removingSliceChart");
}
}
}

View File

@@ -0,0 +1,76 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using TSpdf.Svg.Renderers;
using TSpdf.Test;
namespace TSpdf.Svg.Googlecharts {
[NUnit.Framework.Category("IntegrationTest")]
public class SteppedAreaChartTest : SvgIntegrationTest {
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/googlecharts/SteppedAreaChartsTest/";
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/googlecharts/SteppedAreaChartsTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateDestinationFolder(destinationFolder);
}
[NUnit.Framework.Test]
public virtual void SteppedAreaChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "steppedAreaChart");
}
[NUnit.Framework.Test]
public virtual void SteppedArea2Chart() {
ConvertAndCompare(sourceFolder, destinationFolder, "steppedArea2Chart");
}
[NUnit.Framework.Test]
public virtual void SteppedArea3Chart() {
ConvertAndCompare(sourceFolder, destinationFolder, "steppedArea3Chart");
}
}
}

View File

@@ -0,0 +1,83 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using TSpdf.Kernel.Geom;
using TSpdf.Kernel.Utils;
using TSpdf.Svg.Renderers;
using TSpdf.Svg.Utils;
using TSpdf.Test;
namespace TSpdf.Svg.Googlecharts {
[NUnit.Framework.Category("IntegrationTest")]
public class TimelineChartsTest : SvgIntegrationTest {
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/googlecharts/TimelineChartsTest/";
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/googlecharts/TimelineChartsTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateDestinationFolder(destinationFolder);
}
[NUnit.Framework.Test]
public virtual void TimelineAdvancedChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "timelineAdvancedChart");
}
[NUnit.Framework.Test]
public virtual void TimelineChart() {
PageSize pageSize = PageSize.A4;
TestUtils.ConvertSVGtoPDF(destinationFolder + "timelineChart.pdf", sourceFolder + "timelineChart.svg", 1,
pageSize);
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "timelineChart.pdf",
sourceFolder + "cmp_timelineChart.pdf", destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void TimelineLabeledChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "timelineLabeledChart");
}
}
}

View File

@@ -0,0 +1,71 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using TSpdf.Svg.Renderers;
using TSpdf.Test;
namespace TSpdf.Svg.Googlecharts {
[NUnit.Framework.Category("IntegrationTest")]
public class TreemapsChartsTest : SvgIntegrationTest {
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/googlecharts/TreemapsChartsTest/";
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/googlecharts/TreemapsChartsTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateDestinationFolder(destinationFolder);
}
[NUnit.Framework.Test]
public virtual void TreemapsChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "treemapsChart");
}
[NUnit.Framework.Test]
public virtual void Treemaps2Chart() {
ConvertAndCompare(sourceFolder, destinationFolder, "treemaps2Chart");
}
}
}

View File

@@ -0,0 +1,86 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using TSpdf.Svg.Renderers;
using TSpdf.Test;
namespace TSpdf.Svg.Googlecharts {
[NUnit.Framework.Category("IntegrationTest")]
public class TrendlinesChartsTest : SvgIntegrationTest {
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/googlecharts/TrendlinesChartsTest/";
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/googlecharts/TrendlinesChartsTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateDestinationFolder(destinationFolder);
}
[NUnit.Framework.Test]
public virtual void TrendlinesChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "trendlinesChart");
}
[NUnit.Framework.Test]
public virtual void Trendlines2Chart() {
ConvertAndCompare(sourceFolder, destinationFolder, "trendlines2Chart");
}
[NUnit.Framework.Test]
public virtual void Trendlines3Chart() {
ConvertAndCompare(sourceFolder, destinationFolder, "trendlines3Chart");
}
[NUnit.Framework.Test]
public virtual void Trendlines4Chart() {
ConvertAndCompare(sourceFolder, destinationFolder, "trendlines4Chart");
}
[NUnit.Framework.Test]
public virtual void Trendlines5Chart() {
ConvertAndCompare(sourceFolder, destinationFolder, "trendlines5Chart");
}
}
}

View File

@@ -0,0 +1,85 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using TSpdf.Kernel.Geom;
using TSpdf.Svg.Renderers;
using TSpdf.Test;
namespace TSpdf.Svg.Googlecharts {
[NUnit.Framework.Category("IntegrationTest")]
public class WordTreesChartsTest : SvgIntegrationTest {
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/googlecharts/WordTreesChartsTest/";
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/googlecharts/WordTreesChartsTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateDestinationFolder(destinationFolder);
}
[NUnit.Framework.Test]
public virtual void WordTreesChart() {
ConvertAndCompare(sourceFolder, destinationFolder, "wordTreesChart");
}
[NUnit.Framework.Test]
public virtual void WordTrees2Chart() {
//TODO update cmp file after DEVSIX-4136 will be fixed (opacity gradient)
ConvertAndCompare(sourceFolder, destinationFolder, "wordTrees2Chart", PageSize.A1);
}
[NUnit.Framework.Test]
public virtual void WordTrees3Chart() {
//TODO update cmp file after DEVSIX-4136 will be fixed (opacity gradient)
ConvertAndCompare(sourceFolder, destinationFolder, "wordTrees3Chart", PageSize.A1);
}
[NUnit.Framework.Test]
public virtual void WordTrees4Chart() {
//TODO update cmp file after DEVSIX-4136 will be fixed (opacity gradient)
ConvertAndCompare(sourceFolder, destinationFolder, "wordTrees4Chart", PageSize.A1);
}
}
}

View File

@@ -0,0 +1,119 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using TSpdf.Svg.Renderers;
using TSpdf.Test;
namespace TSpdf.Svg.Jfreesvg {
[NUnit.Framework.Category("IntegrationTest")]
public class JFreeSvgTest : SvgIntegrationTest {
private static readonly String SOURCE_FOLDER = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/JFreeSvgTest/";
private static readonly String DESTINATION_FOLDER = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/JFreeSvgTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateDestinationFolder(DESTINATION_FOLDER);
}
//Do not make changes in svg file because it was generated by JFreeSVG
[NUnit.Framework.Test]
public virtual void UsingJFreeSvgFromStringTest() {
//TODO: update cmp-file when DEVSIX-2246 will be fixed
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "rectangleFromStringTest");
}
//Do not make changes in svg file because it was generated by JFreeSVG
[NUnit.Framework.Test]
public virtual void UsingJFreeSvgFromFileTest() {
//TODO: update cmp-file when DEVSIX-2246 will be fixed
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "rectangleFromFileTest");
}
//Do not make changes in svg file because it was generated by JFreeSVG
[NUnit.Framework.Test]
public virtual void PieChartByJFreeSvgTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "usingJFreeSvgPieChartFromFileTest");
}
//Do not make changes in svg file because it was generated by JFreeSVG
[NUnit.Framework.Test]
public virtual void BarChartByJFreeSvgFromStringTest() {
//TODO: update cmp file when DEVSIX-4043 will be fixed
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "usingJFreeSvgBarChartFromStringTest");
}
//Do not make changes in svg file because it was generated by JFreeSVG
[NUnit.Framework.Test]
public virtual void BarChartByJFreeSvgFromFileTest() {
//TODO: update cmp file when DEVSIX-4043 will be fixed
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "usingJFreeSvgBarChartFromFileTest");
}
//Do not make changes in svg file because it was generated by JFreeSVG
[NUnit.Framework.Test]
public virtual void LineChartByJFreeSvgFromStringTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "usingJFreeSvgLineChartFromStringTest");
}
//Do not make changes in svg file because it was generated by JFreeSVG
[NUnit.Framework.Test]
public virtual void LineChartByJFreeSvgFromFileTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "usingJFreeSvgLineChartFromFileTest");
}
//Do not make changes in svg file because it was generated by JFreeSVG
[NUnit.Framework.Test]
public virtual void XyChartByJFreeSvgFromStringTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "usingJFreeSvgXYChartFromStringTest");
}
//Do not make changes in svg file because it was generated by JFreeSVG
[NUnit.Framework.Test]
public virtual void XyChartByJFreeSvgFromFileTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "usingJFreeSvgXYChartFromFileTest");
}
}
}

View File

@@ -0,0 +1,93 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using System.Collections.Generic;
using System.IO;
using TSpdf.StyledXmlParser.Node;
using TSpdf.StyledXmlParser.Node.Impl.Jsoup;
using TSpdf.Svg.Processors.Impl;
using TSpdf.Svg.Renderers;
namespace TSpdf.Svg.Processors {
[NUnit.Framework.Category("IntegrationTest")]
public class DefaultSvgProcessorIntegrationTest : SvgIntegrationTest {
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/processors/impl/DefaultSvgProcessorIntegrationTest/";
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/processors/impl/DefaultSvgProcessorIntegrationTest/";
[NUnit.Framework.Test]
public virtual void DefaultBehaviourTest() {
String svgFile = sourceFolder + "RedCircle.svg";
Stream svg = new FileStream(svgFile, FileMode.Open, FileAccess.Read);
JsoupXmlParser xmlParser = new JsoupXmlParser();
IDocumentNode root = xmlParser.Parse(svg, null);
IBranchSvgNodeRenderer actual = (IBranchSvgNodeRenderer)new DefaultSvgProcessor().Process(root, null).GetRootRenderer
();
//Attribute comparison from the known RedCircle.svg
IDictionary<String, String> attrs = actual.GetChildren()[0].GetAttributeMapCopy();
NUnit.Framework.Assert.AreEqual(12, attrs.Keys.Count, "Number of parsed attributes is wrong");
NUnit.Framework.Assert.AreEqual("1", attrs.Get("stroke-opacity"), "The stroke-opacity attribute doesn't correspond it's value"
);
NUnit.Framework.Assert.AreEqual("1.76388889", attrs.Get("stroke-width"), "The stroke-width attribute doesn't correspond it's value"
);
NUnit.Framework.Assert.AreEqual("path3699", attrs.Get("id"), "The id attribute doesn't correspond it's value"
);
NUnit.Framework.Assert.AreEqual("none", attrs.Get("stroke-dasharray"), "The stroke-dasharray attribute doesn't correspond it's value"
);
}
[NUnit.Framework.Test]
public virtual void NamedObjectRectangleTest() {
String svgFile = sourceFolder + "namedObjectRectangleTest.svg";
Stream svg = new FileStream(svgFile, FileMode.Open, FileAccess.Read);
JsoupXmlParser xmlParser = new JsoupXmlParser();
IDocumentNode root = xmlParser.Parse(svg, null);
ISvgProcessorResult processorResult = new DefaultSvgProcessor().Process(root, null);
IDictionary<String, ISvgNodeRenderer> actual = processorResult.GetNamedObjects();
NUnit.Framework.Assert.AreEqual(1, actual.Count);
NUnit.Framework.Assert.IsTrue(actual.ContainsKey("MyRect"));
}
}
}

View File

@@ -0,0 +1,119 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using TSpdf.Svg.Dummy.Renderers.Impl;
using TSpdf.Svg.Processors.Impl;
using TSpdf.Svg.Renderers;
using TSpdf.Test;
namespace TSpdf.Svg.Processors {
[NUnit.Framework.Category("UnitTest")]
public class ProcessorStateTest : ExtendedTSpdfTest {
/// <summary>Push test</summary>
[NUnit.Framework.Test]
public virtual void ProcessorStateTestPush() {
ProcessorState testProcessorState = new ProcessorState();
ISvgNodeRenderer renderer = new DummySvgNodeRenderer("test");
testProcessorState.Push(renderer);
NUnit.Framework.Assert.IsTrue(testProcessorState.Size() == 1);
}
/// <summary>Pop test</summary>
[NUnit.Framework.Test]
public virtual void ProcessorStateTestPop() {
ProcessorState testProcessorState = new ProcessorState();
ISvgNodeRenderer renderer = new DummySvgNodeRenderer("test");
testProcessorState.Push(renderer);
ISvgNodeRenderer popped = testProcessorState.Pop();
NUnit.Framework.Assert.IsTrue(popped.ToString().Equals("test") && testProcessorState.Empty());
}
/// <summary>Peek test</summary>
[NUnit.Framework.Test]
public virtual void ProcessorStateTestPeek() {
ProcessorState testProcessorState = new ProcessorState();
ISvgNodeRenderer renderer = new DummySvgNodeRenderer("test");
testProcessorState.Push(renderer);
ISvgNodeRenderer viewed = testProcessorState.Top();
NUnit.Framework.Assert.IsTrue(viewed.ToString().Equals("test") && !testProcessorState.Empty());
}
/// <summary>Multiple push test</summary>
[NUnit.Framework.Test]
public virtual void ProcessorStateTestMultiplePushesPopAndPeek() {
ProcessorState testProcessorState = new ProcessorState();
ISvgNodeRenderer rendererOne = new DummySvgNodeRenderer("test01");
testProcessorState.Push(rendererOne);
ISvgNodeRenderer rendererTwo = new DummySvgNodeRenderer("test02");
testProcessorState.Push(rendererTwo);
ISvgNodeRenderer popped = testProcessorState.Pop();
bool result = popped.ToString().Equals("test02");
result = result && testProcessorState.Top().ToString().Equals("test01");
NUnit.Framework.Assert.IsTrue(result);
}
[NUnit.Framework.Test]
public virtual void ProcessorStateTestPopEmpty() {
ProcessorState testProcessorState = new ProcessorState();
NUnit.Framework.Assert.Catch(typeof(InvalidOperationException), () => testProcessorState.Pop());
}
[NUnit.Framework.Test]
public virtual void ProcessorStateTestPushSameElementTwice() {
ProcessorState testProcessorState = new ProcessorState();
ISvgNodeRenderer rendererOne = new DummySvgNodeRenderer("test01");
testProcessorState.Push(rendererOne);
testProcessorState.Push(rendererOne);
ISvgNodeRenderer popped = testProcessorState.Pop();
bool result = popped.ToString().Equals("test01");
result = result && testProcessorState.Top().ToString().Equals("test01");
NUnit.Framework.Assert.IsTrue(result);
}
[NUnit.Framework.Test]
public virtual void ProcessorStateTestPeekEmpty() {
ProcessorState testProcessorState = new ProcessorState();
NUnit.Framework.Assert.Catch(typeof(InvalidOperationException), () => testProcessorState.Pop());
}
}
}

View File

@@ -0,0 +1,57 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using TSpdf.Svg.Processors.Impl;
using TSpdf.Test;
namespace TSpdf.Svg.Processors {
[NUnit.Framework.Category("UnitTest")]
public class SvgConverterPropertiesTest : ExtendedTSpdfTest {
[NUnit.Framework.Test]
public virtual void GetCharsetNameRegressionTest() {
String expected = System.Text.Encoding.UTF8.Name();
String actual = new SvgConverterProperties().GetCharset();
NUnit.Framework.Assert.AreEqual(expected, actual);
}
}
}

View File

@@ -0,0 +1,309 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using System.Collections.Generic;
using TSpdf.IO.Util;
using TSpdf.StyledXmlParser.Node;
using TSpdf.StyledXmlParser.Node.Impl.Jsoup.Node;
using TSpdf.Svg;
using TSpdf.Svg.Dummy.Processors.Impl;
using TSpdf.Svg.Dummy.Renderers.Impl;
using TSpdf.Svg.Exceptions;
using TSpdf.Svg.Logs;
using TSpdf.Svg.Processors;
using TSpdf.Svg.Renderers;
using TSpdf.Svg.Renderers.Impl;
using TSpdf.Test;
using TSpdf.Test.Attributes;
namespace TSpdf.Svg.Processors.Impl {
[NUnit.Framework.Category("UnitTest")]
public class DefaultSvgProcessorUnitTest : ExtendedTSpdfTest {
//Main success scenario
/// <summary>Simple correct example</summary>
[NUnit.Framework.Test]
public virtual void DummyProcessingTestCorrectSimple() {
//Setup nodes
TSpdf.StyledXmlParser.Jsoup.Nodes.Element jsoupSVGRoot = new TSpdf.StyledXmlParser.Jsoup.Nodes.Element(TSpdf.StyledXmlParser.Jsoup.Parser.Tag
.ValueOf("svg"), "");
TSpdf.StyledXmlParser.Jsoup.Nodes.Element jsoupSVGCircle = new TSpdf.StyledXmlParser.Jsoup.Nodes.Element(TSpdf.StyledXmlParser.Jsoup.Parser.Tag
.ValueOf("circle"), "");
TSpdf.StyledXmlParser.Jsoup.Nodes.Element jsoupSVGPath = new TSpdf.StyledXmlParser.Jsoup.Nodes.Element(TSpdf.StyledXmlParser.Jsoup.Parser.Tag
.ValueOf("path"), "");
INode root = new JsoupElementNode(jsoupSVGRoot);
root.AddChild(new JsoupElementNode(jsoupSVGCircle));
root.AddChild(new JsoupElementNode(jsoupSVGPath));
//Run
DefaultSvgProcessor processor = new DefaultSvgProcessor();
ISvgConverterProperties props = new DummySvgConverterProperties();
ISvgNodeRenderer rootActual = processor.Process(root, props).GetRootRenderer();
//setup expected
IBranchSvgNodeRenderer rootExpected = new DummyBranchSvgNodeRenderer("svg");
rootExpected.AddChild(new DummySvgNodeRenderer("circle"));
rootExpected.AddChild(new DummySvgNodeRenderer("path"));
//Compare
NUnit.Framework.Assert.AreEqual(rootActual, rootExpected);
}
[NUnit.Framework.Test]
public virtual void DummyProcessingTestCorrectNested() {
//Setup nodes
TSpdf.StyledXmlParser.Jsoup.Nodes.Element jsoupSVGRoot = new TSpdf.StyledXmlParser.Jsoup.Nodes.Element(TSpdf.StyledXmlParser.Jsoup.Parser.Tag
.ValueOf("svg"), "");
TSpdf.StyledXmlParser.Jsoup.Nodes.Element jsoupSVGCircle = new TSpdf.StyledXmlParser.Jsoup.Nodes.Element(TSpdf.StyledXmlParser.Jsoup.Parser.Tag
.ValueOf("circle"), "");
TSpdf.StyledXmlParser.Jsoup.Nodes.Element jsoupSVGPath = new TSpdf.StyledXmlParser.Jsoup.Nodes.Element(TSpdf.StyledXmlParser.Jsoup.Parser.Tag
.ValueOf("path"), "");
INode root = new JsoupElementNode(jsoupSVGRoot);
root.AddChild(new JsoupElementNode(jsoupSVGCircle));
root.AddChild(new JsoupElementNode(jsoupSVGPath));
INode nestedSvg = new JsoupElementNode(jsoupSVGRoot);
nestedSvg.AddChild(new JsoupElementNode(jsoupSVGCircle));
nestedSvg.AddChild(new JsoupElementNode(jsoupSVGCircle));
root.AddChild(nestedSvg);
//Run
DefaultSvgProcessor processor = new DefaultSvgProcessor();
ISvgConverterProperties props = new DummySvgConverterProperties();
ISvgNodeRenderer rootActual = processor.Process(root, props).GetRootRenderer();
//setup expected
IBranchSvgNodeRenderer rootExpected = new DummyBranchSvgNodeRenderer("svg");
rootExpected.AddChild(new DummySvgNodeRenderer("circle"));
rootExpected.AddChild(new DummySvgNodeRenderer("path"));
IBranchSvgNodeRenderer nestedSvgRend = new DummyBranchSvgNodeRenderer("svg");
nestedSvgRend.AddChild(new DummySvgNodeRenderer("circle"));
nestedSvgRend.AddChild(new DummySvgNodeRenderer("circle"));
rootExpected.AddChild(nestedSvgRend);
//Compare
NUnit.Framework.Assert.AreEqual(rootActual, rootExpected);
}
//Edge cases
[NUnit.Framework.Test]
/*
Invalid input: null
*/
[LogMessage(TSpdf.StyledXmlParser.Logs.StyledXmlParserLogMessageConstant.ERROR_ADDING_CHILD_NODE)]
public virtual void DummyProcessingTestNodeHasNullChild() {
TSpdf.StyledXmlParser.Jsoup.Nodes.Element jsoupSVGRoot = new TSpdf.StyledXmlParser.Jsoup.Nodes.Element(TSpdf.StyledXmlParser.Jsoup.Parser.Tag
.ValueOf("svg"), "");
TSpdf.StyledXmlParser.Jsoup.Nodes.Element jsoupSVGCircle = new TSpdf.StyledXmlParser.Jsoup.Nodes.Element(TSpdf.StyledXmlParser.Jsoup.Parser.Tag
.ValueOf("circle"), "");
INode root = new JsoupElementNode(jsoupSVGRoot);
root.AddChild(new JsoupElementNode(jsoupSVGCircle));
root.AddChild(null);
root.AddChild(new JsoupElementNode(jsoupSVGCircle));
//Run
DefaultSvgProcessor processor = new DefaultSvgProcessor();
ISvgConverterProperties props = new DummySvgConverterProperties();
ISvgNodeRenderer rootActual = processor.Process(root, props).GetRootRenderer();
//setup expected
ISvgNodeRenderer rootExpected = new DummySvgNodeRenderer("svg");
NUnit.Framework.Assert.AreEqual(rootExpected, rootActual);
}
[NUnit.Framework.Test]
public virtual void DummyProcessingSvgTagIsNotRootOfInput() {
TSpdf.StyledXmlParser.Jsoup.Nodes.Element jsoupRandomElement = new TSpdf.StyledXmlParser.Jsoup.Nodes.Element
(TSpdf.StyledXmlParser.Jsoup.Parser.Tag.ValueOf("body"), "");
TSpdf.StyledXmlParser.Jsoup.Nodes.Element jsoupSVGRoot = new TSpdf.StyledXmlParser.Jsoup.Nodes.Element(TSpdf.StyledXmlParser.Jsoup.Parser.Tag
.ValueOf("svg"), "");
TSpdf.StyledXmlParser.Jsoup.Nodes.Element jsoupSVGCircle = new TSpdf.StyledXmlParser.Jsoup.Nodes.Element(TSpdf.StyledXmlParser.Jsoup.Parser.Tag
.ValueOf("circle"), "");
INode root = new JsoupElementNode(jsoupRandomElement);
INode svg = new JsoupElementNode(jsoupSVGRoot);
svg.AddChild(new JsoupElementNode(jsoupSVGCircle));
root.AddChild(svg);
//Run
DefaultSvgProcessor processor = new DefaultSvgProcessor();
ISvgConverterProperties props = new DummySvgConverterProperties();
ISvgNodeRenderer rootActual = processor.Process(root, props).GetRootRenderer();
//setup expected
IBranchSvgNodeRenderer rootExpected = new DummyBranchSvgNodeRenderer("svg");
rootExpected.AddChild(new DummySvgNodeRenderer("circle"));
NUnit.Framework.Assert.AreEqual(rootActual, rootExpected);
}
[NUnit.Framework.Test]
public virtual void DummyProcessingNoSvgTagInInput() {
TSpdf.StyledXmlParser.Jsoup.Nodes.Element jsoupSVGRoot = new TSpdf.StyledXmlParser.Jsoup.Nodes.Element(TSpdf.StyledXmlParser.Jsoup.Parser.Tag
.ValueOf("polygon"), "");
TSpdf.StyledXmlParser.Jsoup.Nodes.Element jsoupSVGCircle = new TSpdf.StyledXmlParser.Jsoup.Nodes.Element(TSpdf.StyledXmlParser.Jsoup.Parser.Tag
.ValueOf("circle"), "");
INode root = new JsoupElementNode(jsoupSVGRoot);
root.AddChild(new JsoupElementNode(jsoupSVGCircle));
//Run
DefaultSvgProcessor processor = new DefaultSvgProcessor();
ISvgConverterProperties props = new DummySvgConverterProperties();
Exception e = NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => processor.Process(root, props
).GetRootRenderer());
NUnit.Framework.Assert.AreEqual(SvgExceptionMessageConstant.NO_ROOT, e.Message);
}
[NUnit.Framework.Test]
public virtual void DummyProcessingTestNullInput() {
DefaultSvgProcessor processor = new DefaultSvgProcessor();
NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => processor.Process(null, null));
}
[NUnit.Framework.Test]
public virtual void ProcessWithNullPropertiesTest() {
TSpdf.StyledXmlParser.Jsoup.Nodes.Element jsoupSVGRoot = new TSpdf.StyledXmlParser.Jsoup.Nodes.Element(TSpdf.StyledXmlParser.Jsoup.Parser.Tag
.ValueOf("svg"), "");
INode root = new JsoupElementNode(jsoupSVGRoot);
DefaultSvgProcessor processor = new DefaultSvgProcessor();
SvgConverterProperties convProps = new SvgConverterProperties();
convProps.SetRendererFactory(null);
convProps.SetCharset(null);
ISvgNodeRenderer rootRenderer = processor.Process(root, convProps).GetRootRenderer();
NUnit.Framework.Assert.IsTrue(rootRenderer is SvgTagSvgNodeRenderer);
NUnit.Framework.Assert.AreEqual(0, ((SvgTagSvgNodeRenderer)rootRenderer).GetChildren().Count);
}
[NUnit.Framework.Test]
public virtual void DefaultProcessingCorrectlyNestedRenderersTest() {
//Setup nodes
TSpdf.StyledXmlParser.Jsoup.Nodes.Element jsoupSVGRoot = new TSpdf.StyledXmlParser.Jsoup.Nodes.Element(TSpdf.StyledXmlParser.Jsoup.Parser.Tag
.ValueOf("svg"), "");
TSpdf.StyledXmlParser.Jsoup.Nodes.Element jsoupSVGCircle = new TSpdf.StyledXmlParser.Jsoup.Nodes.Element(TSpdf.StyledXmlParser.Jsoup.Parser.Tag
.ValueOf("circle"), "");
TSpdf.StyledXmlParser.Jsoup.Nodes.Element jsoupSVGPath = new TSpdf.StyledXmlParser.Jsoup.Nodes.Element(TSpdf.StyledXmlParser.Jsoup.Parser.Tag
.ValueOf("path"), "");
INode root = new JsoupElementNode(jsoupSVGRoot);
root.AddChild(new JsoupElementNode(jsoupSVGCircle));
root.AddChild(new JsoupElementNode(jsoupSVGPath));
//Run
DefaultSvgProcessor processor = new DefaultSvgProcessor();
SvgConverterProperties convProps = new SvgConverterProperties();
ISvgNodeRenderer rootRenderer = processor.Process(root, convProps).GetRootRenderer();
NUnit.Framework.Assert.IsTrue(rootRenderer is SvgTagSvgNodeRenderer);
IList<ISvgNodeRenderer> children = ((SvgTagSvgNodeRenderer)rootRenderer).GetChildren();
NUnit.Framework.Assert.AreEqual(2, children.Count);
NUnit.Framework.Assert.IsTrue(children[0] is CircleSvgNodeRenderer);
NUnit.Framework.Assert.IsTrue(children[1] is PathSvgNodeRenderer);
}
[NUnit.Framework.Test]
public virtual void FindFirstElementNullTest() {
DefaultSvgProcessor processor = new DefaultSvgProcessor();
IElementNode actual = processor.FindFirstElement(null, "name");
NUnit.Framework.Assert.IsNull(actual);
}
[NUnit.Framework.Test]
[LogMessage(SvgLogMessageConstant.UNMAPPED_TAG)]
public virtual void DepthFirstNullRendererTest() {
TSpdf.StyledXmlParser.Jsoup.Nodes.Element jsoupNonExistingElement = new TSpdf.StyledXmlParser.Jsoup.Nodes.Element
(TSpdf.StyledXmlParser.Jsoup.Parser.Tag.ValueOf("nonExisting"), "");
INode root = new JsoupElementNode(jsoupNonExistingElement);
DefaultSvgProcessor dsp = new DefaultSvgProcessor();
ISvgConverterProperties scp = new SvgConverterProperties();
dsp.PerformSetup(root, scp);
// below method must not throw a NullPointerException
NUnit.Framework.Assert.DoesNotThrow(() => dsp.ExecuteDepthFirstTraversal(root));
}
[NUnit.Framework.Test]
public virtual void XLinkAttributeBaseDirDoesNotExistTest() {
INode root = CreateSvgContainingImage();
String resolvedBaseUrl = "/i7j/TSpdfcore";
String baseUrl = resolvedBaseUrl + "/wrongDirName";
ISvgConverterProperties props = new SvgConverterProperties().SetBaseUri(baseUrl);
SvgTagSvgNodeRenderer rootActual = (SvgTagSvgNodeRenderer)Processor().Process(root, props).GetRootRenderer
();
String fileName = resolvedBaseUrl + "/img.png";
String expectedURL = UrlUtil.ToNormalizedURI(fileName).ToString();
String expectedURLAnotherValidVersion = CreateAnotherValidUrlVersion(expectedURL);
ISvgNodeRenderer imageRendered = rootActual.GetChildren()[0];
String url = imageRendered.GetAttribute(SvgConstants.Attributes.XLINK_HREF);
// Both variants(namely with triple and single slashes) are valid.
NUnit.Framework.Assert.IsTrue(expectedURL.Equals(url) || expectedURLAnotherValidVersion.Equals(url));
}
[NUnit.Framework.Test]
public virtual void XLinkAttributeResolveNonEmptyBaseUrlTest() {
INode root = CreateSvgContainingImage();
String baseUrl = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext.CurrentContext.
TestDirectory) + "/resources/TSpdf/svg/processors/impl/DefaultSvgProcessorIntegrationTest";
ISvgConverterProperties props = new SvgConverterProperties().SetBaseUri(baseUrl);
SvgTagSvgNodeRenderer rootActual = (SvgTagSvgNodeRenderer)Processor().Process(root, props).GetRootRenderer
();
String fileName = baseUrl + "/img.png";
String expectedURL = UrlUtil.ToNormalizedURI(fileName).ToString();
String expectedURLAnotherValidVersion = CreateAnotherValidUrlVersion(expectedURL);
ISvgNodeRenderer imageRendered = rootActual.GetChildren()[0];
String url = imageRendered.GetAttribute(SvgConstants.Attributes.XLINK_HREF);
// Both variants(namely with triple and single slashes) are valid.
NUnit.Framework.Assert.IsTrue(expectedURL.Equals(url) || expectedURLAnotherValidVersion.Equals(url));
}
private INode CreateSvgContainingImage() {
TSpdf.StyledXmlParser.Jsoup.Nodes.Element jsoupSVGRoot = new TSpdf.StyledXmlParser.Jsoup.Nodes.Element(TSpdf.StyledXmlParser.Jsoup.Parser.Tag
.ValueOf("svg"), "");
TSpdf.StyledXmlParser.Jsoup.Nodes.Attributes attr = new TSpdf.StyledXmlParser.Jsoup.Nodes.Attributes();
attr.Put(SvgConstants.Attributes.XLINK_HREF, "img.png");
TSpdf.StyledXmlParser.Jsoup.Nodes.Element jsoupSVGImage = new TSpdf.StyledXmlParser.Jsoup.Nodes.Element(TSpdf.StyledXmlParser.Jsoup.Parser.Tag
.ValueOf("image"), "", attr);
INode root = new JsoupElementNode(jsoupSVGRoot);
root.AddChild(new JsoupElementNode(jsoupSVGImage));
return root;
}
private static String CreateAnotherValidUrlVersion(String url) {
if (url.StartsWith("file:///")) {
return "file:/" + url.Substring("file:///".Length);
}
else {
if (url.StartsWith("file:/")) {
return "file:///" + url.Substring("file:/".Length);
}
else {
return url;
}
}
}
private static ISvgProcessor Processor() {
return new DefaultSvgProcessor();
}
}
}

View File

@@ -0,0 +1,69 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://TSpdfpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using TSpdf.IO.Font;
using TSpdf.IO.Font.Constants;
using TSpdf.Layout.Font;
using TSpdf.Svg.Exceptions;
using TSpdf.Svg.Renderers;
using TSpdf.Svg.Renderers.Impl;
using TSpdf.Test;
namespace TSpdf.Svg.Processors.Impl {
[NUnit.Framework.Category("UnitTest")]
public class SvgProcessorResultUnitTest : ExtendedTSpdfTest {
[NUnit.Framework.Test]
public virtual void ContextParameterCannotBeNullTest() {
IDictionary<String, ISvgNodeRenderer> namedObjects = new Dictionary<String, ISvgNodeRenderer>();
ISvgNodeRenderer root = new SvgTagSvgNodeRenderer();
Exception exception = NUnit.Framework.Assert.Catch(typeof(ArgumentException), () => new SvgProcessorResult
(namedObjects, root, null));
NUnit.Framework.Assert.AreEqual(SvgExceptionMessageConstant.PARAMETER_CANNOT_BE_NULL, exception.Message);
}
[NUnit.Framework.Test]
public virtual void GetFontProviderTest() {
IDictionary<String, ISvgNodeRenderer> namedObjects = new Dictionary<String, ISvgNodeRenderer>();
ISvgNodeRenderer root = new SvgTagSvgNodeRenderer();
SvgProcessorContext context = new SvgProcessorContext(new SvgConverterProperties());
SvgProcessorResult result = new SvgProcessorResult(namedObjects, root, context);
FontProvider fontProviderFromResult = result.GetFontProvider();
NUnit.Framework.Assert.IsNotNull(fontProviderFromResult);
NUnit.Framework.Assert.AreSame(context.GetFontProvider(), fontProviderFromResult);
}
[NUnit.Framework.Test]
public virtual void GetTempFontsTest() {
IDictionary<String, ISvgNodeRenderer> namedObjects = new Dictionary<String, ISvgNodeRenderer>();
ISvgNodeRenderer root = new SvgTagSvgNodeRenderer();
SvgProcessorContext context = new SvgProcessorContext(new SvgConverterProperties());
FontProgram fp = FontProgramFactory.CreateFont(StandardFonts.HELVETICA);
context.AddTemporaryFont(fp, PdfEncodings.IDENTITY_H, "");
SvgProcessorResult result = new SvgProcessorResult(namedObjects, root, context);
FontSet tempFontsFromResult = result.GetTempFonts();
NUnit.Framework.Assert.IsNotNull(tempFontsFromResult);
NUnit.Framework.Assert.AreSame(context.GetTempFonts(), tempFontsFromResult);
}
}
}

View File

@@ -0,0 +1,328 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using System.IO;
using TSpdf.Commons.Utils;
using TSpdf.Kernel.Pdf;
using TSpdf.StyledXmlParser.Css.Media;
using TSpdf.StyledXmlParser.Resolver.Font;
using TSpdf.Svg.Logs;
using TSpdf.Svg.Processors;
using TSpdf.Svg.Processors.Impl;
using TSpdf.Svg.Renderers;
using TSpdf.Test;
using TSpdf.Test.Attributes;
namespace TSpdf.Svg.Processors.Impl.Font {
[NUnit.Framework.Category("IntegrationTest")]
public class FontFaceTest : SvgIntegrationTest {
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/processors/impl/font/FontFaceTest/";
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/processors/impl/font/FontFaceTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateDestinationFolder(destinationFolder);
}
[NUnit.Framework.Test]
public virtual void UnicodeRangeTest() {
// TODO fix cmp file after DEVSIX-2256 is finished. Right now unicode range is not processed correctly
ConvertAndCompare(sourceFolder, destinationFolder, "unicodeRangeTest");
}
[NUnit.Framework.Test]
public virtual void DroidSerifSingleQuotesTest() {
// TODO fix cmp file after DEVSIX-2534 is finished. Right now droid fonts are not applied if
// their aliases are inside single quotes and contain spaces
ConvertAndCompare(sourceFolder, destinationFolder, "droidSerifSingleQuotesTest");
}
[NUnit.Framework.Test]
public virtual void DroidSerifWebFontTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "droidSerifWebFontTest");
}
[NUnit.Framework.Test]
public virtual void DroidSerifLocalFontTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "droidSerifLocalFontTest");
}
[NUnit.Framework.Test]
public virtual void DroidSerifLocalLocalFontTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "droidSerifLocalLocalFontTest");
}
[NUnit.Framework.Test]
public virtual void DroidSerifLocalWithMediaFontTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "droidSerifLocalWithMediaFontTest");
}
[NUnit.Framework.Test]
public virtual void DroidSerifLocalWithMediaRuleFontTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "droidSerifLocalWithMediaRuleFontTest");
}
[NUnit.Framework.Test]
public virtual void FontSelectorTest01() {
ConvertAndCompare(sourceFolder, destinationFolder, "fontSelectorTest01");
}
[NUnit.Framework.Test]
public virtual void FontFaceGrammarTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "fontFaceGrammarTest");
}
[NUnit.Framework.Test]
public virtual void FontFaceWoffTest01() {
RunTest("fontFaceWoffTest01");
}
[NUnit.Framework.Test]
public virtual void FontFaceWoffTest02() {
RunTest("fontFaceWoffTest02");
}
[NUnit.Framework.Test]
[LogMessage(SvgLogMessageConstant.UNABLE_TO_RETRIEVE_FONT)]
public virtual void FontFaceTtcTest() {
//TODO (DEVSIX-2064) Cannot retrieve NotoSansCJK-Regular
RunTest("fontFaceTtcTest");
}
[NUnit.Framework.Test]
public virtual void FontFaceWoff2SimpleTest() {
RunTest("fontFaceWoff2SimpleTest");
}
[NUnit.Framework.Test]
[LogMessage(SvgLogMessageConstant.UNABLE_TO_RETRIEVE_FONT)]
public virtual void FontFaceWoff2TtcTest() {
//TODO (DEVSIX-2064) Cannot retrieve NotoSansCJK-Regular
RunTest("fontFaceWoff2TtcTest");
}
[NUnit.Framework.Test]
public virtual void W3cProblemTest01() {
//TODO(DEVSIX-5755): In w3c test suite this font is labeled as invalid though it correctly parsers both in browser and TSpdf
//See BlocksMetadataPadding001Test in io for decompression details
RunTest("w3cProblemTest01");
}
[NUnit.Framework.Test]
public virtual void W3cProblemTest02() {
try {
RunTest("w3cProblemTest02");
}
catch (OverflowException) {
return;
}
NUnit.Framework.Assert.Fail("In w3c test suite this font is labeled as invalid, " + "so the invalid negative value is expected while creating a glyph."
);
}
[NUnit.Framework.Test]
public virtual void W3cProblemTest03() {
//TODO(DEVSIX-5756): silently omitted, decompression should fail.
//See HeaderFlavor001Test in io for decompression details
RunTest("w3cProblemTest03");
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.IO.Logs.IoLogMessageConstant.FONT_SUBSET_ISSUE)]
public virtual void W3cProblemTest04() {
//TODO(DEVSIX-5756): silently omitted, decompression should fail. Browser loads font but don't draw glyph.
//See HeaderFlavor002Test in io for decompression details
//NOTE, TSpdf fails on subsetting as expected.
RunTest("w3cProblemTest04");
}
[NUnit.Framework.Test]
public virtual void W3cProblemTest05() {
//TODO(DEVSIX-5755): In w3c test suite this font is labeled as invalid though it correctly parsers both in browser and TSpdf
//See HeaderReserved001Test in io for decompression details
RunTest("w3cProblemTest05");
}
[NUnit.Framework.Test]
public virtual void W3cProblemTest06() {
//TODO(DEVSIX-5755): In w3c test suite this font is labeled as invalid though it correctly parsers both in browser and TSpdf
//See TabledataHmtxTransform003Test in io for decompression details
RunTest("w3cProblemTest06");
}
[NUnit.Framework.Test]
public virtual void W3cProblemTest07() {
try {
RunTest("w3cProblemTest07");
}
catch (OverflowException) {
return;
}
NUnit.Framework.Assert.Fail("In w3c test suite this font is labeled as invalid, " + "so the invalid negative value is expected while creating a glyph."
);
}
[NUnit.Framework.Test]
public virtual void IncorrectFontNameTest01() {
RunTest("incorrectFontNameTest01");
}
[NUnit.Framework.Test]
public virtual void IncorrectFontNameTest02() {
// The result of te test is FAIL. However we consider it to be correct.
// Although the font-family specified by the paragraph's class doesn't match the one of fontface,
// font's full name contains specified font-family and TSpdf takes it into account.
RunTest("incorrectFontNameTest02");
}
[NUnit.Framework.Test]
public virtual void IncorrectFontNameTest03() {
//Checks that font used in previous two files is correct
RunTest("incorrectFontNameTest03");
}
[NUnit.Framework.Test]
public virtual void IncorrectFontNameTest04() {
RunTest("incorrectFontNameTest04");
}
[NUnit.Framework.Test]
[NUnit.Framework.Ignore("DEVSIX-1759 - unicode in font family and different result in dotnet")]
public virtual void FontFamilyTest01() {
RunTest("fontFamilyTest01");
}
[NUnit.Framework.Test]
public virtual void ResolveFontsWithoutWriterProperties() {
String fileName = "fontSelectorTest";
ISvgConverterProperties properties = new SvgConverterProperties().SetFontProvider(new BasicFontProvider())
.SetMediaDeviceDescription(new MediaDeviceDescription(MediaType.ALL));
ConvertToSinglePage(new FileInfo(sourceFolder + fileName + ".svg"), new FileInfo(destinationFolder + fileName
+ ".pdf"), properties);
Compare(fileName, sourceFolder, destinationFolder);
}
[NUnit.Framework.Test]
public virtual void ResolveFontsWithoutConverterPropertiesAndWriterProperties() {
String fileName = "resolveFonts_WithoutConverterPropertiesAndWriterProperties";
String svgFile = "fontSelectorTest";
ConvertToSinglePage(new FileInfo(sourceFolder + svgFile + ".svg"), new FileInfo(destinationFolder + fileName
+ ".pdf"));
Compare(fileName, sourceFolder, destinationFolder);
}
[NUnit.Framework.Test]
public virtual void ResolveFontsWithAllProperties() {
String fileName = "resolveFonts_WithAllProperties";
String svgFile = "fontSelectorTest";
WriterProperties writerprops = new WriterProperties().SetCompressionLevel(0);
String baseUri = FileUtil.GetParentDirectoryUri(new FileInfo(sourceFolder + svgFile + ".svg"));
ISvgConverterProperties properties = new SvgConverterProperties().SetBaseUri(baseUri).SetFontProvider(new
BasicFontProvider()).SetMediaDeviceDescription(new MediaDeviceDescription(MediaType.ALL));
ConvertToSinglePage(new FileInfo(sourceFolder + svgFile + ".svg"), new FileInfo(destinationFolder + fileName
+ ".pdf"), properties, writerprops);
Compare(fileName, sourceFolder, destinationFolder);
}
[NUnit.Framework.Test]
public virtual void ResolveFontsWithWriterProperties() {
String fileName = "resolveFonts_WithWriterProperties";
String svgFile = "fontSelectorTest";
WriterProperties writerprops = new WriterProperties().SetCompressionLevel(0);
ConvertToSinglePage(new FileInfo(sourceFolder + svgFile + ".svg"), new FileInfo(destinationFolder + fileName
+ ".pdf"), writerprops);
Compare(fileName, sourceFolder, destinationFolder);
}
[NUnit.Framework.Test]
public virtual void ResolveFontsWithConverterPropsAndWriterProps() {
String fileName = "resolveFonts_WithConverterPropsAndWriterProps";
String svgFile = "fontSelectorTest";
WriterProperties writerprops = new WriterProperties().SetCompressionLevel(0);
String baseUri = FileUtil.GetParentDirectoryUri(new FileInfo(sourceFolder + svgFile + ".svg"));
ISvgConverterProperties properties = new SvgConverterProperties().SetBaseUri(baseUri).SetFontProvider(new
BasicFontProvider()).SetMediaDeviceDescription(new MediaDeviceDescription(MediaType.ALL));
ConvertToSinglePage(new FileStream(sourceFolder + svgFile + ".svg", FileMode.Open, FileAccess.Read), new FileStream
(destinationFolder + fileName + ".pdf", FileMode.Create), properties, writerprops);
Compare(fileName, sourceFolder, destinationFolder);
}
[NUnit.Framework.Test]
public virtual void ResolveFontsWithConverterPropertiesAndEmptyUri() {
String fileName = "resolveFonts_WithConverterPropertiesAndEmptyUri";
String svgFile = "fontSelectorTest";
ISvgConverterProperties properties = new SvgConverterProperties().SetBaseUri("").SetFontProvider(new BasicFontProvider
()).SetMediaDeviceDescription(new MediaDeviceDescription(MediaType.ALL));
ConvertToSinglePage(new FileInfo(sourceFolder + svgFile + ".svg"), new FileInfo(destinationFolder + fileName
+ ".pdf"), properties);
Compare(fileName, sourceFolder, destinationFolder);
}
[NUnit.Framework.Test]
public virtual void ResolveFontsWithConverterPropertiesAndNullUri() {
String fileName = "resolveFonts_WithConverterPropertiesAndNullUri";
String svgFile = "fontSelectorTest";
ISvgConverterProperties properties = new SvgConverterProperties().SetBaseUri(null).SetFontProvider(new BasicFontProvider
()).SetMediaDeviceDescription(new MediaDeviceDescription(MediaType.ALL));
ConvertToSinglePage(new FileInfo(sourceFolder + svgFile + ".svg"), new FileInfo(destinationFolder + fileName
+ ".pdf"), properties);
Compare(fileName, sourceFolder, destinationFolder);
}
[NUnit.Framework.Test]
public virtual void ResolveFontsDefaultUri() {
String fileName = "fontSelectorTest02";
ConvertToSinglePage(new FileInfo(sourceFolder + fileName + ".svg"), new FileInfo(destinationFolder + fileName
+ ".pdf"));
Compare(fileName, sourceFolder, destinationFolder);
}
private void RunTest(String fileName) {
Convert(sourceFolder + fileName + ".svg", destinationFolder + fileName + ".pdf");
Compare(fileName, sourceFolder, destinationFolder);
}
}
}

View File

@@ -0,0 +1,101 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using TSpdf.Svg.Renderers;
using TSpdf.Test;
using TSpdf.Test.Attributes;
namespace TSpdf.Svg.Processors.Impl.Font {
[NUnit.Framework.Category("IntegrationTest")]
public class FontSizeTest : SvgIntegrationTest {
public static readonly String SOURCE_FOLDER = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/processors/impl/font/FontSizeTest/";
public static readonly String DESTINATION_FOLDER = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/processors/impl/font/FontSizeTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateDestinationFolder(DESTINATION_FOLDER);
}
[NUnit.Framework.Test]
public virtual void FontSize01Test() {
String name = "fontSizeTest01";
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, name);
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.StyledXmlParser.Logs.StyledXmlParserLogMessageConstant.UNKNOWN_ABSOLUTE_METRIC_LENGTH_PARSED
)]
public virtual void FontSize02Test() {
String name = "fontSizeTest02";
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, name);
}
[NUnit.Framework.Test]
public virtual void FontSize03Test() {
String name = "fontSizeTest03";
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, name);
}
[NUnit.Framework.Test]
public virtual void FontAbsoluteKeywords() {
String name = "fontAbsoluteKeywords";
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, name);
}
[NUnit.Framework.Test]
public virtual void FontRelativeKeywords() {
String name = "fontRelativeKeywords";
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, name);
}
[NUnit.Framework.Test]
public virtual void DiffUnitsOfMeasure() {
// TODO DEVSIX-2884 rem in font-size doesn't support correctly
String name = "diff_units_of_measure";
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, name);
}
}
}

View File

@@ -0,0 +1,70 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using TSpdf.Layout.Font;
using TSpdf.StyledXmlParser.Css;
using TSpdf.StyledXmlParser.Jsoup.Nodes;
using TSpdf.StyledXmlParser.Node.Impl.Jsoup.Node;
using TSpdf.Svg.Css.Impl;
using TSpdf.Svg.Processors.Impl;
using TSpdf.Test;
namespace TSpdf.Svg.Processors.Impl.Font {
[NUnit.Framework.Category("UnitTest")]
public class SvgFontProcessorTest : ExtendedTSpdfTest {
[NUnit.Framework.Test]
public virtual void AddFontFaceFontsTest() {
TSpdf.StyledXmlParser.Jsoup.Nodes.Element styleTag = new TSpdf.StyledXmlParser.Jsoup.Nodes.Element(TSpdf.StyledXmlParser.Jsoup.Parser.Tag
.ValueOf("style"), "");
TextNode styleContents = new TextNode("\n" + "\t@font-face{\n" + "\t\tfont-family:Courier;\n" + "\t\tsrc:local(Courier);\n"
+ "\t}\n" + " ");
JsoupElementNode jSoupStyle = new JsoupElementNode(styleTag);
jSoupStyle.AddChild(new JsoupTextNode(styleContents));
SvgProcessorContext context = new SvgProcessorContext(new SvgConverterProperties());
ICssResolver cssResolver = new SvgStyleResolver(jSoupStyle, context);
SvgFontProcessor svgFontProcessor = new SvgFontProcessor(context);
svgFontProcessor.AddFontFaceFonts(cssResolver);
FontInfo info = (FontInfo)context.GetTempFonts().GetFonts().ToArray()[0];
NUnit.Framework.Assert.AreEqual("Courier", info.GetFontName());
}
}
}

View File

@@ -0,0 +1,85 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using TSpdf.StyledXmlParser.Node;
using TSpdf.StyledXmlParser.Node.Impl.Jsoup.Node;
using TSpdf.Svg.Dummy.Factories;
using TSpdf.Svg.Dummy.Renderers.Impl;
using TSpdf.Svg.Renderers.Factories;
using TSpdf.Test;
namespace TSpdf.Svg.Renderers {
[NUnit.Framework.Category("UnitTest")]
public class DefaultSvgNodeRendererFactoryDrawTest : ExtendedTSpdfTest {
private readonly ISvgNodeRendererFactory fact = new DummySvgNodeFactory();
[NUnit.Framework.Test]
public virtual void BasicProcessedRendererTest() {
TSpdf.StyledXmlParser.Jsoup.Nodes.Element element = new TSpdf.StyledXmlParser.Jsoup.Nodes.Element(TSpdf.StyledXmlParser.Jsoup.Parser.Tag
.ValueOf("processable"), "");
IElementNode tag = new JsoupElementNode(element);
ISvgNodeRenderer renderer = fact.CreateSvgNodeRendererForTag(tag, null);
NUnit.Framework.Assert.IsTrue(renderer is DummyProcessableSvgNodeRenderer);
renderer.Draw(new SvgDrawContext(null, null));
DummyProcessableSvgNodeRenderer processed = (DummyProcessableSvgNodeRenderer)renderer;
NUnit.Framework.Assert.IsTrue(processed.IsProcessed());
}
[NUnit.Framework.Test]
public virtual void NestedProcessedRendererTest() {
TSpdf.StyledXmlParser.Jsoup.Nodes.Element parentEl = new TSpdf.StyledXmlParser.Jsoup.Nodes.Element(TSpdf.StyledXmlParser.Jsoup.Parser.Tag
.ValueOf("processable"), "");
TSpdf.StyledXmlParser.Jsoup.Nodes.Element childEl = new TSpdf.StyledXmlParser.Jsoup.Nodes.Element(TSpdf.StyledXmlParser.Jsoup.Parser.Tag
.ValueOf("processable"), "");
IElementNode parentTag = new JsoupElementNode(parentEl);
IElementNode childTag = new JsoupElementNode(childEl);
ISvgNodeRenderer parentRenderer = fact.CreateSvgNodeRendererForTag(parentTag, null);
ISvgNodeRenderer childRenderer = fact.CreateSvgNodeRendererForTag(childTag, parentRenderer);
parentRenderer.Draw(new SvgDrawContext(null, null));
DummyProcessableSvgNodeRenderer parentProcessed = (DummyProcessableSvgNodeRenderer)parentRenderer;
NUnit.Framework.Assert.IsTrue(parentProcessed.IsProcessed());
DummyProcessableSvgNodeRenderer childProcessed = (DummyProcessableSvgNodeRenderer)childRenderer;
// child is not processed unless instructed thus in its parent
NUnit.Framework.Assert.IsFalse(childProcessed.IsProcessed());
}
}
}

View File

@@ -0,0 +1,123 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using TSpdf.StyledXmlParser.Node;
using TSpdf.StyledXmlParser.Node.Impl.Jsoup.Node;
using TSpdf.Svg.Dummy.Factories;
using TSpdf.Svg.Dummy.Renderers.Impl;
using TSpdf.Svg.Logs;
using TSpdf.Svg.Renderers.Factories;
using TSpdf.Test;
using TSpdf.Test.Attributes;
namespace TSpdf.Svg.Renderers {
[NUnit.Framework.Category("UnitTest")]
public class DefaultSvgNodeRendererFactoryTest : ExtendedTSpdfTest {
private readonly ISvgNodeRendererFactory fact = new DummySvgNodeFactory();
[NUnit.Framework.Test]
[LogMessage(SvgLogMessageConstant.UNMAPPED_TAG)]
public virtual void NonExistingTagTest() {
ISvgNodeRendererFactory factory = new DefaultSvgNodeRendererFactory();
TSpdf.StyledXmlParser.Jsoup.Nodes.Element nonExistingElement = new TSpdf.StyledXmlParser.Jsoup.Nodes.Element
(TSpdf.StyledXmlParser.Jsoup.Parser.Tag.ValueOf("notAnExistingTag"), "");
IElementNode tag = new JsoupElementNode(nonExistingElement);
factory.CreateSvgNodeRendererForTag(tag, null);
}
[NUnit.Framework.Test]
public virtual void ArgumentedConstructorTest() {
TSpdf.StyledXmlParser.Jsoup.Nodes.Element protectedElement = new TSpdf.StyledXmlParser.Jsoup.Nodes.Element
(TSpdf.StyledXmlParser.Jsoup.Parser.Tag.ValueOf("argumented"), "");
IElementNode tag = new JsoupElementNode(protectedElement);
ISvgNodeRenderer renderer = fact.CreateSvgNodeRendererForTag(tag, null);
NUnit.Framework.Assert.IsTrue(renderer is DummyArgumentedConstructorSvgNodeRenderer);
NUnit.Framework.Assert.AreEqual(15, ((DummyArgumentedConstructorSvgNodeRenderer)renderer).number);
}
[NUnit.Framework.Test]
public virtual void RootTagTest() {
TSpdf.StyledXmlParser.Jsoup.Nodes.Element element = new TSpdf.StyledXmlParser.Jsoup.Nodes.Element(TSpdf.StyledXmlParser.Jsoup.Parser.Tag
.ValueOf("dummy"), "");
IElementNode tag = new JsoupElementNode(element);
ISvgNodeRenderer childRenderer = fact.CreateSvgNodeRendererForTag(tag, null);
NUnit.Framework.Assert.IsTrue(childRenderer is DummySvgNodeRenderer);
}
private class LocalSvgNodeRendererFactory : DefaultSvgNodeRendererFactory {
public override ISvgNodeRenderer CreateSvgNodeRendererForTag(IElementNode tag, ISvgNodeRenderer parent) {
ISvgNodeRenderer result;
if ("test".Equals(tag.Name())) {
result = new DummyProcessableSvgNodeRenderer();
result.SetParent(parent);
return result;
}
else {
return null;
}
}
}
[NUnit.Framework.Test]
public virtual void CustomMapperTest() {
ISvgNodeRendererFactory factory = new DefaultSvgNodeRendererFactoryTest.LocalSvgNodeRendererFactory();
TSpdf.StyledXmlParser.Jsoup.Nodes.Element element = new TSpdf.StyledXmlParser.Jsoup.Nodes.Element(TSpdf.StyledXmlParser.Jsoup.Parser.Tag
.ValueOf("test"), "");
IElementNode tag = new JsoupElementNode(element);
ISvgNodeRenderer rend = factory.CreateSvgNodeRendererForTag(tag, null);
NUnit.Framework.Assert.IsTrue(rend is DummyProcessableSvgNodeRenderer);
}
[NUnit.Framework.Test]
public virtual void HierarchyTagTest() {
TSpdf.StyledXmlParser.Jsoup.Nodes.Element parentEl = new TSpdf.StyledXmlParser.Jsoup.Nodes.Element(TSpdf.StyledXmlParser.Jsoup.Parser.Tag
.ValueOf("dummy"), "");
IElementNode parentTag = new JsoupElementNode(parentEl);
TSpdf.StyledXmlParser.Jsoup.Nodes.Element childEl = new TSpdf.StyledXmlParser.Jsoup.Nodes.Element(TSpdf.StyledXmlParser.Jsoup.Parser.Tag
.ValueOf("dummy"), "");
IElementNode childTag = new JsoupElementNode(childEl);
ISvgNodeRenderer parentRenderer = fact.CreateSvgNodeRendererForTag(parentTag, null);
ISvgNodeRenderer childRenderer = fact.CreateSvgNodeRendererForTag(childTag, parentRenderer);
NUnit.Framework.Assert.AreEqual(parentRenderer, childRenderer.GetParent());
}
}
}

View File

@@ -0,0 +1,140 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using TSpdf.Svg.Exceptions;
using TSpdf.Test;
namespace TSpdf.Svg.Renderers {
[NUnit.Framework.Category("IntegrationTest")]
public class FillTest : SvgIntegrationTest {
private static readonly String SOURCE_FOLDER = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/renderers/impl/FillTest/";
private static readonly String DESTINATION_FOLDER = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/renderers/impl/FillTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateDestinationFolder(DESTINATION_FOLDER);
}
[NUnit.Framework.Test]
public virtual void NormalRectangleFillTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "normalRectangleFill");
}
[NUnit.Framework.Test]
public virtual void MultipleNormalRectangleFillTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "multipleNormalRectangleFill");
}
[NUnit.Framework.Test]
public virtual void NoRectangleFillColorTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "noRectangleFillColor");
}
[NUnit.Framework.Test]
public virtual void EoFillTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "eofill");
}
/* This test should fail when DEVSIX-2251 is resolved*/
[NUnit.Framework.Test]
public virtual void EoFillTest01() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "eofill01");
}
[NUnit.Framework.Test]
public virtual void EoFillTest02() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "eofill02");
}
[NUnit.Framework.Test]
public virtual void EoFillTest03() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "eofill03");
}
[NUnit.Framework.Test]
public virtual void MultipleObjectsTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "multipleObjectsTest");
}
[NUnit.Framework.Test]
public virtual void EoFillStrokeTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "eofillstroke");
}
/* This test should fail when DEVSIX-2251 is resolved*/
[NUnit.Framework.Test]
public virtual void NonZeroFillTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "nonzerofill");
}
[NUnit.Framework.Test]
public virtual void OpacityFillTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "opacityfill");
}
[NUnit.Framework.Test]
public virtual void EofillUnsuportedAtributeTest() {
NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER
, "eofillUnsuportedAtributeTest"));
}
[NUnit.Framework.Test]
public virtual void PathVerticalLineFillTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "pathVerticalLineFillTest");
}
[NUnit.Framework.Test]
public virtual void PathHorizontalLineFillTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "pathHorizontalLineFillTest");
}
[NUnit.Framework.Test]
public virtual void InvalidUrlFillTest() {
//TODO update cmp file after DEVSIX-3365 will be fixed
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "invalidUrlFillTest");
}
}
}

View File

@@ -0,0 +1,89 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using System.Collections.Generic;
using TSpdf.Test;
namespace TSpdf.Svg.Renderers {
[NUnit.Framework.Category("IntegrationTest")]
public class GUnitTest : SvgIntegrationTest {
private static readonly String SOURCE_FOLDER = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/renderers/impl/gunit/";
private static readonly String DESTINATION_FOLDER = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/renderers/impl/gunit/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateDestinationFolder(DESTINATION_FOLDER);
}
[NUnit.Framework.Test]
public virtual void MeetTheTeam() {
IList<Exception> assertionErrorsThrown = new List<Exception>();
for (int i = 1; i < 6; i++) {
try {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "test_00" + i);
}
catch (Exception ae) {
if (ae.Message.Contains("expected null, but was")) {
assertionErrorsThrown.Add(ae);
}
}
}
if (assertionErrorsThrown.Count != 0) {
NUnit.Framework.Assert.Fail("At least one compare file was not identical with the result");
}
}
[NUnit.Framework.Test]
public virtual void ViewboxTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "test_viewbox");
}
[NUnit.Framework.Test]
public virtual void SimpleGTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "simpleG");
}
}
}

View File

@@ -0,0 +1,121 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using TSpdf.Test;
namespace TSpdf.Svg.Renderers {
[NUnit.Framework.Category("IntegrationTest")]
public class OpacityTest : SvgIntegrationTest {
private static readonly String SOURCE_FOLDER = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/renderers/impl/OpacityTest/";
private static readonly String DESTINATION_FOLDER = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/renderers/impl/OpacityTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateDestinationFolder(DESTINATION_FOLDER);
}
[NUnit.Framework.Test]
public virtual void TestOpacitySimple() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "opacity_simple");
}
[NUnit.Framework.Test]
public virtual void TestOpacityRGBA() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "opacity_rgba");
}
[NUnit.Framework.Test]
public virtual void TestOpacityComplex() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "opacity_complex");
}
[NUnit.Framework.Test]
public virtual void TestRGBA() {
//TODO: update after DEVSIX-2673 fix
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "svg_rgba");
}
[NUnit.Framework.Test]
public virtual void TestFillOpacityWithComma() {
//TODO DEVSIX-2678
NUnit.Framework.Assert.Catch(typeof(FormatException), () => ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER
, "testFillOpacityWithComma"));
}
[NUnit.Framework.Test]
public virtual void TestFillOpacityWithPercents() {
//TODO DEVSIX-2678
NUnit.Framework.Assert.Catch(typeof(FormatException), () => ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER
, "testFillOpacityWithPercents"));
}
[NUnit.Framework.Test]
public virtual void TestFillOpacity() {
//TODO: update after DEVSIX-2678 fix
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "svg_fill_opacity");
}
[NUnit.Framework.Test]
public virtual void TestStrokeOpacityWithComma() {
//TODO DEVSIX-2679
NUnit.Framework.Assert.Catch(typeof(Exception), () => ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER,
"testStrokeOpacityWithComma"));
}
[NUnit.Framework.Test]
public virtual void TestStrokeOpacityWithPercents() {
//TODO DEVSIX-2679
NUnit.Framework.Assert.Catch(typeof(FormatException), () => ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER
, "testStrokeOpacityWithPercents"));
}
[NUnit.Framework.Test]
public virtual void TestStrokeOpacity() {
//TODO: update after DEVSIX-2679 fix
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "svg_stroke_opacity");
}
}
}

View File

@@ -0,0 +1,90 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using TSpdf.Test;
using TSpdf.Test.Attributes;
namespace TSpdf.Svg.Renderers {
[NUnit.Framework.Category("IntegrationTest")]
public class StrokeTest : SvgIntegrationTest {
private static readonly String SOURCE_FOLDER = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/renderers/impl/StrokeTest/";
private static readonly String DESTINATION_FOLDER = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/renderers/impl/StrokeTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateDestinationFolder(DESTINATION_FOLDER);
}
[NUnit.Framework.Test]
public virtual void NormalLineStrokeTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "normalLineStroke");
}
[NUnit.Framework.Test]
public virtual void NoLineStrokeTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "noLineStroke");
}
[NUnit.Framework.Test]
public virtual void NoLineStrokeWidthTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "noLineStrokeWidth");
}
[NUnit.Framework.Test]
public virtual void AdvancedStrokeTest() {
//TODO: update cmp-file after DEVSIX-2258
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "strokeAdvanced");
}
[NUnit.Framework.Test]
// TODO DEVSIX-3432 relative values doesn't support correctly for stroke-width attribute
[LogMessage(TSpdf.StyledXmlParser.Logs.StyledXmlParserLogMessageConstant.UNKNOWN_ABSOLUTE_METRIC_LENGTH_PARSED
, Count = 12)]
public virtual void StrokeWidthMeasureUnitsTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "strokeWidthMeasureUnitsTest");
}
}
}

View File

@@ -0,0 +1,216 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using System.Collections.Generic;
using System.IO;
using TSpdf.Kernel.Pdf;
using TSpdf.Kernel.Pdf.Canvas;
using TSpdf.Svg.Dummy.Renderers.Impl;
using TSpdf.Svg.Exceptions;
using TSpdf.Svg.Renderers.Impl;
using TSpdf.Test;
namespace TSpdf.Svg.Renderers {
[NUnit.Framework.Category("UnitTest")]
public class SvgDrawContextTest : ExtendedTSpdfTest {
private PdfDocument tokenDoc;
private PdfCanvas page1;
private PdfCanvas page2;
private SvgDrawContext context;
[NUnit.Framework.SetUp]
public virtual void SetUp() {
tokenDoc = new PdfDocument(new PdfWriter(new MemoryStream()));
page1 = new PdfCanvas(tokenDoc.AddNewPage());
page2 = new PdfCanvas(tokenDoc.AddNewPage());
context = new SvgDrawContext(null, null);
}
[NUnit.Framework.TearDown]
public virtual void TearDown() {
// release all resources
tokenDoc.Close();
}
[NUnit.Framework.Test]
public virtual void DrawContextEmptyDequeGetFirstTest() {
NUnit.Framework.Assert.Catch(typeof(NullReferenceException), () => context.GetCurrentCanvas());
}
[NUnit.Framework.Test]
public virtual void DrawContextEmptyDequePopTest() {
NUnit.Framework.Assert.Catch(typeof(NullReferenceException), () => context.PopCanvas());
}
[NUnit.Framework.Test]
public virtual void DrawContextEmptyStackCountTest() {
NUnit.Framework.Assert.AreEqual(0, context.Size());
}
[NUnit.Framework.Test]
public virtual void DrawContextPushCountTest() {
context.PushCanvas(page1);
NUnit.Framework.Assert.AreEqual(1, context.Size());
}
[NUnit.Framework.Test]
public virtual void DrawContextPushPeekTest() {
context.PushCanvas(page1);
NUnit.Framework.Assert.AreEqual(page1, context.GetCurrentCanvas());
}
[NUnit.Framework.Test]
public virtual void DrawContextPushPopCountTest() {
context.PushCanvas(page1);
context.PopCanvas();
NUnit.Framework.Assert.AreEqual(0, context.Size());
}
[NUnit.Framework.Test]
public virtual void DrawContextPushPopTest() {
context.PushCanvas(page1);
NUnit.Framework.Assert.AreEqual(page1, context.PopCanvas());
}
[NUnit.Framework.Test]
public virtual void DrawContextPushTwiceCountTest() {
context.PushCanvas(page1);
context.PushCanvas(page2);
NUnit.Framework.Assert.AreEqual(2, context.Size());
}
[NUnit.Framework.Test]
public virtual void DrawContextPushTwicePeekTest() {
context.PushCanvas(page1);
context.PushCanvas(page2);
NUnit.Framework.Assert.AreEqual(page2, context.GetCurrentCanvas());
NUnit.Framework.Assert.AreEqual(2, context.Size());
}
[NUnit.Framework.Test]
public virtual void DrawContextPushTwicePopTest() {
context.PushCanvas(page1);
context.PushCanvas(page2);
NUnit.Framework.Assert.AreEqual(page2, context.PopCanvas());
NUnit.Framework.Assert.AreEqual(1, context.Size());
NUnit.Framework.Assert.AreEqual(page1, context.PopCanvas());
}
[NUnit.Framework.Test]
public virtual void AddISvgNodeRender() {
String name = "expected";
ISvgNodeRenderer expected = new GroupSvgNodeRenderer();
this.context.AddNamedObject(name, expected);
Object actual = this.context.GetNamedObject(name);
NUnit.Framework.Assert.AreEqual(expected, actual);
}
[NUnit.Framework.Test]
public virtual void AddNullToNamedObjects() {
String name = "expected";
Exception e = NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => this.context.AddNamedObject
(name, null));
NUnit.Framework.Assert.AreEqual(SvgExceptionMessageConstant.NAMED_OBJECT_NULL, e.Message);
}
[NUnit.Framework.Test]
public virtual void AddNamedObjectWithNullName() {
ISvgNodeRenderer expected = new DummySvgNodeRenderer();
Exception e = NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => this.context.AddNamedObject
(null, expected));
NUnit.Framework.Assert.AreEqual(SvgExceptionMessageConstant.NAMED_OBJECT_NAME_NULL_OR_EMPTY, e.Message);
}
[NUnit.Framework.Test]
public virtual void AddNamedObjectWithEmptyName() {
ISvgNodeRenderer expected = new DummySvgNodeRenderer();
Exception e = NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => this.context.AddNamedObject
("", expected));
NUnit.Framework.Assert.AreEqual(SvgExceptionMessageConstant.NAMED_OBJECT_NAME_NULL_OR_EMPTY, e.Message);
}
[NUnit.Framework.Test]
public virtual void AddNamedRenderer() {
ISvgNodeRenderer expected = new DummySvgNodeRenderer();
String dummyName = "dummy";
this.context.AddNamedObject(dummyName, expected);
Object actual = this.context.GetNamedObject(dummyName);
NUnit.Framework.Assert.AreEqual(expected, actual);
}
[NUnit.Framework.Test]
public virtual void AddNamedObjects() {
ISvgNodeRenderer expectedOne = new DummySvgNodeRenderer();
ISvgNodeRenderer expectedTwo = new DummySvgNodeRenderer();
ISvgNodeRenderer expectedThree = new DummySvgNodeRenderer();
String dummyNameOne = "Ed";
String dummyNameTwo = "Edd";
String dummyNameThree = "Eddy";
IDictionary<String, ISvgNodeRenderer> toAdd = new Dictionary<String, ISvgNodeRenderer>();
toAdd.Put(dummyNameOne, expectedOne);
toAdd.Put(dummyNameTwo, expectedTwo);
toAdd.Put(dummyNameThree, expectedThree);
this.context.AddNamedObjects(toAdd);
Object actualThree = this.context.GetNamedObject(dummyNameThree);
Object actualTwo = this.context.GetNamedObject(dummyNameTwo);
Object actualOne = this.context.GetNamedObject(dummyNameOne);
NUnit.Framework.Assert.AreEqual(expectedOne, actualOne);
NUnit.Framework.Assert.AreEqual(expectedTwo, actualTwo);
NUnit.Framework.Assert.AreEqual(expectedThree, actualThree);
}
[NUnit.Framework.Test]
public virtual void AddNamedObjectAndTryToAddDuplicate() {
ISvgNodeRenderer expectedOne = new DummySvgNodeRenderer();
ISvgNodeRenderer expectedTwo = new DummySvgNodeRenderer();
String dummyName = "Ed";
context.AddNamedObject(dummyName, expectedOne);
context.AddNamedObject(dummyName, expectedTwo);
Object actual = context.GetNamedObject(dummyName);
NUnit.Framework.Assert.AreEqual(expectedOne, actual);
}
}
}

View File

@@ -0,0 +1,144 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using System.IO;
using TSpdf.Kernel.Geom;
using TSpdf.Kernel.Pdf;
using TSpdf.Kernel.Utils;
using TSpdf.Svg.Converter;
using TSpdf.Svg.Processors;
using TSpdf.Svg.Processors.Impl;
using TSpdf.Test;
namespace TSpdf.Svg.Renderers {
[NUnit.Framework.Category("IntegrationTest")]
public class SvgIntegrationTest : ExtendedTSpdfTest {
public virtual void Convert(Stream svg, Stream pdfOutputStream) {
PdfDocument doc = new PdfDocument(new PdfWriter(pdfOutputStream, new WriterProperties().SetCompressionLevel
(0)));
doc.AddNewPage();
SvgConverter.DrawOnDocument(svg, doc, 1);
doc.Close();
}
public virtual void Convert(String svg, String output) {
Convert(svg, output, PageSize.DEFAULT);
}
public virtual void Convert(String svg, String output, PageSize size) {
using (PdfDocument doc = new PdfDocument(new PdfWriter(output, new WriterProperties().SetCompressionLevel(
0)))) {
doc.AddNewPage(size);
ISvgConverterProperties properties = new SvgConverterProperties().SetBaseUri(svg);
SvgConverter.DrawOnDocument(new FileStream(svg, FileMode.Open, FileAccess.Read), doc, 1, properties);
}
}
public static PdfDocument ConvertWithResult(String svg, String output) {
PdfDocument doc = new PdfDocument(new PdfWriter(output, new WriterProperties().SetCompressionLevel(0)));
doc.AddNewPage();
ISvgConverterProperties properties = new SvgConverterProperties().SetBaseUri(svg);
SvgConverter.DrawOnDocument(new FileStream(svg, FileMode.Open, FileAccess.Read), doc, 1, properties);
return doc;
}
public virtual void ConvertToSinglePage(Stream svg, Stream pdfOutputStream) {
WriterProperties writerprops = new WriterProperties().SetCompressionLevel(0);
SvgConverter.CreatePdf(svg, pdfOutputStream, writerprops);
}
public virtual void ConvertToSinglePage(FileInfo svg, FileInfo pdf) {
SvgConverter.CreatePdf(svg, pdf);
}
public virtual void ConvertToSinglePage(FileInfo svg, FileInfo pdf, ISvgConverterProperties properties) {
SvgConverter.CreatePdf(svg, pdf, properties);
}
public virtual void ConvertToSinglePage(FileInfo svg, FileInfo pdf, ISvgConverterProperties properties, WriterProperties
writerProperties) {
SvgConverter.CreatePdf(svg, pdf, properties, writerProperties);
}
public virtual void ConvertToSinglePage(FileInfo svg, FileInfo pdf, WriterProperties writerProperties) {
SvgConverter.CreatePdf(svg, pdf, writerProperties);
}
public virtual void ConvertToSinglePage(Stream svg, Stream pdfOutputStream, ISvgConverterProperties properties
) {
SvgConverter.CreatePdf(svg, pdfOutputStream, properties);
}
public virtual void ConvertToSinglePage(Stream svg, Stream pdfOutputStream, ISvgConverterProperties properties
, WriterProperties writerprops) {
SvgConverter.CreatePdf(svg, pdfOutputStream, properties, writerprops);
}
public virtual void ConvertAndCompare(String src, String dest, String fileName) {
ConvertAndCompare(src, dest, fileName, PageSize.DEFAULT);
}
public virtual void ConvertAndCompare(String src, String dest, String fileName, PageSize size) {
Convert(src + fileName + ".svg", dest + fileName + ".pdf", size);
Compare(fileName, src, dest);
}
public virtual void ConvertAndCompareSinglePage(String src, String dest, String fileName) {
ConvertToSinglePage(new FileStream(src + fileName + ".svg", FileMode.Open, FileAccess.Read), new FileStream
(dest + fileName + ".pdf", FileMode.Create));
Compare(fileName, src, dest);
}
public virtual void ConvertAndCompareSinglePage(String src, String dest, String fileName, ISvgConverterProperties
properties) {
ConvertToSinglePage(new FileStream(src + fileName + ".svg", FileMode.Open, FileAccess.Read), new FileStream
(dest + fileName + ".pdf", FileMode.Create), properties);
Compare(fileName, src, dest);
}
protected internal virtual void Compare(String filename, String sourceFolder, String destinationFolder) {
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + filename + ".pdf", sourceFolder
+ "cmp_" + filename + ".pdf", destinationFolder, "diff_"));
}
}
}

View File

@@ -0,0 +1,89 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using System.Collections.Generic;
using System.IO;
using TSpdf.Kernel.Geom;
using TSpdf.Kernel.Pdf;
using TSpdf.Kernel.Pdf.Canvas;
using TSpdf.Svg;
using TSpdf.Svg.Renderers.Impl;
using TSpdf.Test;
namespace TSpdf.Svg.Renderers {
[NUnit.Framework.Category("UnitTest")]
public class TransformationApplicationTest : ExtendedTSpdfTest {
[NUnit.Framework.Test]
public virtual void NormalDrawTest() {
byte[] expected = "1 0 0 1 7.5 0 cm\n0 0 0 rg\nf\n".GetBytes(System.Text.Encoding.UTF8);
ISvgNodeRenderer nodeRenderer = new _AbstractSvgNodeRenderer_71();
// do nothing
IDictionary<String, String> attributeMap = new Dictionary<String, String>();
attributeMap.Put(SvgConstants.Attributes.TRANSFORM, "translate(10)");
nodeRenderer.SetAttributesAndStyles(attributeMap);
SvgDrawContext context = new SvgDrawContext(null, null);
PdfDocument document = new PdfDocument(new PdfWriter(new MemoryStream()));
PdfCanvas canvas = new PdfCanvas(document.AddNewPage());
context.PushCanvas(canvas);
nodeRenderer.Draw(context);
byte[] actual = canvas.GetContentStream().GetBytes(true);
NUnit.Framework.Assert.AreEqual(expected, actual);
}
private sealed class _AbstractSvgNodeRenderer_71 : AbstractSvgNodeRenderer {
public _AbstractSvgNodeRenderer_71() {
}
public override ISvgNodeRenderer CreateDeepCopy() {
return null;
}
public override Rectangle GetObjectBoundingBox(SvgDrawContext context) {
return null;
}
protected internal override void DoDraw(SvgDrawContext context) {
}
}
}
}

View File

@@ -0,0 +1,518 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System.IO;
using TSpdf.Kernel.Pdf;
using TSpdf.Kernel.Pdf.Canvas;
using TSpdf.Layout.Font;
using TSpdf.StyledXmlParser.Resolver.Resource;
using TSpdf.Svg;
using TSpdf.Svg.Renderers.Impl;
using TSpdf.Test;
namespace TSpdf.Svg.Renderers {
[NUnit.Framework.Category("IntegrationTest")]
public class TransparencyTest : ExtendedTSpdfTest {
private static readonly PdfName DEFAULT_RESOURCE_NAME = new PdfName("Gs1");
private static readonly PdfName FILL_OPAC = new PdfName("ca");
private static readonly PdfName STROKE_OPAC = new PdfName("CA");
private PdfCanvas cv;
private SvgDrawContext sdc;
[NUnit.Framework.SetUp]
public virtual void SetupDrawContextAndCanvas() {
sdc = new SvgDrawContext(new ResourceResolver(""), new FontProvider());
// set compression to none, in case you want to write to disk and inspect the created document
PdfWriter writer = new PdfWriter(new MemoryStream(), new WriterProperties().SetCompressionLevel(0));
PdfDocument doc = new PdfDocument(writer);
cv = new PdfCanvas(doc.AddNewPage());
sdc.PushCanvas(cv);
}
[NUnit.Framework.TearDown]
public virtual void Close() {
cv.GetDocument().Close();
}
[NUnit.Framework.Test]
public virtual void NoOpacitySet() {
AbstractSvgNodeRenderer renderer = new CircleSvgNodeRenderer();
renderer.SetAttribute(SvgConstants.Attributes.STROKE, "blue");
renderer.Draw(sdc);
PdfResources resources = cv.GetResources();
NUnit.Framework.Assert.IsTrue(resources.GetResourceNames().IsEmpty());
}
[NUnit.Framework.Test]
public virtual void StrokeOpacitySetWithStroke() {
AbstractSvgNodeRenderer renderer = new CircleSvgNodeRenderer();
renderer.SetAttribute(SvgConstants.Attributes.STROKE_OPACITY, "0.75");
renderer.SetAttribute(SvgConstants.Attributes.STROKE, "blue");
renderer.Draw(sdc);
PdfResources resources = cv.GetResources();
NUnit.Framework.Assert.AreEqual(1, resources.GetResourceNames().Count);
PdfDictionary resDic = (PdfDictionary)resources.GetResourceObject(PdfName.ExtGState, DEFAULT_RESOURCE_NAME
);
NUnit.Framework.Assert.AreEqual(1, resDic.Size());
NUnit.Framework.Assert.AreEqual(resDic.Get(STROKE_OPAC), new PdfNumber(0.75));
}
[NUnit.Framework.Test]
public virtual void StrokeOpacitySetWithoutStroke() {
AbstractSvgNodeRenderer renderer = new CircleSvgNodeRenderer();
renderer.SetAttribute(SvgConstants.Attributes.STROKE_OPACITY, "0.75");
renderer.Draw(sdc);
PdfResources resources = cv.GetResources();
NUnit.Framework.Assert.IsTrue(resources.GetResourceNames().IsEmpty());
}
[NUnit.Framework.Test]
public virtual void StrokeOpacitySetWithFill() {
AbstractSvgNodeRenderer renderer = new CircleSvgNodeRenderer();
renderer.SetAttribute(SvgConstants.Attributes.STROKE_OPACITY, "0.75");
renderer.SetAttribute(SvgConstants.Attributes.FILL, "blue");
renderer.Draw(sdc);
PdfResources resources = cv.GetResources();
NUnit.Framework.Assert.IsTrue(resources.GetResourceNames().IsEmpty());
}
[NUnit.Framework.Test]
public virtual void StrokeOpacitySetWithNoneStroke() {
AbstractSvgNodeRenderer renderer = new CircleSvgNodeRenderer();
renderer.SetAttribute(SvgConstants.Attributes.STROKE_OPACITY, "0.75");
renderer.SetAttribute(SvgConstants.Attributes.STROKE, SvgConstants.Values.NONE);
renderer.Draw(sdc);
PdfResources resources = cv.GetResources();
NUnit.Framework.Assert.IsTrue(resources.GetResourceNames().IsEmpty());
}
[NUnit.Framework.Test]
public virtual void FillOpacitySetWithFill() {
AbstractSvgNodeRenderer renderer = new CircleSvgNodeRenderer();
renderer.SetAttribute(SvgConstants.Attributes.FILL_OPACITY, "0.75");
renderer.SetAttribute(SvgConstants.Attributes.FILL, "blue");
renderer.Draw(sdc);
PdfResources resources = cv.GetResources();
NUnit.Framework.Assert.AreEqual(1, resources.GetResourceNames().Count);
PdfDictionary resDic = (PdfDictionary)resources.GetResourceObject(PdfName.ExtGState, DEFAULT_RESOURCE_NAME
);
NUnit.Framework.Assert.AreEqual(1, resDic.Size());
NUnit.Framework.Assert.AreEqual(resDic.Get(FILL_OPAC), new PdfNumber(0.75));
}
[NUnit.Framework.Test]
public virtual void FillOpacitySetWithoutFill() {
AbstractSvgNodeRenderer renderer = new CircleSvgNodeRenderer();
renderer.SetAttribute(SvgConstants.Attributes.FILL_OPACITY, "0.75");
renderer.Draw(sdc);
PdfResources resources = cv.GetResources();
NUnit.Framework.Assert.AreEqual(1, resources.GetResourceNames().Count);
PdfDictionary resDic = (PdfDictionary)resources.GetResourceObject(PdfName.ExtGState, DEFAULT_RESOURCE_NAME
);
NUnit.Framework.Assert.AreEqual(1, resDic.Size());
NUnit.Framework.Assert.AreEqual(resDic.Get(FILL_OPAC), new PdfNumber(0.75));
}
[NUnit.Framework.Test]
public virtual void FillOpacitySetWithNoneFill() {
AbstractSvgNodeRenderer renderer = new CircleSvgNodeRenderer();
renderer.SetAttribute(SvgConstants.Attributes.FILL_OPACITY, "0.75");
renderer.SetAttribute(SvgConstants.Attributes.FILL, SvgConstants.Values.NONE);
renderer.Draw(sdc);
PdfResources resources = cv.GetResources();
NUnit.Framework.Assert.IsTrue(resources.GetResourceNames().IsEmpty());
}
[NUnit.Framework.Test]
public virtual void FillOpacitySetWithStroke() {
AbstractSvgNodeRenderer renderer = new CircleSvgNodeRenderer();
renderer.SetAttribute(SvgConstants.Attributes.FILL_OPACITY, "0.75");
renderer.SetAttribute(SvgConstants.Attributes.STROKE, "blue");
renderer.Draw(sdc);
PdfResources resources = cv.GetResources();
NUnit.Framework.Assert.AreEqual(1, resources.GetResourceNames().Count);
PdfDictionary resDic = (PdfDictionary)resources.GetResourceObject(PdfName.ExtGState, DEFAULT_RESOURCE_NAME
);
NUnit.Framework.Assert.AreEqual(1, resDic.Size());
NUnit.Framework.Assert.AreEqual(resDic.Get(FILL_OPAC), new PdfNumber(0.75));
}
[NUnit.Framework.Test]
public virtual void FillAndStrokeOpacitySetWithStrokeAndFill() {
AbstractSvgNodeRenderer renderer = new CircleSvgNodeRenderer();
renderer.SetAttribute(SvgConstants.Attributes.FILL_OPACITY, "0.75");
renderer.SetAttribute(SvgConstants.Attributes.STROKE_OPACITY, "0.75");
renderer.SetAttribute(SvgConstants.Attributes.FILL, "blue");
renderer.SetAttribute(SvgConstants.Attributes.STROKE, "green");
renderer.Draw(sdc);
PdfResources resources = cv.GetResources();
NUnit.Framework.Assert.AreEqual(1, resources.GetResourceNames().Count);
PdfDictionary resDic = (PdfDictionary)resources.GetResourceObject(PdfName.ExtGState, DEFAULT_RESOURCE_NAME
);
NUnit.Framework.Assert.AreEqual(2, resDic.Size());
NUnit.Framework.Assert.AreEqual(resDic.Get(FILL_OPAC), new PdfNumber(0.75));
NUnit.Framework.Assert.AreEqual(resDic.Get(STROKE_OPAC), new PdfNumber(0.75));
}
[NUnit.Framework.Test]
public virtual void NoOpacitySetRGB() {
AbstractSvgNodeRenderer renderer = new CircleSvgNodeRenderer();
renderer.SetAttribute(SvgConstants.Attributes.STROKE, "rgb(100,20,80)");
renderer.Draw(sdc);
PdfResources resources = cv.GetResources();
NUnit.Framework.Assert.IsTrue(resources.GetResourceNames().IsEmpty());
}
[NUnit.Framework.Test]
public virtual void StrokeOpacitySetWithStrokeRGB() {
AbstractSvgNodeRenderer renderer = new CircleSvgNodeRenderer();
renderer.SetAttribute(SvgConstants.Attributes.STROKE_OPACITY, "0.75");
renderer.SetAttribute(SvgConstants.Attributes.STROKE, "rgb(100,20,80)");
renderer.Draw(sdc);
PdfResources resources = cv.GetResources();
NUnit.Framework.Assert.AreEqual(1, resources.GetResourceNames().Count);
PdfDictionary resDic = (PdfDictionary)resources.GetResourceObject(PdfName.ExtGState, DEFAULT_RESOURCE_NAME
);
NUnit.Framework.Assert.AreEqual(1, resDic.Size());
NUnit.Framework.Assert.AreEqual(resDic.Get(STROKE_OPAC), new PdfNumber(0.75));
}
[NUnit.Framework.Test]
public virtual void StrokeOpacitySetWithoutStrokeRGB() {
AbstractSvgNodeRenderer renderer = new CircleSvgNodeRenderer();
renderer.SetAttribute(SvgConstants.Attributes.STROKE_OPACITY, "0.75");
renderer.Draw(sdc);
PdfResources resources = cv.GetResources();
NUnit.Framework.Assert.IsTrue(resources.GetResourceNames().IsEmpty());
}
[NUnit.Framework.Test]
public virtual void StrokeOpacitySetWithFillRGB() {
AbstractSvgNodeRenderer renderer = new CircleSvgNodeRenderer();
renderer.SetAttribute(SvgConstants.Attributes.STROKE_OPACITY, "0.75");
renderer.SetAttribute(SvgConstants.Attributes.FILL, "rgb(100,20,80)");
renderer.Draw(sdc);
PdfResources resources = cv.GetResources();
NUnit.Framework.Assert.IsTrue(resources.GetResourceNames().IsEmpty());
}
[NUnit.Framework.Test]
public virtual void StrokeOpacitySetWithNoneStrokeRGB() {
AbstractSvgNodeRenderer renderer = new CircleSvgNodeRenderer();
renderer.SetAttribute(SvgConstants.Attributes.STROKE_OPACITY, "0.75");
renderer.SetAttribute(SvgConstants.Attributes.STROKE, SvgConstants.Values.NONE);
renderer.Draw(sdc);
PdfResources resources = cv.GetResources();
NUnit.Framework.Assert.IsTrue(resources.GetResourceNames().IsEmpty());
}
[NUnit.Framework.Test]
public virtual void FillOpacitySetWithFillRGB() {
AbstractSvgNodeRenderer renderer = new CircleSvgNodeRenderer();
renderer.SetAttribute(SvgConstants.Attributes.FILL_OPACITY, "0.75");
renderer.SetAttribute(SvgConstants.Attributes.FILL, "rgb(100,20,80)");
renderer.Draw(sdc);
PdfResources resources = cv.GetResources();
NUnit.Framework.Assert.AreEqual(1, resources.GetResourceNames().Count);
PdfDictionary resDic = (PdfDictionary)resources.GetResourceObject(PdfName.ExtGState, DEFAULT_RESOURCE_NAME
);
NUnit.Framework.Assert.AreEqual(1, resDic.Size());
NUnit.Framework.Assert.AreEqual(resDic.Get(FILL_OPAC), new PdfNumber(0.75));
}
[NUnit.Framework.Test]
public virtual void FillOpacitySetWithoutFillRGB() {
AbstractSvgNodeRenderer renderer = new CircleSvgNodeRenderer();
renderer.SetAttribute(SvgConstants.Attributes.FILL_OPACITY, "0.75");
renderer.Draw(sdc);
PdfResources resources = cv.GetResources();
NUnit.Framework.Assert.AreEqual(1, resources.GetResourceNames().Count);
PdfDictionary resDic = (PdfDictionary)resources.GetResourceObject(PdfName.ExtGState, DEFAULT_RESOURCE_NAME
);
NUnit.Framework.Assert.AreEqual(1, resDic.Size());
NUnit.Framework.Assert.AreEqual(resDic.Get(FILL_OPAC), new PdfNumber(0.75));
}
[NUnit.Framework.Test]
public virtual void FillOpacitySetWithNoneFillRGB() {
AbstractSvgNodeRenderer renderer = new CircleSvgNodeRenderer();
renderer.SetAttribute(SvgConstants.Attributes.FILL_OPACITY, "0.75");
renderer.SetAttribute(SvgConstants.Attributes.FILL, SvgConstants.Values.NONE);
renderer.Draw(sdc);
PdfResources resources = cv.GetResources();
NUnit.Framework.Assert.IsTrue(resources.GetResourceNames().IsEmpty());
}
[NUnit.Framework.Test]
public virtual void FillOpacitySetWithStrokeRGB() {
AbstractSvgNodeRenderer renderer = new CircleSvgNodeRenderer();
renderer.SetAttribute(SvgConstants.Attributes.FILL_OPACITY, "0.75");
renderer.SetAttribute(SvgConstants.Attributes.STROKE, "rgb(100,20,80)");
renderer.Draw(sdc);
PdfResources resources = cv.GetResources();
NUnit.Framework.Assert.AreEqual(1, resources.GetResourceNames().Count);
PdfDictionary resDic = (PdfDictionary)resources.GetResourceObject(PdfName.ExtGState, DEFAULT_RESOURCE_NAME
);
NUnit.Framework.Assert.AreEqual(1, resDic.Size());
NUnit.Framework.Assert.AreEqual(resDic.Get(FILL_OPAC), new PdfNumber(0.75));
}
[NUnit.Framework.Test]
public virtual void FillAndStrokeOpacitySetWithStrokeAndFillRGB() {
AbstractSvgNodeRenderer renderer = new CircleSvgNodeRenderer();
renderer.SetAttribute(SvgConstants.Attributes.FILL_OPACITY, "0.75");
renderer.SetAttribute(SvgConstants.Attributes.STROKE_OPACITY, "0.75");
renderer.SetAttribute(SvgConstants.Attributes.FILL, "rgb(100,20,80)");
renderer.SetAttribute(SvgConstants.Attributes.STROKE, "rgb(60,90,180)");
renderer.Draw(sdc);
PdfResources resources = cv.GetResources();
NUnit.Framework.Assert.AreEqual(1, resources.GetResourceNames().Count);
PdfDictionary resDic = (PdfDictionary)resources.GetResourceObject(PdfName.ExtGState, DEFAULT_RESOURCE_NAME
);
NUnit.Framework.Assert.AreEqual(2, resDic.Size());
NUnit.Framework.Assert.AreEqual(resDic.Get(FILL_OPAC), new PdfNumber(0.75));
NUnit.Framework.Assert.AreEqual(resDic.Get(STROKE_OPAC), new PdfNumber(0.75));
}
[NUnit.Framework.Test]
public virtual void NoOpacitySetRGBA() {
AbstractSvgNodeRenderer renderer = new CircleSvgNodeRenderer();
renderer.SetAttribute(SvgConstants.Attributes.STROKE, "rgba(100,20,80, .75)");
renderer.Draw(sdc);
PdfResources resources = cv.GetResources();
NUnit.Framework.Assert.AreEqual(1, resources.GetResourceNames().Count);
PdfDictionary resDic = (PdfDictionary)resources.GetResourceObject(PdfName.ExtGState, DEFAULT_RESOURCE_NAME
);
NUnit.Framework.Assert.AreEqual(1, resDic.Size());
NUnit.Framework.Assert.AreEqual(resDic.Get(STROKE_OPAC), new PdfNumber(0.75));
}
[NUnit.Framework.Test]
public virtual void StrokeOpacitySetWithStrokeRGBA() {
AbstractSvgNodeRenderer renderer = new CircleSvgNodeRenderer();
renderer.SetAttribute(SvgConstants.Attributes.STROKE_OPACITY, "0.75");
renderer.SetAttribute(SvgConstants.Attributes.STROKE, "rgba(100,20,80,.75)");
renderer.Draw(sdc);
PdfResources resources = cv.GetResources();
NUnit.Framework.Assert.AreEqual(1, resources.GetResourceNames().Count);
PdfDictionary resDic = (PdfDictionary)resources.GetResourceObject(PdfName.ExtGState, DEFAULT_RESOURCE_NAME
);
NUnit.Framework.Assert.AreEqual(1, resDic.Size());
NUnit.Framework.Assert.AreEqual(resDic.Get(STROKE_OPAC), new PdfNumber(0.5625));
}
[NUnit.Framework.Test]
public virtual void StrokeOpacitySetWithoutStrokeRGBA() {
AbstractSvgNodeRenderer renderer = new CircleSvgNodeRenderer();
renderer.SetAttribute(SvgConstants.Attributes.STROKE_OPACITY, "0.75");
renderer.Draw(sdc);
PdfResources resources = cv.GetResources();
NUnit.Framework.Assert.IsTrue(resources.GetResourceNames().IsEmpty());
}
[NUnit.Framework.Test]
public virtual void StrokeOpacitySetWithFillRGBA() {
AbstractSvgNodeRenderer renderer = new CircleSvgNodeRenderer();
renderer.SetAttribute(SvgConstants.Attributes.STROKE_OPACITY, "0.75");
renderer.SetAttribute(SvgConstants.Attributes.FILL, "rgba(100,20,80,.75)");
renderer.Draw(sdc);
PdfResources resources = cv.GetResources();
NUnit.Framework.Assert.AreEqual(1, resources.GetResourceNames().Count);
PdfDictionary resDic = (PdfDictionary)resources.GetResourceObject(PdfName.ExtGState, DEFAULT_RESOURCE_NAME
);
NUnit.Framework.Assert.AreEqual(1, resDic.Size());
NUnit.Framework.Assert.AreEqual(resDic.Get(FILL_OPAC), new PdfNumber(0.75));
}
[NUnit.Framework.Test]
public virtual void StrokeOpacitySetWithNoneStrokeRGBA() {
AbstractSvgNodeRenderer renderer = new CircleSvgNodeRenderer();
renderer.SetAttribute(SvgConstants.Attributes.STROKE_OPACITY, "0.75");
renderer.SetAttribute(SvgConstants.Attributes.STROKE, SvgConstants.Values.NONE);
renderer.Draw(sdc);
PdfResources resources = cv.GetResources();
NUnit.Framework.Assert.IsTrue(resources.GetResourceNames().IsEmpty());
}
[NUnit.Framework.Test]
public virtual void FillOpacitySetWithFillRGBA() {
AbstractSvgNodeRenderer renderer = new CircleSvgNodeRenderer();
renderer.SetAttribute(SvgConstants.Attributes.FILL_OPACITY, "0.75");
renderer.SetAttribute(SvgConstants.Attributes.FILL, "rgba(100,20,80,.75)");
renderer.Draw(sdc);
PdfResources resources = cv.GetResources();
NUnit.Framework.Assert.AreEqual(1, resources.GetResourceNames().Count);
PdfDictionary resDic = (PdfDictionary)resources.GetResourceObject(PdfName.ExtGState, DEFAULT_RESOURCE_NAME
);
NUnit.Framework.Assert.AreEqual(1, resDic.Size());
NUnit.Framework.Assert.AreEqual(resDic.Get(FILL_OPAC), new PdfNumber(0.5625));
}
[NUnit.Framework.Test]
public virtual void FillOpacitySetWithoutFillRGBA() {
AbstractSvgNodeRenderer renderer = new CircleSvgNodeRenderer();
renderer.SetAttribute(SvgConstants.Attributes.FILL_OPACITY, "0.75");
renderer.Draw(sdc);
PdfResources resources = cv.GetResources();
NUnit.Framework.Assert.AreEqual(1, resources.GetResourceNames().Count);
PdfDictionary resDic = (PdfDictionary)resources.GetResourceObject(PdfName.ExtGState, DEFAULT_RESOURCE_NAME
);
NUnit.Framework.Assert.AreEqual(1, resDic.Size());
NUnit.Framework.Assert.AreEqual(resDic.Get(FILL_OPAC), new PdfNumber(0.75));
}
[NUnit.Framework.Test]
public virtual void FillOpacitySetWithNoneFillRGBA() {
AbstractSvgNodeRenderer renderer = new CircleSvgNodeRenderer();
renderer.SetAttribute(SvgConstants.Attributes.FILL_OPACITY, "0.75");
renderer.SetAttribute(SvgConstants.Attributes.FILL, SvgConstants.Values.NONE);
renderer.Draw(sdc);
PdfResources resources = cv.GetResources();
NUnit.Framework.Assert.IsTrue(resources.GetResourceNames().IsEmpty());
}
[NUnit.Framework.Test]
public virtual void FillOpacitySetWithStrokeRGBA() {
AbstractSvgNodeRenderer renderer = new CircleSvgNodeRenderer();
renderer.SetAttribute(SvgConstants.Attributes.FILL_OPACITY, "0.75");
renderer.SetAttribute(SvgConstants.Attributes.STROKE, "rgba(100,20,80,.75)");
renderer.Draw(sdc);
PdfResources resources = cv.GetResources();
NUnit.Framework.Assert.AreEqual(1, resources.GetResourceNames().Count);
PdfDictionary resDic = (PdfDictionary)resources.GetResourceObject(PdfName.ExtGState, DEFAULT_RESOURCE_NAME
);
NUnit.Framework.Assert.AreEqual(2, resDic.Size());
NUnit.Framework.Assert.AreEqual(resDic.Get(STROKE_OPAC), new PdfNumber(0.75));
NUnit.Framework.Assert.AreEqual(resDic.Get(FILL_OPAC), new PdfNumber(0.75));
}
[NUnit.Framework.Test]
public virtual void FillAndStrokeOpacitySetWithStrokeAndFillRGBA() {
AbstractSvgNodeRenderer renderer = new CircleSvgNodeRenderer();
renderer.SetAttribute(SvgConstants.Attributes.FILL_OPACITY, "0.75");
renderer.SetAttribute(SvgConstants.Attributes.STROKE_OPACITY, "0.75");
renderer.SetAttribute(SvgConstants.Attributes.FILL, "rgba(100,20,80,.75)");
renderer.SetAttribute(SvgConstants.Attributes.STROKE, "rgba(60,90,180,.75)");
renderer.Draw(sdc);
PdfResources resources = cv.GetResources();
NUnit.Framework.Assert.AreEqual(1, resources.GetResourceNames().Count);
PdfDictionary resDic = (PdfDictionary)resources.GetResourceObject(PdfName.ExtGState, DEFAULT_RESOURCE_NAME
);
NUnit.Framework.Assert.AreEqual(2, resDic.Size());
NUnit.Framework.Assert.AreEqual(resDic.Get(FILL_OPAC), new PdfNumber(0.5625));
NUnit.Framework.Assert.AreEqual(resDic.Get(STROKE_OPAC), new PdfNumber(0.5625));
}
[NUnit.Framework.Test]
public virtual void NoOpacitySetWithStrokeRGBA() {
AbstractSvgNodeRenderer renderer = new CircleSvgNodeRenderer();
renderer.SetAttribute(SvgConstants.Attributes.STROKE, "rgba(100,20,80,.75)");
renderer.Draw(sdc);
PdfResources resources = cv.GetResources();
NUnit.Framework.Assert.AreEqual(1, resources.GetResourceNames().Count);
PdfDictionary resDic = (PdfDictionary)resources.GetResourceObject(PdfName.ExtGState, DEFAULT_RESOURCE_NAME
);
NUnit.Framework.Assert.AreEqual(1, resDic.Size());
NUnit.Framework.Assert.AreEqual(resDic.Get(STROKE_OPAC), new PdfNumber(0.75));
}
[NUnit.Framework.Test]
public virtual void NoOpacitySetWithoutStrokeRGBA() {
AbstractSvgNodeRenderer renderer = new CircleSvgNodeRenderer();
renderer.SetAttribute(SvgConstants.Attributes.STROKE_OPACITY, "0.75");
renderer.Draw(sdc);
PdfResources resources = cv.GetResources();
NUnit.Framework.Assert.IsTrue(resources.GetResourceNames().IsEmpty());
}
[NUnit.Framework.Test]
public virtual void NoOpacitySetWithFillRGBA() {
AbstractSvgNodeRenderer renderer = new CircleSvgNodeRenderer();
renderer.SetAttribute(SvgConstants.Attributes.FILL, "rgba(100,20,80,.75)");
renderer.Draw(sdc);
PdfResources resources = cv.GetResources();
NUnit.Framework.Assert.AreEqual(1, resources.GetResourceNames().Count);
PdfDictionary resDic = (PdfDictionary)resources.GetResourceObject(PdfName.ExtGState, DEFAULT_RESOURCE_NAME
);
NUnit.Framework.Assert.AreEqual(1, resDic.Size());
NUnit.Framework.Assert.AreEqual(resDic.Get(FILL_OPAC), new PdfNumber(0.75));
}
[NUnit.Framework.Test]
public virtual void NoOpacitySetWithNoneStrokeRGBA() {
AbstractSvgNodeRenderer renderer = new CircleSvgNodeRenderer();
renderer.SetAttribute(SvgConstants.Attributes.STROKE_OPACITY, "0.75");
renderer.SetAttribute(SvgConstants.Attributes.STROKE, SvgConstants.Values.NONE);
renderer.Draw(sdc);
PdfResources resources = cv.GetResources();
NUnit.Framework.Assert.IsTrue(resources.GetResourceNames().IsEmpty());
}
[NUnit.Framework.Test]
public virtual void NoOpacitySetWithNoneFillRGBA() {
AbstractSvgNodeRenderer renderer = new CircleSvgNodeRenderer();
renderer.SetAttribute(SvgConstants.Attributes.FILL, SvgConstants.Values.NONE);
renderer.Draw(sdc);
PdfResources resources = cv.GetResources();
NUnit.Framework.Assert.IsTrue(resources.GetResourceNames().IsEmpty());
}
[NUnit.Framework.Test]
public virtual void NoAndStrokeOpacitySetWithStrokeAndFillRGBA() {
AbstractSvgNodeRenderer renderer = new CircleSvgNodeRenderer();
renderer.SetAttribute(SvgConstants.Attributes.FILL, "rgba(100,20,80,.75)");
renderer.SetAttribute(SvgConstants.Attributes.STROKE, "rgba(60,90,180,.75)");
renderer.Draw(sdc);
PdfResources resources = cv.GetResources();
NUnit.Framework.Assert.AreEqual(1, resources.GetResourceNames().Count);
PdfDictionary resDic = (PdfDictionary)resources.GetResourceObject(PdfName.ExtGState, DEFAULT_RESOURCE_NAME
);
NUnit.Framework.Assert.AreEqual(2, resDic.Size());
NUnit.Framework.Assert.AreEqual(resDic.Get(FILL_OPAC), new PdfNumber(0.75));
NUnit.Framework.Assert.AreEqual(resDic.Get(STROKE_OPAC), new PdfNumber(0.75));
}
}
}

View File

@@ -0,0 +1,58 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using TSpdf.Svg.Exceptions;
using TSpdf.Test;
namespace TSpdf.Svg.Renderers.Factories {
[NUnit.Framework.Category("UnitTest")]
public class DefaultSvgNodeRendererFactoryTest : ExtendedTSpdfTest {
[NUnit.Framework.Test]
public virtual void CreateSvgNodeRenderer() {
ISvgNodeRendererFactory nodeRendererFactory = new DefaultSvgNodeRendererFactory();
Exception e = NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => nodeRendererFactory.CreateSvgNodeRendererForTag
(null, null));
NUnit.Framework.Assert.AreEqual(SvgExceptionMessageConstant.TAG_PARAMETER_NULL, e.Message);
}
}
}

View File

@@ -0,0 +1,42 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://TSpdfpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using TSpdf.Test;
namespace TSpdf.Svg.Renderers.Factories {
[NUnit.Framework.Category("UnitTest")]
public class DefaultSvgNodeRendererMapperTest : ExtendedTSpdfTest {
private DefaultSvgNodeRendererMapper mapper = new DefaultSvgNodeRendererMapper();
[NUnit.Framework.Test]
public virtual void MapperNotEmptyTest() {
bool result = mapper.GetMapping().IsEmpty();
NUnit.Framework.Assert.IsFalse(result);
}
[NUnit.Framework.Test]
public virtual void IgnoredTagsNotEmptyTest() {
bool result = mapper.GetIgnoredTags().IsEmpty();
NUnit.Framework.Assert.IsFalse(result);
}
}
}

View File

@@ -0,0 +1,79 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using TSpdf.Svg.Logs;
using TSpdf.Svg.Processors;
using TSpdf.Svg.Processors.Impl;
using TSpdf.Svg.Renderers;
using TSpdf.Test;
using TSpdf.Test.Attributes;
namespace TSpdf.Svg.Renderers.Impl {
[NUnit.Framework.Category("IntegrationTest")]
public class AnimationSvgTest : SvgIntegrationTest {
private static readonly String SOURCE_FOLDER = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/renderers/impl/AnimationSvgTest/";
private static readonly String DESTINATION_FOLDER = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/renderers/impl/AnimationSvgTest/";
private ISvgConverterProperties properties;
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateDestinationFolder(DESTINATION_FOLDER);
}
[NUnit.Framework.SetUp]
public virtual void Before() {
properties = new SvgConverterProperties().SetBaseUri(SOURCE_FOLDER);
}
[NUnit.Framework.Test]
[LogMessage(SvgLogMessageConstant.UNMAPPED_TAG)]
public virtual void Animation() {
//TODO: update when DEVSIX-2282 fixed
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "animation");
}
}
}

View File

@@ -0,0 +1,142 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using TSpdf.Svg.Renderers;
using TSpdf.Test;
namespace TSpdf.Svg.Renderers.Impl {
[NUnit.Framework.Category("IntegrationTest")]
public class CircleNodeRendererIntegrationTest : SvgIntegrationTest {
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/renderers/impl/CircleSvgNodeRendererTest/";
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/renderers/impl/CircleSvgNodeRendererTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateDestinationFolder(destinationFolder);
}
[NUnit.Framework.Test]
public virtual void BasicCircleTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "basicCircle");
}
[NUnit.Framework.Test]
public virtual void CircleCxCyAbsentTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "circleCxCyAbsent");
}
[NUnit.Framework.Test]
public virtual void CircleCxAbsentTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "circleCxAbsent");
}
[NUnit.Framework.Test]
public virtual void CircleCxNegativeTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "circleCxNegative");
}
[NUnit.Framework.Test]
public virtual void CircleCyAbsentTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "circleCyAbsent");
}
[NUnit.Framework.Test]
public virtual void CircleCyNegativeTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "circleCyNegative");
}
[NUnit.Framework.Test]
public virtual void CircleRAbsentTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "circleRAbsent");
}
[NUnit.Framework.Test]
public virtual void CircleRNegativeTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "circleRNegative");
}
[NUnit.Framework.Test]
public virtual void CircleTranslatedTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "circleTranslated");
}
[NUnit.Framework.Test]
public virtual void CircleRotatedTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "circleRotated");
}
[NUnit.Framework.Test]
public virtual void CircleScaledUpTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "circleScaledUp");
}
[NUnit.Framework.Test]
public virtual void CircleScaledDownTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "circleScaledDown");
}
[NUnit.Framework.Test]
public virtual void CircleScaledXYTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "circleScaledXY");
}
[NUnit.Framework.Test]
public virtual void CircleSkewXTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "circleSkewX");
}
[NUnit.Framework.Test]
public virtual void CircleSkewYTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "circleSkewY");
}
[NUnit.Framework.Test]
public virtual void CircleWithBigStrokeWidthTest() {
// TODO: DEVSIX-3932 update cmp_ after fix
ConvertAndCompare(sourceFolder, destinationFolder, "circleWithBigStrokeWidth");
}
}
}

View File

@@ -0,0 +1,140 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using TSpdf.Svg.Processors.Impl;
using TSpdf.Svg.Renderers;
using TSpdf.Test;
namespace TSpdf.Svg.Renderers.Impl {
[NUnit.Framework.Category("IntegrationTest")]
public class ClipPathSvgNodeRendererIntegrationTest : SvgIntegrationTest {
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/renderers/impl/ClipPathTest/";
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/renderers/impl/ClipPathTest/";
private SvgConverterProperties properties;
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateDestinationFolder(destinationFolder);
}
[NUnit.Framework.Test]
public virtual void RectClipPathComplexTest() {
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "clippath_rect_complex");
}
[NUnit.Framework.Test]
public virtual void RectClipPathSimpleTest() {
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "clippath_rect_simple");
}
[NUnit.Framework.Test]
public virtual void CircleClipPathComplexTest() {
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "clippath_circle_complex");
}
[NUnit.Framework.Test]
public virtual void CircleClipPathSimpleTest() {
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "clippath_circle_simple");
}
[NUnit.Framework.Test]
public virtual void MultiClipPathComplexTest() {
//TODO: update cmp file after DEVSIX-4044 will be fixed
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "clippath_multi_complex");
}
[NUnit.Framework.Test]
public virtual void MoveClipPathTest() {
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "clippath_move");
}
[NUnit.Framework.Test]
public virtual void MoveClipPathRuleMultipleTest() {
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "clippath_rule_multiple");
}
[NUnit.Framework.Test]
public virtual void ClipRule() {
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "clipRule");
}
[NUnit.Framework.Test]
public virtual void ClipPathRuleParameterVsFillRule() {
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "clipPathRuleParameterVsFillRule");
}
[NUnit.Framework.Test]
public virtual void ClipPathRuleEvenoddNonzero() {
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "clipPathRuleEvenoddNonzero");
}
[NUnit.Framework.Test]
public virtual void ClipPathCss() {
//TODO: update after DEVSIX-2827
properties = new SvgConverterProperties().SetBaseUri(sourceFolder);
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "clipPathCss", properties);
}
[NUnit.Framework.Test]
public virtual void ClipPathCssProperty() {
properties = new SvgConverterProperties().SetBaseUri(sourceFolder);
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "clipPathCssProperty", properties);
}
[NUnit.Framework.Test]
public virtual void ClipPathRulesCombined() {
//TODO: update after DEVSIX-2377
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "clipPathRulesCombined");
}
[NUnit.Framework.Test]
public virtual void InvalidClipPathTagTest() {
// TODO: DEVSIX-3923 update cmp_ after fix
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "clippath_invalid_tag");
}
}
}

View File

@@ -0,0 +1,205 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using System.Collections.Generic;
using System.IO;
using TSpdf.Kernel.Pdf;
using TSpdf.Kernel.Pdf.Canvas;
using TSpdf.Layout.Font;
using TSpdf.StyledXmlParser.Resolver.Resource;
using TSpdf.Svg;
using TSpdf.Svg.Renderers;
namespace TSpdf.Svg.Renderers.Impl {
[NUnit.Framework.Category("IntegrationTest")]
public class ClipPathSvgNodeRendererLowLevelIntegrationTest : SvgIntegrationTest {
private PdfCanvas cv;
private SvgDrawContext sdc;
[NUnit.Framework.SetUp]
public virtual void SetupDrawContextAndCanvas() {
sdc = new SvgDrawContext(new ResourceResolver(""), new FontProvider());
// set compression to none, in case you want to write to disk and inspect the created document
PdfWriter writer = new PdfWriter(new MemoryStream(), new WriterProperties().SetCompressionLevel(0));
PdfDocument doc = new PdfDocument(writer);
cv = new PdfCanvas(doc.AddNewPage());
sdc.PushCanvas(cv);
}
[NUnit.Framework.TearDown]
public virtual void Close() {
cv.GetDocument().Close();
}
[NUnit.Framework.Test]
public virtual void TestEmptyClipPathRendererNotDrawn() {
ClipPathSvgNodeRenderer clipRenderer = new ClipPathSvgNodeRenderer();
clipRenderer.SetAttributesAndStyles(new Dictionary<String, String>());
clipRenderer.Draw(sdc);
NUnit.Framework.Assert.AreEqual(0, cv.GetContentStream().GetBytes().Length);
}
[NUnit.Framework.Test]
public virtual void TestEmptyEoClipPathRendererNotDrawn() {
ClipPathSvgNodeRenderer clipRenderer = new ClipPathSvgNodeRenderer();
clipRenderer.SetAttribute(SvgConstants.Attributes.CLIP_RULE, SvgConstants.Values.FILL_RULE_EVEN_ODD);
clipRenderer.Draw(sdc);
NUnit.Framework.Assert.AreEqual(0, cv.GetContentStream().GetBytes().Length);
}
[NUnit.Framework.Test]
public virtual void TestRectClipPathRenderer() {
ClipPathSvgNodeRenderer clipRenderer = new ClipPathSvgNodeRenderer();
clipRenderer.SetAttributesAndStyles(new Dictionary<String, String>());
RectangleSvgNodeRenderer rectRenderer = new RectangleSvgNodeRenderer();
rectRenderer.SetAttribute(SvgConstants.Attributes.WIDTH, "400");
rectRenderer.SetAttribute(SvgConstants.Attributes.HEIGHT, "400");
clipRenderer.AddChild(rectRenderer);
clipRenderer.Draw(sdc);
NUnit.Framework.Assert.AreEqual("q\n% rect\n0 0 300 300 re\nW\nn\nQ\n", TSpdf.Commons.Utils.JavaUtil.GetStringForBytes
(cv.GetContentStream().GetBytes()));
}
[NUnit.Framework.Test]
public virtual void TestRectClipPathEoRendererNoChange() {
ClipPathSvgNodeRenderer clipRenderer = new ClipPathSvgNodeRenderer();
// clip-rule can only be set on elements in a clipPath, and must not have any influence on drawing
clipRenderer.SetAttribute(SvgConstants.Attributes.CLIP_RULE, SvgConstants.Values.FILL_RULE_EVEN_ODD);
RectangleSvgNodeRenderer rectRenderer = new RectangleSvgNodeRenderer();
rectRenderer.SetAttribute(SvgConstants.Attributes.WIDTH, "400");
rectRenderer.SetAttribute(SvgConstants.Attributes.HEIGHT, "400");
clipRenderer.AddChild(rectRenderer);
clipRenderer.Draw(sdc);
NUnit.Framework.Assert.AreEqual("q\n% rect\n0 0 300 300 re\nW\nn\nQ\n", TSpdf.Commons.Utils.JavaUtil.GetStringForBytes
(cv.GetContentStream().GetBytes()));
}
[NUnit.Framework.Test]
public virtual void TestRectEoClipPathRenderer() {
ClipPathSvgNodeRenderer clipRenderer = new ClipPathSvgNodeRenderer();
clipRenderer.SetAttributesAndStyles(new Dictionary<String, String>());
RectangleSvgNodeRenderer rectRenderer = new RectangleSvgNodeRenderer();
rectRenderer.SetAttribute(SvgConstants.Attributes.WIDTH, "400");
rectRenderer.SetAttribute(SvgConstants.Attributes.HEIGHT, "400");
rectRenderer.SetAttribute(SvgConstants.Attributes.CLIP_RULE, SvgConstants.Values.FILL_RULE_EVEN_ODD);
clipRenderer.AddChild(rectRenderer);
clipRenderer.Draw(sdc);
NUnit.Framework.Assert.AreEqual("q\n% rect\n0 0 300 300 re\nW*\nn\nQ\n", TSpdf.Commons.Utils.JavaUtil.GetStringForBytes
(cv.GetContentStream().GetBytes()));
}
[NUnit.Framework.Test]
public virtual void TestAppliedClipPathRenderer() {
AbstractBranchSvgNodeRenderer clipPathRenderer = new ClipPathSvgNodeRenderer();
clipPathRenderer.SetAttribute(SvgConstants.Attributes.ID, "randomString");
ISvgNodeRenderer clippedRenderer = new RectangleSvgNodeRenderer();
clippedRenderer.SetAttribute(SvgConstants.Attributes.WIDTH, "80");
clippedRenderer.SetAttribute(SvgConstants.Attributes.HEIGHT, "80");
clipPathRenderer.AddChild(clippedRenderer);
sdc.AddNamedObject("randomString", clipPathRenderer);
ISvgNodeRenderer drawnRenderer = new CircleSvgNodeRenderer();
drawnRenderer.SetAttribute(SvgConstants.Attributes.R, "84");
drawnRenderer.SetAttribute(SvgConstants.Attributes.CLIP_PATH, "url(#randomString)");
drawnRenderer.Draw(sdc);
String expected = "q\n" + "% rect\n" + "0 0 60 60 re\n" + "W\n" + "n\n" + "0 0 0 rg\n" + "% ellipse\n" + "63 0 m\n"
+ "63 34.79 34.79 63 0 63 c\n" + "-34.79 63 -63 34.79 -63 0 c\n" + "-63 -34.79 -34.79 -63 0 -63 c\n"
+ "34.79 -63 63 -34.79 63 0 c\n" + "f\n" + "Q\n";
NUnit.Framework.Assert.AreEqual(expected, TSpdf.Commons.Utils.JavaUtil.GetStringForBytes(cv.GetContentStream
().GetBytes()));
}
[NUnit.Framework.Test]
public virtual void TestAppliedGroupClipPathRenderer() {
AbstractBranchSvgNodeRenderer clipPathRenderer = new ClipPathSvgNodeRenderer();
clipPathRenderer.SetAttribute(SvgConstants.Attributes.ID, "randomString");
ISvgNodeRenderer clippedRenderer = new RectangleSvgNodeRenderer();
clippedRenderer.SetAttribute(SvgConstants.Attributes.WIDTH, "80");
clippedRenderer.SetAttribute(SvgConstants.Attributes.HEIGHT, "80");
clipPathRenderer.AddChild(clippedRenderer);
sdc.AddNamedObject("randomString", clipPathRenderer);
AbstractBranchSvgNodeRenderer groupRenderer = new GroupSvgNodeRenderer();
groupRenderer.SetAttributesAndStyles(new Dictionary<String, String>());
ISvgNodeRenderer drawnRenderer = new CircleSvgNodeRenderer();
drawnRenderer.SetAttribute(SvgConstants.Attributes.R, "84");
drawnRenderer.SetAttribute(SvgConstants.Attributes.CLIP_PATH, "url(#randomString)");
groupRenderer.AddChild(drawnRenderer);
groupRenderer.Draw(sdc);
String expected = "0 0 0 rg\n" + "q\n" + "q\n" + "% rect\n" + "0 0 60 60 re\n" + "W\n" + "n\n" + "% ellipse\n"
+ "63 0 m\n" + "63 34.79 34.79 63 0 63 c\n" + "-34.79 63 -63 34.79 -63 0 c\n" + "-63 -34.79 -34.79 -63 0 -63 c\n"
+ "34.79 -63 63 -34.79 63 0 c\n" + "f\n" + "Q\n" + "Q\n";
NUnit.Framework.Assert.AreEqual(expected, TSpdf.Commons.Utils.JavaUtil.GetStringForBytes(cv.GetContentStream
().GetBytes()));
}
[NUnit.Framework.Test]
public virtual void TestEoAppliedGroupClipPathRenderer() {
AbstractBranchSvgNodeRenderer clipPathRenderer = new ClipPathSvgNodeRenderer();
clipPathRenderer.SetAttribute(SvgConstants.Attributes.ID, "randomString");
ISvgNodeRenderer clippedRenderer = new RectangleSvgNodeRenderer();
clippedRenderer.SetAttribute(SvgConstants.Attributes.WIDTH, "80");
clippedRenderer.SetAttribute(SvgConstants.Attributes.HEIGHT, "80");
clippedRenderer.SetAttribute(SvgConstants.Attributes.CLIP_RULE, SvgConstants.Values.FILL_RULE_EVEN_ODD);
ISvgNodeRenderer clippedRenderer2 = new RectangleSvgNodeRenderer();
clippedRenderer2.SetAttribute(SvgConstants.Attributes.WIDTH, "80");
clippedRenderer2.SetAttribute(SvgConstants.Attributes.HEIGHT, "80");
clipPathRenderer.AddChild(clippedRenderer);
clipPathRenderer.AddChild(clippedRenderer2);
sdc.AddNamedObject("randomString", clipPathRenderer);
AbstractBranchSvgNodeRenderer groupRenderer = new GroupSvgNodeRenderer();
groupRenderer.SetAttributesAndStyles(new Dictionary<String, String>());
ISvgNodeRenderer drawnRenderer = new CircleSvgNodeRenderer();
drawnRenderer.SetAttribute(SvgConstants.Attributes.R, "84");
drawnRenderer.SetAttribute(SvgConstants.Attributes.CLIP_PATH, "url(#randomString)");
groupRenderer.AddChild(drawnRenderer);
groupRenderer.Draw(sdc);
String expected = "0 0 0 rg\n" + "q\n" + "q\n" + "% rect\n" + "0 0 60 60 re\n" + "W*\n" + "n\n" + "% ellipse\n"
+ "63 0 m\n" + "63 34.79 34.79 63 0 63 c\n" + "-34.79 63 -63 34.79 -63 0 c\n" + "-63 -34.79 -34.79 -63 0 -63 c\n"
+ "34.79 -63 63 -34.79 63 0 c\n" + "f\n" + "Q\n" + "q\n" + "% rect\n" + "0 0 60 60 re\n" + "W\n" + "n\n"
+ "% ellipse\n" + "63 0 m\n" + "63 34.79 34.79 63 0 63 c\n" + "-34.79 63 -63 34.79 -63 0 c\n" + "-63 -34.79 -34.79 -63 0 -63 c\n"
+ "34.79 -63 63 -34.79 63 0 c\n" + "f\n" + "Q\n" + "Q\n";
NUnit.Framework.Assert.AreEqual(expected, TSpdf.Commons.Utils.JavaUtil.GetStringForBytes(cv.GetContentStream
().GetBytes()));
}
}
}

View File

@@ -0,0 +1,34 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://TSpdfpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using TSpdf.Test;
namespace TSpdf.Svg.Renderers.Impl {
[NUnit.Framework.Category("UnitTest")]
public class ClipPathSvgNodeRendererUnitTest : ExtendedTSpdfTest {
[NUnit.Framework.Test]
public virtual void NoObjectBoundingBoxTest() {
ClipPathSvgNodeRenderer renderer = new ClipPathSvgNodeRenderer();
NUnit.Framework.Assert.IsNull(renderer.GetObjectBoundingBox(null));
}
}
}

View File

@@ -0,0 +1,81 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using TSpdf.Svg.Renderers;
using TSpdf.Test;
namespace TSpdf.Svg.Renderers.Impl {
[NUnit.Framework.Category("IntegrationTest")]
public class DefsSvgNodeRendererIntegrationTest : SvgIntegrationTest {
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/renderers/impl/DefsSvgNodeRendererTest/";
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/renderers/impl/DefsSvgNodeRendererTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateDestinationFolder(destinationFolder);
}
[NUnit.Framework.Test]
public virtual void DefsWithNoChildrenTest() {
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "onlyDefsWithNoChildren");
}
[NUnit.Framework.Test]
public virtual void DefsWithOneChildTest() {
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "onlyDefsWithOneChild");
}
[NUnit.Framework.Test]
public virtual void DefsWithMultipleChildrenTest() {
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "onlyDefsWithMultipleChildren");
}
[NUnit.Framework.Test]
public virtual void DefsWithOneChildAndNonDefsBeingDrawnTest() {
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "defsWithOneChildAndNonDefsBeingDrawn");
}
}
}

View File

@@ -0,0 +1,97 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using System.IO;
using TSpdf.StyledXmlParser.Node;
using TSpdf.Svg.Converter;
using TSpdf.Svg.Processors;
using TSpdf.Svg.Processors.Impl;
using TSpdf.Test;
namespace TSpdf.Svg.Renderers.Impl {
[NUnit.Framework.Category("UnitTest")]
public class DefsSvgNodeRendererUnitTest : ExtendedTSpdfTest {
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/renderers/impl/DefsSvgNodeRendererTest/";
[NUnit.Framework.Test]
public virtual void ProcessDefsNoChildrenTest() {
INode parsedSvg = SvgConverter.Parse(new FileStream(sourceFolder + "onlyDefsWithNoChildren.svg", FileMode.Open
, FileAccess.Read));
ISvgProcessorResult result = new DefaultSvgProcessor().Process(parsedSvg, null);
NUnit.Framework.Assert.IsTrue(result.GetNamedObjects().IsEmpty());
}
[NUnit.Framework.Test]
public virtual void ProcessDefsOneChildTest() {
INode parsedSvg = SvgConverter.Parse(new FileStream(sourceFolder + "onlyDefsWithOneChild.svg", FileMode.Open
, FileAccess.Read));
ISvgProcessorResult result = new DefaultSvgProcessor().Process(parsedSvg, null);
NUnit.Framework.Assert.IsTrue(result.GetNamedObjects().Get("circle1") is CircleSvgNodeRenderer);
}
[NUnit.Framework.Test]
public virtual void ProcessDefsMultipleChildrenTest() {
INode parsedSvg = SvgConverter.Parse(new FileStream(sourceFolder + "onlyDefsWithMultipleChildren.svg", FileMode.Open
, FileAccess.Read));
ISvgProcessorResult result = new DefaultSvgProcessor().Process(parsedSvg, null);
NUnit.Framework.Assert.IsTrue(result.GetNamedObjects().Get("circle1") is CircleSvgNodeRenderer);
NUnit.Framework.Assert.IsTrue(result.GetNamedObjects().Get("line1") is LineSvgNodeRenderer);
NUnit.Framework.Assert.IsTrue(result.GetNamedObjects().Get("rect1") is RectangleSvgNodeRenderer);
}
[NUnit.Framework.Test]
public virtual void ProcessDefsParentShouldBeNullTest() {
INode parsedSvg = SvgConverter.Parse(new FileStream(sourceFolder + "onlyDefsWithOneChild.svg", FileMode.Open
, FileAccess.Read));
ISvgProcessorResult result = new DefaultSvgProcessor().Process(parsedSvg, null);
NUnit.Framework.Assert.IsNull(result.GetNamedObjects().Get("circle1").GetParent());
}
[NUnit.Framework.Test]
public virtual void NoObjectBoundingBoxTest() {
DefsSvgNodeRenderer renderer = new DefsSvgNodeRenderer();
NUnit.Framework.Assert.IsNull(renderer.GetObjectBoundingBox(null));
}
}
}

View File

@@ -0,0 +1,80 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://TSpdfpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System;
using TSpdf.StyledXmlParser.Css.Validate;
using TSpdf.StyledXmlParser.Css.Validate.Impl;
using TSpdf.Svg.Processors;
using TSpdf.Svg.Processors.Impl;
using TSpdf.Svg.Renderers;
using TSpdf.Test;
using TSpdf.Test.Attributes;
namespace TSpdf.Svg.Renderers.Impl {
public class DeviceCmykSvgTest : SvgIntegrationTest {
private static readonly String SOURCE_FOLDER = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/renderers/impl/DeviceCmykTest/";
private static readonly String DESTINATION_FOLDER = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/renderers/impl/DeviceCmykTest/";
private ISvgConverterProperties properties;
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateDestinationFolder(DESTINATION_FOLDER);
CssDeclarationValidationMaster.SetValidator(new CssDeviceCmykAwareValidator());
}
[NUnit.Framework.SetUp]
public virtual void Before() {
properties = new SvgConverterProperties().SetBaseUri(SOURCE_FOLDER);
}
[NUnit.Framework.OneTimeTearDown]
public static void AfterClass() {
CssDeclarationValidationMaster.SetValidator(new CssDefaultValidator());
}
[NUnit.Framework.Test]
public virtual void SvgFillColorTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "svgFillColor");
}
[NUnit.Framework.Test]
public virtual void SvgStrokeColorTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "svgStrokeColor");
}
[NUnit.Framework.Test]
public virtual void SvgFillStrokeColorTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "svgFillStrokeColor");
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.StyledXmlParser.Logs.StyledXmlParserLogMessageConstant.UNKNOWN_ABSOLUTE_METRIC_LENGTH_PARSED
)]
public virtual void SvgSimpleShapesColorTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "svgSimpleShapesColor");
}
}
}

View File

@@ -0,0 +1,182 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using TSpdf.Kernel.Pdf;
using TSpdf.Kernel.Pdf.Canvas;
using TSpdf.Svg;
using TSpdf.Svg.Renderers;
using TSpdf.Test;
namespace TSpdf.Svg.Renderers.Impl {
[NUnit.Framework.Category("IntegrationTest")]
public class EllipseSvgNodeRendererIntegrationTest : SvgIntegrationTest {
public static readonly String SOURCE_FOLDER = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/renderers/impl/EllipseSvgNodeRendererIntegrationTest/";
public static readonly String DESTINATION_FOLDER = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/renderers/impl/EllipseSvgNodeRendererIntegrationTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateDestinationFolder(DESTINATION_FOLDER);
}
[NUnit.Framework.Test]
public virtual void BasicEllipseTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "basicEllipse");
}
[NUnit.Framework.Test]
public virtual void EllipseCxCyAbsentTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "ellipseCxCyAbsent");
}
[NUnit.Framework.Test]
public virtual void EllipseCxAbsentTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "ellipseCxAbsent");
}
[NUnit.Framework.Test]
public virtual void EllipseCxNegativeTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "ellipseCxNegative");
}
[NUnit.Framework.Test]
public virtual void EllipseCyNegativeTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "ellipseCyNegative");
}
[NUnit.Framework.Test]
public virtual void EllipseCyAbsentTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "ellipseCyAbsent");
}
[NUnit.Framework.Test]
public virtual void EllipseRxAbsentTest() {
//TODO: update cmp_ when DEVSIX-3119
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "ellipseRxAbsent");
}
[NUnit.Framework.Test]
public virtual void EllipseRyAbsentTest() {
//TODO: update cmp_ when DEVSIX-3119
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "ellipseRyAbsent");
}
[NUnit.Framework.Test]
public virtual void EllipseRxNegativeTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "ellipseRxNegative");
}
[NUnit.Framework.Test]
public virtual void EllipseRyNegativeTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "ellipseRyNegative");
}
[NUnit.Framework.Test]
public virtual void EllipseTranslatedTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "ellipseTranslated");
}
[NUnit.Framework.Test]
public virtual void EllipseRotatedTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "ellipseRotated");
}
[NUnit.Framework.Test]
public virtual void EllipseScaledUpTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "ellipseScaledUp");
}
[NUnit.Framework.Test]
public virtual void EllipseScaledDownTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "ellipseScaledDown");
}
[NUnit.Framework.Test]
public virtual void EllipseScaledXYTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "ellipseScaledXY");
}
[NUnit.Framework.Test]
public virtual void EllipseSkewXTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "ellipseSkewX");
}
[NUnit.Framework.Test]
public virtual void EllipseSkewYTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "ellipseSkewY");
}
[NUnit.Framework.Test]
public virtual void ParseParametersAndCalculateCoordinatesWithBetterPrecisionEllipseTest() {
String filename = "calculateCoordinatesWithBetterPrecision.pdf";
PdfDocument doc = new PdfDocument(new PdfWriter(DESTINATION_FOLDER + filename));
doc.AddNewPage();
EllipseSvgNodeRenderer ellipseRenderer = new EllipseSvgNodeRenderer();
ellipseRenderer.SetAttribute(SvgConstants.Attributes.CX, "170.3");
ellipseRenderer.SetAttribute(SvgConstants.Attributes.CY, "339.5");
ellipseRenderer.SetAttribute(SvgConstants.Attributes.RX, "6");
ellipseRenderer.SetAttribute(SvgConstants.Attributes.RY, "6");
// Parse parameters with better precision (in double type) in the method CssUtils#parseAbsoluteLength
ellipseRenderer.SetParameters();
SvgDrawContext context = new SvgDrawContext(null, null);
PdfCanvas cv = new PdfCanvas(doc, 1);
context.PushCanvas(cv);
// Calculate coordinates with better precision (in double type) in the method EllipseSvgNodeRenderer#doDraw
ellipseRenderer.Draw(context);
String pageContentBytes = TSpdf.Commons.Utils.JavaUtil.GetStringForBytes(doc.GetPage(1).GetContentBytes(),
System.Text.Encoding.UTF8);
doc.Close();
String expectedResult = "132.22 254.63 m\n" + "132.22 257.11 130.21 259.13 127.72 259.13 c\n" + "125.24 259.13 123.22 257.11 123.22 254.63 c\n"
+ "123.22 252.14 125.24 250.13 127.72 250.13 c\n" + "130.21 250.13 132.22 252.14 132.22 254.63 c";
NUnit.Framework.Assert.IsTrue(pageContentBytes.Contains(expectedResult));
}
[NUnit.Framework.Test]
public virtual void EllipseWithBigStrokeWidthTest() {
// TODO: DEVSIX-3932 update cmp_ after fix
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "ellipseWithBigStrokeWidth");
}
}
}

View File

@@ -0,0 +1,41 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://TSpdfpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using TSpdf.Layout.Font;
using TSpdf.StyledXmlParser.Resolver.Resource;
using TSpdf.Svg.Renderers;
using TSpdf.Test;
namespace TSpdf.Svg.Renderers.Impl {
[NUnit.Framework.Category("UnitTest")]
public class EllipseSvgNodeRendererUnitTest : ExtendedTSpdfTest {
[NUnit.Framework.Test]
public virtual void GetObjectBoundingBoxTest() {
EllipseSvgNodeRenderer renderer = new EllipseSvgNodeRenderer();
SvgDrawContext context = new SvgDrawContext(new ResourceResolver(""), new FontProvider());
renderer.SetAttributesAndStyles(new Dictionary<String, String>());
NUnit.Framework.Assert.IsNull(renderer.GetObjectBoundingBox(context));
}
}
}

View File

@@ -0,0 +1,129 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using TSpdf.Svg.Processors.Impl;
using TSpdf.Svg.Renderers;
using TSpdf.Test;
namespace TSpdf.Svg.Renderers.Impl {
[NUnit.Framework.Category("IntegrationTest")]
public class GroupSvgNodeRendererIntegrationTest : SvgIntegrationTest {
private static readonly String SOURCE_FOLDER = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/renderers/impl/GroupRendererTest/";
private static readonly String DESTINATION_FOLDER = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/renderers/impl/GroupRendererTest/";
private SvgConverterProperties properties;
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateDestinationFolder(DESTINATION_FOLDER);
}
[NUnit.Framework.Test]
public virtual void NestedGroupReuseTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "nestedGroupReuse");
}
[NUnit.Framework.Test]
public virtual void NestedGroupWithoutReuseTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "nestedGroupWithoutReuse");
}
[NUnit.Framework.Test]
public virtual void SimpleGroupReuseTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "simpleGroupReuse");
}
[NUnit.Framework.Test]
public virtual void NestedGroupTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "nestedGroup");
}
[NUnit.Framework.Test]
public virtual void OverlayingGroupsTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "overlayingGroups");
}
[NUnit.Framework.Test]
public virtual void OverlappingBorderTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "overlappingBorder");
}
[NUnit.Framework.Test]
public virtual void MoreOverlappingBorderTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "moreOverlappingBorder");
}
[NUnit.Framework.Test]
public virtual void MoreOverlappingBorderWithCenterSquareTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "moreOverlappingBorderWithCenterSquare");
}
[NUnit.Framework.Test]
public virtual void MoreOverlappingBorderWithTwoSideSquaresTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "moreOverlappingBorderWithTwoSideSquares");
}
[NUnit.Framework.Test]
public virtual void CompleteOverlappingBorderTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "completeOverlappingBorder");
}
[NUnit.Framework.Test]
public virtual void TranslatedGroupTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "translated");
}
[NUnit.Framework.Test]
public virtual void MultipleTransformationsTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "multipleTransformations");
}
[NUnit.Framework.Test]
public virtual void FillGradientTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "fillGradient");
}
}
}

View File

@@ -0,0 +1,34 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://TSpdfpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using TSpdf.Test;
namespace TSpdf.Svg.Renderers.Impl {
[NUnit.Framework.Category("UnitTest")]
public class GroupSvgNodeRendererUnitTest : ExtendedTSpdfTest {
[NUnit.Framework.Test]
public virtual void NoObjectBoundingBoxTest() {
GroupSvgNodeRenderer renderer = new GroupSvgNodeRenderer();
NUnit.Framework.Assert.IsNull(renderer.GetObjectBoundingBox(null));
}
}
}

View File

@@ -0,0 +1,208 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using TSpdf.Svg.Processors;
using TSpdf.Svg.Processors.Impl;
using TSpdf.Svg.Renderers;
using TSpdf.Test;
namespace TSpdf.Svg.Renderers.Impl {
[NUnit.Framework.Category("IntegrationTest")]
public class ImageSvgNodeRendererIntegrationTest : SvgIntegrationTest {
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/renderers/impl/ImageSvgNodeRendererTest/";
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/renderers/impl/ImageSvgNodeRendererTest/";
private ISvgConverterProperties properties;
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateDestinationFolder(destinationFolder);
}
[NUnit.Framework.SetUp]
public virtual void Before() {
properties = new SvgConverterProperties().SetBaseUri(sourceFolder);
}
[NUnit.Framework.Test]
public virtual void SingleImageTest() {
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "singleImage", properties);
}
[NUnit.Framework.Test]
public virtual void ImageWithRectangleTest() {
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "imageWithRectangle", properties);
}
[NUnit.Framework.Test]
public virtual void ImageWithMultipleShapesTest() {
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "imageWithMultipleShapes", properties);
}
[NUnit.Framework.Test]
public virtual void ImageXYTest() {
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "imageXY", properties);
}
[NUnit.Framework.Test]
public virtual void MultipleImagesTest() {
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "multipleImages", properties);
}
[NUnit.Framework.Test]
public virtual void NonSquareImageTest() {
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "nonSquareImage", properties);
}
[NUnit.Framework.Test]
public virtual void SingleImageTranslateTest() {
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "singleImageTranslate", properties);
}
[NUnit.Framework.Test]
public virtual void SingleImageRotateTest() {
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "singleImageRotate", properties);
}
[NUnit.Framework.Test]
public virtual void SingleImageScaleUpTest() {
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "singleImageScaleUp", properties);
}
[NUnit.Framework.Test]
public virtual void SingleImageScaleDownTest() {
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "singleImageScaleDown", properties);
}
[NUnit.Framework.Test]
public virtual void SingleImageMultipleTransformationsTest() {
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "singleImageMultipleTransformations", properties
);
}
[NUnit.Framework.Test]
public virtual void TwoImagesWithTransformationsTest() {
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "twoImagesWithTransformations", properties);
}
[NUnit.Framework.Test]
public virtual void DifferentDimensionsTest() {
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "differentDimensions", properties);
}
[NUnit.Framework.Test]
public virtual void ImageWithTransparencyTest() {
//TODO: update cmp_ when DEVSIX-2250, DEVSIX-2258 fixed
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "imageWithTransparency", properties);
}
[NUnit.Framework.Test]
public virtual void ImageWithPreserveAspectRatioNoneTest() {
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "imageWithPreserveAspectRatioNone", properties
);
}
[NUnit.Framework.Test]
public virtual void ImageWithPreserveAspectRatioInvalidValueTest() {
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "imageWithPreserveAspectRatioInvalidValue", properties
);
}
[NUnit.Framework.Test]
public virtual void ImageWithPreserveAspectRatioXMinYMinTest() {
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "imageWithPreserveAspectRatioXMinYMin", properties
);
}
[NUnit.Framework.Test]
public virtual void ImageWithPreserveAspectRatioXMinYMidTest() {
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "imageWithPreserveAspectRatioXMinYMid", properties
);
}
[NUnit.Framework.Test]
public virtual void ImageWithPreserveAspectRatioXMinYMaxTest() {
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "imageWithPreserveAspectRatioXMinYMax", properties
);
}
[NUnit.Framework.Test]
public virtual void ImageWithPreserveAspectRatioXMidYMinTest() {
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "imageWithPreserveAspectRatioXMidYMin", properties
);
}
[NUnit.Framework.Test]
public virtual void ImageWithPreserveAspectRatioXMidYMidTest() {
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "imageWithPreserveAspectRatioXMidYMid", properties
);
}
[NUnit.Framework.Test]
public virtual void ImageWithPreserveAspectRatioXMidYMaxTest() {
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "imageWithPreserveAspectRatioXMidYMax", properties
);
}
[NUnit.Framework.Test]
public virtual void ImageWithPreserveAspectRatioXMaxYMinTest() {
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "imageWithPreserveAspectRatioXMaxYMin", properties
);
}
[NUnit.Framework.Test]
public virtual void ImageWithPreserveAspectRatioXMaxYMidTest() {
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "imageWithPreserveAspectRatioXMaxYMid", properties
);
}
[NUnit.Framework.Test]
public virtual void ImageWithPreserveAspectRatioXMaxYMaxTest() {
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "imageWithPreserveAspectRatioXMaxYMax", properties
);
}
}
}

View File

@@ -0,0 +1,34 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://TSpdfpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using TSpdf.Test;
namespace TSpdf.Svg.Renderers.Impl {
[NUnit.Framework.Category("UnitTest")]
public class ImageSvgNodeRendererUnitTest : ExtendedTSpdfTest {
[NUnit.Framework.Test]
public virtual void NoObjectBoundingBoxTest() {
ImageSvgNodeRenderer renderer = new ImageSvgNodeRenderer();
NUnit.Framework.Assert.IsNull(renderer.GetObjectBoundingBox(null));
}
}
}

View File

@@ -0,0 +1,189 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using System.Collections.Generic;
using System.IO;
using TSpdf.Commons.Utils;
using TSpdf.Kernel.Pdf;
using TSpdf.Kernel.Pdf.Canvas;
using TSpdf.Kernel.Utils;
using TSpdf.StyledXmlParser.Exceptions;
using TSpdf.Svg.Renderers;
using TSpdf.Test;
using TSpdf.Test.Attributes;
namespace TSpdf.Svg.Renderers.Impl {
[NUnit.Framework.Category("IntegrationTest")]
public class LineSvgNodeRendererTest : SvgIntegrationTest {
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/renderers/impl/LineSvgNodeRendererTest/";
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/renderers/impl/LineSvgNodeRendererTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateDestinationFolder(destinationFolder);
}
[NUnit.Framework.Test]
public virtual void LineRendererTest() {
String filename = "lineSvgRendererTest.pdf";
PdfDocument doc = new PdfDocument(new PdfWriter(destinationFolder + filename));
doc.AddNewPage();
IDictionary<String, String> lineProperties = new Dictionary<String, String>();
lineProperties.Put("x1", "100");
lineProperties.Put("y1", "800");
lineProperties.Put("x2", "300");
lineProperties.Put("y2", "800");
lineProperties.Put("stroke", "green");
lineProperties.Put("stroke-width", "25");
LineSvgNodeRenderer root = new LineSvgNodeRenderer();
root.SetAttributesAndStyles(lineProperties);
SvgDrawContext context = new SvgDrawContext(null, null);
PdfCanvas cv = new PdfCanvas(doc, 1);
context.PushCanvas(cv);
root.Draw(context);
doc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + filename, sourceFolder
+ "cmp_" + filename, destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void LineWithEmpyAttributesTest() {
String filename = "lineWithEmpyAttributesTest.pdf";
PdfDocument doc = new PdfDocument(new PdfWriter(destinationFolder + filename));
doc.AddNewPage();
IDictionary<String, String> lineProperties = new Dictionary<String, String>();
LineSvgNodeRenderer root = new LineSvgNodeRenderer();
root.SetAttributesAndStyles(lineProperties);
SvgDrawContext context = new SvgDrawContext(null, null);
PdfCanvas cv = new PdfCanvas(doc, 1);
context.PushCanvas(cv);
root.Draw(context);
doc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + filename, sourceFolder
+ "cmp_" + filename, destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void InvalidAttributeTest01() {
PdfDocument doc = new PdfDocument(new PdfWriter(new MemoryStream()));
doc.AddNewPage();
ISvgNodeRenderer root = new LineSvgNodeRenderer();
IDictionary<String, String> lineProperties = new Dictionary<String, String>();
lineProperties.Put("x1", "1");
lineProperties.Put("y1", "800");
lineProperties.Put("x2", "notAnum");
lineProperties.Put("y2", "alsoNotANum");
root.SetAttributesAndStyles(lineProperties);
SvgDrawContext context = new SvgDrawContext(null, null);
PdfCanvas cv = new PdfCanvas(doc, 1);
context.PushCanvas(cv);
Exception e = NUnit.Framework.Assert.Catch(typeof(StyledXMLParserException), () => root.Draw(context));
NUnit.Framework.Assert.AreEqual(MessageFormatUtil.Format(StyledXMLParserException.NAN, "notAnum"), e.Message
);
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.StyledXmlParser.Logs.StyledXmlParserLogMessageConstant.UNKNOWN_ABSOLUTE_METRIC_LENGTH_PARSED
, Count = 2)]
public virtual void InvalidAttributeTest02() {
IDictionary<String, String> lineProperties = new Dictionary<String, String>();
lineProperties.Put("x1", "100");
lineProperties.Put("y1", "800");
lineProperties.Put("x2", "1 0");
lineProperties.Put("y2", "0 2 0");
lineProperties.Put("stroke", "orange");
String filename = "invalidAttributes02.pdf";
PdfDocument doc = new PdfDocument(new PdfWriter(destinationFolder + filename));
doc.AddNewPage();
LineSvgNodeRenderer root = new LineSvgNodeRenderer();
root.SetAttributesAndStyles(lineProperties);
SvgDrawContext context = new SvgDrawContext(null, null);
PdfCanvas cv = new PdfCanvas(doc, 1);
context.PushCanvas(cv);
root.Draw(context);
doc.Close();
}
[NUnit.Framework.Test]
public virtual void EmptyPointsListTest() {
String filename = "lineEmptyPointsListTest.pdf";
PdfDocument doc = new PdfDocument(new PdfWriter(destinationFolder + filename));
doc.AddNewPage();
ISvgNodeRenderer root = new LineSvgNodeRenderer();
IDictionary<String, String> lineProperties = new Dictionary<String, String>();
root.SetAttributesAndStyles(lineProperties);
SvgDrawContext context = new SvgDrawContext(null, null);
PdfCanvas cv = new PdfCanvas(doc, 1);
context.PushCanvas(cv);
root.Draw(context);
doc.Close();
int numPoints = ((LineSvgNodeRenderer)root).attributesAndStyles.Count;
NUnit.Framework.Assert.AreEqual(numPoints, 0);
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + filename, sourceFolder
+ "cmp_" + filename, destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void GetAttributeTest() {
float expected = 0.75f;
LineSvgNodeRenderer lineSvgNodeRenderer = new LineSvgNodeRenderer();
IDictionary<String, String> attributes = new Dictionary<String, String>();
attributes.Put("key", "1.0");
float actual = lineSvgNodeRenderer.GetAttribute(attributes, "key");
NUnit.Framework.Assert.AreEqual(expected, actual, 0f);
}
[NUnit.Framework.Test]
public virtual void GetNotPresentAttributeTest() {
float expected = 0f;
LineSvgNodeRenderer lineSvgNodeRenderer = new LineSvgNodeRenderer();
IDictionary<String, String> attributes = new Dictionary<String, String>();
attributes.Put("key", "1.0");
float actual = lineSvgNodeRenderer.GetAttribute(attributes, "notHere");
NUnit.Framework.Assert.AreEqual(expected, actual, 0f);
}
}
}

View File

@@ -0,0 +1,542 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://TSpdfpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System;
using TSpdf.Kernel.Geom;
using TSpdf.Svg.Logs;
using TSpdf.Svg.Renderers;
using TSpdf.Test;
using TSpdf.Test.Attributes;
namespace TSpdf.Svg.Renderers.Impl {
[NUnit.Framework.Category("IntegrationTest")]
public class LinearGradientSvgNodeRendererTest : SvgIntegrationTest {
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/renderers/impl/LinearGradientSvgNodeRendererTest/";
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/renderers/impl/LinearGradientSvgNodeRendererTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateOrClearDestinationFolder(destinationFolder);
}
// TODO: DEVSIX-3932 update cmp_ after fix
[NUnit.Framework.Test]
public virtual void CircleTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "circle");
}
// TODO: DEVSIX-3932 update cmp_ after fix
[NUnit.Framework.Test]
public virtual void EllipseTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "ellipse");
}
[NUnit.Framework.Test]
public virtual void LineTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "line");
}
[NUnit.Framework.Test]
public virtual void PathLinesBasedTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "pathLinesBased");
}
[NUnit.Framework.Test]
public virtual void PathLinesBasedTransformedTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "pathLinesBasedTransformed");
}
[NUnit.Framework.Test]
public virtual void PathLinesBasedWithMoveTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "pathLinesBasedWithMove");
}
[NUnit.Framework.Test]
public virtual void PathLinesBasedWithTwoFiguresTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "pathLinesBasedWithTwoFigures");
}
[NUnit.Framework.Test]
public virtual void CubicBezierTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "cubicBezier");
}
[NUnit.Framework.Test]
public virtual void CubicBezier2Test() {
ConvertAndCompare(sourceFolder, destinationFolder, "cubicBezier2");
}
[NUnit.Framework.Test]
public virtual void CubicBezier3Test() {
ConvertAndCompare(sourceFolder, destinationFolder, "cubicBezier3");
}
[NUnit.Framework.Test]
public virtual void CubicBezier4Test() {
ConvertAndCompare(sourceFolder, destinationFolder, "cubicBezier4");
}
[NUnit.Framework.Test]
public virtual void CubicBezierZeroDiscriminantTest() {
// See CurveTo#calculateTValues to see which discriminant is mentioned.
ConvertAndCompare(sourceFolder, destinationFolder, "cubicBezierZeroDiscriminant");
}
[NUnit.Framework.Test]
public virtual void CubicBezierNegativeDiscriminantTest() {
// See CurveTo#calculateTValues to see which discriminant is mentioned.
ConvertAndCompare(sourceFolder, destinationFolder, "cubicBezierNegativeDiscriminant");
}
[NUnit.Framework.Test]
public virtual void CubicBezierInsideOtherCubicBezierTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "cubicBezierInsideOtherCubicBezier");
}
[NUnit.Framework.Test]
public virtual void SmoothCubicBezierWithAbsoluteCoordinatesTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "smoothCubicBezierWithAbsoluteCoordinates");
}
[NUnit.Framework.Test]
public virtual void SmoothCubicBezierWithRelativeCoordinatesTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "smoothCubicBezierWithRelativeCoordinates");
}
[NUnit.Framework.Test]
public virtual void SmoothCubicBezierRelativeAndAbsoluteCoordWithMoveTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "smoothCubicBezierRelativeAndAbsoluteCoordWithMove");
}
[NUnit.Framework.Test]
public virtual void SmoothCubicBezierRelativeAndAbsoluteCoordNoZOperatorTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "smoothCubicBezierRelativeAndAbsoluteCoordNoZOperator");
}
[NUnit.Framework.Test]
public virtual void QuadraticBezierTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "quadraticBezier");
}
[NUnit.Framework.Test]
public virtual void QuadraticBezier2Test() {
ConvertAndCompare(sourceFolder, destinationFolder, "quadraticBezier2");
}
[NUnit.Framework.Test]
public virtual void QuadraticBezier3Test() {
ConvertAndCompare(sourceFolder, destinationFolder, "quadraticBezier3");
}
[NUnit.Framework.Test]
public virtual void QuadraticBezierInsideOtherQuadraticBezierTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "quadraticBezierInsideOtherQuadraticBezier");
}
[NUnit.Framework.Test]
public virtual void SmoothQuadraticBezierWithAbsoluteCoordinatesTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "smoothQuadraticBezierWithAbsoluteCoordinates");
}
[NUnit.Framework.Test]
public virtual void SmoothQuadraticBezierWithRelativeCoordinatesTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "smoothQuadraticBezierWithRelativeCoordinates");
}
[NUnit.Framework.Test]
public virtual void SmoothQuadraticBezierAbsoluteAndRelativeCoordWithMoveTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "smoothQuadraticBezierAbsoluteAndRelativeCoordWithMove"
);
}
[NUnit.Framework.Test]
public virtual void SmoothQuadraticBezierRelativeAndAbsoluteCoordNoZOperatorTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "smoothQuadraticBezierRelativeAndAbsoluteCoordNoZOperator"
);
}
[NUnit.Framework.Test]
public virtual void EllipticalArcsTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "ellipticalArcs");
}
[NUnit.Framework.Test]
public virtual void EllipticalArcsNegativeRxRyTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "ellipticalArcsNegativeRxRy");
}
[NUnit.Framework.Test]
public virtual void EllipticalArcZeroRxRyTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "ellipticalArcZeroRxRy");
}
[NUnit.Framework.Test]
public virtual void EllipticalArcsWithPhiTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "ellipticalArcsWithPhi", PageSize.A3.Rotate());
}
[NUnit.Framework.Test]
public virtual void EllipticalArcsWithPhi0Test() {
ConvertAndCompare(sourceFolder, destinationFolder, "ellipticalArcsWithPhi0");
}
[NUnit.Framework.Test]
public virtual void EllipticalArcsWithPhi90Test() {
ConvertAndCompare(sourceFolder, destinationFolder, "ellipticalArcsWithPhi90");
}
[NUnit.Framework.Test]
public virtual void EllipticalArcsWithPhi180Test() {
ConvertAndCompare(sourceFolder, destinationFolder, "ellipticalArcsWithPhi180");
}
[NUnit.Framework.Test]
public virtual void EllipticalArcsWithPhi270Test() {
ConvertAndCompare(sourceFolder, destinationFolder, "ellipticalArcsWithPhi270");
}
[NUnit.Framework.Test]
public virtual void EllipticalArcsWithPhiRelativeTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "ellipticalArcsWithPhiRelative");
}
[NUnit.Framework.Test]
public virtual void EllipticalArcsWithPhiAbsoluteTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "ellipticalArcsWithPhiAbsolute");
}
[NUnit.Framework.Test]
public virtual void EllipticalArcsRelativeCoordinatesTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "ellipticalArcsRelativeCoordinates");
}
[NUnit.Framework.Test]
public virtual void ArcInsideOtherEllipticalArcTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "arcInsideOtherEllipticalArc");
}
// TODO: DEVSIX-3932 update cmp_ after fix
[NUnit.Framework.Test]
public virtual void PolygonTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "polygon");
}
[NUnit.Framework.Test]
public virtual void PolylineTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "polyline");
}
[NUnit.Framework.Test]
public virtual void RectTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "rect");
}
[NUnit.Framework.Test]
[LogMessage(SvgLogMessageConstant.GRADIENT_INVALID_SPREAD_METHOD_LOG, LogLevel = LogLevelConstants.WARN)]
public virtual void RectWithInvalidSpreadMethodValueTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "rectWithInvalidSpreadMethodValue");
}
[NUnit.Framework.Test]
public virtual void RectsWithFallBackColorsTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "rectsWithFallBackColors");
}
[NUnit.Framework.Test]
public virtual void RectMultipleStopsWithSameOffsetPadTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "rectMultipleStopsWithSameOffsetPad");
}
[NUnit.Framework.Test]
public virtual void RectMultipleStopsWithSameOffsetReflectTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "rectMultipleStopsWithSameOffsetReflect");
}
[NUnit.Framework.Test]
public virtual void RectMultipleStopsWithSameOffsetRepeatTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "rectMultipleStopsWithSameOffsetRepeat");
}
// TODO: DEVSIX-4136 update cmp_ after fix
// (opacity is not implemented. No stops defines no color, i.e. transparent color or black with 100% opacity)
[NUnit.Framework.Test]
public virtual void RectNoStopsTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "rectNoStops");
}
[NUnit.Framework.Test]
public virtual void RectSingle0StopTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "rectSingle0Stop");
}
[NUnit.Framework.Test]
public virtual void RectSingle1StopTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "rectSingle1Stop");
}
[NUnit.Framework.Test]
public virtual void RectStopWithoutColorTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "rectStopWithoutColor");
}
[NUnit.Framework.Test]
public virtual void RectTransformedTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "rectTransformed");
}
[NUnit.Framework.Test]
public virtual void RectWithGradientTransformTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "rectWithGradientTransform");
}
[NUnit.Framework.Test]
public virtual void RectWithMultipleTransformsTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "rectWithMultipleTransforms");
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.StyledXmlParser.Logs.StyledXmlParserLogMessageConstant.UNKNOWN_ABSOLUTE_METRIC_LENGTH_PARSED
)]
public virtual void TextTest() {
// TODO DEVSIX-4140 font-relative values doesn't support
ConvertAndCompare(sourceFolder, destinationFolder, "text");
}
[NUnit.Framework.Test]
public virtual void TextNestedTSpansTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "textNestedTSpansTest");
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.StyledXmlParser.Logs.StyledXmlParserLogMessageConstant.UNKNOWN_ABSOLUTE_METRIC_LENGTH_PARSED
)]
public virtual void TextRotatedTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "textRotatedTest");
}
[NUnit.Framework.Test]
public virtual void TextDxTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "textDxTest");
}
[NUnit.Framework.Test]
public virtual void TextDyTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "textDyTest");
}
[NUnit.Framework.Test]
public virtual void TextXYOffset() {
ConvertAndCompare(sourceFolder, destinationFolder, "textXYOffset");
}
[NUnit.Framework.Test]
public virtual void TextXOffset() {
// TODO DEVSIX-4143 change cmp file after fixing
ConvertAndCompare(sourceFolder, destinationFolder, "textXOffset");
}
[NUnit.Framework.Test]
public virtual void TextXYDxDyOffset() {
ConvertAndCompare(sourceFolder, destinationFolder, "textXYDxDyOffset");
}
[NUnit.Framework.Test]
public virtual void TextGradientEmUnits() {
ConvertAndCompare(sourceFolder, destinationFolder, "textGradientEmUnits");
}
[NUnit.Framework.Test]
public virtual void TextGradientEmUnitsRelated() {
ConvertAndCompare(sourceFolder, destinationFolder, "textGradientEmUnitsRelated");
}
[NUnit.Framework.Test]
public virtual void TextGradientEmUnitsRelatedNotDefs() {
ConvertAndCompare(sourceFolder, destinationFolder, "textGradientEmUnitsRelatedNotDefs");
}
[NUnit.Framework.Test]
public virtual void TextGradientEmUnitsRelatedDefault() {
ConvertAndCompare(sourceFolder, destinationFolder, "textGradientEmUnitsRelatedDefault");
}
[NUnit.Framework.Test]
public virtual void TextGradientExUnits() {
ConvertAndCompare(sourceFolder, destinationFolder, "textGradientExUnits");
}
[NUnit.Framework.Test]
public virtual void TextGradientRemUnits() {
ConvertAndCompare(sourceFolder, destinationFolder, "textGradientRemUnits");
}
[NUnit.Framework.Test]
public virtual void TextGradientRemUnitsNestedSvg() {
ConvertAndCompare(sourceFolder, destinationFolder, "textGradientRemUnitsNestedSvg");
}
[NUnit.Framework.Test]
public virtual void RectMultipleStopsWithSameOffsetAndZeroCoordLengthPadTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "rectMultipleStopsWithSameOffsetAndZeroCoordLengthPad");
}
[NUnit.Framework.Test]
public virtual void RectMultipleStopsWithSameOffsetAndZeroCoordLengthReflectTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "rectMultipleStopsWithSameOffsetAndZeroCoordLengthReflect"
);
}
[NUnit.Framework.Test]
public virtual void RectMultipleStopsWithSameOffsetAndZeroCoordLengthRepeatTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "rectMultipleStopsWithDiffOffsetAndZeroCoordLengthRepeat"
);
}
[NUnit.Framework.Test]
public virtual void RectMultipleStopsWithDiffOffsetAndZeroCoordLengthPadTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "rectMultipleStopsWithDiffOffsetAndZeroCoordLengthPad");
}
[NUnit.Framework.Test]
public virtual void RectMultipleStopsWithDiffOffsetAndZeroCoordLengthReflectTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "rectMultipleStopsWithDiffOffsetAndZeroCoordLengthReflect"
);
}
[NUnit.Framework.Test]
public virtual void RectMultipleStopsWithDiffOffsetAndZeroCoordLengthRepeatTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "rectMultipleStopsWithSameOffsetAndZeroCoordLengthRepeat"
);
}
[NUnit.Framework.Test]
public virtual void RectInvalidStopsSequenceTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "rectInvalidStopsSequence");
}
[NUnit.Framework.Test]
public virtual void RectInvalidCoordinatesMetricsTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "rectInvalidCoordinatesMetrics");
}
[NUnit.Framework.Test]
public virtual void RectInvalidStopsSequenceWithoutBoundingStopsTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "rectInvalidStopsSequenceWithoutBoundingStops");
}
[NUnit.Framework.Test]
public virtual void UserSpaceOnUseWithAbsoluteCoordinatesTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "userSpaceOnUseWithAbsoluteCoordinates");
}
[NUnit.Framework.Test]
public virtual void UserSpaceOnUseDiffAbsoluteUnitsInGradientTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "userSpaceOnUseDiffAbsoluteUnitsInGradient");
}
[NUnit.Framework.Test]
public virtual void UserSpaceOnUseWithChUnitTest() {
// TODO: DEVSIX-3596 update cmp_ after fix ("ch" unit is not implemented yet)
ConvertAndCompare(sourceFolder, destinationFolder, "userSpaceOnUseWithChUnit");
}
[NUnit.Framework.Test]
public virtual void UserSpaceOnUseWithUnitsRelativeToFontTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "userSpaceOnUseWithUnitsRelativeToFont");
}
[NUnit.Framework.Test]
public virtual void UserSpaceOnUseWithUnitsRelativeToViewportTest() {
// TODO: DEVSIX-3596 update cmp_ after fix ("vh" "vw" "vmin" "vmax" units are not implemented yet)
ConvertAndCompare(sourceFolder, destinationFolder, "userSpaceOnUseWithUnitsRelativeToViewport");
}
[NUnit.Framework.Test]
public virtual void UserSpaceOnUseDiffRelativeUnitsInGradientTest() {
// TODO: DEVSIX-3596 update cmp_ after fix ("ch" "vmin"+"vmax"+"vw"+"vh" not implemented yet)
ConvertAndCompare(sourceFolder, destinationFolder, "userSpaceOnUseDiffRelativeUnitsInGradient");
}
[NUnit.Framework.Test]
public virtual void ObjectBoundingBoxWithAbsoluteCoordinatesTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "objectBoundingBoxWithAbsoluteCoordinates");
}
[NUnit.Framework.Test]
public virtual void ObjectBoundingBoxDifferentAbsoluteUnitsInGradientTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "objectBoundingBoxDifferentAbsoluteUnitsInGradient");
}
[NUnit.Framework.Test]
public virtual void ObjectBoundingBoxWithUnitsRelativeToFontTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "objectBoundingBoxWithUnitsRelativeToFont");
}
[NUnit.Framework.Test]
public virtual void ObjectBoundingBoxWithChUnitTest() {
// TODO: DEVSIX-3596 update cmp_ after fix ("ch" not implemented yet)
// actually the value type should not affect on the objectBoundingBox coordinate, but as
// we are not recognize these values as valid relative type,
// we get the the resulted coordinate uses defaults
ConvertAndCompare(sourceFolder, destinationFolder, "objectBoundingBoxWithChUnit");
}
[NUnit.Framework.Test]
public virtual void ObjectBoundingBoxWithUnitsRelativeToViewportTest() {
// TODO: DEVSIX-3596 update cmp_ after fix ("vmin", "vmax", "vw", "vh" not implemented yet)
// actually the value type should not affect on the objectBoundingBox coordinate, but as
// we are not recognize these values as valid relative type,
// we get the the resulted coordinate uses defaults
ConvertAndCompare(sourceFolder, destinationFolder, "objectBoundingBoxWithUnitsRelativeToViewport");
}
[NUnit.Framework.Test]
public virtual void ObjectBoundingBoxDifferentRelativeUnitsInGradientTest() {
// TODO: DEVSIX-3596 update cmp_ after fix ("ch" "vmin"+"vmax"+"vw"+"vh" not implemented yet)
// actually the value type should not affect on the objectBoundingBox coordinate, but as
// we are not recognize these values as valid relative type,
// we get the the resulted coordinate uses defaults
ConvertAndCompare(sourceFolder, destinationFolder, "objectBoundingBoxDifferentRelativeUnitsInGradient");
}
[NUnit.Framework.Test]
public virtual void TranslateTransformInGradientWithObjectBoundingBoxUnitsTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "translateTransformInGradientWithObjectBoundingBoxUnits"
);
}
[NUnit.Framework.Test]
public virtual void MatrixTransformInGradientWithObjectBoundingBoxUnitsTest() {
//TODO change cmp after DEVSIX-4143 is fixed (bug with only one absolute coordinate in tspan)
ConvertAndCompare(sourceFolder, destinationFolder, "matrixTransformInGradientWithObjectBoundingBoxUnits");
}
[NUnit.Framework.Test]
public virtual void SeveralTransformsInGradientWithObjectBoundingBoxUnitsTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "severalTransformsInGradientWithObjectBoundingBoxUnits"
);
}
}
}

View File

@@ -0,0 +1,34 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://TSpdfpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using TSpdf.Test;
namespace TSpdf.Svg.Renderers.Impl {
[NUnit.Framework.Category("UnitTest")]
public class LinearGradientSvgNodeRendererUnitTest : ExtendedTSpdfTest {
[NUnit.Framework.Test]
public virtual void NoObjectBoundingBoxTest() {
LinearGradientSvgNodeRenderer renderer = new LinearGradientSvgNodeRenderer();
NUnit.Framework.Assert.IsNull(renderer.GetObjectBoundingBox(null));
}
}
}

View File

@@ -0,0 +1,314 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using TSpdf.Svg.Processors;
using TSpdf.Svg.Processors.Impl;
using TSpdf.Svg.Renderers;
using TSpdf.Test;
using TSpdf.Test.Attributes;
namespace TSpdf.Svg.Renderers.Impl {
[NUnit.Framework.Category("IntegrationTest")]
public class MarkerSvgNodeRendererIntegrationTest : SvgIntegrationTest {
private static readonly String SOURCE_FOLDER = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/renderers/impl/MarkerSvgNodeRendererIntegrationTest/";
private static readonly String DESTINATION_FOLDER = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/renderers/impl/MarkerSvgNodeRendererIntegrationTest/";
private ISvgConverterProperties properties;
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateDestinationFolder(DESTINATION_FOLDER);
}
[NUnit.Framework.SetUp]
public virtual void Before() {
properties = new SvgConverterProperties().SetBaseUri(SOURCE_FOLDER);
}
[NUnit.Framework.Test]
public virtual void MarkerPathAutoOrientTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "markerPathAutoOrient");
}
[NUnit.Framework.Test]
public virtual void MarkerPathAngleOrientTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "markerPathAngleOrient");
}
[NUnit.Framework.Test]
public virtual void MarkerPathRefXRefYNoAspectRatioPreservationTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "markerPathRefXRefYNoAspectRatioPreservation");
}
[NUnit.Framework.Test]
public virtual void MarkerPathRefXAndRefYTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "markerPathAutoOrient");
}
[NUnit.Framework.Test]
public virtual void MarkerPathViewboxRightOrientTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "markerPathViewboxRightOrient");
}
[NUnit.Framework.Test]
public virtual void MarkerPathViewboxRightOrientNoAspectRatioPreservationTest() {
// TODO (DEVSIX-3621) fix cmp after fixing
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "markerPathViewboxRightOrientNoAspectRatioPreservation"
);
}
[NUnit.Framework.Test]
public virtual void MarkerPathViewboxLeftOrientTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "markerPathViewboxLeftOrient");
}
[NUnit.Framework.Test]
public virtual void MarkerPathViewboxUpOrientTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "markerPathViewboxUpOrient");
}
[NUnit.Framework.Test]
public virtual void MarkerPathViewboxDownOrientTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "markerPathViewboxDownOrient");
}
[NUnit.Framework.Test]
public virtual void MarkerPathViewboxAngledOrientTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "markerPathViewboxAngledOrient");
}
[NUnit.Framework.Test]
public virtual void MarkerPathPreserveAspectRatioTest() {
// TODO (DEVSIX-3621) fix cmp after fixing
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "markerPathPreserveAspectRatio");
}
// Markers in different elements
[NUnit.Framework.Test]
public virtual void MarkerTest() {
// TODO: update when DEVSIX-3397 will be closed
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "marker");
}
[NUnit.Framework.Test]
public virtual void MarkerInLineElementTest() {
// TODO: update when DEVSIX-3397 will be closed
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "markerInLineElement");
}
[NUnit.Framework.Test]
public virtual void MarkerInPolylineElementTest() {
// TODO: update when DEVSIX-3397 will be closed
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "markerInPolylineElement");
}
[NUnit.Framework.Test]
public virtual void MarkerInPolygonElementTest() {
// TODO: update when DEVSIX-3397, DEVSIX-2719 will be closed
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "markerInPolygonElement");
}
[NUnit.Framework.Test]
public virtual void MarkerInPathTest() {
// TODO: update when DEVSIX-3397 will be closed
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "markerInPath");
}
[NUnit.Framework.Test]
public virtual void MarkerUnitsTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "markerUnits");
}
[NUnit.Framework.Test]
public virtual void MarkerRefXYTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "markerRefXY");
}
// orient attribute tests
[NUnit.Framework.Test]
public virtual void MarkerOrientTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "markerOrient");
}
[NUnit.Framework.Test]
public virtual void OrientAutoLineInDifferentPositionTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "orientAutoLineInDifferentPosition");
}
[NUnit.Framework.Test]
public virtual void OrientAutoPolylineInDifferentPositionTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "orientAutoPolylineInDifferentPosition");
}
[NUnit.Framework.Test]
public virtual void OrientAutoPolygonInDifferentPositionTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "orientAutoPolygonInDifferentPosition");
}
[NUnit.Framework.Test]
// TODO DEVSIX-3432 relative values doesn't support correctly for stroke-width attribute
[LogMessage(TSpdf.StyledXmlParser.Logs.StyledXmlParserLogMessageConstant.UNKNOWN_ABSOLUTE_METRIC_LENGTH_PARSED
, Count = 3)]
public virtual void MarkerUnitsStrokeWidthWhenParentStrokeWidthIsFontRelativeValuesTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "parentStrokeWidthIsFontRelativeValues");
}
[NUnit.Framework.Test]
public virtual void MarkerUnitsStrokeWidthWhenParentStrokeWidthIsMetricValuesTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "parentStrokeWidthIsMetricValues");
}
[NUnit.Framework.Test]
// TODO DEVSIX-3432 relative values doesn't support correctly for stroke-width attribute
[LogMessage(TSpdf.StyledXmlParser.Logs.StyledXmlParserLogMessageConstant.UNKNOWN_ABSOLUTE_METRIC_LENGTH_PARSED
, Count = 3)]
public virtual void MarkerUnitsStrokeWidthWhenParentStrokeWidthIsPercentageValuesTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "parentStrokeWidthIsPercentageValues");
}
[NUnit.Framework.Test]
public virtual void MarkerDefaultValuesTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "markerDefaultValues");
}
// Style inheritance
[NUnit.Framework.Test]
public virtual void MarkerInheritFillAttributeTest0() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "markerInheritFillAttribute0");
}
[NUnit.Framework.Test]
public virtual void MarkerInheritFillAttributeTest1() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "markerInheritFillAttribute1");
}
[NUnit.Framework.Test]
public virtual void MarkerInheritFillAttributeTest2() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "markerInheritFillAttribute2");
}
[NUnit.Framework.Test]
public virtual void MarkerInheritFillAttributeNestedMarkerTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "markerInheritFillAttributeNestedMarker");
}
[NUnit.Framework.Test]
public virtual void FontRelativeValueInRefXTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "fontRelativeValueInRefX");
}
[NUnit.Framework.Test]
public virtual void FontRelativeValueInRefXDefaultTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "fontRelativeValueInRefXDefault");
}
[NUnit.Framework.Test]
public virtual void MarkerAspectRatioTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "markerAspectRatio");
}
// Overflow attribute
[NUnit.Framework.Test]
public virtual void MarkerOverflowVisibleIncreaseViewBoxScaleRootElementTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "markerOverflowVisibleIncreaseViewBoxScaleRootElement"
);
}
[NUnit.Framework.Test]
public virtual void MarkerOverflowVisibleIncreaseViewBoxScaleSvgElementTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "markerOverflowVisibleIncreaseViewBoxScaleSvgElement"
);
}
[NUnit.Framework.Test]
public virtual void MarkerOverflowVisibleTransformScaleTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "markerOverflowVisibleTransformScale");
}
[NUnit.Framework.Test]
public virtual void MarkerOverflowVisibleTransformTranslateTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "markerOverflowVisibleTransformTranslate");
}
[NUnit.Framework.Test]
public virtual void MarkerOverflowVisibleNestedSvgViewBoxesTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "markerOverflowVisibleNestedSvgViewBoxes");
}
[NUnit.Framework.Test]
public virtual void MarkerOverflowVisibleNestedSvgViewBoxes2Test() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "markerOverflowVisibleNestedSvgViewBoxes2");
}
[NUnit.Framework.Test]
public virtual void MarkerOverflowVisibleTransformRotateTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "markerOverflowVisibleTransformRotate");
}
[NUnit.Framework.Test]
[LogMessage("markerWidth has zero value. Marker will not be rendered.")]
[LogMessage("markerHeight has zero value. Marker will not be rendered.")]
[LogMessage("markerWidth has negative value. Marker will not be rendered.")]
[LogMessage("markerHeight has negative value. Marker will not be rendered.")]
public virtual void MarkerEspecialMarkerWidthHeightValuesTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "markerEspecialMarkerWidthHeightValues");
}
[NUnit.Framework.Test]
public virtual void DeformationWhenRotationAndPreserveAspectRationNoneTest() {
// TODO (DEVSIX-3621) change cmp after fixing
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "deformationWhenRotationAndPreserveAspectRationNone"
);
}
[NUnit.Framework.Test]
public virtual void MarkerParentElementTest() {
// TODO DEVSIX-4130 fix after ticket will be completed
// Compare with Chrome browser
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "markerParentElement");
}
}
}

View File

@@ -0,0 +1,34 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://TSpdfpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using TSpdf.Test;
namespace TSpdf.Svg.Renderers.Impl {
[NUnit.Framework.Category("UnitTest")]
public class MarkerSvgNodeRendererUnitTest : ExtendedTSpdfTest {
[NUnit.Framework.Test]
public virtual void NoObjectBoundingBoxTest() {
MarkerSvgNodeRenderer renderer = new MarkerSvgNodeRenderer();
NUnit.Framework.Assert.IsNull(renderer.GetObjectBoundingBox(null));
}
}
}

View File

@@ -0,0 +1,82 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using TSpdf.Svg.Processors;
using TSpdf.Svg.Processors.Impl;
using TSpdf.Svg.Renderers;
using TSpdf.Test;
namespace TSpdf.Svg.Renderers.Impl {
[NUnit.Framework.Category("IntegrationTest")]
public class MaskTest : SvgIntegrationTest {
private static readonly String SOURCE_FOLDER = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/renderers/impl/MaskTest/";
private static readonly String DESTINATION_FOLDER = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/renderers/impl/MaskTest/";
private ISvgConverterProperties properties;
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateDestinationFolder(DESTINATION_FOLDER);
}
[NUnit.Framework.SetUp]
public virtual void Before() {
properties = new SvgConverterProperties().SetBaseUri(SOURCE_FOLDER);
}
[NUnit.Framework.Test]
public virtual void MaskBasic() {
//TODO: update after DEVSIX-2378 implementation
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "maskBasic", properties);
}
[NUnit.Framework.Test]
public virtual void MaskWithGradient() {
//TODO: update after DEVSIX-2378 implementation
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "maskWithGradient", properties);
}
}
}

View File

@@ -0,0 +1,65 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System.IO;
using TSpdf.StyledXmlParser.Node;
using TSpdf.Svg.Converter;
using TSpdf.Svg.Processors;
using TSpdf.Svg.Processors.Impl;
using TSpdf.Svg.Renderers;
using TSpdf.Test.Attributes;
namespace TSpdf.Svg.Renderers.Impl {
[NUnit.Framework.Category("UnitTest")]
public class NamedObjectsTest : SvgIntegrationTest {
[NUnit.Framework.Test]
[LogMessage(TSpdf.StyledXmlParser.Logs.StyledXmlParserLogMessageConstant.RULE_IS_NOT_SUPPORTED)]
public virtual void AddNamedObject() {
INode parsedSvg = SvgConverter.Parse(new FileStream(TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/renderers/impl/NamedObjectsTest/names.svg", FileMode.Open
, FileAccess.Read));
ISvgProcessorResult result = new DefaultSvgProcessor().Process(parsedSvg, null);
NUnit.Framework.Assert.IsTrue(result.GetNamedObjects().Get("name_svg") is SvgTagSvgNodeRenderer);
NUnit.Framework.Assert.IsTrue(result.GetNamedObjects().Get("name_rect") is RectangleSvgNodeRenderer);
}
}
}

View File

@@ -0,0 +1,86 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using TSpdf.Svg.Renderers;
using TSpdf.Test;
namespace TSpdf.Svg.Renderers.Impl {
[NUnit.Framework.Category("IntegrationTest")]
public class NestedSvgTagSvgNodeRendererIntegrationTest : SvgIntegrationTest {
private static readonly String SOURCE_FOLDER = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/renderers/impl/RootSvgNodeRendererTest/nested/";
private static readonly String DESTINATION_FOLDER = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/renderers/impl/RootSvgNodeRendererTest/nested/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateDestinationFolder(DESTINATION_FOLDER);
}
[NUnit.Framework.Test]
public virtual void SingleNestedSvgTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "singleNested");
}
[NUnit.Framework.Test]
public virtual void DoubleNestedSvgTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "doubleNested");
}
[NUnit.Framework.Test]
public virtual void TwoNestedSvgTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "twoNested");
}
[NUnit.Framework.Test]
public virtual void EmptySvgTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "empty");
}
[NUnit.Framework.Test]
public virtual void TranslatedSvgTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "translated");
}
}
}

View File

@@ -0,0 +1,110 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://TSpdfpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System;
using TSpdf.Svg.Processors;
using TSpdf.Svg.Processors.Impl;
using TSpdf.Svg.Renderers;
using TSpdf.Test;
namespace TSpdf.Svg.Renderers.Impl {
[NUnit.Framework.Category("IntegrationTest")]
public class OverflowAttributeTest : SvgIntegrationTest {
private static readonly String SOURCE_FOLDER = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/renderers/impl/OverflowAttributeTest/";
private static readonly String DESTINATION_FOLDER = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/renderers/impl/OverflowAttributeTest/";
private ISvgConverterProperties properties;
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateDestinationFolder(DESTINATION_FOLDER);
}
[NUnit.Framework.SetUp]
public virtual void Before() {
properties = new SvgConverterProperties().SetBaseUri(SOURCE_FOLDER);
}
[NUnit.Framework.Test]
public virtual void OverflowVisibleInMarkerElementTest() {
//TODO: update when DEVSIX-3482 fixed
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "overflowVisibleInMarkerElement");
}
[NUnit.Framework.Test]
public virtual void OverflowHiddenInMarkerElementTest() {
//TODO: update when DEVSIX-3482 fixed
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "overflowHiddenInMarkerElement");
}
[NUnit.Framework.Test]
public virtual void OverflowAutoInMarkerElementTest() {
//TODO: update when DEVSIX-3482 fixed
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "overflowAutoInMarkerElement");
}
[NUnit.Framework.Test]
public virtual void OverflowScrollInMarkerElementTest() {
//TODO: update when DEVSIX-3482 fixed
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "overflowScrollInMarkerElement");
}
[NUnit.Framework.Test]
public virtual void OverflowInitialInMarkerElementTest() {
//TODO: update when DEVSIX-3482 fixed
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "overflowInitialInMarkerElement");
}
[NUnit.Framework.Test]
public virtual void OverflowVisibleInSymbolElementTest() {
//TODO: update when DEVSIX-3482 fixed
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "overflowVisibleInSymbol");
}
[NUnit.Framework.Test]
public virtual void OverflowHiddenInSymbolElementTest() {
//TODO: update when DEVSIX-3482 fixed
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "overflowHiddenInSymbol");
}
[NUnit.Framework.Test]
public virtual void OverflowInitialInSymbolElementTest() {
//TODO: update when DEVSIX-3482 fixed
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "overflowInitialInSymbol");
}
[NUnit.Framework.Test]
public virtual void OverflowScrollInSymbolElementTest() {
//TODO: update when DEVSIX-3482 fixed
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "overflowScrollInSymbol");
}
[NUnit.Framework.Test]
public virtual void OverflowInSvgElementTest() {
//TODO: update when DEVSIX-3482 fixed
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "overflowInSvgElement");
}
}
}

View File

@@ -0,0 +1,64 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using TSpdf.Test;
namespace TSpdf.Svg.Renderers.Impl {
[NUnit.Framework.Category("UnitTest")]
public class PathOperatorSplitTest : ExtendedTSpdfTest {
[NUnit.Framework.Test]
public virtual void TestNumbersContainingExponent01() {
// Android-Conversion-Ignore-Test (TODO DEVSIX-6457 fix different behavior of Pattern.split method)
String path = "M10,9.999999999999972C203.33333333333334,9.999999999999972,396.6666666666667,1.4210854715202004e-14,590,1.4210854715202004e-14L590,41.666666666666686C396.6666666666667,41.666666666666686,203.33333333333334,51.66666666666664,10,51.66666666666664Z";
String[] operators = new String[] { "M10,9.999999999999972", "C203.33333333333334,9.999999999999972,396.6666666666667,1.4210854715202004e-14,590,1.4210854715202004e-14"
, "L590,41.666666666666686", "C396.6666666666667,41.666666666666686,203.33333333333334,51.66666666666664,10,51.66666666666664"
, "Z" };
TestSplitting(path, operators);
}
private void TestSplitting(String originalStr, String[] expectedSplitting) {
String[] result = PathSvgNodeRenderer.SplitPathStringIntoOperators(originalStr);
NUnit.Framework.Assert.AreEqual(expectedSplitting, result);
}
}
}

View File

@@ -0,0 +1,212 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using TSpdf.Svg.Exceptions;
using TSpdf.Svg.Logs;
using TSpdf.Svg.Renderers;
using TSpdf.Test;
using TSpdf.Test.Attributes;
namespace TSpdf.Svg.Renderers.Impl {
[NUnit.Framework.Category("IntegrationTest")]
public class PathParsingIntegrationTest : SvgIntegrationTest {
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/renderers/impl/PathParsingIntegrationTest/";
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/renderers/impl/PathParsingIntegrationTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateDestinationFolder(destinationFolder);
}
[NUnit.Framework.Test]
public virtual void NormalTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "normal");
}
[NUnit.Framework.Test]
public virtual void MixTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "mix");
}
[NUnit.Framework.Test]
public virtual void NoWhitespace() {
ConvertAndCompare(sourceFolder, destinationFolder, "noWhitespace");
}
[NUnit.Framework.Test]
public virtual void ZOperator() {
ConvertAndCompare(sourceFolder, destinationFolder, "zOperator");
}
[NUnit.Framework.Test]
public virtual void MissingOperandArgument() {
ConvertAndCompare(sourceFolder, destinationFolder, "missingOperandArgument");
}
[NUnit.Framework.Test]
public virtual void DecimalPointHandlingTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "decimalPointHandling");
}
[NUnit.Framework.Test]
public virtual void InvalidOperatorTest() {
NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => ConvertAndCompare(sourceFolder, destinationFolder
, "invalidOperator"));
}
[NUnit.Framework.Test]
public virtual void InvalidOperatorCSensTest() {
NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => ConvertAndCompare(sourceFolder, destinationFolder
, "invalidOperatorCSens"));
}
[NUnit.Framework.Test]
public virtual void MoreThanOneHParam() {
// TODO DEVSIX-2331 Update the cmp after the issue is resolved
// UPD: Seems to be fixed now, but leaving the remark and issue open because the scope of the issue might be bigger than
// this test
ConvertAndCompare(sourceFolder, destinationFolder, "moreThanOneHParam");
}
[NUnit.Framework.Test]
public virtual void NegativeAfterPositiveHandlingTest01() {
//TODO update after DEVSIX-2331 - several (negative) line operators
ConvertAndCompare(sourceFolder, destinationFolder, "negativeAfterPositiveHandling");
}
[NUnit.Framework.Test]
public virtual void NegativeAfterPositiveHandlingTest02() {
//TODO update after DEVSIX-2333 (negative viewbox) fix
ConvertAndCompare(sourceFolder, destinationFolder, "negativeAfterPositiveHandlingExtendedViewbox");
}
[NUnit.Framework.Test]
public virtual void InsignificantSpacesTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "insignificantSpaces");
}
[NUnit.Framework.Test]
public virtual void PrecedingSpacesTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "precedingSpaces");
}
[NUnit.Framework.Test]
[LogMessage(SvgLogMessageConstant.UNMAPPED_TAG)]
public virtual void Text_path_Test() {
//TODO: update cmp-file after DEVSIX-2255
ConvertAndCompare(sourceFolder, destinationFolder, "textpath");
}
[NUnit.Framework.Test]
[LogMessage(SvgLogMessageConstant.UNMAPPED_TAG)]
public virtual void TextPathExample() {
//TODO: update when DEVSIX-2255 implemented
ConvertAndCompare(sourceFolder, destinationFolder, "textPathExample");
}
[NUnit.Framework.Test]
public virtual void PathH() {
ConvertAndCompare(sourceFolder, destinationFolder, "pathH");
}
[NUnit.Framework.Test]
public virtual void PathV() {
ConvertAndCompare(sourceFolder, destinationFolder, "pathV");
}
[NUnit.Framework.Test]
public virtual void PathHV() {
ConvertAndCompare(sourceFolder, destinationFolder, "pathHV");
}
[NUnit.Framework.Test]
public virtual void PathRelativeAbsoluteCombinedTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "pathRelativeAbsoluteCombined");
}
[NUnit.Framework.Test]
public virtual void PathHVExponential() {
// TODO DEVSIX-2906 This file has large numbers (2e+10) in it. At the moment we do not post-process such big numbers
// and simply print them to the output PDF. Not all the viewers are able to process such large numbers
// and hence different results in different viewers. Acrobat is not able to process the numbers
// and the result is garbled visual representation. GhostScript, however, renders the PDF just fine
ConvertAndCompare(sourceFolder, destinationFolder, "pathHVExponential");
}
[NUnit.Framework.Test]
public virtual void PathABasic() {
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "pathABasic");
}
[NUnit.Framework.Test]
public virtual void PathAFlags() {
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "pathAFlags");
}
[NUnit.Framework.Test]
public virtual void PathAAxisRotation() {
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "pathAAxisRotation");
}
[NUnit.Framework.Test]
public virtual void PathAOutOfRange() {
//TODO: update cmp when DEVSIX-3010 and DEVSIX-3011 fixed
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "pathAOutOfRange");
}
[NUnit.Framework.Test]
public virtual void Arcs_end_point() {
//TODO: update cmp when DEVSIX-3010 fixed
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "arcsEndPoint");
}
[NUnit.Framework.Test]
public virtual void Flags_out_of_range() {
//TODO: update cmp when DEVSIX-3011 fixed
ConvertAndCompareSinglePage(sourceFolder, destinationFolder, "flags_out_of_range");
}
}
}

View File

@@ -0,0 +1,204 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using System.Collections.Generic;
using TSpdf.Svg;
using TSpdf.Svg.Exceptions;
using TSpdf.Test;
namespace TSpdf.Svg.Renderers.Impl {
[NUnit.Framework.Category("UnitTest")]
public class PathParsingTest : ExtendedTSpdfTest {
[NUnit.Framework.Test]
public virtual void PathParsingOperatorEmptyTest() {
PathSvgNodeRenderer path = new PathSvgNodeRenderer();
path.SetAttribute(SvgConstants.Attributes.D, "");
ICollection<String> ops = path.ParsePathOperations();
NUnit.Framework.Assert.IsTrue(ops.IsEmpty());
}
[NUnit.Framework.Test]
public virtual void PathParsingOperatorDefaultValueTest() {
PathSvgNodeRenderer path = new PathSvgNodeRenderer();
path.SetAttributesAndStyles(new Dictionary<String, String>());
ICollection<String> ops = path.ParsePathOperations();
NUnit.Framework.Assert.IsTrue(ops.IsEmpty());
}
[NUnit.Framework.Test]
public virtual void PathParsingOperatorOnlySpacesTest() {
PathSvgNodeRenderer path = new PathSvgNodeRenderer();
path.SetAttribute(SvgConstants.Attributes.D, " ");
ICollection<String> ops = path.ParsePathOperations();
NUnit.Framework.Assert.IsTrue(ops.IsEmpty());
}
[NUnit.Framework.Test]
public virtual void PathParsingOperatorBadOperatorTest() {
PathSvgNodeRenderer path = new PathSvgNodeRenderer();
path.SetAttribute(SvgConstants.Attributes.D, "b 1 1");
NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => path.ParsePathOperations());
}
[NUnit.Framework.Test]
public virtual void PathParsingOperatorLaterBadOperatorTest() {
PathSvgNodeRenderer path = new PathSvgNodeRenderer();
path.SetAttribute(SvgConstants.Attributes.D, "m 200 100 l 50 50 x");
NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => path.ParsePathOperations());
}
[NUnit.Framework.Test]
public virtual void PathParsingOperatorStartWithSpacesTest() {
PathSvgNodeRenderer path = new PathSvgNodeRenderer();
path.SetAttribute(SvgConstants.Attributes.D, " \t\n m 200 100 l 50 50");
ICollection<String> ops = path.ParsePathOperations();
NUnit.Framework.Assert.AreEqual(2, ops.Count);
}
[NUnit.Framework.Test]
public virtual void PathParsingOperatorEndWithSpacesTest() {
PathSvgNodeRenderer path = new PathSvgNodeRenderer();
path.SetAttribute(SvgConstants.Attributes.D, "m 200 100 l 50 50 m 200 100 l 50 50 \t\n ");
ICollection<String> ops = path.ParsePathOperations();
NUnit.Framework.Assert.AreEqual(4, ops.Count);
}
[NUnit.Framework.Test]
public virtual void PathParsingNoOperatorSpacesNoExceptionTest() {
PathSvgNodeRenderer path = new PathSvgNodeRenderer();
path.SetAttribute(SvgConstants.Attributes.D, "m200,100L50,50L200,100");
ICollection<String> ops = path.ParsePathOperations();
NUnit.Framework.Assert.AreEqual(3, ops.Count);
}
[NUnit.Framework.Test]
public virtual void PathParsingLoseCommasTest() {
PathSvgNodeRenderer path = new PathSvgNodeRenderer();
path.SetAttribute(SvgConstants.Attributes.D, "m200,100L50,50L200,100");
ICollection<String> ops = path.ParsePathOperations();
foreach (String op in ops) {
NUnit.Framework.Assert.IsFalse(op.Contains(","));
}
}
[NUnit.Framework.Test]
public virtual void PathParsingBadOperatorArgsNoExceptionTest() {
PathSvgNodeRenderer path = new PathSvgNodeRenderer();
path.SetAttribute(SvgConstants.Attributes.D, "m 200 l m");
ICollection<String> ops = path.ParsePathOperations();
NUnit.Framework.Assert.AreEqual(3, ops.Count);
}
[NUnit.Framework.Test]
public virtual void PathParsingHandlesDecPointsTest() {
PathSvgNodeRenderer path = new PathSvgNodeRenderer();
path.SetAttribute(SvgConstants.Attributes.D, "m2.35.96");
ICollection<String> ops = path.ParsePathOperations();
NUnit.Framework.Assert.AreEqual(1, ops.Count);
NUnit.Framework.Assert.IsTrue(ops.Contains("m 2.35 .96"));
}
[NUnit.Framework.Test]
public virtual void PathParsingHandlesMinusTest() {
PathSvgNodeRenderer path = new PathSvgNodeRenderer();
path.SetAttribute(SvgConstants.Attributes.D, "m40-50");
ICollection<String> ops = path.ParsePathOperations();
NUnit.Framework.Assert.AreEqual(1, ops.Count);
NUnit.Framework.Assert.IsTrue(ops.Contains("m 40 -50"));
}
[NUnit.Framework.Test]
public virtual void DecimalPointParsingTest() {
PathSvgNodeRenderer path = new PathSvgNodeRenderer();
String input = "2.35.96";
String expected = "2.35 .96";
String actual = path.SeparateDecimalPoints(input);
NUnit.Framework.Assert.AreEqual(expected, actual);
}
[NUnit.Framework.Test]
public virtual void DecimalPointParsingSpaceTest() {
PathSvgNodeRenderer path = new PathSvgNodeRenderer();
String input = "2.35.96 3.25 .25";
String expected = "2.35 .96 3.25 .25";
String actual = path.SeparateDecimalPoints(input);
NUnit.Framework.Assert.AreEqual(expected, actual);
}
[NUnit.Framework.Test]
public virtual void DecimalPointParsingTabTest() {
PathSvgNodeRenderer path = new PathSvgNodeRenderer();
String input = "2.35.96 3.25\t.25";
String expected = "2.35 .96 3.25\t.25";
String actual = path.SeparateDecimalPoints(input);
NUnit.Framework.Assert.AreEqual(expected, actual);
}
[NUnit.Framework.Test]
public virtual void DecimalPointParsingMinusTest() {
PathSvgNodeRenderer path = new PathSvgNodeRenderer();
String input = "2.35.96 3.25-.25";
String expected = "2.35 .96 3.25 -.25";
String actual = path.SeparateDecimalPoints(input);
NUnit.Framework.Assert.AreEqual(expected, actual);
}
[NUnit.Framework.Test]
public virtual void NegativeAfterPositiveTest() {
PathSvgNodeRenderer path = new PathSvgNodeRenderer();
String input = "40-50";
String expected = "40 -50";
String actual = path.SeparateDecimalPoints(input);
NUnit.Framework.Assert.AreEqual(expected, actual);
}
[NUnit.Framework.Test]
public virtual void ExponentInNumberTest01() {
PathSvgNodeRenderer path = new PathSvgNodeRenderer();
String input = "C 268.88888888888886 67.97916666666663e+10 331.1111111111111 -2.842170943040401e-14 393.3333333333333 -2.842170943040401e-14";
String expected = "C 268.88888888888886 67.97916666666663e+10 331.1111111111111 -2.842170943040401e-14 393.3333333333333 -2.842170943040401e-14";
String actual = path.SeparateDecimalPoints(input);
NUnit.Framework.Assert.AreEqual(expected, actual);
}
}
}

View File

@@ -0,0 +1,207 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using System.Collections.Generic;
using TSpdf.Kernel.Geom;
using TSpdf.Svg;
using TSpdf.Svg.Exceptions;
using TSpdf.Svg.Renderers;
using TSpdf.Svg.Renderers.Path;
using TSpdf.Svg.Renderers.Path.Impl;
namespace TSpdf.Svg.Renderers.Impl {
[NUnit.Framework.Category("IntegrationTest")]
public class PathSvgNodeRendererLowLevelIntegrationTest : SvgIntegrationTest {
[NUnit.Framework.Test]
public virtual void TestRelativeArcOperatorShapes() {
PathSvgNodeRenderer path = new PathSvgNodeRenderer();
String instructions = "M 200,300 a 10 10 0 0 0 10 10";
path.SetAttribute(SvgConstants.Attributes.D, instructions);
IList<IPathShape> segments = (IList<IPathShape>)path.GetShapes();
NUnit.Framework.Assert.AreEqual(2, segments.Count);
NUnit.Framework.Assert.IsTrue(segments[0] is MoveTo);
NUnit.Framework.Assert.IsTrue(segments[1] is EllipticalCurveTo);
}
[NUnit.Framework.Test]
public virtual void TestRelativeArcOperatorCoordinates() {
PathSvgNodeRenderer path = new PathSvgNodeRenderer();
String instructions = "M 200,300 a 10 10 0 0 0 10 10";
path.SetAttribute(SvgConstants.Attributes.D, instructions);
IPathShape arc = ((IList<IPathShape>)path.GetShapes())[1];
Point end = arc.GetEndingPoint();
NUnit.Framework.Assert.AreEqual(new Point(210, 310), end);
}
[NUnit.Framework.Test]
public virtual void TestMultipleRelativeArcOperatorCoordinates() {
PathSvgNodeRenderer path = new PathSvgNodeRenderer();
String instructions = "M 200,300 a 10 10 0 0 0 10 10 a 10 10 0 0 0 10 10";
path.SetAttribute(SvgConstants.Attributes.D, instructions);
IPathShape arc = ((IList<IPathShape>)path.GetShapes())[2];
Point end = arc.GetEndingPoint();
NUnit.Framework.Assert.AreEqual(new Point(220, 320), end);
}
[NUnit.Framework.Test]
public virtual void TestAbsoluteArcOperatorCoordinates() {
PathSvgNodeRenderer path = new PathSvgNodeRenderer();
String instructions = "M 200,300 A 10 10 0 0 0 210 310";
path.SetAttribute(SvgConstants.Attributes.D, instructions);
IPathShape arc = ((IList<IPathShape>)path.GetShapes())[1];
Point end = arc.GetEndingPoint();
NUnit.Framework.Assert.AreEqual(new Point(210, 310), end);
}
[NUnit.Framework.Test]
public virtual void TestMultipleAbsoluteArcOperatorCoordinates() {
PathSvgNodeRenderer path = new PathSvgNodeRenderer();
String instructions = "M 200,300 A 10 10 0 0 0 210 310 A 10 10 0 0 0 220 320";
path.SetAttribute(SvgConstants.Attributes.D, instructions);
IPathShape arc = ((IList<IPathShape>)path.GetShapes())[2];
Point end = arc.GetEndingPoint();
NUnit.Framework.Assert.AreEqual(new Point(220, 320), end);
}
// tests resulting in empty path
[NUnit.Framework.Test]
public virtual void TestEmptyPath() {
PathSvgNodeRenderer path = new PathSvgNodeRenderer();
String instructions = "";
path.SetAttribute(SvgConstants.Attributes.D, instructions);
NUnit.Framework.Assert.IsTrue(path.GetShapes().IsEmpty());
}
[NUnit.Framework.Test]
public virtual void TestNonsensePathNoOperators() {
PathSvgNodeRenderer path = new PathSvgNodeRenderer();
String instructions = "200";
path.SetAttribute(SvgConstants.Attributes.D, instructions);
NUnit.Framework.Assert.IsTrue(path.GetShapes().IsEmpty());
}
[NUnit.Framework.Test]
public virtual void TestNonsensePathNotExistingOperator() {
PathSvgNodeRenderer path = new PathSvgNodeRenderer();
String instructions = "F";
path.SetAttribute(SvgConstants.Attributes.D, instructions);
NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => path.GetShapes());
}
[NUnit.Framework.Test]
public virtual void TestClosePathNoPrecedingPathsOperator() {
PathSvgNodeRenderer path = new PathSvgNodeRenderer();
String instructions = "z";
path.SetAttribute(SvgConstants.Attributes.D, instructions);
NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => path.GetShapes());
}
[NUnit.Framework.Test]
public virtual void TestMoveNoArgsOperator() {
PathSvgNodeRenderer path = new PathSvgNodeRenderer();
String instructions = "M";
path.SetAttribute(SvgConstants.Attributes.D, instructions);
NUnit.Framework.Assert.IsTrue(path.GetShapes().IsEmpty());
}
[NUnit.Framework.Test]
public virtual void TestMoveOddArgsOperator() {
PathSvgNodeRenderer path = new PathSvgNodeRenderer();
String instructions = "M 500";
path.SetAttribute(SvgConstants.Attributes.D, instructions);
NUnit.Framework.Assert.IsTrue(path.GetShapes().IsEmpty());
}
[NUnit.Framework.Test]
public virtual void TestAddMultipleArgsOperator() {
PathSvgNodeRenderer path = new PathSvgNodeRenderer();
String instructions = "M 500 500 200 200 300 300";
path.SetAttribute(SvgConstants.Attributes.D, instructions);
NUnit.Framework.Assert.AreEqual(3, path.GetShapes().Count);
}
[NUnit.Framework.Test]
public virtual void TestAddMultipleOddArgsOperator() {
PathSvgNodeRenderer path = new PathSvgNodeRenderer();
String instructions = "L 500 500 200 200 300";
path.SetAttribute(SvgConstants.Attributes.D, instructions);
NUnit.Framework.Assert.AreEqual(2, path.GetShapes().Count);
}
[NUnit.Framework.Test]
public virtual void TestAddMultipleOddArgsOperatorThenOtherStuff() {
PathSvgNodeRenderer path = new PathSvgNodeRenderer();
String instructions = "M 500 500 200 200 300 z";
path.SetAttribute(SvgConstants.Attributes.D, instructions);
NUnit.Framework.Assert.AreEqual(3, path.GetShapes().Count);
NUnit.Framework.Assert.IsTrue(((IList<IPathShape>)path.GetShapes())[2] is ClosePath);
}
[NUnit.Framework.Test]
public virtual void TestAddDoubleArgsOperator() {
PathSvgNodeRenderer path = new PathSvgNodeRenderer();
String instructions = "M 500 500 S 200 100 100 200 300 300 400 400";
path.SetAttribute(SvgConstants.Attributes.D, instructions);
NUnit.Framework.Assert.AreEqual(3, path.GetShapes().Count);
NUnit.Framework.Assert.IsTrue(((IList<IPathShape>)path.GetShapes())[2] is SmoothSCurveTo);
}
[NUnit.Framework.Test]
public virtual void SmoothCurveAsFirstShapeTest1() {
String instructions = "S 100 200 300 400";
PathSvgNodeRenderer path = new PathSvgNodeRenderer();
path.SetAttribute(SvgConstants.Attributes.D, instructions);
Exception e = NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => path.GetShapes());
NUnit.Framework.Assert.AreEqual(SvgExceptionMessageConstant.INVALID_SMOOTH_CURVE_USE, e.Message);
}
[NUnit.Framework.Test]
public virtual void SmoothCurveAsFirstShapeTest2() {
String instructions = "T 100,200";
PathSvgNodeRenderer path = new PathSvgNodeRenderer();
path.SetAttribute(SvgConstants.Attributes.D, instructions);
Exception e = NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => path.GetShapes());
NUnit.Framework.Assert.AreEqual(SvgExceptionMessageConstant.INVALID_SMOOTH_CURVE_USE, e.Message);
}
}
}

View File

@@ -0,0 +1,385 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using System.Collections.Generic;
using System.IO;
using TSpdf.Kernel.Pdf;
using TSpdf.Kernel.Pdf.Canvas;
using TSpdf.Kernel.Utils;
using TSpdf.StyledXmlParser.Node;
using TSpdf.StyledXmlParser.Node.Impl.Jsoup;
using TSpdf.Svg.Exceptions;
using TSpdf.Svg.Processors.Impl;
using TSpdf.Svg.Renderers;
using TSpdf.Test;
namespace TSpdf.Svg.Renderers.Impl {
[NUnit.Framework.Category("IntegrationTest")]
public class PathSvgNodeRendererTest : SvgIntegrationTest {
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/renderers/impl/PathSvgNodeRendererTest/";
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/renderers/impl/PathSvgNodeRendererTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateDestinationFolder(destinationFolder);
}
[NUnit.Framework.Test]
public virtual void PathNodeRendererMoveToTest() {
String filename = "pathNodeRendererMoveToTest.pdf";
PdfDocument doc = new PdfDocument(new PdfWriter(destinationFolder + filename));
doc.AddNewPage();
IDictionary<String, String> pathShapes = new Dictionary<String, String>();
pathShapes.Put("d", "M 100,100, L300,100,L200,300,z");
ISvgNodeRenderer pathRenderer = new PathSvgNodeRenderer();
pathRenderer.SetAttributesAndStyles(pathShapes);
SvgDrawContext context = new SvgDrawContext(null, null);
PdfCanvas cv = new PdfCanvas(doc, 1);
context.PushCanvas(cv);
pathRenderer.Draw(context);
doc.Close();
String result = new CompareTool().CompareByContent(destinationFolder + filename, sourceFolder + "cmp_" + filename
, destinationFolder, "diff_");
if (result != null && !result.Contains("No visual differences")) {
NUnit.Framework.Assert.Fail(result);
}
}
[NUnit.Framework.Test]
public virtual void PathNodeRendererMoveToTest1() {
String filename = "pathNodeRendererMoveToTest1.pdf";
PdfDocument doc = new PdfDocument(new PdfWriter(destinationFolder + filename));
doc.AddNewPage();
IDictionary<String, String> pathShapes = new Dictionary<String, String>();
pathShapes.Put("d", "M 100 100 l300 100 L200 300 z");
ISvgNodeRenderer pathRenderer = new PathSvgNodeRenderer();
pathRenderer.SetAttributesAndStyles(pathShapes);
SvgDrawContext context = new SvgDrawContext(null, null);
PdfCanvas cv = new PdfCanvas(doc, 1);
context.PushCanvas(cv);
pathRenderer.Draw(context);
doc.Close();
String result = new CompareTool().CompareByContent(destinationFolder + filename, sourceFolder + "cmp_" + filename
, destinationFolder, "diff_");
if (result != null && !result.Contains("No visual differences")) {
NUnit.Framework.Assert.Fail(result);
}
}
[NUnit.Framework.Test]
public virtual void PathNodeRendererCurveToTest() {
String filename = "pathNodeRendererCurveToTest.pdf";
PdfDocument doc = new PdfDocument(new PdfWriter(destinationFolder + filename));
doc.AddNewPage();
IDictionary<String, String> pathShapes = new Dictionary<String, String>();
pathShapes.Put("d", "M100,200 C100,100 250,100 250,200 S400,300 400,200,z");
ISvgNodeRenderer pathRenderer = new PathSvgNodeRenderer();
pathRenderer.SetAttributesAndStyles(pathShapes);
SvgDrawContext context = new SvgDrawContext(null, null);
PdfCanvas cv = new PdfCanvas(doc, 1);
context.PushCanvas(cv);
pathRenderer.Draw(context);
doc.Close();
String result = new CompareTool().CompareByContent(destinationFolder + filename, sourceFolder + "cmp_" + filename
, destinationFolder, "diff_");
if (result != null && !result.Contains("No visual differences")) {
NUnit.Framework.Assert.Fail(result);
}
}
[NUnit.Framework.Test]
public virtual void PathNodeRendererCurveToTest1() {
String filename = "pathNodeRendererCurveToTest1.pdf";
PdfDocument doc = new PdfDocument(new PdfWriter(destinationFolder + filename));
doc.AddNewPage();
IDictionary<String, String> pathShapes = new Dictionary<String, String>();
pathShapes.Put("d", "M100 200 C100 300 250 300 250 200 S400 100 400 200 z");
ISvgNodeRenderer pathRenderer = new PathSvgNodeRenderer();
pathRenderer.SetAttributesAndStyles(pathShapes);
SvgDrawContext context = new SvgDrawContext(null, null);
PdfCanvas cv = new PdfCanvas(doc, 1);
context.PushCanvas(cv);
pathRenderer.Draw(context);
doc.Close();
String result = new CompareTool().CompareByContent(destinationFolder + filename, sourceFolder + "cmp_" + filename
, destinationFolder, "diff_");
if (result != null && !result.Contains("No visual differences")) {
NUnit.Framework.Assert.Fail(result);
}
}
[NUnit.Framework.Test]
public virtual void PathNodeRendererQCurveToCurveToTest() {
String filename = "pathNodeRendererQCurveToCurveToTest.pdf";
PdfDocument doc = new PdfDocument(new PdfWriter(destinationFolder + filename));
doc.AddNewPage();
IDictionary<String, String> pathShapes = new Dictionary<String, String>();
pathShapes.Put("d", "M200,300 Q400,50 600,300,z");
ISvgNodeRenderer pathRenderer = new PathSvgNodeRenderer();
pathRenderer.SetAttributesAndStyles(pathShapes);
SvgDrawContext context = new SvgDrawContext(null, null);
PdfCanvas cv = new PdfCanvas(doc, 1);
context.PushCanvas(cv);
pathRenderer.Draw(context);
doc.Close();
String result = new CompareTool().CompareByContent(destinationFolder + filename, sourceFolder + "cmp_" + filename
, destinationFolder, "diff_");
if (result != null && !result.Contains("No visual differences")) {
NUnit.Framework.Assert.Fail(result);
}
}
[NUnit.Framework.Test]
public virtual void PathNodeRendererQCurveToCurveToTest1() {
String filename = "pathNodeRendererQCurveToCurveToTest1.pdf";
PdfDocument doc = new PdfDocument(new PdfWriter(destinationFolder + filename));
doc.AddNewPage();
IDictionary<String, String> pathShapes = new Dictionary<String, String>();
pathShapes.Put("d", "M200 300 Q400 50 600 300 z");
ISvgNodeRenderer pathRenderer = new PathSvgNodeRenderer();
pathRenderer.SetAttributesAndStyles(pathShapes);
SvgDrawContext context = new SvgDrawContext(null, null);
PdfCanvas cv = new PdfCanvas(doc, 1);
context.PushCanvas(cv);
pathRenderer.Draw(context);
doc.Close();
String result = new CompareTool().CompareByContent(destinationFolder + filename, sourceFolder + "cmp_" + filename
, destinationFolder, "diff_");
if (result != null && !result.Contains("No visual differences")) {
NUnit.Framework.Assert.Fail(result);
}
}
[NUnit.Framework.Test]
public virtual void SmoothCurveTest1() {
String filename = "smoothCurveTest1.pdf";
PdfDocument doc = new PdfDocument(new PdfWriter(destinationFolder + filename));
doc.AddNewPage();
String svgFilename = "smoothCurveTest1.svg";
Stream xmlStream = new FileStream(sourceFolder + svgFilename, FileMode.Open, FileAccess.Read);
IElementNode rootTag = new JsoupXmlParser().Parse(xmlStream, "ISO-8859-1");
DefaultSvgProcessor processor = new DefaultSvgProcessor();
IBranchSvgNodeRenderer root = (IBranchSvgNodeRenderer)processor.Process(rootTag, null).GetRootRenderer();
SvgDrawContext context = new SvgDrawContext(null, null);
PdfCanvas cv = new PdfCanvas(doc, 1);
context.PushCanvas(cv);
NUnit.Framework.Assert.IsTrue(root.GetChildren()[0] is PathSvgNodeRenderer);
root.GetChildren()[0].Draw(context);
doc.Close();
}
[NUnit.Framework.Test]
public virtual void SmoothCurveTest2() {
String filename = "smoothCurveTest2.pdf";
PdfDocument doc = new PdfDocument(new PdfWriter(destinationFolder + filename));
doc.AddNewPage();
String svgFilename = "smoothCurveTest2.svg";
Stream xmlStream = new FileStream(sourceFolder + svgFilename, FileMode.Open, FileAccess.Read);
IElementNode rootTag = new JsoupXmlParser().Parse(xmlStream, "ISO-8859-1");
DefaultSvgProcessor processor = new DefaultSvgProcessor();
IBranchSvgNodeRenderer root = (IBranchSvgNodeRenderer)processor.Process(rootTag, null).GetRootRenderer();
SvgDrawContext context = new SvgDrawContext(null, null);
PdfCanvas cv = new PdfCanvas(doc, 1);
context.PushCanvas(cv);
NUnit.Framework.Assert.IsTrue(root.GetChildren()[0] is PathSvgNodeRenderer);
root.GetChildren()[0].Draw(context);
doc.Close();
}
[NUnit.Framework.Test]
public virtual void SmoothCurveTest3() {
String filename = "smoothCurveTest3.pdf";
PdfDocument doc = new PdfDocument(new PdfWriter(destinationFolder + filename));
doc.AddNewPage();
String svgFilename = "smoothCurveTest3.svg";
Stream xmlStream = new FileStream(sourceFolder + svgFilename, FileMode.Open, FileAccess.Read);
IElementNode rootTag = new JsoupXmlParser().Parse(xmlStream, "ISO-8859-1");
DefaultSvgProcessor processor = new DefaultSvgProcessor();
IBranchSvgNodeRenderer root = (IBranchSvgNodeRenderer)processor.Process(rootTag, null).GetRootRenderer();
SvgDrawContext context = new SvgDrawContext(null, null);
PdfCanvas cv = new PdfCanvas(doc, 1);
context.PushCanvas(cv);
NUnit.Framework.Assert.IsTrue(root.GetChildren()[0] is PathSvgNodeRenderer);
root.GetChildren()[0].Draw(context);
doc.Close();
}
[NUnit.Framework.Test]
public virtual void PathNodeRendererCurveComplexTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "curves");
}
[NUnit.Framework.Test]
public virtual void PathZOperatorMultipleZTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "pathZOperatorMultipleZTest");
}
[NUnit.Framework.Test]
public virtual void PathZOperatorSingleZTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "pathZOperatorSingleZTest");
}
[NUnit.Framework.Test]
public virtual void PathZOperatorSingleZInstructionsAfterTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "pathZOperatorSingleZInstructionsAfterTest");
}
[NUnit.Framework.Test]
public virtual void InvalidZOperatorTest() {
NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => ConvertAndCompare(sourceFolder, destinationFolder
, "invalidZOperatorTest01"));
}
[NUnit.Framework.Test]
public virtual void InvalidOperatorTest() {
NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => ConvertAndCompare(sourceFolder, destinationFolder
, "invalidOperatorTest01"));
}
//TODO DEVSIX-2242. This test should fail when the ticket is resolved
[NUnit.Framework.Test]
public virtual void PathLOperatorMultipleCoordinates() {
ConvertAndCompare(sourceFolder, destinationFolder, "pathLOperatorMultipleCoordinates");
}
[NUnit.Framework.Test]
public virtual void PathVOperatorTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "pathVOperatorTest01");
}
[NUnit.Framework.Test]
public virtual void PathZOperatorContinuePathingTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "pathZOperatorContinuePathingTest");
}
[NUnit.Framework.Test]
public virtual void PathVOperatorMultipleArgumentsTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "pathVOperatorMultipleArgumentsTest");
}
[NUnit.Framework.Test]
public virtual void PathHOperatorSimpleTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "pathHOperatorSimpleTest");
}
[NUnit.Framework.Test]
public virtual void PathHandVOperatorTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "pathHandVOperatorTest");
}
[NUnit.Framework.Test]
public virtual void CurveToContinuePathingTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "curveToContinuePathingTest");
}
[NUnit.Framework.Test]
public virtual void RelativeHorizontalLineToTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "relativeHorizontalLineTo");
}
[NUnit.Framework.Test]
public virtual void RelativeVerticalLineToTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "relativeVerticalLineTo");
}
[NUnit.Framework.Test]
public virtual void CombinedRelativeVerticalLineToAndRelativeHorizontalLineToTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "combinedRelativeVerticalLineToAndRelativeHorizontalLineTo"
);
}
[NUnit.Framework.Test]
public virtual void MultipleRelativeHorizontalLineToTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "multipleRelativeHorizontalLineTo");
}
[NUnit.Framework.Test]
public virtual void MultipleRelativeVerticalLineToTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "multipleRelativeVerticalLineTo");
}
[NUnit.Framework.Test]
public virtual void MoveToRelativeMultipleTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "moveToRelativeMultiple");
}
[NUnit.Framework.Test]
public virtual void MoveToAbsoluteMultipleTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "moveToAbsoluteMultiple");
}
[NUnit.Framework.Test]
public virtual void TSpdfLogoTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "TSpdfLogo");
}
[NUnit.Framework.Test]
public virtual void EofillUnsuportedPathTest() {
NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => ConvertAndCompare(sourceFolder, destinationFolder
, "eofillUnsuportedPathTest"));
}
[NUnit.Framework.Test]
public virtual void MultiplePairsAfterMoveToRelativeTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "multiplePairsAfterMoveToRelative");
}
[NUnit.Framework.Test]
public virtual void MultiplePairsAfterMoveToAbsoluteTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "multiplePairsAfterMoveToAbsolute");
}
[NUnit.Framework.Test]
public virtual void PathHOperatorAbsoluteAfterMultiplePairsTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "pathHOperatorAbsoluteAfterMultiplePairs");
}
[NUnit.Framework.Test]
public virtual void PathHOperatorRelativeAfterMultiplePairsTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "pathHOperatorRelativeAfterMultiplePairs");
}
}
}

View File

@@ -0,0 +1,34 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://TSpdfpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using TSpdf.Test;
namespace TSpdf.Svg.Renderers.Impl {
[NUnit.Framework.Category("UnitTest")]
public class PatternSvgNodeRendererUnitTest : ExtendedTSpdfTest {
[NUnit.Framework.Test]
public virtual void NoObjectBoundingBoxTest() {
PatternSvgNodeRenderer renderer = new PatternSvgNodeRenderer();
NUnit.Framework.Assert.IsNull(renderer.GetObjectBoundingBox(null));
}
}
}

View File

@@ -0,0 +1,472 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://TSpdfpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System;
using TSpdf.Kernel.Geom;
using TSpdf.Svg.Logs;
using TSpdf.Svg.Renderers;
using TSpdf.Test;
using TSpdf.Test.Attributes;
namespace TSpdf.Svg.Renderers.Impl {
[NUnit.Framework.Category("IntegrationTest")]
public class PatternTest : SvgIntegrationTest {
public static readonly String DESTINATION_FOLDER = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/renderers/impl/PatternTest/";
public static readonly String SOURCE_FOLDER = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/renderers/impl/PatternTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateDestinationFolder(DESTINATION_FOLDER);
}
[NUnit.Framework.Test]
public virtual void WidthHeightXYInCmUnitDiffPatternUnitsTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "widthHeightXYInCmUnitDiffPatternUnits");
}
[NUnit.Framework.Test]
public virtual void WidthHeightXYInInchUnitDiffPatternUnitsTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "widthHeightXYInInchUnitDiffPatternUnits");
}
[NUnit.Framework.Test]
public virtual void WidthHeightXYInEmUnitDiffPatternUnitsTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "widthHeightXYInEmUnitDiffPatternUnits");
}
[NUnit.Framework.Test]
public virtual void WidthHeightXYInExUnitDiffPatternUnitsTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "widthHeightXYInExUnitDiffPatternUnits");
}
[NUnit.Framework.Test]
public virtual void WidthHeightXYInPercentsDiffPatternUnitsTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "widthHeightXYInPercentsDiffPatternUnits");
}
[NUnit.Framework.Test]
public virtual void WidthHeightXYInPxUnitDiffPatternUnitsTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "widthHeightXYInPxUnitDiffPatternUnits");
}
[NUnit.Framework.Test]
public virtual void WidthHeightXYInMmUnitDiffPatternUnitsTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "widthHeightXYInMmUnitDiffPatternUnits");
}
[NUnit.Framework.Test]
public virtual void WidthHeightXYInPtUnitDiffPatternUnitsTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "widthHeightXYInPtUnitDiffPatternUnits");
}
[NUnit.Framework.Test]
public virtual void WidthHeightXYNoMeasureUnitTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "widthHeightXYNoMeasureUnit");
}
[NUnit.Framework.Test]
public virtual void HrefAttributeTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "hrefAttribute");
}
[NUnit.Framework.Test]
public virtual void PatternUnitsObjectBoundingBoxTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "patternUnitsObjectBoundingBox");
}
[NUnit.Framework.Test]
public virtual void PatternUnitsUserSpaceOnUseTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "patternUnitsUserSpaceOnUse");
}
[NUnit.Framework.Test]
public virtual void PreserveAspectRatioObjBoundingBoxTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "preserveAspectRatioObjBoundingBox", PageSize.A8);
}
[NUnit.Framework.Test]
public virtual void PreserveAspectRatioUserSpaceOnUseTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "preserveAspectRatioUserSpaceOnUse", PageSize.A8);
}
[NUnit.Framework.Test]
public virtual void ObjectBoundingBoxXMinYMidMeetTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "objectBoundingBoxXMinYMidMeet", PageSize.A8);
}
[NUnit.Framework.Test]
public virtual void ObjectBoundingBoxXMidYMidMeetTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "objectBoundingBoxXMidYMidMeet", PageSize.A10);
}
[NUnit.Framework.Test]
public virtual void ObjectBoundingBoxXMaxYMidMeetTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "objectBoundingBoxXMaxYMidMeet", PageSize.A10);
}
[NUnit.Framework.Test]
public virtual void ObjectBoundingBoxXMidYMinMeetTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "objectBoundingBoxXMidYMinMeet", PageSize.A10);
}
[NUnit.Framework.Test]
public virtual void ObjectBoundingBoxXMidYMaxMeetTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "objectBoundingBoxXMidYMaxMeet", PageSize.A10);
}
[NUnit.Framework.Test]
public virtual void ObjectBoundingBoxXMidYMidMeetVerticalTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "objectBoundingBoxXMidYMidMeetVertical", PageSize.A10
);
}
[NUnit.Framework.Test]
public virtual void ObjectBoundingBoxXMinYMinMeetTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "objectBoundingBoxXMinYMinMeet", PageSize.A10);
}
[NUnit.Framework.Test]
public virtual void ObjectBoundingBoxXMinYMinMeetVerticalTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "objectBoundingBoxXMinYMinMeetVertical", PageSize.A10
);
}
[NUnit.Framework.Test]
public virtual void ObjectBoundingBoxXMinYMaxMeetVerticalTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "objectBoundingBoxXMinYMaxMeetVertical", PageSize.A10
);
}
[NUnit.Framework.Test]
public virtual void ObjectBoundingBoxXMinYMaxMeetTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "objectBoundingBoxXMinYMaxMeet", PageSize.A10);
}
[NUnit.Framework.Test]
public virtual void ObjectBoundingBoxXMaxYMinMeetTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "objectBoundingBoxXMaxYMinMeet", PageSize.A10);
}
[NUnit.Framework.Test]
public virtual void ObjectBoundingBoxXMaxYMinMeetVerticalTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "objectBoundingBoxXMaxYMinMeetVertical", PageSize.A10
);
}
[NUnit.Framework.Test]
public virtual void ObjectBoundingBoxXMaxYMaxMeetTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "objectBoundingBoxXMaxYMaxMeet", PageSize.A10);
}
[NUnit.Framework.Test]
public virtual void ObjectBoundingBoxXMaxYMaxMeetVerticalTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "objectBoundingBoxXMaxYMaxMeetVertical", PageSize.A10
);
}
[NUnit.Framework.Test]
public virtual void ObjectBoundingBoxNoneTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "objectBoundingBoxNone", PageSize.A10);
}
[NUnit.Framework.Test]
public virtual void PatternContentUnitsUserSpaceOnUseTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "patternContentUnitsUserSpaceOnUse");
}
[NUnit.Framework.Test]
public virtual void PatternContentUnitsObjBoundBoxTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "patternContentUnitsObjBoundBox");
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.StyledXmlParser.Logs.StyledXmlParserLogMessageConstant.UNKNOWN_ABSOLUTE_METRIC_LENGTH_PARSED
, Count = 8)]
public virtual void PatternContentUnitsObjBoundBoxAbsoluteCoordTest() {
// TODO DEVSIX-4834 support relative units in attributes of svg elements
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "patternContentUnitsObjBoundBoxAbsoluteCoord");
}
[NUnit.Framework.Test]
//TODO DEVSIX-4834 support relative units in attributes of svg elements
[LogMessage(TSpdf.StyledXmlParser.Logs.StyledXmlParserLogMessageConstant.UNKNOWN_ABSOLUTE_METRIC_LENGTH_PARSED
, Count = 8)]
public virtual void ViewBoxAndAbsoluteCoordinatesTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "viewBoxAndAbsoluteCoordinates");
}
[NUnit.Framework.Test]
public virtual void PatternTransformSimpleTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "patternTransformSimple");
}
[NUnit.Framework.Test]
public virtual void PatternTransformUnitsObjectBoundingBoxTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "patternTransformUnitsObjectBoundingBox");
}
[NUnit.Framework.Test]
public virtual void PatternTransformUnitsUserSpaceOnUseTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "patternTransformUnitsUserSpaceOnUse");
}
[NUnit.Framework.Test]
public virtual void PatternTransformObjBoundingBoxTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "patternTransformObjBoundingBox");
}
[NUnit.Framework.Test]
public virtual void PatternTransformUserSpaceOnUseTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "patternTransformUserSpaceOnUse");
}
[NUnit.Framework.Test]
public virtual void PatternTransformMixed1Test() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "patternTransformMixed1");
}
[NUnit.Framework.Test]
public virtual void PatternTransformMixed2Test() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "patternTransformMixed2");
}
[NUnit.Framework.Test]
public virtual void PatternTransformViewBoxUsrSpaceOnUseTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "patternTransformViewBoxUsrSpaceOnUse");
}
[NUnit.Framework.Test]
public virtual void PatternTransformViewBoxObjBoundBoxTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "patternTransformViewBoxObjBoundBox");
}
[NUnit.Framework.Test]
public virtual void PatternTransformElementTransformTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "patternTransformElementTransform", PageSize.A8);
}
[NUnit.Framework.Test]
public virtual void PatternTransformTranslateTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "patternTransformTranslate");
}
[NUnit.Framework.Test]
public virtual void PreserveAspectRatioXMaxYMidMeetTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "preserveAspectRatioXMaxYMidMeet");
}
[NUnit.Framework.Test]
public virtual void PreserveAspectRatioXMaxYMidSliceTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "preserveAspectRatioXMaxYMidSlice");
}
[NUnit.Framework.Test]
public virtual void PreserveAspectRatioXMidYMaxMeetTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "preserveAspectRatioXMidYMaxMeet");
}
[NUnit.Framework.Test]
public virtual void PreserveAspectRatioXMidYMaxSliceTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "preserveAspectRatioXMidYMaxSlice");
}
[NUnit.Framework.Test]
public virtual void RelativeUnitsResolveFromDefsTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "relativeUnitsResolveFromDefs");
}
[NUnit.Framework.Test]
public virtual void RelativeUnitsResolveFromPatternTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "relativeUnitsResolveFromPattern");
}
[NUnit.Framework.Test]
public virtual void LinearGradientInsidePatternTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "linearGradientInsidePattern");
}
[NUnit.Framework.Test]
public virtual void NestedPatternsTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "nestedPatterns");
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.StyledXmlParser.Logs.StyledXmlParserLogMessageConstant.UNKNOWN_ABSOLUTE_METRIC_LENGTH_PARSED
, Count = 2)]
public virtual void SeveralComplexElementsInsidePatternTest() {
// TODO DEVSIX-4834 support relative units in attributes of svg elements
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "severalComplexElementsInsidePattern");
}
[NUnit.Framework.Test]
public virtual void NestedPatternsWithComplexElementsInsideTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "nestedPatternsWithComplexElementsInside");
}
[NUnit.Framework.Test]
public virtual void PatternUseItselfTest() {
// Behavior differs from browser. In our implementation we use default color for element with cycled pattern.
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "patternUseItself");
}
[NUnit.Framework.Test]
public virtual void NestedPatternsLinkedToEachOtherTest() {
// Behavior differs from browser. In our implementation we use default color for element with cycled pattern.
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "nestedPatternsLinkedToEachOther");
}
[NUnit.Framework.Test]
public virtual void SimplePatternTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "simplePatternTest");
}
[NUnit.Framework.Test]
public virtual void SimplePatternInheritStylesTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "simplePatternInheritStylesTest");
}
[NUnit.Framework.Test]
public virtual void SimplePatternNestedTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "simplePatternNestedTest");
}
[NUnit.Framework.Test]
public virtual void SimplePatternStrokeTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "simplePatternStrokeTest");
}
[NUnit.Framework.Test]
public virtual void SimplePatternNestedFillInheritanceTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "simplePatternNestedFillInheritanceTest");
}
[NUnit.Framework.Test]
public virtual void PatternContentUnitsObjectBoundingBoxTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "patternContentUnitsObjectBoundingBox");
}
[NUnit.Framework.Test]
public virtual void CycledPatternsUserSpaceOnUseTest() {
// Behavior differs from browser. We use default color instead cycled pattern.
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "cycledPatternsUserSpaceOnUse");
}
[NUnit.Framework.Test]
public virtual void ObjBoundingBoxWithMarginsTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "objBoundingBoxWithMargins");
}
[NUnit.Framework.Test]
public virtual void ObjBoundingBoxUserSpaceOnUseTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "objBoundingBoxUserSpaceOnUse");
}
[NUnit.Framework.Test]
public virtual void UserSpaceOnUseObjBoundingBoxTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "userSpaceOnUseObjBoundingBox");
}
[NUnit.Framework.Test]
public virtual void PatternDefaultWidthTest() {
// we print the default color that is black
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "patternDefaultWidth");
}
[NUnit.Framework.Test]
public virtual void PatternDefaultHeightTest() {
// we print the default color that is black
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "patternDefaultHeight");
}
[NUnit.Framework.Test]
public virtual void ViewBoxPatternXYTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "viewBoxPatternXY");
}
[NUnit.Framework.Test]
public virtual void ViewBoxClippedTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "viewBoxClipped");
}
[NUnit.Framework.Test]
public virtual void CoordSystemTransformUserSpaceOnUseTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "coordSystemTransformUserSpaceOnUse");
}
[NUnit.Framework.Test]
public virtual void CoordSystemTransformObjBoundingBoxTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "coordSystemTransformObjBoundingBox");
}
[NUnit.Framework.Test]
public virtual void CoordSystemTransformMixed1Test() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "coordSystemTransformMixed1");
}
[NUnit.Framework.Test]
public virtual void CoordSystemTransformMixed2Test() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "coordSystemTransformMixed2");
}
[NUnit.Framework.Test]
public virtual void CoordSystemTransform() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "coordSystemTransform");
}
[NUnit.Framework.Test]
[LogMessage(SvgLogMessageConstant.VIEWBOX_VALUE_MUST_BE_FOUR_NUMBERS, Count = 1)]
public virtual void IncorrectViewBoxValuesNumberTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "incorrectViewBoxValuesNumber");
}
[NUnit.Framework.Test]
[LogMessage(SvgLogMessageConstant.VIEWBOX_WIDTH_AND_HEIGHT_CANNOT_BE_NEGATIVE)]
public virtual void IncorrectViewBoxNegativeWidthTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "incorrectViewBoxNegativeWidth");
}
[NUnit.Framework.Test]
[LogMessage(SvgLogMessageConstant.VIEWBOX_WIDTH_AND_HEIGHT_CANNOT_BE_NEGATIVE)]
public virtual void IncorrectViewBoxNegativeHeightTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "incorrectViewBoxNegativeHeight");
}
[NUnit.Framework.Test]
public virtual void ViewBoxZeroWidthTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "viewBoxZeroWidth");
}
[NUnit.Framework.Test]
public virtual void ViewBoxZeroHeightTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "viewBoxZeroHeight");
}
[NUnit.Framework.Test]
[LogMessage(SvgLogMessageConstant.PATTERN_WIDTH_OR_HEIGHT_IS_NEGATIVE)]
public virtual void PatternNegativeWidthTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "patternNegativeWidth");
}
}
}

View File

@@ -0,0 +1,144 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using System.Collections.Generic;
using System.IO;
using TSpdf.Kernel.Geom;
using TSpdf.Kernel.Pdf;
using TSpdf.Kernel.Pdf.Canvas;
using TSpdf.Kernel.Pdf.Xobject;
using TSpdf.Svg.Converter;
using TSpdf.Svg.Exceptions;
using TSpdf.Svg.Renderers;
namespace TSpdf.Svg.Renderers.Impl {
[NUnit.Framework.Category("IntegrationTest")]
public class PdfRootSvgNodeRendererIntegrationTest : SvgIntegrationTest {
[NUnit.Framework.Test]
public virtual void CalculateOutermostViewportTest() {
Rectangle expected = new Rectangle(0, 0, 600, 600);
SvgDrawContext context = new SvgDrawContext(null, null);
PdfDocument document = new PdfDocument(new PdfWriter(new MemoryStream(), new WriterProperties().SetCompressionLevel
(0)));
document.AddNewPage();
PdfFormXObject pdfForm = new PdfFormXObject(expected);
PdfCanvas canvas = new PdfCanvas(pdfForm, document);
context.PushCanvas(canvas);
SvgTagSvgNodeRenderer renderer = new SvgTagSvgNodeRenderer();
PdfRootSvgNodeRenderer root = new PdfRootSvgNodeRenderer(renderer);
Rectangle actual = root.CalculateViewPort(context);
NUnit.Framework.Assert.IsTrue(expected.EqualsWithEpsilon(actual));
}
[NUnit.Framework.Test]
public virtual void CalculateOutermostViewportWithDifferentXYTest() {
Rectangle expected = new Rectangle(10, 20, 600, 600);
SvgDrawContext context = new SvgDrawContext(null, null);
PdfDocument document = new PdfDocument(new PdfWriter(new MemoryStream(), new WriterProperties().SetCompressionLevel
(0)));
document.AddNewPage();
PdfFormXObject pdfForm = new PdfFormXObject(expected);
PdfCanvas canvas = new PdfCanvas(pdfForm, document);
context.PushCanvas(canvas);
SvgTagSvgNodeRenderer renderer = new SvgTagSvgNodeRenderer();
PdfRootSvgNodeRenderer root = new PdfRootSvgNodeRenderer(renderer);
Rectangle actual = root.CalculateViewPort(context);
NUnit.Framework.Assert.IsTrue(expected.EqualsWithEpsilon(actual));
}
[NUnit.Framework.Test]
public virtual void CalculateNestedViewportDifferentFromParentTest() {
Rectangle expected = new Rectangle(0, 0, 500, 500);
SvgDrawContext context = new SvgDrawContext(null, null);
PdfDocument document = new PdfDocument(new PdfWriter(new MemoryStream(), new WriterProperties().SetCompressionLevel
(0)));
document.AddNewPage();
PdfFormXObject pdfForm = new PdfFormXObject(expected);
PdfCanvas canvas = new PdfCanvas(pdfForm, document);
context.PushCanvas(canvas);
context.AddViewPort(expected);
SvgTagSvgNodeRenderer parent = new SvgTagSvgNodeRenderer();
SvgTagSvgNodeRenderer renderer = new SvgTagSvgNodeRenderer();
PdfRootSvgNodeRenderer root = new PdfRootSvgNodeRenderer(parent);
IDictionary<String, String> styles = new Dictionary<String, String>();
styles.Put("width", "500");
styles.Put("height", "500");
renderer.SetAttributesAndStyles(styles);
renderer.SetParent(parent);
Rectangle actual = root.CalculateViewPort(context);
NUnit.Framework.Assert.IsTrue(expected.EqualsWithEpsilon(actual));
}
[NUnit.Framework.Test]
public virtual void NoBoundingBoxOnXObjectTest() {
PdfDocument document = new PdfDocument(new PdfWriter(new MemoryStream(), new WriterProperties().SetCompressionLevel
(0)));
document.AddNewPage();
ISvgNodeRenderer processed = SvgConverter.Process(SvgConverter.Parse("<svg />"), null).GetRootRenderer();
PdfRootSvgNodeRenderer root = new PdfRootSvgNodeRenderer(processed);
PdfFormXObject pdfForm = new PdfFormXObject(new PdfStream());
PdfCanvas canvas = new PdfCanvas(pdfForm, document);
SvgDrawContext context = new SvgDrawContext(null, null);
context.PushCanvas(canvas);
Exception e = NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => root.Draw(context));
NUnit.Framework.Assert.AreEqual(SvgExceptionMessageConstant.ROOT_SVG_NO_BBOX, e.Message);
}
[NUnit.Framework.Test]
public virtual void CalculateOutermostTransformation() {
AffineTransform expected = new AffineTransform(1d, 0d, 0d, -1d, 0d, 600d);
SvgDrawContext context = new SvgDrawContext(null, null);
PdfDocument document = new PdfDocument(new PdfWriter(new MemoryStream(), new WriterProperties().SetCompressionLevel
(0)));
document.AddNewPage();
PdfFormXObject pdfForm = new PdfFormXObject(new Rectangle(0, 0, 600, 600));
PdfCanvas canvas = new PdfCanvas(pdfForm, document);
context.PushCanvas(canvas);
SvgTagSvgNodeRenderer renderer = new SvgTagSvgNodeRenderer();
PdfRootSvgNodeRenderer root = new PdfRootSvgNodeRenderer(renderer);
context.AddViewPort(root.CalculateViewPort(context));
AffineTransform actual = root.CalculateTransformation(context);
NUnit.Framework.Assert.AreEqual(expected, actual);
}
}
}

View File

@@ -0,0 +1,36 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://TSpdfpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using TSpdf.Svg.Renderers;
using TSpdf.Test;
namespace TSpdf.Svg.Renderers.Impl {
[NUnit.Framework.Category("UnitTest")]
public class PdfRootSvgNodeRendererUnitTest : ExtendedTSpdfTest {
[NUnit.Framework.Test]
public virtual void NoObjectBoundingBoxTest() {
ISvgNodeRenderer subTreeRoot = new SvgTagSvgNodeRenderer();
PdfRootSvgNodeRenderer renderer = new PdfRootSvgNodeRenderer(subTreeRoot);
NUnit.Framework.Assert.IsNull(renderer.GetObjectBoundingBox(null));
}
}
}

View File

@@ -0,0 +1,183 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using System.Collections.Generic;
using System.IO;
using TSpdf.Kernel.Geom;
using TSpdf.Kernel.Pdf;
using TSpdf.Kernel.Pdf.Canvas;
using TSpdf.Kernel.Utils;
using TSpdf.Svg;
using TSpdf.Svg.Renderers;
using TSpdf.Test;
namespace TSpdf.Svg.Renderers.Impl {
[NUnit.Framework.Category("IntegrationTest")]
public class PolygonSvgNodeRendererTest : SvgIntegrationTest {
private static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/renderers/impl/PolygonSvgNoderendererTest/";
private static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/renderers/impl/PolygonSvgNoderendererTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateDestinationFolder(destinationFolder);
}
[NUnit.Framework.Test]
public virtual void PolygonLineRendererTest() {
String filename = "polygonLineRendererTest.pdf";
PdfDocument doc = new PdfDocument(new PdfWriter(destinationFolder + filename));
doc.AddNewPage();
ISvgNodeRenderer root = new PolygonSvgNodeRenderer();
IDictionary<String, String> polyLineAttributes = new Dictionary<String, String>();
polyLineAttributes.Put(SvgConstants.Attributes.POINTS, "60,20 100,40 100,80 60,100 20,80 20,40");
root.SetAttributesAndStyles(polyLineAttributes);
SvgDrawContext context = new SvgDrawContext(null, null);
PdfCanvas cv = new PdfCanvas(doc, 1);
context.PushCanvas(cv);
root.Draw(context);
doc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareVisually(destinationFolder + filename, sourceFolder
+ "cmp_" + filename, destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void PolygonLinkedPointCheckerImplicit() {
PdfDocument doc = new PdfDocument(new PdfWriter(new MemoryStream()));
doc.AddNewPage();
ISvgNodeRenderer root = new PolygonSvgNodeRenderer();
IDictionary<String, String> polyLineAttributes = new Dictionary<String, String>();
polyLineAttributes.Put(SvgConstants.Attributes.POINTS, "0,0 100,100 200,200 300,300");
root.SetAttributesAndStyles(polyLineAttributes);
SvgDrawContext context = new SvgDrawContext(null, null);
PdfCanvas cv = new PdfCanvas(doc, 1);
context.PushCanvas(cv);
root.Draw(context);
IList<Point> expectedPoints = new List<Point>();
expectedPoints.Add(new Point(0, 0));
expectedPoints.Add(new Point(75, 75));
expectedPoints.Add(new Point(150, 150));
expectedPoints.Add(new Point(225, 225));
expectedPoints.Add(new Point(0, 0));
IList<Point> attributePoints = ((PolygonSvgNodeRenderer)root).GetPoints();
NUnit.Framework.Assert.AreEqual(expectedPoints.Count, attributePoints.Count);
for (int x = 0; x < attributePoints.Count; x++) {
NUnit.Framework.Assert.AreEqual(expectedPoints[x], attributePoints[x]);
}
}
[NUnit.Framework.Test]
public virtual void PolygonLinkedPointCheckerExplicit() {
PdfDocument doc = new PdfDocument(new PdfWriter(new MemoryStream()));
doc.AddNewPage();
ISvgNodeRenderer root = new PolygonSvgNodeRenderer();
IDictionary<String, String> polyLineAttributes = new Dictionary<String, String>();
polyLineAttributes.Put(SvgConstants.Attributes.POINTS, "0,0 100,100 200,200 300,300 0,0");
root.SetAttributesAndStyles(polyLineAttributes);
SvgDrawContext context = new SvgDrawContext(null, null);
PdfCanvas cv = new PdfCanvas(doc, 1);
context.PushCanvas(cv);
root.Draw(context);
IList<Point> expectedPoints = new List<Point>();
expectedPoints.Add(new Point(0, 0));
expectedPoints.Add(new Point(75, 75));
expectedPoints.Add(new Point(150, 150));
expectedPoints.Add(new Point(225, 225));
expectedPoints.Add(new Point(0, 0));
IList<Point> attributePoints = ((PolygonSvgNodeRenderer)root).GetPoints();
NUnit.Framework.Assert.AreEqual(expectedPoints.Count, attributePoints.Count);
for (int x = 0; x < attributePoints.Count; x++) {
NUnit.Framework.Assert.AreEqual(expectedPoints[x], attributePoints[x]);
}
}
[NUnit.Framework.Test]
public virtual void PolygonEmptyPointCheckerTest() {
String filename = "polygonEmptyPointCheckerTest.pdf";
PdfDocument doc = new PdfDocument(new PdfWriter(destinationFolder + filename));
doc.AddNewPage();
ISvgNodeRenderer root = new PolygonSvgNodeRenderer();
IDictionary<String, String> polyLineAttributes = new Dictionary<String, String>();
root.SetAttributesAndStyles(polyLineAttributes);
SvgDrawContext context = new SvgDrawContext(null, null);
PdfCanvas cv = new PdfCanvas(doc, 1);
context.PushCanvas(cv);
root.Draw(context);
doc.Close();
int numPoints = ((PolygonSvgNodeRenderer)root).GetPoints().Count;
NUnit.Framework.Assert.AreEqual(numPoints, 0);
NUnit.Framework.Assert.IsNull(new CompareTool().CompareVisually(destinationFolder + filename, sourceFolder
+ "cmp_" + filename, destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void ConnectPointsWithSameYCoordinateTest() {
PdfDocument doc = new PdfDocument(new PdfWriter(new MemoryStream()));
doc.AddNewPage();
ISvgNodeRenderer root = new PolygonSvgNodeRenderer();
IDictionary<String, String> polyLineAttributes = new Dictionary<String, String>();
polyLineAttributes.Put(SvgConstants.Attributes.POINTS, "100,100 100,200 150,200 150,100");
polyLineAttributes.Put(SvgConstants.Attributes.FILL, "none");
polyLineAttributes.Put(SvgConstants.Attributes.STROKE, "black");
root.SetAttributesAndStyles(polyLineAttributes);
SvgDrawContext context = new SvgDrawContext(null, null);
PdfCanvas cv = new PdfCanvas(doc, 1);
context.PushCanvas(cv);
root.Draw(context);
doc.Close();
IList<Point> expectedPoints = new List<Point>();
expectedPoints.Add(new Point(75, 75));
expectedPoints.Add(new Point(75, 150));
expectedPoints.Add(new Point(112.5, 150));
expectedPoints.Add(new Point(112.5, 75));
expectedPoints.Add(new Point(75, 75));
IList<Point> attributePoints = ((PolygonSvgNodeRenderer)root).GetPoints();
NUnit.Framework.Assert.AreEqual(expectedPoints.Count, attributePoints.Count);
for (int x = 0; x < attributePoints.Count; x++) {
NUnit.Framework.Assert.AreEqual(expectedPoints[x], attributePoints[x]);
}
}
}
}

View File

@@ -0,0 +1,164 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using System.Collections.Generic;
using System.IO;
using TSpdf.Kernel.Geom;
using TSpdf.Kernel.Pdf;
using TSpdf.Kernel.Pdf.Canvas;
using TSpdf.Kernel.Utils;
using TSpdf.StyledXmlParser.Exceptions;
using TSpdf.Svg;
using TSpdf.Svg.Exceptions;
using TSpdf.Svg.Renderers;
using TSpdf.Test;
namespace TSpdf.Svg.Renderers.Impl {
[NUnit.Framework.Category("IntegrationTest")]
public class PolylineSvgNodeRendererTest : SvgIntegrationTest {
private static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/renderers/impl/PolylineSvgNodeRendererTest/";
private static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/renderers/impl/PolylineSvgNodeRendererTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateDestinationFolder(destinationFolder);
}
[NUnit.Framework.Test]
public virtual void PolylineRendererTest() {
String filename = "polylineRendererTest.pdf";
PdfDocument doc = new PdfDocument(new PdfWriter(destinationFolder + filename));
doc.AddNewPage();
ISvgNodeRenderer root = new PolylineSvgNodeRenderer();
IDictionary<String, String> polyLineAttributes = new Dictionary<String, String>();
polyLineAttributes.Put(SvgConstants.Attributes.POINTS, "0,40 40,40 40,80 80,80 80,120 120,120 120,160");
root.SetAttributesAndStyles(polyLineAttributes);
SvgDrawContext context = new SvgDrawContext(null, null);
PdfCanvas cv = new PdfCanvas(doc, 1);
context.PushCanvas(cv);
root.Draw(context);
doc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareVisually(destinationFolder + filename, sourceFolder
+ "cmp_" + filename, destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void PolyLineInvalidAttributeTest01() {
PdfDocument doc = new PdfDocument(new PdfWriter(new MemoryStream()));
doc.AddNewPage();
ISvgNodeRenderer root = new PolylineSvgNodeRenderer();
IDictionary<String, String> polyLineAttributes = new Dictionary<String, String>();
polyLineAttributes.Put(SvgConstants.Attributes.POINTS, "0,0 notAnum,alsoNotANum");
root.SetAttributesAndStyles(polyLineAttributes);
SvgDrawContext context = new SvgDrawContext(null, null);
PdfCanvas cv = new PdfCanvas(doc, 1);
context.PushCanvas(cv);
NUnit.Framework.Assert.Catch(typeof(StyledXMLParserException), () => root.Draw(context));
}
[NUnit.Framework.Test]
public virtual void PolyLineInvalidAttributeTest02() {
PdfDocument doc = new PdfDocument(new PdfWriter(new MemoryStream()));
doc.AddNewPage();
ISvgNodeRenderer root = new PolylineSvgNodeRenderer();
IDictionary<String, String> polyLineAttributes = new Dictionary<String, String>();
polyLineAttributes.Put(SvgConstants.Attributes.POINTS, "0,0 100,100 5, 20,30");
root.SetAttributesAndStyles(polyLineAttributes);
SvgDrawContext context = new SvgDrawContext(null, null);
PdfCanvas cv = new PdfCanvas(doc, 1);
context.PushCanvas(cv);
NUnit.Framework.Assert.Catch(typeof(SvgProcessingException), () => root.Draw(context));
}
[NUnit.Framework.Test]
public virtual void PolyLineEmptyPointsListTest() {
String filename = "polyLineEmptyPointsListTest.pdf";
PdfDocument doc = new PdfDocument(new PdfWriter(destinationFolder + filename));
doc.AddNewPage();
ISvgNodeRenderer root = new PolylineSvgNodeRenderer();
IDictionary<String, String> polyLineAttributes = new Dictionary<String, String>();
root.SetAttributesAndStyles(polyLineAttributes);
SvgDrawContext context = new SvgDrawContext(null, null);
PdfCanvas cv = new PdfCanvas(doc, 1);
context.PushCanvas(cv);
root.Draw(context);
doc.Close();
int numPoints = ((PolylineSvgNodeRenderer)root).GetPoints().Count;
NUnit.Framework.Assert.AreEqual(numPoints, 0);
NUnit.Framework.Assert.IsNull(new CompareTool().CompareVisually(destinationFolder + filename, sourceFolder
+ "cmp_" + filename, destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void PolyPointCheckerTest() {
PdfDocument doc = new PdfDocument(new PdfWriter(new MemoryStream()));
doc.AddNewPage();
ISvgNodeRenderer root = new PolylineSvgNodeRenderer();
IDictionary<String, String> polyLineAttributes = new Dictionary<String, String>();
polyLineAttributes.Put(SvgConstants.Attributes.POINTS, "0,0 100,100 200,200 300,300");
root.SetAttributesAndStyles(polyLineAttributes);
SvgDrawContext context = new SvgDrawContext(null, null);
PdfCanvas cv = new PdfCanvas(doc, 1);
context.PushCanvas(cv);
root.Draw(context);
IList<Point> expectedPoints = new List<Point>();
expectedPoints.Add(new Point(0, 0));
expectedPoints.Add(new Point(75, 75));
expectedPoints.Add(new Point(150, 150));
expectedPoints.Add(new Point(225, 225));
IList<Point> attributePoints = ((PolylineSvgNodeRenderer)root).GetPoints();
NUnit.Framework.Assert.AreEqual(expectedPoints.Count, attributePoints.Count);
for (int x = 0; x < attributePoints.Count; x++) {
NUnit.Framework.Assert.AreEqual(expectedPoints[x], attributePoints[x]);
}
}
[NUnit.Framework.Test]
public virtual void ElementDimensionExceedsViewboxBoundaryTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "elementDimensionExceedsViewboxBoundary");
}
}
}

View File

@@ -0,0 +1,41 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://TSpdfpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using TSpdf.Layout.Font;
using TSpdf.StyledXmlParser.Resolver.Resource;
using TSpdf.Svg.Renderers;
using TSpdf.Test;
namespace TSpdf.Svg.Renderers.Impl {
[NUnit.Framework.Category("UnitTest")]
public class PolylineSvgNodeRendererUnitTest : ExtendedTSpdfTest {
[NUnit.Framework.Test]
public virtual void GetObjectBoundingBoxTest() {
PolylineSvgNodeRenderer renderer = new PolygonSvgNodeRenderer();
SvgDrawContext context = new SvgDrawContext(new ResourceResolver(""), new FontProvider());
renderer.SetAttributesAndStyles(new Dictionary<String, String>());
NUnit.Framework.Assert.IsNull(renderer.GetObjectBoundingBox(context));
}
}
}

View File

@@ -0,0 +1,196 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using TSpdf.Svg.Renderers;
using TSpdf.Test;
using TSpdf.Test.Attributes;
namespace TSpdf.Svg.Renderers.Impl {
[NUnit.Framework.Category("IntegrationTest")]
public class PreserveAspectRatioSvgNodeRendererIntegrationTest : SvgIntegrationTest {
private static readonly String SOURCE_FOLDER = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/renderers/impl/PreserveAspectRatioSvgNodeRendererIntegrationTest/";
private static readonly String DESTINATION_FOLDER = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/renderers/impl/PreserveAspectRatioSvgNodeRendererIntegrationTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateDestinationFolder(DESTINATION_FOLDER);
}
[NUnit.Framework.Test]
public virtual void AspectRatioPreservationMidXMidYMeetMinimalTest() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "MidXMidYMeetMinimalTest");
}
[NUnit.Framework.Test]
public virtual void ViewBoxScalingTestPreserveAspectDefaultAll() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "PreserveAspectDefaultAll");
}
[NUnit.Framework.Test]
public virtual void ViewBoxWithoutSetPreserveAspectRatioTest() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "PreserveAspectRatio");
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.StyledXmlParser.Logs.StyledXmlParserLogMessageConstant.INVALID_CSS_PROPERTY_DECLARATION,
Count = 19)]
public virtual void DifferentAspectRatiosTest() {
//TODO: update cmp_ when DEVSIX-2250 fixed
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "differentAspectRatios");
}
[NUnit.Framework.Test]
public virtual void ViewBoxScalingTestPreserveAspectDefaultAllGroup() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "PreserveAspectDefaultAllGroup");
}
[NUnit.Framework.Test]
public virtual void ViewBoxScalingTestDoNotPreserveAspectMin() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "DoNotPreserveAspectMin");
}
[NUnit.Framework.Test]
public virtual void ViewBoxScalingTestDoNotPreserveAspectAll() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "DoNotPreserveAspectAll");
}
[NUnit.Framework.Test]
public virtual void ViewBoxScalingTestDoNotPreserveAspectMetricDimensionsMin() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "DoNotPreserveAspectMetricDimensionsMin");
}
[NUnit.Framework.Test]
public virtual void ViewBoxScalingTestDoNotPreserveAspectMetricDimensionsAll() {
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "DoNotPreserveAspectMetricDimensionsAll");
}
[NUnit.Framework.Test]
public virtual void ViewBoxScalingTestPreserveAspectRatioXMinYMinMeetScaling() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "PreserveAspectRatioXMinYMinMeetScaling");
}
[NUnit.Framework.Test]
public virtual void ViewBoxScalingTestPreserveAspectRatioXMinYMidMeetScaling() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "PreserveAspectRatioXMinYMidMeetScaling");
}
[NUnit.Framework.Test]
public virtual void ViewBoxScalingTestPreserveAspectRatioXMinYMaxMeetScaling() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "PreserveAspectRatioXMinYMaxMeetScaling");
}
[NUnit.Framework.Test]
public virtual void ViewBoxScalingTestPreserveAspectRatioXMidYMinMeetScaling() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "PreserveAspectRatioXMidYMinMeetScaling");
}
[NUnit.Framework.Test]
public virtual void ViewBoxScalingTestPreserveAspectRatioXMidYMaxMeetScaling() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "PreserveAspectRatioXMidYMaxMeetScaling");
}
[NUnit.Framework.Test]
public virtual void ViewBoxScalingTestPreserveAspectRatioXMaxYMinMeetScaling() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "PreserveAspectRatioXMaxYMinMeetScaling");
}
[NUnit.Framework.Test]
public virtual void ViewBoxScalingTestPreserveAspectRatioXMaxYMidMeetScaling() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "PreserveAspectRatioXMaxYMidMeetScaling");
}
[NUnit.Framework.Test]
public virtual void ViewBoxTranslationTestInnerZeroCoordinatesViewBox() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "InnerZeroCoordinatesViewBox");
}
[NUnit.Framework.Test]
public virtual void ViewBoxTranslationTestOuterZeroCoordinatesViewBox() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "OuterZeroCoordinatesViewBox");
}
[NUnit.Framework.Test]
public virtual void ViewBoxTranslationTestMultipleViewBoxes() {
ConvertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "MultipleViewBoxes");
}
[NUnit.Framework.Test]
public virtual void SvgTranslationYMinMeetTest() {
//TODO (DEVSIX-3537) change cmp files after the ticket will be fixed
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "svgTranslationYMinMeet");
}
[NUnit.Framework.Test]
public virtual void SvgTranslationYMidMeetTest() {
//TODO (DEVSIX-3537) change cmp files after the ticket will be fixed
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "svgTranslationYMidMeet");
}
[NUnit.Framework.Test]
public virtual void SvgTranslationYMaxMeetTest() {
//TODO (DEVSIX-3537) change cmp files after the ticket will be fixed
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "svgTranslationYMaxMeet");
}
[NUnit.Framework.Test]
public virtual void SvgTranslationXMinMeetTest() {
//TODO (DEVSIX-3537) change cmp files after the ticket will be fixed
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "svgTranslationXMinMeet");
}
[NUnit.Framework.Test]
public virtual void SvgTranslationXMidMeetTest() {
//TODO (DEVSIX-3537) change cmp files after the ticket will be fixed
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "svgTranslationXMidMeet");
}
[NUnit.Framework.Test]
public virtual void SvgTranslationXMaxMeetTest() {
//TODO (DEVSIX-3537) change cmp files after the ticket will be fixed
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "svgTranslationXMaxMeet");
}
}
}

View File

@@ -0,0 +1,218 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://TSpdfpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using TSpdf.Commons.Utils;
using TSpdf.Kernel.Geom;
using TSpdf.Svg;
using TSpdf.Svg.Renderers;
using TSpdf.Test;
namespace TSpdf.Svg.Renderers.Impl {
[NUnit.Framework.Category("UnitTest")]
public class PreserveAspectRatioSvgNodeRendererUnitTest : ExtendedTSpdfTest {
private static readonly Rectangle VIEWPORT_VALUE = PageSize.DEFAULT;
private static readonly float[] VIEWBOX_VALUES = new float[] { 0, 0, 300, 400 };
[NUnit.Framework.Test]
public virtual void ProcessAspectRatioPositionDefault() {
//default aspect ration is xMidYMid
String alignValue = SvgConstants.Values.DEFAULT_ASPECT_RATIO;
AffineTransform cmpTransform = new AffineTransform();
cmpTransform.Translate(147.5, 221);
ProcessAspectRatioPositionAndCompare(alignValue, cmpTransform);
}
[NUnit.Framework.Test]
public virtual void ProcessAspectRatioPositionNone() {
String alignValue = SvgConstants.Values.NONE;
AffineTransform cmpTransform = new AffineTransform();
cmpTransform.Translate(0, 0);
ProcessAspectRatioPositionAndCompare(alignValue, cmpTransform);
}
[NUnit.Framework.Test]
public virtual void ProcessAspectRatioPositionXMinYMin() {
String alignValue = SvgConstants.Values.XMIN_YMIN;
AffineTransform cmpTransform = new AffineTransform();
cmpTransform.Translate(0, 0);
ProcessAspectRatioPositionAndCompare(alignValue, cmpTransform);
}
[NUnit.Framework.Test]
public virtual void ProcessAspectRatioPositionXMinYMid() {
String alignValue = SvgConstants.Values.XMIN_YMID;
AffineTransform cmpTransform = new AffineTransform();
cmpTransform.Translate(0, 221);
ProcessAspectRatioPositionAndCompare(alignValue, cmpTransform);
}
[NUnit.Framework.Test]
public virtual void ProcessAspectRatioPositionXMinYMax() {
String alignValue = SvgConstants.Values.XMIN_YMAX;
AffineTransform cmpTransform = new AffineTransform();
cmpTransform.Translate(0, 442);
ProcessAspectRatioPositionAndCompare(alignValue, cmpTransform);
}
[NUnit.Framework.Test]
public virtual void ProcessAspectRatioPositionXMidYMin() {
String alignValue = SvgConstants.Values.XMID_YMIN;
AffineTransform cmpTransform = new AffineTransform();
cmpTransform.Translate(147.5, 0);
ProcessAspectRatioPositionAndCompare(alignValue, cmpTransform);
}
[NUnit.Framework.Test]
public virtual void ProcessAspectRatioPositionXMidYMax() {
String alignValue = SvgConstants.Values.XMID_YMAX;
AffineTransform cmpTransform = new AffineTransform();
cmpTransform.Translate(147.5, 442);
ProcessAspectRatioPositionAndCompare(alignValue, cmpTransform);
}
[NUnit.Framework.Test]
public virtual void ProcessAspectRatioPositionXMaxYMin() {
String alignValue = SvgConstants.Values.XMAX_YMIN;
AffineTransform cmpTransform = new AffineTransform();
cmpTransform.Translate(295, 0);
ProcessAspectRatioPositionAndCompare(alignValue, cmpTransform);
}
[NUnit.Framework.Test]
public virtual void ProcessAspectRatioPositionXMaxYMid() {
String alignValue = SvgConstants.Values.XMAX_YMID;
AffineTransform cmpTransform = new AffineTransform();
cmpTransform.Translate(295, 221);
ProcessAspectRatioPositionAndCompare(alignValue, cmpTransform);
}
[NUnit.Framework.Test]
public virtual void ProcessAspectRatioPositionXMaxYMax() {
String alignValue = SvgConstants.Values.XMAX_YMAX;
AffineTransform cmpTransform = new AffineTransform();
cmpTransform.Translate(295, 442);
ProcessAspectRatioPositionAndCompare(alignValue, cmpTransform);
}
[NUnit.Framework.Test]
public virtual void RetrieveAlignAndMeetXMinYMinMeet() {
String align = SvgConstants.Values.XMIN_YMIN;
String meet = SvgConstants.Values.MEET;
String[] cmpAlignAndMeet = new String[] { align, meet };
String[] outAlignAndMeet = RetrieveAlignAndMeet(align, meet);
NUnit.Framework.Assert.AreEqual(cmpAlignAndMeet, outAlignAndMeet);
}
[NUnit.Framework.Test]
public virtual void RetrieveAlignAndMeetXMinYMinSlice() {
String align = SvgConstants.Values.XMIN_YMIN;
String meet = SvgConstants.Values.SLICE;
String[] cmpAlignAndMeet = new String[] { align, meet };
String[] outAlignAndMeet = RetrieveAlignAndMeet(align, meet);
NUnit.Framework.Assert.AreEqual(cmpAlignAndMeet, outAlignAndMeet);
}
[NUnit.Framework.Test]
public virtual void RetrieveAlignAndMeetXMinYMinNone() {
String align = SvgConstants.Values.XMIN_YMIN;
String meet = SvgConstants.Values.MEET;
String[] cmpAlignAndMeet = new String[] { align, meet };
String[] outAlignAndMeet = RetrieveAlignAndMeet(align, "");
NUnit.Framework.Assert.AreEqual(cmpAlignAndMeet, outAlignAndMeet);
}
[NUnit.Framework.Test]
public virtual void RetrieveAlignAndMeetEmptyMeet() {
String align = SvgConstants.Values.DEFAULT_ASPECT_RATIO;
String meet = SvgConstants.Values.MEET;
String[] cmpAlignAndMeet = new String[] { align, meet };
String[] outAlignAndMeet = RetrieveAlignAndMeet("", meet);
//should fail, because align attribute must be present
NUnit.Framework.Assert.IsFalse(JavaUtil.ArraysEquals(cmpAlignAndMeet, outAlignAndMeet));
}
[NUnit.Framework.Test]
public virtual void RetrieveAlignAndMeetEmptySlice() {
String align = SvgConstants.Values.DEFAULT_ASPECT_RATIO;
String meet = SvgConstants.Values.SLICE;
String[] cmpAlignAndMeet = new String[] { align, meet };
String[] outAlignAndMeet = RetrieveAlignAndMeet("", meet);
//should fail, because align attribute must be present
NUnit.Framework.Assert.IsFalse(JavaUtil.ArraysEquals(cmpAlignAndMeet, outAlignAndMeet));
}
[NUnit.Framework.Test]
public virtual void RetrieveAlignAndMeetNoneMeet() {
String align = SvgConstants.Values.NONE;
String meet = SvgConstants.Values.MEET;
String[] cmpAlignAndMeet = new String[] { align, meet };
String[] outAlignAndMeet = RetrieveAlignAndMeet(align, meet);
NUnit.Framework.Assert.AreEqual(cmpAlignAndMeet, outAlignAndMeet);
}
[NUnit.Framework.Test]
public virtual void RetrieveAlignAndMeetNoneSlice() {
String align = SvgConstants.Values.NONE;
String meet = SvgConstants.Values.SLICE;
String[] cmpAlignAndMeet = new String[] { align, meet };
String[] outAlignAndMeet = RetrieveAlignAndMeet(align, meet);
NUnit.Framework.Assert.AreEqual(cmpAlignAndMeet, outAlignAndMeet);
}
[NUnit.Framework.Test]
public virtual void RetrieveAlignAndMeetAllDefault() {
String align = SvgConstants.Values.DEFAULT_ASPECT_RATIO;
String meet = SvgConstants.Values.MEET;
String[] cmpAlignAndMeet = new String[] { align, meet };
String[] outAlignAndMeet = RetrieveAlignAndMeet("", "");
NUnit.Framework.Assert.AreEqual(cmpAlignAndMeet, outAlignAndMeet);
}
private void ProcessAspectRatioPositionAndCompare(String alignValue, AffineTransform cmpTransform) {
SvgDrawContext context = new SvgDrawContext(null, null);
// topmost viewport has default page size values for bounding rectangle
context.AddViewPort(VIEWPORT_VALUE);
float[] viewboxValues = VIEWBOX_VALUES;
float scaleWidth = 1.0f;
float scaleHeight = 1.0f;
AbstractBranchSvgNodeRenderer renderer = new SvgTagSvgNodeRenderer();
IDictionary<String, String> attributesAndStyles = new Dictionary<String, String>();
renderer.SetAttributesAndStyles(attributesAndStyles);
AffineTransform outTransform = renderer.ProcessAspectRatioPosition(context, viewboxValues, alignValue, scaleWidth
, scaleHeight);
NUnit.Framework.Assert.IsTrue(cmpTransform.Equals(outTransform));
}
private String[] RetrieveAlignAndMeet(String align, String meet) {
AbstractBranchSvgNodeRenderer renderer = new SvgTagSvgNodeRenderer();
IDictionary<String, String> attributesAndStyles = new Dictionary<String, String>();
if (!"".Equals(align) || !"".Equals(meet)) {
attributesAndStyles.Put(SvgConstants.Attributes.PRESERVE_ASPECT_RATIO, align + " " + meet);
}
renderer.SetAttributesAndStyles(attributesAndStyles);
return renderer.RetrieveAlignAndMeet();
}
}
}

View File

@@ -0,0 +1,136 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using System;
using TSpdf.Svg.Renderers;
using TSpdf.Test;
using TSpdf.Test.Attributes;
namespace TSpdf.Svg.Renderers.Impl {
[NUnit.Framework.Category("IntegrationTest")]
public class RectangleSvgNodeRendererIntegrationTest : SvgIntegrationTest {
public static readonly String sourceFolder = TSpdf.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/TSpdf/svg/renderers/impl/RectangleSvgNodeRendererTest/";
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/TSpdf/svg/renderers/impl/RectangleSvgNodeRendererTest/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
TSpdfTest.CreateDestinationFolder(destinationFolder);
}
[NUnit.Framework.Test]
public virtual void BasicRectangleTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "basicRectangle");
}
[NUnit.Framework.Test]
public virtual void BasicRectangleRxRyZeroTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "basicRectangleRxRyZero");
}
[NUnit.Framework.Test]
public virtual void BasicCircularRoundedRectangleRyZeroTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "basicCircularRoundedRectangleRyZero");
}
[NUnit.Framework.Test]
public virtual void BasicCircularRoundedRectangleRxZeroTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "basicCircularRoundedRectangleRxZero");
}
[NUnit.Framework.Test]
public virtual void BasicCircularRoundedRxRectangleTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "basicCircularRoundedRxRectangle");
}
[NUnit.Framework.Test]
public virtual void BasicCircularRoundedRyRectangleTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "basicCircularRoundedRyRectangle");
}
[NUnit.Framework.Test]
public virtual void BasicEllipticalRoundedRectangleXTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "basicEllipticalRoundedRectangleX");
}
[NUnit.Framework.Test]
public virtual void BasicEllipticalRoundedRectangleYTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "basicEllipticalRoundedRectangleY");
}
[NUnit.Framework.Test]
public virtual void BasicEllipticalWidthCappedRoundedRectangleTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "basicEllipticalWidthCappedRoundedRectangle");
}
[NUnit.Framework.Test]
public virtual void BasicEllipticalHeightCappedRoundedRectangleTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "basicEllipticalHeightCappedRoundedRectangle");
}
[NUnit.Framework.Test]
public virtual void BasicEllipticalNegativeWidthRoundedRectangleTest() {
//TODO change cmp-file after DEVSIX-3121 fixed
ConvertAndCompare(sourceFolder, destinationFolder, "basicEllipticalNegativeWidthRoundedRectangle");
}
[NUnit.Framework.Test]
public virtual void BasicEllipticalNegativeHeightRoundedRectangleTest() {
//TODO change cmp-file after DEVSIX-3121 fixed
ConvertAndCompare(sourceFolder, destinationFolder, "basicEllipticalNegativeHeightRoundedRectangle");
}
[NUnit.Framework.Test]
public virtual void ComplexRectangleTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "complexRectangle");
}
[NUnit.Framework.Test]
[LogMessage(TSpdf.StyledXmlParser.Logs.StyledXmlParserLogMessageConstant.INVALID_CSS_PROPERTY_DECLARATION,
Count = 1)]
public virtual void NoFillRectangleTest() {
ConvertAndCompare(sourceFolder, destinationFolder, "noFillRectangle");
}
}
}

View File

@@ -0,0 +1,105 @@
/*
This file is part of the TSpdf (R) project.
Copyright (c) 1987-2023 TSpdf
Authors: TSpdf Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
TSpdf GROUP. TSpdf GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://TSpdfpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using TSpdf.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the TSpdf software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping TSpdf with a closed
source product.
For more information, please contact TSpdf Software Corp. at this
address: sales@TSpdfpdf.com
*/
using TSpdf.Test;
namespace TSpdf.Svg.Renderers.Impl {
[NUnit.Framework.Category("UnitTest")]
public class RectangleSvgNodeRendererUnitTest : ExtendedTSpdfTest {
private const float EPSILON = 0.00001f;
internal RectangleSvgNodeRenderer renderer;
[NUnit.Framework.SetUp]
public virtual void Setup() {
renderer = new RectangleSvgNodeRenderer();
}
[NUnit.Framework.Test]
public virtual void CheckRadiusTest() {
float rad = renderer.CheckRadius(0f, 20f);
NUnit.Framework.Assert.AreEqual(0f, rad, EPSILON);
}
[NUnit.Framework.Test]
public virtual void CheckRadiusNegativeTest() {
float rad = renderer.CheckRadius(-1f, 20f);
NUnit.Framework.Assert.AreEqual(0f, rad, EPSILON);
}
[NUnit.Framework.Test]
public virtual void CheckRadiusTooLargeTest() {
float rad = renderer.CheckRadius(30f, 20f);
NUnit.Framework.Assert.AreEqual(10f, rad, EPSILON);
}
[NUnit.Framework.Test]
public virtual void CheckRadiusTooLargeNegativeTest() {
float rad = renderer.CheckRadius(-100f, 20f);
NUnit.Framework.Assert.AreEqual(0f, rad, EPSILON);
}
[NUnit.Framework.Test]
public virtual void CheckRadiusHalfLengthTest() {
float rad = renderer.CheckRadius(10f, 20f);
NUnit.Framework.Assert.AreEqual(10f, rad, EPSILON);
}
[NUnit.Framework.Test]
public virtual void FindCircularRadiusTest() {
float rad = renderer.FindCircularRadius(0f, 20f, 100f, 200f);
NUnit.Framework.Assert.AreEqual(20f, rad, EPSILON);
}
[NUnit.Framework.Test]
public virtual void FindCircularRadiusHalfLengthTest() {
float rad = renderer.FindCircularRadius(0f, 200f, 100f, 200f);
NUnit.Framework.Assert.AreEqual(50f, rad, EPSILON);
}
[NUnit.Framework.Test]
public virtual void FindCircularRadiusSmallWidthTest() {
float rad = renderer.FindCircularRadius(0f, 20f, 5f, 200f);
NUnit.Framework.Assert.AreEqual(2.5f, rad, EPSILON);
}
}
}

Some files were not shown because too many files have changed in this diff Show More