# HG changeset patch # User Ingo Weinzierl # Date 1276161813 0 # Node ID 92fce3b3d07f0bfc7396ab026db17ff1c6a2bfae # Parent f2127cd0fe31dbd763b00729c0492b2051e036e0 Centered histograms in pdf exports. gnv-artifacts/trunk@1189 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r f2127cd0fe31 -r 92fce3b3d07f gnv-artifacts/ChangeLog --- a/gnv-artifacts/ChangeLog Thu Jun 10 09:05:58 2010 +0000 +++ b/gnv-artifacts/ChangeLog Thu Jun 10 09:23:33 2010 +0000 @@ -1,3 +1,10 @@ +2010-06-10 Ingo Weinzierl + + Issue290 - Centering of pdf exports + + * src/main/java/de/intevation/gnv/exports/ChartExportHelper.java: PDF + exports of histograms are centered now. + 2010-06-10 Ingo Weinzierl Issue290 - Centering of pdf exports diff -r f2127cd0fe31 -r 92fce3b3d07f gnv-artifacts/src/main/java/de/intevation/gnv/exports/ChartExportHelper.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/exports/ChartExportHelper.java Thu Jun 10 09:05:58 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/exports/ChartExportHelper.java Thu Jun 10 09:23:33 2010 +0000 @@ -359,10 +359,8 @@ pageFormat = DEFAULT_PAGE_SIZE; Rectangle page = PageSize.getRectangle(pageFormat); - int pageWidth = - (int) (page.getRight(marginRight) - page.getLeft(marginLeft)); - int pageHeight = - (int) (page.getTop(marginTop) - page.getBottom(marginBottom)); + float pageWidth = page.getWidth(); + float pageHeight = page.getHeight(); // the chart width int chartWidth = (Integer) context.getContextValue("chart.width"); @@ -370,8 +368,8 @@ boolean landscape = chartWidth > chartHeight ? true : false; - int width = 0; - int height = 0; + float width = 0; + float height = 0; if (landscape) { width = pageHeight; height = pageWidth; @@ -381,20 +379,22 @@ height = pageHeight; } - if (chartWidth > width) { + float spaceX = width - marginLeft - marginRight; + if (chartWidth > spaceX) { log.warn("Histogram width is too big for pdf -> resize it now."); - double ratio = ((double)width) / chartWidth; + double ratio = ((double)spaceX) / chartWidth; chartWidth *= ratio; chartHeight *= ratio; - log.debug("Resized histogram to " + chartWidth + "x" + chartHeight); + log.debug("Resized chart to " + chartWidth + "x" + chartHeight); } - if (chartHeight > height) { + float spaceY = height - marginTop - marginBottom; + if (chartHeight > spaceY) { log.warn("Histogram height is too big for pdf -> resize it now."); - double ratio = ((double)height) / chartHeight; + double ratio = ((double)spaceY) / chartHeight; chartWidth *= ratio; chartHeight *= ratio; - log.debug("Resized histogram to " + chartWidth + "x" + chartHeight); + log.debug("Resized chart to " + chartWidth + "x" + chartHeight); } Document document = null; @@ -421,14 +421,19 @@ JFreeChart chart = histograms[i].generateChart(); PdfTemplate template = content.createTemplate(width, height); - Graphics2D graphics = template.createGraphics( + Graphics2D graphics = template.createGraphics(width, height); + + double[] origin = getCenteredAnchor( + marginLeft, marginRight, marginBottom, marginTop, + width, height, chartWidth, chartHeight); + Rectangle2D area = new Rectangle2D.Double( - 0.0D, 0.0D, chartWidth, chartHeight); + origin[0], origin[1], chartWidth, chartHeight); chart.draw(graphics, area); graphics.dispose(); - content.addTemplate(template, marginLeft, marginBottom); + content.addTemplate(template, 0f, 0f); } } catch (DocumentException de) {