Merge commit '42b2e5ca519766e37ce6941ba4faecc9691cc403' into upstream
[debian/openrocket] / core / src / net / sf / openrocket / gui / print / visitor / FinSetPrintStrategy.java
index 80e15a216763fd034bf15a0c098fa2d0e6ef3101..3870490831217061986a4c16b7d60aa70f6be8fe 100644 (file)
@@ -6,16 +6,15 @@ package net.sf.openrocket.gui.print.visitor;
 import com.itextpdf.text.Document;
 import com.itextpdf.text.DocumentException;
 import com.itextpdf.text.Rectangle;
-import com.itextpdf.text.pdf.PdfContentByte;
 import com.itextpdf.text.pdf.PdfWriter;
 import net.sf.openrocket.gui.print.ITextHelper;
+import net.sf.openrocket.gui.print.PrintUnit;
 import net.sf.openrocket.gui.print.PrintableFinSet;
 import net.sf.openrocket.logging.LogHelper;
 import net.sf.openrocket.rocketcomponent.FinSet;
 import net.sf.openrocket.rocketcomponent.RocketComponent;
 import net.sf.openrocket.startup.Application;
 
-import java.awt.*;
 import java.awt.image.BufferedImage;
 import java.util.List;
 import java.util.Set;
@@ -45,6 +44,11 @@ public class FinSetPrintStrategy {
      */
     protected Set<Integer> stages;
 
+    /**
+     * Strategy for fitting multiple components onto a page.
+     */
+       protected PageFitPrintStrategy pageFitPrint;
+
     /**
      * Constructor.
      *
@@ -52,10 +56,11 @@ public class FinSetPrintStrategy {
      * @param theWriter        The direct iText writer
      * @param theStages        The stages to be printed by this strategy
      */
-    public FinSetPrintStrategy(Document doc, PdfWriter theWriter, Set<Integer> theStages) {
+    public FinSetPrintStrategy(Document doc, PdfWriter theWriter, Set<Integer> theStages, PageFitPrintStrategy pageFit) {
         document = doc;
         writer = theWriter;
         stages = theStages;
+        pageFitPrint = pageFit;
     }
 
     /**
@@ -98,14 +103,16 @@ public class FinSetPrintStrategy {
                 java.awt.Dimension finSize = pfs.getSize();
                 final Dimension pageSize = getPageSize();
                 if (fitsOnOnePage(pageSize, finSize.getWidth(), finSize.getHeight())) {
-                    printOnOnePage(pfs);
+                                       pageFitPrint.addComponent(pfs);
                 }
                 else {
+                    int off = (int)(PrintUnit.POINTS_PER_INCH * 0.3f);
+                    pfs.setPrintOffset(off, off);
                     BufferedImage image = (BufferedImage) pfs.createImage();
                     ITextHelper.renderImageAcrossPages(new Rectangle(pageSize.getWidth(), pageSize.getHeight()),
                             document, writer, image);
+                    document.newPage();
                 }
-                document.newPage();
             }
             catch (DocumentException e) {
                 log.error("Could not render fin.", e);
@@ -153,19 +160,6 @@ public class FinSetPrintStrategy {
         return wRatio <= 1.0d && hRatio <= 1.0d;
     }
 
-    /**
-     * Print the fin set.
-     *
-     * @param thePfs the printable fin set
-     */
-    private void printOnOnePage (final PrintableFinSet thePfs) {
-        Dimension d = getPageSize();
-        PdfContentByte cb = writer.getDirectContent();
-        Graphics2D g2 = cb.createGraphics(d.width, d.height);
-        thePfs.print(g2);
-        g2.dispose();
-    }
-
     /**
      * Get the dimensions of the paper page.
      *