Skip to content

Commit 110e63e

Browse files
committed
Use double type for better precision in local calculations in SVG and SXP
ITXT-CR-1425 Autoported commit. Original commit hash: [be68535a5] Failed to automatically remove sharp analogs of next files: styled-xml-parser/src/test/java/com/itextpdf/styledxmlparser/css/util/CssUtilTest.java
1 parent 5224483 commit 110e63e

File tree

127 files changed

+95
-24
lines changed

Some content is hidden

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

127 files changed

+95
-24
lines changed

itext.tests/itext.styledxmlparser.tests/itext/styledxmlparser/css/util/CssUtilTest.cs renamed to itext.tests/itext.styledxmlparser.tests/itext/styledxmlparser/css/util/CssUtilsTest.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ source product.
4848
using iText.Test.Attributes;
4949

5050
namespace iText.StyledXmlParser.Css.Util {
51-
public class CssUtilTest : ExtendedITextTest {
51+
public class CssUtilsTest : ExtendedITextTest {
5252
public static float EPS = 0.0001f;
5353

5454
[NUnit.Framework.Test]
@@ -244,5 +244,21 @@ public virtual void ParseInvalidFloat() {
244244
NUnit.Framework.Assert.Fail();
245245
}
246246
}
247+
248+
[NUnit.Framework.Test]
249+
public virtual void ParseAbsoluteLength12cmTest() {
250+
// Calculations in CssUtils#parseAbsoluteLength were changed to work
251+
// with double values instead of float to improve precision and eliminate
252+
// the difference between java and .net. So the test verifies this fix.
253+
NUnit.Framework.Assert.AreEqual(340.15747f, CssUtils.ParseAbsoluteLength("12cm"), 0f);
254+
}
255+
256+
[NUnit.Framework.Test]
257+
public virtual void ParseAbsoluteLength12qTest() {
258+
// Calculations in CssUtils#parseAbsoluteLength were changed to work
259+
// with double values instead of float to improve precision and eliminate
260+
// the difference between java and .net. So the test verifies this fix
261+
NUnit.Framework.Assert.AreEqual(8.503937f, CssUtils.ParseAbsoluteLength("12q"), 0f);
262+
}
247263
}
248264
}

itext.tests/itext.svg.tests/itext/svg/renderers/impl/EllipseNodeRendererIntegrationTest.cs renamed to itext.tests/itext.svg.tests/itext/svg/renderers/impl/EllipseSvgNodeRendererIntegrationTest.cs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,19 @@ source product.
4141
4242
*/
4343
using System;
44+
using iText.Kernel.Pdf;
45+
using iText.Kernel.Pdf.Canvas;
46+
using iText.Svg;
4447
using iText.Svg.Renderers;
4548
using iText.Test;
4649

4750
namespace iText.Svg.Renderers.Impl {
48-
public class EllipseNodeRendererIntegrationTest : SvgIntegrationTest {
51+
public class EllipseSvgNodeRendererIntegrationTest : SvgIntegrationTest {
4952
public static readonly String sourceFolder = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
50-
.CurrentContext.TestDirectory) + "/resources/itext/svg/renderers/impl/EllipseSvgNodeRendererTest/";
53+
.CurrentContext.TestDirectory) + "/resources/itext/svg/renderers/impl/EllipseSvgNodeRendererIntegrationTest/";
5154

5255
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
53-
+ "/test/itext/svg/renderers/impl/EllipseSvgNodeRendererTest/";
56+
+ "/test/itext/svg/renderers/impl/EllipseSvgNodeRendererIntegrationTest/";
5457

5558
[NUnit.Framework.OneTimeSetUp]
5659
public static void BeforeClass() {
@@ -143,5 +146,30 @@ public virtual void EllipseSkewXTest() {
143146
public virtual void EllipseSkewYTest() {
144147
ConvertAndCompare(sourceFolder, destinationFolder, "ellipseSkewY");
145148
}
149+
150+
[NUnit.Framework.Test]
151+
public virtual void ParseParametersAndCalculateCoordinatesWithBetterPrecisionEllipseTest() {
152+
String filename = "parseParametersAndCalculateCoordinatesWithBetterPrecisionEllipseTest.pdf";
153+
PdfDocument doc = new PdfDocument(new PdfWriter(destinationFolder + filename));
154+
doc.AddNewPage();
155+
EllipseSvgNodeRenderer ellipseRenderer = new EllipseSvgNodeRenderer();
156+
ellipseRenderer.SetAttribute(SvgConstants.Attributes.CX, "170.3");
157+
ellipseRenderer.SetAttribute(SvgConstants.Attributes.CY, "339.5");
158+
ellipseRenderer.SetAttribute(SvgConstants.Attributes.RX, "6");
159+
ellipseRenderer.SetAttribute(SvgConstants.Attributes.RY, "6");
160+
// Parse parameters with better precision (in double type) in the method CssUtils#parseAbsoluteLength
161+
ellipseRenderer.SetParameters();
162+
SvgDrawContext context = new SvgDrawContext(null, null);
163+
PdfCanvas cv = new PdfCanvas(doc, 1);
164+
context.PushCanvas(cv);
165+
// Calculate coordinates with better precision (in double type) in the method EllipseSvgNodeRenderer#doDraw
166+
ellipseRenderer.Draw(context);
167+
String pageContentBytes = iText.IO.Util.JavaUtil.GetStringForBytes(doc.GetPage(1).GetContentBytes(), System.Text.Encoding
168+
.UTF8);
169+
doc.Close();
170+
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"
171+
+ "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";
172+
NUnit.Framework.Assert.IsTrue(pageContentBytes.Contains(expectedResult));
173+
}
146174
}
147175
}

0 commit comments

Comments
 (0)