From 01d025823c8a7ffe64564ac56a73d7b21db2230e Mon Sep 17 00:00:00 2001 From: hneemann Date: Sat, 17 Aug 2019 17:18:40 +0200 Subject: [PATCH] Adds a better configuration of the SVG export; see #310 --- .../digital/draw/elements/VisualElement.java | 7 +- .../draw/graphics/ColorStyleHighContrast.java | 24 ++++ .../draw/graphics/ColorStyleMonochrome.java | 32 +++++ .../digital/draw/graphics/Graphic.java | 17 ++- .../digital/draw/graphics/GraphicSVG.java | 106 ++++++++++---- .../draw/graphics/GraphicSVGIndex.java | 60 -------- .../draw/graphics/GraphicSVGLaTeX.java | 135 ------------------ .../draw/graphics/GraphicSVGLaTeXInOut.java | 31 ---- .../digital/draw/graphics/SVGSettings.java | 63 ++++++++ .../draw/graphics/TextFormatLaTeX.java | 81 +++++++++++ .../digital/draw/graphics/TextFormatSVG.java | 29 ++++ .../digital/draw/shapes/AsyncClockShape.java | 2 +- .../digital/draw/shapes/ClockShape.java | 2 +- .../digital/draw/shapes/GenericShape.java | 2 +- .../digital/draw/shapes/InputShape.java | 2 +- .../digital/draw/shapes/OutputShape.java | 2 +- .../digital/draw/shapes/TestCaseShape.java | 2 +- .../de/neemann/digital/fsm/gui/FSMFrame.java | 3 +- .../java/de/neemann/digital/gui/Main.java | 17 ++- .../java/de/neemann/digital/gui/Settings.java | 79 ++-------- .../de/neemann/digital/gui/SettingsBase.java | 95 ++++++++++++ .../gui/components/data/GraphDialog.java | 3 +- src/main/resources/lang/lang_de.xml | 18 ++- src/main/resources/lang/lang_en.xml | 18 ++- src/main/resources/lang/lang_es.xml | 2 - src/main/resources/lang/lang_es_ref.xml | 2 - src/main/resources/lang/lang_pt.xml | 2 - src/main/resources/lang/lang_pt_ref.xml | 2 - .../de/neemann/digital/docu/DocuTest.java | 4 +- .../draw/graphics/GraphicSVGIndexTest.java | 11 +- .../draw/graphics/GraphicSVGLaTeXTest.java | 34 ++--- .../digital/draw/graphics/GraphicSVGTest.java | 7 +- .../digital/integration/TestExport.java | 10 +- 33 files changed, 513 insertions(+), 391 deletions(-) create mode 100644 src/main/java/de/neemann/digital/draw/graphics/ColorStyleHighContrast.java create mode 100644 src/main/java/de/neemann/digital/draw/graphics/ColorStyleMonochrome.java delete mode 100644 src/main/java/de/neemann/digital/draw/graphics/GraphicSVGIndex.java delete mode 100644 src/main/java/de/neemann/digital/draw/graphics/GraphicSVGLaTeX.java delete mode 100644 src/main/java/de/neemann/digital/draw/graphics/GraphicSVGLaTeXInOut.java create mode 100644 src/main/java/de/neemann/digital/draw/graphics/SVGSettings.java create mode 100644 src/main/java/de/neemann/digital/draw/graphics/TextFormatLaTeX.java create mode 100644 src/main/java/de/neemann/digital/draw/graphics/TextFormatSVG.java create mode 100644 src/main/java/de/neemann/digital/gui/SettingsBase.java diff --git a/src/main/java/de/neemann/digital/draw/elements/VisualElement.java b/src/main/java/de/neemann/digital/draw/elements/VisualElement.java index c2f445236..bc3ccb344 100644 --- a/src/main/java/de/neemann/digital/draw/elements/VisualElement.java +++ b/src/main/java/de/neemann/digital/draw/elements/VisualElement.java @@ -228,9 +228,10 @@ public class VisualElement implements Drawable, Movable, AttributeListener { Graphic gr = new GraphicTransform(graphic, getTransform()); Shape shape = getShape(); shape.drawTo(gr, highLight); - for (Pin p : shape.getPins()) - gr.drawCircle(p.getPos().add(-PIN, -PIN), p.getPos().add(PIN, PIN), - p.getDirection() == Pin.Direction.input ? Style.WIRE : Style.WIRE_OUT); + if (!graphic.isFlagSet(GraphicSVG.NO_PIN_MARKER)) + for (Pin p : shape.getPins()) + gr.drawCircle(p.getPos().add(-PIN, -PIN), p.getPos().add(PIN, PIN), + p.getDirection() == Pin.Direction.input ? Style.WIRE : Style.WIRE_OUT); } private Transform getTransform() { diff --git a/src/main/java/de/neemann/digital/draw/graphics/ColorStyleHighContrast.java b/src/main/java/de/neemann/digital/draw/graphics/ColorStyleHighContrast.java new file mode 100644 index 000000000..771a742b6 --- /dev/null +++ b/src/main/java/de/neemann/digital/draw/graphics/ColorStyleHighContrast.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2019 Helmut Neemann. + * Use of this source code is governed by the GPL v3 license + * that can be found in the LICENSE file. + */ +package de.neemann.digital.draw.graphics; + +import java.awt.*; + +/** + * Creates a high contrast style best for printing + */ +public class ColorStyleHighContrast implements GraphicSVG.ColorStyle { + @Override + public Color getColor(Style style) { + if (style == Style.WIRE) return Style.NORMAL.getColor(); + else if (style == Style.WIRE_OUT) return Style.NORMAL.getColor(); + else if (style == Style.WIRE_BITS) return Style.NORMAL.getColor(); + else if (style == Style.WIRE_BUS) return Style.NORMAL.getColor(); + else if (style == Style.SHAPE_PIN) return Style.NORMAL.getColor(); + else if (style == Style.SHAPE_SPLITTER) return Style.NORMAL.getColor(); + else return style.getColor(); + } +} diff --git a/src/main/java/de/neemann/digital/draw/graphics/ColorStyleMonochrome.java b/src/main/java/de/neemann/digital/draw/graphics/ColorStyleMonochrome.java new file mode 100644 index 000000000..c1d1b3fa0 --- /dev/null +++ b/src/main/java/de/neemann/digital/draw/graphics/ColorStyleMonochrome.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2019 Helmut Neemann. + * Use of this source code is governed by the GPL v3 license + * that can be found in the LICENSE file. + */ +package de.neemann.digital.draw.graphics; + +import java.awt.*; + +/** + * Generates monochrome colors. + */ +public class ColorStyleMonochrome implements GraphicSVG.ColorStyle { + + private GraphicSVG.ColorStyle parent; + + /** + * Creates a new instance + * + * @param parent the parent color style + */ + public ColorStyleMonochrome(GraphicSVG.ColorStyle parent) { + this.parent = parent; + } + + @Override + public Color getColor(Style style) { + Color color = parent.getColor(style); + int c = (color.getBlue() + color.getRed() + color.getGreen()) / 3; + return new Color(c, c, c, color.getAlpha()); + } +} diff --git a/src/main/java/de/neemann/digital/draw/graphics/Graphic.java b/src/main/java/de/neemann/digital/draw/graphics/Graphic.java index 9b9a1c944..39c64d6b1 100644 --- a/src/main/java/de/neemann/digital/draw/graphics/Graphic.java +++ b/src/main/java/de/neemann/digital/draw/graphics/Graphic.java @@ -14,10 +14,23 @@ import java.io.IOException; * implementations which create export formats like SVG ({@link GraphicSVG}). */ public interface Graphic extends Closeable { + /** - * Flag to enable LaTeX output mode. + * The shape filling flag */ - String LATEX = "LaTeX"; + String NO_SHAPE_FILLING = "noShapeFilling"; + /** + * the small IO flag + */ + String SMALL_IO = "smallIO"; + /** + * flag used to hide the test cases + */ + String HIDE_TEST = "hideTest"; + /** + * flag used to hide the pin marker + */ + String NO_PIN_MARKER = "noPinMarker"; /** * Sets the bounding box of the future usage of this instance diff --git a/src/main/java/de/neemann/digital/draw/graphics/GraphicSVG.java b/src/main/java/de/neemann/digital/draw/graphics/GraphicSVG.java index 7159c119a..8c529bc36 100644 --- a/src/main/java/de/neemann/digital/draw/graphics/GraphicSVG.java +++ b/src/main/java/de/neemann/digital/draw/graphics/GraphicSVG.java @@ -5,14 +5,16 @@ */ package de.neemann.digital.draw.graphics; +import de.neemann.digital.core.element.ElementAttributes; + +import java.awt.*; import java.io.*; import java.nio.charset.StandardCharsets; import java.util.Date; +import java.util.HashSet; /** * Used to create a SVG representation of the circuit. - * Don't use this implementation directly. Use {@link GraphicSVGIndex} to create plain SVG or - * {@link GraphicSVGLaTeX} if you want to include your SVG to LaTeX. */ public class GraphicSVG implements Graphic { private static final int DEF_SCALE = 15; @@ -20,15 +22,35 @@ public class GraphicSVG implements Graphic { private final File source; private final int svgScale; private BufferedWriter w; + private TextStyle textStyle = new TextFormatSVG(); + private ColorStyle colorStyle = Style::getColor; + private HashSet flags = new HashSet<>(); /** * Creates a new instance. * * @param out the stream - * @throws IOException IOException */ - public GraphicSVG(OutputStream out) throws IOException { + public GraphicSVG(OutputStream out) { this(out, null, DEF_SCALE); + ElementAttributes a = SVGSettings.getInstance().getAttributes(); + if (a.get(SVGSettings.LATEX)) + setTextStyle(new TextFormatLaTeX()); + if (a.get(SVGSettings.HIGH_CONTRAST)) + setColorStyle(new ColorStyleHighContrast()); + if (a.get(SVGSettings.SMALL_IO)) + setFlag(SMALL_IO); + if (a.get(SVGSettings.HIDE_TEST)) + setFlag(HIDE_TEST); + if (a.get(SVGSettings.NO_SHAPE_FILLING)) + setFlag(NO_SHAPE_FILLING); + if (a.get(SVGSettings.NO_SHAPE_FILLING)) + setFlag(NO_SHAPE_FILLING); + if (a.get(SVGSettings.NO_PIN_MARKER)) + setFlag(NO_PIN_MARKER); + + if (a.get(SVGSettings.MONOCHROME)) + setColorStyle(new ColorStyleMonochrome(colorStyle)); } /** @@ -49,9 +71,8 @@ public class GraphicSVG implements Graphic { * @param out the stream to write the file to * @param source source file, only used to create a comment in the SVG file * @param svgScale the scaling - * @throws IOException IOException */ - public GraphicSVG(OutputStream out, File source, int svgScale) throws IOException { + public GraphicSVG(OutputStream out, File source, int svgScale) { this.out = out; this.source = source; this.svgScale = svgScale; @@ -117,10 +138,14 @@ public class GraphicSVG implements Graphic { if (p.getEvenOdd() && style.isFilled()) w.write(" fill-rule=\"evenodd\""); - if (style.isFilled() && p.isClosed()) + if (style.isFilled() && p.isClosed() && !isFlagSet(NO_SHAPE_FILLING)) w.write(" stroke=\"" + getColor(style) + "\" stroke-width=\"" + getStrokeWidth(style) + "\" fill=\"" + getColor(style) + "\" fill-opacity=\"" + getOpacity(style) + "\"/>\n"); - else - w.write(" stroke=\"" + getColor(style) + "\" stroke-width=\"" + getStrokeWidth(style) + "\" fill=\"none\"/>\n"); + else { + double strokeWidth = getStrokeWidth(style); + if (strokeWidth == 0) + strokeWidth = getStrokeWidth(Style.THIN); + w.write(" stroke=\"" + getColor(style) + "\" stroke-width=\"" + strokeWidth + "\" fill=\"none\"/>\n"); + } } catch (IOException e) { throw new RuntimeException(e); } @@ -152,7 +177,7 @@ public class GraphicSVG implements Graphic { if (text == null || text.length() == 0) return; try { - text = formatText(text, style); + text = textStyle.format(text, style); boolean rotateText = false; if (p1.getY() == p2.getY()) { // 0 and 180 deg @@ -188,18 +213,6 @@ public class GraphicSVG implements Graphic { } } - /** - * Is used by drawText to format the given text to SVG. - * This implementation only calls escapeXML(text). - * - * @param text the text - * @param style the text style - * @return the formatted text - */ - public String formatText(String text, Style style) { - return escapeXML(text); - } - /** * Creates the color to use from the given Style instance. * This instance creates the common HTML representation. @@ -207,8 +220,8 @@ public class GraphicSVG implements Graphic { * @param style the {@link Style} * @return the COLOR */ - protected String getColor(Style style) { - return "#" + Integer.toHexString(style.getColor().getRGB()).substring(2); + private String getColor(Style style) { + return "#" + Integer.toHexString(colorStyle.getColor(style).getRGB()).substring(2); } private String getOpacity(Style style) { @@ -293,4 +306,49 @@ public class GraphicSVG implements Graphic { return p.getXFloat() + "," + p.getYFloat(); } + private void setTextStyle(TextStyle textStyle) { + this.textStyle = textStyle; + } + + private void setColorStyle(ColorStyle colorStyle) { + this.colorStyle = colorStyle; + } + + private void setFlag(String flag) { + flags.add(flag); + } + + @Override + public boolean isFlagSet(String name) { + return flags.contains(name); + } + + /** + * Defines the text style. + */ + public interface TextStyle { + /** + * Is used by drawText to format the given text to SVG. + * This implementation only calls escapeXML(text). + * + * @param text the text + * @param style the text style + * @return the formatted text + */ + String format(String text, Style style); + } + + /** + * Defines the color style + */ + public interface ColorStyle { + /** + * Returns the color to by used for the given style. + * + * @param style the style + * @return the color to be used + */ + Color getColor(Style style); + } + } diff --git a/src/main/java/de/neemann/digital/draw/graphics/GraphicSVGIndex.java b/src/main/java/de/neemann/digital/draw/graphics/GraphicSVGIndex.java deleted file mode 100644 index 2d10041ed..000000000 --- a/src/main/java/de/neemann/digital/draw/graphics/GraphicSVGIndex.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2016 Helmut Neemann - * Use of this source code is governed by the GPL v3 license - * that can be found in the LICENSE file. - */ -package de.neemann.digital.draw.graphics; - -import de.neemann.digital.draw.graphics.text.ParseException; -import de.neemann.digital.draw.graphics.text.Parser; -import de.neemann.digital.draw.graphics.text.formatter.SVGFormatter; -import de.neemann.digital.draw.graphics.text.text.Decorate; -import de.neemann.digital.draw.graphics.text.text.Text; - -import java.awt.*; -import java.io.File; -import java.io.IOException; -import java.io.OutputStream; - -/** - * Subclass of {@link GraphicSVG} which creates the correct SVG representation - * of an index if used like "x_0". - */ -public class GraphicSVGIndex extends GraphicSVG { - - /** - * Creates new instance - * - * @param out the file - * @throws IOException IOException - */ - public GraphicSVGIndex(OutputStream out) throws IOException { - super(out); - } - - /** - * Creates new instance - * - * @param out the output stream to use - * @param source source file, only used to create a comment in the SVG file - * @param svgScale the scaling - * @throws IOException IOException - */ - public GraphicSVGIndex(OutputStream out, File source, int svgScale) throws IOException { - super(out, source, svgScale); - } - - @Override - public String formatText(String text, Style style) { - try { - Text t = new Parser(text).parse(); - if (style.getFontStyle() == Font.ITALIC) - t = Decorate.math(t); - return SVGFormatter.format(t); - } catch (ParseException e) { - e.printStackTrace(); - } - return text; - } - -} diff --git a/src/main/java/de/neemann/digital/draw/graphics/GraphicSVGLaTeX.java b/src/main/java/de/neemann/digital/draw/graphics/GraphicSVGLaTeX.java deleted file mode 100644 index af9cb751a..000000000 --- a/src/main/java/de/neemann/digital/draw/graphics/GraphicSVGLaTeX.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright (c) 2016 Helmut Neemann - * Use of this source code is governed by the GPL v3 license - * that can be found in the LICENSE file. - */ -package de.neemann.digital.draw.graphics; - -import de.neemann.digital.draw.graphics.text.ParseException; -import de.neemann.digital.draw.graphics.text.Parser; -import de.neemann.digital.draw.graphics.text.formatter.LaTeXFormatter; -import de.neemann.digital.draw.graphics.text.text.Decorate; -import de.neemann.digital.draw.graphics.text.text.Text; - -import java.awt.*; -import java.io.File; -import java.io.IOException; -import java.io.OutputStream; -import java.util.ArrayList; - -/** - * Subclass of {@link GraphicSVG} which creates the correct SVG representation - * of an index if used like "x_0". But the text itself is created to be interpreted - * by LaTeX. To include such a SVG file in LaTeX Inkscape is needed to transform the SVG to PDF. - * In this case the image itself is included as a PDF file in which all the text is missing. - * Inkscape also creates a LaTeX overlay containing the text only. So you get best document quality: - * All the graphics as included PDF, all the text set with LaTeX fonts matching the rest of your LaTeX document. - * To run the transformation automatically by the LaTeX compiler see InkscapePDFLaTeX.pdf. - * - * @see inkscape - * @see InkscapePDFLaTeX.pdf - */ -public class GraphicSVGLaTeX extends GraphicSVG { - private static final ArrayList FONT_SIZES = new ArrayList<>(); - - private static final class FontSize { - - private final String name; - private final int size; - - private FontSize(String name, int size) { - this.name = name; - this.size = size; - } - } - - static { - add("tiny", 35); // measured pixel sizes in a BEAMER created PDF - add("scriptsize", 46); - add("footnotesize", 52); - add("small", 58); - add("normalsize", 63); - add("large", 69); - add("Large", 83); - add("LARGE", 100); - add("huge", 120); - add("Huge", 143); - } - - private static void add(String name, int size) { - FONT_SIZES.add(new FontSize(name, (size * Style.NORMAL.getFontSize()) / 63)); - } - - private static String getFontSizeName(int fontSize) { - String best = "normalsize"; - int diff = Integer.MAX_VALUE; - for (FontSize fs : FONT_SIZES) { - int d = Math.abs(fontSize - fs.size); - if (d < diff) { - diff = d; - best = fs.name; - } - } - return best; - } - - /** - * Creates new instance - * - * @param out the file - * @throws IOException IOException - */ - public GraphicSVGLaTeX(OutputStream out) throws IOException { - super(out); - } - - /** - * Creates new instance - * - * @param out the output stream to use - * @param source source file, only used to create a comment in the SVG file - * @param svgScale the scaling - * @throws IOException IOException - */ - public GraphicSVGLaTeX(OutputStream out, File source, int svgScale) throws IOException { - super(out, source, svgScale); - } - - @Override - public String formatText(String text, Style style) { - try { - Text t = new Parser(text).parse(); - if (style.getFontStyle() == Font.ITALIC && isFlagSet(LATEX)) - t = Decorate.math(t); - text = LaTeXFormatter.format(t); - } catch (ParseException e) { - e.printStackTrace(); - } - if (style.getFontSize() != Style.NORMAL.getFontSize()) { - final String fontSizeName = getFontSizeName(style.getFontSize()); - if (!fontSizeName.equals("normalsize")) - text = "{\\" + fontSizeName + " " + text + "}"; - } - return escapeXML(text); - } - - @Override - public void drawCircle(VectorInterface p1, VectorInterface p2, Style style) { - if (!isFlagSet(LATEX) - || (style != Style.WIRE && style != Style.WIRE_OUT) || Math.abs(p1.getX() - p2.getX()) > 4) - super.drawCircle(p1, p2, style); - } - - @Override - public String getColor(Style style) { - if (style == Style.WIRE) return super.getColor(Style.NORMAL); - else if (style == Style.WIRE_OUT) return super.getColor(Style.NORMAL); - else if (style == Style.WIRE_BITS) return super.getColor(Style.NORMAL); - else if (style == Style.WIRE_BUS) return super.getColor(Style.NORMAL); - else if (isFlagSet(LATEX)) { - if (style == Style.SHAPE_PIN) return super.getColor(Style.NORMAL); - else if (style == Style.SHAPE_SPLITTER) return super.getColor(Style.NORMAL); - } - return super.getColor(style); - } -} diff --git a/src/main/java/de/neemann/digital/draw/graphics/GraphicSVGLaTeXInOut.java b/src/main/java/de/neemann/digital/draw/graphics/GraphicSVGLaTeXInOut.java deleted file mode 100644 index 7735a1dec..000000000 --- a/src/main/java/de/neemann/digital/draw/graphics/GraphicSVGLaTeXInOut.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2017 Helmut Neemann - * Use of this source code is governed by the GPL v3 license - * that can be found in the LICENSE file. - */ -package de.neemann.digital.draw.graphics; - -import java.io.IOException; -import java.io.OutputStream; - -/** - * Replaces input and outputs by small circles - */ -public class GraphicSVGLaTeXInOut extends GraphicSVGLaTeX { - - /** - * Creates a new instance - * - * @param out the stream to write the data to - * @throws IOException IOException - */ - public GraphicSVGLaTeXInOut(OutputStream out) throws IOException { - super(out); - } - - @Override - public boolean isFlagSet(String name) { - return name.equals(LATEX); - } - -} diff --git a/src/main/java/de/neemann/digital/draw/graphics/SVGSettings.java b/src/main/java/de/neemann/digital/draw/graphics/SVGSettings.java new file mode 100644 index 000000000..85a20d207 --- /dev/null +++ b/src/main/java/de/neemann/digital/draw/graphics/SVGSettings.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2019 Helmut Neemann. + * Use of this source code is governed by the GPL v3 license + * that can be found in the LICENSE file. + */ +package de.neemann.digital.draw.graphics; + +import de.neemann.digital.core.element.Key; +import de.neemann.digital.gui.SettingsBase; + +import java.util.ArrayList; +import java.util.List; + +/** + * Settings used by the SVG exporter. + */ +public final class SVGSettings extends SettingsBase { + + static final Key HIGH_CONTRAST = + new Key<>("SVG_highContrast", false); + static final Key MONOCHROME = + new Key<>("SVG_monochrome", false); + static final Key SMALL_IO = + new Key<>("SVG_smallIO", false); + static final Key NO_PIN_MARKER = + new Key<>("SVG_noPinMarker", false); + static final Key HIDE_TEST = + new Key<>("SVG_hideTest", false); + static final Key NO_SHAPE_FILLING = + new Key<>("SVG_noShapeFilling", false); + static final Key LATEX = + new Key<>("SVG_LaTeX", false); + + private static final class SettingsHolder { + static final SVGSettings INSTANCE = new SVGSettings(); + } + + /** + * Returns the settings instance + * + * @return the Settings + */ + public static SVGSettings getInstance() { + return SettingsHolder.INSTANCE; + } + + private SVGSettings() { + super(createKeyList(), ".svgStyle.cfg"); + } + + private static List createKeyList() { + ArrayList list = new ArrayList<>(); + list.add(LATEX); + list.add(HIDE_TEST); + list.add(NO_SHAPE_FILLING); + list.add(SMALL_IO); + list.add(NO_PIN_MARKER); + list.add(HIGH_CONTRAST); + list.add(MONOCHROME); + return list; + } + +} diff --git a/src/main/java/de/neemann/digital/draw/graphics/TextFormatLaTeX.java b/src/main/java/de/neemann/digital/draw/graphics/TextFormatLaTeX.java new file mode 100644 index 000000000..f9cbeb2af --- /dev/null +++ b/src/main/java/de/neemann/digital/draw/graphics/TextFormatLaTeX.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2019 Helmut Neemann. + * Use of this source code is governed by the GPL v3 license + * that can be found in the LICENSE file. + */ +package de.neemann.digital.draw.graphics; + +import de.neemann.digital.draw.graphics.text.ParseException; +import de.neemann.digital.draw.graphics.text.Parser; +import de.neemann.digital.draw.graphics.text.formatter.LaTeXFormatter; +import de.neemann.digital.draw.graphics.text.text.Decorate; +import de.neemann.digital.draw.graphics.text.text.Text; + +import java.awt.*; +import java.util.ArrayList; + +/** + * Formats text in LaTeX style. + */ +public class TextFormatLaTeX implements GraphicSVG.TextStyle { + private static final ArrayList FONT_SIZES = new ArrayList<>(); + + private static final class FontSize { + + private final String name; + private final int size; + + private FontSize(String name, int size) { + this.name = name; + this.size = size; + } + } + + static { + add("tiny", 35); // measured pixel sizes in a BEAMER created PDF + add("scriptsize", 46); + add("footnotesize", 52); + add("small", 58); + add("normalsize", 63); + add("large", 69); + add("Large", 83); + add("LARGE", 100); + add("huge", 120); + add("Huge", 143); + } + + private static void add(String name, int size) { + FONT_SIZES.add(new FontSize(name, (size * Style.NORMAL.getFontSize()) / 63)); + } + + private static String getFontSizeName(int fontSize) { + String best = "normalsize"; + int diff = Integer.MAX_VALUE; + for (FontSize fs : FONT_SIZES) { + int d = Math.abs(fontSize - fs.size); + if (d < diff) { + diff = d; + best = fs.name; + } + } + return best; + } + + @Override + public String format(String text, Style style) { + try { + Text t = new Parser(text).parse(); + if (style.getFontStyle() == Font.ITALIC) + t = Decorate.math(t); + text = LaTeXFormatter.format(t); + } catch (ParseException e) { + e.printStackTrace(); + } + if (style.getFontSize() != Style.NORMAL.getFontSize()) { + final String fontSizeName = getFontSizeName(style.getFontSize()); + if (!fontSizeName.equals("normalsize")) + text = "{\\" + fontSizeName + " " + text + "}"; + } + return GraphicSVG.escapeXML(text); + } +} diff --git a/src/main/java/de/neemann/digital/draw/graphics/TextFormatSVG.java b/src/main/java/de/neemann/digital/draw/graphics/TextFormatSVG.java new file mode 100644 index 000000000..02269a75e --- /dev/null +++ b/src/main/java/de/neemann/digital/draw/graphics/TextFormatSVG.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2019 Helmut Neemann. + * Use of this source code is governed by the GPL v3 license + * that can be found in the LICENSE file. + */ +package de.neemann.digital.draw.graphics; + +import de.neemann.digital.draw.graphics.text.ParseException; +import de.neemann.digital.draw.graphics.text.Parser; +import de.neemann.digital.draw.graphics.text.formatter.SVGFormatter; +import de.neemann.digital.draw.graphics.text.text.Decorate; +import de.neemann.digital.draw.graphics.text.text.Text; + +import java.awt.*; + +final class TextFormatSVG implements GraphicSVG.TextStyle { + @Override + public String format(String text, Style style) { + try { + Text t = new Parser(text).parse(); + if (style.getFontStyle() == Font.ITALIC) + t = Decorate.math(t); + return SVGFormatter.format(t); + } catch (ParseException e) { + e.printStackTrace(); + } + return text; + } +} diff --git a/src/main/java/de/neemann/digital/draw/shapes/AsyncClockShape.java b/src/main/java/de/neemann/digital/draw/shapes/AsyncClockShape.java index 364d688c1..64ecfdaef 100644 --- a/src/main/java/de/neemann/digital/draw/shapes/AsyncClockShape.java +++ b/src/main/java/de/neemann/digital/draw/shapes/AsyncClockShape.java @@ -49,7 +49,7 @@ public class AsyncClockShape implements Shape { @Override public void drawTo(Graphic graphic, Style highLight) { - if (!graphic.isFlagSet(Graphic.LATEX)) { + if (!graphic.isFlagSet(Graphic.HIDE_TEST)) { Polygon pol = new Polygon(true) .add(SIZE2, SIZE2) .add(SIZE2 + SIZE * 4, SIZE2) diff --git a/src/main/java/de/neemann/digital/draw/shapes/ClockShape.java b/src/main/java/de/neemann/digital/draw/shapes/ClockShape.java index 93c33e700..983f6076a 100644 --- a/src/main/java/de/neemann/digital/draw/shapes/ClockShape.java +++ b/src/main/java/de/neemann/digital/draw/shapes/ClockShape.java @@ -74,7 +74,7 @@ public class ClockShape implements Shape { @Override public void drawTo(Graphic graphic, Style heighLight) { Vector wavePos; - if (graphic.isFlagSet(Graphic.LATEX)) { + if (graphic.isFlagSet(Graphic.SMALL_IO)) { Vector center = new Vector(-LATEX_RAD.x, 0); graphic.drawCircle(center.sub(LATEX_RAD), center.add(LATEX_RAD), Style.NORMAL); Vector textPos = new Vector(-SIZE2 - LATEX_RAD.x, 0); diff --git a/src/main/java/de/neemann/digital/draw/shapes/GenericShape.java b/src/main/java/de/neemann/digital/draw/shapes/GenericShape.java index 7817e1e57..28bff6b64 100644 --- a/src/main/java/de/neemann/digital/draw/shapes/GenericShape.java +++ b/src/main/java/de/neemann/digital/draw/shapes/GenericShape.java @@ -218,7 +218,7 @@ public class GenericShape implements Shape { .add(SIZE * width - 1, yBottom) .add(1, yBottom); - if (color != Color.WHITE && !graphic.isFlagSet(Graphic.LATEX)) + if (color != Color.WHITE) graphic.drawPolygon(polygon, Style.NORMAL.deriveFillStyle(color)); graphic.drawPolygon(polygon, Style.NORMAL); diff --git a/src/main/java/de/neemann/digital/draw/shapes/InputShape.java b/src/main/java/de/neemann/digital/draw/shapes/InputShape.java index 0fc97ab20..e1fb1ed7c 100644 --- a/src/main/java/de/neemann/digital/draw/shapes/InputShape.java +++ b/src/main/java/de/neemann/digital/draw/shapes/InputShape.java @@ -123,7 +123,7 @@ public class InputShape implements Shape { @Override public void drawTo(Graphic graphic, Style heighLight) { - if (graphic.isFlagSet(Graphic.LATEX)) { + if (graphic.isFlagSet(Graphic.SMALL_IO)) { Vector center = new Vector(-LATEX_RAD.x, 0); graphic.drawCircle(center.sub(LATEX_RAD), center.add(LATEX_RAD), Style.NORMAL); Vector textPos = new Vector(-SIZE2 - LATEX_RAD.x, 0); diff --git a/src/main/java/de/neemann/digital/draw/shapes/OutputShape.java b/src/main/java/de/neemann/digital/draw/shapes/OutputShape.java index 1ca355681..c7c0d7eec 100644 --- a/src/main/java/de/neemann/digital/draw/shapes/OutputShape.java +++ b/src/main/java/de/neemann/digital/draw/shapes/OutputShape.java @@ -84,7 +84,7 @@ public class OutputShape implements Shape { @Override public void drawTo(Graphic graphic, Style highLight) { - if (graphic.isFlagSet(Graphic.LATEX)) { + if (graphic.isFlagSet(Graphic.SMALL_IO)) { Vector center = new Vector(LATEX_RAD.x, 0); graphic.drawCircle(center.sub(LATEX_RAD), center.add(LATEX_RAD), Style.NORMAL); Vector textPos = new Vector(SIZE2 + LATEX_RAD.x, 0); diff --git a/src/main/java/de/neemann/digital/draw/shapes/TestCaseShape.java b/src/main/java/de/neemann/digital/draw/shapes/TestCaseShape.java index c65234897..22821c1c3 100644 --- a/src/main/java/de/neemann/digital/draw/shapes/TestCaseShape.java +++ b/src/main/java/de/neemann/digital/draw/shapes/TestCaseShape.java @@ -49,7 +49,7 @@ public class TestCaseShape implements Shape { @Override public void drawTo(Graphic graphic, Style highLight) { - if (!graphic.isFlagSet(Graphic.LATEX)) { + if (!graphic.isFlagSet(Graphic.HIDE_TEST)) { Polygon pol = new Polygon(true) .add(SIZE2, SIZE2) .add(SIZE2 + SIZE * 4, SIZE2) diff --git a/src/main/java/de/neemann/digital/fsm/gui/FSMFrame.java b/src/main/java/de/neemann/digital/fsm/gui/FSMFrame.java index 02d767363..38660d3a2 100644 --- a/src/main/java/de/neemann/digital/fsm/gui/FSMFrame.java +++ b/src/main/java/de/neemann/digital/fsm/gui/FSMFrame.java @@ -223,8 +223,7 @@ public class FSMFrame extends JFrame implements ClosingWindowListener.ConfirmSav }.setAcceleratorCTRLplus('S').setEnabledChain(false); JMenu export = new JMenu(Lang.get("menu_export")); - export.add(new ExportAction(Lang.get("menu_exportSVG"), "svg", GraphicSVGIndex::new)); - export.add(new ExportAction(Lang.get("menu_exportSVGLaTex"), "svg", GraphicSVGLaTeX::new)); + export.add(new ExportAction(Lang.get("menu_exportSVG"), "svg", GraphicSVG::new)); JMenu file = new JMenu(Lang.get("menu_file")); diff --git a/src/main/java/de/neemann/digital/gui/Main.java b/src/main/java/de/neemann/digital/gui/Main.java index 76c62f42e..1e2073a47 100644 --- a/src/main/java/de/neemann/digital/gui/Main.java +++ b/src/main/java/de/neemann/digital/gui/Main.java @@ -542,20 +542,29 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS }.setAcceleratorCTRLplus('S').setEnabledChain(false); JMenu export = new JMenu(Lang.get("menu_export")); - export.add(new ExportAction(Lang.get("menu_exportSVG"), "svg", GraphicSVGIndex::new)); - export.add(new ExportAction(Lang.get("menu_exportSVGLaTex"), "svg", GraphicSVGLaTeX::new)); - export.add(new ExportAction(Lang.get("menu_exportSVGLaTexInOut"), "svg", GraphicSVGLaTeXInOut::new)); + export.add(new ExportAction(Lang.get("menu_exportSVG"), "svg", GraphicSVG::new)); + export.add(new ToolTipAction(Lang.get("menu_exportSVGSettings")) { + @Override + public void actionPerformed(ActionEvent actionEvent) { + ElementAttributes modified = new AttributeDialog(Main.this, SVGSettings.getInstance().getKeys(), SVGSettings.getInstance().getAttributes()).showDialog(); + SVGSettings.getInstance().getAttributes().getValuesFrom(modified); + } + }); + export.addSeparator(); export.add(new ExportAction(Lang.get("menu_exportPNGSmall"), "png", (out) -> new GraphicsImage(out, "PNG", 1))); export.add(new ExportAction(Lang.get("menu_exportPNGLarge"), "png", (out) -> new GraphicsImage(out, "PNG", 2))); if (isExperimentalMode()) export.add(new ExportGifAction(Lang.get("menu_exportAnimatedGIF"))); - export.add(new ExportZipAction(this).createJMenuItem()); + export.addSeparator(); export.add(createVHDLExportAction().createJMenuItem()); export.add(createVerilogExportAction().createJMenuItem()); + export.addSeparator(); + export.add(new ExportZipAction(this).createJMenuItem()); + JMenu file = new JMenu(Lang.get("menu_file")); menuBar.add(file); file.add(newFile.createJMenuItem()); diff --git a/src/main/java/de/neemann/digital/gui/Settings.java b/src/main/java/de/neemann/digital/gui/Settings.java index d3957f21b..d7f934d52 100644 --- a/src/main/java/de/neemann/digital/gui/Settings.java +++ b/src/main/java/de/neemann/digital/gui/Settings.java @@ -5,16 +5,10 @@ */ package de.neemann.digital.gui; -import com.thoughtworks.xstream.XStream; -import com.thoughtworks.xstream.io.xml.PrettyPrintWriter; -import de.neemann.digital.core.element.AttributeListener; import de.neemann.digital.core.element.ElementAttributes; import de.neemann.digital.core.element.Key; import de.neemann.digital.core.element.Keys; -import de.neemann.digital.draw.elements.Circuit; -import java.io.*; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -24,7 +18,7 @@ import java.util.List; *

* Created by Helmut.Neemann on 11.05.2016. */ -public final class Settings implements AttributeListener { +public final class Settings extends SettingsBase { private static final class SettingsHolder { static final Settings INSTANCE = new Settings(); @@ -39,11 +33,11 @@ public final class Settings implements AttributeListener { return SettingsHolder.INSTANCE; } - private final ElementAttributes attributes; - private final File filename; - private final List settingsKeys; - private Settings() { + super(createKeyList(), ".digital.cfg"); + } + + private static List createKeyList() { List intList = new ArrayList<>(); intList.add(Keys.SETTINGS_IEEE_SHAPES); intList.add(Keys.SETTINGS_LANGUAGE); @@ -63,64 +57,7 @@ public final class Settings implements AttributeListener { intList.add(Keys.SETTINGS_FONT_SCALING); intList.add(Keys.SETTINGS_MAC_MOUSE); - settingsKeys = Collections.unmodifiableList(intList); - - filename = new File(new File(System.getProperty("user.home")), ".digital.cfg"); - - ElementAttributes attr = null; - if (filename.exists()) { - XStream xStream = Circuit.getxStream(); - try (InputStream in = new FileInputStream(filename)) { - attr = (ElementAttributes) xStream.fromXML(in); - } catch (Exception e) { - e.printStackTrace(); - } - } - - if (attr == null) { - System.out.println("Use default settings!"); - attributes = new ElementAttributes(); - } else - attributes = attr; - - attributes.addListener(this); - } - - /** - * @return the settings - */ - public ElementAttributes getAttributes() { - return attributes; - } - - /** - * Gets a value from the settings. - * If the value is not present the default value is returned - * - * @param key the key - * @param the type of the value - * @return the value - */ - public VALUE get(Key key) { - return attributes.get(key); - } - - @Override - public void attributeChanged() { - XStream xStream = Circuit.getxStream(); - try (Writer out = new OutputStreamWriter(new FileOutputStream(filename), StandardCharsets.UTF_8)) { - out.write("\n"); - xStream.marshal(attributes, new PrettyPrintWriter(out)); - } catch (Exception e) { - e.printStackTrace(); - } - } - - /** - * @return the settings keys - */ - public List getKeys() { - return settingsKeys; + return Collections.unmodifiableList(intList); } /** @@ -130,8 +67,8 @@ public final class Settings implements AttributeListener { * @return true if the modification requires a restart */ public boolean requiresRestart(ElementAttributes modified) { - for (Key key : settingsKeys) - if (key.getRequiresRestart() && !attributes.equalsKey(key, modified)) + for (Key key : getKeys()) + if (key.getRequiresRestart() && !getAttributes().equalsKey(key, modified)) return true; return false; diff --git a/src/main/java/de/neemann/digital/gui/SettingsBase.java b/src/main/java/de/neemann/digital/gui/SettingsBase.java new file mode 100644 index 000000000..d5cd93953 --- /dev/null +++ b/src/main/java/de/neemann/digital/gui/SettingsBase.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2019 Helmut Neemann. + * Use of this source code is governed by the GPL v3 license + * that can be found in the LICENSE file. + */ +package de.neemann.digital.gui; + +import com.thoughtworks.xstream.XStream; +import com.thoughtworks.xstream.io.xml.PrettyPrintWriter; +import de.neemann.digital.core.element.AttributeListener; +import de.neemann.digital.core.element.ElementAttributes; +import de.neemann.digital.core.element.Key; +import de.neemann.digital.draw.elements.Circuit; + +import java.io.*; +import java.nio.charset.StandardCharsets; +import java.util.List; + +/** + * Base class for Settings + */ +public class SettingsBase implements AttributeListener { + + private final ElementAttributes attributes; + private final File filename; + private final List settingsKeys; + + /** + * Creates a new instance + * + * @param settingsKeys the list of keys + * @param name the filename + */ + protected SettingsBase(List settingsKeys, String name) { + this.settingsKeys = settingsKeys; + + filename = new File(new File(System.getProperty("user.home")), name); + + ElementAttributes attr = null; + if (filename.exists()) { + XStream xStream = Circuit.getxStream(); + try (InputStream in = new FileInputStream(filename)) { + attr = (ElementAttributes) xStream.fromXML(in); + } catch (Exception e) { + e.printStackTrace(); + } + } + + if (attr == null) { + System.out.println("Use default settings!"); + attributes = new ElementAttributes(); + } else + attributes = attr; + + attributes.addListener(this); + } + + /** + * @return the settings + */ + public ElementAttributes getAttributes() { + return attributes; + } + + /** + * Gets a value from the settings. + * If the value is not present the default value is returned + * + * @param key the key + * @param the type of the value + * @return the value + */ + public VALUE get(Key key) { + return attributes.get(key); + } + + @Override + public void attributeChanged() { + XStream xStream = Circuit.getxStream(); + try (Writer out = new OutputStreamWriter(new FileOutputStream(filename), StandardCharsets.UTF_8)) { + out.write("\n"); + xStream.marshal(attributes, new PrettyPrintWriter(out)); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * @return the settings keys + */ + public List getKeys() { + return settingsKeys; + } + +} diff --git a/src/main/java/de/neemann/digital/gui/components/data/GraphDialog.java b/src/main/java/de/neemann/digital/gui/components/data/GraphDialog.java index 200aafad1..5228d1c7a 100644 --- a/src/main/java/de/neemann/digital/gui/components/data/GraphDialog.java +++ b/src/main/java/de/neemann/digital/gui/components/data/GraphDialog.java @@ -165,8 +165,7 @@ public class GraphDialog extends JDialog implements Observer { .checkOverwrite(logData::saveCSV); } }.setToolTip(Lang.get("menu_saveData_tt")).createJMenuItem()); - file.add(new ExportAction(Lang.get("menu_exportSVG"), GraphicSVGIndex::new).createJMenuItem()); - file.add(new ExportAction(Lang.get("menu_exportSVGLaTex"), GraphicSVGLaTeX::new).createJMenuItem()); + file.add(new ExportAction(Lang.get("menu_exportSVG"), GraphicSVG::new).createJMenuItem()); JMenu view = new JMenu(Lang.get("menu_view")); bar.add(view); diff --git a/src/main/resources/lang/lang_de.xml b/src/main/resources/lang/lang_de.xml index f2d0874a0..e19f9d4e3 100644 --- a/src/main/resources/lang/lang_de.xml +++ b/src/main/resources/lang/lang_de.xml @@ -1360,6 +1360,22 @@ Sind evtl. die Namen der Variablen nicht eindeutig? Tutorial beim Start anzeigen Aktiviert das Tutorial. + SVG Exporteinstellungen + Text als LaTeX + Text wird in LaTeX-Notation eingefügt. Inkscape ist für die Weiterverabeitung erforderlich. + Testfälle verbergen + Die Testfälle werden nicht mit exportiert. + Polygone nicht ausfüllen + Polygone werden nicht ausgefüllt. + kleine Ein- und Ausgänge + Ein- und Ausgänge werden als kleine Kreise dargestellt. + keine Pin-Marker + Die Pin-Marker an den Symbolen entfallen. + hoher Kontrast + Leitungen und der Text der Pins werden in Schwarz ausgegeben. + Monochrom + Es werden nur Graustufen verwendet. + Leitung eingefügt. Aus Zwischenablage eingefügt. Wert ''{0}'' in Element ''{1}'' verändert. @@ -1421,8 +1437,6 @@ Sind evtl. die Namen der Variablen nicht eindeutig? Export PNG groß Export PNG klein Export SVG - Export SVG + LaTeX - Export SVG + LaTeX + kleine Ein- und Ausgänge Export Animated GIF Run To Break Führt die Schaltung aus, bis ein Stopsignal über ein BRK-Element detektiert wird. diff --git a/src/main/resources/lang/lang_en.xml b/src/main/resources/lang/lang_en.xml index 8378d82a2..94be813bf 100644 --- a/src/main/resources/lang/lang_en.xml +++ b/src/main/resources/lang/lang_en.xml @@ -1346,6 +1346,22 @@ Show Tutorial at Startup Enables the tutorial. + SVG Export Settings + Text as LaTeX + Text is inserted in LaTeX notation. Inkscape is required for further processing. + Hide Test Cases + The test cases are not exported. + Shapes not filled + Polygons are not filled. + Small Inputs and Outputs + Inputs and outputs are represented as small circles. + No Pin Marker + The pin markers at the symbols are omitted. + High Contrast + The wires and the text of the pins are displayed in black. + Monochrome + Only gray colors are used. + Inserted wire. Insert from clipboard. Value ''{0}'' in component ''{1}'' modified. @@ -1404,8 +1420,6 @@ Export PNG large Export PNG small Export SVG - Export SVG + LaTeX - Export SVG + LaTeX + small in/out Export Animated GIF Run to Break Runs the circuit until a break is detected by a BRK component. diff --git a/src/main/resources/lang/lang_es.xml b/src/main/resources/lang/lang_es.xml index 8c08421f4..79199f680 100644 --- a/src/main/resources/lang/lang_es.xml +++ b/src/main/resources/lang/lang_es.xml @@ -1222,8 +1222,6 @@ Exportar PNG grande Exportar PNG pequeño Exportar SVG - Exportar SVG + LaTeX - Exportar SVG + LaTeX + entradas/salidas pequeñas Exportar GIF animado Ejecutar hasta un Break Ejecuta el circuito hasta que un componente BRK detecta un break. diff --git a/src/main/resources/lang/lang_es_ref.xml b/src/main/resources/lang/lang_es_ref.xml index adacd0587..2e8849ba0 100644 --- a/src/main/resources/lang/lang_es_ref.xml +++ b/src/main/resources/lang/lang_es_ref.xml @@ -1235,8 +1235,6 @@ Export PNG large Export PNG small Export SVG - Export SVG + LaTeX - Export SVG + LaTeX + small in/out Export Animated GIF Run to Break Runs the circuit until a break is detected by a BRK component. diff --git a/src/main/resources/lang/lang_pt.xml b/src/main/resources/lang/lang_pt.xml index 002950369..1cebb2901 100644 --- a/src/main/resources/lang/lang_pt.xml +++ b/src/main/resources/lang/lang_pt.xml @@ -1289,8 +1289,6 @@ Exportar PNG grande Exportar PNG pequeno Exportar SVG - Exportar SVG + LaTeX - Exportar SVG + LaTeX + entrada/saídas pequenas Exportar GIF animado Executar com interrupção Executará o circuito até que uma interrupção seja detectada por uso de um componente BRK. diff --git a/src/main/resources/lang/lang_pt_ref.xml b/src/main/resources/lang/lang_pt_ref.xml index f9e8afdb2..e380381d8 100644 --- a/src/main/resources/lang/lang_pt_ref.xml +++ b/src/main/resources/lang/lang_pt_ref.xml @@ -1300,8 +1300,6 @@ Export PNG large Export PNG small Export SVG - Export SVG + LaTeX - Export SVG + LaTeX + small in/out Export Animated GIF Run to Break Runs the circuit until a break is detected by a BRK component. diff --git a/src/test/java/de/neemann/digital/docu/DocuTest.java b/src/test/java/de/neemann/digital/docu/DocuTest.java index 2f69a7840..a1e2a237f 100644 --- a/src/test/java/de/neemann/digital/docu/DocuTest.java +++ b/src/test/java/de/neemann/digital/docu/DocuTest.java @@ -7,12 +7,10 @@ package de.neemann.digital.docu; import de.neemann.digital.core.NodeException; import de.neemann.digital.core.element.*; -import de.neemann.digital.core.memory.Counter; 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.GraphicSVG; -import de.neemann.digital.draw.graphics.GraphicSVGIndex; import de.neemann.digital.draw.library.ElementLibrary; import de.neemann.digital.draw.library.LibraryNode; import de.neemann.digital.draw.library.NumStringComparator; @@ -160,7 +158,7 @@ public class DocuTest extends TestCase { private void writeSVG(File imageFile, VisualElement ve) throws IOException { try (FileOutputStream out = new FileOutputStream(imageFile)) { - try (GraphicSVG svg = new GraphicSVGIndex(out, null, 20)) { + try (GraphicSVG svg = new GraphicSVG(out,null, 20)) { GraphicMinMax minMax = new GraphicMinMax(true, svg); ve.drawTo(minMax, null); svg.setBoundingBox(minMax.getMin(), minMax.getMax()); diff --git a/src/test/java/de/neemann/digital/draw/graphics/GraphicSVGIndexTest.java b/src/test/java/de/neemann/digital/draw/graphics/GraphicSVGIndexTest.java index 0d5285aaa..b2620e302 100644 --- a/src/test/java/de/neemann/digital/draw/graphics/GraphicSVGIndexTest.java +++ b/src/test/java/de/neemann/digital/draw/graphics/GraphicSVGIndexTest.java @@ -10,13 +10,12 @@ import junit.framework.TestCase; /** */ public class GraphicSVGIndexTest extends TestCase { - public void testFormatText() throws Exception { - GraphicSVGIndex gs = new GraphicSVGIndex(System.out, null, 30); - gs.setBoundingBox(new Vector(0, 0), new Vector(30, 30)); + public void testFormatText() { + GraphicSVG.TextStyle gs = new TextFormatSVG(); - assertEquals("Z0", gs.formatText("Z_0", Style.NORMAL)); - assertEquals("<a>", gs.formatText("", Style.NORMAL)); - assertEquals("Z", gs.formatText("~Z", Style.NORMAL)); + assertEquals("Z0", gs.format("Z_0", Style.NORMAL)); + assertEquals("<a>", gs.format("", Style.NORMAL)); + assertEquals("Z", gs.format("~Z", Style.NORMAL)); } } diff --git a/src/test/java/de/neemann/digital/draw/graphics/GraphicSVGLaTeXTest.java b/src/test/java/de/neemann/digital/draw/graphics/GraphicSVGLaTeXTest.java index f6bdfbdbf..45cf712de 100644 --- a/src/test/java/de/neemann/digital/draw/graphics/GraphicSVGLaTeXTest.java +++ b/src/test/java/de/neemann/digital/draw/graphics/GraphicSVGLaTeXTest.java @@ -13,24 +13,24 @@ import java.io.IOException; */ public class GraphicSVGLaTeXTest extends TestCase { public void testFormatText() throws Exception { - GraphicSVGLaTeX gs = new GraphicSVGLaTeX(System.out, null, 30); + GraphicSVG.TextStyle gs = new TextFormatLaTeX(); - assertEquals("$Z_0$", gs.formatText("$Z_0$", Style.NORMAL)); - assertEquals("$Z_{in}$", gs.formatText("$Z_{in}$", Style.NORMAL)); - assertEquals("$Z_0$", gs.formatText("Z_0", Style.NORMAL)); - assertEquals("\\&", gs.formatText("&", Style.NORMAL)); - assertEquals("$\\geq\\!\\!{}$1", gs.formatText("\u22651", Style.NORMAL)); - assertEquals("$\\geq\\!\\!{}1$", gs.formatText("$\u22651$", Style.NORMAL)); - assertEquals("$\\overline{\\mbox{Q}}$", gs.formatText("~Q", Style.NORMAL)); - assertEquals("$\\overline{Q}$", gs.formatText("$~Q$", Style.NORMAL)); - assertEquals("\\textless{}a\\textgreater{}", gs.formatText("", Style.NORMAL)); - assertEquals("Grün", gs.formatText("Grün", Style.NORMAL)); + assertEquals("$Z_0$", gs.format("$Z_0$", Style.NORMAL)); + assertEquals("$Z_{in}$", gs.format("$Z_{in}$", Style.NORMAL)); + assertEquals("$Z_0$", gs.format("Z_0", Style.NORMAL)); + assertEquals("\\&", gs.format("&", Style.NORMAL)); + assertEquals("$\\geq\\!\\!{}$1", gs.format("\u22651", Style.NORMAL)); + assertEquals("$\\geq\\!\\!{}1$", gs.format("$\u22651$", Style.NORMAL)); + assertEquals("$\\overline{\\mbox{Q}}$", gs.format("~Q", Style.NORMAL)); + assertEquals("$\\overline{Q}$", gs.format("$~Q$", Style.NORMAL)); + assertEquals("\\textless{}a\\textgreater{}", gs.format("", Style.NORMAL)); + assertEquals("Grün", gs.format("Grün", Style.NORMAL)); - assertEquals("{\\scriptsize Grün}", gs.formatText("Grün", Style.SHAPE_PIN)); - assertEquals("{\\scriptsize $Z_0$}", gs.formatText("Z_0", Style.SHAPE_PIN)); - assertEquals("{\\tiny $Z_0$}", gs.formatText("Z_0", Style.SHAPE_SPLITTER)); - assertEquals("{\\tiny $Z_0$}", gs.formatText("Z_0", Style.WIRE_BITS)); + assertEquals("{\\scriptsize Grün}", gs.format("Grün", Style.SHAPE_PIN)); + assertEquals("{\\scriptsize $Z_0$}", gs.format("Z_0", Style.SHAPE_PIN)); + assertEquals("{\\tiny $Z_0$}", gs.format("Z_0", Style.SHAPE_SPLITTER)); + assertEquals("{\\tiny $Z_0$}", gs.format("Z_0", Style.WIRE_BITS)); } public void testCleanLabel() throws IOException { @@ -41,7 +41,7 @@ public class GraphicSVGLaTeXTest extends TestCase { } private void check(String orig, String LaTeX) throws IOException { - GraphicSVGLaTeX gs = new GraphicSVGLaTeX(System.out, null, 30); - assertEquals(LaTeX, gs.formatText(orig, Style.NORMAL)); + GraphicSVG.TextStyle gs = new TextFormatLaTeX(); + assertEquals(LaTeX, gs.format(orig, Style.NORMAL)); } } diff --git a/src/test/java/de/neemann/digital/draw/graphics/GraphicSVGTest.java b/src/test/java/de/neemann/digital/draw/graphics/GraphicSVGTest.java index 9bf6f03b9..e7f9b51da 100644 --- a/src/test/java/de/neemann/digital/draw/graphics/GraphicSVGTest.java +++ b/src/test/java/de/neemann/digital/draw/graphics/GraphicSVGTest.java @@ -11,11 +11,10 @@ import junit.framework.TestCase; */ public class GraphicSVGTest extends TestCase { public void testFormatText() throws Exception { - GraphicSVG gs = new GraphicSVG(System.out, null, 30); - gs.setBoundingBox(new Vector(0, 0), new Vector(30, 30)); + GraphicSVG.TextStyle gs = new TextFormatSVG(); - assertEquals("Z0", gs.formatText("Z0", Style.NORMAL)); - assertEquals("<a>", gs.formatText("", Style.NORMAL)); + assertEquals("Z0", gs.format("Z0", Style.NORMAL)); + assertEquals("<a>", gs.format("", Style.NORMAL)); } } diff --git a/src/test/java/de/neemann/digital/integration/TestExport.java b/src/test/java/de/neemann/digital/integration/TestExport.java index 4bec50a7a..122ea1e5d 100644 --- a/src/test/java/de/neemann/digital/integration/TestExport.java +++ b/src/test/java/de/neemann/digital/integration/TestExport.java @@ -31,19 +31,11 @@ public class TestExport extends TestCase { public void testSVGExport() throws NodeException, PinException, IOException, ElementNotFoundException { ByteArrayOutputStream baos = export("../../main/dig/processor/Processor.dig", - (out) -> new GraphicSVGIndex(out, null, 15)); + (out) -> new GraphicSVG(out, null, 15)); assertTrue(baos.size() > 20000); } - public void testSVGExportLaTeX() throws NodeException, PinException, IOException, ElementNotFoundException { - ByteArrayOutputStream baos - = export("../../main/dig/processor/Processor.dig", - (out) -> new GraphicSVGLaTeX(out, null, 15)); - - assertTrue(baos.size() > 15000); - } - public void testPNGExport() throws NodeException, PinException, IOException, ElementNotFoundException { ByteArrayOutputStream baos = export("../../main/dig/processor/Processor.dig",