Package org.apache.fop.layoutmgr

Examples of org.apache.fop.layoutmgr.LayoutManager


        getPSLM().addIDToPage(getListBlockFO().getId());

        // the list block contains areas stacked from each list item

        LayoutManager childLM = null;
        LayoutContext lc = new LayoutContext(0);
        LayoutManager firstLM = null;
        LayoutManager lastLM = null;
        Position firstPos = null;
        Position lastPos = null;

        // "unwrap" the NonLeafPositions stored in parentIter
        // and put them in a new list;
View Full Code Here


    }

    /** @see org.apache.fop.layoutmgr.LayoutManager */
    public LinkedList getNextKnuthElements(LayoutContext context, int alignment) {
        InlineLevelLayoutManager curILM;
        LayoutManager curLM, lastLM = null;

        // the list returned by child LM
        LinkedList returnedList;
        KnuthElement returnedElement;

        // the list which will be returned to the parent LM
        LinkedList returnList = new LinkedList();
        KnuthSequence lastSequence = null;

        SpaceSpecifier leadingSpace = context.getLeadingSpace();
       
        alignmentContext = new AlignmentContext(font
                                    , lineHeight.getOptimum(this).getLength().getValue(this)
                                    , alignmentAdjust
                                    , alignmentBaseline
                                    , baselineShift
                                    , dominantBaseline
                                    , context.getAlignmentContext());

        childLC = new LayoutContext(context);
        childLC.setAlignmentContext(alignmentContext);

        if (context.startsNewArea()) {
            // First call to this LM in new parent "area", but this may
            // not be the first area created by this inline
            if (getSpaceStart() != null) {
                context.getLeadingSpace().addSpace(new SpaceVal(getSpaceStart(), this));
            }

            // Check for "fence"
            if (hasLeadingFence(!context.isFirstArea())) {
                // Reset leading space sequence for child areas
                leadingSpace = new SpaceSpecifier(false);
            }
            // Reset state variables
            clearPrevIPD(); // Clear stored prev content dimensions
        }

        StringBuffer trace = new StringBuffer("InlineLM:");

        // We'll add the border to the first inline sequence created.
        // This flag makes sure we do it only once.
        boolean borderAdded = false;

        if (borderProps != null) {
            childLC.setLineStartBorderAndPaddingWidth(context.getLineStartBorderAndPaddingWidth()
                + borderProps.getPaddingStart(true, this)
                + borderProps.getBorderStartWidth(true)
             );
            childLC.setLineEndBorderAndPaddingWidth(context.getLineEndBorderAndPaddingWidth()
                + borderProps.getPaddingEnd(true, this)
                + borderProps.getBorderEndWidth(true)
             );
        }
       
        while ((curLM = (LayoutManager) getChildLM()) != null) {
            if (!(curLM instanceof InlineLevelLayoutManager)) {
                // A block LM
                // Leave room for start/end border and padding
                if (borderProps != null) {
                    childLC.setRefIPD(childLC.getRefIPD()
                            - borderProps.getPaddingStart(lastChildLM != null, this)
                            - borderProps.getBorderStartWidth(lastChildLM != null)
                            - borderProps.getPaddingEnd(hasNextChildLM(), this)
                            - borderProps.getBorderEndWidth(hasNextChildLM()));
                }
            }
            // get KnuthElements from curLM
            returnedList = curLM.getNextKnuthElements(childLC, alignment);
            if (returnedList == null) {
                // curLM returned null because it finished;
                // just iterate once more to see if there is another child
                continue;
            }
View Full Code Here

        // set in the layout context, it must be also set in the
        // layout context given to lastLM, but must be cleared in the
        // layout context given to the other LMs.
        LinkedList positionList = new LinkedList();
        NonLeafPosition pos = null;
        LayoutManager lastLM = null; // last child LM in this iterator
        while (parentIter.hasNext()) {
            pos = (NonLeafPosition) parentIter.next();
            if (pos != null && pos.getPosition() != null) {
                positionList.add(pos.getPosition());
                lastLM = pos.getPosition().getLM();
                lastPos = pos;
            }
        }
        /*if (pos != null) {
            lastLM = pos.getPosition().getLM();
        }*/

        InlineArea parent = createArea(lastLM == null
                                        || lastLM instanceof InlineLevelLayoutManager);
        parent.setBPD(alignmentContext.getHeight());
        if (parent instanceof InlineParent) {
            parent.setOffset(alignmentContext.getOffset());
        } else if (parent instanceof InlineBlockParent) {
            // All inline elements are positioned by the renderers relative to
            // the before edge of their content rectangle
            if (borderProps != null) {
                parent.setOffset(borderProps.getPaddingBefore(false, this)
                                + borderProps.getBorderBeforeWidth(false));
            }
        }
        setCurrentArea(parent);
       
        StackingIter childPosIter
            = new StackingIter(positionList.listIterator());

        LayoutManager prevLM = null;
        LayoutManager childLM;
        while ((childLM = childPosIter.getNextChildLM()) != null) {
            getContext().setFlags(LayoutContext.LAST_AREA,
                                  context.isLastArea() && childLM == lastLM);
            childLM.addAreas(childPosIter, getContext());
            getContext().setLeadingSpace(getContext().getTrailingSpace());
            getContext().setFlags(LayoutContext.RESOLVE_LEADING_SPACE, true);
            prevLM = childLM;
        }

View Full Code Here

     * @param parentIter the iterator of break positions
     * @param context the context for adding areas
     */
    public void addAreas(PositionIterator parentIter,
                         LayoutContext context) {
        LayoutManager childLM;
        LayoutContext lc = new LayoutContext(0);
        lc.setAlignmentContext(alignmentContext);
        int iCurrParIndex;
        while (parentIter.hasNext()) {
            Position pos = (Position) parentIter.next();
            if (pos instanceof LineBreakPosition) {
                ListIterator seqIterator = null;
                KnuthElement tempElement = null;
                // the TLM which created the last KnuthElement in this line
                LayoutManager lastLM = null;
   
                LineBreakPosition lbp = (LineBreakPosition) pos;
                iCurrParIndex = lbp.iParIndex;
                KnuthSequence seq = (KnuthSequence) knuthParagraphs.get(iCurrParIndex);
                int iStartElement = lbp.iStartIndex;
                int iEndElement = lbp.getLeafPos();
   
                LineArea lineArea = new LineArea((lbp.getLeafPos() < seq.size() - 1 ? textAlignment : textAlignmentLast),
                                                 lbp.difference, lbp.availableStretch, lbp.availableShrink);
                lineArea.setStartIndent(lbp.startIndent);
                lineArea.setBPD(lbp.lineHeight);
                lineArea.setIPD(lbp.lineWidth);
                lineArea.addTrait(Trait.SPACE_BEFORE, new Integer(lbp.spaceBefore));
                lineArea.addTrait(Trait.SPACE_AFTER, new Integer(lbp.spaceAfter));
                alignmentContext.resizeLine(lbp.lineHeight, lbp.baseline);

                if (seq instanceof Paragraph) {
                    Paragraph currPar = (Paragraph) seq;
                    // ignore the first elements added by the LineLayoutManager
                    iStartElement += (iStartElement == 0) ? currPar.ignoreAtStart : 0;
                   
                    // if this is the last line area that for this paragraph,
                    // ignore the last elements added by the LineLayoutManager and
                    // subtract the last-line-end-indent from the area ipd
                    if (iEndElement == (currPar.size() - 1)) {
                        iEndElement -= currPar.ignoreAtEnd;
                        lineArea.setIPD(lineArea.getIPD() - lastLineEndIndent.getValue(this));
                    }
                }
               
                // ignore the last element in the line if it is a KnuthGlue object
                seqIterator = seq.listIterator(iEndElement);
                tempElement = (KnuthElement) seqIterator.next();
                if (tempElement.isGlue()) {
                    iEndElement--;
                    // this returns the same KnuthElement
                    seqIterator.previous();
                    tempElement = (KnuthElement) seqIterator.previous();
                }
                lastLM = tempElement.getLayoutManager();
   
                // ignore KnuthGlue and KnuthPenalty objects
                // at the beginning of the line
                seqIterator = seq.listIterator(iStartElement);
                tempElement = (KnuthElement) seqIterator.next();
                while (!tempElement.isBox() && seqIterator.hasNext()) {
                    tempElement = (KnuthElement) seqIterator.next();
                    iStartElement++;
                }
   
                // Add the inline areas to lineArea
                PositionIterator inlinePosIter
                    = new KnuthPossPosIter(seq, iStartElement,
                                           iEndElement + 1);
   
                iStartElement = lbp.getLeafPos() + 1;
                if (iStartElement == seq.size()) {
                    // advance to next paragraph
                    iStartElement = 0;
                }
   
                lc.setSpaceAdjust(lbp.dAdjust);
                lc.setIPDAdjust(lbp.ipdAdjust);
                lc.setLeadingSpace(new SpaceSpecifier(true));
                lc.setTrailingSpace(new SpaceSpecifier(false));
                lc.setFlags(LayoutContext.RESOLVE_LEADING_SPACE, true);

                /* extension (not in the XSL FO recommendation): if the left and right margins
                   have been optimized, recompute indents and / or adjust ratio, according
                   to the paragraph horizontal alignment */
                if (false && textAlignment == EN_JUSTIFY) {
                    // re-compute space adjust ratio
                    int updatedDifference = context.getStackLimit().opt - lbp.lineWidth + lbp.difference;
                    double updatedRatio = 0.0;
                    if (updatedDifference > 0) {
                        updatedRatio = (float) updatedDifference / lbp.availableStretch;
                    } else if (updatedDifference < 0) {
                        updatedRatio = (float) updatedDifference / lbp.availableShrink;
                    }
                    lc.setIPDAdjust(updatedRatio);
                    //log.debug("LLM.addAreas> old difference = " + lbp.difference + " new difference = " + updatedDifference);
                    //log.debug("              old ratio = " + lbp.ipdAdjust + " new ratio = " + updatedRatio);
                } else if (false && textAlignment == EN_CENTER) {
                    // re-compute indent
                    int updatedIndent = lbp.startIndent
                                            + (context.getStackLimit().opt - lbp.lineWidth) / 2;
                    lineArea.setStartIndent(updatedIndent);
                } else if (false && textAlignment == EN_END) {
                    // re-compute indent
                    int updatedIndent = lbp.startIndent
                                            + (context.getStackLimit().opt - lbp.lineWidth);
                    lineArea.setStartIndent(updatedIndent);
                }

                setCurrentArea(lineArea);
                setChildContext(lc);
                while ((childLM = inlinePosIter.getNextChildLM()) != null) {
                    lc.setFlags(LayoutContext.LAST_AREA, (childLM == lastLM));
                    childLM.addAreas(inlinePosIter, lc);
                    lc.setLeadingSpace(lc.getTrailingSpace());
                    lc.setTrailingSpace(new SpaceSpecifier(false));
                }
               
                // when can this be null?
                // if display-align is distribute, add space after
                if (context.getSpaceAfter() > 0
                    && (!context.isLastArea() || parentIter.hasNext())) {
                    lineArea.setBPD(lineArea.getBPD() + context.getSpaceAfter());
                }
                lineArea.finalize();
                parentLM.addChildArea(lineArea);
            } else if (pos instanceof NonLeafPosition) {
                // Nested block-level content;
                // go down the LM stack again;
                // collect all consecutive NonLeafPosition objects,
                // "unwrap" them and put the child positions in a new list.
                LinkedList positionList = new LinkedList();
                Position innerPosition;
                innerPosition = ((NonLeafPosition) pos).getPosition();
                positionList.add(innerPosition);
                while (parentIter.hasNext()) {
                    pos = (Position)parentIter.peekNext();
                    if (!(pos instanceof NonLeafPosition)) {
                        break;
                    }
                    pos = (Position) parentIter.next();
                    innerPosition = ((NonLeafPosition) pos).getPosition();
                    positionList.add(innerPosition);
                }
               
                // do we have the last LM?
                LayoutManager lastLM = null;
                if (!parentIter.hasNext()) {
                    lastLM = innerPosition.getLM();
                }

                // this may be wrong; not all areas belong inside a single line area
View Full Code Here

    }

    /** @see org.apache.fop.layoutmgr.LayoutManager */
    public LinkedList getNextKnuthElements(LayoutContext context, int alignment) {
        InlineLevelLayoutManager curILM;
        LayoutManager curLM, lastLM = null;

        // the list returned by child LM
        LinkedList returnedList;
        KnuthElement returnedElement;

        // the list which will be returned to the parent LM
        LinkedList returnList = new LinkedList();
        KnuthSequence lastSequence = null;

        SpaceSpecifier leadingSpace = context.getLeadingSpace();
       
        alignmentContext = new AlignmentContext(font
                                    , lineHeight.getOptimum(this).getLength().getValue(this)
                                    , alignmentAdjust
                                    , alignmentBaseline
                                    , baselineShift
                                    , dominantBaseline
                                    , context.getAlignmentContext());

        childLC = new LayoutContext(context);
        childLC.setAlignmentContext(alignmentContext);

        if (context.startsNewArea()) {
            // First call to this LM in new parent "area", but this may
            // not be the first area created by this inline
            if (getSpaceStart() != null) {
                context.getLeadingSpace().addSpace(new SpaceVal(getSpaceStart(), this));
            }

            // Check for "fence"
            if (hasLeadingFence(!context.isFirstArea())) {
                // Reset leading space sequence for child areas
                leadingSpace = new SpaceSpecifier(false);
            }
            // Reset state variables
            clearPrevIPD(); // Clear stored prev content dimensions
        }

        StringBuffer trace = new StringBuffer("InlineLM:");

        // We'll add the border to the first inline sequence created.
        // This flag makes sure we do it only once.
        boolean borderAdded = false;

        if (borderProps != null) {
            childLC.setLineStartBorderAndPaddingWidth(context.getLineStartBorderAndPaddingWidth()
                + borderProps.getPaddingStart(true, this)
                + borderProps.getBorderStartWidth(true)
             );
            childLC.setLineEndBorderAndPaddingWidth(context.getLineEndBorderAndPaddingWidth()
                + borderProps.getPaddingEnd(true, this)
                + borderProps.getBorderEndWidth(true)
             );
        }
       
        while ((curLM = (LayoutManager) getChildLM()) != null) {
            if (!(curLM instanceof InlineLevelLayoutManager)) {
                // A block LM
                // Leave room for start/end border and padding
                if (borderProps != null) {
                    childLC.setRefIPD(childLC.getRefIPD()
                            - borderProps.getPaddingStart(lastChildLM != null, this)
                            - borderProps.getBorderStartWidth(lastChildLM != null)
                            - borderProps.getPaddingEnd(hasNextChildLM(), this)
                            - borderProps.getBorderEndWidth(hasNextChildLM()));
                }
            }
            // get KnuthElements from curLM
            returnedList = curLM.getNextKnuthElements(childLC, alignment);
            if (returnedList == null) {
                // curLM returned null because it finished;
                // just iterate once more to see if there is another child
                continue;
            }
View Full Code Here

        // set in the layout context, it must be also set in the
        // layout context given to lastLM, but must be cleared in the
        // layout context given to the other LMs.
        LinkedList positionList = new LinkedList();
        NonLeafPosition pos = null;
        LayoutManager lastLM = null; // last child LM in this iterator
        while (parentIter.hasNext()) {
            pos = (NonLeafPosition) parentIter.next();
            if (pos.getPosition() != null) {
                positionList.add(pos.getPosition());
                lastLM = pos.getPosition().getLM();
                lastPos = pos;
            }
        }
        /*if (pos != null) {
            lastLM = pos.getPosition().getLM();
        }*/

        InlineArea parent = createArea(lastLM == null
                                        || lastLM instanceof InlineLevelLayoutManager);
        parent.setBPD(alignmentContext.getHeight());
        if (parent instanceof InlineParent) {
            parent.setOffset(alignmentContext.getOffset());
        } else if (parent instanceof InlineBlockParent) {
            // All inline elements are positioned by the renderers relative to
            // the before edge of their content rectangle
            if (borderProps != null) {
                parent.setOffset(borderProps.getPaddingBefore(false, this)
                                + borderProps.getBorderBeforeWidth(false));
            }
        }
        setCurrentArea(parent);
       
        StackingIter childPosIter
            = new StackingIter(positionList.listIterator());

        LayoutManager prevLM = null;
        LayoutManager childLM;
        while ((childLM = childPosIter.getNextChildLM()) != null) {
            getContext().setFlags(LayoutContext.LAST_AREA,
                                  context.isLastArea() && childLM == lastLM);
            childLM.addAreas(childPosIter, getContext());
            getContext().setLeadingSpace(getContext().getTrailingSpace());
            getContext().setFlags(LayoutContext.RESOLVE_LEADING_SPACE, true);
            prevLM = childLM;
        }

View Full Code Here

        if (newLMs == null || newLMs.size() == 0) {
            return;
        }
        ListIterator iter = newLMs.listIterator();
        while (iter.hasNext()) {
            LayoutManager lm = (LayoutManager) iter.next();
            addChildLM(lm);
        }
    }
View Full Code Here

     * @param parentIter the iterator of break positions
     * @param context the context for adding areas
     */
    public void addAreas(PositionIterator parentIter,
                         LayoutContext context) {
        LayoutManager childLM;
        LayoutContext lc = new LayoutContext(0);
        lc.setAlignmentContext(alignmentContext);
        int iCurrParIndex;
        while (parentIter.hasNext()) {
            Position pos = (Position) parentIter.next();
            if (pos instanceof LineBreakPosition) {
                ListIterator seqIterator = null;
                KnuthElement tempElement = null;
                // the TLM which created the last KnuthElement in this line
                LayoutManager lastLM = null;
   
                LineBreakPosition lbp = (LineBreakPosition) pos;
                iCurrParIndex = lbp.iParIndex;
                KnuthSequence seq = (KnuthSequence) knuthParagraphs.get(iCurrParIndex);
                iEndElement = lbp.getLeafPos();
   
                LineArea lineArea = new LineArea((lbp.getLeafPos() < seq.size() - 1 ? textAlignment : textAlignmentLast),
                                                 lbp.difference, lbp.availableStretch, lbp.availableShrink);
                lineArea.setStartIndent(lbp.startIndent);
                lineArea.setBPD(lbp.lineHeight);
                lineArea.setIPD(lbp.lineWidth);
                lineArea.addTrait(Trait.SPACE_BEFORE, new Integer(lbp.spaceBefore));
                lineArea.addTrait(Trait.SPACE_AFTER, new Integer(lbp.spaceAfter));
                alignmentContext.resizeLine(lbp.lineHeight, lbp.baseline);

                if (seq instanceof Paragraph) {
                    Paragraph currPar = (Paragraph) seq;
                    // ignore the first elements added by the LineLayoutManager
                    iStartElement += (iStartElement == 0) ? currPar.ignoreAtStart : 0;
                   
                    // if this is the last line area that for this paragraph,
                    // ignore the last elements added by the LineLayoutManager and
                    // subtract the last-line-end-indent from the area ipd
                    if (iEndElement == (currPar.size() - 1)) {
                        iEndElement -= currPar.ignoreAtEnd;
                        lineArea.setIPD(lineArea.getIPD() - lastLineEndIndent.getValue(this));
                    }
                }
               
                // ignore the last element in the line if it is a KnuthGlue object
                seqIterator = seq.listIterator(iEndElement);
                tempElement = (KnuthElement) seqIterator.next();
                if (tempElement.isGlue()) {
                    iEndElement--;
                    // this returns the same KnuthElement
                    seqIterator.previous();
                    tempElement = (KnuthElement) seqIterator.previous();
                }
                lastLM = tempElement.getLayoutManager();
   
                // ignore KnuthGlue and KnuthPenalty objects
                // at the beginning of the line
                seqIterator = seq.listIterator(iStartElement);
                tempElement = (KnuthElement) seqIterator.next();
                while (!tempElement.isBox() && seqIterator.hasNext()) {
                    tempElement = (KnuthElement) seqIterator.next();
                    iStartElement++;
                }
   
                // Add the inline areas to lineArea
                PositionIterator inlinePosIter
                    = new KnuthPossPosIter(seq, iStartElement,
                                           iEndElement + 1);
   
                iStartElement = lbp.getLeafPos() + 1;
                if (iStartElement == seq.size()) {
                    // advance to next paragraph
                    iStartElement = 0;
                }
   
                lc.setSpaceAdjust(lbp.dAdjust);
                lc.setIPDAdjust(lbp.ipdAdjust);
                lc.setLeadingSpace(new SpaceSpecifier(true));
                lc.setTrailingSpace(new SpaceSpecifier(false));
                lc.setFlags(LayoutContext.RESOLVE_LEADING_SPACE, true);

                /* extension (not in the XSL FO recommendation): if the left and right margins
                   have been optimized, recompute indents and / or adjust ratio, according
                   to the paragraph horizontal alignment */
                if (false && textAlignment == EN_JUSTIFY) {
                    // re-compute space adjust ratio
                    int updatedDifference = context.getStackLimit().opt - lbp.lineWidth + lbp.difference;
                    double updatedRatio = 0.0;
                    if (updatedDifference > 0) {
                        updatedRatio = (float) updatedDifference / lbp.availableStretch;
                    } else if (updatedDifference < 0) {
                        updatedRatio = (float) updatedDifference / lbp.availableShrink;
                    }
                    lc.setIPDAdjust(updatedRatio);
                    //log.debug("LLM.addAreas> old difference = " + lbp.difference + " new difference = " + updatedDifference);
                    //log.debug("              old ratio = " + lbp.ipdAdjust + " new ratio = " + updatedRatio);
                } else if (false && textAlignment == EN_CENTER) {
                    // re-compute indent
                    int updatedIndent = lbp.startIndent
                                            + (context.getStackLimit().opt - lbp.lineWidth) / 2;
                    lineArea.setStartIndent(updatedIndent);
                } else if (false && textAlignment == EN_END) {
                    // re-compute indent
                    int updatedIndent = lbp.startIndent
                                            + (context.getStackLimit().opt - lbp.lineWidth);
                    lineArea.setStartIndent(updatedIndent);
                }

                setCurrentArea(lineArea);
                setChildContext(lc);
                while ((childLM = inlinePosIter.getNextChildLM()) != null) {
                    lc.setFlags(LayoutContext.LAST_AREA, (childLM == lastLM));
                    childLM.addAreas(inlinePosIter, lc);
                    lc.setLeadingSpace(lc.getTrailingSpace());
                    lc.setTrailingSpace(new SpaceSpecifier(false));
                }
               
                // when can this be null?
                // if display-align is distribute, add space after
                if (context.getSpaceAfter() > 0
                    && (!context.isLastArea() || parentIter.hasNext())) {
                    lineArea.setBPD(lineArea.getBPD() + context.getSpaceAfter());
                }
                lineArea.finalize();
                parentLM.addChildArea(lineArea);
            } else if (pos instanceof NonLeafPosition) {
                // Nested block-level content;
                // go down the LM stack again;
                // collect all consecutive NonLeafPosition objects,
                // "unwrap" them and put the child positions in a new list.
                LinkedList positionList = new LinkedList();
                Position innerPosition;
                innerPosition = ((NonLeafPosition) pos).getPosition();
                positionList.add(innerPosition);
                while (parentIter.hasNext()) {
                    pos = (Position)parentIter.peekNext();
                    if (!(pos instanceof NonLeafPosition)) {
                        break;
                    }
                    pos = (Position) parentIter.next();
                    innerPosition = ((NonLeafPosition) pos).getPosition();
                    positionList.add(innerPosition);
                }
               
                // do we have the last LM?
                LayoutManager lastLM = null;
                if (!parentIter.hasNext()) {
                    lastLM = innerPosition.getLM();
                }

                // this may be wrong; not all areas belong inside a single line area
View Full Code Here

        getPSLM().addIDToPage(getListBlockFO().getId());

        // the list block contains areas stacked from each list item

        LayoutManager childLM = null;
        LayoutContext lc = new LayoutContext(0);
        LayoutManager firstLM = null;
        LayoutManager lastLM = null;
        Position firstPos = null;
        Position lastPos = null;

        // "unwrap" the NonLeafPositions stored in parentIter
        // and put them in a new list;
View Full Code Here

TOP

Related Classes of org.apache.fop.layoutmgr.LayoutManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.