@Test public void testRenderDoubleDpi() throws Exception { MapBounds bounds = new CenterScaleMapBounds( CRS.decode("EPSG:3857"), -8235878.4938425, 4979784.7605681, 26000); MapfishMapContext mapParams = new MapfishMapContext( bounds, new Dimension(780, 330), 0, 144, true, false); ScalebarAttribute scalebarAttibute = new ScalebarAttribute(); scalebarAttibute.setWidth(300); scalebarAttibute.setHeight(40); ScalebarAttributeValues scalebarParams = scalebarAttibute.createValue(null); scalebarParams.font = "Liberation Sans"; scalebarParams.renderAsSvg = false; ScalebarGraphic scalebar = new ScalebarGraphic(); URI file = scalebar.render(mapParams, scalebarParams, folder.getRoot(), this.template); new ImageSimilarity(getFile("expected-scalebar-graphic-dpi.png")) .assertSimilarity(new File(file), 370); }
public final URI render( final MapfishMapContext mapContext, final ScalebarAttributeValues scalebarParams, final File tempFolder, final Template template) throws IOException, ParserConfigurationException { final double dpi = mapContext.getDPI(); final Rectangle paintArea = new Rectangle(mapContext.getMapSize()); MapBounds bounds = mapContext.getBounds(); final DistanceUnit mapUnit = getUnit(bounds); final Scale scale = bounds.getScale(paintArea, PDF_DPI); final double scaleDenominator = scale.getDenominator(scalebarParams.geodetic, bounds.getProjection(), dpi, bounds.getCenter()); DistanceUnit scaleUnit = scalebarParams.getUnit(); if (scaleUnit == null) { scaleUnit = mapUnit; } final double maxLengthInPixel = (scalebarParams.getOrientation().isHorizontal()) ? scalebarParams.getSize().width : scalebarParams.getSize().height; final double maxIntervalLengthInWorldUnits = DistanceUnit.PX.convertTo(maxLengthInPixel, scaleUnit) * scaleDenominator / scalebarParams.intervals; final double niceIntervalLengthInWorldUnits = getNearestNiceValue(maxIntervalLengthInWorldUnits, scaleUnit, scalebarParams.lockUnits); final ScaleBarRenderSettings settings = new ScaleBarRenderSettings(); settings.setParams(scalebarParams); settings.setMaxSize(scalebarParams.getSize()); settings.setPadding(getPadding(settings)); File path = null; if (template.getConfiguration().renderAsSvg(scalebarParams.renderAsSvg)) { final SVGGraphics2D graphics2D = CreateMapProcessor.createSvgGraphics(scalebarParams.getSize()); try { tryLayout( graphics2D, scaleUnit, scaleDenominator, niceIntervalLengthInWorldUnits, settings, 0); path = File.createTempFile("scalebar-graphic-", ".svg", tempFolder); CreateMapProcessor.saveSvgFile(graphics2D, path); } finally { graphics2D.dispose(); } } else { double dpiRatio = mapContext.getDPI() / PDF_DPI; final BufferedImage bufferedImage = new BufferedImage( (int) Math.round(scalebarParams.getSize().width * dpiRatio), (int) Math.round(scalebarParams.getSize().height * dpiRatio), template.isPdfA() ? TYPE_3BYTE_BGR : TYPE_4BYTE_ABGR); final Graphics2D graphics2D = bufferedImage.createGraphics(); try { AffineTransform saveAF = new AffineTransform(graphics2D.getTransform()); graphics2D.scale(dpiRatio, dpiRatio); tryLayout( graphics2D, scaleUnit, scaleDenominator, niceIntervalLengthInWorldUnits, settings, 0); graphics2D.setTransform(saveAF); path = File.createTempFile("scalebar-graphic-", ".png", tempFolder); ImageUtils.writeImage(bufferedImage, "png", path); } finally { graphics2D.dispose(); } } return path.toURI(); }
ScalebarGraphic { public final URI render( final MapfishMapContext mapContext, final ScalebarAttributeValues scalebarParams, final File tempFolder, final Template template) throws IOException, ParserConfigurationException { final double dpi = mapContext.getDPI(); final Rectangle paintArea = new Rectangle(mapContext.getMapSize()); MapBounds bounds = mapContext.getBounds(); final DistanceUnit mapUnit = getUnit(bounds); final Scale scale = bounds.getScale(paintArea, PDF_DPI); final double scaleDenominator = scale.getDenominator(scalebarParams.geodetic, bounds.getProjection(), dpi, bounds.getCenter()); DistanceUnit scaleUnit = scalebarParams.getUnit(); if (scaleUnit == null) { scaleUnit = mapUnit; } final double maxLengthInPixel = (scalebarParams.getOrientation().isHorizontal()) ? scalebarParams.getSize().width : scalebarParams.getSize().height; final double maxIntervalLengthInWorldUnits = DistanceUnit.PX.convertTo(maxLengthInPixel, scaleUnit) * scaleDenominator / scalebarParams.intervals; final double niceIntervalLengthInWorldUnits = getNearestNiceValue(maxIntervalLengthInWorldUnits, scaleUnit, scalebarParams.lockUnits); final ScaleBarRenderSettings settings = new ScaleBarRenderSettings(); settings.setParams(scalebarParams); settings.setMaxSize(scalebarParams.getSize()); settings.setPadding(getPadding(settings)); File path = null; if (template.getConfiguration().renderAsSvg(scalebarParams.renderAsSvg)) { final SVGGraphics2D graphics2D = CreateMapProcessor.createSvgGraphics(scalebarParams.getSize()); try { tryLayout( graphics2D, scaleUnit, scaleDenominator, niceIntervalLengthInWorldUnits, settings, 0); path = File.createTempFile("scalebar-graphic-", ".svg", tempFolder); CreateMapProcessor.saveSvgFile(graphics2D, path); } finally { graphics2D.dispose(); } } else { double dpiRatio = mapContext.getDPI() / PDF_DPI; final BufferedImage bufferedImage = new BufferedImage( (int) Math.round(scalebarParams.getSize().width * dpiRatio), (int) Math.round(scalebarParams.getSize().height * dpiRatio), template.isPdfA() ? TYPE_3BYTE_BGR : TYPE_4BYTE_ABGR); final Graphics2D graphics2D = bufferedImage.createGraphics(); try { AffineTransform saveAF = new AffineTransform(graphics2D.getTransform()); graphics2D.scale(dpiRatio, dpiRatio); tryLayout( graphics2D, scaleUnit, scaleDenominator, niceIntervalLengthInWorldUnits, settings, 0); graphics2D.setTransform(saveAF); path = File.createTempFile("scalebar-graphic-", ".png", tempFolder); ImageUtils.writeImage(bufferedImage, "png", path); } finally { graphics2D.dispose(); } } return path.toURI(); } }
ScalebarGraphic { public final URI render( final MapfishMapContext mapContext, final ScalebarAttributeValues scalebarParams, final File tempFolder, final Template template) throws IOException, ParserConfigurationException { final double dpi = mapContext.getDPI(); final Rectangle paintArea = new Rectangle(mapContext.getMapSize()); MapBounds bounds = mapContext.getBounds(); final DistanceUnit mapUnit = getUnit(bounds); final Scale scale = bounds.getScale(paintArea, PDF_DPI); final double scaleDenominator = scale.getDenominator(scalebarParams.geodetic, bounds.getProjection(), dpi, bounds.getCenter()); DistanceUnit scaleUnit = scalebarParams.getUnit(); if (scaleUnit == null) { scaleUnit = mapUnit; } final double maxLengthInPixel = (scalebarParams.getOrientation().isHorizontal()) ? scalebarParams.getSize().width : scalebarParams.getSize().height; final double maxIntervalLengthInWorldUnits = DistanceUnit.PX.convertTo(maxLengthInPixel, scaleUnit) * scaleDenominator / scalebarParams.intervals; final double niceIntervalLengthInWorldUnits = getNearestNiceValue(maxIntervalLengthInWorldUnits, scaleUnit, scalebarParams.lockUnits); final ScaleBarRenderSettings settings = new ScaleBarRenderSettings(); settings.setParams(scalebarParams); settings.setMaxSize(scalebarParams.getSize()); settings.setPadding(getPadding(settings)); File path = null; if (template.getConfiguration().renderAsSvg(scalebarParams.renderAsSvg)) { final SVGGraphics2D graphics2D = CreateMapProcessor.createSvgGraphics(scalebarParams.getSize()); try { tryLayout( graphics2D, scaleUnit, scaleDenominator, niceIntervalLengthInWorldUnits, settings, 0); path = File.createTempFile("scalebar-graphic-", ".svg", tempFolder); CreateMapProcessor.saveSvgFile(graphics2D, path); } finally { graphics2D.dispose(); } } else { double dpiRatio = mapContext.getDPI() / PDF_DPI; final BufferedImage bufferedImage = new BufferedImage( (int) Math.round(scalebarParams.getSize().width * dpiRatio), (int) Math.round(scalebarParams.getSize().height * dpiRatio), template.isPdfA() ? TYPE_3BYTE_BGR : TYPE_4BYTE_ABGR); final Graphics2D graphics2D = bufferedImage.createGraphics(); try { AffineTransform saveAF = new AffineTransform(graphics2D.getTransform()); graphics2D.scale(dpiRatio, dpiRatio); tryLayout( graphics2D, scaleUnit, scaleDenominator, niceIntervalLengthInWorldUnits, settings, 0); graphics2D.setTransform(saveAF); path = File.createTempFile("scalebar-graphic-", ".png", tempFolder); ImageUtils.writeImage(bufferedImage, "png", path); } finally { graphics2D.dispose(); } } return path.toURI(); }  }
ScalebarGraphic { public final URI render( final MapfishMapContext mapContext, final ScalebarAttributeValues scalebarParams, final File tempFolder, final Template template) throws IOException, ParserConfigurationException { final double dpi = mapContext.getDPI(); final Rectangle paintArea = new Rectangle(mapContext.getMapSize()); MapBounds bounds = mapContext.getBounds(); final DistanceUnit mapUnit = getUnit(bounds); final Scale scale = bounds.getScale(paintArea, PDF_DPI); final double scaleDenominator = scale.getDenominator(scalebarParams.geodetic, bounds.getProjection(), dpi, bounds.getCenter()); DistanceUnit scaleUnit = scalebarParams.getUnit(); if (scaleUnit == null) { scaleUnit = mapUnit; } final double maxLengthInPixel = (scalebarParams.getOrientation().isHorizontal()) ? scalebarParams.getSize().width : scalebarParams.getSize().height; final double maxIntervalLengthInWorldUnits = DistanceUnit.PX.convertTo(maxLengthInPixel, scaleUnit) * scaleDenominator / scalebarParams.intervals; final double niceIntervalLengthInWorldUnits = getNearestNiceValue(maxIntervalLengthInWorldUnits, scaleUnit, scalebarParams.lockUnits); final ScaleBarRenderSettings settings = new ScaleBarRenderSettings(); settings.setParams(scalebarParams); settings.setMaxSize(scalebarParams.getSize()); settings.setPadding(getPadding(settings)); File path = null; if (template.getConfiguration().renderAsSvg(scalebarParams.renderAsSvg)) { final SVGGraphics2D graphics2D = CreateMapProcessor.createSvgGraphics(scalebarParams.getSize()); try { tryLayout( graphics2D, scaleUnit, scaleDenominator, niceIntervalLengthInWorldUnits, settings, 0); path = File.createTempFile("scalebar-graphic-", ".svg", tempFolder); CreateMapProcessor.saveSvgFile(graphics2D, path); } finally { graphics2D.dispose(); } } else { double dpiRatio = mapContext.getDPI() / PDF_DPI; final BufferedImage bufferedImage = new BufferedImage( (int) Math.round(scalebarParams.getSize().width * dpiRatio), (int) Math.round(scalebarParams.getSize().height * dpiRatio), template.isPdfA() ? TYPE_3BYTE_BGR : TYPE_4BYTE_ABGR); final Graphics2D graphics2D = bufferedImage.createGraphics(); try { AffineTransform saveAF = new AffineTransform(graphics2D.getTransform()); graphics2D.scale(dpiRatio, dpiRatio); tryLayout( graphics2D, scaleUnit, scaleDenominator, niceIntervalLengthInWorldUnits, settings, 0); graphics2D.setTransform(saveAF); path = File.createTempFile("scalebar-graphic-", ".png", tempFolder); ImageUtils.writeImage(bufferedImage, "png", path); } finally { graphics2D.dispose(); } } return path.toURI(); }  final URI render(
            final MapfishMapContext mapContext,
            final ScalebarAttributeValues scalebarParams,
            final File tempFolder,
            final Template template); }
ScalebarGraphic { public final URI render( final MapfishMapContext mapContext, final ScalebarAttributeValues scalebarParams, final File tempFolder, final Template template) throws IOException, ParserConfigurationException { final double dpi = mapContext.getDPI(); final Rectangle paintArea = new Rectangle(mapContext.getMapSize()); MapBounds bounds = mapContext.getBounds(); final DistanceUnit mapUnit = getUnit(bounds); final Scale scale = bounds.getScale(paintArea, PDF_DPI); final double scaleDenominator = scale.getDenominator(scalebarParams.geodetic, bounds.getProjection(), dpi, bounds.getCenter()); DistanceUnit scaleUnit = scalebarParams.getUnit(); if (scaleUnit == null) { scaleUnit = mapUnit; } final double maxLengthInPixel = (scalebarParams.getOrientation().isHorizontal()) ? scalebarParams.getSize().width : scalebarParams.getSize().height; final double maxIntervalLengthInWorldUnits = DistanceUnit.PX.convertTo(maxLengthInPixel, scaleUnit) * scaleDenominator / scalebarParams.intervals; final double niceIntervalLengthInWorldUnits = getNearestNiceValue(maxIntervalLengthInWorldUnits, scaleUnit, scalebarParams.lockUnits); final ScaleBarRenderSettings settings = new ScaleBarRenderSettings(); settings.setParams(scalebarParams); settings.setMaxSize(scalebarParams.getSize()); settings.setPadding(getPadding(settings)); File path = null; if (template.getConfiguration().renderAsSvg(scalebarParams.renderAsSvg)) { final SVGGraphics2D graphics2D = CreateMapProcessor.createSvgGraphics(scalebarParams.getSize()); try { tryLayout( graphics2D, scaleUnit, scaleDenominator, niceIntervalLengthInWorldUnits, settings, 0); path = File.createTempFile("scalebar-graphic-", ".svg", tempFolder); CreateMapProcessor.saveSvgFile(graphics2D, path); } finally { graphics2D.dispose(); } } else { double dpiRatio = mapContext.getDPI() / PDF_DPI; final BufferedImage bufferedImage = new BufferedImage( (int) Math.round(scalebarParams.getSize().width * dpiRatio), (int) Math.round(scalebarParams.getSize().height * dpiRatio), template.isPdfA() ? TYPE_3BYTE_BGR : TYPE_4BYTE_ABGR); final Graphics2D graphics2D = bufferedImage.createGraphics(); try { AffineTransform saveAF = new AffineTransform(graphics2D.getTransform()); graphics2D.scale(dpiRatio, dpiRatio); tryLayout( graphics2D, scaleUnit, scaleDenominator, niceIntervalLengthInWorldUnits, settings, 0); graphics2D.setTransform(saveAF); path = File.createTempFile("scalebar-graphic-", ".png", tempFolder); ImageUtils.writeImage(bufferedImage, "png", path); } finally { graphics2D.dispose(); } } return path.toURI(); }  final URI render(
            final MapfishMapContext mapContext,
            final ScalebarAttributeValues scalebarParams,
            final File tempFolder,
            final Template template);  }