jeremias 2005/01/12 04:03:01 Modified: src/java/org/apache/fop/layoutmgr BlockContainerLayoutManager.java TraitSetter.java BlockLayoutManager.java src/java/org/apache/fop/fo/properties CommonMarginBlock.java src/java/org/apache/fop/pdf PDFState.java src/java/org/apache/fop/render AbstractRenderer.java src/java/org/apache/fop/render/pdf PDFRenderer.java Log: Removed the "inheritedStartIndent" hack again. Switched to start|end-indent-oriented calculation. Improved line painting in the PDFRenderer. Some improvements in BlockContainerLayoutManager (but still WIP ATM). Revision Changes Path 1.28 +110 -19 xml-fop/src/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java Index: BlockContainerLayoutManager.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java,v retrieving revision 1.27 retrieving revision 1.28 diff -u -r1.27 -r1.28 --- BlockContainerLayoutManager.java 24 Nov 2004 21:07:30 -0000 1.27 +++ BlockContainerLayoutManager.java 12 Jan 2005 12:03:00 -0000 1.28 @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,8 +24,11 @@ import org.apache.fop.area.Area; import org.apache.fop.area.BlockViewport; import org.apache.fop.area.Block; +import org.apache.fop.area.PageViewport; +import org.apache.fop.fo.Constants; import org.apache.fop.fo.flow.BlockContainer; import org.apache.fop.fo.properties.CommonAbsolutePosition; +import org.apache.fop.fo.properties.FixedLength; import org.apache.fop.area.CTM; import org.apache.fop.datatypes.FODimension; import org.apache.fop.datatypes.Length; @@ -53,51 +56,135 @@ // When viewport should grow with the content. private boolean autoHeight = true; + private int referenceIPD; + /** * Create a new block container layout manager. + * @param node block-container node to create the layout manager for. */ public BlockContainerLayoutManager(BlockContainer node) { super(node); fobj = node; } + + protected PageViewport getPageViewport() { + LayoutManager lm = this; + while (lm != null && !(lm instanceof PageSequenceLayoutManager)) { + lm = lm.getParent(); + } + if (lm == null) { + return null; + } else { + return ((PageSequenceLayoutManager)lm).getCurrentPageViewport(); + } + } /** * @see org.apache.fop.layoutmgr.AbstractLayoutManager#initProperties() */ protected void initProperties() { + log.debug(fobj.getBlockProgressionDimension().getOptimum()); + log.debug(fobj.getInlineProgressionDimension().getOptimum()); abProps = fobj.getCommonAbsolutePosition(); - if (abProps.absolutePosition == EN_ABSOLUTE) { + log.debug(abProps); + + int iIndents = fobj.getCommonMarginBlock().startIndent.getValue(); + iIndents += fobj.getCommonMarginBlock().endIndent.getValue(); + int bIndents = fobj.getCommonBorderPaddingBackground().getBPPaddingAndBorder(false); + + + if (abProps.absolutePosition == EN_ABSOLUTE && false) { Rectangle2D rect = new Rectangle2D.Double(abProps.left.getValue(), - abProps.top.getValue(), abProps.right.getValue() - abProps.left.getValue(), + abProps.top.getValue(), + abProps.right.getValue() - abProps.left.getValue(), abProps.bottom.getValue() - abProps.top.getValue()); relDims = new FODimension(0, 0); absoluteCTM = CTM.getCTMandRelDims(fobj.getReferenceOrientation(), fobj.getWritingMode(), rect, relDims); + } else if (abProps.absolutePosition == EN_FIXED + || abProps.absolutePosition == EN_ABSOLUTE) { + Rectangle2D viewArea = getPageViewport().getViewArea(); + double x = viewArea.getX() + abProps.left.getValue(); + double y = viewArea.getY() + abProps.top.getValue(); + double w = 0.0; + if (abProps.right.getEnum() == Constants.EN_AUTO) { + if (fobj.getWidth().getEnum() == Constants.EN_AUTO) { + w = viewArea.getWidth() - x; + } else { + if (fobj.getReferenceOrientation() % 180 == 0) { + w = fobj.getInlineProgressionDimension().getOptimum().getLength().getValue(); + } else { + w = fobj.getBlockProgressionDimension().getOptimum().getLength().getValue(); + } + } + } else { + w = viewArea.getWidth() - x - abProps.right.getValue(); + } + double h = 0.0; + if (abProps.bottom.getEnum() == Constants.EN_AUTO) { + if (fobj.getHeight().getEnum() == Constants.EN_AUTO) { + h = viewArea.getHeight() - y; + } else { + if (fobj.getReferenceOrientation() % 180 == 0) { + h = fobj.getBlockProgressionDimension().getOptimum().getLength().getValue(); + } else { + h = fobj.getInlineProgressionDimension().getOptimum().getLength().getValue(); + } + } + } else { + h = viewArea.getHeight() - y - abProps.bottom.getValue(); + } + log.debug("x=" + x + " y=" + y + " w=" + w + " h=" + h + " orient=" + fobj.getReferenceOrientation()); + if (w != 0) { + this.width = new FixedLength((int)w); + } + if (h != 0) { + this.height = new FixedLength((int)h); + } + Rectangle2D rect = new Rectangle2D.Double(x, y, w, h); + relDims = new FODimension(0, 0); + absoluteCTM = CTM.getCTMandRelDims(fobj.getReferenceOrientation(), + fobj.getWritingMode(), rect, relDims); } - height = fobj.getBlockProgressionDimension().getOptimum().getLength(); - width = fobj.getInlineProgressionDimension().getOptimum().getLength(); + if (height == null) { + height = fobj.getBlockProgressionDimension().getOptimum().getLength(); + } + if (width == null) { + width = fobj.getInlineProgressionDimension().getOptimum().getLength(); + } } protected int getRotatedIPD() { return fobj.getInlineProgressionDimension().getOptimum().getLength().getValue(); } + private int getIPIndents() { + int iIndents = 0; + iIndents += fobj.getCommonMarginBlock().startIndent.getValue(); + iIndents += fobj.getCommonMarginBlock().endIndent.getValue(); + return iIndents; + } + public BreakPoss getNextBreakPoss(LayoutContext context) { if (abProps.absolutePosition == EN_ABSOLUTE) { return getAbsoluteBreakPoss(context); + } else if (abProps.absolutePosition == EN_FIXED) { + return getAbsoluteBreakPoss(context); } - int ipd = context.getRefIPD(); + referenceIPD = context.getRefIPD(); int bpd = context.getStackLimit().opt; if (width.getEnum() != EN_AUTO) { - ipd = width.getValue(); + referenceIPD = width.getValue(); } if (height.getEnum() != EN_AUTO) { bpd = height.getValue(); } - Rectangle2D rect = new Rectangle2D.Double(0, 0, ipd, bpd); + int contentIPD = referenceIPD - getIPIndents(); + + Rectangle2D rect = new Rectangle2D.Double(0, 0, contentIPD, bpd); relDims = new FODimension(0, 0); absoluteCTM = CTM.getCTMandRelDims(fobj.getReferenceOrientation(), fobj.getWritingMode(), rect, relDims); @@ -122,16 +209,16 @@ stackLimit = context.getStackLimit(); } - LayoutManager curLM ; // currently active LM + LayoutManager curLM; // currently active LM MinOptMax stackSize = new MinOptMax(); // if starting add space before // stackSize.add(spaceBefore); BreakPoss lastPos = null; - fobj.setLayoutDimension(PercentBase.BLOCK_IPD, ipd); + fobj.setLayoutDimension(PercentBase.BLOCK_IPD, contentIPD); fobj.setLayoutDimension(PercentBase.BLOCK_BPD, bpd); - fobj.setLayoutDimension(PercentBase.REFERENCE_AREA_IPD, ipd); + fobj.setLayoutDimension(PercentBase.REFERENCE_AREA_IPD, contentIPD); fobj.setLayoutDimension(PercentBase.REFERENCE_AREA_BPD, bpd); while ((curLM = getChildLM()) != null) { @@ -143,7 +230,7 @@ childLC.setStackLimit( MinOptMax.subtract(stackLimit, stackSize)); - childLC.setRefIPD(ipd); + childLC.setRefIPD(contentIPD); boolean over = false; while (!curLM.isFinished()) { @@ -187,7 +274,7 @@ BreakPoss breakPoss; breakPoss = new BreakPoss(new LeafPosition(this, childBreaks.size() - 1)); - breakPoss.setStackingSize(new MinOptMax(ipd)); + breakPoss.setStackingSize(new MinOptMax(contentIPD)); return breakPoss; } return null; @@ -207,8 +294,8 @@ BreakPoss bp; LayoutContext childLC = new LayoutContext(0); - childLC.setStackLimit(new MinOptMax(1000000)); - childLC.setRefIPD(ipd); + childLC.setStackLimit(new MinOptMax(1000000)); + childLC.setRefIPD(ipd); while (!curLM.isFinished()) { if ((bp = curLM.getNextBreakPoss(childLC)) != null) { @@ -225,10 +312,11 @@ breakPoss.setStackingSize(new MinOptMax(0)); if (stackSize.opt > relDims.bpd) { + log.warn("Contents overflow block-container viewport: clipping"); if (fobj.getOverflow() == EN_HIDDEN) { clip = true; } else if (fobj.getOverflow() == EN_ERROR_IF_OVERFLOW) { - log.error("contents overflows block-container viewport: clipping"); + //TODO Throw layout exception clip = true; } } @@ -279,11 +367,12 @@ TraitSetter.addBorders(viewportBlockArea, fobj.getCommonBorderPaddingBackground()); TraitSetter.addBackground(viewportBlockArea, fobj.getCommonBorderPaddingBackground()); - if (abProps.absolutePosition == EN_ABSOLUTE) { + if (abProps.absolutePosition == EN_ABSOLUTE + || abProps.absolutePosition == EN_FIXED) { viewportBlockArea.setXOffset(abProps.left.getValue()); viewportBlockArea.setYOffset(abProps.top.getValue()); - viewportBlockArea.setIPD(abProps.right.getValue() - abProps.left.getValue()); - viewportBlockArea.setBPD(abProps.bottom.getValue() - abProps.top.getValue()); + viewportBlockArea.setIPD(width.getValue()); + viewportBlockArea.setBPD(height.getValue()); viewportBlockArea.setCTM(absoluteCTM); viewportBlockArea.setClip(clip); @@ -320,6 +409,8 @@ if (abProps.absolutePosition == EN_ABSOLUTE) { viewportBlockArea.setPositioning(Block.ABSOLUTE); + } else if (abProps.absolutePosition == EN_FIXED) { + viewportBlockArea.setPositioning(Block.FIXED); } // Set up dimensions 1.12 +10 -3 xml-fop/src/java/org/apache/fop/layoutmgr/TraitSetter.java Index: TraitSetter.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/TraitSetter.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- TraitSetter.java 7 Jan 2005 08:21:21 -0000 1.11 +++ TraitSetter.java 12 Jan 2005 12:03:00 -0000 1.12 @@ -183,19 +183,26 @@ * @param bpProps the border, padding and background properties * @param marginProps the margin properties. */ - public static void addMargins(Area area, + public static void addMargins(Area area, Area parentArea, CommonBorderPaddingBackground bpProps, CommonMarginBlock marginProps) { + int startIndent = marginProps.startIndent.getValue(); + if (startIndent != 0) { + area.addTrait(Trait.START_INDENT, new Integer(startIndent)); + } + int spaceStart = marginProps.startIndent.getValue() - - marginProps.inheritedStartIndent.getValue() - bpProps.getBorderStartWidth(false) - bpProps.getPaddingStart(false); if (spaceStart != 0) { area.addTrait(Trait.SPACE_START, new Integer(spaceStart)); } + int endIndent = marginProps.endIndent.getValue(); + if (endIndent != 0) { + area.addTrait(Trait.END_INDENT, new Integer(endIndent)); + } int spaceEnd = marginProps.endIndent.getValue() - - marginProps.inheritedEndIndent.getValue() - bpProps.getBorderEndWidth(false) - bpProps.getPaddingEnd(false); if (spaceEnd != 0) { 1.36 +33 -23 xml-fop/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java Index: BlockLayoutManager.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java,v retrieving revision 1.35 retrieving revision 1.36 diff -u -r1.35 -r1.36 --- BlockLayoutManager.java 7 Jan 2005 08:21:21 -0000 1.35 +++ BlockLayoutManager.java 12 Jan 2005 12:03:00 -0000 1.36 @@ -22,6 +22,9 @@ import java.util.List; import org.apache.fop.datatypes.PercentBase; +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.FObj; +import org.apache.fop.fo.properties.CommonMarginBlock; import org.apache.fop.fonts.Font; import org.apache.fop.area.Area; import org.apache.fop.area.Block; @@ -61,6 +64,9 @@ private int iStartPos = 0; + private int referenceIPD = 0; + //private int contentIPD = 0; + /** The list of child BreakPoss instances. */ protected List childBreaks = new java.util.ArrayList(); @@ -163,19 +169,22 @@ return llm; } + private int getIPIndents() { + int iIndents = 0; + iIndents += fobj.getCommonMarginBlock().startIndent.getValue(); + iIndents += fobj.getCommonMarginBlock().endIndent.getValue(); + return iIndents; + } + /** * @see org.apache.fop.layoutmgr.LayoutManager#getNextBreakPoss(org.apache.fop.layoutmgr.LayoutContext) */ public BreakPoss getNextBreakPoss(LayoutContext context) { LayoutManager curLM; // currently active LM - int ipd = context.getRefIPD(); - int iIndents = fobj.getCommonMarginBlock().startIndent.getValue(); - iIndents += fobj.getCommonMarginBlock().endIndent.getValue(); - iIndents -= fobj.getCommonMarginBlock().inheritedStartIndent.getValue(); - iIndents -= fobj.getCommonMarginBlock().inheritedEndIndent.getValue(); - //int bIndents = fobj.getCommonBorderPaddingBackground().getBPPaddingAndBorder(false); - ipd -= iIndents; + //int refipd = context.getRefIPD(); + referenceIPD = context.getRefIPD(); + int contentipd = referenceIPD - getIPIndents(); MinOptMax stackSize = new MinOptMax(); @@ -193,7 +202,7 @@ BreakPoss lastPos = null; // Set context for percentage property values. - fobj.setLayoutDimension(PercentBase.BLOCK_IPD, ipd); + fobj.setLayoutDimension(PercentBase.BLOCK_IPD, contentipd); fobj.setLayoutDimension(PercentBase.BLOCK_BPD, -1); while ((curLM = getChildLM()) != null) { @@ -206,13 +215,13 @@ // line LM actually generates a LineArea which is a block if (curLM.generatesInlineAreas()) { // set stackLimit for lines - childLC.setStackLimit(new MinOptMax(ipd/* - iIndents - iTextIndent*/)); - childLC.setRefIPD(ipd); + childLC.setStackLimit(new MinOptMax(contentipd)); + childLC.setRefIPD(contentipd); } else { childLC.setStackLimit( MinOptMax.subtract(context.getStackLimit(), stackSize)); - childLC.setRefIPD(ipd); + childLC.setRefIPD(referenceIPD); } boolean over = false; while (!curLM.isFinished()) { @@ -242,7 +251,7 @@ if (curLM.generatesInlineAreas()) { // Reset stackLimit for non-first lines - childLC.setStackLimit(new MinOptMax(ipd/* - iIndents*/)); + childLC.setStackLimit(new MinOptMax(contentipd)); } else { childLC.setStackLimit(MinOptMax.subtract( context.getStackLimit(), stackSize)); @@ -329,27 +338,28 @@ if (curBlockArea == null) { curBlockArea = new Block(); + // Must get dimensions from parent area + Area parentArea = parentLM.getParentArea(curBlockArea); + // set traits TraitSetter.addBorders(curBlockArea, fobj.getCommonBorderPaddingBackground()); TraitSetter.addBackground(curBlockArea, fobj.getCommonBorderPaddingBackground()); - TraitSetter.addMargins(curBlockArea, + TraitSetter.addMargins(curBlockArea, parentArea, fobj.getCommonBorderPaddingBackground(), fobj.getCommonMarginBlock()); TraitSetter.addBreaks(curBlockArea, fobj.getBreakBefore(), fobj.getBreakAfter()); // Set up dimensions - // Must get dimensions from parent area - Area parentArea = parentLM.getParentArea(curBlockArea); - // Get reference IPD from parentArea - int referenceIPD = parentArea.getIPD(); - curBlockArea.setIPD(referenceIPD); + //int referenceIPD = parentArea.getIPD(); + //curBlockArea.setIPD(referenceIPD); // Set the width of the block based on the parent block // Need to be careful though, if parent is BC then width may not be set + /* TODO remove if really not used anymore int parentwidth = 0; if (parentArea instanceof BlockParent) { parentwidth = ((BlockParent) parentArea).getIPD(); @@ -357,12 +367,12 @@ if (parentwidth == 0) { parentwidth = referenceIPD; } - parentwidth -= fobj.getCommonMarginBlock().startIndent.getValue(); - parentwidth -= fobj.getCommonMarginBlock().endIndent.getValue(); - parentwidth += fobj.getCommonMarginBlock().inheritedStartIndent.getValue(); - parentwidth += fobj.getCommonMarginBlock().inheritedEndIndent.getValue(); + parentwidth -= getIPIndents(); + */ + + int contentIPD = referenceIPD - getIPIndents(); - curBlockArea.setIPD(parentwidth); + curBlockArea.setIPD(contentIPD/*parentwidth*/); setCurrentArea(curBlockArea); // ??? for generic operations } return curBlockArea; 1.6 +2 -21 xml-fop/src/java/org/apache/fop/fo/properties/CommonMarginBlock.java Index: CommonMarginBlock.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/properties/CommonMarginBlock.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- CommonMarginBlock.java 7 Jan 2005 08:21:21 -0000 1.5 +++ CommonMarginBlock.java 12 Jan 2005 12:03:00 -0000 1.6 @@ -70,16 +70,6 @@ public Length endIndent; /** - * The inherited "start-indent" property. - */ - public Length inheritedStartIndent; - - /** - * The inherited "end-indent" property. - */ - public Length inheritedEndIndent; - - /** * Create a CommonMarginBlock object. * @param pList The PropertyList with propery values. */ @@ -94,13 +84,6 @@ startIndent = pList.get(Constants.PR_START_INDENT).getLength(); endIndent = pList.get(Constants.PR_END_INDENT).getLength(); - - if (!pList.getFObj().generatesReferenceAreas()) { - inheritedStartIndent = pList.getParentPropertyList() - .get(Constants.PR_START_INDENT).getLength(); - inheritedEndIndent = pList.getParentPropertyList() - .get(Constants.PR_END_INDENT).getLength(); - } } /** @see java.lang.Object#toString() */ @@ -112,9 +95,7 @@ + "Space (before, after): (" + spaceBefore + ", " + spaceAfter + ")\n" + "Indents (start, end): (" - + startIndent + ", " + endIndent + ")\n" - + "Indents inherited (start, end): (" - + inheritedStartIndent + ", " + inheritedEndIndent + ")\n"; + + startIndent + ", " + endIndent + ")\n"; } } 1.4 +15 -1 xml-fop/src/java/org/apache/fop/pdf/PDFState.java Index: PDFState.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/pdf/PDFState.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- PDFState.java 27 Feb 2004 17:50:31 -0000 1.3 +++ PDFState.java 12 Jan 2005 12:03:00 -0000 1.4 @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -186,6 +186,20 @@ return false; } + /** + * Set the current line width. + * @param width the line width in points + * @return true if the line width has changed + */ + public boolean setLineWidth(float width) { + if (lineWidth != width) { + lineWidth = width; + return true; + } else { + return false; + } + } + /** * Set the current color. * Check if the new color is a change and then set the current color. 1.40 +11 -3 xml-fop/src/java/org/apache/fop/render/AbstractRenderer.java Index: AbstractRenderer.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/render/AbstractRenderer.java,v retrieving revision 1.39 retrieving revision 1.40 diff -u -r1.39 -r1.40 --- AbstractRenderer.java 29 Nov 2004 08:45:14 -0000 1.39 +++ AbstractRenderer.java 12 Jan 2005 12:03:00 -0000 1.40 @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -468,11 +468,12 @@ // Calculate the position of the content rectangle. if (parent != null) { currentBPPosition += parent.getBorderAndPaddingWidthBefore(); + /* This is unnecessary now as we're going to use the *-indent traits currentIPPosition += parent.getBorderAndPaddingWidthStart(); Integer spaceStart = (Integer) parent.getTrait(Trait.SPACE_START); if (spaceStart != null) { currentIPPosition += spaceStart.intValue(); - } + }*/ } // the position of the containing block is used for @@ -495,7 +496,9 @@ // a line area is rendered from the top left position // of the line, each inline object is offset from there LineArea line = (LineArea) obj; - currentIPPosition = contIP + line.getStartIndent(); + currentIPPosition = contIP + + parent.getStartIndent() + + line.getStartIndent(); renderLineArea(line); currentBPPosition += line.getAllocBPD(); } @@ -547,6 +550,10 @@ } } + protected void renderTextDecoration(InlineArea area) { + //getLogger().debug("renderTextDecoration for " + area + " -> " + area.getTrait(Trait.UNDERLINE)); + } + /** * Renders a line area. <p> * @@ -565,6 +572,7 @@ } protected void renderInlineArea(InlineArea inlineArea) { + renderTextDecoration(inlineArea); if (inlineArea instanceof TextArea) { renderText((TextArea) inlineArea); } else if (inlineArea instanceof InlineParent) { 1.66 +57 -34 xml-fop/src/java/org/apache/fop/render/pdf/PDFRenderer.java Index: PDFRenderer.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/render/pdf/PDFRenderer.java,v retrieving revision 1.65 retrieving revision 1.66 diff -u -r1.65 -r1.66 --- PDFRenderer.java 4 Jan 2005 00:21:47 -0000 1.65 +++ PDFRenderer.java 12 Jan 2005 12:03:00 -0000 1.66 @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,6 +49,7 @@ import org.apache.fop.area.OffDocumentItem; import org.apache.fop.area.BookmarkData; import org.apache.fop.area.inline.Character; +import org.apache.fop.area.inline.InlineArea; import org.apache.fop.area.inline.TextArea; import org.apache.fop.area.inline.Viewport; import org.apache.fop.area.inline.ForeignObject; @@ -237,8 +238,12 @@ * @see org.apache.fop.render.Renderer#startRenderer(OutputStream) */ public void startRenderer(OutputStream stream) throws IOException { + if (userAgent == null) { + throw new IllegalStateException("UserAgent must be set before starting the renderer"); + } ostream = stream; - this.pdfDoc = new PDFDocument(userAgent.getProducer()); + this.pdfDoc = new PDFDocument( + userAgent.getProducer() != null ? userAgent.getProducer() : ""); this.pdfDoc.setCreator(userAgent.getCreator()); this.pdfDoc.setCreationDate(userAgent.getCreationDate()); this.pdfDoc.setFilterMap(filterMap); @@ -505,10 +510,13 @@ float width = block.getIPD() / 1000f; float height = block.getBPD() / 1000f; + /* using start-indent now Integer spaceStart = (Integer) block.getTrait(Trait.SPACE_START); if (spaceStart != null) { - startx += spaceStart.floatValue() / 1000; - } + startx += spaceStart.floatValue() / 1000f; + }*/ + startx += block.getStartIndent() / 1000f; + startx -= block.getBorderAndPaddingWidthStart() / 1000f; width += borderPaddingStart / 1000f; width += block.getBorderAndPaddingWidthEnd() / 1000f; @@ -572,11 +580,9 @@ float bwidth = bps.width / 1000f; updateColor(bps.color, false, null); updateLineStyle(bps.style); - currentStream.add(bwidth + " w\n"); + updateLineWidth(bwidth); float y1 = starty + bwidth / 2; - currentStream.add(startx + " " + y1 + " m\n"); - currentStream.add(startx + width + " " + y1 + " l\n"); - currentStream.add("S\n"); + drawLine(startx, y1, startx + width, y1); } bps = (BorderProps)area.getTrait(Trait.BORDER_AFTER); if (bps != null) { @@ -585,11 +591,9 @@ float bwidth = bps.width / 1000f; updateColor(bps.color, false, null); updateLineStyle(bps.style); - currentStream.add(bwidth + " w\n"); + updateLineWidth(bwidth); float y1 = starty - bwidth / 2; - currentStream.add(startx + " " + (y1 + height) + " m\n"); - currentStream.add((startx + width) + " " + (y1 + height) + " l\n"); - currentStream.add("S\n"); + drawLine(startx, y1 + height, startx + width, y1 + height); } bps = (BorderProps)area.getTrait(Trait.BORDER_START); if (bps != null) { @@ -598,11 +602,9 @@ float bwidth = bps.width / 1000f; updateColor(bps.color, false, null); updateLineStyle(bps.style); - currentStream.add(bwidth + " w\n"); + updateLineWidth(bwidth); float x1 = startx + bwidth / 2; - currentStream.add(x1 + " " + starty + " m\n"); - currentStream.add(x1 + " " + (starty + height) + " l\n"); - currentStream.add("S\n"); + drawLine(x1, starty, x1, starty + height); } bps = (BorderProps)area.getTrait(Trait.BORDER_END); if (bps != null) { @@ -611,14 +613,23 @@ float bwidth = bps.width / 1000f; updateColor(bps.color, false, null); updateLineStyle(bps.style); - currentStream.add(bwidth + " w\n"); + updateLineWidth(bwidth); float x1 = startx - bwidth / 2; - currentStream.add((x1 + width) + " " + starty + " m\n"); - currentStream.add((x1 + width) + " " + (starty + height) + " l\n"); - currentStream.add("S\n"); + drawLine(x1 + width, starty, x1 + width, starty + height); } } + /** + * Sets the current line width in points. + * @param width line width in points + */ + private void updateLineWidth(float width) { + if (currentState.setLineWidth(width)) { + //Only write if value has changed WRT the current line width + currentStream.add(width + " w\n"); + } + } + private void updateLineStyle(int style) { switch (style) { case Constants.EN_DASHED: @@ -643,9 +654,8 @@ * @param endy the y end position */ private void drawLine(float startx, float starty, float endx, float endy) { - currentStream.add(startx + " " + starty + " m\n"); - currentStream.add(endx + " " + endy + " l\n"); - currentStream.add("S\n"); + currentStream.add(startx + " " + starty + " m "); + currentStream.add(endx + " " + endy + " l S\n"); } /** @@ -661,15 +671,33 @@ CTM ctm = bv.getCTM(); - if (bv.getPositioning() == Block.ABSOLUTE) { + if (bv.getPositioning() == Block.ABSOLUTE + || bv.getPositioning() == Block.FIXED) { + getLogger().debug("containing position ip=" + containingIPPosition + " bp=" + containingBPPosition); CTM tempctm = new CTM(containingIPPosition, containingBPPosition); ctm = tempctm.multiply(ctm); + getLogger().debug("tempctm=" + tempctm + " ctm=" + ctm); - float x = (float)(bv.getXOffset() + containingIPPosition) / 1000f; - float y = (float)(bv.getYOffset() + containingBPPosition) / 1000f; + float x,y; + x = (float)(bv.getXOffset() + containingIPPosition) / 1000f; + y = (float)(bv.getYOffset() + containingBPPosition) / 1000f; float width = (float)bv.getIPD() / 1000f; float height = (float)bv.getBPD() / 1000f; + getLogger().debug("renderBlockViewport: x=" + x + " y=" + y + " width=" + width + " height=" + height); + + int borderPaddingStart = bv.getBorderAndPaddingWidthStart(); + int borderPaddingBefore = bv.getBorderAndPaddingWidthBefore(); + + Integer spaceStart = (Integer) bv.getTrait(Trait.SPACE_START); + if (spaceStart != null) { + x += spaceStart.floatValue() / 1000; + } + + width += borderPaddingStart / 1000f; + width += bv.getBorderAndPaddingWidthEnd() / 1000f; + height += borderPaddingBefore / 1000f; + height += bv.getBorderAndPaddingWidthAfter() / 1000f; drawBackAndBorders(bv, x, y, width, height); @@ -750,12 +778,7 @@ * @param height the height of the area */ protected void clip(float x, float y, float width, float height) { - currentStream.add(x + " " + y + " m\n"); - currentStream.add((x + width) + " " + y + " l\n"); - currentStream.add((x + width) + " " + (y + height) + " l\n"); - currentStream.add(x + " " + (y + height) + " l\n"); - currentStream.add("h\n"); - currentStream.add("W\n"); + currentStream.add(x + " " + y + " " + width + " " + height + " re W\n"); currentStream.add("n\n"); } @@ -1278,12 +1301,12 @@ float starty = ((currentBPPosition + area.getOffset()) / 1000f); float endx = (currentIPPosition + area.getIPD()) / 1000f; if (!alt) { - currentStream.add(area.getRuleThickness() / 1000f + " w\n"); + updateLineWidth(area.getRuleThickness() / 1000f); drawLine(startx, starty, endx, starty); } else { if (style == EN_DOUBLE) { float third = area.getRuleThickness() / 3000f; - currentStream.add(third + " w\n"); + updateLineWidth(third); drawLine(startx, starty, endx, starty); drawLine(startx, (starty + 2 * third), endx, (starty + 2 * third));
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]