Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,42 +68,58 @@ public void handleElement(BridgeContext ctx, Element e) {
* @return The new TextPath.
*/
public TextPath createTextPath(BridgeContext ctx, Element textPathElement) {
Element pathElement;
// Check whether the textPath has a 'path' attribute
String path = textPathElement.getAttributeNS(null, SVG_PATH_ATTRIBUTE).trim();

if (path.isEmpty()) {
// get the referenced element
String uri = XLinkSupport.getXLinkHref(textPathElement);
pathElement = ctx.getReferencedElement(textPathElement, uri);

if (pathElement == null || !SVG_NAMESPACE_URI.equals(pathElement.getNamespaceURI())
|| !pathElement.getLocalName().equals(SVG_PATH_TAG)) {
// couldn't find the referenced element
// or the referenced element was not a path
throw new BridgeException(ctx, textPathElement, ERR_URI_BAD_TARGET,
new Object[] { uri });
}

// get the referenced element
String uri = XLinkSupport.getXLinkHref(textPathElement);
Element pathElement = ctx.getReferencedElement(textPathElement, uri);

if ((pathElement == null) || (!SVG_NAMESPACE_URI.equals(pathElement.getNamespaceURI()))
|| (!pathElement.getLocalName().equals(SVG_PATH_TAG))) {
// couldn't find the referenced element
// or the referenced element was not a path
throw new BridgeException(ctx, textPathElement, ERR_URI_BAD_TARGET, new Object[] { uri });
// construct a shape for the referenced path element
path = pathElement.getAttributeNS(null, SVG_D_ATTRIBUTE);
if (path.isEmpty()) {
throw new BridgeException(ctx, pathElement, ERR_ATTRIBUTE_MISSING,
new Object[] { SVG_D_ATTRIBUTE });
}
} else {
pathElement = textPathElement;
}

// construct a shape for the referenced path element
String s = pathElement.getAttributeNS(null, SVG_D_ATTRIBUTE);
Shape pathShape = null;
if (s.length() != 0) {
AWTPathProducer app = new AWTPathProducer();
app.setWindingRule(CSSUtilities.convertFillRule(pathElement));
try {
PathParser pathParser = new PathParser(app);
pathParser.parse(s);
} catch (ParseException pEx) {
throw new BridgeException(ctx, pathElement, pEx, ERR_ATTRIBUTE_VALUE_MALFORMED,
new Object[] { SVG_D_ATTRIBUTE });
} finally {
pathShape = app.getShape();
AWTPathProducer app = new AWTPathProducer();
app.setWindingRule(CSSUtilities.convertFillRule(pathElement));
try {
PathParser pathParser = new PathParser(app);
pathParser.parse(path);
} catch (ParseException pEx) {
final String attrName;
if (pathElement != textPathElement) {
attrName = SVG_D_ATTRIBUTE;
} else {
attrName = SVG_PATH_ATTRIBUTE;
}
} else {
throw new BridgeException(ctx, pathElement, ERR_ATTRIBUTE_MISSING, new Object[] { SVG_D_ATTRIBUTE });
throw new BridgeException(ctx, pathElement, pEx, ERR_ATTRIBUTE_VALUE_MALFORMED,
new Object[] { attrName });
} finally {
pathShape = app.getShape();
}

// if the reference path element has a transform apply the transform
// to the path shape
s = pathElement.getAttributeNS(null, SVG_TRANSFORM_ATTRIBUTE);
if (s.length() != 0) {
AffineTransform tr = SVGUtilities.convertTransform(pathElement, SVG_TRANSFORM_ATTRIBUTE, s, ctx);
String s = pathElement.getAttributeNS(null, SVG_TRANSFORM_ATTRIBUTE);
if (!s.isEmpty()) {
AffineTransform tr = SVGUtilities.convertTransform(pathElement, SVG_TRANSFORM_ATTRIBUTE,
s, ctx);
pathShape = tr.createTransformedShape(pathShape);
}

Expand All @@ -112,7 +128,7 @@ public TextPath createTextPath(BridgeContext ctx, Element textPathElement) {

// set the start offset if specified
s = textPathElement.getAttributeNS(null, SVG_START_OFFSET_ATTRIBUTE);
if (s.length() > 0) {
if (!s.isEmpty()) {
float startOffset = 0;
int percentIndex = s.indexOf('%');
if (percentIndex != -1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ public void testTextLength() throws TranscoderException, IOException {

@Test
public void testTextOnPath() throws TranscoderException, IOException {
test("samples/tests/spec/text/textOnPath.svg");
testNV("samples/tests/spec/text/textOnPath.svg");
}

@Test
Expand All @@ -932,6 +932,26 @@ public void testTextOnPathSpaces() throws TranscoderException, IOException {
test("samples/tests/spec/text/textOnPathSpaces.svg");
}

@Test
public void testTextOnPathPathAttr() throws TranscoderException, IOException {
testNV("samples/tests/spec/text/textOnPathPathAttr.svg");
}

@Test
public void testTextOnPathPathAttr2() throws TranscoderException, IOException {
testNV("samples/tests/spec/text/textOnPathPathAttr2.svg");
}

@Test
public void testTextOnPathPathAttr3() throws TranscoderException, IOException {
testNV("samples/tests/spec/text/textOnPathPathAttr3.svg");
}

@Test
public void testTextOnPathPathAttrSpaces() throws TranscoderException, IOException {
testNV("samples/tests/spec/text/textOnPathPathAttrSpaces.svg");
}

@Test
public void testTextPCDATA() throws TranscoderException, IOException {
test("samples/tests/spec/text/textPCDATA.svg");
Expand Down Expand Up @@ -962,6 +982,11 @@ public void testVerticalTextOnPath() throws TranscoderException, IOException {
test("samples/tests/spec/text/verticalTextOnPath.svg");
}

@Test
public void testVerticalTextOnPathPathAttr() throws TranscoderException, IOException {
testNV("samples/tests/spec/text/verticalTextOnPathPathAttr.svg");
}

@Test
public void testTextPosition() throws TranscoderException, IOException {
test("samples/tests/spec/text/textPosition.svg");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ public void testTextLength() throws TranscoderException, IOException {

@Test
public void testTextOnPath() throws TranscoderException, IOException {
test("samples/tests/spec/text/textOnPath.svg");
testNV("samples/tests/spec/text/textOnPath.svg");
}

@Test
Expand Down
4 changes: 1 addition & 3 deletions samples/tests/spec/text/textOnPath.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
158 changes: 158 additions & 0 deletions samples/tests/spec/text/textOnPathPathAttr.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading