Skip to content

Commit

Permalink
SVG: Support (x y)+ parameters in MoveTo path operator
Browse files Browse the repository at this point in the history
DEVSIX-2479
  • Loading branch information
Snipx authored and iText-CI committed Feb 6, 2019
1 parent d19d287 commit beb64ed
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 5 deletions.
15 changes: 10 additions & 5 deletions svg/src/main/java/com/itextpdf/svg/renderers/path/impl/MoveTo.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ This file is part of the iText (R) project.
public class MoveTo extends AbstractPathShape {

private String[] coordinates;
private LineTo additionalLines;

public MoveTo() {
this(false);
Expand All @@ -71,23 +72,27 @@ public void draw(PdfCanvas canvas) {
float x = CssUtils.parseAbsoluteLength(coordinates[0]);
float y = CssUtils.parseAbsoluteLength(coordinates[1]);
canvas.moveTo(x, y);
if (additionalLines != null) {
additionalLines.draw(canvas);
}
}

@Override
public void setCoordinates(String[] coordinates, Point startPoint) {
if (coordinates.length == 0 || coordinates.length % 2 != 0) {
throw new IllegalArgumentException(MessageFormatUtil.format(SvgExceptionMessageConstant.MOVE_TO_EXPECTS_FOLLOWING_PARAMETERS_GOT_0, Arrays.toString(coordinates)));
}
if (coordinates.length > 2) {
// (x y)+ parameters will be implemented in the future
throw new UnsupportedOperationException();
}

this.coordinates = new String[] {coordinates[0], coordinates[1]};

if (isRelative()) {
this.coordinates = SvgCoordinateUtils.makeRelativeOperatorCoordinatesAbsolute(coordinates, new double[]{startPoint.x, startPoint.y});
}

// If a moveto is followed by multiple pairs of coordinates, the subsequent pairs are treated as implicit lineto commands
if (coordinates.length > 2) {
additionalLines = new LineTo(isRelative());
additionalLines.setCoordinates(Arrays.copyOfRange(coordinates, 2, coordinates.length), getEndingPoint());
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,16 @@ public void multipleRelativeVerticalLineToTest() throws IOException, Interrupted
convertAndCompareVisually(sourceFolder, destinationFolder, "multipleRelativeVerticalLineTo");
}

@Test
public void moveToRelativeMultipleTest() throws IOException, InterruptedException {
convertAndCompareVisually(sourceFolder, destinationFolder, "moveToRelativeMultiple");
}

@Test
public void moveToAbsoluteMultipleTest() throws IOException, InterruptedException {
convertAndCompareVisually(sourceFolder, destinationFolder, "moveToAbsoluteMultiple");
}

@Test
public void iTextLogoTest() throws IOException, InterruptedException {
convertAndCompareVisually(sourceFolder, destinationFolder, "iTextLogo");
Expand Down
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit beb64ed

Please sign in to comment.