From e6c560a1a8a5f8a1eecda6a54e84ab091167221a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88rg=20Prante?= Date: Tue, 21 Dec 2021 22:23:49 +0100 Subject: [PATCH] working on SVG salamander, but with little success --- graphics-pdfbox/build.gradle | 1 + .../graphics/pdfbox/test/RenderSVGsTest.java | 20 ++++- graphics-svg/src/main/java/module-info.java | 13 ++++ .../java/org/xbib/graphics/svg/Hkern.java | 42 ----------- .../java/org/xbib/graphics/svg/MarkerPos.java | 30 -------- .../java/org/xbib/graphics/svg/Metadata.java | 21 ------ .../org/xbib/graphics/svg/SVGDiagram.java | 8 +- .../java/org/xbib/graphics/svg/SVGIcon.java | 54 +++++--------- .../java/org/xbib/graphics/svg/SVGLoader.java | 37 +++++++--- .../xbib/graphics/svg/SVGLoaderHelper.java | 1 - .../java/org/xbib/graphics/svg/SVGRoot.java | 2 +- .../org/xbib/graphics/svg/SVGUniverse.java | 21 +++--- .../xbib/graphics/svg/{ => element}/A.java | 16 ++-- .../xbib/graphics/svg/element/ClipPath.java | 16 +--- .../org/xbib/graphics/svg/element/Defs.java | 7 +- .../org/xbib/graphics/svg/element/Desc.java | 6 +- .../org/xbib/graphics/svg/element/Filter.java | 73 ++++++++----------- .../org/xbib/graphics/svg/element/Font.java | 26 +++---- .../graphics/svg/{ => element}/FontFace.java | 14 +--- .../svg/{ => element}/FontSystem.java | 47 ++---------- .../org/xbib/graphics/svg/element/Hkern.java | 23 ++++++ .../graphics/svg/{ => element}/ImageSVG.java | 29 +++----- .../xbib/graphics/svg/element/Metadata.java | 14 ++++ .../svg/{ => element}/PatternSVG.java | 32 ++++---- .../svg/element/RenderableElement.java | 29 +++++--- .../xbib/graphics/svg/element/SVGElement.java | 16 ++-- .../graphics/svg/element/ShapeElement.java | 9 +-- .../xbib/graphics/svg/{ => element}/Stop.java | 25 +++++-- .../org/xbib/graphics/svg/element/Style.java | 15 +--- .../graphics/svg/{ => element}/Symbol.java | 16 ++-- .../graphics/svg/{ => element}/Title.java | 14 ++-- .../element/filtereffects/DistantLight.java | 8 +- .../element/filtereffects/FilterEffects.java | 53 +++++--------- .../svg/element/filtereffects/FilterOp.java | 12 ++- .../element/filtereffects/GaussianBlur.java | 17 +---- .../svg/element/filtereffects/Light.java | 4 +- .../svg/element/filtereffects/PointLight.java | 13 +--- .../svg/element/filtereffects/SpotLight.java | 20 +++-- .../graphics/svg/element/glyph/Glyph.java | 9 +-- .../svg/element/glyph/MissingGlyph.java | 7 +- .../svg/element/gradient/Gradient.java | 39 +++++----- .../{LinearGradient.java => Linear.java} | 18 ++--- .../{RadialGradient.java => Radial.java} | 22 ++---- .../svg/element/{ => shape}/Circle.java | 18 ++--- .../svg/element/{ => shape}/Ellipse.java | 20 ++--- .../svg/element/{ => shape}/Group.java | 16 ++-- .../svg/element/{ => shape}/Line.java | 19 ++--- .../svg/{ => element/shape}/Marker.java | 41 ++++------- .../svg/element/{ => shape}/Mask.java | 7 +- .../svg/{ => element/shape}/Path.java | 16 ++-- .../svg/{ => element/shape}/Polygon.java | 39 ++-------- .../svg/{ => element/shape}/Polyline.java | 16 ++-- .../svg/{ => element/shape}/Rect.java | 26 ++++--- .../svg/{ => element/shape}/Text.java | 69 ++++-------------- .../svg/{ => element/shape}/Tspan.java | 48 ++++++------ .../graphics/svg/{ => element/shape}/Use.java | 22 +++--- .../org/xbib/graphics/svg/pathcmd/Arc.java | 20 ++--- .../graphics/svg/pathcmd/BuildHistory.java | 21 ++++-- .../org/xbib/graphics/svg/pathcmd/Cubic.java | 21 ++++-- .../graphics/svg/pathcmd/CubicSmooth.java | 20 ++--- .../xbib/graphics/svg/pathcmd/Horizontal.java | 19 ++--- .../org/xbib/graphics/svg/pathcmd/LineTo.java | 10 +-- .../org/xbib/graphics/svg/pathcmd/MoveTo.java | 11 +-- .../graphics/svg/pathcmd/PathCommand.java | 7 +- .../xbib/graphics/svg/pathcmd/PathUtil.java | 42 ----------- .../xbib/graphics/svg/pathcmd/Quadratic.java | 15 ++-- .../graphics/svg/pathcmd/QuadraticSmooth.java | 29 ++++---- .../xbib/graphics/svg/pathcmd/Terminal.java | 17 ++--- .../xbib/graphics/svg/pathcmd/Vertical.java | 19 ++--- .../svg/{ => util}/AdobeComposite.java | 2 +- .../svg/{ => util}/AdobeCompositeContext.java | 2 +- .../graphics/svg/util/ClipPathConstants.java | 7 ++ .../org/xbib/graphics/svg/util/FontUtil.java | 42 ++++++++++- .../xbib/graphics/svg/{ => util}/Handler.java | 2 +- .../svg/{ => util}/HandlerFactory.java | 4 +- .../graphics/svg/{ => util}/MarkerLayout.java | 5 +- .../org/xbib/graphics/svg/util/MarkerPos.java | 62 ++++++++++++++++ .../org/xbib/graphics/svg/util/PaintUtil.java | 24 +++--- .../graphics/svg/{ => util}/PatternPaint.java | 2 +- .../svg/{ => util}/PatternPaintContext.java | 2 +- .../org/xbib/graphics/svg/util/TextConst.java | 41 +++++++++++ .../xbib/graphics/svg/util/VectorEffect.java | 7 ++ .../org/xbib/graphics/svg/xml/ColorTable.java | 2 +- .../xbib/graphics/svg/xml/XMLParseUtil.java | 4 +- .../graphics/svg/test/SimpleSVGLoadTest.java | 2 + .../org/xbib/graphics/svg/test/test.svg | 26 ------- 86 files changed, 774 insertions(+), 969 deletions(-) create mode 100644 graphics-svg/src/main/java/module-info.java delete mode 100644 graphics-svg/src/main/java/org/xbib/graphics/svg/Hkern.java delete mode 100644 graphics-svg/src/main/java/org/xbib/graphics/svg/MarkerPos.java delete mode 100644 graphics-svg/src/main/java/org/xbib/graphics/svg/Metadata.java rename graphics-svg/src/main/java/org/xbib/graphics/svg/{ => element}/A.java (83%) rename graphics-svg/src/main/java/org/xbib/graphics/svg/{ => element}/FontFace.java (95%) rename graphics-svg/src/main/java/org/xbib/graphics/svg/{ => element}/FontSystem.java (56%) create mode 100644 graphics-svg/src/main/java/org/xbib/graphics/svg/element/Hkern.java rename graphics-svg/src/main/java/org/xbib/graphics/svg/{ => element}/ImageSVG.java (93%) create mode 100644 graphics-svg/src/main/java/org/xbib/graphics/svg/element/Metadata.java rename graphics-svg/src/main/java/org/xbib/graphics/svg/{ => element}/PatternSVG.java (90%) rename graphics-svg/src/main/java/org/xbib/graphics/svg/{ => element}/Stop.java (83%) rename graphics-svg/src/main/java/org/xbib/graphics/svg/{ => element}/Symbol.java (88%) rename graphics-svg/src/main/java/org/xbib/graphics/svg/{ => element}/Title.java (63%) rename graphics-svg/src/main/java/org/xbib/graphics/svg/element/gradient/{LinearGradient.java => Linear.java} (93%) rename graphics-svg/src/main/java/org/xbib/graphics/svg/element/gradient/{RadialGradient.java => Radial.java} (92%) rename graphics-svg/src/main/java/org/xbib/graphics/svg/element/{ => shape}/Circle.java (89%) rename graphics-svg/src/main/java/org/xbib/graphics/svg/element/{ => shape}/Ellipse.java (89%) rename graphics-svg/src/main/java/org/xbib/graphics/svg/element/{ => shape}/Group.java (95%) rename graphics-svg/src/main/java/org/xbib/graphics/svg/element/{ => shape}/Line.java (91%) rename graphics-svg/src/main/java/org/xbib/graphics/svg/{ => element/shape}/Marker.java (81%) rename graphics-svg/src/main/java/org/xbib/graphics/svg/element/{ => shape}/Mask.java (97%) rename graphics-svg/src/main/java/org/xbib/graphics/svg/{ => element/shape}/Path.java (90%) rename graphics-svg/src/main/java/org/xbib/graphics/svg/{ => element/shape}/Polygon.java (78%) rename graphics-svg/src/main/java/org/xbib/graphics/svg/{ => element/shape}/Polyline.java (91%) rename graphics-svg/src/main/java/org/xbib/graphics/svg/{ => element/shape}/Rect.java (92%) rename graphics-svg/src/main/java/org/xbib/graphics/svg/{ => element/shape}/Text.java (70%) rename graphics-svg/src/main/java/org/xbib/graphics/svg/{ => element/shape}/Tspan.java (92%) rename graphics-svg/src/main/java/org/xbib/graphics/svg/{ => element/shape}/Use.java (93%) delete mode 100644 graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/PathUtil.java rename graphics-svg/src/main/java/org/xbib/graphics/svg/{ => util}/AdobeComposite.java (96%) rename graphics-svg/src/main/java/org/xbib/graphics/svg/{ => util}/AdobeCompositeContext.java (98%) create mode 100644 graphics-svg/src/main/java/org/xbib/graphics/svg/util/ClipPathConstants.java rename graphics-svg/src/main/java/org/xbib/graphics/svg/{ => util}/Handler.java (97%) rename graphics-svg/src/main/java/org/xbib/graphics/svg/{ => util}/HandlerFactory.java (84%) rename graphics-svg/src/main/java/org/xbib/graphics/svg/{ => util}/MarkerLayout.java (97%) create mode 100644 graphics-svg/src/main/java/org/xbib/graphics/svg/util/MarkerPos.java rename graphics-svg/src/main/java/org/xbib/graphics/svg/{ => util}/PatternPaint.java (96%) rename graphics-svg/src/main/java/org/xbib/graphics/svg/{ => util}/PatternPaintContext.java (98%) create mode 100644 graphics-svg/src/main/java/org/xbib/graphics/svg/util/TextConst.java create mode 100644 graphics-svg/src/main/java/org/xbib/graphics/svg/util/VectorEffect.java diff --git a/graphics-pdfbox/build.gradle b/graphics-pdfbox/build.gradle index 96fb267..924b579 100644 --- a/graphics-pdfbox/build.gradle +++ b/graphics-pdfbox/build.gradle @@ -1,4 +1,5 @@ dependencies { api "org.apache.pdfbox:pdfbox:${project.property('pdfbox.version')}" testImplementation "org.jfree:jfreechart:${project.property('jfreechart.version')}" + testImplementation project(':graphics-svg') } diff --git a/graphics-pdfbox/src/test/java/org/xbib/graphics/pdfbox/test/RenderSVGsTest.java b/graphics-pdfbox/src/test/java/org/xbib/graphics/pdfbox/test/RenderSVGsTest.java index 444e688..4bf5ead 100644 --- a/graphics-pdfbox/src/test/java/org/xbib/graphics/pdfbox/test/RenderSVGsTest.java +++ b/graphics-pdfbox/src/test/java/org/xbib/graphics/pdfbox/test/RenderSVGsTest.java @@ -24,10 +24,16 @@ import org.xbib.graphics.pdfbox.color.DefaultColorMapper; import org.xbib.graphics.pdfbox.color.RGBtoCMYKColorMapper; import org.xbib.graphics.pdfbox.font.DefaultFontDrawer; import org.xbib.graphics.pdfbox.font.FontDrawer; +import org.xbib.graphics.svg.SVGDiagram; +import org.xbib.graphics.svg.SVGException; +import org.xbib.graphics.svg.SVGUniverse; import java.awt.color.ICC_Profile; import java.io.File; import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.logging.Logger; public class RenderSVGsTest extends PdfBoxGraphics2DTestBase { @@ -63,7 +69,19 @@ public class RenderSVGsTest extends PdfBoxGraphics2DTestBase { renderSVGCMYK("atmospheric-composiition.svg", 0.7); } - private void renderSVG(String name, final double scale) throws IOException { + private void renderSVG(String name, final double scale) { + URL url = getClass().getResource(name); + SVGUniverse svgUniverse = new SVGUniverse(); + SVGDiagram diagram = svgUniverse.getDiagram(svgUniverse.loadSVG(url)); + exportGraphic("xbibsvg", name.replace(".svg", ""), gfx -> { + gfx.scale(scale, scale); + try { + diagram.render(gfx); + } catch (SVGException e) { + throw new IllegalArgumentException(e); + } + }); + /*String uri = RenderSVGsTest.class.getResource(name).toString(); SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(); Document document = f.createDocument(uri, RenderSVGsTest.class.getResourceAsStream(name)); diff --git a/graphics-svg/src/main/java/module-info.java b/graphics-svg/src/main/java/module-info.java new file mode 100644 index 0000000..3a03a17 --- /dev/null +++ b/graphics-svg/src/main/java/module-info.java @@ -0,0 +1,13 @@ +module org.xbib.graphics.svg { + requires transitive java.desktop; + requires java.logging; + exports org.xbib.graphics.svg; + exports org.xbib.graphics.svg.element; + exports org.xbib.graphics.svg.element.filtereffects; + exports org.xbib.graphics.svg.element.glyph; + exports org.xbib.graphics.svg.element.gradient; + exports org.xbib.graphics.svg.element.shape; + exports org.xbib.graphics.svg.pathcmd; + exports org.xbib.graphics.svg.xml; + exports org.xbib.graphics.svg.util; +} \ No newline at end of file diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/Hkern.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/Hkern.java deleted file mode 100644 index f71b359..0000000 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/Hkern.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.xbib.graphics.svg; - -import org.xbib.graphics.svg.element.SVGElement; -import org.xbib.graphics.svg.xml.StyleAttribute; - -import java.io.IOException; - -public class Hkern extends SVGElement { - - public static final String TAG_NAME = "hkern"; - - String u1; - - String u2; - - int k; - - @Override - public String getTagName() { - return TAG_NAME; - } - - @Override - protected void build() throws SVGException, IOException { - super.build(); - StyleAttribute sty = new StyleAttribute(); - if (getPres(sty.setName("u1"))) { - u1 = sty.getStringValue(); - } - if (getPres(sty.setName("u2"))) { - u2 = sty.getStringValue(); - } - if (getPres(sty.setName("k"))) { - k = sty.getIntValue(); - } - } - - @Override - public boolean updateTime(double curTime) throws SVGException { - return false; - } -} diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/MarkerPos.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/MarkerPos.java deleted file mode 100644 index a84b340..0000000 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/MarkerPos.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.xbib.graphics.svg; - -public class MarkerPos { - - private int type; - - double x; - - double y; - - double dx; - - double dy; - - public MarkerPos(int type, double x, double y, double dx, double dy) { - this.type = type; - this.x = x; - this.y = y; - this.dx = dx; - this.dy = dy; - } - - public void setType(int type) { - this.type = type; - } - - public int getType() { - return type; - } -} diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/Metadata.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/Metadata.java deleted file mode 100644 index 4480838..0000000 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/Metadata.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.xbib.graphics.svg; - -import org.xbib.graphics.svg.element.SVGElement; - -public class Metadata extends SVGElement { - - public static final String TAG_NAME = "metadata"; - - public Metadata() { - } - - @Override - public String getTagName() { - return TAG_NAME; - } - - @Override - public boolean updateTime(double curTime) { - return false; - } -} diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/SVGDiagram.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/SVGDiagram.java index 1f35d97..4837305 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/SVGDiagram.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/SVGDiagram.java @@ -20,17 +20,17 @@ public class SVGDiagram { private static final Logger logger = Logger.getLogger(SVGDiagram.class.getName()); - final Map idMap = new HashMap<>(); + private final Map idMap = new HashMap<>(); - SVGRoot root; + private SVGRoot root; - final SVGUniverse universe; + private final SVGUniverse universe; private final Rectangle deviceViewport = new Rectangle(100, 100); protected boolean ignoreClipHeuristic = false; - final URI xmlBase; + private final URI xmlBase; public SVGDiagram(URI xmlBase, SVGUniverse universe) { this.universe = universe; diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/SVGIcon.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/SVGIcon.java index 1f8cb14..6de2886 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/SVGIcon.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/SVGIcon.java @@ -12,59 +12,47 @@ import java.awt.RenderingHints; import java.awt.geom.AffineTransform; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; import java.io.IOException; import java.net.URI; @SuppressWarnings("serial") public class SVGIcon extends ImageIcon { - public static final String PROP_AUTOSIZE = "PROP_AUTOSIZE"; + private SVGUniverse svgUniverse = new SVGUniverse(); - private final PropertyChangeSupport changes = new PropertyChangeSupport(this); + private static final int INTERP_NEAREST_NEIGHBOR = 0; - SVGUniverse svgUniverse = new SVGUniverse(); + private static final int INTERP_BILINEAR = 1; - public static final int INTERP_NEAREST_NEIGHBOR = 0; + private static final int INTERP_BICUBIC = 2; - public static final int INTERP_BILINEAR = 1; + private static final int AUTOSIZE_NONE = 0; - public static final int INTERP_BICUBIC = 2; + private static final int AUTOSIZE_HORIZ = 1; + + private static final int AUTOSIZE_VERT = 2; + + private static final int AUTOSIZE_BESTFIT = 3; + + private static final int AUTOSIZE_STRETCH = 4; private boolean antiAlias; + private int interpolation = INTERP_NEAREST_NEIGHBOR; + private boolean clipToViewbox; - URI svgURI; + private URI svgURI; - AffineTransform scaleXform = new AffineTransform(); - - public static final int AUTOSIZE_NONE = 0; - - public static final int AUTOSIZE_HORIZ = 1; - - public static final int AUTOSIZE_VERT = 2; - - public static final int AUTOSIZE_BESTFIT = 3; - - public static final int AUTOSIZE_STRETCH = 4; + private final AffineTransform scaleXform = new AffineTransform(); private int autosize = AUTOSIZE_NONE; - Dimension preferredSize; + private Dimension preferredSize; public SVGIcon() { } - public void addPropertyChangeListener(PropertyChangeListener p) { - changes.addPropertyChangeListener(p); - } - - public void removePropertyChangeListener(PropertyChangeListener p) { - changes.removePropertyChangeListener(p); - } - @Override public Image getImage() { BufferedImage bi = new BufferedImage(getIconWidth(), getIconHeight(), BufferedImage.TYPE_INT_ARGB); @@ -211,7 +199,6 @@ public class SVGIcon extends ImageIcon { public void setSvgUniverse(SVGUniverse svgUniverse) { SVGUniverse old = this.svgUniverse; this.svgUniverse = svgUniverse; - changes.firePropertyChange("svgUniverse", old, svgUniverse); } public URI getSvgURI() { @@ -229,14 +216,12 @@ public class SVGIcon extends ImageIcon { } diagram.setDeviceViewport(new Rectangle(0, 0, size.width, size.height)); } - changes.firePropertyChange("svgURI", old, svgURI); } public void setSvgResourcePath(String resourcePath) { URI old = this.svgURI; try { svgURI = new URI(getClass().getResource(resourcePath).toString()); - changes.firePropertyChange("svgURI", old, svgURI); SVGDiagram diagram = svgUniverse.getDiagram(svgURI); if (diagram != null) { diagram.setDeviceViewport(new Rectangle(0, 0, preferredSize.width, preferredSize.height)); @@ -272,8 +257,6 @@ public class SVGIcon extends ImageIcon { if (diagram != null) { diagram.setDeviceViewport(new Rectangle(0, 0, preferredSize.width, preferredSize.height)); } - - changes.firePropertyChange("preferredSize", old, preferredSize); } public boolean getUseAntiAlias() { @@ -291,7 +274,6 @@ public class SVGIcon extends ImageIcon { public void setAntiAlias(boolean antiAlias) { boolean old = this.antiAlias; this.antiAlias = antiAlias; - changes.firePropertyChange("antiAlias", old, antiAlias); } public int getInterpolation() { @@ -301,7 +283,6 @@ public class SVGIcon extends ImageIcon { public void setInterpolation(int interpolation) { int old = this.interpolation; this.interpolation = interpolation; - changes.firePropertyChange("interpolation", old, interpolation); } public boolean isClipToViewbox() { @@ -319,6 +300,5 @@ public class SVGIcon extends ImageIcon { public void setAutosize(int autosize) { int oldAutosize = this.autosize; this.autosize = autosize; - changes.firePropertyChange(PROP_AUTOSIZE, oldAutosize, autosize); } } diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/SVGLoader.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/SVGLoader.java index a07d671..dc6b59b 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/SVGLoader.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/SVGLoader.java @@ -1,23 +1,40 @@ package org.xbib.graphics.svg; -import org.xbib.graphics.svg.element.Circle; +import org.xbib.graphics.svg.element.A; +import org.xbib.graphics.svg.element.Metadata; +import org.xbib.graphics.svg.element.PatternSVG; +import org.xbib.graphics.svg.element.Stop; +import org.xbib.graphics.svg.element.Symbol; +import org.xbib.graphics.svg.element.Title; +import org.xbib.graphics.svg.element.shape.Circle; import org.xbib.graphics.svg.element.ClipPath; import org.xbib.graphics.svg.element.Defs; import org.xbib.graphics.svg.element.Desc; -import org.xbib.graphics.svg.element.Ellipse; +import org.xbib.graphics.svg.element.shape.Ellipse; import org.xbib.graphics.svg.element.Filter; import org.xbib.graphics.svg.element.Font; -import org.xbib.graphics.svg.element.Group; -import org.xbib.graphics.svg.element.Line; -import org.xbib.graphics.svg.element.Mask; +import org.xbib.graphics.svg.element.FontFace; +import org.xbib.graphics.svg.element.shape.Group; +import org.xbib.graphics.svg.element.Hkern; +import org.xbib.graphics.svg.element.ImageSVG; +import org.xbib.graphics.svg.element.shape.Line; +import org.xbib.graphics.svg.element.shape.Marker; +import org.xbib.graphics.svg.element.shape.Mask; import org.xbib.graphics.svg.element.SVGElement; import org.xbib.graphics.svg.element.ShapeElement; import org.xbib.graphics.svg.element.Style; import org.xbib.graphics.svg.element.filtereffects.GaussianBlur; import org.xbib.graphics.svg.element.glyph.Glyph; import org.xbib.graphics.svg.element.glyph.MissingGlyph; -import org.xbib.graphics.svg.element.gradient.LinearGradient; -import org.xbib.graphics.svg.element.gradient.RadialGradient; +import org.xbib.graphics.svg.element.gradient.Linear; +import org.xbib.graphics.svg.element.gradient.Radial; +import org.xbib.graphics.svg.element.shape.Path; +import org.xbib.graphics.svg.element.shape.Polygon; +import org.xbib.graphics.svg.element.shape.Polyline; +import org.xbib.graphics.svg.element.shape.Rect; +import org.xbib.graphics.svg.element.shape.Text; +import org.xbib.graphics.svg.element.shape.Tspan; +import org.xbib.graphics.svg.element.shape.Use; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; @@ -58,7 +75,7 @@ public class SVGLoader extends DefaultHandler { nodeClasses.put("desc", Desc.class); nodeClasses.put("ellipse", Ellipse.class); nodeClasses.put("filter", Filter.class); - nodeClasses.put(GaussianBlur.TAG_NAME, GaussianBlur.class); + nodeClasses.put("fegaussianblur", GaussianBlur.class); nodeClasses.put("font", Font.class); nodeClasses.put("font-face", FontFace.class); nodeClasses.put("g", Group.class); @@ -66,7 +83,7 @@ public class SVGLoader extends DefaultHandler { nodeClasses.put("hkern", Hkern.class); nodeClasses.put("image", ImageSVG.class); nodeClasses.put("line", Line.class); - nodeClasses.put("lineargradient", LinearGradient.class); + nodeClasses.put("lineargradient", Linear.class); nodeClasses.put("marker", Marker.class); nodeClasses.put("mask", Mask.class); nodeClasses.put("metadata", Metadata.class); @@ -75,7 +92,7 @@ public class SVGLoader extends DefaultHandler { nodeClasses.put("pattern", PatternSVG.class); nodeClasses.put("polygon", Polygon.class); nodeClasses.put("polyline", Polyline.class); - nodeClasses.put("radialgradient", RadialGradient.class); + nodeClasses.put("radialgradient", Radial.class); nodeClasses.put("rect", Rect.class); nodeClasses.put("shape", ShapeElement.class); nodeClasses.put("stop", Stop.class); diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/SVGLoaderHelper.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/SVGLoaderHelper.java index 4db9e79..3412a4f 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/SVGLoaderHelper.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/SVGLoaderHelper.java @@ -14,5 +14,4 @@ public class SVGLoaderHelper { this.universe = universe; this.diagram = diagram; } - } diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/SVGRoot.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/SVGRoot.java index 329d815..3c839e3 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/SVGRoot.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/SVGRoot.java @@ -1,7 +1,7 @@ package org.xbib.graphics.svg; import org.xbib.graphics.svg.element.Defs; -import org.xbib.graphics.svg.element.Group; +import org.xbib.graphics.svg.element.shape.Group; import org.xbib.graphics.svg.element.SVGElement; import org.xbib.graphics.svg.element.Style; import org.xbib.graphics.svg.xml.NumberWithUnits; diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/SVGUniverse.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/SVGUniverse.java index 9b7f5ae..d749655 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/SVGUniverse.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/SVGUniverse.java @@ -37,13 +37,11 @@ public class SVGUniverse { private static final Logger logger = Logger.getLogger(SVGUniverse.class.getName()); - final Map loadedDocs = new HashMap<>(); + private final Map loadedDocs = new HashMap<>(); - final Map loadedFonts = new HashMap<>(); + private final Map loadedFonts = new HashMap<>(); - final Map> loadedImages = new HashMap<>(); - - public static final String INPUTSTREAM_SCHEME = "svgXbib"; + private final Map> loadedImages = new HashMap<>(); protected double curTime = 0.0; @@ -131,7 +129,7 @@ public class SVGUniverse { } } - void registerImage(URL imageURL) { + public void registerImage(URL imageURL) { if (loadedImages.containsKey(imageURL)) { return; } @@ -156,7 +154,7 @@ public class SVGUniverse { } } - BufferedImage getImage(URL imageURL) throws IOException { + public BufferedImage getImage(URL imageURL) throws IOException { SoftReference ref = loadedImages.get(imageURL); if (ref == null) { return null; @@ -202,12 +200,13 @@ public class SVGUniverse { } public SVGElement getElement(URI path, boolean loadIfAbsent) { + path = cleanUri(path); try { - path = cleanUri(path); URI xmlBase = new URI(path.getScheme(), path.getSchemeSpecificPart(), null); SVGDiagram dia = loadedDocs.get(xmlBase); if (dia == null && loadIfAbsent) { - URL url = xmlBase.toURL(); + URL url; + url = xmlBase.toURL(); loadSVG(url, false); dia = loadedDocs.get(xmlBase); if (dia == null) { @@ -216,7 +215,7 @@ public class SVGUniverse { } String fragment = path.getFragment(); return fragment == null ? dia.getRoot() : dia.getElement(fragment); - } catch (Exception e) { + } catch (MalformedURLException | URISyntaxException e) { logger.log(Level.SEVERE, "Could not parse path " + path, e); return null; } @@ -323,7 +322,7 @@ public class SVGUniverse { name = '/' + name; } try { - return new URI(INPUTSTREAM_SCHEME, name, null); + return new URI("svg", name, null); } catch (Exception e) { logger.log(Level.SEVERE, "Could not parse", e); return null; diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/A.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/A.java similarity index 83% rename from graphics-svg/src/main/java/org/xbib/graphics/svg/A.java rename to graphics-svg/src/main/java/org/xbib/graphics/svg/element/A.java index c94cb38..64321ec 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/A.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/A.java @@ -1,6 +1,7 @@ -package org.xbib.graphics.svg; +package org.xbib.graphics.svg.element; -import org.xbib.graphics.svg.element.Group; +import org.xbib.graphics.svg.SVGException; +import org.xbib.graphics.svg.element.shape.Group; import org.xbib.graphics.svg.xml.StyleAttribute; import java.io.IOException; @@ -8,18 +9,13 @@ import java.net.URI; public class A extends Group { - public static final String TAG_NAME = "a"; + private URI href; - URI href; - - String title; - - public A() { - } + private String title; @Override public String getTagName() { - return TAG_NAME; + return "a"; } @Override diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/ClipPath.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/ClipPath.java index 035dd30..0fdd576 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/ClipPath.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/ClipPath.java @@ -1,28 +1,20 @@ package org.xbib.graphics.svg.element; import org.xbib.graphics.svg.SVGException; +import org.xbib.graphics.svg.util.ClipPathConstants; import org.xbib.graphics.svg.xml.StyleAttribute; import java.awt.Shape; import java.awt.geom.Area; import java.io.IOException; -public class ClipPath extends SVGElement { +public class ClipPath extends SVGElement implements ClipPathConstants { - public static final String TAG_NAME = "clippath"; - - public static final int CP_USER_SPACE_ON_USE = 0; - - public static final int CP_OBJECT_BOUNDING_BOX = 1; - - int clipPathUnits = CP_USER_SPACE_ON_USE; - - public ClipPath() { - } + private int clipPathUnits = CP_USER_SPACE_ON_USE; @Override public String getTagName() { - return TAG_NAME; + return "clippath"; } @Override diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/Defs.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/Defs.java index acade91..b923f66 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/Defs.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/Defs.java @@ -7,14 +7,9 @@ import java.io.IOException; public class Defs extends TransformableElement { - public static final String TAG_NAME = "defs"; - - public Defs() { - } - @Override public String getTagName() { - return TAG_NAME; + return "defs"; } @Override diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/Desc.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/Desc.java index 73d8c45..4d08b5f 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/Desc.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/Desc.java @@ -4,13 +4,11 @@ import org.xbib.graphics.svg.SVGLoaderHelper; public class Desc extends SVGElement { - public static final String TAG_NAME = "desc"; - - StringBuilder text = new StringBuilder(); + private final StringBuilder text = new StringBuilder(); @Override public String getTagName() { - return TAG_NAME; + return "desc"; } @Override diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/Filter.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/Filter.java index 6b6b564..9272251 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/Filter.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/Filter.java @@ -14,38 +14,51 @@ import java.util.List; public class Filter extends SVGElement { - public static final String TAG_NAME = "filter"; + private static final int FU_OBJECT_BOUNDING_BOX = 0; - public static final int FU_OBJECT_BOUNDING_BOX = 0; + private static final int FU_USER_SPACE_ON_USE = 1; - public static final int FU_USER_SPACE_ON_USE = 1; + private static final int PU_OBJECT_BOUNDING_BOX = 0; - public int filterUnits = FU_OBJECT_BOUNDING_BOX; + private static final int PU_USER_SPACE_ON_USE = 1; - public static final int PU_OBJECT_BOUNDING_BOX = 0; + private int filterUnits = FU_OBJECT_BOUNDING_BOX; - public static final int PU_USER_SPACE_ON_USE = 1; + private float x = 0f; - protected int primitiveUnits = PU_OBJECT_BOUNDING_BOX; + private float y = 0f; - float x = 0f; + private float width = 1f; - float y = 0f; + private float height = 1f; - float width = 1f; + private URL href = null; - float height = 1f; - - URL href = null; - - public final List filterEffects = new ArrayList<>(); - - public Filter() { - } + private final List filterEffects = new ArrayList<>(); @Override public String getTagName() { - return TAG_NAME; + return "filter"; + } + + public List getFilterEffects() { + return filterEffects; + } + + public float getX() { + return x; + } + + public float getY() { + return y; + } + + public float getWidth() { + return width; + } + + public float getHeight() { + return height; } @Override @@ -71,11 +84,6 @@ public class Filter extends SVGElement { } if (getPres(sty.setName("primitiveUnits"))) { strn = sty.getStringValue().toLowerCase(); - if (strn.equals("userspaceonuse")) { - primitiveUnits = PU_USER_SPACE_ON_USE; - } else { - primitiveUnits = PU_OBJECT_BOUNDING_BOX; - } } if (getPres(sty.setName("x"))) { x = sty.getFloatValueWithUnits(); @@ -100,22 +108,6 @@ public class Filter extends SVGElement { } - public float getX() { - return x; - } - - public float getY() { - return y; - } - - public float getWidth() { - return width; - } - - public float getHeight() { - return height; - } - @Override public boolean updateTime(double curTime) throws SVGException { StyleAttribute sty = new StyleAttribute(); @@ -183,7 +175,6 @@ public class Filter extends SVGElement { newVal = PU_OBJECT_BOUNDING_BOX; } if (newVal != filterUnits) { - primitiveUnits = newVal; stateChange = true; } } diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/Font.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/Font.java index c74fb30..1e37756 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/Font.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/Font.java @@ -1,6 +1,5 @@ package org.xbib.graphics.svg.element; -import org.xbib.graphics.svg.FontFace; import org.xbib.graphics.svg.element.glyph.Glyph; import org.xbib.graphics.svg.element.glyph.MissingGlyph; import org.xbib.graphics.svg.SVGElementException; @@ -15,32 +14,27 @@ import java.util.Map; public class Font extends SVGElement { - public static final String TAG_NAME = "font"; + private int horizOriginX = 0; - int horizOriginX = 0; + private int horizOriginY = 0; - int horizOriginY = 0; + private int horizAdvX = -1; - int horizAdvX = -1; + private int vertOriginX = -1; - int vertOriginX = -1; + private int vertOriginY = -1; - int vertOriginY = -1; + private int vertAdvY = -1; - int vertAdvY = -1; + private FontFace fontFace = null; - FontFace fontFace = null; + private MissingGlyph missingGlyph = null; - MissingGlyph missingGlyph = null; - - final Map glyphs = new HashMap<>(); - - public Font() { - } + private final Map glyphs = new HashMap<>(); @Override public String getTagName() { - return TAG_NAME; + return "font"; } @Override diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/FontFace.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/FontFace.java similarity index 95% rename from graphics-svg/src/main/java/org/xbib/graphics/svg/FontFace.java rename to graphics-svg/src/main/java/org/xbib/graphics/svg/element/FontFace.java index 6b6cae6..2413a37 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/FontFace.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/FontFace.java @@ -1,16 +1,13 @@ -package org.xbib.graphics.svg; +package org.xbib.graphics.svg.element; -import org.xbib.graphics.svg.element.Font; -import org.xbib.graphics.svg.element.SVGElement; +import org.xbib.graphics.svg.SVGException; import org.xbib.graphics.svg.xml.StyleAttribute; import java.io.IOException; public class FontFace extends SVGElement { - public static final String TAG_NAME = "fontface"; - - String fontFamily; + private String fontFamily; private int unitsPerEm = 1000; @@ -32,12 +29,9 @@ public class FontFace extends SVGElement { private int overlineThickness = -1; - public FontFace() { - } - @Override public String getTagName() { - return TAG_NAME; + return "fontface"; } @Override diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/FontSystem.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/FontSystem.java similarity index 56% rename from graphics-svg/src/main/java/org/xbib/graphics/svg/FontSystem.java rename to graphics-svg/src/main/java/org/xbib/graphics/svg/element/FontSystem.java index cce01f5..f52adb9 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/FontSystem.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/FontSystem.java @@ -1,60 +1,23 @@ -package org.xbib.graphics.svg; +package org.xbib.graphics.svg.element; -import org.xbib.graphics.svg.element.Font; import org.xbib.graphics.svg.element.glyph.Glyph; import org.xbib.graphics.svg.element.glyph.MissingGlyph; +import org.xbib.graphics.svg.element.shape.Text; -import java.awt.GraphicsEnvironment; import java.awt.font.FontRenderContext; import java.awt.font.GlyphMetrics; import java.awt.font.GlyphVector; import java.awt.font.LineMetrics; -import java.util.Collections; import java.util.HashMap; -import java.util.HashSet; -import java.util.Locale; import java.util.Map; -import java.util.Set; public class FontSystem extends Font { - java.awt.Font sysFont; + private final java.awt.Font sysFont; - Map glyphCache = new HashMap<>(); + private final Map glyphCache = new HashMap<>(); - static Set sysFontNames = new HashSet<>(); - - public static boolean checkIfSystemFontExists(String fontName) { - if (sysFontNames.isEmpty()) { - Collections.addAll(sysFontNames, GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(Locale.ENGLISH)); - } - - return sysFontNames.contains(fontName); - } - - public static FontSystem createFont(String[] fontFamilies, int fontStyle, int fontWeight, float fontSize) { - for (String fontName : fontFamilies) { - String javaFontName = mapJavaFontName(fontName); - if (checkIfSystemFontExists(javaFontName)) { - return new FontSystem(javaFontName, fontStyle, fontWeight, fontSize); - } - } - - return null; - } - - private static String mapJavaFontName(String fontName) { - if ("serif".equals(fontName)) { - return java.awt.Font.SERIF; - } else if ("sans-serif".equals(fontName)) { - return java.awt.Font.SANS_SERIF; - } else if ("monospace".equals(fontName)) { - return java.awt.Font.MONOSPACED; - } - return fontName; - } - - private FontSystem(String fontFamily, int fontStyle, int fontWeight, float fontSize) { + public FontSystem(String fontFamily, int fontStyle, int fontWeight, float fontSize) { int style; if (fontStyle == Text.TXST_ITALIC) { style = java.awt.Font.ITALIC; diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/Hkern.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/Hkern.java new file mode 100644 index 0000000..3ccc724 --- /dev/null +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/Hkern.java @@ -0,0 +1,23 @@ +package org.xbib.graphics.svg.element; + +import org.xbib.graphics.svg.SVGException; + +import java.io.IOException; + +public class Hkern extends SVGElement { + + @Override + public String getTagName() { + return "hkern"; + } + + @Override + protected void build() throws SVGException, IOException { + super.build(); + } + + @Override + public boolean updateTime(double curTime) throws SVGException { + return false; + } +} diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/ImageSVG.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/ImageSVG.java similarity index 93% rename from graphics-svg/src/main/java/org/xbib/graphics/svg/ImageSVG.java rename to graphics-svg/src/main/java/org/xbib/graphics/svg/element/ImageSVG.java index 7e67d90..f82edb7 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/ImageSVG.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/ImageSVG.java @@ -1,7 +1,7 @@ -package org.xbib.graphics.svg; +package org.xbib.graphics.svg.element; -import org.xbib.graphics.svg.element.RenderableElement; -import org.xbib.graphics.svg.element.SVGElement; +import org.xbib.graphics.svg.SVGException; +import org.xbib.graphics.svg.util.Handler; import org.xbib.graphics.svg.xml.StyleAttribute; import java.awt.AlphaComposite; @@ -22,28 +22,23 @@ public class ImageSVG extends RenderableElement { private static final Logger logger = Logger.getLogger(ImageSVG.class.getName()); - public static final String TAG_NAME = "image"; + private float x = 0f; - float x = 0f; + private float y = 0f; - float y = 0f; + private float width = 0f; - float width = 0f; + private float height = 0f; - float height = 0f; + private URL imageSrc = null; - URL imageSrc = null; + private AffineTransform xform; - AffineTransform xform; - - Rectangle2D bounds; - - public ImageSVG() { - } + private Rectangle2D bounds; @Override public String getTagName() { - return TAG_NAME; + return "image"; } @Override @@ -223,7 +218,7 @@ public class ImageSVG extends RenderableElement { logger.log(Level.SEVERE, "Image provided with illegal value for href: \"" + sty.getStringValue() + '"', ie); } catch (Exception e) { - logger.log(Level.WARNING, "Could not parse xlink:href", e); + logger.log(Level.SEVERE, "Could not parse xlink:href", e); } if (shapeChange) { build(); diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/Metadata.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/Metadata.java new file mode 100644 index 0000000..ae0e432 --- /dev/null +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/Metadata.java @@ -0,0 +1,14 @@ +package org.xbib.graphics.svg.element; + +public class Metadata extends SVGElement { + + @Override + public String getTagName() { + return "metadata"; + } + + @Override + public boolean updateTime(double curTime) { + return false; + } +} diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/PatternSVG.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/PatternSVG.java similarity index 90% rename from graphics-svg/src/main/java/org/xbib/graphics/svg/PatternSVG.java rename to graphics-svg/src/main/java/org/xbib/graphics/svg/element/PatternSVG.java index 68d2ba7..34f25a2 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/PatternSVG.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/PatternSVG.java @@ -1,8 +1,9 @@ -package org.xbib.graphics.svg; +package org.xbib.graphics.svg.element; -import org.xbib.graphics.svg.element.FillElement; -import org.xbib.graphics.svg.element.RenderableElement; -import org.xbib.graphics.svg.element.SVGElement; +import org.xbib.graphics.svg.util.PatternPaint; +import org.xbib.graphics.svg.SVGElementException; +import org.xbib.graphics.svg.SVGException; +import org.xbib.graphics.svg.SVGLoaderHelper; import org.xbib.graphics.svg.xml.StyleAttribute; import java.awt.Graphics2D; @@ -18,34 +19,29 @@ import java.net.URI; public class PatternSVG extends FillElement { - public static final String TAG_NAME = "pattern"; - public static final int GU_OBJECT_BOUNDING_BOX = 0; public static final int GU_USER_SPACE_ON_USE = 1; - int gradientUnits = GU_OBJECT_BOUNDING_BOX; + private int gradientUnits = GU_OBJECT_BOUNDING_BOX; - float x; + private float x; - float y; + private float y; - float width; + private float width; - float height; + private float height; - AffineTransform patternXform = new AffineTransform(); + private AffineTransform patternXform = new AffineTransform(); - Rectangle2D.Float viewBox; + private Rectangle2D.Float viewBox; - Paint texPaint; - - public PatternSVG() { - } + private Paint texPaint; @Override public String getTagName() { - return TAG_NAME; + return "pattern"; } @Override diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/RenderableElement.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/RenderableElement.java index 0673991..2e9c470 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/RenderableElement.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/RenderableElement.java @@ -1,8 +1,11 @@ package org.xbib.graphics.svg.element; import org.xbib.graphics.svg.SVGException; +import org.xbib.graphics.svg.element.shape.Mask; +import org.xbib.graphics.svg.util.ClipPathConstants; import org.xbib.graphics.svg.util.PaintCache; import org.xbib.graphics.svg.util.PaintUtil; +import org.xbib.graphics.svg.util.VectorEffect; import org.xbib.graphics.svg.xml.StyleAttribute; import java.awt.Graphics2D; @@ -15,19 +18,15 @@ import java.io.IOException; import java.net.URI; import java.util.List; -public abstract class RenderableElement extends TransformableElement { +public abstract class RenderableElement extends TransformableElement implements VectorEffect { - protected AffineTransform cachedXform = null; + protected AffineTransform cachedXform; - public Mask cachedMask; + private Mask cachedMask; - public Filter filter; + private Filter filter; - protected Shape cachedClip = null; - - public static final int VECTOR_EFFECT_NONE = 0; - - public static final int VECTOR_EFFECT_NON_SCALING_STROKE = 1; + private Shape cachedClip; protected int vectorEffect; @@ -40,6 +39,14 @@ public abstract class RenderableElement extends TransformableElement { super(id, parent); } + public Mask getCachedMask() { + return cachedMask; + } + + public Filter getFilter() { + return filter; + } + public PaintCache getBufferCache() { return bufferCache; } @@ -100,7 +107,7 @@ public abstract class RenderableElement extends TransformableElement { } StyleAttribute styleAttrib = new StyleAttribute(); Shape clipPath = null; - int clipPathUnits = ClipPath.CP_USER_SPACE_ON_USE; + int clipPathUnits = ClipPathConstants.CP_USER_SPACE_ON_USE; if (getStyle(styleAttrib.setName("clip-path"), false) && !"none".equals(styleAttrib.getStringValue())) { URI uri = styleAttrib.getURIValue(getXMLBase()); @@ -111,7 +118,7 @@ public abstract class RenderableElement extends TransformableElement { } } if (clipPath != null) { - if (clipPathUnits == ClipPath.CP_OBJECT_BOUNDING_BOX && (this instanceof ShapeElement)) { + if (clipPathUnits == ClipPathConstants.CP_OBJECT_BOUNDING_BOX && (this instanceof ShapeElement)) { Rectangle2D rect = this.getBoundingBox(); AffineTransform at = new AffineTransform(); at.scale(rect.getWidth(), rect.getHeight()); diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/SVGElement.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/SVGElement.java index 21237e4..7e0948d 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/SVGElement.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/SVGElement.java @@ -24,6 +24,7 @@ import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -32,26 +33,26 @@ public abstract class SVGElement { public static final String SVG_NS = "http://www.w3.org/2000/svg"; - LinkedList contexts = new LinkedList<>(); + private static final Pattern TRANSFORM_PATTERN = Pattern.compile("\\w+\\([^)]*\\)"); + + private final LinkedList contexts = new LinkedList<>(); protected SVGElement parent; - protected final ArrayList children = new ArrayList<>(); + protected final List children = new ArrayList<>(); protected String id; protected String cssClass; - protected final HashMap inlineStyles = new HashMap<>(); + protected final Map inlineStyles = new HashMap<>(); - protected final HashMap presAttribs = new HashMap<>(); + protected final Map presAttribs = new HashMap<>(); protected URI xmlBase = null; protected SVGDiagram diagram; - private static final Pattern TRANSFORM_PATTERN = Pattern.compile("\\w+\\([^)]*\\)"); - public SVGElement() { this(null, null, null); } @@ -131,7 +132,7 @@ public abstract class SVGElement { this.cssClass = (className == null || className.equals("")) ? null : className.intern(); String style = attrs.getValue("style"); if (style != null) { - HashMap map = XMLParseUtil.parseStyle(style, inlineStyles); + Map map = XMLParseUtil.parseStyle(style, inlineStyles); } String base = attrs.getValue("xml:base"); if (base != null && !base.equals("")) { @@ -294,7 +295,6 @@ public abstract class SVGElement { while (matchExpression.find()) { retXform.concatenate(parseSingleTransform(matchExpression.group())); } - return retXform; } diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/ShapeElement.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/ShapeElement.java index f42564e..5aa9291 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/ShapeElement.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/ShapeElement.java @@ -1,9 +1,9 @@ package org.xbib.graphics.svg.element; -import org.xbib.graphics.svg.Marker; -import org.xbib.graphics.svg.MarkerLayout; -import org.xbib.graphics.svg.MarkerPos; +import org.xbib.graphics.svg.util.MarkerLayout; +import org.xbib.graphics.svg.util.MarkerPos; import org.xbib.graphics.svg.SVGException; +import org.xbib.graphics.svg.element.shape.Marker; import org.xbib.graphics.svg.xml.StyleAttribute; import java.awt.AlphaComposite; @@ -24,9 +24,6 @@ public abstract class ShapeElement extends RenderableElement { protected float strokeWidthScalar = 1f; - public ShapeElement() { - } - @Override public abstract void doRender(Graphics2D g) throws SVGException, IOException; diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/Stop.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/Stop.java similarity index 83% rename from graphics-svg/src/main/java/org/xbib/graphics/svg/Stop.java rename to graphics-svg/src/main/java/org/xbib/graphics/svg/element/Stop.java index 748e6de..8d713a9 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/Stop.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/Stop.java @@ -1,5 +1,6 @@ -package org.xbib.graphics.svg; +package org.xbib.graphics.svg.element; +import org.xbib.graphics.svg.SVGException; import org.xbib.graphics.svg.element.SVGElement; import org.xbib.graphics.svg.xml.StyleAttribute; @@ -8,20 +9,30 @@ import java.io.IOException; public class Stop extends SVGElement { - public static final String TAG_NAME = "stop"; + private float offset = 0f; - public float offset = 0f; + private float opacity = 1f; - public float opacity = 1f; - - public Color color = Color.black; + private Color color = Color.black; public Stop() { } + public float getOffset() { + return offset; + } + + public float getOpacity() { + return opacity; + } + + public Color getColor() { + return color; + } + @Override public String getTagName() { - return TAG_NAME; + return "stop"; } @Override diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/Style.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/Style.java index 2d84d2e..4aeda69 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/Style.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/Style.java @@ -10,20 +10,13 @@ import java.io.IOException; public class Style extends SVGElement { - public static final String TAG_NAME = "style"; + private final StringBuilder text = new StringBuilder(); - String type; - - StringBuilder text = new StringBuilder(); - - StyleSheet styleSheet; - - public Style() { - } + private StyleSheet styleSheet; @Override public String getTagName() { - return TAG_NAME; + return "style"; } @Override @@ -37,7 +30,7 @@ public class Style extends SVGElement { super.build(); StyleAttribute sty = new StyleAttribute(); if (getPres(sty.setName("type"))) { - type = sty.getStringValue(); + String type = sty.getStringValue(); } } diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/Symbol.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/Symbol.java similarity index 88% rename from graphics-svg/src/main/java/org/xbib/graphics/svg/Symbol.java rename to graphics-svg/src/main/java/org/xbib/graphics/svg/element/Symbol.java index 2c13e4b..c535582 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/Symbol.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/Symbol.java @@ -1,6 +1,7 @@ -package org.xbib.graphics.svg; +package org.xbib.graphics.svg.element; -import org.xbib.graphics.svg.element.Group; +import org.xbib.graphics.svg.SVGException; +import org.xbib.graphics.svg.element.shape.Group; import org.xbib.graphics.svg.xml.StyleAttribute; import java.awt.Graphics2D; @@ -12,18 +13,13 @@ import java.io.IOException; public class Symbol extends Group { - public static final String TAG_NAME = "symbol"; + private AffineTransform viewXform; - AffineTransform viewXform; - - Rectangle2D viewBox; - - public Symbol() { - } + private Rectangle2D viewBox; @Override public String getTagName() { - return TAG_NAME; + return "symbol"; } @Override diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/Title.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/Title.java similarity index 63% rename from graphics-svg/src/main/java/org/xbib/graphics/svg/Title.java rename to graphics-svg/src/main/java/org/xbib/graphics/svg/element/Title.java index 2e7e9a8..8eaeb46 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/Title.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/Title.java @@ -1,19 +1,15 @@ -package org.xbib.graphics.svg; +package org.xbib.graphics.svg.element; -import org.xbib.graphics.svg.element.SVGElement; +import org.xbib.graphics.svg.SVGException; +import org.xbib.graphics.svg.SVGLoaderHelper; public class Title extends SVGElement { - public static final String TAG_NAME = "title"; - - StringBuilder text = new StringBuilder(); - - public Title() { - } + private final StringBuilder text = new StringBuilder(); @Override public String getTagName() { - return TAG_NAME; + return "title"; } @Override diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/filtereffects/DistantLight.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/filtereffects/DistantLight.java index 8fadef6..3533a03 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/filtereffects/DistantLight.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/filtereffects/DistantLight.java @@ -7,15 +7,13 @@ import java.io.IOException; public class DistantLight extends Light { - public static final String TAG_NAME = "fedistantlight"; + private float azimuth = 0f; - float azimuth = 0f; - - float elevation = 0f; + private float elevation = 0f; @Override public String getTagName() { - return TAG_NAME; + return "fedistantlight"; } @Override diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/filtereffects/FilterEffects.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/filtereffects/FilterEffects.java index f1c6fd2..4c5e7ca 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/filtereffects/FilterEffects.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/filtereffects/FilterEffects.java @@ -6,44 +6,26 @@ import org.xbib.graphics.svg.xml.StyleAttribute; import java.awt.Rectangle; import java.io.IOException; +import java.net.MalformedURLException; import java.net.URI; import java.net.URL; import java.util.List; public abstract class FilterEffects extends SVGElement { - public static final String TAG_NAME = "filtereffects"; + private float x = 0f; - public static final int FP_SOURCE_GRAPHIC = 0; + private float y = 0f; - public static final int FP_SOURCE_ALPHA = 1; + private float width = 1f; - public static final int FP_BACKGROUND_IMAGE = 2; + private float height = 1f; - public static final int FP_BACKGROUND_ALPHA = 3; - - public static final int FP_FILL_PAINT = 4; - - public static final int FP_STROKE_PAINT = 5; - - public static final int FP_CUSTOM = 5; - - float x = 0f; - - float y = 0f; - - float width = 1f; - - float height = 1f; - - URL href = null; - - public FilterEffects() { - } + private URL href; @Override public String getTagName() { - return TAG_NAME; + return "filtereffects"; } @Override @@ -103,17 +85,18 @@ public abstract class FilterEffects extends SVGElement { stateChange = true; } } - try { - if (getPres(sty.setName("xlink:href"))) { - URI src = sty.getURIValue(getXMLBase()); - URL newVal = src.toURL(); - if (!newVal.equals(href)) { - href = newVal; - stateChange = true; - } + if (getPres(sty.setName("xlink:href"))) { + URI src = sty.getURIValue(getXMLBase()); + URL newVal; + try { + newVal = src.toURL(); + } catch (MalformedURLException e) { + throw new SVGException(e); + } + if (!newVal.equals(href)) { + href = newVal; + stateChange = true; } - } catch (Exception e) { - throw new SVGException(e); } return stateChange; } diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/filtereffects/FilterOp.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/filtereffects/FilterOp.java index 67c84a6..8565deb 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/filtereffects/FilterOp.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/filtereffects/FilterOp.java @@ -5,12 +5,20 @@ import java.awt.image.BufferedImageOp; public class FilterOp { - public final BufferedImageOp op; + private final BufferedImageOp op; - public final Rectangle requiredImageBounds; + private final Rectangle requiredImageBounds; public FilterOp(BufferedImageOp op, Rectangle requiredImageBounds) { this.op = op; this.requiredImageBounds = requiredImageBounds; } + + public BufferedImageOp getOp() { + return op; + } + + public Rectangle getRequiredImageBounds() { + return requiredImageBounds; + } } diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/filtereffects/GaussianBlur.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/filtereffects/GaussianBlur.java index 859c0b8..0acd618 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/filtereffects/GaussianBlur.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/filtereffects/GaussianBlur.java @@ -12,8 +12,6 @@ import java.util.List; public class GaussianBlur extends FilterEffects { - public static final String TAG_NAME = "fegaussianblur"; - private float[] stdDeviation; private float xCurrent; @@ -26,7 +24,7 @@ public class GaussianBlur extends FilterEffects { @Override public String getTagName() { - return TAG_NAME; + return "fegaussianblur"; } @Override @@ -45,14 +43,8 @@ public class GaussianBlur extends FilterEffects { public List getOperations(Rectangle inputBounds, float xScale, float yScale) { float xSigma = xScale * stdDeviation[0]; float ySigma = yScale * stdDeviation[Math.min(stdDeviation.length - 1, 1)]; - return Arrays.asList( - xSigma > 0 - ? getGaussianBlurFilter(inputBounds, xSigma, true) - : null, - ySigma > 0 - ? getGaussianBlurFilter(inputBounds, ySigma, false) - : null - ); + return Arrays.asList(xSigma > 0 ? getGaussianBlurFilter(inputBounds, xSigma, true) : null, + ySigma > 0 ? getGaussianBlurFilter(inputBounds, ySigma, false) : null); } public FilterOp getGaussianBlurFilter(Rectangle inputBounds, float sigma, boolean horizontal) { @@ -75,8 +67,7 @@ public class GaussianBlur extends FilterEffects { for (int i = 0; i < size; i++) { float distance = middle - i; distance *= distance; - data[i] = distance > radius2 - ? 0 + data[i] = distance > radius2 ? 0 : (float) Math.exp(-distance / twoSigmaSquare) / sigmaRoot; total += data[i]; } diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/filtereffects/Light.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/filtereffects/Light.java index bf5eb06..fad8684 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/filtereffects/Light.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/filtereffects/Light.java @@ -2,10 +2,8 @@ package org.xbib.graphics.svg.element.filtereffects; public abstract class Light extends FilterEffects { - public static final String TAG_NAME = "feLight"; - @Override public String getTagName() { - return TAG_NAME; + return "feLight"; } } diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/filtereffects/PointLight.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/filtereffects/PointLight.java index d881d2d..c022d6b 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/filtereffects/PointLight.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/filtereffects/PointLight.java @@ -7,20 +7,15 @@ import java.io.IOException; public class PointLight extends Light { - public static final String TAG_NAME = "fepointlight"; + private float x = 0f; - float x = 0f; + private float y = 0f; - float y = 0f; - - float z = 0f; - - public PointLight() { - } + private float z = 0f; @Override public String getTagName() { - return TAG_NAME; + return "fepointlight"; } @Override diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/filtereffects/SpotLight.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/filtereffects/SpotLight.java index 260c406..8ce0cfc 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/filtereffects/SpotLight.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/filtereffects/SpotLight.java @@ -7,27 +7,25 @@ import java.io.IOException; public class SpotLight extends Light { - public static final String TAG_NAME = "fespotlight"; + private float x = 0f; - float x = 0f; + private float y = 0f; - float y = 0f; + private float z = 0f; - float z = 0f; + private float pointsAtX = 0f; - float pointsAtX = 0f; + private float pointsAtY = 0f; - float pointsAtY = 0f; + private float pointsAtZ = 0f; - float pointsAtZ = 0f; + private float specularComponent = 0f; - float specularComponent = 0f; - - float limitingConeAngle = 0f; + private float limitingConeAngle = 0f; @Override public String getTagName() { - return TAG_NAME; + return "fespotlight"; } @Override diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/glyph/Glyph.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/glyph/Glyph.java index c227535..e8ff6fb 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/glyph/Glyph.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/glyph/Glyph.java @@ -7,16 +7,11 @@ import java.io.IOException; public class Glyph extends MissingGlyph { - public static final String TAG_NAME = "missingglyph"; - - String unicode; - - public Glyph() { - } + private String unicode; @Override public String getTagName() { - return TAG_NAME; + return "glyph"; } @Override diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/glyph/MissingGlyph.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/glyph/MissingGlyph.java index fc33cb4..b8229b7 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/glyph/MissingGlyph.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/glyph/MissingGlyph.java @@ -20,8 +20,6 @@ import java.io.IOException; public class MissingGlyph extends ShapeElement { - public static final String TAG_NAME = "missingglyph"; - private Shape path = null; private float horizAdvX = -1; @@ -32,12 +30,9 @@ public class MissingGlyph extends ShapeElement { private float vertAdvY = -1; - public MissingGlyph() { - } - @Override public String getTagName() { - return TAG_NAME; + return "missingglyph"; } @Override diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/gradient/Gradient.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/gradient/Gradient.java index 7b681a5..05dc18a 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/gradient/Gradient.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/gradient/Gradient.java @@ -3,7 +3,7 @@ package org.xbib.graphics.svg.element.gradient; import org.xbib.graphics.svg.SVGElementException; import org.xbib.graphics.svg.SVGException; import org.xbib.graphics.svg.SVGLoaderHelper; -import org.xbib.graphics.svg.Stop; +import org.xbib.graphics.svg.element.Stop; import org.xbib.graphics.svg.element.FillElement; import org.xbib.graphics.svg.element.SVGElement; import org.xbib.graphics.svg.xml.StyleAttribute; @@ -17,38 +17,33 @@ import java.util.List; public abstract class Gradient extends FillElement { - public static final String TAG_NAME = "gradient"; + protected static final int SM_PAD = 0; - public static final int SM_PAD = 0; + protected static final int SM_REPEAT = 1; - public static final int SM_REPEAT = 1; + protected static final int SM_REFLECT = 2; - public static final int SM_REFLECT = 2; + protected int spreadMethod = SM_PAD; - public int spreadMethod = SM_PAD; + protected static final int GU_OBJECT_BOUNDING_BOX = 0; - public static final int GU_OBJECT_BOUNDING_BOX = 0; - - public static final int GU_USER_SPACE_ON_USE = 1; + protected static final int GU_USER_SPACE_ON_USE = 1; protected int gradientUnits = GU_OBJECT_BOUNDING_BOX; - List stops = new ArrayList<>(); + private final List stops = new ArrayList<>(); - URI stopRef = null; + private URI stopRef = null; protected AffineTransform gradientTransform = null; - float[] stopFractions; + private float[] stopFractions; - Color[] stopColors; - - public Gradient() { - } + private Color[] stopColors; @Override public String getTagName() { - return TAG_NAME; + return "gradient"; } @Override @@ -100,9 +95,9 @@ public abstract class Gradient extends FillElement { private void buildStops() { ArrayList stopList = new ArrayList<>(stops); - stopList.sort((o1, o2) -> Float.compare(o1.offset, o2.offset)); + stopList.sort((o1, o2) -> Float.compare(o1.getOffset(), o2.getOffset())); for (int i = stopList.size() - 2; i >= 0; --i) { - if (stopList.get(i + 1).offset == stopList.get(i).offset) { + if (stopList.get(i + 1).getOffset() == stopList.get(i).getOffset()) { stopList.remove(i + 1); } } @@ -110,10 +105,10 @@ public abstract class Gradient extends FillElement { stopColors = new Color[stopList.size()]; int idx = 0; for (Stop stop : stopList) { - int stopColorVal = stop.color.getRGB(); - Color stopColor = new Color((stopColorVal >> 16) & 0xff, (stopColorVal >> 8) & 0xff, stopColorVal & 0xff, clamp((int) (stop.opacity * 255), 0, 255)); + int stopColorVal = stop.getColor().getRGB(); + Color stopColor = new Color((stopColorVal >> 16) & 0xff, (stopColorVal >> 8) & 0xff, stopColorVal & 0xff, clamp((int) (stop.getOpacity() * 255), 0, 255)); stopColors[idx] = stopColor; - stopFractions[idx] = stop.offset; + stopFractions[idx] = stop.getOffset(); idx++; } } diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/gradient/LinearGradient.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/gradient/Linear.java similarity index 93% rename from graphics-svg/src/main/java/org/xbib/graphics/svg/element/gradient/LinearGradient.java rename to graphics-svg/src/main/java/org/xbib/graphics/svg/element/gradient/Linear.java index fa9b44a..898f955 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/gradient/LinearGradient.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/gradient/Linear.java @@ -1,7 +1,6 @@ package org.xbib.graphics.svg.element.gradient; import org.xbib.graphics.svg.SVGException; -import org.xbib.graphics.svg.element.gradient.Gradient; import org.xbib.graphics.svg.xml.StyleAttribute; import java.awt.Color; @@ -13,24 +12,19 @@ import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.io.IOException; -public class LinearGradient extends Gradient { +public class Linear extends Gradient { - public static final String TAG_NAME = "lineargradient"; + private float x1 = 0f; - float x1 = 0f; + private float y1 = 0f; - float y1 = 0f; + private float x2 = 1f; - float x2 = 1f; - - float y2 = 0f; - - public LinearGradient() { - } + private float y2 = 0f; @Override public String getTagName() { - return TAG_NAME; + return "lineargradient"; } @Override diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/gradient/RadialGradient.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/gradient/Radial.java similarity index 92% rename from graphics-svg/src/main/java/org/xbib/graphics/svg/element/gradient/RadialGradient.java rename to graphics-svg/src/main/java/org/xbib/graphics/svg/element/gradient/Radial.java index 83ba0cb..687e749 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/gradient/RadialGradient.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/gradient/Radial.java @@ -1,7 +1,6 @@ package org.xbib.graphics.svg.element.gradient; import org.xbib.graphics.svg.SVGException; -import org.xbib.graphics.svg.element.gradient.Gradient; import org.xbib.graphics.svg.xml.StyleAttribute; import java.awt.Color; @@ -13,28 +12,23 @@ import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.io.IOException; -public class RadialGradient extends Gradient { +public class Radial extends Gradient { - public static final String TAG_NAME = "radialgradient"; + private float cx = 0.5f; - float cx = 0.5f; + private float cy = 0.5f; - float cy = 0.5f; + private boolean hasFocus = false; - boolean hasFocus = false; + private float fx = 0f; - float fx = 0f; + private float fy = 0f; - float fy = 0f; - - float r = 0.5f; - - public RadialGradient() { - } + private float r = 0.5f; @Override public String getTagName() { - return TAG_NAME; + return "radialgradient"; } @Override diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/Circle.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/shape/Circle.java similarity index 89% rename from graphics-svg/src/main/java/org/xbib/graphics/svg/element/Circle.java rename to graphics-svg/src/main/java/org/xbib/graphics/svg/element/shape/Circle.java index 0ec7f32..34e3864 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/Circle.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/shape/Circle.java @@ -1,6 +1,7 @@ -package org.xbib.graphics.svg.element; +package org.xbib.graphics.svg.element.shape; import org.xbib.graphics.svg.SVGException; +import org.xbib.graphics.svg.element.ShapeElement; import org.xbib.graphics.svg.xml.StyleAttribute; import java.awt.Graphics2D; @@ -11,22 +12,17 @@ import java.io.IOException; public class Circle extends ShapeElement { - public static final String TAG_NAME = "circle"; + private float cx = 0f; - float cx = 0f; + private float cy = 0f; - float cy = 0f; + private float r = 0f; - float r = 0f; - - Ellipse2D.Float circle = new Ellipse2D.Float(); - - public Circle() { - } + private final Ellipse2D.Float circle = new Ellipse2D.Float(); @Override public String getTagName() { - return TAG_NAME; + return "circle"; } @Override diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/Ellipse.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/shape/Ellipse.java similarity index 89% rename from graphics-svg/src/main/java/org/xbib/graphics/svg/element/Ellipse.java rename to graphics-svg/src/main/java/org/xbib/graphics/svg/element/shape/Ellipse.java index c1b3a36..5d8e7a9 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/Ellipse.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/shape/Ellipse.java @@ -1,6 +1,7 @@ -package org.xbib.graphics.svg.element; +package org.xbib.graphics.svg.element.shape; import org.xbib.graphics.svg.SVGException; +import org.xbib.graphics.svg.element.ShapeElement; import org.xbib.graphics.svg.xml.StyleAttribute; import java.awt.Graphics2D; @@ -11,24 +12,19 @@ import java.io.IOException; public class Ellipse extends ShapeElement { - public static final String TAG_NAME = "ellipse"; + private float cx = 0.0f; - float cx = 0.0f; + private float cy = 0.0f; - float cy = 0.0f; + private float rx = 0.0f; - float rx = 0.0f; + private float ry = 0.0f; - float ry = 0.0f; - - Ellipse2D.Float ellipse = new Ellipse2D.Float(); - - public Ellipse() { - } + private final Ellipse2D.Float ellipse = new Ellipse2D.Float(); @Override public String getTagName() { - return TAG_NAME; + return "ellipse"; } @Override diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/Group.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/shape/Group.java similarity index 95% rename from graphics-svg/src/main/java/org/xbib/graphics/svg/element/Group.java rename to graphics-svg/src/main/java/org/xbib/graphics/svg/element/shape/Group.java index b44195a..33b2d99 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/Group.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/shape/Group.java @@ -1,8 +1,11 @@ -package org.xbib.graphics.svg.element; +package org.xbib.graphics.svg.element.shape; import org.xbib.graphics.svg.SVGElementException; import org.xbib.graphics.svg.SVGException; import org.xbib.graphics.svg.SVGLoaderHelper; +import org.xbib.graphics.svg.element.RenderableElement; +import org.xbib.graphics.svg.element.SVGElement; +import org.xbib.graphics.svg.element.ShapeElement; import org.xbib.graphics.svg.xml.StyleAttribute; import java.awt.Graphics2D; @@ -18,18 +21,13 @@ import java.util.List; public class Group extends ShapeElement { - public static final String TAG_NAME = "group"; + private Rectangle2D boundingBox; - Rectangle2D boundingBox; - - Shape cachedShape; - - public Group() { - } + private Shape cachedShape; @Override public String getTagName() { - return TAG_NAME; + return "group"; } @Override diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/Line.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/shape/Line.java similarity index 91% rename from graphics-svg/src/main/java/org/xbib/graphics/svg/element/Line.java rename to graphics-svg/src/main/java/org/xbib/graphics/svg/element/shape/Line.java index f84bf2f..2372eec 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/Line.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/shape/Line.java @@ -1,4 +1,4 @@ -package org.xbib.graphics.svg.element; +package org.xbib.graphics.svg.element.shape; import org.xbib.graphics.svg.SVGException; import org.xbib.graphics.svg.element.ShapeElement; @@ -12,24 +12,19 @@ import java.io.IOException; public class Line extends ShapeElement { - public static final String TAG_NAME = "line"; + private float x1 = 0f; - float x1 = 0f; + private float y1 = 0f; - float y1 = 0f; + private float x2 = 0f; - float x2 = 0f; + private float y2 = 0f; - float y2 = 0f; - - Line2D.Float line; - - public Line() { - } + private Line2D.Float line; @Override public String getTagName() { - return TAG_NAME; + return "line"; } @Override diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/Marker.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/shape/Marker.java similarity index 81% rename from graphics-svg/src/main/java/org/xbib/graphics/svg/Marker.java rename to graphics-svg/src/main/java/org/xbib/graphics/svg/element/shape/Marker.java index 673b468..edc3dd7 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/Marker.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/shape/Marker.java @@ -1,6 +1,7 @@ -package org.xbib.graphics.svg; +package org.xbib.graphics.svg.element.shape; -import org.xbib.graphics.svg.element.Group; +import org.xbib.graphics.svg.util.MarkerPos; +import org.xbib.graphics.svg.SVGException; import org.xbib.graphics.svg.xml.StyleAttribute; import java.awt.Graphics2D; @@ -12,35 +13,29 @@ import java.io.IOException; public class Marker extends Group { - public static final String TAG_NAME = "marker"; - public static final int MARKER_START = 0; public static final int MARKER_MID = 1; public static final int MARKER_END = 2; - AffineTransform viewXform; + private AffineTransform markerXform; - AffineTransform markerXform; + private Rectangle2D viewBox; - Rectangle2D viewBox; + private float refX; - float refX; + private float refY; - float refY; + private float markerWidth = 1; - float markerWidth = 1; + private float markerHeight = 1; - float markerHeight = 1; - - float orient = Float.NaN; - - boolean markerUnitsStrokeWidth = true; + private boolean markerUnitsStrokeWidth = true; @Override public String getTagName() { - return TAG_NAME; + return "marker"; } @Override @@ -59,14 +54,6 @@ public class Marker extends Group { if (getPres(sty.setName("markerHeight"))) { markerHeight = sty.getFloatValueWithUnits(); } - - if (getPres(sty.setName("orient"))) { - if ("auto".equals(sty.getStringValue())) { - orient = Float.NaN; - } else { - orient = sty.getFloatValue(); - } - } if (getPres(sty.setName("viewBox"))) { float[] dim = sty.getFloatList(); viewBox = new Rectangle2D.Float(dim[0], dim[1], dim[2], dim[3]); @@ -80,7 +67,7 @@ public class Marker extends Group { markerUnitsStrokeWidth = false; } } - viewXform = new AffineTransform(); + AffineTransform viewXform = new AffineTransform(); viewXform.scale(1.0 / viewBox.getWidth(), 1.0 / viewBox.getHeight()); viewXform.translate(-viewBox.getX(), -viewBox.getY()); markerXform = new AffineTransform(); @@ -106,11 +93,11 @@ public class Marker extends Group { public void render(Graphics2D g, MarkerPos pos, float strokeWidth) throws SVGException, IOException { AffineTransform cacheXform = g.getTransform(); - g.translate(pos.x, pos.y); + g.translate(pos.getX(), pos.getY()); if (markerUnitsStrokeWidth) { g.scale(strokeWidth, strokeWidth); } - g.rotate(Math.atan2(pos.dy, pos.dx)); + g.rotate(Math.atan2(pos.getDy(), pos.getDx())); g.transform(markerXform); super.doRender(g); g.setTransform(cacheXform); diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/Mask.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/shape/Mask.java similarity index 97% rename from graphics-svg/src/main/java/org/xbib/graphics/svg/element/Mask.java rename to graphics-svg/src/main/java/org/xbib/graphics/svg/element/shape/Mask.java index b3ac8ff..2c1fd89 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/element/Mask.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/shape/Mask.java @@ -1,7 +1,6 @@ -package org.xbib.graphics.svg.element; +package org.xbib.graphics.svg.element.shape; import org.xbib.graphics.svg.SVGException; -import org.xbib.graphics.svg.element.Group; import org.xbib.graphics.svg.element.RenderableElement; import org.xbib.graphics.svg.element.SVGElement; import org.xbib.graphics.svg.util.PaintUtil; @@ -25,11 +24,9 @@ import java.util.List; public class Mask extends Group { - public static final String TAG_NAME = "mask"; - @Override public String getTagName() { - return TAG_NAME; + return "mask"; } @Override diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/Path.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/shape/Path.java similarity index 90% rename from graphics-svg/src/main/java/org/xbib/graphics/svg/Path.java rename to graphics-svg/src/main/java/org/xbib/graphics/svg/element/shape/Path.java index 2c9ba9b..7ac94f3 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/Path.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/shape/Path.java @@ -1,5 +1,6 @@ -package org.xbib.graphics.svg; +package org.xbib.graphics.svg.element.shape; +import org.xbib.graphics.svg.SVGException; import org.xbib.graphics.svg.element.ShapeElement; import org.xbib.graphics.svg.xml.StyleAttribute; @@ -11,20 +12,15 @@ import java.io.IOException; public class Path extends ShapeElement { - public static final String TAG_NAME = "path"; + private int fillRule = GeneralPath.WIND_NON_ZERO; - int fillRule = GeneralPath.WIND_NON_ZERO; + private String d = ""; - String d = ""; - - GeneralPath path; - - public Path() { - } + private GeneralPath path; @Override public String getTagName() { - return TAG_NAME; + return "path"; } @Override diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/Polygon.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/shape/Polygon.java similarity index 78% rename from graphics-svg/src/main/java/org/xbib/graphics/svg/Polygon.java rename to graphics-svg/src/main/java/org/xbib/graphics/svg/element/shape/Polygon.java index 8c208d1..7f72f78 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/Polygon.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/shape/Polygon.java @@ -1,5 +1,6 @@ -package org.xbib.graphics.svg; +package org.xbib.graphics.svg.element.shape; +import org.xbib.graphics.svg.SVGException; import org.xbib.graphics.svg.element.ShapeElement; import org.xbib.graphics.svg.xml.StyleAttribute; import org.xbib.graphics.svg.xml.XMLParseUtil; @@ -12,43 +13,32 @@ import java.io.IOException; public class Polygon extends ShapeElement { - public static final String TAG_NAME = "polygon"; + private int fillRule = GeneralPath.WIND_NON_ZERO; - int fillRule = GeneralPath.WIND_NON_ZERO; - String pointsStrn = ""; - GeneralPath path; + private String pointsStrn = ""; - /** - * Creates a new instance of Rect - */ - public Polygon() { - } + private GeneralPath path; @Override public String getTagName() { - return TAG_NAME; + return "polygon"; } @Override protected void build() throws SVGException, IOException { super.build(); - StyleAttribute sty = new StyleAttribute(); - if (getPres(sty.setName("points"))) { pointsStrn = sty.getStringValue(); } - String fillRuleStrn = getStyle(sty.setName("fill-rule")) ? sty.getStringValue() : "nonzero"; fillRule = fillRuleStrn.equals("evenodd") ? GeneralPath.WIND_EVEN_ODD : GeneralPath.WIND_NON_ZERO; - buildPath(); } protected void buildPath() { float[] points = XMLParseUtil.parseFloatList(pointsStrn); path = new GeneralPath(fillRule, points.length / 2); - path.moveTo(points[0], points[1]); for (int i = 2; i < points.length; i += 2) { path.lineTo(points[i], points[i + 1]); @@ -73,22 +63,11 @@ public class Polygon extends ShapeElement { return boundsToParent(includeStrokeInBounds(path.getBounds2D())); } - /** - * Updates all attributes in this diagram associated with a time event. Ie, - * all attributes with track information. - * - * @return - true if this node has changed state as a result of the time - * update - */ @Override public boolean updateTime(double curTime) throws SVGException, IOException { -// if (trackManager.getNumTracks() == 0) return false; boolean changeState = super.updateTime(curTime); - - //Get current values for parameters StyleAttribute sty = new StyleAttribute(); boolean shapeChange = false; - if (getStyle(sty.setName("fill-rule"))) { int newVal = sty.getStringValue().equals("evenodd") ? GeneralPath.WIND_EVEN_ODD @@ -98,7 +77,6 @@ public class Polygon extends ShapeElement { shapeChange = true; } } - if (getPres(sty.setName("points"))) { String newVal = sty.getStringValue(); if (!newVal.equals(pointsStrn)) { @@ -106,14 +84,9 @@ public class Polygon extends ShapeElement { shapeChange = true; } } - - if (shapeChange) { build(); -// buildPath(); -// return true; } - return changeState || shapeChange; } } diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/Polyline.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/shape/Polyline.java similarity index 91% rename from graphics-svg/src/main/java/org/xbib/graphics/svg/Polyline.java rename to graphics-svg/src/main/java/org/xbib/graphics/svg/element/shape/Polyline.java index 5aba970..322fd2d 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/Polyline.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/shape/Polyline.java @@ -1,5 +1,6 @@ -package org.xbib.graphics.svg; +package org.xbib.graphics.svg.element.shape; +import org.xbib.graphics.svg.SVGException; import org.xbib.graphics.svg.element.ShapeElement; import org.xbib.graphics.svg.xml.StyleAttribute; import org.xbib.graphics.svg.xml.XMLParseUtil; @@ -12,20 +13,15 @@ import java.io.IOException; public class Polyline extends ShapeElement { - public static final String TAG_NAME = "polyline"; + private int fillRule = GeneralPath.WIND_NON_ZERO; - int fillRule = GeneralPath.WIND_NON_ZERO; + private String pointsStrn = ""; - String pointsStrn = ""; - - GeneralPath path; - - public Polyline() { - } + private GeneralPath path; @Override public String getTagName() { - return TAG_NAME; + return "polyline"; } @Override diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/Rect.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/shape/Rect.java similarity index 92% rename from graphics-svg/src/main/java/org/xbib/graphics/svg/Rect.java rename to graphics-svg/src/main/java/org/xbib/graphics/svg/element/shape/Rect.java index 000e780..c86f1e9 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/Rect.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/shape/Rect.java @@ -1,5 +1,6 @@ -package org.xbib.graphics.svg; +package org.xbib.graphics.svg.element.shape; +import org.xbib.graphics.svg.SVGException; import org.xbib.graphics.svg.element.ShapeElement; import org.xbib.graphics.svg.xml.StyleAttribute; @@ -12,22 +13,23 @@ import java.io.IOException; public class Rect extends ShapeElement { - public static final String TAG_NAME = "rect"; + private float x = 0f; - float x = 0f; - float y = 0f; - float width = 0f; - float height = 0f; - float rx = 0f; - float ry = 0f; - RectangularShape rect; + private float y = 0f; - public Rect() { - } + private float width = 0f; + + private float height = 0f; + + private float rx = 0f; + + private float ry = 0f; + + private RectangularShape rect; @Override public String getTagName() { - return TAG_NAME; + return "rect"; } @Override diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/Text.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/shape/Text.java similarity index 70% rename from graphics-svg/src/main/java/org/xbib/graphics/svg/Text.java rename to graphics-svg/src/main/java/org/xbib/graphics/svg/element/shape/Text.java index d241048..3278525 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/Text.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/shape/Text.java @@ -1,6 +1,8 @@ -package org.xbib.graphics.svg; +package org.xbib.graphics.svg.element.shape; +import org.xbib.graphics.svg.SVGException; import org.xbib.graphics.svg.util.FontUtil; +import org.xbib.graphics.svg.util.TextConst; import org.xbib.graphics.svg.xml.StyleAttribute; import java.awt.geom.AffineTransform; @@ -10,56 +12,13 @@ import java.io.IOException; import java.util.Arrays; import java.util.List; -public class Text extends Tspan { +public class Text extends Tspan implements TextConst { - public static final String TAG_NAME = "text"; - - public static final int TXAN_START = 0; - - public static final int TXAN_MIDDLE = 1; - - public static final int TXAN_END = 2; - - public static final int TXST_NORMAL = 0; - - public static final int TXST_ITALIC = 1; - - public static final int TXST_OBLIQUE = 2; - - public static final int TXWE_NORMAL = 0; - - public static final int TXWE_BOLD = 1; - - public static final int TXWE_BOLDER = 2; - - public static final int TXWE_LIGHTER = 3; - - public static final int TXWE_100 = 4; - - public static final int TXWE_200 = 5; - - public static final int TXWE_300 = 6; - - public static final int TXWE_400 = 7; - - public static final int TXWE_500 = 8; - - public static final int TXWE_600 = 9; - - public static final int TXWE_700 = 10; - - public static final int TXWE_800 = 11; - - public static final int TXWE_900 = 12; - - int textAnchor = TXAN_START; - - public Text() { - } + private int textAnchor = TXAN_START; @Override public String getTagName() { - return TAG_NAME; + return "text"; } public void rebuild() throws SVGException, IOException { @@ -138,16 +97,16 @@ public class Text extends Tspan { public boolean updateTime(double curTime) throws SVGException { boolean changeState = super.updateTime(curTime); FontUtil.FontInfo fontInfoOld = fontInfo; - float[] xOld = x; - float[] yOld = y; - float[] dxOld = dx; - float[] dyOld = dy; + float[] xOld = getX(); + float[] yOld = getY(); + float[] dxOld = getDx(); + float[] dyOld = getDy(); buildShapeInformation(); boolean shapeChange = !fontInfo.equals(fontInfoOld) - || !Arrays.equals(xOld, x) - || !Arrays.equals(yOld, y) - || !Arrays.equals(dxOld, dx) - || !Arrays.equals(dyOld, dy); + || !Arrays.equals(xOld, getX()) + || !Arrays.equals(yOld, getY()) + || !Arrays.equals(dxOld, getDx()) + || !Arrays.equals(dyOld, getDy()); if (shapeChange) { buildText(); } diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/Tspan.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/shape/Tspan.java similarity index 92% rename from graphics-svg/src/main/java/org/xbib/graphics/svg/Tspan.java rename to graphics-svg/src/main/java/org/xbib/graphics/svg/element/shape/Tspan.java index 08e61bd..91496b7 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/Tspan.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/shape/Tspan.java @@ -1,5 +1,8 @@ -package org.xbib.graphics.svg; +package org.xbib.graphics.svg.element.shape; +import org.xbib.graphics.svg.SVGElementException; +import org.xbib.graphics.svg.SVGException; +import org.xbib.graphics.svg.SVGLoaderHelper; import org.xbib.graphics.svg.element.Font; import org.xbib.graphics.svg.element.SVGElement; import org.xbib.graphics.svg.element.ShapeElement; @@ -21,21 +24,15 @@ import java.util.regex.Pattern; public class Tspan extends ShapeElement { - public static final String TAG_NAME = "tspan"; + private float[] x = null; - float[] x = null; + private float[] y = null; - float[] y = null; + private float[] dx = null; - float[] dx = null; + private float[] dy = null; - float[] dy = null; - - float[] rotate = null; - - float textLength = -1; - - String lengthAdjust = "spacing"; + private float[] rotate = null; private final List content = new ArrayList<>(); @@ -49,12 +46,25 @@ public class Tspan extends ShapeElement { private Font font; - public Tspan() { + public float[] getDx() { + return dx; + } + + public float[] getDy() { + return dy; + } + + public float[] getX() { + return x; + } + + public float[] getY() { + return y; } @Override public String getTagName() { - return TAG_NAME; + return "tspan"; } @Override @@ -107,16 +117,6 @@ public class Tspan extends ShapeElement { rotate[i] = (float) Math.toRadians(this.rotate[i]); } } - if (getStyle(sty.setName("textLength"))) { - textLength = sty.getFloatValueWithUnits(); - } else { - textLength = -1; - } - if (getStyle(sty.setName("lengthAdjust"))) { - lengthAdjust = sty.getStringValue(); - } else { - lengthAdjust = "spacing"; - } } protected void buildShapeInformation() throws SVGException { diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/Use.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/shape/Use.java similarity index 93% rename from graphics-svg/src/main/java/org/xbib/graphics/svg/Use.java rename to graphics-svg/src/main/java/org/xbib/graphics/svg/element/shape/Use.java index e862c61..7ab4852 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/Use.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/element/shape/Use.java @@ -1,5 +1,6 @@ -package org.xbib.graphics.svg; +package org.xbib.graphics.svg.element.shape; +import org.xbib.graphics.svg.SVGException; import org.xbib.graphics.svg.element.RenderableElement; import org.xbib.graphics.svg.element.SVGElement; import org.xbib.graphics.svg.element.ShapeElement; @@ -14,26 +15,21 @@ import java.net.URI; public class Use extends ShapeElement { - public static final String TAG_NAME = "use"; + private float x = 0f; - float x = 0f; + private float y = 0f; - float y = 0f; + private float width = 1f; - float width = 1f; + private float height = 1f; - float height = 1f; + private URI href = null; - URI href = null; - - AffineTransform refXform; - - public Use() { - } + private AffineTransform refXform; @Override public String getTagName() { - return TAG_NAME; + return "use"; } @Override diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/Arc.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/Arc.java index 93b573a..05d883b 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/Arc.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/Arc.java @@ -7,19 +7,19 @@ import java.awt.geom.GeneralPath; public class Arc extends PathCommand { - public float rx = 0f; + private float rx = 0f; - public float ry = 0f; + private float ry = 0f; - public float xAxisRot = 0f; + private float xAxisRot = 0f; - public boolean largeArc = false; + private boolean largeArc = false; - public boolean sweep = false; + private boolean sweep = false; - public float x = 0f; + private float x = 0f; - public float y = 0f; + private float y = 0f; public Arc() { } @@ -37,11 +37,11 @@ public class Arc extends PathCommand { @Override public void appendPath(GeneralPath path, BuildHistory hist) { - float offx = isRelative ? hist.lastPoint.x : 0f; - float offy = isRelative ? hist.lastPoint.y : 0f; + float offx = isRelative() ? hist.getLastPoint().x : 0f; + float offy = isRelative() ? hist.getLastPoint().y : 0f; arcTo(path, rx, ry, xAxisRot, largeArc, sweep, x + offx, y + offy, - hist.lastPoint.x, hist.lastPoint.y); + hist.getLastPoint().x, hist.getLastPoint().y); hist.setLastPoint(x + offx, y + offy); hist.setLastKnot(x + offx, y + offy); } diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/BuildHistory.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/BuildHistory.java index b6faf8b..9d8c46e 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/BuildHistory.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/BuildHistory.java @@ -4,22 +4,33 @@ import java.awt.geom.Point2D; public class BuildHistory { - Point2D.Float startPoint = new Point2D.Float(); - Point2D.Float lastPoint = new Point2D.Float(); - Point2D.Float lastKnot = new Point2D.Float(); + private final Point2D.Float startPoint = new Point2D.Float(); - public BuildHistory() { - } + private final Point2D.Float lastPoint = new Point2D.Float(); + + private final Point2D.Float lastKnot = new Point2D.Float(); public void setStartPoint(float x, float y) { startPoint.setLocation(x, y); } + public Point2D.Float getStartPoint() { + return startPoint; + } + public void setLastPoint(float x, float y) { lastPoint.setLocation(x, y); } + public Point2D.Float getLastPoint() { + return lastPoint; + } + public void setLastKnot(float x, float y) { lastKnot.setLocation(x, y); } + + public Point2D.Float getLastKnot() { + return lastKnot; + } } diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/Cubic.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/Cubic.java index a6ee322..81464db 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/Cubic.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/Cubic.java @@ -4,12 +4,17 @@ import java.awt.geom.GeneralPath; public class Cubic extends PathCommand { - public float k1x = 0f; - public float k1y = 0f; - public float k2x = 0f; - public float k2y = 0f; - public float x = 0f; - public float y = 0f; + private float k1x = 0f; + + private float k1y = 0f; + + private float k2x = 0f; + + private float k2y = 0f; + + private float x = 0f; + + private float y = 0f; public Cubic() { } @@ -26,8 +31,8 @@ public class Cubic extends PathCommand { @Override public void appendPath(GeneralPath path, BuildHistory hist) { - float offx = isRelative ? hist.lastPoint.x : 0f; - float offy = isRelative ? hist.lastPoint.y : 0f; + float offx = isRelative() ? hist.getLastPoint().x : 0f; + float offy = isRelative() ? hist.getLastPoint().y : 0f; path.curveTo(k1x + offx, k1y + offy, k2x + offx, k2y + offy, x + offx, y + offy); diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/CubicSmooth.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/CubicSmooth.java index 0a27564..6029342 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/CubicSmooth.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/CubicSmooth.java @@ -4,13 +4,13 @@ import java.awt.geom.GeneralPath; public class CubicSmooth extends PathCommand { - public float x = 0f; + private float x = 0f; - public float y = 0f; + private float y = 0f; - public float k2x = 0f; + private float k2x = 0f; - public float k2y = 0f; + private float k2y = 0f; public CubicSmooth() { } @@ -25,12 +25,12 @@ public class CubicSmooth extends PathCommand { @Override public void appendPath(GeneralPath path, BuildHistory hist) { - float offx = isRelative ? hist.lastPoint.x : 0f; - float offy = isRelative ? hist.lastPoint.y : 0f; - float oldKx = hist.lastKnot.x; - float oldKy = hist.lastKnot.y; - float oldX = hist.lastPoint.x; - float oldY = hist.lastPoint.y; + float offx = isRelative() ? hist.getLastPoint().x : 0f; + float offy = isRelative() ? hist.getLastPoint().y : 0f; + float oldKx = hist.getLastKnot().x; + float oldKy = hist.getLastKnot().y; + float oldX = hist.getLastPoint().x; + float oldY = hist.getLastPoint().y; float k1x = oldX * 2f - oldKx; float k1y = oldY * 2f - oldKy; path.curveTo(k1x, k1y, k2x + offx, k2y + offy, x + offx, y + offy); diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/Horizontal.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/Horizontal.java index ac8f346..ed61aae 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/Horizontal.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/Horizontal.java @@ -4,15 +4,7 @@ import java.awt.geom.GeneralPath; public class Horizontal extends PathCommand { - public float x = 0f; - - public Horizontal() { - } - - @Override - public String toString() { - return "H " + x; - } + private final float x; public Horizontal(boolean isRelative, float x) { super(isRelative); @@ -21,8 +13,8 @@ public class Horizontal extends PathCommand { @Override public void appendPath(GeneralPath path, BuildHistory hist) { - float offx = isRelative ? hist.lastPoint.x : 0f; - float offy = hist.lastPoint.y; + float offx = isRelative() ? hist.getLastPoint().x : 0f; + float offy = hist.getLastPoint().y; path.lineTo(x + offx, offy); hist.setLastPoint(x + offx, offy); hist.setLastKnot(x + offx, offy); @@ -32,4 +24,9 @@ public class Horizontal extends PathCommand { public int getNumKnotsAdded() { return 2; } + + @Override + public String toString() { + return "H " + x; + } } diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/LineTo.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/LineTo.java index 3d48975..9a24830 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/LineTo.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/LineTo.java @@ -4,11 +4,9 @@ import java.awt.geom.GeneralPath; public class LineTo extends PathCommand { - public float x = 0f; - public float y = 0f; + private final float x; - public LineTo() { - } + private final float y; public LineTo(boolean isRelative, float x, float y) { super(isRelative); @@ -18,8 +16,8 @@ public class LineTo extends PathCommand { @Override public void appendPath(GeneralPath path, BuildHistory hist) { - float offx = isRelative ? hist.lastPoint.x : 0f; - float offy = isRelative ? hist.lastPoint.y : 0f; + float offx = isRelative() ? hist.getLastPoint().x : 0f; + float offy = isRelative() ? hist.getLastPoint().y : 0f; path.lineTo(x + offx, y + offy); hist.setLastPoint(x + offx, y + offy); hist.setLastKnot(x + offx, y + offy); diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/MoveTo.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/MoveTo.java index 1f5d8a8..828c79a 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/MoveTo.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/MoveTo.java @@ -4,12 +4,9 @@ import java.awt.geom.GeneralPath; public class MoveTo extends PathCommand { - public float x = 0f; + private final float x; - public float y = 0f; - - public MoveTo() { - } + private final float y; public MoveTo(boolean isRelative, float x, float y) { super(isRelative); @@ -19,8 +16,8 @@ public class MoveTo extends PathCommand { @Override public void appendPath(GeneralPath path, BuildHistory hist) { - float offx = isRelative ? hist.lastPoint.x : 0f; - float offy = isRelative ? hist.lastPoint.y : 0f; + float offx = isRelative() ? hist.getLastPoint().x : 0f; + float offy = isRelative() ? hist.getLastPoint().y : 0f; path.moveTo(x + offx, y + offy); hist.setStartPoint(x + offx, y + offy); hist.setLastPoint(x + offx, y + offy); diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/PathCommand.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/PathCommand.java index 9286bf3..6f3f64f 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/PathCommand.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/PathCommand.java @@ -4,15 +4,20 @@ import java.awt.geom.GeneralPath; abstract public class PathCommand { - public boolean isRelative = false; + private final boolean isRelative; public PathCommand() { + this(true); } public PathCommand(boolean isRelative) { this.isRelative = isRelative; } + public boolean isRelative() { + return isRelative; + } + abstract public void appendPath(GeneralPath path, BuildHistory hist); abstract public int getNumKnotsAdded(); diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/PathUtil.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/PathUtil.java deleted file mode 100644 index fb99552..0000000 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/PathUtil.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.xbib.graphics.svg.pathcmd; - -import java.awt.geom.AffineTransform; -import java.awt.geom.GeneralPath; -import java.awt.geom.PathIterator; - -public class PathUtil { - - public PathUtil() { - } - - public static String buildPathString(GeneralPath path) { - float[] coords = new float[6]; - StringBuilder sb = new StringBuilder(); - for (PathIterator pathIt = path.getPathIterator(new AffineTransform()); !pathIt.isDone(); pathIt.next()) { - int segId = pathIt.currentSegment(coords); - switch (segId) { - case PathIterator.SEG_CLOSE: { - sb.append(" Z"); - break; - } - case PathIterator.SEG_CUBICTO: { - sb.append(" C " + coords[0] + " " + coords[1] + " " + coords[2] + " " + coords[3] + " " + coords[4] + " " + coords[5]); - break; - } - case PathIterator.SEG_LINETO: { - sb.append(" L " + coords[0] + " " + coords[1]); - break; - } - case PathIterator.SEG_MOVETO: { - sb.append(" M " + coords[0] + " " + coords[1]); - break; - } - case PathIterator.SEG_QUADTO: { - sb.append(" Q " + coords[0] + " " + coords[1] + " " + coords[2] + " " + coords[3]); - break; - } - } - } - return sb.toString(); - } -} diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/Quadratic.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/Quadratic.java index fbca360..8b4fd39 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/Quadratic.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/Quadratic.java @@ -4,16 +4,13 @@ import java.awt.geom.GeneralPath; public class Quadratic extends PathCommand { - public float kx = 0f; + private final float kx; - public float ky = 0f; + private final float ky; - public float x = 0f; + private final float x; - public float y = 0f; - - public Quadratic() { - } + private final float y; public Quadratic(boolean isRelative, float kx, float ky, float x, float y) { super(isRelative); @@ -25,8 +22,8 @@ public class Quadratic extends PathCommand { @Override public void appendPath(GeneralPath path, BuildHistory hist) { - float offx = isRelative ? hist.lastPoint.x : 0f; - float offy = isRelative ? hist.lastPoint.y : 0f; + float offx = isRelative() ? hist.getLastPoint().x : 0f; + float offy = isRelative() ? hist.getLastPoint().y : 0f; path.quadTo(kx + offx, ky + offy, x + offx, y + offy); hist.setLastPoint(x + offx, y + offy); hist.setLastKnot(kx + offx, ky + offy); diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/QuadraticSmooth.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/QuadraticSmooth.java index 5b19a32..55b7770 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/QuadraticSmooth.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/QuadraticSmooth.java @@ -4,17 +4,9 @@ import java.awt.geom.GeneralPath; public class QuadraticSmooth extends PathCommand { - public float x = 0f; + private final float x; - public float y = 0f; - - public QuadraticSmooth() { - } - - @Override - public String toString() { - return "T " + x + " " + y; - } + private final float y; public QuadraticSmooth(boolean isRelative, float x, float y) { super(isRelative); @@ -24,12 +16,12 @@ public class QuadraticSmooth extends PathCommand { @Override public void appendPath(GeneralPath path, BuildHistory hist) { - float offx = isRelative ? hist.lastPoint.x : 0f; - float offy = isRelative ? hist.lastPoint.y : 0f; - float oldKx = hist.lastKnot.x; - float oldKy = hist.lastKnot.y; - float oldX = hist.lastPoint.x; - float oldY = hist.lastPoint.y; + float offx = isRelative() ? hist.getLastPoint().x : 0f; + float offy = isRelative() ? hist.getLastPoint().y : 0f; + float oldKx = hist.getLastKnot().x; + float oldKy = hist.getLastKnot().y; + float oldX = hist.getLastPoint().x; + float oldY = hist.getLastPoint().y; float kx = oldX * 2f - oldKx; float ky = oldY * 2f - oldKy; path.quadTo(kx, ky, x + offx, y + offy); @@ -41,4 +33,9 @@ public class QuadraticSmooth extends PathCommand { public int getNumKnotsAdded() { return 4; } + + @Override + public String toString() { + return "T " + x + " " + y; + } } diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/Terminal.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/Terminal.java index 53b7cba..a36c95d 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/Terminal.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/Terminal.java @@ -4,23 +4,20 @@ import java.awt.geom.GeneralPath; public class Terminal extends PathCommand { - public Terminal() { - } - - @Override - public String toString() { - return "Z"; - } - @Override public void appendPath(GeneralPath path, BuildHistory hist) { path.closePath(); - hist.setLastPoint(hist.startPoint.x, hist.startPoint.y); - hist.setLastKnot(hist.startPoint.x, hist.startPoint.y); + hist.setLastPoint(hist.getStartPoint().x, hist.getStartPoint().y); + hist.setLastKnot(hist.getStartPoint().x, hist.getStartPoint().y); } @Override public int getNumKnotsAdded() { return 0; } + + @Override + public String toString() { + return "Z"; + } } diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/Vertical.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/Vertical.java index fe19b46..7880f3f 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/Vertical.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/pathcmd/Vertical.java @@ -4,15 +4,7 @@ import java.awt.geom.GeneralPath; public class Vertical extends PathCommand { - public float y = 0f; - - public Vertical() { - } - - @Override - public String toString() { - return "V " + y; - } + private final float y; public Vertical(boolean isRelative, float y) { super(isRelative); @@ -21,8 +13,8 @@ public class Vertical extends PathCommand { @Override public void appendPath(GeneralPath path, BuildHistory hist) { - float offx = hist.lastPoint.x; - float offy = isRelative ? hist.lastPoint.y : 0f; + float offx = hist.getLastPoint().x; + float offy = isRelative() ? hist.getLastPoint().y : 0f; path.lineTo(offx, y + offy); hist.setLastPoint(offx, y + offy); hist.setLastKnot(offx, y + offy); @@ -32,4 +24,9 @@ public class Vertical extends PathCommand { public int getNumKnotsAdded() { return 2; } + + @Override + public String toString() { + return "V " + y; + } } diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/AdobeComposite.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/util/AdobeComposite.java similarity index 96% rename from graphics-svg/src/main/java/org/xbib/graphics/svg/AdobeComposite.java rename to graphics-svg/src/main/java/org/xbib/graphics/svg/util/AdobeComposite.java index 9971921..ca25e1e 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/AdobeComposite.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/util/AdobeComposite.java @@ -1,4 +1,4 @@ -package org.xbib.graphics.svg; +package org.xbib.graphics.svg.util; import java.awt.Composite; import java.awt.CompositeContext; diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/AdobeCompositeContext.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/util/AdobeCompositeContext.java similarity index 98% rename from graphics-svg/src/main/java/org/xbib/graphics/svg/AdobeCompositeContext.java rename to graphics-svg/src/main/java/org/xbib/graphics/svg/util/AdobeCompositeContext.java index 62e481f..77e5970 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/AdobeCompositeContext.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/util/AdobeCompositeContext.java @@ -1,4 +1,4 @@ -package org.xbib.graphics.svg; +package org.xbib.graphics.svg.util; import java.awt.CompositeContext; import java.awt.image.Raster; diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/util/ClipPathConstants.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/util/ClipPathConstants.java new file mode 100644 index 0000000..b63f9ba --- /dev/null +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/util/ClipPathConstants.java @@ -0,0 +1,7 @@ +package org.xbib.graphics.svg.util; + +public interface ClipPathConstants { + int CP_USER_SPACE_ON_USE = 0; + + int CP_OBJECT_BOUNDING_BOX = 1; +} diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/util/FontUtil.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/util/FontUtil.java index 6cc292f..0453247 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/util/FontUtil.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/util/FontUtil.java @@ -1,15 +1,20 @@ package org.xbib.graphics.svg.util; import org.xbib.graphics.svg.element.Font; -import org.xbib.graphics.svg.FontSystem; +import org.xbib.graphics.svg.element.FontSystem; import org.xbib.graphics.svg.SVGDiagram; import org.xbib.graphics.svg.element.SVGElement; import org.xbib.graphics.svg.SVGException; -import org.xbib.graphics.svg.Text; +import org.xbib.graphics.svg.element.shape.Text; import org.xbib.graphics.svg.xml.StyleAttribute; +import java.awt.GraphicsEnvironment; import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.Locale; import java.util.Objects; +import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; @@ -25,6 +30,8 @@ public final class FontUtil { private static final int DEFAULT_FONT_WEIGHT = Text.TXWE_NORMAL; + private static final Set sysFontNames = new HashSet<>(); + private FontUtil() { } @@ -113,15 +120,42 @@ public final class FontUtil { if (font != null) break; } if (font == null) { - font = FontSystem.createFont(families, fontStyle, fontWeight, fontSize); + font = createFont(families, fontStyle, fontWeight, fontSize); } if (font == null) { Logger.getLogger(FontSystem.class.getName()) .log(Level.WARNING, "Could not create font " + Arrays.toString(families)); String[] defaultFont = new String[]{FontUtil.DEFAULT_FONT_FAMILY}; - font = FontSystem.createFont(defaultFont, fontStyle, fontWeight, fontSize); + font = createFont(defaultFont, fontStyle, fontWeight, fontSize); } return font; } + private static FontSystem createFont(String[] fontFamilies, int fontStyle, int fontWeight, float fontSize) { + for (String fontName : fontFamilies) { + String javaFontName = mapJavaFontName(fontName); + if (checkIfSystemFontExists(javaFontName)) { + return new FontSystem(javaFontName, fontStyle, fontWeight, fontSize); + } + } + return null; + } + + private static boolean checkIfSystemFontExists(String fontName) { + if (sysFontNames.isEmpty()) { + Collections.addAll(sysFontNames, GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(Locale.ENGLISH)); + } + return sysFontNames.contains(fontName); + } + + private static String mapJavaFontName(String fontName) { + if ("serif".equals(fontName)) { + return java.awt.Font.SERIF; + } else if ("sans-serif".equals(fontName)) { + return java.awt.Font.SANS_SERIF; + } else if ("monospace".equals(fontName)) { + return java.awt.Font.MONOSPACED; + } + return fontName; + } } diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/Handler.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/util/Handler.java similarity index 97% rename from graphics-svg/src/main/java/org/xbib/graphics/svg/Handler.java rename to graphics-svg/src/main/java/org/xbib/graphics/svg/util/Handler.java index 6a8ca58..2b5b10d 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/Handler.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/util/Handler.java @@ -1,4 +1,4 @@ -package org.xbib.graphics.svg; +package org.xbib.graphics.svg.util; import java.io.ByteArrayInputStream; import java.io.InputStream; diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/HandlerFactory.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/util/HandlerFactory.java similarity index 84% rename from graphics-svg/src/main/java/org/xbib/graphics/svg/HandlerFactory.java rename to graphics-svg/src/main/java/org/xbib/graphics/svg/util/HandlerFactory.java index 75b5437..a462bdf 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/HandlerFactory.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/util/HandlerFactory.java @@ -1,6 +1,4 @@ -package org.xbib.graphics.svg; - -import org.xbib.graphics.svg.Handler; +package org.xbib.graphics.svg.util; import java.net.URLStreamHandler; import java.net.URLStreamHandlerFactory; diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/MarkerLayout.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/util/MarkerLayout.java similarity index 97% rename from graphics-svg/src/main/java/org/xbib/graphics/svg/MarkerLayout.java rename to graphics-svg/src/main/java/org/xbib/graphics/svg/util/MarkerLayout.java index c509f8d..8556589 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/MarkerLayout.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/util/MarkerLayout.java @@ -1,4 +1,6 @@ -package org.xbib.graphics.svg; +package org.xbib.graphics.svg.util; + +import org.xbib.graphics.svg.element.shape.Marker; import java.awt.Shape; import java.awt.geom.PathIterator; @@ -86,7 +88,6 @@ public class MarkerLayout { for (int i = 1; i < markerList.size(); ++i) { MarkerPos prev = markerList.get(i - 1); MarkerPos cur = markerList.get(i); - if (cur.getType() == Marker.MARKER_START) { prev.setType(Marker.MARKER_END); } diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/util/MarkerPos.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/util/MarkerPos.java new file mode 100644 index 0000000..31923da --- /dev/null +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/util/MarkerPos.java @@ -0,0 +1,62 @@ +package org.xbib.graphics.svg.util; + +public class MarkerPos { + + private int type; + + double x; + + double y; + + double dx; + + double dy; + + public MarkerPos(int type, double x, double y, double dx, double dy) { + this.type = type; + this.x = x; + this.y = y; + this.dx = dx; + this.dy = dy; + } + + public void setType(int type) { + this.type = type; + } + + public int getType() { + return type; + } + + public void setDx(double dx) { + this.dx = dx; + } + + public double getDx() { + return dx; + } + + public void setDy(double dy) { + this.dy = dy; + } + + public double getDy() { + return dy; + } + + public void setX(double x) { + this.x = x; + } + + public double getX() { + return x; + } + + public void setY(double y) { + this.y = y; + } + + public double getY() { + return y; + } +} diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/util/PaintUtil.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/util/PaintUtil.java index 7d1a95b..bcc7540 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/util/PaintUtil.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/util/PaintUtil.java @@ -21,8 +21,8 @@ public class PaintUtil { public static final boolean DEBUG_PAINT = false; public static void paintElement(Graphics2D g, RenderableElement element) throws SVGException, IOException { - if (element.cachedMask != null - || (element.filter != null && !element.filter.filterEffects.isEmpty())) { + if (element.getCachedMask() != null + || (element.getFilter() != null && !element.getFilter().getFilterEffects().isEmpty())) { renderElement(g, element); } else { element.doRender(g); @@ -73,33 +73,33 @@ public class PaintUtil { float xScale = getTransformScale(origin, testPoint, transform); testPoint.setLocation(0, 1); float yScale = getTransformScale(origin, testPoint, transform); - List filterOps = element.filter == null + List filterOps = element.getFilter() == null ? Collections.emptyList() - : element.filter.filterEffects.stream() + : element.getFilter().getFilterEffects().stream() .flatMap(f -> f.getOperations(dstBounds, xScale, yScale).stream()) .filter(Objects::nonNull) .collect(Collectors.toList()); for (FilterOp filterOp : filterOps) { int right = Math.max(dstBounds.x + dstBounds.width, - filterOp.requiredImageBounds.x + filterOp.requiredImageBounds.width); + filterOp.getRequiredImageBounds().x + filterOp.getRequiredImageBounds().width); int bottom = Math.max(dstBounds.y + dstBounds.height, - filterOp.requiredImageBounds.y + filterOp.requiredImageBounds.height); - dstBounds.x = Math.min(dstBounds.x, filterOp.requiredImageBounds.x); - dstBounds.y = Math.min(dstBounds.y, filterOp.requiredImageBounds.y); + filterOp.getRequiredImageBounds().y + filterOp.getRequiredImageBounds().height); + dstBounds.x = Math.min(dstBounds.x, filterOp.getRequiredImageBounds().x); + dstBounds.y = Math.min(dstBounds.y, filterOp.getRequiredImageBounds().y); dstBounds.width = right - dstBounds.x; dstBounds.height = bottom - dstBounds.y; } BufferedImage elementImage = PaintUtil.paintToBuffer(gg, transform, dstBounds, transformedBounds, element, null, true); for (FilterOp filterOp : filterOps) { - elementImage = filterOp.op.filter(elementImage, null); + elementImage = filterOp.getOp().filter(elementImage, null); } - if (element.cachedMask != null) { + if (element.getCachedMask() != null) { BufferedImage maskImage = PaintUtil.paintToBuffer(gg, transform, dstBounds, transformedBounds, - element.cachedMask, Color.BLACK, false); + element.getCachedMask(), Color.BLACK, false); Graphics2D elementGraphics = (Graphics2D) elementImage.getGraphics(); elementGraphics.setRenderingHints(gg.getRenderingHints()); - elementGraphics.setComposite(element.cachedMask.createMaskComposite()); + elementGraphics.setComposite(element.getCachedMask().createMaskComposite()); elementGraphics.drawImage(maskImage, 0, 0, null); elementGraphics.dispose(); } diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/PatternPaint.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/util/PatternPaint.java similarity index 96% rename from graphics-svg/src/main/java/org/xbib/graphics/svg/PatternPaint.java rename to graphics-svg/src/main/java/org/xbib/graphics/svg/util/PatternPaint.java index ee9c55a..cc4298e 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/PatternPaint.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/util/PatternPaint.java @@ -1,4 +1,4 @@ -package org.xbib.graphics.svg; +package org.xbib.graphics.svg.util; import java.awt.Paint; import java.awt.PaintContext; diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/PatternPaintContext.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/util/PatternPaintContext.java similarity index 98% rename from graphics-svg/src/main/java/org/xbib/graphics/svg/PatternPaintContext.java rename to graphics-svg/src/main/java/org/xbib/graphics/svg/util/PatternPaintContext.java index 39a74c5..b5e7dfc 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/PatternPaintContext.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/util/PatternPaintContext.java @@ -1,4 +1,4 @@ -package org.xbib.graphics.svg; +package org.xbib.graphics.svg.util; import java.awt.PaintContext; import java.awt.Rectangle; diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/util/TextConst.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/util/TextConst.java new file mode 100644 index 0000000..8e8957d --- /dev/null +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/util/TextConst.java @@ -0,0 +1,41 @@ +package org.xbib.graphics.svg.util; + +public interface TextConst { + int TXAN_START = 0; + + int TXAN_MIDDLE = 1; + + int TXAN_END = 2; + + int TXST_NORMAL = 0; + + int TXST_ITALIC = 1; + + int TXST_OBLIQUE = 2; + + int TXWE_NORMAL = 0; + + int TXWE_BOLD = 1; + + int TXWE_BOLDER = 2; + + int TXWE_LIGHTER = 3; + + int TXWE_100 = 4; + + int TXWE_200 = 5; + + int TXWE_300 = 6; + + int TXWE_400 = 7; + + int TXWE_500 = 8; + + int TXWE_600 = 9; + + int TXWE_700 = 10; + + int TXWE_800 = 11; + + int TXWE_900 = 12; +} diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/util/VectorEffect.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/util/VectorEffect.java new file mode 100644 index 0000000..74940bf --- /dev/null +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/util/VectorEffect.java @@ -0,0 +1,7 @@ +package org.xbib.graphics.svg.util; + +public interface VectorEffect { + int VECTOR_EFFECT_NONE = 0; + + int VECTOR_EFFECT_NON_SCALING_STROKE = 1; +} diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/xml/ColorTable.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/xml/ColorTable.java index 1e402d1..5617be8 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/xml/ColorTable.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/xml/ColorTable.java @@ -9,7 +9,7 @@ import java.util.regex.Pattern; public class ColorTable { - static final Map colorTable; + private static final Map colorTable; static { Map table = new HashMap<>(); diff --git a/graphics-svg/src/main/java/org/xbib/graphics/svg/xml/XMLParseUtil.java b/graphics-svg/src/main/java/org/xbib/graphics/svg/xml/XMLParseUtil.java index 7195709..7d2d980 100644 --- a/graphics-svg/src/main/java/org/xbib/graphics/svg/xml/XMLParseUtil.java +++ b/graphics-svg/src/main/java/org/xbib/graphics/svg/xml/XMLParseUtil.java @@ -1,10 +1,10 @@ package org.xbib.graphics.svg.xml; import java.awt.Toolkit; -import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.List; +import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Matcher; @@ -194,7 +194,7 @@ public class XMLParseUtil { return new NumberWithUnits(val); } - public static HashMap parseStyle(String styleString, HashMap map) { + public static Map parseStyle(String styleString, Map map) { Pattern patSemi = Pattern.compile(";"); String[] styles = patSemi.split(styleString); for (String style : styles) { diff --git a/graphics-svg/src/test/java/org/xbib/graphics/svg/test/SimpleSVGLoadTest.java b/graphics-svg/src/test/java/org/xbib/graphics/svg/test/SimpleSVGLoadTest.java index 0558fb0..061a280 100644 --- a/graphics-svg/src/test/java/org/xbib/graphics/svg/test/SimpleSVGLoadTest.java +++ b/graphics-svg/src/test/java/org/xbib/graphics/svg/test/SimpleSVGLoadTest.java @@ -6,6 +6,7 @@ import org.xbib.graphics.svg.SVGUniverse; import java.io.IOException; import java.io.InputStream; +import java.util.logging.Logger; public class SimpleSVGLoadTest { @@ -14,5 +15,6 @@ public class SimpleSVGLoadTest { InputStream inputStream = getClass().getResourceAsStream("test.svg"); SVGUniverse svgUniverse = new SVGUniverse(); SVGDiagram diagram = svgUniverse.getDiagram(svgUniverse.loadSVG(inputStream, "test.svg")); + Logger.getAnonymousLogger().info(diagram.toString()); } } diff --git a/graphics-svg/src/test/resources/org/xbib/graphics/svg/test/test.svg b/graphics-svg/src/test/resources/org/xbib/graphics/svg/test/test.svg index f04b690..57194dd 100644 --- a/graphics-svg/src/test/resources/org/xbib/graphics/svg/test/test.svg +++ b/graphics-svg/src/test/resources/org/xbib/graphics/svg/test/test.svg @@ -2,32 +2,6 @@ - - - - - - - - - Bar Chart