Skip to content

Commit 610b582

Browse files
ars18wrwiText-CI
authored andcommitted
Update the path-processing algo.
Optimize the algo: use a StringBuilder instance instead of a string. Process minuses correctly. DEVSIX-2043, DEVSIX-2044 Autoported commit. Original commit hash: [0b9c18600]
1 parent 6727ebf commit 610b582

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

itext/itext.svg/itext/svg/renderers/impl/PathSvgNodeRenderer.cs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public class PathSvgNodeRenderer : AbstractSvgNodeRenderer {
9090
/// the attribute to be split is valid.
9191
/// The regex splits at each letter.
9292
/// </summary>
93-
private readonly String SPLIT_REGEX = "(?=[\\p{L}])";
93+
private const String SPLIT_REGEX = "(?=[\\p{L}])";
9494

9595
/// <summary>
9696
/// The
@@ -276,7 +276,7 @@ private IList<IPathShape> ProcessPathOperator(String[] pathProperties, IPathShap
276276

277277
/// <summary>
278278
/// Processes the
279-
/// <see cref="SvgConstants.Attributes.D"/>
279+
/// <see cref="iText.Svg.SvgConstants.Attributes.D"/>
280280
///
281281
/// <see cref="AbstractSvgNodeRenderer.attributesAndStyles"/>
282282
/// and converts them
@@ -340,38 +340,41 @@ private ICollection<String> ParsePropertiesAndStyles() {
340340
}
341341
}
342342
String[] resultArray = iText.IO.Util.StringUtil.Split(result.ToString(), SPLIT_REGEX);
343-
IList<String> resultList = new List<String>(JavaUtil.ArraysAsList(resultArray));
344-
return resultList;
343+
return new List<String>(JavaUtil.ArraysAsList(resultArray));
345344
}
346345

347346
/// <summary>Iterate over the input string and to seperate</summary>
348-
/// <param name="input"/>
349-
/// <returns/>
350347
internal virtual String SeparateDecimalPoints(String input) {
351348
//If a space or minus sign is found reset
352349
//If a another point is found, add an extra space on before the point
353-
String res = "";
350+
StringBuilder res = new StringBuilder();
354351
//Iterate over string
355352
bool decimalPointEncountered = false;
356353
for (int i = 0; i < input.Length; i++) {
357354
char c = input[i];
358-
//If it's a whitespace or minus sign and a point was previously found, reset
355+
//If it's a whitespace or a minus sign and a point was previously found, reset the decimal point flag
359356
if (decimalPointEncountered && (c == '-' || iText.IO.Util.TextUtil.IsWhiteSpace(c))) {
360357
decimalPointEncountered = false;
361358
}
362359
//If a point is found, mark and continue
363360
if (c == '.') {
364-
//If it's the second point, add extra space
361+
//If it's the second point, add an extra space
365362
if (decimalPointEncountered) {
366-
res += " ";
363+
res.Append(" ");
367364
}
368365
else {
369366
decimalPointEncountered = true;
370367
}
371368
}
372-
res += c;
369+
else {
370+
if (c == '-') {
371+
// If a minus is found, add an extra space
372+
res.Append(" ");
373+
}
374+
}
375+
res.Append(c);
373376
}
374-
return res;
377+
return res.ToString();
375378
}
376379
}
377380
}

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
022fa281e293615213a453da5ca829f4b984dcd3
1+
0b9c18600f3ca4538b045a49e452c26c4b6f95d7

0 commit comments

Comments
 (0)