Package org.apache.fop.layoutmgr

Examples of org.apache.fop.layoutmgr.KnuthElement


                nextIsBox = ((KnuthElement) iter.next()).isBox();
            }
            int len = 0;
            if (((KnuthElement) iter.previous()).isBox()) {
                while (iter.nextIndex() < endIndex) {
                    KnuthElement el = (KnuthElement) iter.next();
                    if (el.isBox() || el.isGlue()) {
                        len += el.getWidth();
                    }
                }
                len += ActiveCell.getElementContentLength((KnuthElement) iter.next());
            }
            return len;
View Full Code Here


        if (((KnuthElement) returnList.get(0)).isForcedBreak()) {
            primaryGridUnit.setBreakBefore(((KnuthPenalty) returnList.get(0)).getBreakClass());
            returnList.remove(0);
            assert !returnList.isEmpty();
        }
        final KnuthElement lastItem = (KnuthElement) ListUtil
                .getLast(returnList);
        if (lastItem.isForcedBreak()) {
            KnuthPenalty p = (KnuthPenalty) lastItem;
            primaryGridUnit.setBreakAfter(p.getBreakClass());
            p.setPenalty(0);
        }
View Full Code Here

    /** {@inheritDoc} */
    public List addALetterSpaceTo(List oldList) {
        // old list contains only a box, or the sequence: box penalty glue box

        ListIterator oldListIterator = oldList.listIterator();
        KnuthElement element = null;
        // "unwrap" the Position stored in each element of oldList
        while (oldListIterator.hasNext()) {
            element = (KnuthElement) oldListIterator.next();
            element.setPosition(element.getPosition().getPosition());
        }

        // The last element may not have a layout manager (its position == null);
        // this may happen if it is a padding box; see bug 39571.
        InlineLevelLayoutManager LM =
            (InlineLevelLayoutManager) element.getLayoutManager();
        if (LM != null) {
            oldList = LM.addALetterSpaceTo(oldList);
        }
        // "wrap" again the Position stored in each element of oldList
        oldListIterator = oldList.listIterator();
        while (oldListIterator.hasNext()) {
            element = (KnuthElement) oldListIterator.next();
            element.setPosition(notifyPos(new NonLeafPosition(this, element.getPosition())));
        }

        return oldList;
    }
View Full Code Here

     *
     * @param oldList the elements representing the word space
     */
    public void removeWordSpace(List oldList) {
        ListIterator oldListIterator = oldList.listIterator();
        KnuthElement element = null;
        // "unwrap" the Position stored in each element of oldList
        while (oldListIterator.hasNext()) {
            element = (KnuthElement) oldListIterator.next();
            element.setPosition(element.getPosition().getPosition());
        }

        ((InlineLevelLayoutManager)
                   element.getLayoutManager()).removeWordSpace(oldList);

    }
View Full Code Here

    /** {@inheritDoc} */
    public boolean applyChanges(List oldList) {
        // "unwrap" the Positions stored in the elements
        ListIterator oldListIterator = oldList.listIterator();
        KnuthElement oldElement;
        while (oldListIterator.hasNext()) {
            oldElement = (KnuthElement) oldListIterator.next();
            oldElement.setPosition
                (oldElement.getPosition().getPosition());
        }
        // reset the iterator
        oldListIterator = oldList.listIterator();

        InlineLevelLayoutManager prevLM = null;
        InlineLevelLayoutManager currLM;
        int fromIndex = 0;

        boolean bSomethingChanged = false;
        while (oldListIterator.hasNext()) {
            oldElement = (KnuthElement) oldListIterator.next();
            currLM = (InlineLevelLayoutManager) oldElement.getLayoutManager();
            // initialize prevLM
            if (prevLM == null) {
                prevLM = currLM;
            }

            if (currLM != prevLM || !oldListIterator.hasNext()) {
                if (prevLM == this || currLM == this) {
                    prevLM = currLM;
                } else if (oldListIterator.hasNext()) {
                    bSomethingChanged
                        = prevLM.applyChanges(oldList.subList(fromIndex
                                                              , oldListIterator.previousIndex()))
                        || bSomethingChanged;
                    prevLM = currLM;
                    fromIndex = oldListIterator.previousIndex();
                } else if (currLM == prevLM) {
                    bSomethingChanged
                        = (prevLM != null)
                            && prevLM.applyChanges(oldList.subList(fromIndex, oldList.size()))
                            || bSomethingChanged;
                } else {
                    bSomethingChanged
                        = prevLM.applyChanges(oldList.subList(fromIndex
                                                              , oldListIterator.previousIndex()))
                            || bSomethingChanged;
                    if (currLM != null) {
                        bSomethingChanged
                            = currLM.applyChanges(oldList.subList(oldListIterator.previousIndex()
                                                                  , oldList.size()))
                            || bSomethingChanged;
                    }
                }
            }
        }

        // "wrap" again the Positions stored in the elements
        oldListIterator = oldList.listIterator();
        while (oldListIterator.hasNext()) {
            oldElement = (KnuthElement) oldListIterator.next();
            oldElement.setPosition
                (notifyPos(new NonLeafPosition(this, oldElement.getPosition())));
        }
        return bSomethingChanged;
    }
View Full Code Here

     * {@inheritDoc}
     */
    public List getChangedKnuthElements(List oldList, int alignment) {
        // "unwrap" the Positions stored in the elements
        ListIterator oldListIterator = oldList.listIterator();
        KnuthElement oldElement;
        while (oldListIterator.hasNext()) {
            oldElement = (KnuthElement) oldListIterator.next();
            oldElement.setPosition
                (oldElement.getPosition().getPosition());
        }
        // reset the iterator
        oldListIterator = oldList.listIterator();

        KnuthElement returnedElement;
        LinkedList returnedList = new LinkedList();
        LinkedList returnList = new LinkedList();
        InlineLevelLayoutManager prevLM = null;
        InlineLevelLayoutManager currLM;
        int fromIndex = 0;

        while (oldListIterator.hasNext()) {
            oldElement = (KnuthElement) oldListIterator.next();
            currLM = (InlineLevelLayoutManager) oldElement.getLayoutManager();
            if (prevLM == null) {
                prevLM = currLM;
            }

            if (currLM != prevLM || !oldListIterator.hasNext()) {
                if (oldListIterator.hasNext()) {
                    returnedList.addAll
                        (prevLM.getChangedKnuthElements
                         (oldList.subList(fromIndex,
                                          oldListIterator.previousIndex()),
                          /*flaggedPenalty,*/ alignment));
                    prevLM = currLM;
                    fromIndex = oldListIterator.previousIndex();
                } else if (currLM == prevLM) {
                    returnedList.addAll
                        (prevLM.getChangedKnuthElements
                         (oldList.subList(fromIndex, oldList.size()),
                          /*flaggedPenalty,*/ alignment));
                } else {
                    returnedList.addAll
                        (prevLM.getChangedKnuthElements
                         (oldList.subList(fromIndex,
                                          oldListIterator.previousIndex()),
                          /*flaggedPenalty,*/ alignment));
                    if (currLM != null) {
                        returnedList.addAll
                            (currLM.getChangedKnuthElements
                             (oldList.subList(oldListIterator.previousIndex(),
                                              oldList.size()),
                              /*flaggedPenalty,*/ alignment));
                    }
                }
            }
        }

        // "wrap" the Position stored in each element of returnedList
        ListIterator listIter = returnedList.listIterator();
        while (listIter.hasNext()) {
            returnedElement = (KnuthElement) listIter.next();
            returnedElement.setPosition
                (notifyPos(new NonLeafPosition(this, returnedElement.getPosition())));
            returnList.add(returnedElement);
        }
        return returnList;
    }
View Full Code Here

    public List addALetterSpaceTo(final List oldList) {
        // old list contains only a box, or the sequence: box penalty glue box;
        // look at the Position stored in the first element in oldList
        // which is always a box
        ListIterator oldListIterator = oldList.listIterator();
        KnuthElement knuthElement = (KnuthElement) oldListIterator.next();
        LeafPosition pos = (LeafPosition) ((KnuthBox) knuthElement).getPosition();
        int index = pos.getLeafPos();
        //element could refer to '-1' position, for non-collapsed spaces (?)
        if (index > -1) {
            AreaInfo areaInfo = getAreaInfo(index);
View Full Code Here

            // alignment is either center, start or end:
            // the first two elements does not store the needed Position
            oldListIterator.next();
            oldListIterator.next();
        }
        KnuthElement knuthElement = (KnuthElement) oldListIterator.next();
        int leafValue = ((LeafPosition) knuthElement.getPosition()).getLeafPos();
        // only the last word space can be a trailing space!
        if (leafValue == areaInfos.size() - 1) {
            areaInfos.remove(leafValue);
        } else {
            TextLayoutManager.LOG.error("trying to remove a non-trailing word space");
View Full Code Here

        for (int i = 0; i < children.getLength(); i++) {
            Node node = children.item(i);
            if (node instanceof Element) {
                pos++;
                Element domEl = (Element)node;
                KnuthElement knuthEl = (KnuthElement)elementList.getElementList().get(pos);
                if ("skip".equals(domEl.getLocalName())) {
                    pos += Integer.parseInt(getElementText(domEl)) - 1;
                } else if ("box".equals(domEl.getLocalName())) {
                    if (!(knuthEl instanceof KnuthBox)) {
                        fail("Expected KnuthBox"
                                + " at position " + pos
                                + " but got: " + knuthEl.getClass().getName());
                    }
                    if (domEl.getAttribute("w").length() > 0) {
                        int w = Integer.parseInt(domEl.getAttribute("w"));
                        if (w != knuthEl.getWidth()) {
                            fail("Expected w=" + w
                                    + " at position " + pos
                                    + " but got: " + knuthEl.getWidth());
                        }
                    }
                    if ("true".equals(domEl.getAttribute("aux"))) {
                        if (!knuthEl.isAuxiliary()) {
                            fail("Expected auxiliary box"
                                    + " at position " + pos);
                        }
                    }
                    if ("false".equals(domEl.getAttribute("aux"))) {
                        if (knuthEl.isAuxiliary()) {
                            fail("Expected a normal, not an auxiliary box"
                                    + " at position " + pos);
                        }
                    }
                } else if ("penalty".equals(domEl.getLocalName())) {
                    if (!(knuthEl instanceof KnuthPenalty)) {
                        fail("Expected KnuthPenalty "
                                + " at position " + pos
                                + " but got: " + knuthEl.getClass().getName());
                    }
                    KnuthPenalty pen = (KnuthPenalty)knuthEl;
                    if (domEl.getAttribute("w").length() > 0) {
                        int w = Integer.parseInt(domEl.getAttribute("w"));
                        if (w != knuthEl.getWidth()) {
                            fail("Expected w=" + w
                                    + " at position " + pos
                                    + " but got: " + knuthEl.getWidth());
                        }
                    }
                    if (domEl.getAttribute("p").length() > 0) {
                        if ("<0".equals(domEl.getAttribute("p"))) {
                            if (knuthEl.getPenalty() >= 0) {
                                fail("Expected p<0"
                                        + " at position " + pos
                                        + " but got: " + knuthEl.getPenalty());
                            }
                        } else if (">0".equals(domEl.getAttribute("p"))) {
                            if (knuthEl.getPenalty() <= 0) {
                                fail("Expected p>0"
                                        + " at position " + pos
                                        + " but got: " + knuthEl.getPenalty());
                            }
                        } else {
                            int p;
                            if ("INF".equalsIgnoreCase(domEl.getAttribute("p"))) {
                                p = KnuthPenalty.INFINITE;
                            } else if ("INFINITE".equalsIgnoreCase(domEl.getAttribute("p"))) {
                                p = KnuthPenalty.INFINITE;
                            } else if ("-INF".equalsIgnoreCase(domEl.getAttribute("p"))) {
                                p = -KnuthPenalty.INFINITE;
                            } else if ("-INFINITE".equalsIgnoreCase(domEl.getAttribute("p"))) {
                                p = -KnuthPenalty.INFINITE;
                            } else {
                                p = Integer.parseInt(domEl.getAttribute("p"));
                            }
                            if (p != knuthEl.getPenalty()) {
                                fail("Expected p=" + p
                                        + " at position " + pos
                                        + " but got: " + knuthEl.getPenalty());
                            }
                        }
                    }
                    if ("true".equals(domEl.getAttribute("flagged"))) {
                        if (!pen.isPenaltyFlagged()) {
                            fail("Expected flagged penalty"
                                    + " at position " + pos);
                        }
                    } else if ("false".equals(domEl.getAttribute("flagged"))) {
                        if (pen.isPenaltyFlagged()) {
                            fail("Expected non-flagged penalty"
                                    + " at position " + pos);
                        }
                    }
                    if ("true".equals(domEl.getAttribute("aux"))) {
                        if (!pen.isAuxiliary()) {
                            fail("Expected auxiliary penalty"
                                    + " at position " + pos);
                        }
                    } else if ("false".equals(domEl.getAttribute("aux"))) {
                        if (pen.isAuxiliary()) {
                            fail("Expected non-auxiliary penalty"
                                    + " at position " + pos);
                        }
                    }
                } else if ("glue".equals(domEl.getLocalName())) {
                    if (!(knuthEl instanceof KnuthGlue)) {
                        fail("Expected KnuthGlue"
                                + " at position " + pos
                                + " but got: " + knuthEl.getClass().getName());
                    }
                    KnuthGlue glue = (KnuthGlue)knuthEl;
                    if (domEl.getAttribute("w").length() > 0) {
                        int w = Integer.parseInt(domEl.getAttribute("w"));
                        if (w != knuthEl.getWidth()) {
                            fail("Expected w=" + w
                                    + " at position " + pos
                                    + " but got: " + knuthEl.getWidth());
                        }
                    }
                    if (domEl.getAttribute("y").length() > 0) {
                        int stretch = Integer.parseInt(domEl.getAttribute("y"));
                        if (stretch != knuthEl.getStretch()) {
                            fail("Expected y=" + stretch
                                    + " (stretch) at position " + pos
                                    + " but got: " + knuthEl.getStretch());
                        }
                    }
                    if (domEl.getAttribute("z").length() > 0) {
                        int shrink = Integer.parseInt(domEl.getAttribute("z"));
                        if (shrink != knuthEl.getShrink()) {
                            fail("Expected z=" + shrink
                                    + " (shrink) at position " + pos
                                    + " but got: " + knuthEl.getShrink());
                        }
                    }
                } else {
                    throw new IllegalArgumentException("Invalid child node for 'element-list': "
                            + domEl.getLocalName()
View Full Code Here

    public List addALetterSpaceTo(final List oldList, int depth) {
        // old list contains only a box, or the sequence: box penalty glue box;
        // look at the Position stored in the first element in oldList
        // which is always a box
        ListIterator oldListIterator = oldList.listIterator();
        KnuthElement knuthElement = (KnuthElement) oldListIterator.next();
        Position pos = knuthElement.getPosition();
        LeafPosition leafPos = (LeafPosition) pos.getPosition(depth);
        int index = leafPos.getLeafPos();
        //element could refer to '-1' position, for non-collapsed spaces (?)
        if (index > -1) {
            AreaInfo areaInfo = getAreaInfo(index);
View Full Code Here

TOP

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

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.