]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Take CTM into account for PDF rendering (small test)
authorKaren Lease <klease@apache.org>
Sat, 23 Feb 2002 16:48:59 +0000 (16:48 +0000)
committerKaren Lease <klease@apache.org>
Sat, 23 Feb 2002 16:48:59 +0000 (16:48 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194668 13f79535-47bb-0310-9956-ffa450edef68

src/org/apache/fop/render/AbstractRenderer.java
src/org/apache/fop/render/pdf/PDFRenderer.java

index 4d6584b3805ab7fc2676fd3516cdb7bd48a8f7a2..bfcf41f7530b2ac042a435ca1c9d57b8dcc3dd1d 100644 (file)
@@ -134,19 +134,28 @@ public abstract class AbstractRenderer implements Renderer {
     protected void renderRegionViewport(RegionViewport port) {
         if (port != null) {
             Rectangle2D view = port.getViewArea();
-            currentBPPosition = (int) (view.getY() / 1000);
-            currentIPPosition = (int) (view.getX() / 1000);
+           // The CTM will transform coordinates relative to
+           // this region-reference area into page coords, so
+           // set origin for the region to 0,0.
+            currentBPPosition = 0; // (int) (view.getY() / 1000);
+            currentIPPosition = 0; // (int) (view.getX() / 1000);
             currentBlockIPPosition = currentIPPosition;
 
             RegionReference region = port.getRegion();
+           startVParea(region.getCTM());
             if (region.getRegionClass() == Region.BODY) {
                 renderBodyRegion((BodyRegion) region);
             } else {
                 renderRegion(region);
             }
+           endVParea();
         }
     }
 
+    protected void startVParea(CTM ctm) { }
+
+    protected void endVParea() { }
+
     protected void renderRegion(RegionReference region) {
         List blocks = region.getBlocks();
 
index a8ba5ad93dc77ccb21140fa863186baaa432171f..ea6a579e5bf59eb5a4267e7ec45b08819d6cbf67 100644 (file)
@@ -204,18 +204,48 @@ public class PDFRenderer extends PrintRenderer {
             pageReferences.put(page, currentPage.referencePDF());
         }
         currentStream = this.pdfDoc.makeStream();
-        currentStream.add("BT\n");
+       // Transform origin at top left to origin at bottom left
+       currentStream.add("1 0 0 -1 0 " +
+                         (int) Math.round(pageHeight / 1000) + " cm\n");
+        //currentStream.add("BT\n");
 
         Page p = page.getPage();
         renderPageAreas(p);
 
-        currentStream.add("ET\n");
+        //currentStream.add("ET\n");
 
         currentPage.setContents(currentStream);
         this.pdfDoc.addPage(currentPage);
         this.pdfDoc.output(ostream);
     }
 
+
+    protected void startVParea(CTM ctm) {
+       // Set the given CTM in the graphics state
+       currentStream.add("q\n");
+       // multiply with current CTM
+       currentStream.add(ctm.toPDFctm() + " cm\n");
+       // Set clip?
+    }
+
+    protected void endVParea() {
+       currentStream.add("Q\n");
+    }
+
+    protected void renderRegion(RegionReference region) {
+       // Draw a rectangle so we can see it!
+       // x=0,y=0,w=ipd,h=bpd
+       currentStream.add("BT\n");
+       super.renderRegion(region);
+       currentStream.add("ET\n");
+    }
+
+
+    protected void renderLineArea(LineArea line) {
+       super.renderLineArea(line);
+       closeText();
+    }
+
     public void renderCharacter(Character ch) {
 
         super.renderCharacter(ch);
@@ -248,7 +278,8 @@ public class PDFRenderer extends PrintRenderer {
             updateColor(true, pdf);
 
             int rx = currentBlockIPPosition;
-            int bl = pageHeight - currentBPPosition;
+            // int bl = pageHeight - currentBPPosition;
+            int bl = currentBPPosition;
 
             // Set letterSpacing
             //float ls = fs.getLetterSpacing() / this.currentFontSize;
@@ -257,7 +288,7 @@ public class PDFRenderer extends PrintRenderer {
             if (!textOpen || bl != prevWordY) {
                 closeText();
 
-                pdf.append("1 0 0 1 " + (rx / 1000f) + " " + (bl / 1000f)
+                pdf.append("1 0 0 -1 " + (rx / 1000f) + " " + (bl / 1000f)
                            + " Tm [" + startText);
                 prevWordY = bl;
                 textOpen = true;