Package org.apache.fop.traits

Examples of org.apache.fop.traits.MinOptMax


        }
        return sum;
    }
   
    private void generate(ListIterator iter) {
        MinOptMax noBreakLength = new MinOptMax();
        MinOptMax glue1; //space before break possibility if break occurs
        //MinOptMax glue2; //difference between glue 1 and 3 when no break occurs
        MinOptMax glue3; //space after break possibility if break occurs
        glue1 = sum(firstPartLengths);
        glue3 = sum(secondPartLengths);
        noBreakLength = sum(noBreakLengths);
       
        //This doesn't produce the right glue2
        //glue2 = new MinOptMax(noBreakLength);
        //glue2.subtract(glue1);
        //glue2.subtract(glue3);
       
        int glue2w = noBreakLength.opt - glue1.opt - glue3.opt;
        int glue2stretch = (noBreakLength.max - noBreakLength.opt);
        int glue2shrink = (noBreakLength.opt - noBreakLength.min);
        glue2stretch -= glue1.max - glue1.opt;
        glue2stretch -= glue3.max - glue3.opt;
        glue2shrink -= glue1.opt - glue1.min;
        glue2shrink -= glue3.opt - glue3.min;
       
        boolean hasPrecedingNonBlock = false;
        if (log.isDebugEnabled()) {
            log.debug("noBreakLength=" + noBreakLength
                    + ", glue1=" + glue1
                    + ", glue2=" + glue2w + "+" + glue2stretch + "-" + glue2shrink
                    + ", glue3=" + glue3);
        }
        if (breakPoss != null) {
            boolean forcedBreak = breakPoss.isForcedBreak();
            if (glue1.isNonZero()) {
                iter.add(new KnuthPenalty(0, KnuthPenalty.INFINITE,
                        false, (Position)null, true));
                iter.add(new KnuthGlue(glue1.opt, glue1.max - glue1.opt, glue1.opt - glue1.min,
                        (Position)null, true));
                if (forcedBreak) {
                    //Otherwise, the preceding penalty and glue will be cut off
                    iter.add(new KnuthBox(0, (Position)null, true));
                }
            }
            iter.add(new KnuthPenalty(breakPoss.getPenaltyWidth(), breakPoss.getPenaltyValue(),
                    false, breakPoss.getBreakClass(),
                    new SpaceHandlingBreakPosition(this, breakPoss), false));
            if (breakPoss.getPenaltyValue() <= -KnuthPenalty.INFINITE) {
                return; //return early. Not necessary (even wrong) to add additional elements
            }
            if (glue2w != 0 || glue2stretch != 0 || glue2shrink != 0) {
                iter.add(new KnuthGlue(glue2w, glue2stretch, glue2shrink,
                        (Position)null, true));
            }
        } else {
            if (glue1.isNonZero()) {
                throw new IllegalStateException("glue1 should be 0 in this case");
            }
        }
        Position pos = null;
        if (breakPoss == null) {
            pos = new SpaceHandlingPosition(this);
        }
        if (glue3.isNonZero() || pos != null) {
            iter.add(new KnuthBox(0, pos, true));
        }
        if (glue3.isNonZero()) {
            iter.add(new KnuthPenalty(0, KnuthPenalty.INFINITE,
                    false, (Position)null, true));
            iter.add(new KnuthGlue(glue3.opt, glue3.max - glue3.opt, glue3.opt - glue3.min,
                    (Position)null, true));
            hasPrecedingNonBlock = true;
View Full Code Here


            performSpaceResolutionRules2to3(secondPart, secondPartLengths);
        }
    }

    private MinOptMax sum(MinOptMax[] lengths) {
        MinOptMax sum = MinOptMax.ZERO;
        for (int i = 0; i < lengths.length; i++) {
            if (lengths[i] != null) {
                sum = sum.plus(lengths[i]);
            }
        }
        return sum;
    }
View Full Code Here

        }
        return sum;
    }

    private void generate(ListIterator iter) {
        MinOptMax spaceBeforeBreak = sum(firstPartLengths);
        MinOptMax spaceAfterBreak = sum(secondPartLengths);

        boolean hasPrecedingNonBlock = false;
        if (breakPoss != null) {
            if (spaceBeforeBreak.isNonZero()) {
                iter.add(new KnuthPenalty(0, KnuthPenalty.INFINITE, false, null, true));
                iter.add(new KnuthGlue(spaceBeforeBreak, null, true));
                if (breakPoss.isForcedBreak()) {
                    //Otherwise, the preceding penalty and glue will be cut off
                    iter.add(new KnuthBox(0, null, true));
                }
            }
            iter.add(new KnuthPenalty(breakPoss.getPenaltyWidth(), breakPoss.getPenaltyValue(),
                    false, breakPoss.getBreakClass(),
                    new SpaceHandlingBreakPosition(this, breakPoss), false));
            if (breakPoss.getPenaltyValue() <= -KnuthPenalty.INFINITE) {
                return; //return early. Not necessary (even wrong) to add additional elements
            }

            // No break
            // TODO: We can't use a MinOptMax for glue2, because min <= opt <= max is not always true - why?
            MinOptMax noBreakLength = sum(noBreakLengths);
            MinOptMax spaceSum = spaceBeforeBreak.plus(spaceAfterBreak);
            int glue2width = noBreakLength.getOpt() - spaceSum.getOpt();
            int glue2stretch = noBreakLength.getStretch() - spaceSum.getStretch();
            int glue2shrink = noBreakLength.getShrink() - spaceSum.getShrink();

            if (glue2width != 0 || glue2stretch != 0 || glue2shrink != 0) {
                iter.add(new KnuthGlue(glue2width, glue2stretch, glue2shrink, null, true));
            }
        } else {
View Full Code Here

    /**
     * {@inheritDoc}
     */
    public List getNextKnuthElements(LayoutContext context, int alignment) {
        MinOptMax stackLimit = context.getStackLimitBP();

        referenceIPD = context.getRefIPD();
        cellIPD = referenceIPD;
        cellIPD -= getIPIndents();

View Full Code Here

        AreaInfo areaInfo;
        int wordSpaceCount = 0;
        int letterSpaceCount = 0;
        int firstAreaInfoIndex = -1;
        int lastAreaInfoIndex = 0;
        MinOptMax realWidth = MinOptMax.ZERO;

        /* On first area created, add any leading space.
         * Calculate word-space stretch value.
         */
        AreaInfo lastAreaInfo = null;
        while (posIter.hasNext()) {
            final LeafPosition tbpNext = (LeafPosition) posIter.next();
            if (tbpNext == null) {
                continue; //Ignore elements without Positions
            }
            if (tbpNext.getLeafPos() != -1) {
                areaInfo = (AreaInfo) areaInfos.get(tbpNext.getLeafPos());
                if (lastAreaInfo == null || areaInfo.font != lastAreaInfo.font) {
                    if (lastAreaInfo != null) {
                        addAreaInfoAreas(lastAreaInfo, wordSpaceCount,
                                letterSpaceCount, firstAreaInfoIndex,
                                lastAreaInfoIndex, realWidth, context);
                    }
                    firstAreaInfoIndex = tbpNext.getLeafPos();
                    wordSpaceCount = 0;
                    letterSpaceCount = 0;
                    realWidth = MinOptMax.ZERO;
                }
                wordSpaceCount += areaInfo.wordSpaceCount;
                letterSpaceCount += areaInfo.letterSpaceCount;
                realWidth = realWidth.plus(areaInfo.areaIPD);
                lastAreaInfoIndex = tbpNext.getLeafPos();
                lastAreaInfo = areaInfo;
            }
        }
        if (lastAreaInfo != null) {
View Full Code Here

            realWidth = realWidth.minus(letterSpaceIPD);
            letterSpaceCount--;
        }

        for (int i = areaInfo.startIndex; i < areaInfo.breakIndex; i++) {
            MinOptMax letterAdjustment = letterAdjustArray[i + 1];
            if (letterAdjustment != null && letterAdjustment.isElastic()) {
                letterSpaceCount++;
            }
        }

        // add hyphenation character if the last word is hyphenated
View Full Code Here

                        breakOpportunity, spaceFont);
                thisStart = nextStart + 1;
            } else if (CharUtilities.isFixedWidthSpace(ch) || CharUtilities.isZeroWidthSpace(ch)) {
                // create the AreaInfo object
                Font font = FontSelector.selectFontForCharacterInText(ch, foText, this);
                MinOptMax ipd = MinOptMax.getInstance(font.getCharWidth(ch));
                areaInfo = new AreaInfo(nextStart, nextStart + 1, 0, 0, ipd, false, true,
                        breakOpportunity, font);
                thisStart = nextStart + 1;
            } else if (CharUtilities.isExplicitBreak(ch)) {
                //mandatory break-character: only advance index
View Full Code Here

        final boolean endsWithHyphen = checkEndsWithHyphen
                && foText.charAt(lastIndex) == CharUtilities.SOFT_HYPHEN;
        Font font = FontSelector.selectFontForCharactersInText(foText, thisStart, lastIndex, foText, this);
        int wordLength = lastIndex - thisStart;
        boolean kerning = font.hasKerning();
        MinOptMax wordIPD = MinOptMax.ZERO;
        for (int i = thisStart; i < lastIndex; i++) {
            char currentChar = foText.charAt(i);

            //character width
            int charWidth = font.getCharWidth(currentChar);
            wordIPD = wordIPD.plus(charWidth);

            //kerning
            if (kerning) {
                int kern = 0;
                if (i > thisStart) {
                    char previousChar = foText.charAt(i - 1);
                    kern = font.getKernValue(previousChar, currentChar);
                } else if (prevAreaInfo != null && !prevAreaInfo.isSpace && prevAreaInfo.breakIndex > 0) {
                    char previousChar = foText.charAt(prevAreaInfo.breakIndex - 1);
                    kern = font.getKernValue(previousChar, currentChar);
                }
                if (kern != 0) {
                    addToLetterAdjust(i, kern);
                    wordIPD = wordIPD.plus(kern);
                }
            }
        }
        if (kerning
                && breakOpportunity
                && !TextLayoutManager.isSpace(ch)
                && lastIndex > 0
                && endsWithHyphen) {
            final int kern = font.getKernValue(foText.charAt(lastIndex - 1), ch);
            if (kern != 0) {
                addToLetterAdjust(lastIndex, kern);
                //TODO: add kern to wordIPD?
            }
        }
        int iLetterSpaces = wordLength - 1;
        // if there is a break opportunity and the next one
        // is not a space, it could be used as a line end;
        // add one more letter space, in case other text follows
        if (breakOpportunity && !TextLayoutManager.isSpace(ch)) {
            iLetterSpaces++;
        }
        assert iLetterSpaces >= 0;
        wordIPD = wordIPD.plus(letterSpaceIPD.mult(iLetterSpaces));

        // create the AreaInfo object
        AreaInfo areaInfo = new AreaInfo(thisStart, lastIndex, 0,
                iLetterSpaces, wordIPD,
                endsWithHyphen,
View Full Code Here

        int stopIndex;
        boolean nothingChanged = true;
        Font font = areaInfo.font;

        while (startIndex < areaInfo.breakIndex) {
            MinOptMax newIPD = MinOptMax.ZERO;
            boolean hyphenFollows;

            stopIndex = startIndex + hyphContext.getNextHyphPoint();
            if (hyphContext.hasMoreHyphPoints() && stopIndex <= areaInfo.breakIndex) {
                // stopIndex is the index of the first character
                // after a hyphenation point
                hyphenFollows = true;
            } else {
                // there are no more hyphenation points,
                // or the next one is after areaInfo.breakIndex
                hyphenFollows = false;
                stopIndex = areaInfo.breakIndex;
            }

            hyphContext.updateOffset(stopIndex - startIndex);

            //log.info("Word: " + new String(textArray, startIndex, stopIndex - startIndex));
            for (int i = startIndex; i < stopIndex; i++) {
                char ch = foText.charAt(i);
                newIPD = newIPD.plus(font.getCharWidth(ch));
                //if (i > startIndex) {
                if (i < stopIndex) {
                    MinOptMax letterAdjust = letterAdjustArray[i + 1];
                    if (i == stopIndex - 1 && hyphenFollows) {
                        //the letter adjust here needs to be handled further down during
                        //element generation because it depends on hyph/no-hyph condition
                        letterAdjust = null;
                    }
View Full Code Here

        }

        // extra-elements if the word fragment is the end of a syllable,
        // or it ends with a character that can be used as a line break
        if (areaInfo.isHyphenated) {
            MinOptMax widthIfNoBreakOccurs = null;
            if (areaInfo.breakIndex < foText.length()) {
                //Add in kerning in no-break condition
                widthIfNoBreakOccurs = letterAdjustArray[areaInfo.breakIndex];
            }
            //if (areaInfo.breakIndex)
View Full Code Here

TOP

Related Classes of org.apache.fop.traits.MinOptMax

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.