From 395c50bc680396814b7a23610385d667e0ff7e98 Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Wed, 11 Jun 2008 12:18:53 +0000 Subject: [PATCH] Fixed resolution handling inside AWT preview dialog. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/fop-0_95@666635 13f79535-47bb-0310-9956-ffa450edef68 --- .../fop/render/awt/viewer/PreviewDialog.java | 32 +++++++++++-------- .../fop/render/awt/viewer/PreviewPanel.java | 12 +++++-- status.xml | 3 ++ 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/src/java/org/apache/fop/render/awt/viewer/PreviewDialog.java b/src/java/org/apache/fop/render/awt/viewer/PreviewDialog.java index ee220d629..98e610297 100644 --- a/src/java/org/apache/fop/render/awt/viewer/PreviewDialog.java +++ b/src/java/org/apache/fop/render/awt/viewer/PreviewDialog.java @@ -38,7 +38,6 @@ import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.print.PrinterException; import java.awt.print.PrinterJob; - import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.util.Locale; @@ -60,8 +59,8 @@ import javax.swing.JToolBar; import javax.swing.KeyStroke; import javax.swing.SwingUtilities; -import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.FOPException; +import org.apache.fop.apps.FOUserAgent; import org.apache.fop.render.awt.AWTRenderer; /** @@ -76,6 +75,8 @@ public class PreviewDialog extends JFrame implements StatusListener { protected AWTRenderer renderer; /** The FOUserAgent associated with this window */ protected FOUserAgent foUserAgent; + /** The originally configured target resolution */ + protected float configuredTargetResolution; /** * Renderable instance that can be used to reload and re-render a document after * modifications. @@ -107,6 +108,7 @@ public class PreviewDialog extends JFrame implements StatusListener { public PreviewDialog(FOUserAgent foUserAgent, Renderable renderable) { renderer = (AWTRenderer) foUserAgent.getRendererOverride(); this.foUserAgent = foUserAgent; + this.configuredTargetResolution = this.foUserAgent.getTargetResolution(); this.renderable = renderable; translator = new Translator(); @@ -551,23 +553,23 @@ public class PreviewDialog extends JFrame implements StatusListener { } private void scaleActionPerformed(ActionEvent e) { - try { - int index = scale.getSelectedIndex(); - if (index == 0) { - setScale(previewPanel.getScaleToFitWindow() * 100); - } else if (index == 1) { - setScale(previewPanel.getScaleToFitWidth() * 100); - } else { - String item = (String)scale.getSelectedItem(); - setScale(Double.parseDouble(item.substring(0, item.indexOf('%')))); - } - } catch (FOPException fopEx) { - fopEx.printStackTrace(); + int index = scale.getSelectedIndex(); + if (index == 0) { + setScaleToFitWindow(); + } else if (index == 1) { + setScaleToFitWidth(); + } else { + String item = (String)scale.getSelectedItem(); + setScale(Double.parseDouble(item.substring(0, item.indexOf('%')))); } } /** Prints the document */ public void startPrinterJob(boolean showDialog) { + //Restore originally configured target resolution + float saveResolution = foUserAgent.getTargetResolution(); + foUserAgent.setTargetResolution(this.configuredTargetResolution); + PrinterJob pj = PrinterJob.getPrinterJob(); pj.setPageable(renderer); if (!showDialog || pj.printDialog()) { @@ -577,6 +579,8 @@ public class PreviewDialog extends JFrame implements StatusListener { e.printStackTrace(); } } + + foUserAgent.setTargetResolution(saveResolution); } /** diff --git a/src/java/org/apache/fop/render/awt/viewer/PreviewPanel.java b/src/java/org/apache/fop/render/awt/viewer/PreviewPanel.java index 734dc90dd..e93127759 100644 --- a/src/java/org/apache/fop/render/awt/viewer/PreviewPanel.java +++ b/src/java/org/apache/fop/render/awt/viewer/PreviewPanel.java @@ -23,6 +23,7 @@ import java.awt.Color; import java.awt.Dimension; import java.awt.GridLayout; import java.awt.Point; +import java.awt.Toolkit; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; @@ -36,11 +37,12 @@ import javax.swing.JViewport; import javax.swing.SwingUtilities; import javax.swing.border.EmptyBorder; +import org.apache.xmlgraphics.util.UnitConv; + import org.apache.fop.apps.FOPException; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.MimeConstants; import org.apache.fop.area.PageViewport; - import org.apache.fop.render.awt.AWTRenderer; @@ -155,6 +157,8 @@ public class PreviewPanel extends JPanel { this.renderable = renderable; this.renderer = renderer; this.foUserAgent = foUserAgent; + //Override target resolution for the computer screen + this.foUserAgent.setTargetResolution(Toolkit.getDefaultToolkit().getScreenResolution()); gridPanel = new JPanel(); gridPanel.setLayout(new GridLayout(0, 1)); // rows, cols @@ -393,8 +397,10 @@ public class PreviewPanel extends JPanel { public double getScaleToFit(double viewWidth, double viewHeight) throws FOPException { PageViewport pageViewport = renderer.getPageViewport(currentPage); Rectangle2D pageSize = pageViewport.getViewArea(); - double widthScale = viewWidth / (pageSize.getWidth() / 1000f); - double heightScale = viewHeight / (pageSize.getHeight() / 1000f); + float screenResolution = Toolkit.getDefaultToolkit().getScreenResolution(); + float screenFactor = screenResolution / UnitConv.IN2PT; + double widthScale = viewWidth / (pageSize.getWidth() / 1000f) / screenFactor; + double heightScale = viewHeight / (pageSize.getHeight() / 1000f) / screenFactor; return Math.min(displayMode == CONT_FACING ? widthScale / 2 : widthScale, heightScale); } diff --git a/status.xml b/status.xml index 5350284bf..b1236072d 100644 --- a/status.xml +++ b/status.xml @@ -60,6 +60,9 @@ --> + + Fixed resolution handling inside AWT preview dialog. + Fixed positioning of absolutely positioned block-containers in multi-column documents. -- 2.39.5