#490: Adobe Path PoC

This commit is contained in:
Harald Kuhr 2020-01-02 15:26:48 +01:00
parent 859b232f64
commit eec8268eb9
4 changed files with 25 additions and 14 deletions

View File

@ -10,16 +10,26 @@ import java.io.IOException;
* @deprecated Use {@link AdobePathReader} instead. This class will be removed in a future release. * @deprecated Use {@link AdobePathReader} instead. This class will be removed in a future release.
*/ */
public final class AdobePathBuilder { public final class AdobePathBuilder {
private final AdobePathReader delegate; private final AdobePathReader delegate;
public AdobePathBuilder(final byte[] data) { /**
this.delegate = new AdobePathReader(data); * @see AdobePathReader#AdobePathReader(DataInput)
} */
public AdobePathBuilder(final DataInput data) { public AdobePathBuilder(final DataInput data) {
this.delegate = new AdobePathReader(data); this.delegate = new AdobePathReader(data);
} }
/**
* @see AdobePathReader#AdobePathReader(byte[])
*/
public AdobePathBuilder(final byte[] data) {
this.delegate = new AdobePathReader(data);
}
/**
* @see AdobePathReader#path()
*/
public Path2D path() throws IOException { public Path2D path() throws IOException {
return delegate.path(); return delegate.path();
} }

View File

@ -57,8 +57,8 @@ public final class AdobePathReader {
private final DataInput data; private final DataInput data;
/** /**
* Creates a path builder that will read its data from a {@code DataInput}, such as an * Creates a path reader that will read its data from a {@code DataInput},
* {@code ImageInputStream}. * such as an {@code ImageInputStream}.
* The data length is assumed to be a multiple of 26. * The data length is assumed to be a multiple of 26.
* *
* @param data the input to read data from. * @param data the input to read data from.
@ -70,7 +70,7 @@ public final class AdobePathReader {
} }
/** /**
* Creates a path builder that will read its data from a {@code byte} array. * Creates a path reader that will read its data from a {@code byte} array.
* The array length must be a multiple of 26, and greater than 0. * The array length must be a multiple of 26, and greater than 0.
* *
* @param data the array to read data from. * @param data the array to read data from.
@ -84,14 +84,14 @@ public final class AdobePathReader {
} }
/** /**
* Builds the path. * Builds the path by reading from the supplied input.
* *
* @return the path * @return the path
* @throws javax.imageio.IIOException if the input contains a bad path data. * @throws javax.imageio.IIOException if the input contains a bad path data.
* @throws IOException if a general I/O exception occurs during reading. * @throws IOException if a general I/O exception occurs during reading.
*/ */
public Path2D path() throws IOException { public Path2D path() throws IOException {
List<List<AdobePathSegment>> subPaths = new ArrayList<List<AdobePathSegment>>(); List<List<AdobePathSegment>> subPaths = new ArrayList<>();
List<AdobePathSegment> currentPath = null; List<AdobePathSegment> currentPath = null;
int currentPathLength = 0; int currentPathLength = 0;
@ -110,7 +110,7 @@ public final class AdobePathReader {
subPaths.add(currentPath); subPaths.add(currentPath);
} }
currentPath = new ArrayList<AdobePathSegment>(segment.length); currentPath = new ArrayList<>(segment.length);
currentPathLength = segment.length; currentPathLength = segment.length;
} }
else if (segment.selector == AdobePathSegment.OPEN_SUBPATH_BEZIER_LINKED else if (segment.selector == AdobePathSegment.OPEN_SUBPATH_BEZIER_LINKED
@ -137,7 +137,7 @@ public final class AdobePathReader {
subPaths.add(currentPath); subPaths.add(currentPath);
} }
// now we have collected the PathPoints now create a Shape. // We have collected the Path points, now create a Shape
return pathToShape(subPaths); return pathToShape(subPaths);
} }
@ -199,6 +199,8 @@ public final class AdobePathReader {
break; break;
} }
default:
throw new AssertionError();
} }
} }
} }

View File

@ -86,7 +86,7 @@ final class AdobePathSegment {
} }
AdobePathSegment(int fillRuleSelector) { AdobePathSegment(int fillRuleSelector) {
this(isTrue(fillRuleSelector == PATH_FILL_RULE_RECORD, fillRuleSelector, "Expected fill rule record (6): %s"), this(isTrue(fillRuleSelector == PATH_FILL_RULE_RECORD || fillRuleSelector == INITIAL_FILL_RULE_RECORD, fillRuleSelector, "Expected fill rule record (6 or 8): %s"),
0, -1, -1, -1, -1, -1, -1); 0, -1, -1, -1, -1, -1, -1);
} }
@ -190,7 +190,6 @@ final class AdobePathSegment {
default: default:
// fall-through // fall-through
} }
return String.format("Pt(pre=(%.3f, %.3f), knot=(%.3f, %.3f), post=(%.3f, %.3f), selector=%s)", cppx, cppy, apx, apy, cplx, cply, SELECTOR_NAMES[selector]); return String.format("Pt(pre=(%.3f, %.3f), knot=(%.3f, %.3f), post=(%.3f, %.3f), selector=%s)", cppx, cppy, apx, apy, cplx, cply, SELECTOR_NAMES[selector]);
} }
} }

View File

@ -91,7 +91,7 @@ public final class AdobePathWriter {
if (initial.apx != prev.apx || initial.apy != prev.apy) { if (initial.apx != prev.apx || initial.apy != prev.apy) {
// TODO: Line back to initial if last anchor point does not equal initial anchor? // TODO: Line back to initial if last anchor point does not equal initial anchor?
// subpath.add(new AdobePathSegment(CLOSED_SUBPATH_BEZIER_LINKED, prev.cppy, prev.cppx, prev.apy, prev.apx, 0, 0)); // subpath.add(new AdobePathSegment(CLOSED_SUBPATH_BEZIER_LINKED, prev.cppy, prev.cppx, prev.apy, prev.apx, 0, 0));
System.err.println("FOO!"); throw new AssertionError("Not a closed path");
} }
subpath.set(0, new AdobePathSegment(CLOSED_SUBPATH_BEZIER_LINKED, prev.cppy, prev.cppx, initial.apy, initial.apx, initial.cply, initial.cplx)); subpath.set(0, new AdobePathSegment(CLOSED_SUBPATH_BEZIER_LINKED, prev.cppy, prev.cppx, initial.apy, initial.apx, initial.cply, initial.cplx));