]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Fixed resolution handling inside AWT preview dialog.
authorJeremias Maerki <jeremias@apache.org>
Wed, 11 Jun 2008 12:18:53 +0000 (12:18 +0000)
committerJeremias Maerki <jeremias@apache.org>
Wed, 11 Jun 2008 12:18:53 +0000 (12:18 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/fop-0_95@666635 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/render/awt/viewer/PreviewDialog.java
src/java/org/apache/fop/render/awt/viewer/PreviewPanel.java
status.xml

index ee220d629fb47b686554582b1a38552bf6e0ffb4..98e6102975000b7a601bdbc065bdabc3f8a1472a 100644 (file)
@@ -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);
     }
 
     /**
index 734dc90dd6aebecff98773ed6d9486cac0a6f9ee..e931277595c84befd6abfb04056112cdb9e7e531 100644 (file)
@@ -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);
     }
 
index 5350284bfd137003af439b0b0f28f6bd03ded78c..b1236072d8d51ab19b7f67a56ed869977320c86e 100644 (file)
@@ -60,6 +60,9 @@
       -->
     <!--/release-->
     <release version="0.95" date="TBD">
+      <action context="Renderers" dev="JM" type="fix">
+        Fixed resolution handling inside AWT preview dialog.
+      </action>
       <action context="Renderers" dev="JM" type="fix">
         Fixed positioning of absolutely positioned block-containers in multi-column documents.
       </action>