Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #168 from cdk/patch/11Oct15-regressions
Patch/11 oct15 regressions
  • Loading branch information
egonw committed Oct 11, 2015
2 parents 7e2a3d5 + bf96e0e commit df1fb51
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 41 deletions.
Expand Up @@ -44,11 +44,9 @@ public void empty() {
String empty = new SvgDrawVisitor(50, 50).toString();
assertThat(empty, is("<?xml version='1.0' encoding='UTF-8'?>\n"
+ "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n"
+ "<svg version='1.2' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' width='50' height='50'>\n"
+ " <desc>Generated with the Chemistry Development Kit (http://github.com/cdk)</desc>\n"
+ " <g stroke-linecap='round' stroke-linejoin='round'>\n"
+ " </g>\n"
+ "</svg>"));
+ "<svg version='1.2' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' width='50.0mm' height='50.0mm' viewBox='0 0 50.0 50.0'>\n"
+ " <desc>Generated by the Chemistry Development Kit (http://github.com/cdk)</desc>\n"
+ "</svg>\n"));
}

@Test
Expand All @@ -58,14 +56,12 @@ public void markedElement() {
"test-class"));
assertThat(visitor.toString(), is("<?xml version='1.0' encoding='UTF-8'?>\n"
+ "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n"
+ "<svg version='1.2' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' width='50' height='50'>\n"
+ " <desc>Generated with the Chemistry Development Kit (http://github.com/cdk)</desc>\n"
+ "<svg version='1.2' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' width='50.0mm' height='50.0mm' viewBox='0 0 50.0 50.0'>\n"
+ " <desc>Generated by the Chemistry Development Kit (http://github.com/cdk)</desc>\n"
+ " <g stroke-linecap='round' stroke-linejoin='round'>\n"
+ " <g class='test-class'>\n"
+ " <line x1='0' y1='0' x2='1' y2='1' stroke='#FF0000' stroke-width='0.5'/>\n"
+ " </g>\n"
+ " <line x1='.0' y1='.0' x2='1.0' y2='1.0' stroke='#FF0000' stroke-width='.5'/>\n"
+ " </g>\n"
+ "</svg>"));
+ "</svg>\n"));
}

@Test
Expand All @@ -76,13 +72,13 @@ public void translatedLine() {
visitor.visit(new LineElement(0, 0, 1, 1, 0.5, Color.RED));
assertThat(visitor.toString(), is("<?xml version='1.0' encoding='UTF-8'?>\n"
+ "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n"
+ "<svg version='1.2' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' width='50' height='50'>\n"
+ " <desc>Generated with the Chemistry Development Kit (http://github.com/cdk)</desc>\n"
+ "<svg version='1.2' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' width='50.0mm' height='50.0mm' viewBox='0 0 50.0 50.0'>\n"
+ " <desc>Generated by the Chemistry Development Kit (http://github.com/cdk)</desc>\n"
+ " <g stroke-linecap='round' stroke-linejoin='round'>\n"
+ " <line x1='0' y1='0' x2='1' y2='1' stroke='#FF0000' stroke-width='0.5'/>\n"
+ " <line x1='10' y1='10' x2='11' y2='11' stroke='#FF0000' stroke-width='0.5'/>\n"
+ " <line x1='.0' y1='.0' x2='1.0' y2='1.0' stroke='#FF0000' stroke-width='.5'/>\n"
+ " <line x1='10.0' y1='10.0' x2='11.0' y2='11.0' stroke='#FF0000' stroke-width='.5'/>\n"
+ " </g>\n"
+ "</svg>"));
+ "</svg>\n"));
}

@Test
Expand All @@ -93,13 +89,13 @@ public void scaledStroke() {
visitor.visit(new LineElement(0, 0, 1, 1, 0.5, Color.RED));
assertThat(visitor.toString(), is("<?xml version='1.0' encoding='UTF-8'?>\n"
+ "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n"
+ "<svg version='1.2' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' width='50' height='50'>\n"
+ " <desc>Generated with the Chemistry Development Kit (http://github.com/cdk)</desc>\n"
+ "<svg version='1.2' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' width='50.0mm' height='50.0mm' viewBox='0 0 50.0 50.0'>\n"
+ " <desc>Generated by the Chemistry Development Kit (http://github.com/cdk)</desc>\n"
+ " <g stroke-linecap='round' stroke-linejoin='round'>\n"
+ " <line x1='0' y1='0' x2='1' y2='1' stroke='#FF0000' stroke-width='0.5'/>\n"
+ " <line x1='0' y1='0' x2='2' y2='2' stroke='#FF0000' stroke-width='1'/>\n"
+ " <line x1='.0' y1='.0' x2='1.0' y2='1.0' stroke='#FF0000' stroke-width='.5'/>\n"
+ " <line x1='.0' y1='.0' x2='2.0' y2='2.0' stroke='#FF0000' stroke-width='1.0'/>\n"
+ " </g>\n"
+ "</svg>"));
+ "</svg>\n"));
}

@Test
Expand All @@ -108,12 +104,12 @@ public void filledPath() {
visitor.visit(GeneralPath.shapeOf(new RoundRectangle2D.Double(0,0,10,10,2,2), Color.BLUE));
assertThat(visitor.toString(), is("<?xml version='1.0' encoding='UTF-8'?>\n"
+ "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n"
+ "<svg version='1.2' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' width='50' height='50'>\n"
+ " <desc>Generated with the Chemistry Development Kit (http://github.com/cdk)</desc>\n"
+ "<svg version='1.2' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' width='50.0mm' height='50.0mm' viewBox='0 0 50.0 50.0'>\n"
+ " <desc>Generated by the Chemistry Development Kit (http://github.com/cdk)</desc>\n"
+ " <g stroke-linecap='round' stroke-linejoin='round'>\n"
+ " <path d='M 0 1 L 0 9 C 0 9.55 0.45 10 1 10 L 9 10 C 9.55 10 10 9.55 10 9 L 10 1 C 10 0.45 9.55 0 9 0 L 1 0 C 0.45 0 0 0.45 0 1 Z ' stroke='none' fill='#0000FF'/>\n"
+ " <path d='M.0 1.0v8.0c.0 .55 .45 1.0 1.0 1.0h8.0c.55 .0 1.0 -.45 1.0 -1.0v-8.0c.0 -.55 -.45 -1.0 -1.0 -1.0h-8.0c-.55 .0 -1.0 .45 -1.0 1.0z' stroke='none' fill='#0000FF'/>\n"
+ " </g>\n"
+ "</svg>"));
+ "</svg>\n"));
}

@Test
Expand All @@ -123,12 +119,12 @@ public void transformedPath() {
visitor.visit(GeneralPath.shapeOf(new RoundRectangle2D.Double(0, 0, 10, 10, 2, 2), Color.BLUE));
assertThat(visitor.toString(), is("<?xml version='1.0' encoding='UTF-8'?>\n"
+ "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n"
+ "<svg version='1.2' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' width='50' height='50'>\n"
+ " <desc>Generated with the Chemistry Development Kit (http://github.com/cdk)</desc>\n"
+ "<svg version='1.2' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' width='50.0mm' height='50.0mm' viewBox='0 0 50.0 50.0'>\n"
+ " <desc>Generated by the Chemistry Development Kit (http://github.com/cdk)</desc>\n"
+ " <g stroke-linecap='round' stroke-linejoin='round'>\n"
+ " <path d='M 15 16 L 15 24 C 15 24.55 15.45 25 16 25 L 24 25 C 24.55 25 25 24.55 25 24 L 25 16 C 25 15.45 24.55 15 24 15 L 16 15 C 15.45 15 15 15.45 15 16 Z ' stroke='none' fill='#0000FF'/>\n"
+ " <path d='M15.0 16.0v8.0c.0 .55 .45 1.0 1.0 1.0h8.0c.55 .0 1.0 -.45 1.0 -1.0v-8.0c.0 -.55 -.45 -1.0 -1.0 -1.0h-8.0c-.55 .0 -1.0 .45 -1.0 1.0z' stroke='none' fill='#0000FF'/>\n"
+ " </g>\n"
+ "</svg>"));
+ "</svg>\n"));
}

@Test
Expand All @@ -137,12 +133,12 @@ public void textElements() {
visitor.visit(new TextElement(50, 50, "PNG < EPS < SVG", Color.RED));
assertThat(visitor.toString(), is("<?xml version='1.0' encoding='UTF-8'?>\n"
+ "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n"
+ "<svg version='1.2' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' width='100' height='100'>\n"
+ " <desc>Generated with the Chemistry Development Kit (http://github.com/cdk)</desc>\n"
+ "<svg version='1.2' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' width='100.0mm' height='100.0mm' viewBox='0 0 100.0 100.0'>\n"
+ " <desc>Generated by the Chemistry Development Kit (http://github.com/cdk)</desc>\n"
+ " <g stroke-linecap='round' stroke-linejoin='round'>\n"
+ " <text x='50' y='50' fill='#FF0000' text-anchor='middle'>PNG &lt; EPS &lt; SVG</text>\n"
+ " <text x='50.0' y='50.0' fill='#FF0000' text-anchor='middle'>PNG &lt; EPS &lt; SVG</text>\n"
+ " </g>\n"
+ "</svg>"));
+ "</svg>\n"));
}

@Test
Expand All @@ -151,12 +147,12 @@ public void rectElements() {
visitor.visit(new RectangleElement(0,0,100,100, Color.WHITE));
assertThat(visitor.toString(), is("<?xml version='1.0' encoding='UTF-8'?>\n"
+ "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n"
+ "<svg version='1.2' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' width='100' height='100'>\n"
+ " <desc>Generated with the Chemistry Development Kit (http://github.com/cdk)</desc>\n"
+ "<svg version='1.2' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' width='100.0mm' height='100.0mm' viewBox='0 0 100.0 100.0'>\n"
+ " <desc>Generated by the Chemistry Development Kit (http://github.com/cdk)</desc>\n"
+ " <g stroke-linecap='round' stroke-linejoin='round'>\n"
+ " <rect x='0' y='0' width='100' height='100' fill='none' stroke='#FFFFFF'/>\n"
+ " <rect x='.0' y='-100.0' width='100.0' height='100.0' fill='none' stroke='#FFFFFF'/>\n"
+ " </g>\n"
+ "</svg>"));
+ "</svg>\n"));
}

}
Expand Up @@ -164,7 +164,8 @@ public static MarkedElement markupMol(IRenderingElement elem, IAtomContainer mol
* @return the marked element
*/
public static MarkedElement markupAtom(IRenderingElement elem, IAtom atom) {
assert elem != null;
if (elem == null)
return null;
MarkedElement tagElem = markupChemObj(elem, atom);
tagElem.aggClass("atom");
return tagElem;
Expand Down
Expand Up @@ -28,9 +28,11 @@

import org.openscience.cdk.renderer.RendererModel;
import org.openscience.cdk.renderer.elements.AtomSymbolElement;
import org.openscience.cdk.renderer.elements.Bounds;
import org.openscience.cdk.renderer.elements.ElementGroup;
import org.openscience.cdk.renderer.elements.IRenderingElement;
import org.openscience.cdk.renderer.elements.LineElement;
import org.openscience.cdk.renderer.elements.MarkedElement;
import org.openscience.cdk.renderer.elements.OvalElement;
import org.openscience.cdk.renderer.font.IFontManager;
import org.openscience.cdk.renderer.visitor.IDrawVisitor;
Expand Down Expand Up @@ -67,6 +69,10 @@ public void visit(IRenderingElement element) {
this.elements.add(element);
}
((ElementGroup) element).visitChildren(this);
} else if (element instanceof MarkedElement) {
visit(((MarkedElement) element).element());
} else if (element instanceof Bounds) {
visit(((Bounds) element).root());
} else {
this.elements.add(element);
}
Expand Down
Expand Up @@ -37,6 +37,7 @@
import org.openscience.cdk.renderer.color.IAtomColorer;
import org.openscience.cdk.renderer.elements.AtomSymbolElement;
import org.openscience.cdk.renderer.elements.IRenderingElement;
import org.openscience.cdk.renderer.elements.MarkedElement;
import org.openscience.cdk.renderer.elements.OvalElement;
import org.openscience.cdk.renderer.elements.RectangleElement;
import org.openscience.cdk.renderer.generators.BasicAtomGenerator.AtomColor;
Expand All @@ -58,6 +59,12 @@ public class BasicAtomGeneratorTest extends AbstractGeneratorTest {

private BasicAtomGenerator generator;

static IRenderingElement unbox(IRenderingElement element) {
if (element instanceof MarkedElement)
return ((MarkedElement) element).element();
return element;
}

@Override
public Rectangle getCustomCanvas() {
return null;
Expand Down Expand Up @@ -229,7 +236,7 @@ public void getAtomColorTest() {

List<IRenderingElement> elements = getAllSimpleElements(generator, singleAtom);
Assert.assertEquals(1, elements.size());
AtomSymbolElement element = ((AtomSymbolElement) elements.get(0));
AtomSymbolElement element = ((AtomSymbolElement) unbox(elements.get(0)));
Assert.assertEquals(testColor, element.color);
}

Expand Down Expand Up @@ -267,7 +274,7 @@ public Color getAtomColor(IAtom atom, Color defaultColor) {
List<IRenderingElement> elements = getAllSimpleElements(generator, cnop);
Assert.assertEquals(4, elements.size());
for (IRenderingElement element : elements) {
AtomSymbolElement symbolElement = (AtomSymbolElement) element;
AtomSymbolElement symbolElement = (AtomSymbolElement) unbox(element);
String symbol = symbolElement.text;
Assert.assertTrue(colorMap.containsKey(symbol));
Assert.assertEquals(colorMap.get(symbol), symbolElement.color);
Expand All @@ -281,7 +288,7 @@ public void colorByTypeTest() {
List<IRenderingElement> elements = getAllSimpleElements(generator, snop);
Color defaultColor = model.getDefault(AtomColor.class);
for (IRenderingElement element : elements) {
AtomSymbolElement symbolElement = (AtomSymbolElement) element;
AtomSymbolElement symbolElement = (AtomSymbolElement) unbox(element);
Assert.assertEquals(defaultColor, symbolElement.color);
}
}
Expand Down
Expand Up @@ -11,6 +11,7 @@
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.renderer.elements.IRenderingElement;
import org.openscience.cdk.renderer.elements.LineElement;
import org.openscience.cdk.renderer.elements.MarkedElement;

/**
* Test the {@link BasicBondGenerator}.
Expand All @@ -22,6 +23,12 @@ public class BasicBondGeneratorTest extends AbstractGeneratorTest {

private BasicBondGenerator generator;

static IRenderingElement unbox(IRenderingElement element) {
if (element instanceof MarkedElement)
return ((MarkedElement) element).element();
return element;
}

@Override
public Rectangle getCustomCanvas() {
return null;
Expand Down

0 comments on commit df1fb51

Please sign in to comment.