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;
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;
/**
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.
public PreviewDialog(FOUserAgent foUserAgent, Renderable renderable) {
renderer = (AWTRenderer) foUserAgent.getRendererOverride();
this.foUserAgent = foUserAgent;
+ this.configuredTargetResolution = this.foUserAgent.getTargetResolution();
this.renderable = renderable;
translator = new Translator();
}
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()) {
e.printStackTrace();
}
}
+
+ foUserAgent.setTargetResolution(saveResolution);
}
/**
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;
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;
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
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);
}