@@ -42,7 +42,6 @@ This file is part of the iText (R) project.
42
42
*/
43
43
package com .itextpdf .svg .renderers .impl ;
44
44
45
-
46
45
import com .itextpdf .io .util .MessageFormatUtil ;
47
46
import com .itextpdf .kernel .geom .Point ;
48
47
import com .itextpdf .kernel .pdf .canvas .PdfCanvas ;
@@ -89,15 +88,15 @@ public class PathSvgNodeRenderer extends AbstractSvgNodeRenderer {
89
88
* Find any occurence of a letter that is not an operator
90
89
*/
91
90
private static final String INVALID_OPERATOR_REGEX = "(?:(?![mzlhvcsqtae])\\ p{L})" ;
92
- private static Pattern invalidRegexPattern = Pattern .compile (INVALID_OPERATOR_REGEX , Pattern .CASE_INSENSITIVE );;
91
+ private static Pattern invalidRegexPattern = Pattern .compile (INVALID_OPERATOR_REGEX , Pattern .CASE_INSENSITIVE );
93
92
94
93
/**
95
94
* The regular expression to split the <a href="https://www.w3.org/TR/SVG/paths.html#PathData">PathData attribute of the <path> element</a>
96
95
* <p>
97
96
* Since {@link PathSvgNodeRenderer#containsInvalidAttributes(String)} is called before the use of this expression in {@link PathSvgNodeRenderer#parsePropertiesAndStyles()} the attribute to be split is valid.
98
97
* The regex splits at each letter.
99
98
*/
100
- private final String SPLIT_REGEX = "(?=[\\ p{L}])" ;
99
+ private static final String SPLIT_REGEX = "(?=[\\ p{L}])" ;
101
100
102
101
103
102
/**
@@ -116,7 +115,7 @@ public class PathSvgNodeRenderer extends AbstractSvgNodeRenderer {
116
115
public void doDraw (SvgDrawContext context ) {
117
116
PdfCanvas canvas = context .getCurrentCanvas ();
118
117
canvas .writeLiteral ("% path\n " );
119
- currentPoint = new Point (0 ,0 );
118
+ currentPoint = new Point (0 , 0 );
120
119
for (IPathShape item : getShapes ()) {
121
120
item .draw (canvas );
122
121
}
@@ -168,7 +167,7 @@ private String[] getShapeCoordinates(IPathShape shape, IPathShape previousShape,
168
167
} else if (shape instanceof VerticalLineTo ) {
169
168
String currentX = String .valueOf (currentPoint .x );
170
169
String currentY = String .valueOf (currentPoint .y );
171
- String [] yValues = concatenate (new String [] { currentY }, shape .isRelative () ? makeRelativeOperatorsAbsolute (operatorArgs , currentPoint .y ) : operatorArgs );
170
+ String [] yValues = concatenate (new String []{ currentY }, shape .isRelative () ? makeRelativeOperatorsAbsolute (operatorArgs , currentPoint .y ) : operatorArgs );
172
171
shapeCoordinates = concatenate (new String []{currentX }, yValues );
173
172
174
173
} else if (shape instanceof HorizontalLineTo ) {
@@ -237,7 +236,7 @@ private List<IPathShape> processPathOperator(String[] pathProperties, IPathShape
237
236
}
238
237
239
238
/**
240
- * Processes the {@link SvgConstants.Attributes. D} {@link PathSvgNodeRenderer#attributesAndStyles} and converts them
239
+ * Processes the {@link SvgConstants.Attributes# D} {@link PathSvgNodeRenderer#attributesAndStyles} and converts them
241
240
* into one or more {@link IPathShape} objects to be drawn on the canvas.
242
241
* <p>
243
242
* Each individual operator is passed to {@link PathSvgNodeRenderer#processPathOperator(String[], IPathShape)} to be processed individually.
@@ -264,6 +263,7 @@ private static String[] concatenate(String[] first, String[] second) {
264
263
return arr ;
265
264
}
266
265
266
+
267
267
boolean containsInvalidAttributes (String attributes ) {
268
268
return SvgRegexUtils .containsAtLeastOneMatch (invalidRegexPattern ,attributes );
269
269
}
@@ -289,43 +289,37 @@ private Collection<String> parsePropertiesAndStyles() {
289
289
}
290
290
291
291
String [] resultArray = result .toString ().split (SPLIT_REGEX );
292
- List <String > resultList = new ArrayList <>(Arrays .asList (resultArray ));
293
-
294
- return resultList ;
292
+ return new ArrayList <>(Arrays .asList (resultArray ));
295
293
}
296
294
297
295
/**
298
296
* Iterate over the input string and to seperate
299
- * @param input
300
- * @return
301
297
*/
302
- String separateDecimalPoints (String input ){
298
+ String separateDecimalPoints (String input ) {
303
299
//If a space or minus sign is found reset
304
300
//If a another point is found, add an extra space on before the point
305
- String res = "" ;
301
+ StringBuilder res = new StringBuilder () ;
306
302
//Iterate over string
307
303
boolean decimalPointEncountered = false ;
308
304
for (int i = 0 ; i < input .length (); i ++) {
309
305
char c = input .charAt (i );
310
- //If it's a whitespace or minus sign and a point was previously found, reset
311
- if (decimalPointEncountered && (c == '-' || Character .isWhitespace (c ))){
306
+ //If it's a whitespace or a minus sign and a point was previously found, reset the decimal point flag
307
+ if (decimalPointEncountered && (c == '-' || Character .isWhitespace (c ))) {
312
308
decimalPointEncountered = false ;
313
309
}
314
310
//If a point is found, mark and continue
315
- if (c =='.' ){
316
- //If it's the second point, add extra space
317
- if (decimalPointEncountered ){
318
- res += " " ;
319
- }else {
320
- decimalPointEncountered = true ;
311
+ if (c == '.' ) {
312
+ //If it's the second point, add an extra space
313
+ if (decimalPointEncountered ) {
314
+ res . append ( " " ) ;
315
+ } else {
316
+ decimalPointEncountered = true ;
321
317
}
318
+ } else if (c == '-' ) {// If a minus is found, add an extra space
319
+ res .append (" " );
322
320
}
323
- res += c ;
321
+ res . append ( c ) ;
324
322
}
325
-
326
-
327
- return res ;
323
+ return res .toString ();
328
324
}
329
-
330
-
331
325
}
0 commit comments