From 31e520e3a8bc5dd68427b17f1307c46a971406df Mon Sep 17 00:00:00 2001 From: Keiron Liddle Date: Wed, 18 Sep 2002 14:12:42 +0000 Subject: [PATCH] updated for area tree and prepare for block border and back git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@195225 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/fop/render/AbstractRenderer.java | 28 +++++++-- .../apache/fop/render/pdf/PDFRenderer.java | 61 +++++++++++++++---- 2 files changed, 71 insertions(+), 18 deletions(-) diff --git a/src/org/apache/fop/render/AbstractRenderer.java b/src/org/apache/fop/render/AbstractRenderer.java index 36a9f1cc4..c23148c33 100644 --- a/src/org/apache/fop/render/AbstractRenderer.java +++ b/src/org/apache/fop/render/AbstractRenderer.java @@ -278,7 +278,7 @@ public abstract class AbstractRenderer extends AbstractLogEnabled * @param bf The before float area */ protected void renderBeforeFloat(BeforeFloat bf) { - List blocks = bf.getBlocks(); + List blocks = bf.getChildAreas(); if (blocks != null) { renderBlocks(blocks); Block sep = bf.getSeparator(); @@ -294,7 +294,7 @@ public abstract class AbstractRenderer extends AbstractLogEnabled * @param footnote The footnote */ protected void renderFootnote(Footnote footnote) { - List blocks = footnote.getBlocks(); + List blocks = footnote.getChildAreas(); if (blocks != null) { Block sep = footnote.getSeparator(); if (sep != null) { @@ -343,7 +343,7 @@ public abstract class AbstractRenderer extends AbstractLogEnabled */ protected void renderFlow(Flow flow) { // the normal flow reference area contains stacked blocks - List blocks = flow.getBlocks(); + List blocks = flow.getChildAreas(); renderBlocks(blocks); } @@ -356,6 +356,7 @@ public abstract class AbstractRenderer extends AbstractLogEnabled protected void renderBlock(Block block) { List children = block.getChildAreas(); if (children == null) { + handleBlockTraits(block); // simply move position currentBPPosition += block.getHeight(); } else if (block instanceof BlockViewport) { @@ -366,8 +367,10 @@ public abstract class AbstractRenderer extends AbstractLogEnabled int saveBP = currentBPPosition; if (block.getPositioning() == Block.ABSOLUTE) { - currentIPPosition += block.getXOffset(); - currentBPPosition += block.getYOffset(); + currentIPPosition = containingIPPosition + block.getXOffset(); + currentBPPosition = containingBPPosition + block.getYOffset(); + + handleBlockTraits(block); renderBlocks(children); @@ -378,6 +381,8 @@ public abstract class AbstractRenderer extends AbstractLogEnabled currentIPPosition += block.getXOffset(); currentBPPosition += block.getYOffset(); + handleBlockTraits(block); + renderBlocks(children); // stacked and relative blocks effect stacking @@ -387,6 +392,18 @@ public abstract class AbstractRenderer extends AbstractLogEnabled } } + /** + * Handle block traits. + * This method is called when the correct ip and bp posiiton is + * set. This should be overridden to draw border and background + * traits for the block area. + * + * @param block the block area + */ + protected void handleBlockTraits(Block block) { + // draw border and background + } + /** * Renders a block viewport. * @@ -405,6 +422,7 @@ public abstract class AbstractRenderer extends AbstractLogEnabled currentBPPosition = 0; startVParea(ctm); + handleBlockTraits(bv); renderBlocks(children); endVParea(); diff --git a/src/org/apache/fop/render/pdf/PDFRenderer.java b/src/org/apache/fop/render/pdf/PDFRenderer.java index 66bb16c20..02cbc8e56 100644 --- a/src/org/apache/fop/render/pdf/PDFRenderer.java +++ b/src/org/apache/fop/render/pdf/PDFRenderer.java @@ -17,7 +17,6 @@ import org.apache.fop.image.ImageFactory; import org.apache.fop.apps.FOPException; import org.apache.fop.apps.Version; import org.apache.fop.fo.properties.RuleStyle; -//import org.apache.fop.datatypes.*; import org.apache.fop.pdf.PDFStream; import org.apache.fop.pdf.PDFDocument; import org.apache.fop.pdf.PDFInfo; @@ -50,6 +49,7 @@ import org.apache.fop.area.inline.Leader; import org.apache.fop.area.inline.InlineParent; import org.apache.fop.layout.FontState; import org.apache.fop.layout.FontMetric; +import org.apache.fop.traits.BorderProps; import org.w3c.dom.Document; @@ -117,47 +117,47 @@ public class PDFRenderer extends PrintRenderer { /** * the current stream to add PDF commands to */ - PDFStream currentStream; + protected PDFStream currentStream; /** * the current annotation list to add annotations to */ - PDFAnnotList currentAnnotList; + protected PDFAnnotList currentAnnotList; /** * the current page to add annotations to */ - PDFPage currentPage; + protected PDFPage currentPage; // drawing state - PDFState currentState = null; + protected PDFState currentState = null; - PDFColor currentColor; - String currentFontName = ""; - int currentFontSize = 0; - int pageHeight; + protected PDFColor currentColor; + protected String currentFontName = ""; + protected int currentFontSize = 0; + protected int pageHeight; /** * true if a TJ command is left to be written */ - boolean textOpen = false; + protected boolean textOpen = false; /** * the previous Y coordinate of the last word written. * Used to decide if we can draw the next word on the same line. */ - int prevWordY = 0; + protected int prevWordY = 0; /** * the previous X coordinate of the last word written. * used to calculate how much space between two words */ - int prevWordX = 0; + protected int prevWordX = 0; /** * The width of the previous word. Used to calculate space between */ - int prevWordWidth = 0; + protected int prevWordWidth = 0; /** * reusable word area string buffer to reduce memory usage @@ -341,12 +341,44 @@ public class PDFRenderer extends PrintRenderer { super.renderRegion(region); } + protected void handleBlockTraits(Block block) { + // draw border and background + BorderProps bps = (BorderProps)block.getTrait(Trait.BORDER_BEFORE); + if(bps != null) { + float startx = ((float) currentBlockIPPosition) / 1000f; + float starty = (currentBPPosition / 1000f); + float endx = (currentBlockIPPosition + block.getWidth()) / 1000f; + + currentStream.add("ET\n"); + currentStream.add("q\n"); + + currentStream.add(bps.width / 1000f + " w\n"); + + currentStream.add(startx + " " + starty + " m\n"); + currentStream.add(endx + " " + starty + " l\n"); + currentStream.add("S\n"); + + currentStream.add("Q\n"); + currentStream.add("BT\n"); + } + bps = (BorderProps)block.getTrait(Trait.BORDER_START); + if(bps != null) { + } + bps = (BorderProps)block.getTrait(Trait.BORDER_AFTER); + if(bps != null) { + } + bps = (BorderProps)block.getTrait(Trait.BORDER_END); + if(bps != null) { + } + } + protected void renderBlockViewport(BlockViewport bv, List children) { // clip and position viewport if necessary // save positions int saveIP = currentIPPosition; int saveBP = currentBPPosition; + String saveFontName = currentFontName; CTM ctm = bv.getCTM(); @@ -372,6 +404,7 @@ public class PDFRenderer extends PrintRenderer { ctm = tempctm.multiply(ctm); startVParea(ctm); + handleBlockTraits(bv); renderBlocks(children); endVParea(); @@ -415,6 +448,7 @@ public class PDFRenderer extends PrintRenderer { if (ctm != null) { startVParea(ctm); } + handleBlockTraits(bv); renderBlocks(children); if (ctm != null) { endVParea(); @@ -433,6 +467,7 @@ public class PDFRenderer extends PrintRenderer { currentBPPosition = saveBP; currentBPPosition += (int)(bv.getHeight()); } + currentFontName = saveFontName; } /** -- 2.39.5