Skip to content

Commit f300143

Browse files
committed
redo BATIK-1319
1 parent 76cb440 commit f300143

File tree

4 files changed

+41
-9
lines changed

4 files changed

+41
-9
lines changed

batik-bridge/src/main/java/org/apache/batik/bridge/BridgeContext.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,28 @@ public class BridgeContext implements ErrorConstants, CSSContext {
270270
*/
271271
protected float animationLimitingAmount;
272272

273+
protected int useElementBridgeCalculationLimit = DEFAULT_USE_ELEMENT_CALCULATION_BRIDGE_LIMIT;
274+
275+
public static final int DEFAULT_USE_ELEMENT_CALCULATION_BRIDGE_LIMIT = 1024;
276+
277+
public int getUseElementBridgeCalculationLimit() {
278+
return useElementBridgeCalculationLimit;
279+
}
280+
281+
public void setUseElementBridgeCalculationLimit(int useElementBridgeCalculationLimit) {
282+
this.useElementBridgeCalculationLimit = useElementBridgeCalculationLimit;
283+
}
284+
285+
public boolean stopAfterConsumeUseElementBridgeCalculationLimit() {
286+
int useElementBridgeCalculationLimit = this.getUseElementBridgeCalculationLimit();
287+
if (useElementBridgeCalculationLimit <= 0) {
288+
return true;
289+
}
290+
--useElementBridgeCalculationLimit;
291+
this.setUseElementBridgeCalculationLimit(useElementBridgeCalculationLimit);
292+
return false;
293+
}
294+
273295
/**
274296
* By default we share a unique instance of InterpreterPool.
275297
*/

batik-bridge/src/main/java/org/apache/batik/bridge/SVGUseElementBridge.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ Licensed to the Apache Software Foundation (ASF) under one or more
2222
import java.awt.RenderingHints;
2323
import java.awt.geom.AffineTransform;
2424
import java.awt.geom.Rectangle2D;
25-
import java.util.ArrayList;
26-
import java.util.List;
2725

2826
import org.apache.batik.anim.dom.AbstractSVGAnimatedLength;
2927
import org.apache.batik.anim.dom.AnimatedLiveAttributeValue;
@@ -54,8 +52,6 @@ Licensed to the Apache Software Foundation (ASF) under one or more
5452
*/
5553
public class SVGUseElementBridge extends AbstractGraphicsNodeBridge {
5654

57-
private List<String> visited = new ArrayList<>();
58-
5955
/**
6056
* Used to handle mutation of the referenced content. This is
6157
* only used in dynamic context and only for reference to local
@@ -117,14 +113,14 @@ public GraphicsNode createGraphicsNode(BridgeContext ctx, Element e) {
117113
*/
118114
public CompositeGraphicsNode buildCompositeGraphicsNode
119115
(BridgeContext ctx, Element e, CompositeGraphicsNode gn) {
116+
117+
if (ctx.stopAfterConsumeUseElementBridgeCalculationLimit()) {
118+
return null;
119+
}
120+
120121
// get the referenced element
121122
SVGOMUseElement ue = (SVGOMUseElement) e;
122123
String uri = ue.getHref().getAnimVal();
123-
String id = uri + ";" + ue.getStyle().getCssText();
124-
if (visited.contains(id)) {
125-
return null;
126-
}
127-
visited.add(id);
128124
if (uri.length() == 0) {
129125
throw new BridgeException(ctx, e, ERR_ATTRIBUTE_MISSING,
130126
new Object[] {"xlink:href"});
@@ -168,6 +164,9 @@ public GraphicsNode createGraphicsNode(BridgeContext ctx, Element e) {
168164
for (Node n = localRefElement.getFirstChild();
169165
n != null;
170166
n = localRefElement.getFirstChild()) {
167+
if (ctx.stopAfterConsumeUseElementBridgeCalculationLimit()) {
168+
return null;
169+
}
171170
svgElement.appendChild(n);
172171
}
173172
localRefElement = svgElement;

batik-test-old/src/test/java/org/apache/batik/apps/rasterizer/SVGConverterTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,12 @@ protected void configure(SVGConverter c){
420420
"test-references/samples/manyuse.png"); // reference
421421
addTest(t);
422422
t.setId("manyuse");
423+
424+
t = new ConverterOutputTest("samples/3points.svg", // File to convert
425+
"test-reports/3points.png", // Output
426+
"test-references/samples/3points.png"); // reference
427+
addTest(t);
428+
t.setId("3points");
423429
}
424430
}
425431

samples/3points.svg

Lines changed: 5 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)