Skip to content

Commit

Permalink
redo BATIK-1319
Browse files Browse the repository at this point in the history
  • Loading branch information
XenoAmess committed Mar 25, 2022
1 parent d94bc5f commit 315b4ca
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,28 @@ public class BridgeContext implements ErrorConstants, CSSContext {
*/
protected float animationLimitingAmount;

protected int useElementBridgeCalculationLimit = DEFAULT_USE_ELEMENT_CALCULATION_BRIDGE_LIMIT;

public static final int DEFAULT_USE_ELEMENT_CALCULATION_BRIDGE_LIMIT = 1024;

public int getUseElementBridgeCalculationLimit() {
return useElementBridgeCalculationLimit;
}

public void setUseElementBridgeCalculationLimit(int useElementBridgeCalculationLimit) {
this.useElementBridgeCalculationLimit = useElementBridgeCalculationLimit;
}

public boolean stopAfterConsumeUseElementBridgeCalculationLimit() {
int useElementBridgeCalculationLimit = this.getUseElementBridgeCalculationLimit();
if (useElementBridgeCalculationLimit <= 0) {
return true;
}
--useElementBridgeCalculationLimit;
this.setUseElementBridgeCalculationLimit(useElementBridgeCalculationLimit);
return false;
}

/**
* By default we share a unique instance of InterpreterPool.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ public GraphicsNode createGraphicsNode(BridgeContext ctx, Element e) {
*/
public CompositeGraphicsNode buildCompositeGraphicsNode
(BridgeContext ctx, Element e, CompositeGraphicsNode gn) {

if (ctx.stopAfterConsumeUseElementBridgeCalculationLimit()) {
return null;
}

// get the referenced element
SVGOMUseElement ue = (SVGOMUseElement) e;
String uri = ue.getHref().getAnimVal();
Expand Down Expand Up @@ -159,6 +164,9 @@ public GraphicsNode createGraphicsNode(BridgeContext ctx, Element e) {
for (Node n = localRefElement.getFirstChild();
n != null;
n = localRefElement.getFirstChild()) {
if (ctx.stopAfterConsumeUseElementBridgeCalculationLimit()) {
return null;
}
svgElement.appendChild(n);
}
localRefElement = svgElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,17 @@ protected void configure(SVGConverter c){
addTest(t);
t.setId("OutputTest.reference");

t = new ConverterOutputTest("samples/manyuse.svg", // File to convert
"test-reports/manyuse.png", // Output
"test-references/samples/manyuse.png"); // reference
addTest(t);
t.setId("manyuse");

t = new ConverterOutputTest("samples/3points.svg", // File to convert
"test-reports/3points.png", // Output
"test-references/samples/3points.png"); // reference
addTest(t);
t.setId("3points");
}
}

Expand Down
5 changes: 5 additions & 0 deletions samples/3points.svg
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 315b4ca

Please sign in to comment.