Skip to content

Commit cfa7d3e

Browse files
ar3emBezrukovM
authored andcommitted
Add calculating path and text bounding box in SVG
DEVSIX-4018 Autoported commit. Original commit hash: [91d4fb8fc] Manual files: svg/src/main/java/com/itextpdf/svg/utils/SvgCssUtils.java
1 parent 7be5256 commit cfa7d3e

File tree

119 files changed

+1765
-183
lines changed

Some content is hidden

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

119 files changed

+1765
-183
lines changed

itext.tests/itext.svg.tests/itext/svg/googlecharts/GoogleChartsTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public virtual void BubbleChart() {
9090

9191
[NUnit.Framework.Test]
9292
public virtual void CalendarChart() {
93-
//TODO update cmp file after DEVSIX-3347, DEVSIX-4018 will be fixed
93+
//TODO update cmp file after DEVSIX-3347 will be fixed
9494
PageSize pageSize = PageSize.A4;
9595
TestUtils.ConvertSVGtoPDF(destinationFolder + "calendarChart.pdf", sourceFolder + "calendarChart.svg", 1,
9696
pageSize);

itext.tests/itext.svg.tests/itext/svg/renderers/impl/LinearGradientSvgNodeRendererTest.cs

Lines changed: 169 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ You should have received a copy of the GNU Affero General Public License
2121
along with this program. If not, see <https://www.gnu.org/licenses/>.
2222
*/
2323
using System;
24+
using iText.Kernel.Geom;
2425
using iText.Svg.Exceptions;
2526
using iText.Svg.Renderers;
2627
using iText.Test;
@@ -56,114 +57,182 @@ public virtual void LineTest() {
5657
ConvertAndCompare(sourceFolder, destinationFolder, "line");
5758
}
5859

59-
// TODO: DEVSIX-4018 add tests for all other types of path components
60-
// TODO: DEVSIX-4018 update cmp_ after fix (box for path is not implemented)
6160
[NUnit.Framework.Test]
6261
public virtual void PathLinesBasedTest() {
6362
ConvertAndCompare(sourceFolder, destinationFolder, "pathLinesBased");
6463
}
6564

66-
// TODO: DEVSIX-4018 update cmp_ after fix (box for path is not implemented)
65+
[NUnit.Framework.Test]
66+
public virtual void PathLinesBasedTransformedTest() {
67+
ConvertAndCompare(sourceFolder, destinationFolder, "pathLinesBasedTransformed");
68+
}
69+
6770
[NUnit.Framework.Test]
6871
public virtual void PathLinesBasedWithMoveTest() {
6972
ConvertAndCompare(sourceFolder, destinationFolder, "pathLinesBasedWithMove");
7073
}
7174

72-
// TODO: DEVSIX-4018 update cmp_ after fix (box for path is not implemented)
7375
[NUnit.Framework.Test]
7476
public virtual void PathLinesBasedWithTwoFiguresTest() {
7577
ConvertAndCompare(sourceFolder, destinationFolder, "pathLinesBasedWithTwoFigures");
7678
}
7779

7880
[NUnit.Framework.Test]
7981
public virtual void CubicBezierTest() {
80-
// TODO: update cmp-file after DEVSIX-4018 will be fixed
8182
ConvertAndCompare(sourceFolder, destinationFolder, "cubicBezier");
8283
}
8384

85+
[NUnit.Framework.Test]
86+
public virtual void CubicBezier2Test() {
87+
ConvertAndCompare(sourceFolder, destinationFolder, "cubicBezier2");
88+
}
89+
90+
[NUnit.Framework.Test]
91+
public virtual void CubicBezier3Test() {
92+
ConvertAndCompare(sourceFolder, destinationFolder, "cubicBezier3");
93+
}
94+
95+
[NUnit.Framework.Test]
96+
public virtual void CubicBezier4Test() {
97+
ConvertAndCompare(sourceFolder, destinationFolder, "cubicBezier4");
98+
}
99+
100+
[NUnit.Framework.Test]
101+
public virtual void CubicBezierZeroDiscriminantTest() {
102+
// See CurveTo#calculateTValues to see which discriminant is mentioned.
103+
ConvertAndCompare(sourceFolder, destinationFolder, "cubicBezierZeroDiscriminant");
104+
}
105+
106+
[NUnit.Framework.Test]
107+
public virtual void CubicBezierNegativeDiscriminantTest() {
108+
// See CurveTo#calculateTValues to see which discriminant is mentioned.
109+
ConvertAndCompare(sourceFolder, destinationFolder, "cubicBezierNegativeDiscriminant");
110+
}
111+
84112
[NUnit.Framework.Test]
85113
public virtual void CubicBezierInsideOtherCubicBezierTest() {
86-
// TODO: update cmp-file after DEVSIX-4018 will be fixed
87114
ConvertAndCompare(sourceFolder, destinationFolder, "cubicBezierInsideOtherCubicBezier");
88115
}
89116

90117
[NUnit.Framework.Test]
91118
public virtual void SmoothCubicBezierWithAbsoluteCoordinatesTest() {
92-
// TODO: update cmp-file after DEVSIX-4018 will be fixed
93119
ConvertAndCompare(sourceFolder, destinationFolder, "smoothCubicBezierWithAbsoluteCoordinates");
94120
}
95121

96122
[NUnit.Framework.Test]
97123
public virtual void SmoothCubicBezierWithRelativeCoordinatesTest() {
98-
// TODO: update cmp-file after DEVSIX-4018 will be fixed
99124
ConvertAndCompare(sourceFolder, destinationFolder, "smoothCubicBezierWithRelativeCoordinates");
100125
}
101126

102127
[NUnit.Framework.Test]
103128
public virtual void SmoothCubicBezierRelativeAndAbsoluteCoordWithMoveTest() {
104-
// TODO: update cmp-file after DEVSIX-4018 will be fixed
105129
ConvertAndCompare(sourceFolder, destinationFolder, "smoothCubicBezierRelativeAndAbsoluteCoordWithMove");
106130
}
107131

108132
[NUnit.Framework.Test]
109133
public virtual void SmoothCubicBezierRelativeAndAbsoluteCoordNoZOperatorTest() {
110-
// TODO: update cmp-file after DEVSIX-4018 will be fixed
111134
ConvertAndCompare(sourceFolder, destinationFolder, "smoothCubicBezierRelativeAndAbsoluteCoordNoZOperator");
112135
}
113136

114137
[NUnit.Framework.Test]
115138
public virtual void QuadraticBezierTest() {
116-
// TODO: update cmp-file after DEVSIX-4018 will be fixed
117139
ConvertAndCompare(sourceFolder, destinationFolder, "quadraticBezier");
118140
}
119141

142+
[NUnit.Framework.Test]
143+
public virtual void QuadraticBezier2Test() {
144+
ConvertAndCompare(sourceFolder, destinationFolder, "quadraticBezier2");
145+
}
146+
147+
[NUnit.Framework.Test]
148+
public virtual void QuadraticBezier3Test() {
149+
ConvertAndCompare(sourceFolder, destinationFolder, "quadraticBezier3");
150+
}
151+
120152
[NUnit.Framework.Test]
121153
public virtual void QuadraticBezierInsideOtherQuadraticBezierTest() {
122-
// TODO: update cmp-file after DEVSIX-4018 will be fixed
123154
ConvertAndCompare(sourceFolder, destinationFolder, "quadraticBezierInsideOtherQuadraticBezier");
124155
}
125156

126157
[NUnit.Framework.Test]
127158
public virtual void SmoothQuadraticBezierWithAbsoluteCoordinatesTest() {
128-
// TODO: update cmp-file after DEVSIX-4018 will be fixed
129159
ConvertAndCompare(sourceFolder, destinationFolder, "smoothQuadraticBezierWithAbsoluteCoordinates");
130160
}
131161

132162
[NUnit.Framework.Test]
133163
public virtual void SmoothQuadraticBezierWithRelativeCoordinatesTest() {
134-
// TODO: update cmp-file after DEVSIX-4018 will be fixed
135164
ConvertAndCompare(sourceFolder, destinationFolder, "smoothQuadraticBezierWithRelativeCoordinates");
136165
}
137166

138167
[NUnit.Framework.Test]
139168
public virtual void SmoothQuadraticBezierAbsoluteAndRelativeCoordWithMoveTest() {
140-
// TODO: update cmp-file after DEVSIX-4018 will be fixed
141169
ConvertAndCompare(sourceFolder, destinationFolder, "smoothQuadraticBezierAbsoluteAndRelativeCoordWithMove"
142170
);
143171
}
144172

145173
[NUnit.Framework.Test]
146174
public virtual void SmoothQuadraticBezierRelativeAndAbsoluteCoordNoZOperatorTest() {
147-
// TODO: update cmp-file after DEVSIX-4018 will be fixed
148175
ConvertAndCompare(sourceFolder, destinationFolder, "smoothQuadraticBezierRelativeAndAbsoluteCoordNoZOperator"
149176
);
150177
}
151178

152179
[NUnit.Framework.Test]
153180
public virtual void EllipticalArcsTest() {
154-
// TODO: update cmp-file after DEVSIX-4018 will be fixed
155181
ConvertAndCompare(sourceFolder, destinationFolder, "ellipticalArcs");
156182
}
157183

184+
[NUnit.Framework.Test]
185+
public virtual void EllipticalArcsNegativeRxRyTest() {
186+
ConvertAndCompare(sourceFolder, destinationFolder, "ellipticalArcsNegativeRxRy");
187+
}
188+
189+
[NUnit.Framework.Test]
190+
public virtual void EllipticalArcZeroRxRyTest() {
191+
ConvertAndCompare(sourceFolder, destinationFolder, "ellipticalArcZeroRxRy");
192+
}
193+
194+
[NUnit.Framework.Test]
195+
public virtual void EllipticalArcsWithPhiTest() {
196+
ConvertAndCompare(sourceFolder, destinationFolder, "ellipticalArcsWithPhi", PageSize.A3.Rotate());
197+
}
198+
199+
[NUnit.Framework.Test]
200+
public virtual void EllipticalArcsWithPhi0Test() {
201+
ConvertAndCompare(sourceFolder, destinationFolder, "ellipticalArcsWithPhi0");
202+
}
203+
204+
[NUnit.Framework.Test]
205+
public virtual void EllipticalArcsWithPhi90Test() {
206+
ConvertAndCompare(sourceFolder, destinationFolder, "ellipticalArcsWithPhi90");
207+
}
208+
209+
[NUnit.Framework.Test]
210+
public virtual void EllipticalArcsWithPhi180Test() {
211+
ConvertAndCompare(sourceFolder, destinationFolder, "ellipticalArcsWithPhi180");
212+
}
213+
214+
[NUnit.Framework.Test]
215+
public virtual void EllipticalArcsWithPhi270Test() {
216+
ConvertAndCompare(sourceFolder, destinationFolder, "ellipticalArcsWithPhi270");
217+
}
218+
219+
[NUnit.Framework.Test]
220+
public virtual void EllipticalArcsWithPhiRelativeTest() {
221+
ConvertAndCompare(sourceFolder, destinationFolder, "ellipticalArcsWithPhiRelative");
222+
}
223+
224+
[NUnit.Framework.Test]
225+
public virtual void EllipticalArcsWithPhiAbsoluteTest() {
226+
ConvertAndCompare(sourceFolder, destinationFolder, "ellipticalArcsWithPhiAbsolute");
227+
}
228+
158229
[NUnit.Framework.Test]
159230
public virtual void EllipticalArcsRelativeCoordinatesTest() {
160-
// TODO: update cmp-file after DEVSIX-4018 will be fixed
161231
ConvertAndCompare(sourceFolder, destinationFolder, "ellipticalArcsRelativeCoordinates");
162232
}
163233

164234
[NUnit.Framework.Test]
165235
public virtual void ArcInsideOtherEllipticalArcTest() {
166-
// TODO: update cmp-file after DEVSIX-4018 will be fixed
167236
ConvertAndCompare(sourceFolder, destinationFolder, "arcInsideOtherEllipticalArc");
168237
}
169238

@@ -246,13 +315,90 @@ public virtual void RectWithMultipleTransformsTest() {
246315
ConvertAndCompare(sourceFolder, destinationFolder, "rectWithMultipleTransforms");
247316
}
248317

249-
// TODO: DEVSIX-4018 update cmp_ after fix (box for text is not implemented)
250318
[NUnit.Framework.Test]
251319
[LogMessage(iText.StyledXmlParser.LogMessageConstant.UNKNOWN_ABSOLUTE_METRIC_LENGTH_PARSED)]
252320
public virtual void TextTest() {
321+
// TODO DEVSIX-4140 remove log message check and update cmp
253322
ConvertAndCompare(sourceFolder, destinationFolder, "text");
254323
}
255324

325+
[NUnit.Framework.Test]
326+
public virtual void TextNestedTSpansTest() {
327+
ConvertAndCompare(sourceFolder, destinationFolder, "textNestedTSpansTest");
328+
}
329+
330+
[NUnit.Framework.Test]
331+
[LogMessage(iText.StyledXmlParser.LogMessageConstant.UNKNOWN_ABSOLUTE_METRIC_LENGTH_PARSED)]
332+
public virtual void TextRotatedTest() {
333+
ConvertAndCompare(sourceFolder, destinationFolder, "textRotatedTest");
334+
}
335+
336+
[NUnit.Framework.Test]
337+
public virtual void TextDxTest() {
338+
ConvertAndCompare(sourceFolder, destinationFolder, "textDxTest");
339+
}
340+
341+
[NUnit.Framework.Test]
342+
public virtual void TextDyTest() {
343+
ConvertAndCompare(sourceFolder, destinationFolder, "textDyTest");
344+
}
345+
346+
[NUnit.Framework.Test]
347+
public virtual void TextXYOffset() {
348+
ConvertAndCompare(sourceFolder, destinationFolder, "textXYOffset");
349+
}
350+
351+
[NUnit.Framework.Test]
352+
public virtual void TextXOffset() {
353+
// TODO DEVSIX-4143 change cmp file after fixing
354+
ConvertAndCompare(sourceFolder, destinationFolder, "textXOffset");
355+
}
356+
357+
[NUnit.Framework.Test]
358+
public virtual void TextXYDxDyOffset() {
359+
ConvertAndCompare(sourceFolder, destinationFolder, "textXYDxDyOffset");
360+
}
361+
362+
[NUnit.Framework.Test]
363+
public virtual void TextGradientEmUnits() {
364+
ConvertAndCompare(sourceFolder, destinationFolder, "textGradientEmUnits");
365+
}
366+
367+
[NUnit.Framework.Test]
368+
// TODO DEVSIX-4140 update cmp file
369+
[LogMessage(iText.StyledXmlParser.LogMessageConstant.UNKNOWN_ABSOLUTE_METRIC_LENGTH_PARSED)]
370+
public virtual void TextGradientEmUnitsRelated() {
371+
ConvertAndCompare(sourceFolder, destinationFolder, "textGradientEmUnitsRelated");
372+
}
373+
374+
[NUnit.Framework.Test]
375+
// TODO DEVSIX-4140 update cmp file
376+
[LogMessage(iText.StyledXmlParser.LogMessageConstant.UNKNOWN_ABSOLUTE_METRIC_LENGTH_PARSED)]
377+
public virtual void TextGradientEmUnitsRelatedNotDefs() {
378+
ConvertAndCompare(sourceFolder, destinationFolder, "textGradientEmUnitsRelatedNotDefs");
379+
}
380+
381+
[NUnit.Framework.Test]
382+
public virtual void TextGradientEmUnitsRelatedDefault() {
383+
// TODO DEVSIX-4140 update cmp file
384+
ConvertAndCompare(sourceFolder, destinationFolder, "textGradientEmUnitsRelatedDefault");
385+
}
386+
387+
[NUnit.Framework.Test]
388+
public virtual void TextGradientExUnits() {
389+
ConvertAndCompare(sourceFolder, destinationFolder, "textGradientExUnits");
390+
}
391+
392+
[NUnit.Framework.Test]
393+
public virtual void TextGradientRemUnits() {
394+
ConvertAndCompare(sourceFolder, destinationFolder, "textGradientRemUnits");
395+
}
396+
397+
[NUnit.Framework.Test]
398+
public virtual void TextGradientRemUnitsNestedSvg() {
399+
ConvertAndCompare(sourceFolder, destinationFolder, "textGradientRemUnitsNestedSvg");
400+
}
401+
256402
[NUnit.Framework.Test]
257403
public virtual void RectMultipleStopsWithSameOffsetAndZeroCoordLengthPadTest() {
258404
ConvertAndCompare(sourceFolder, destinationFolder, "rectMultipleStopsWithSameOffsetAndZeroCoordLengthPad");
@@ -320,6 +466,7 @@ public virtual void UserSpaceOnUseWithChUnitTest() {
320466

321467
[NUnit.Framework.Test]
322468
public virtual void UserSpaceOnUseWithUnitsRelativeToFontTest() {
469+
// TODO DEVSIX-4140 update after fix
323470
ConvertAndCompare(sourceFolder, destinationFolder, "userSpaceOnUseWithUnitsRelativeToFont");
324471
}
325472

@@ -331,7 +478,7 @@ public virtual void UserSpaceOnUseWithUnitsRelativeToViewportTest() {
331478

332479
[NUnit.Framework.Test]
333480
public virtual void UserSpaceOnUseDiffRelativeUnitsInGradientTest() {
334-
// TODO: DEVSIX-3596 update cmp_ after fix ("ch" "vmin"+"vmax"+"vw"+"vh" not implemented yet)
481+
// TODO: DEVSIX-4140, DEVSIX-3596 update cmp_ after fix ("ch" "vmin"+"vmax"+"vw"+"vh" not implemented yet)
335482
ConvertAndCompare(sourceFolder, destinationFolder, "userSpaceOnUseDiffRelativeUnitsInGradient");
336483
}
337484

@@ -385,6 +532,7 @@ public virtual void TranslateTransformInGradientWithObjectBoundingBoxUnitsTest()
385532

386533
[NUnit.Framework.Test]
387534
public virtual void MatrixTransformInGradientWithObjectBoundingBoxUnitsTest() {
535+
//TODO change cmp after DEVSIX-4143 is fixed (bug with only one absolute coordinate in tspan)
388536
ConvertAndCompare(sourceFolder, destinationFolder, "matrixTransformInGradientWithObjectBoundingBoxUnits");
389537
}
390538

itext.tests/itext.svg.tests/itext/svg/renderers/impl/MarkerSvgNodeRendererIntegrationTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ public virtual void MarkerUnitsTest() {
163163

164164
[NUnit.Framework.Test]
165165
public virtual void MarkerRefXYTest() {
166+
// TODO DEVSIX-4140 update cmp
166167
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "markerRefXYTest");
167168
}
168169

@@ -188,7 +189,7 @@ public virtual void OrientAutoPolygonInDifferentPositionTest() {
188189
}
189190

190191
[NUnit.Framework.Test]
191-
// TODO: update when DEVSIX-3432 will be fixed
192+
// TODO: update when DEVSIX-3432 and DEVSIX-4140 will be fixed
192193
[LogMessage(iText.StyledXmlParser.LogMessageConstant.UNKNOWN_ABSOLUTE_METRIC_LENGTH_PARSED, Count = 3)]
193194
public virtual void TestMarkerUnitsStrokeWidthWhenParentStrokeWidthIsFontRelativeValues() {
194195
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "testMarkerUnitsStrokeWidthWhenParentStrokeWidthIsFontRelativeValues"
@@ -237,13 +238,12 @@ public virtual void MarkerInheritFillAttributeNestedMarker() {
237238

238239
[NUnit.Framework.Test]
239240
public virtual void FontRelativeValueInRefX() {
240-
// This file is rendered differently in different browsers.
241-
// Look at MarkerSvgNOdeRenderer#parseFontRelativeOrAbsoluteLengthOnMarker to see the processing of font-relative unit .
242241
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "fontRelativeValueInRefX");
243242
}
244243

245244
[NUnit.Framework.Test]
246245
public virtual void FontRelativeValueInRefXDefault() {
246+
// TODO DEVSIX-4140 update cmp
247247
ConvertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "fontRelativeValueInRefXDefault");
248248
}
249249

0 commit comments

Comments
 (0)