This is an automated email from the ASF dual-hosted git repository. jsorel pushed a commit to branch geoapi-4.0 in repository https://gitbox.apache.org/repos/asf/sis.git
The following commit(s) were added to refs/heads/geoapi-4.0 by this push: new ff08b71b51 Add DPI parameter on GraphicsPortrayer ff08b71b51 is described below commit ff08b71b5120e06c70b1e6f98a48bd587df1c003 Author: jsorel <johann.so...@geomatys.com> AuthorDate: Fri Mar 8 09:13:47 2024 +0100 Add DPI parameter on GraphicsPortrayer --- .../apache/sis/map/service/GraphicsPortrayer.java | 2 +- .../main/org/apache/sis/map/service/Scene2D.java | 44 +++++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/incubator/src/org.apache.sis.portrayal.map/main/org/apache/sis/map/service/GraphicsPortrayer.java b/incubator/src/org.apache.sis.portrayal.map/main/org/apache/sis/map/service/GraphicsPortrayer.java index 6500fd1f49..9b6d019caf 100644 --- a/incubator/src/org.apache.sis.portrayal.map/main/org/apache/sis/map/service/GraphicsPortrayer.java +++ b/incubator/src/org.apache.sis.portrayal.map/main/org/apache/sis/map/service/GraphicsPortrayer.java @@ -117,7 +117,7 @@ public final class GraphicsPortrayer { */ private Scene2D init() { Objects.requireNonNull(domain, "domain"); // Not an argument. - if (image == null) { + if (graphics == null) { setCanvas(new BufferedImage( (int) domain.getExtent().getSize(0), (int) domain.getExtent().getSize(1), diff --git a/incubator/src/org.apache.sis.portrayal.map/main/org/apache/sis/map/service/Scene2D.java b/incubator/src/org.apache.sis.portrayal.map/main/org/apache/sis/map/service/Scene2D.java index 02ac199164..95060330c8 100644 --- a/incubator/src/org.apache.sis.portrayal.map/main/org/apache/sis/map/service/Scene2D.java +++ b/incubator/src/org.apache.sis.portrayal.map/main/org/apache/sis/map/service/Scene2D.java @@ -19,8 +19,10 @@ package org.apache.sis.map.service; import java.awt.Graphics2D; import java.util.Objects; import java.util.logging.Logger; +import javax.measure.Unit; +import javax.measure.quantity.Length; import org.apache.sis.coverage.grid.GridGeometry; - +import org.apache.sis.measure.Units; /** * Holds the rendering properties. @@ -41,6 +43,18 @@ public final class Scene2D { */ public final Graphics2D graphics; + /** + * Definition from OGC SLD/SE : + * The portrayal unit “pixel” is the default unit of measure. + * If available, the pixel size depends on the viewer client resolution, otherwise it is equal to 0.28mm * 0.28mm (~ 90 DPI). + * + * In facts, all displays have there own DPI, but the common is around 96dpi (old 72dpi x 4/3). + * This dpi is the default on windows and replicated on different tools such as Apache Batik user agents. + * + * TODO : should we use a transform as in GraphicsConfiguration.getNormalizingTransform() ? + */ + private double dpi = 96; + public Scene2D(GridGeometry grid, Graphics2D graphics) { this.grid = Objects.requireNonNull(grid); this.graphics = Objects.requireNonNull(graphics); @@ -50,4 +64,32 @@ public final class Scene2D { return graphics; } + /** + * Set current rendering DPI. + * Default is 99. + * + * @param dpi new DPI + */ + public void setDpi(double dpi) { + this.dpi = dpi; + } + + /** + * @return current DPI. + */ + public double getDpi() { + return dpi; + } + + /** + * Convert given distance to pixels. + * + * @param distance to convert + * @param unit distance unit, not null + * @return distance in pixels + */ + public double toPixels(double distance, Unit<Length> unit) { + return unit.getConverterTo(Units.INCH).convert(distance) * dpi; + } + }