You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-commits@xmlgraphics.apache.org by de...@apache.org on 2005/09/01 12:19:59 UTC

svn commit: r265692 - /xmlgraphics/batik/branches/svg11/sources/org/apache/batik/transcoder/print/PrintTranscoder.java

Author: deweese
Date: Thu Sep  1 03:19:53 2005
New Revision: 265692

URL: http://svn.apache.org/viewcvs?rev=265692&view=rev
Log:
Fix to PrintTranscoder to offset document to start of imagable area.

Modified:
    xmlgraphics/batik/branches/svg11/sources/org/apache/batik/transcoder/print/PrintTranscoder.java

Modified: xmlgraphics/batik/branches/svg11/sources/org/apache/batik/transcoder/print/PrintTranscoder.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/batik/branches/svg11/sources/org/apache/batik/transcoder/print/PrintTranscoder.java?rev=265692&r1=265691&r2=265692&view=diff
==============================================================================
--- xmlgraphics/batik/branches/svg11/sources/org/apache/batik/transcoder/print/PrintTranscoder.java (original)
+++ xmlgraphics/batik/branches/svg11/sources/org/apache/batik/transcoder/print/PrintTranscoder.java Thu Sep  1 03:19:53 2005
@@ -170,11 +170,8 @@
         // Now, request the transcoder to actually perform the
         // printing job.
         //
-        PrinterJob printerJob =
-            PrinterJob.getPrinterJob();
-
-        PageFormat pageFormat =
-            printerJob.defaultPage();
+        PrinterJob printerJob = PrinterJob.getPrinterJob();
+        PageFormat pageFormat = printerJob.defaultPage();
 
         //
         // Set the page parameters from the hints
@@ -193,19 +190,20 @@
         }
 
         float x=0, y=0;
-        float width=(float)paper.getWidth(), height=(float)paper.getHeight();
+        float width =(float)paper.getWidth();
+        float height=(float)paper.getHeight();
 
-        Float leftMargin = (Float)hints.get(KEY_MARGIN_LEFT);
-        Float topMargin = (Float)hints.get(KEY_MARGIN_TOP);
-        Float rightMargin = (Float)hints.get(KEY_MARGIN_RIGHT);
+        Float leftMargin   = (Float)hints.get(KEY_MARGIN_LEFT);
+        Float topMargin    = (Float)hints.get(KEY_MARGIN_TOP);
+        Float rightMargin  = (Float)hints.get(KEY_MARGIN_RIGHT);
         Float bottomMargin = (Float)hints.get(KEY_MARGIN_BOTTOM);
 
         if(leftMargin != null){
-            x = leftMargin.floatValue();
+            x      = leftMargin.floatValue();
             width -= leftMargin.floatValue();
         }
         if(topMargin != null){
-            y = topMargin.floatValue();
+            y       = topMargin.floatValue();
             height -= topMargin.floatValue();
         }
         if(rightMargin != null){
@@ -235,7 +233,7 @@
         // If required, pop up a dialog to adjust the page format
         //
         Boolean showPageFormat = (Boolean)hints.get(KEY_SHOW_PAGE_DIALOG);
-        if(showPageFormat != null && showPageFormat.booleanValue()){
+        if ((showPageFormat != null) && (showPageFormat.booleanValue())) {
             PageFormat tmpPageFormat = printerJob.pageDialog(pageFormat);
             if(tmpPageFormat == pageFormat){
                 // Dialog was cancelled, meaning that the print process should
@@ -249,7 +247,8 @@
         //
         // If required, pop up a dialog to select the printer
         //
-        Boolean showPrinterDialog = (Boolean)hints.get(KEY_SHOW_PRINTER_DIALOG);
+        Boolean showPrinterDialog;
+        showPrinterDialog = (Boolean)hints.get(KEY_SHOW_PRINTER_DIALOG);
         if(showPrinterDialog != null && showPrinterDialog.booleanValue()){
             if(!printerJob.printDialog()){
                 // Dialog was cancelled, meaning that the print process
@@ -298,8 +297,8 @@
             // method which takes a document as an input. That method
             // builds the GVT root tree.{
             try{
-                width  = (int)(pageFormat.getImageableWidth()+0.5);
-                height = (int)(pageFormat.getImageableHeight()+0.5);
+                width  = (int)pageFormat.getImageableWidth();
+                height = (int)pageFormat.getImageableHeight();
                 super.transcode
                     ((TranscoderInput)printedInputs.elementAt(pageIndex),null);
                 curIndex = pageIndex;
@@ -324,6 +323,14 @@
         AffineTransform t = g.getTransform();
         Shape clip = g.getClip();
 
+        // System.err.println("X/Y: " + pageFormat.getImageableX() + ", " +
+        //                    pageFormat.getImageableY());
+        // System.err.println("W/H: " + width + ", " + height);
+        // System.err.println("Clip: " + clip.getBounds2D());
+
+        // Offset 0,0 to the start of the imageable Area.
+        g.translate(pageFormat.getImageableX(),
+                    pageFormat.getImageableY());
         //
         // Append transform to selected area
         //