[javafxsvg] 01/03: Import Upstream version 1.2.1

Tony Mancill tmancill at moszumanska.debian.org
Wed Mar 8 00:00:08 UTC 2017


This is an automated email from the git hooks/post-receive script.

tmancill pushed a commit to branch master
in repository javafxsvg.

commit 7080ecafb26d9f42849cea3537393f6787478fd3
Author: tony mancill <tmancill at debian.org>
Date:   Mon Mar 6 21:54:08 2017 -0800

    Import Upstream version 1.2.1
---
 .gitignore                                         |   5 +
 LICENSE.txt                                        |  24 ++++
 README.md                                          |  32 +++++
 pom.xml                                            | 152 +++++++++++++++++++++
 .../javafxsvg/BufferedImageTranscoder.java         |  52 +++++++
 .../javafxsvg/FixedPixelDensityImageFrame.java     |  20 +++
 .../centerdevice/javafxsvg/ScreenHelper.java       |  50 +++++++
 .../centerdevice/javafxsvg/SvgDescriptor.java      |  26 ++++
 .../centerdevice/javafxsvg/SvgImageLoader.java     | 127 +++++++++++++++++
 .../javafxsvg/SvgImageLoaderFactory.java           |  32 +++++
 .../javafxsvg/TestLoadImageUsingClass.java         |  44 ++++++
 .../javafxsvg/TestLoadImageUsingCss.java           |  41 ++++++
 .../javafxsvg/TestLoadImageUsingFxml.java          |  44 ++++++
 src/test/resources/bacon.svg                       | 147 ++++++++++++++++++++
 src/test/resources/imagetest.css                   |   3 +
 src/test/resources/imagetest.fxml                  |  18 +++
 16 files changed, 817 insertions(+)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..25ac7c7
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,5 @@
+.classpath
+.project
+screenshot*.png
+.settings/*
+target/*
diff --git a/LICENSE.txt b/LICENSE.txt
new file mode 100644
index 0000000..904f63c
--- /dev/null
+++ b/LICENSE.txt
@@ -0,0 +1,24 @@
+Copyright (c) 2015, codecentric AG
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+    * Redistributions of source code must retain the above copyright
+      notice, this list of conditions and the following disclaimer.
+    * Redistributions in binary form must reproduce the above copyright
+      notice, this list of conditions and the following disclaimer in the
+      documentation and/or other materials provided with the distribution.
+    * Neither the name of the codecentric AG nor the
+      names of its contributors may be used to endorse or promote products
+      derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL CODECENTRIC AG BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..cffe92d
--- /dev/null
+++ b/README.md
@@ -0,0 +1,32 @@
+# JavaFxSVG
+
+A simple library to add SVG support to JavaFX, allowing to use SVG
+graphics just like any other image type.
+
+More details about the project can be found at the codecentric blog: 
+[Adding a custom image renderer to JavaFX 8](https://blog.codecentric.de/en/2015/03/adding-custom-image-renderer-javafx-8/)
+
+## Installation
+
+If you are using maven, just add JavaFxSVG to the dependencies
+
+		<dependency>
+			<groupId>de.codecentric.centerdevice</groupId>
+			<artifactId>javafxsvg</artifactId>
+			<version>1.2.1</version>
+		</dependency>
+
+## Usage
+
+Add this line to your application:
+
+    SvgImageLoaderFactory.install();
+    
+preferably before any JavaFX code is executed. After this, you can use 
+SVG images just as any other Image in your application.
+
+## Known Issues
+
+Currently, SVGs are required to start with either "<svg" or "<?xml" 
+due to some rather static signature matching. As a result, svg might
+not be displayed when starting with whitespace characters or comment.
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..57cbe99
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,152 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<groupId>de.codecentric.centerdevice</groupId>
+	<artifactId>javafxsvg</artifactId>
+	<version>1.2.1</version>
+	<name>CenterDevice JavaFxSVG</name>
+	<packaging>jar</packaging>
+	<description>JavaFxSVG is a simple library adding SVG support to JavaFX and thus allowing to use SVG graphics just like any other image type.</description>
+	<url>https://github.com/codecentric/javafxsvg</url>
+	<developers>
+		<developer>
+			<id>jan.gassen</id>
+			<name>Jan Gassen</name>
+			<email>jan.gassen at centerdevice.com</email>
+			<organization>CenterDevice GmbH</organization>
+			<organizationUrl>http://www.centerdevice.de</organizationUrl>
+		</developer>
+	</developers>
+
+	<organization>
+		<name>CenterDevice GmbH</name>
+	</organization>
+
+	<properties>
+		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+	</properties>
+
+  <licenses>
+		<license>
+			<name>BSD 3-Clause</name>
+			<url>http://opensource.org/licenses/BSD-3-Clause</url>
+			<distribution>repo</distribution>
+		</license>
+	</licenses>
+
+	<scm>
+		<url>https://github.com/codecentric/javafxsvg.git</url>
+	</scm>
+
+	<distributionManagement>
+		<snapshotRepository>
+			<id>ossrh</id>
+			<url>https://oss.sonatype.org/content/repositories/snapshots</url>
+		</snapshotRepository>
+		<repository>
+			<id>ossrh</id>
+			<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
+		</repository>
+	</distributionManagement>
+
+	<build>
+    <finalName>centerdevice-javafxsvg</finalName>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-eclipse-plugin</artifactId>
+				<version>2.9</version>
+				<configuration>
+					<wtpversion>2.0</wtpversion>
+					<downloadSources>true</downloadSources>
+					<downloadJavadocs>true</downloadJavadocs>
+				</configuration>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<version>3.2</version>
+				<configuration>
+					<source>1.8</source>
+					<target>1.8</target>
+				</configuration>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-source-plugin</artifactId>
+				<version>2.2.1</version>
+				<executions>
+					<execution>
+						<id>attach-sources</id>
+						<goals>
+							<goal>jar-no-fork</goal>
+						</goals>
+					</execution>
+				</executions>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-javadoc-plugin</artifactId>
+				<version>2.9.1</version>
+				<executions>
+					<execution>
+						<id>attach-javadocs</id>
+						<goals>
+							<goal>jar</goal>
+						</goals>
+					</execution>
+				</executions>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-gpg-plugin</artifactId>
+				<version>1.5</version>
+				<executions>
+					<execution>
+						<id>sign-artifacts</id>
+						<phase>verify</phase>
+						<goals>
+							<goal>sign</goal>
+						</goals>
+					</execution>
+				</executions>
+			</plugin>
+			<plugin>
+				<groupId>org.sonatype.plugins</groupId>
+				<artifactId>nexus-staging-maven-plugin</artifactId>
+				<version>1.6.3</version>
+				<extensions>true</extensions>
+				<configuration>
+					<serverId>ossrh</serverId>
+					<nexusUrl>https://oss.sonatype.org/</nexusUrl>
+					<autoReleaseAfterClose>true</autoReleaseAfterClose>
+				</configuration>
+			</plugin>
+		</plugins>
+	</build>
+
+	<dependencies>
+		<dependency>
+			<groupId>org.apache.xmlgraphics</groupId>
+			<artifactId>batik-transcoder</artifactId>
+			<version>1.8</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.xmlgraphics</groupId>
+			<artifactId>xmlgraphics-commons</artifactId>
+			<version>2.1</version>
+		</dependency>
+		<dependency>
+			<groupId>org.loadui</groupId>
+			<artifactId>testFx</artifactId>
+			<version>3.1.2</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+			<version>4.12</version>
+			<scope>test</scope>
+		</dependency>
+	</dependencies>
+</project>
diff --git a/src/main/java/de/codecentric/centerdevice/javafxsvg/BufferedImageTranscoder.java b/src/main/java/de/codecentric/centerdevice/javafxsvg/BufferedImageTranscoder.java
new file mode 100644
index 0000000..6292718
--- /dev/null
+++ b/src/main/java/de/codecentric/centerdevice/javafxsvg/BufferedImageTranscoder.java
@@ -0,0 +1,52 @@
+package de.codecentric.centerdevice.javafxsvg;
+
+import java.awt.image.BufferedImage;
+
+import org.apache.batik.transcoder.TranscoderException;
+import org.apache.batik.transcoder.TranscoderOutput;
+import org.apache.batik.transcoder.image.ImageTranscoder;
+
+/**
+ * Code based on: https://gist.github.com/ComFreek/b0684ac324c815232556
+ * 
+ * Many thanks to bb-generation for sharing this code!
+ * 
+ * License unfortunately unknown, but using this code is probably categorized as
+ * "fair use" (because the code is in my opinion too simple to be licensed)
+ * 
+ * @author bb-generation
+ * @see <a href="https://web.archive.org/web/20131215231214/http://bbgen.net/blog/2011/06/java-svg-to-bufferedimage/">java-
+ *      svg-to-bufferedimage (as archived by archive.org)</a>
+ */
+public class BufferedImageTranscoder extends ImageTranscoder {
+
+	private BufferedImage img = null;
+	private final int type;
+
+	public BufferedImageTranscoder(int type) {
+		this.type = type;
+	}
+
+	@Override
+	protected void setImageSize(float width, float height) {
+		if (width > 0 && height > 0) {
+			super.setImageSize(width, height);
+		}
+	}
+
+	@Override
+	public BufferedImage createImage(int width, int height) {
+		BufferedImage bi = new BufferedImage(width, height, type);
+		return bi;
+	}
+
+	@Override
+	public void writeImage(BufferedImage img, TranscoderOutput to)
+			throws TranscoderException {
+		this.img = img;
+	}
+
+	public BufferedImage getBufferedImage() {
+		return img;
+	}
+}
diff --git a/src/main/java/de/codecentric/centerdevice/javafxsvg/FixedPixelDensityImageFrame.java b/src/main/java/de/codecentric/centerdevice/javafxsvg/FixedPixelDensityImageFrame.java
new file mode 100644
index 0000000..2d078d7
--- /dev/null
+++ b/src/main/java/de/codecentric/centerdevice/javafxsvg/FixedPixelDensityImageFrame.java
@@ -0,0 +1,20 @@
+package de.codecentric.centerdevice.javafxsvg;
+
+import java.nio.ByteBuffer;
+
+import com.sun.javafx.iio.ImageFrame;
+import com.sun.javafx.iio.ImageMetadata;
+import com.sun.javafx.iio.ImageStorage.ImageType;
+
+public class FixedPixelDensityImageFrame extends ImageFrame {
+
+	public FixedPixelDensityImageFrame(ImageType imageType, ByteBuffer imageData, int width, int height, int stride,
+			byte[][] palette, float pixelScale, ImageMetadata metadata) {
+		super(imageType, imageData, width, height, stride, palette, pixelScale, metadata);
+	}
+
+	@Override
+	public void setPixelScale(float pixelScale) {
+		// Prevent ImageStorage class from overwriting the pixel density
+	}
+}
diff --git a/src/main/java/de/codecentric/centerdevice/javafxsvg/ScreenHelper.java b/src/main/java/de/codecentric/centerdevice/javafxsvg/ScreenHelper.java
new file mode 100644
index 0000000..3aca71c
--- /dev/null
+++ b/src/main/java/de/codecentric/centerdevice/javafxsvg/ScreenHelper.java
@@ -0,0 +1,50 @@
+package de.codecentric.centerdevice.javafxsvg;
+
+import javafx.stage.Screen;
+
+import java.lang.reflect.Method;
+
+public class ScreenHelper {
+
+  private static ScreenAccessor accessor = null;
+
+  public static class ScreenAccessor {
+    private static Method getRenderScale = null;
+
+    private Method getScaleMethod() throws NoSuchMethodException {
+      if (getRenderScale == null) {
+        getRenderScale = lookupScaleMethod();
+      }
+
+      return getRenderScale;
+    }
+
+    private Method lookupScaleMethod() throws NoSuchMethodException {
+      Method scaleMethod;
+      try {
+        scaleMethod = Screen.class.getDeclaredMethod("getScale"); // until 8u51
+      } catch (NoSuchMethodException e) {
+        scaleMethod = Screen.class.getDeclaredMethod("getRenderScale");
+      }
+      scaleMethod.setAccessible(true);
+      return scaleMethod;
+    }
+
+    public float getRenderScale(Screen screen) {
+      try {
+        Method m = getScaleMethod();
+        return ((float) m.invoke(screen));
+      } catch (ReflectiveOperationException e) {
+        return 1f;
+      }
+    }
+  }
+
+  public static ScreenAccessor getScreenAccessor() {
+    if (accessor == null) {
+      accessor = new ScreenAccessor();
+    }
+
+    return accessor;
+  }
+}
diff --git a/src/main/java/de/codecentric/centerdevice/javafxsvg/SvgDescriptor.java b/src/main/java/de/codecentric/centerdevice/javafxsvg/SvgDescriptor.java
new file mode 100644
index 0000000..ad004f6
--- /dev/null
+++ b/src/main/java/de/codecentric/centerdevice/javafxsvg/SvgDescriptor.java
@@ -0,0 +1,26 @@
+package de.codecentric.centerdevice.javafxsvg;
+
+import com.sun.javafx.iio.common.ImageDescriptor;
+
+public class SvgDescriptor extends ImageDescriptor {
+
+	private static final String formatName = "SVG";
+
+	private static final String[] extensions = { "svg" };
+
+	private static final Signature[] signatures = {
+			new Signature("<svg".getBytes()), new Signature("<?xml".getBytes()) };
+
+	private static ImageDescriptor theInstance = null;
+
+	private SvgDescriptor() {
+		super(formatName, extensions, signatures);
+	}
+
+	public static synchronized ImageDescriptor getInstance() {
+		if (theInstance == null) {
+			theInstance = new SvgDescriptor();
+		}
+		return theInstance;
+	}
+}
diff --git a/src/main/java/de/codecentric/centerdevice/javafxsvg/SvgImageLoader.java b/src/main/java/de/codecentric/centerdevice/javafxsvg/SvgImageLoader.java
new file mode 100644
index 0000000..ee4cce3
--- /dev/null
+++ b/src/main/java/de/codecentric/centerdevice/javafxsvg/SvgImageLoader.java
@@ -0,0 +1,127 @@
+package de.codecentric.centerdevice.javafxsvg;
+
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.ByteBuffer;
+
+import javafx.stage.Screen;
+import org.apache.batik.transcoder.TranscoderException;
+import org.apache.batik.transcoder.TranscoderInput;
+
+import com.sun.javafx.iio.ImageFrame;
+import com.sun.javafx.iio.ImageStorage;
+import com.sun.javafx.iio.common.ImageLoaderImpl;
+
+import static org.apache.batik.transcoder.SVGAbstractTranscoder.KEY_HEIGHT;
+import static org.apache.batik.transcoder.SVGAbstractTranscoder.KEY_WIDTH;
+
+public class SvgImageLoader extends ImageLoaderImpl {
+
+	private static final int DEFAULT_SIZE = 400;
+
+	private static final int BYTES_PER_PIXEL = 4; // RGBA
+
+	private final InputStream input;
+
+	private float maxPixelScale = 0;
+
+	protected SvgImageLoader(InputStream input) {
+		super(SvgDescriptor.getInstance());
+
+		if (input == null) {
+			throw new IllegalArgumentException("input == null!");
+		}
+
+		this.input = input;
+	}
+
+	@Override
+	public ImageFrame load(int imageIndex, int width, int height, boolean preserveAspectRatio, boolean smooth)
+			throws IOException {
+		if (0 != imageIndex) {
+			return null;
+		}
+
+		int imageWidth = width > 0 ? width : DEFAULT_SIZE;
+		int imageHeight = height > 0 ? height : DEFAULT_SIZE;
+
+		try {
+			return createImageFrame(imageWidth, imageHeight, getPixelScale());
+		} catch (TranscoderException ex) {
+			throw new IOException(ex);
+		}
+	}
+
+	public float getPixelScale() {
+		if (maxPixelScale == 0) {
+			maxPixelScale = calculateMaxRenderScale();
+		}
+		return maxPixelScale;
+	}
+
+	public float calculateMaxRenderScale() {
+		float maxRenderScale = 0;
+		ScreenHelper.ScreenAccessor accessor = ScreenHelper.getScreenAccessor();
+		for (Screen screen : Screen.getScreens()) {
+			maxRenderScale = Math.max(maxRenderScale, accessor.getRenderScale(screen));
+		}
+		return maxRenderScale;
+	}
+
+	private ImageFrame createImageFrame(int width, int height, float pixelScale) throws TranscoderException {
+		BufferedImage bufferedImage = getTranscodedImage(width * pixelScale, height * pixelScale);
+		ByteBuffer imageData = getImageData(bufferedImage);
+
+		return new FixedPixelDensityImageFrame(ImageStorage.ImageType.RGBA, imageData, bufferedImage.getWidth(),
+				bufferedImage.getHeight(), getStride(bufferedImage), null, pixelScale, null);
+	}
+
+	private BufferedImage getTranscodedImage(float width, float height) throws TranscoderException {
+		BufferedImageTranscoder trans = new BufferedImageTranscoder(BufferedImage.TYPE_INT_ARGB);
+		trans.addTranscodingHint(KEY_WIDTH, width);
+		trans.addTranscodingHint(KEY_HEIGHT, height);
+		trans.transcode(new TranscoderInput(this.input), null);
+
+		return trans.getBufferedImage();
+	}
+
+	private int getStride(BufferedImage bufferedImage) {
+		return bufferedImage.getWidth() * BYTES_PER_PIXEL;
+	}
+
+	private ByteBuffer getImageData(BufferedImage bufferedImage) {
+		int[] rgb = bufferedImage.getRGB(0, 0, bufferedImage.getWidth(), bufferedImage.getHeight(), null, 0,
+				bufferedImage.getWidth());
+
+		byte[] imageData = new byte[getStride(bufferedImage) * bufferedImage.getHeight()];
+
+		copyColorToBytes(rgb, imageData);
+		return ByteBuffer.wrap(imageData);
+	}
+
+	private void copyColorToBytes(int[] rgb, byte[] imageData) {
+		if (rgb.length * BYTES_PER_PIXEL != imageData.length) {
+			throw new ArrayIndexOutOfBoundsException();
+		}
+
+		ByteBuffer byteBuffer = ByteBuffer.allocate(Integer.BYTES);
+
+		for (int i = 0; i < rgb.length; i++) {
+			byte[] bytes = byteBuffer.putInt(rgb[i]).array();
+
+			int dataOffset = BYTES_PER_PIXEL * i;
+			imageData[dataOffset] = bytes[1];
+			imageData[dataOffset + 1] = bytes[2];
+			imageData[dataOffset + 2] = bytes[3];
+			imageData[dataOffset + 3] = bytes[0];
+
+			byteBuffer.clear();
+		}
+	}
+
+	@Override
+	public void dispose() {
+		// Nothing to do
+	}
+}
diff --git a/src/main/java/de/codecentric/centerdevice/javafxsvg/SvgImageLoaderFactory.java b/src/main/java/de/codecentric/centerdevice/javafxsvg/SvgImageLoaderFactory.java
new file mode 100644
index 0000000..ac9f67d
--- /dev/null
+++ b/src/main/java/de/codecentric/centerdevice/javafxsvg/SvgImageLoaderFactory.java
@@ -0,0 +1,32 @@
+package de.codecentric.centerdevice.javafxsvg;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import com.sun.javafx.iio.ImageFormatDescription;
+import com.sun.javafx.iio.ImageLoader;
+import com.sun.javafx.iio.ImageLoaderFactory;
+import com.sun.javafx.iio.ImageStorage;
+
+public class SvgImageLoaderFactory implements ImageLoaderFactory {
+	private static final ImageLoaderFactory instance = new SvgImageLoaderFactory();
+
+	public static final void install() {
+		ImageStorage.addImageLoaderFactory(instance);
+	}
+
+	public static final ImageLoaderFactory getInstance() {
+		return instance;
+	}
+
+	@Override
+	public ImageFormatDescription getFormatDescription() {
+		return SvgDescriptor.getInstance();
+	}
+
+	@Override
+	public ImageLoader createImageLoader(InputStream input) throws IOException {
+		return new SvgImageLoader(input);
+	}
+
+}
diff --git a/src/test/java/de/codecentric/centerdevice/javafxsvg/TestLoadImageUsingClass.java b/src/test/java/de/codecentric/centerdevice/javafxsvg/TestLoadImageUsingClass.java
new file mode 100644
index 0000000..58d535d
--- /dev/null
+++ b/src/test/java/de/codecentric/centerdevice/javafxsvg/TestLoadImageUsingClass.java
@@ -0,0 +1,44 @@
+package de.codecentric.centerdevice.javafxsvg;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.InputStream;
+
+import javafx.scene.Parent;
+import javafx.scene.image.Image;
+import javafx.scene.image.ImageView;
+import javafx.scene.layout.AnchorPane;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.loadui.testfx.GuiTest;
+
+public class TestLoadImageUsingClass extends GuiTest {
+
+	@BeforeClass
+	public static void installSvgLoader() {
+		SvgImageLoaderFactory.install();
+	}
+
+	@Override
+	protected Parent getRootNode() {
+		InputStream imageData = this.getClass().getClassLoader()
+				.getResourceAsStream("bacon.svg");
+
+		Image image = new Image(imageData);
+		ImageView imageView = new ImageView(image);
+		imageView.setId("TestImage");
+
+		return new AnchorPane(imageView);
+	}
+
+	@Test
+	public void imageShouldBeVisible() {
+		ImageView imageView = find("#TestImage");
+		Image image = imageView.getImage();
+
+		assertNotNull(image);
+		assertFalse(image.errorProperty().get());
+	}
+}
diff --git a/src/test/java/de/codecentric/centerdevice/javafxsvg/TestLoadImageUsingCss.java b/src/test/java/de/codecentric/centerdevice/javafxsvg/TestLoadImageUsingCss.java
new file mode 100644
index 0000000..542997a
--- /dev/null
+++ b/src/test/java/de/codecentric/centerdevice/javafxsvg/TestLoadImageUsingCss.java
@@ -0,0 +1,41 @@
+package de.codecentric.centerdevice.javafxsvg;
+
+import static org.junit.Assert.assertNotNull;
+import javafx.scene.Node;
+import javafx.scene.Parent;
+import javafx.scene.control.Button;
+import javafx.scene.layout.AnchorPane;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.loadui.testfx.GuiTest;
+
+public class TestLoadImageUsingCss extends GuiTest {
+
+	@BeforeClass
+	public static void installSvgLoader() {
+		SvgImageLoaderFactory.install();
+	}
+
+	@Override
+	protected Parent getRootNode() {
+		String css = getClass().getClassLoader().getResource("imagetest.css")
+				.toExternalForm();
+
+		Button button = new Button("Test");
+		button.setId("TestButton");
+
+		AnchorPane anchorPane = new AnchorPane(button);
+		anchorPane.getStylesheets().add(css);
+
+		return anchorPane;
+	}
+
+	@Test
+	public void imageShouldBeVisible() {
+		Button button = find("#TestButton");
+		Node image = button.getGraphic();
+
+		assertNotNull(image);
+	}
+}
diff --git a/src/test/java/de/codecentric/centerdevice/javafxsvg/TestLoadImageUsingFxml.java b/src/test/java/de/codecentric/centerdevice/javafxsvg/TestLoadImageUsingFxml.java
new file mode 100644
index 0000000..4a52ff6
--- /dev/null
+++ b/src/test/java/de/codecentric/centerdevice/javafxsvg/TestLoadImageUsingFxml.java
@@ -0,0 +1,44 @@
+package de.codecentric.centerdevice.javafxsvg;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.IOException;
+
+import javafx.fxml.FXMLLoader;
+import javafx.scene.Parent;
+import javafx.scene.image.Image;
+import javafx.scene.image.ImageView;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.loadui.testfx.GuiTest;
+
+public class TestLoadImageUsingFxml extends GuiTest {
+
+	@BeforeClass
+	public static void installSvgLoader() {
+		SvgImageLoaderFactory.install();
+	}
+
+	@Override
+	protected Parent getRootNode() {
+		try {
+			return FXMLLoader.load(getClass().getClassLoader().getResource(
+					"imagetest.fxml"));
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+
+		return null;
+	}
+
+	@Test
+	public void imageShouldBeVisible() {
+		ImageView imageView = find("#TestImage");
+		Image image = imageView.getImage();
+
+		assertNotNull(image);
+		assertFalse(image.errorProperty().get());
+	}
+}
diff --git a/src/test/resources/bacon.svg b/src/test/resources/bacon.svg
new file mode 100644
index 0000000..0837b7d
--- /dev/null
+++ b/src/test/resources/bacon.svg
@@ -0,0 +1,147 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+<svg
+    xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+    xmlns="http://www.w3.org/2000/svg"
+    xmlns:xlink="http://www.w3.org/1999/xlink"
+    xmlns:ns1="http://sozi.baierouge.fr"
+    xmlns:cc="http://creativecommons.org/ns#"
+    xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+    xmlns:dc="http://purl.org/dc/elements/1.1/"
+    id="svg2"
+    xml:space="preserve"
+    viewBox="0 0 64.106 28.822"
+    version="1.1"
+  >
+  <g
+      id="g10"
+      transform="matrix(1.25 0 0 -1.25 0 28.822)"
+    >
+    <g
+        id="g12"
+      >
+      <path
+          id="path14"
+          style="fill-rule:evenodd;fill:#ecb6a3"
+          d="m33.289 13.347c0.184-0.047 0.363-0.09 0.539-0.129 0.508-0.14 0.961-0.336 1.363-0.582 0.211-0.144 0.399-0.301 0.571-0.465 0.164-0.183 0.308-0.386 0.433-0.601 0.106-0.211 0.215-0.43 0.332-0.657 0.078-0.183 0.227-0.304 0.446-0.371 0.343-0.109 0.511-0.332 0.496-0.672-0.024-0.226-0.012-0.449 0.035-0.667 0.016-0.157 0.055-0.309 0.121-0.454 0.27-0.535 0.676-0.914 1.227-1.14 0.89-0.391 1.785-0.602 2.683-0.629 0.895-0.059 1.703 0.125 2.422 0.547 0.117 0.07 0.262 0.14 0.434 0.218 1.09 [...]
+          inkscape:connector-curvature="0"
+      />
+      <path
+          id="path16"
+          style="fill-rule:evenodd;fill:#da5b5b"
+          d="m5.402 13.663-0.004 0.016c0.024 0.024 0.055 0.047 0.098 0.066-0.078 0-0.156 0.008-0.238 0.024 0.019 0.004 0.031 0.023 0.031 0.051-0.242-0.094-0.547-0.121-0.91-0.086-0.527 0.043-0.914 0.015-1.156-0.078-0.067-0.039-0.203-0.11-0.407-0.211-0.175-0.125-0.273-0.188-0.293-0.192-0.066-0.031-0.168-0.019-0.296 0.035-0.11 0.016-0.176 0.051-0.2 0.106-0.039 0.066-0.058 0.144-0.066 0.238 0.465 0.27 0.965 0.512 1.5 0.735 0.566 0.179 1.027 0.476 1.387 0.886 0.269 0.285 0.57 0.547 0.91 0.789 [...]
+          inkscape:connector-curvature="0"
+      />
+      <path
+          id="path18"
+          style="fill-rule:evenodd;fill:#ffdac8"
+          d="m7.906 15.902c-0.187 0.062-0.386 0.117-0.59 0.156-0.625 0.16-1.097 0.191-1.418 0.094 0.016 0.015 0.043 0.035 0.086 0.066 0.274 0.16 0.582 0.285 0.934 0.379 0.23 0.102 0.461 0.113 0.695 0.031 0.141-0.058 0.289-0.125 0.453-0.195 0.293-0.125 0.598-0.242 0.918-0.359 0.254-0.102 0.493-0.227 0.715-0.368 0.61-0.375 1.278-0.664 2.016-0.867 0.543-0.172 1.101-0.301 1.668-0.386 0.816-0.157 1.613-0.254 2.39-0.293 0.118-0.008 0.239 0.003 0.364 0.039 0.711 0.074 1.453 0.074 2.23-0.008 0.5 [...]
+          inkscape:connector-curvature="0"
+      />
+      <path
+          id="path20"
+          style="fill-rule:evenodd;fill:#ffecda"
+          d="m7.906 15.902c0.379-0.129 0.629-0.278 0.75-0.446 0.024-0.043 0.059-0.128 0.114-0.257 0.05-0.121 0.093-0.2 0.121-0.239 0.214-0.269 0.574-0.465 1.078-0.59 0.301-0.082 0.746-0.167 1.336-0.261 0.386-0.094 0.789-0.285 1.199-0.567 0.437-0.277 0.859-0.476 1.266-0.597 0.554-0.176 1.316-0.125 2.289 0.156 0.285 0.074 0.683 0.191 1.199 0.348 0.465 0.125 0.836 0.195 1.121 0.214 0.019-0.003 0.031-0.015 0.035-0.031-0.414-0.168-0.898-0.355-1.457-0.562-0.465-0.164-1.043-0.364-1.738-0.598-0. [...]
+          inkscape:connector-curvature="0"
+      />
+      <path
+          id="path22"
+          style="fill-rule:evenodd;fill:#ec7f6d"
+          d="m0.625 12.773c0.246 0.191 0.516 0.379 0.813 0.562 0.203-0.34 0.496-0.461 0.874-0.371 0.204 0.035 0.493 0.149 0.872 0.336 0.285 0.055 0.644 0.098 1.089 0.117 0.387 0.02 0.688 0.067 0.899 0.141 0.07 0.02 0.137 0.051 0.203 0.098l0.027 0.007c0.297 0.063 0.668 0.153 1.106 0.27 0.422 0.074 0.793 0.086 1.121 0.043 0.387-0.043 0.68-0.113 0.879-0.211 0.078-0.047 0.226-0.18 0.449-0.398 0.152-0.141 0.34-0.227 0.559-0.254 0.117-0.016 0.289-0.008 0.507 0.023 0.215-0.012 0.434-0.066 0.665 [...]
+          inkscape:connector-curvature="0"
+      />
+      <path
+          id="path24"
+          style="fill-rule:evenodd;fill:#ffc8c8"
+          d="m1.961 13.632c0.008-0.094 0.027-0.172 0.066-0.238 0.024-0.055 0.09-0.086 0.2-0.106 0.128-0.05 0.23-0.066 0.296-0.035 0.02 0.004 0.118 0.067 0.293 0.192 0.204 0.101 0.34 0.172 0.407 0.211 0.242 0.093 0.629 0.117 1.156 0.078 0.363-0.035 0.664-0.008 0.91 0.086 0-0.028-0.012-0.047-0.031-0.051 0.082-0.016 0.16-0.024 0.238-0.024-0.043-0.019-0.074-0.042-0.098-0.066l0.004-0.016-0.027-0.007c-0.066-0.047-0.133-0.078-0.203-0.098-0.211-0.074-0.508-0.121-0.899-0.141-0.441-0.019-0.804-0.0 [...]
+          inkscape:connector-curvature="0"
+      />
+      <path
+          id="path26"
+          style="fill-rule:evenodd;fill:#ecc8c8"
+          d="m18.074 8.351c-0.344-0.035-0.617 0.098-0.824 0.398-0.047 0.063-0.121 0.098-0.227 0.098-0.363-0.004-0.664-0.144-0.906-0.43-0.25-0.277-0.543-0.488-0.879-0.625-0.086-0.004-0.156 0.004-0.207 0.016-0.238 0.109-0.476 0.09-0.715-0.063-0.605-0.39-1.254-0.593-1.949-0.605-0.578-0.031-1.164 0.004-1.754 0.102-0.519 0.082-1.027 0.246-1.527 0.5-0.641 0.316-1.309 0.652-2.008 1.011-1.051 0.516-2.062 1.137-3.047 1.871-1.343 0.262-2.648 0.559-3.914 0.891-0.144 0.25-0.156 0.48-0.031 0.695l0.02 [...]
+          inkscape:connector-curvature="0"
+      />
+      <path
+          id="path28"
+          style="fill-rule:evenodd;fill:#eca391"
+          d="m19.102 8.542c0.027 0.325-0.098 0.508-0.379 0.559-0.321 0.047-0.485 0.078-0.5 0.094-0.02-0.004-0.032 0.004-0.035 0.019 0.023-0.011 0.039-0.015 0.046-0.015 0.102 0.019 0.192 0.043 0.27 0.074 0.008 0 0.035 0.008 0.082 0.019 0.031 0.028 0.078 0.063 0.141 0.11 0.109 0.066 0.183 0.117 0.234 0.148 0.125 0.035 0.258 0.031 0.391-0.008 0.117-0.035 0.234-0.031 0.351 0.024 0.188 0.058 0.445 0.199 0.781 0.422 0.328 0.195 0.532 0.312 0.61 0.351 0.133 0.035 0.234 0 0.301-0.105 0.011-0.047 [...]
+          inkscape:connector-curvature="0"
+      />
+      <path
+          id="path30"
+          style="fill-rule:evenodd;fill:#e29990"
+          d="m32.84 0.812c0.234 0.101 0.32 0.273 0.265 0.519-0.187 0.235-0.347 0.43-0.472 0.575 0.168-0.118 0.308-0.215 0.422-0.289 0.476-0.274 1.234-0.407 2.277-0.395 0.008 0 0.234-0.039 0.68-0.121 0.472-0.094 0.808-0.137 0.996-0.133 0.445-0.015 1.086 0.102 1.918 0.356 0.172 0.043 0.355 0.109 0.551 0.191 0.136 0.035 0.461-0.02 0.98-0.172 0.231-0.148 0.371-0.301 0.414-0.465 0.047-0.246-0.008-0.449-0.168-0.617-0.211 0.012-0.398 0.031-0.562 0.067-0.125 0.003-0.243 0.007-0.348 0.007-0.805 0 [...]
+          inkscape:connector-curvature="0"
+      />
+      <path
+          id="path32"
+          style="fill-rule:evenodd;fill:#da6d5b"
+          d="m32.633 1.906c0.125-0.145 0.285-0.34 0.472-0.575 0.055-0.246-0.031-0.418-0.265-0.519l-0.012-0.004c-0.019 0.004-0.074 0.027-0.16 0.059-0.078 0.039-0.191 0.121-0.34 0.253-0.144 0.106-0.308 0.215-0.492 0.329-0.191 0.113-0.336 0.226-0.438 0.343-0.121 0.141-0.269 0.266-0.445 0.383-0.555 0.36-1.133 0.703-1.726 1.031-0.735 0.379-1.274 0.934-1.614 1.668-0.074 0.18-0.172 0.371-0.281 0.571-0.578 0.984-1.344 1.66-2.297 2.027-0.219 0.066-0.441 0.094-0.668 0.082-0.269-0.066-0.535-0.148-0 [...]
+          inkscape:connector-curvature="0"
+      />
+      <path
+          id="path34"
+          style="fill-rule:evenodd;fill:#da5b5b"
+          d="m50.359 15.328c-0.398-0.336-0.797-0.668-1.199-0.997-0.605 0.184-1.066 0.332-1.383 0.45-0.492 0.191-0.91 0.418-1.246 0.672-0.308 0.23-0.746 0.359-1.308 0.382-0.184 0.008-0.43-0.004-0.735-0.039-0.324-0.019-0.566-0.039-0.734-0.054-0.594-0.036-1.035 0.011-1.328 0.132-0.422 0.176-0.699 0.512-0.832 1.016-0.008 0.023-0.129 0.137-0.364 0.332-0.277 0.215-0.562 0.418-0.855 0.617-0.883 0.578-1.508 0.832-1.871 0.766-0.508-0.11-0.977-0.133-1.402-0.074-0.274 0.019-0.606 0.101-0.997 0.234- [...]
+          inkscape:connector-curvature="0"
+      />
+      <path
+          id="path36"
+          style="fill-rule:evenodd;fill:#ffc8c8"
+          d="m39.832 19.98c-0.133-0.008-0.27-0.016-0.41-0.024-0.258-0.011-0.625-0.058-1.102-0.136-0.472-0.09-0.824-0.145-1.047-0.168-0.41-0.012-0.773 0.015-1.097 0.082-0.723 0.16-1.465 0.234-2.219 0.222-0.418-0.035-1.137-0.121-2.156-0.261-1.524-0.215-3.024-0.157-4.5 0.175-1.305 0.293-2.422 0.75-3.356 1.372-0.238 0.168-0.515 0.253-0.832 0.265-0.183 0.008-0.476-0.012-0.875-0.062-0.394-0.039-0.687-0.047-0.886-0.024-0.313 0.032-0.582 0.133-0.797 0.305-0.434 0.324-1.063 0.562-1.891 0.715-0.81 [...]
+          inkscape:connector-curvature="0"
+      />
+      <path
+          id="path38"
+          style="fill-rule:evenodd;fill:#ffecda"
+          d="m49.16 14.331c-0.207-0.191-0.422-0.367-0.648-0.531-0.356 0.227-0.664 0.41-0.922 0.543-1.207 0.684-2.11 0.902-2.707 0.668-0.66-0.254-1.246-0.348-1.762-0.285-0.391 0.059-0.82 0.215-1.293 0.473-0.664 0.379-1.062 0.589-1.191 0.644-0.516 0.207-1.047 0.289-1.59 0.25 0.117 0.567-0.059 1.016-0.52 1.352-0.39 0.281-0.925 0.437-1.609 0.476-0.289 0.008-0.609 0.047-0.965 0.117-0.402 0.082-0.699 0.141-0.883 0.18-0.718 0.121-1.34 0.113-1.859-0.023-0.098-0.028-0.758-0.25-1.981-0.66-1.199-0. [...]
+          inkscape:connector-curvature="0"
+      />
+      <path
+          id="path40"
+          style="fill-rule:evenodd;fill:#ec7f6d"
+          d="m48.512 13.8c-0.746-0.613-1.512-1.226-2.293-1.836-0.074-0.301-0.16-0.574-0.254-0.832-1.184-0.269-2.242-0.226-3.18 0.125-0.449 0.176-0.918 0.449-1.398 0.821-0.325 0.246-0.746 0.613-1.258 1.097-0.602 0.567-1.031 0.953-1.285 1.153-0.5 0.437-0.992 0.789-1.477 1.054-1.215 0.649-2.633 0.906-4.242 0.774-1.836-0.223-3.184-0.364-4.039-0.422-1.465-0.086-2.793 0.011-3.984 0.285-0.528 0.105-1.086 0.297-1.676 0.57-0.621 0.305-1.086 0.524-1.399 0.66-0.519 0.215-1.019 0.34-1.496 0.375-0.59 [...]
+          inkscape:connector-curvature="0"
+      />
+      <path
+          id="path42"
+          style="fill-rule:evenodd;fill:#e29990"
+          d="m9.09 18.87c0.019-0.07 0.043-0.16 0.074-0.269 1.324-1.043 2.434-1.734 3.328-2.066 0.524-0.207 1.387-0.325 2.594-0.356 0.605-0.008 1.16-0.019 1.66-0.027l0.352 0.136c0.312 0.114 0.621 0.219 0.922 0.317 1.074 0.316 2.113 0.48 3.128 0.496 0.293 0 0.774-0.234 1.438-0.707l0.738-0.551c0.281-0.203 0.504-0.328 0.664-0.383 0.828-0.277 2.121-0.375 3.871-0.3 1.004 0.043 2.309 0.164 3.911 0.375 1.253 0.144 2.527-0.036 3.824-0.543 0.832-0.352 1.914-0.973 3.254-1.856 0.957-0.644 1.484-0.99 [...]
+          inkscape:connector-curvature="0"
+      />
+    </g
+    >
+  </g
+  >
+<metadata
+    ><rdf:RDF
+      ><cc:Work
+        ><dc:format
+          >image/svg+xml</dc:format
+        ><dc:type
+            rdf:resource="http://purl.org/dc/dcmitype/StillImage"
+        /><cc:license
+            rdf:resource="http://creativecommons.org/licenses/publicdomain/"
+        /><dc:publisher
+          ><cc:Agent
+              rdf:about="http://openclipart.org/"
+            ><dc:title
+              >Openclipart</dc:title
+            ></cc:Agent
+          ></dc:publisher
+        ></cc:Work
+      ><cc:License
+          rdf:about="http://creativecommons.org/licenses/publicdomain/"
+        ><cc:permits
+            rdf:resource="http://creativecommons.org/ns#Reproduction"
+        /><cc:permits
+            rdf:resource="http://creativecommons.org/ns#Distribution"
+        /><cc:permits
+            rdf:resource="http://creativecommons.org/ns#DerivativeWorks"
+        /></cc:License
+      ></rdf:RDF
+    ></metadata
+  ></svg
+>
diff --git a/src/test/resources/imagetest.css b/src/test/resources/imagetest.css
new file mode 100644
index 0000000..26b3aaf
--- /dev/null
+++ b/src/test/resources/imagetest.css
@@ -0,0 +1,3 @@
+#TestButton {
+  -fx-graphic: url('bacon.svg');
+}
diff --git a/src/test/resources/imagetest.fxml b/src/test/resources/imagetest.fxml
new file mode 100644
index 0000000..2f2c540
--- /dev/null
+++ b/src/test/resources/imagetest.fxml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<?import javafx.scene.image.*?>
+<?import javafx.scene.*?>
+<?import javafx.scene.control.*?>
+<?import javafx.scene.layout.*?>
+<?import javafx.scene.image.ImageView?>
+<?import javafx.scene.image.Image?>
+ 
+<AnchorPane id="AnchorPane" prefHeight="200" prefWidth="320" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
+   <children>
+ 		<ImageView id="TestImage">
+ 			<image>
+ 				<Image url="@bacon.svg"/>
+ 			</image>
+ 		</ImageView>
+   </children>
+</AnchorPane>

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/javafxsvg.git



More information about the pkg-java-commits mailing list