used SVG images in XSL-FO to get better quality and smaller files

This commit is contained in:
hneemann 2016-11-24 22:25:02 +01:00
parent 9f8aecb04e
commit 32ce8dfd92

View File

@ -4,6 +4,8 @@ import de.neemann.digital.core.NodeException;
import de.neemann.digital.core.element.*;
import de.neemann.digital.draw.elements.PinException;
import de.neemann.digital.draw.elements.VisualElement;
import de.neemann.digital.draw.graphics.GraphicMinMax;
import de.neemann.digital.draw.graphics.GraphicSVGIndex;
import de.neemann.digital.draw.library.ElementLibrary;
import de.neemann.digital.draw.shapes.ShapeFactory;
import de.neemann.digital.integration.Resources;
@ -29,7 +31,7 @@ import java.io.*;
* information used to create the tooltips in the program. After that Xalan is used to transform the XML document
* to a XSL-FO document. Then FOP is used to read the XSL-FO file and to compile it to a PDF document.
* The PDF document is then included in the distribution ZIP. This done for all supported languages.
*
* <p>
* Created by hneemann on 17.11.16.
*/
public class DocuTest extends TestCase {
@ -76,15 +78,18 @@ public class DocuTest extends TestCase {
final ElementTypeDescription etd = e.getDescription();
String imageName = etd.getName() + "_" + language;
File imageFile = new File(images, imageName + ".png");
File imageFile = new File(images, imageName + ".svg");
w.append(" <element name=\"")
.append(escapeHTML(etd.getTranslatedName()))
.append("\" img=\"")
.append(imageFile.toURI().toString())
.append("\">\n");
BufferedImage bi = new VisualElement(etd.getName()).setShapeFactory(shapeFactory).getBufferedImage(0.75 * IMAGE_SCALE, 250 * IMAGE_SCALE);
ImageIO.write(bi, "png", imageFile);
VisualElement ve = new VisualElement(etd.getName()).setShapeFactory(shapeFactory);
writeSVG(imageFile, ve);
// BufferedImage bi = new VisualElement(etd.getName()).setShapeFactory(shapeFactory).getBufferedImage(0.75 * IMAGE_SCALE, 250 * IMAGE_SCALE);
// ImageIO.write(bi, "png", imageFile);
final ElementAttributes attr = new ElementAttributes();
w.append(" <descr>").append(escapeHTML(etd.getDescription(attr))).append("</descr>\n");
@ -117,6 +122,16 @@ public class DocuTest extends TestCase {
w.append("</root>");
}
private void writeSVG(File imageFile, VisualElement ve) throws IOException {
GraphicMinMax minMax = new GraphicMinMax(false);
ve.drawTo(minMax, false);
try (FileOutputStream out = new FileOutputStream(imageFile)) {
try (GraphicSVGIndex svg = new GraphicSVGIndex(out, minMax.getMin(), minMax.getMax(), null, 100)) {
ve.drawTo(svg, false);
}
}
}
private void writePins(Writer w, PinDescriptions pinDescriptions) throws IOException {
for (PinDescription p : pinDescriptions) {
w.append(" <pin name=\"").append(escapeHTML(p.getName())).append("\">\n");