• Stars
    star
    200
  • Rank 195,325 (Top 4 %)
  • Language
    Java
  • License
    Other
  • Created over 10 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A JavaFX library that allows Java2D code (Graphics2D) to be used to draw to a Canvas node.

FXGraphics2D

Version 2.1.4, 12 February 2023.

Maven Central

Overview

FXGraphics2D is an implementation of Java's Graphics2D API that targets the JavaFX Canvas. It makes it possible to reuse existing Java2D code in a JavaFX application. The following example is generated by JFreeChart-FX:

FXGraphics2D sample

Background

The code has been developed for the use of Orson Charts (https://github.com/jfree/orson-charts/) and JFreeChart (http://www.jfree.org/jfreechart). Numerous demos can be found in the JFree-FXDemos project page at GitHub.

You can also read about FXGraphics2D in this Java Magazine article:

Temporary: link above is broken, please use this in the meantime:

FXGraphics2D requires JDK 11 or later and is licensed under the terms of a (three clause) BSD-style license.

Include

To include FXGraphics2D in your own project, add the following Maven dependency:

<dependency>
    <groupId>org.jfree</groupId>
    <artifactId>org.jfree.fxgraphics2d</artifactId>
    <version>2.1.4</version>
</dependency>

Build

You can build FXGraphics2D from sources using Maven:

mvn clean install

Testing

FXGraphics2D is being tested using Graphics2D Tester and produces the output shown below. There are several areas that still need work:

  • the compositing rules in AlphaComposite cannot be mapped 100% to JavaFX equivalents
  • font metrics are approximated
  • image drawing with clipping shows a strange greying out effect

fxgraphics2d

Feedback

If you have feedback about the FXGraphics2D library, please use the discussion area.

License

FXGraphics2D is licensed under a BSD-style license:

Copyright (c) 2014-present, David Gilbert.

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, 
are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. 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.

3. Neither the name of the copyright holder 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 THE COPYRIGHT HOLDER OR CONTRIBUTORS 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.

History

12-Feb-2023 : Version 2.1.4
  • fixed clip handling with child Graphics2D.create() (PR #11 by Laurent BourgΓ¨s)
  • fix bug in drawArc()/fillArc()
  • set JavaFX dependency to version 19
23-Jan-2022 : Version 2.1.3
  • set JavaFX dependency to version 17
  • apply code clean-up suggested by IntelliJ
5-Aug-2021 : Version 2.1.2
  • set winding rule for Path2D instances;
  • set cycle method on gradient paints;
  • fix focus distance on RadialGradientPaint.
24-May-2021 : Version 2.1.1
  • fix handling for null arguments in drawImage() methods;
  • update JavaFX dependency to version 16;
  • update JUnit test dependency to 5.7.2.
3-Oct-2020 : Version 2.1
  • update JavaFX dependencies to version 15;
  • migrated tests to JUnit 5.
27-Feb-2020 : Version 2.0
  • converted to a module (org.jfree.fxgraphics2d);
  • now requires JDK 11 or later.
7-Feb-2019 : Version 1.8
  • fixed bug #8 where draw(Shape) alters the shape state for RenderingHints.VALUE_STROKE_PURE;
  • added automatic module name (org.jfree.fxgraphics2d).
5-Jul-2018 : Version 1.7
  • fixed bug #6 where color, stroke and font attributes are changed after calling setClip() twice.
5-Nov-2017 : Version 1.6
  • added support for JDK9 by removing the use of some non-public classes;
  • simplified the project set-up by removing Ant as a build option, and removing the demos (these will be provided in a separate Git project https://github.com/jfree/jfree-fxdemos).
15-Oct-2016 : Version 1.5
  • add rendering hint to provide option for measuring fonts via JavaFX API;
  • fix exception in drawImage() method with null transform;
  • updated JFreeSVG to version 3.2 (affects demo only).
27-Apr-2016 : Version 1.4
  • improve handling of setComposite() for alpha values;
  • fixed bug in rotate method, incorrect conversion to degrees.
28-Jan-2016 : Version 1.3
  • fixed bug in drawImage() method;
  • add 'maven' directory with a pom that can be copied over to load the project in NetBeans;
  • updated Ant script to copy over pom.xml to distribution.
23-Jan-2016 : Version 1.2.1
  • implemented getGraphicsDevice() method;
  • add support for dashed lines;
  • in setPaint() and setStroke(), don't update anything if the value is the same;
  • various performance fixes;
  • fixed bug in drawImage() method;
  • updated demos.

Note that version 1.2.1 corrects a Maven dependency problem that sneaked into the 1.2 release.

30-Jul-2014 : Version 1.1
  • fix clipping so that combined plots in JFreeChart work correctly;
  • observe KEY_STROKE_CONTROL rendering hint for lines and rectangles (used to sharpen gridlines and borders in JFreeChart);
  • adjust fontRenderContext so that glyph positioning is more precise for TextLayout;
  • add clearRect() call in the JFreeChart demo;
  • add Maven support (pom.xml).
19-May-2014 : Version 1.0
  • initial public release.

More Repositories

1

jfreechart

A 2D chart library for Java applications (JavaFX, Swing or server-side).
Java
1,075
star
2

jfreesvg

A fast, lightweight Java library for creating Scalable Vector Graphics (SVG) output.
Java
295
star
3

jfreechart-fse

JFreeChart - Future State Edition
Java
116
star
4

orson-charts

A 3D chart library for Java applications (JavaFX, Swing or server-side).
Java
102
star
5

jfreechart-fx

Extensions for JFreeChart to support JavaFX client applications.
Java
101
star
6

skijagraphics2d

A Graphics2D implementation targeting Skija as a backend.
Java
60
star
7

jfree-demos

Various demo programs for JFree projects
Java
59
star
8

jfree-fxdemos

This project contains JavaFX demo programs for the libraries created by JFree.
Java
42
star
9

jcommon

JCommon class library (used by JFreeChart 1.0.x)
Java
25
star
10

orsonpdf

A fast, lightweight PDF generator for the Java platform
Java
24
star
11

skikographics2d

A Graphics2D implementation written in Kotlin and targeting Skiko as a backend.
Kotlin
18
star
12

jfreepdf

JFreePDF is a modular library for the Java platform that provides an implementation of the Graphics2D API that emits PDF.
Java
14
star
13

orson-charts-fx

Extensions for the Orson Charts library to support JavaFX.
Java
13
star
14

orson-charts-android

A 3D chart library for Android applications.
Java
13
star
15

swtgraphics2d

A Graphics2D implementation targeting SWT
Java
10
star
16

jsfreechart

An interactive chart library written in JavaScript.
JavaScript
8
star
17

graphics2d-tester

A visual tester for Graphics2D implementations
Java
8
star
18

flowplot

Work in progress for a new plot to incorporate in JFreeChart
Java
7
star
19

jfreechart-swt

SWT support classes for JFreeChart
Java
6
star
20

jfree-starter

A minimal Maven-driven Java project for Java 11 or later
Java
3
star
21

orson-charts-fx-demo

A JavaFX demo application for Orson Charts.
Java
2
star
22

fxgraphics2d-perf

Java
1
star