Package com.itextpdf.text

Examples of com.itextpdf.text.TabStop


        int oldCurrentChar = currentChar;
        int uniC = 0;
        PdfChunk ck = null;
        float charWidth = 0;
        PdfChunk lastValidChunk = null;
        TabStop tabStop = null;
        float tabStopAnchorPosition = Float.NaN;
        float tabPosition = Float.NaN;
        boolean surrogate = false;
        for (; currentChar < totalTextLength; ++currentChar) {
            ck = detailChunks[currentChar];
            if (ck.isImage() && minY < yLine) {
                Image img = ck.getImage();
                if (img.isScaleToFitHeight() && yLine + 2 * descender - img.getScaledHeight() - ck.getImageOffsetY() - img.getSpacingBefore() < minY) {
                    float scalePercent = (yLine + 2 * descender - ck.getImageOffsetY() - img.getSpacingBefore() - minY) / img.getScaledHeight();
                  ck.setImageScalePercentage(scalePercent);
                }
            }
            surrogate = Utilities.isSurrogatePair(text, currentChar);
            if (surrogate)
                uniC = ck.getUnicodeEquivalent(Utilities.convertToUtf32(text, currentChar));
            else
                uniC = ck.getUnicodeEquivalent(text[currentChar]);
            if (PdfChunk.noPrint(uniC))
                continue;
            if (surrogate)
                charWidth = ck.getCharWidth(uniC);
            else {
                if (ck.isImage()) {
                    charWidth = ck.getImageWidth();
                } else {
                    charWidth = ck.getCharWidth(text[currentChar]);
                }
            }
            if (width - charWidth < 0) {
              // If the chunk is an image and it is the first one in line, check if resize requested
              // If so, resize to fit the current line width
              if (lastValidChunk == null && ck.isImage()) {
                Image img = ck.getImage();
                if (img.isScaleToFitLineWhenOverflow()) {
                  //float scalePercent = width / img.getWidth() * 100;
                  //img.scalePercent(scalePercent);
                  float scalePercent = width / img.getWidth();
                  ck.setImageScalePercentage(scalePercent);
                  charWidth = width;
                }
              }
            }
            if (ck.isTab()) {
                if (ck.isAttribute(Chunk.TABSETTINGS)) {
                    lastSplit = currentChar;
                    if (tabStop != null) {
                        float tabStopPosition = tabStop.getPosition(tabPosition, originalWidth - width, tabStopAnchorPosition);
                        width = originalWidth - (tabStopPosition + (originalWidth - width - tabPosition));
                        if (width < 0) {
                            tabStopPosition += width;
                            width = 0;
                        }
                        tabStop.setPosition(tabStopPosition);
                    }

                    tabStop = PdfChunk.getTabStop(ck, originalWidth - width);
                    if (tabStop.getPosition() > originalWidth) {
                        tabStop = null;
                        break;
                    }
                    ck.setTabStop(tabStop);
                    if (tabStop.getAlignment() == TabStop.Alignment.LEFT) {
                        width = originalWidth - tabStop.getPosition();
                        tabStop = null;
                        tabPosition = Float.NaN;
                        tabStopAnchorPosition = Float.NaN;
                    } else {
                        tabPosition = originalWidth - width;
                        tabStopAnchorPosition = Float.NaN;
                    }
                } else {
                    Object[] tab = (Object[])ck.getAttribute(Chunk.TAB);
                    //Keep deprecated tab logic for backward compatibility...
                    float tabStopPosition = ((Float)tab[1]).floatValue();
                    boolean newLine = ((Boolean)tab[2]).booleanValue();
                    if (newLine && tabStopPosition < originalWidth - width) {
                        return new PdfLine(0, originalWidth, width, alignment, true, createArrayOfPdfChunks(oldCurrentChar, currentChar - 1), isRTL);
                    }
                    detailChunks[currentChar].adjustLeft(leftX);
                    width = originalWidth - tabStopPosition;
                }
            }
            else if (ck.isSeparator()) {
                Object[] sep = (Object[])ck.getAttribute(Chunk.SEPARATOR);
                DrawInterface di = (DrawInterface)sep[0];
                Boolean vertical = (Boolean)sep[1];
                if (vertical && di instanceof LineSeparator) {
                    float separatorWidth = originalWidth * ((LineSeparator) di).getPercentage() / 100f;
                    width -= separatorWidth;
                    if (width < 0) {
                        width = 0;
                    }
                }
            } else {
                boolean splitChar = ck.isExtSplitCharacter(oldCurrentChar, currentChar, totalTextLength, text, detailChunks);
                if (splitChar && Character.isWhitespace((char)uniC))
                    lastSplit = currentChar;
                if (width - charWidth < 0)
                    break;
                if (tabStop != null && tabStop.getAlignment() == TabStop.Alignment.ANCHOR && Float.isNaN(tabStopAnchorPosition) && tabStop.getAnchorChar() == (char) uniC) {
                    tabStopAnchorPosition = originalWidth - width;
                }
                width -= charWidth;
                if (splitChar)
                    lastSplit = currentChar;
            }
            lastValidChunk = ck;
            if (surrogate)
                ++currentChar;
        }
        if (lastValidChunk == null) {
            // not even a single char fit; must output the first char
            ++currentChar;
            if (surrogate)
                ++currentChar;
            return new PdfLine(0, originalWidth, 0, alignment, false, createArrayOfPdfChunks(currentChar - 1, currentChar - 1), isRTL);
        }

        if (tabStop != null) {
            float tabStopPosition = tabStop.getPosition(tabPosition, originalWidth - width, tabStopAnchorPosition);
            width = originalWidth - (tabStopPosition + (originalWidth - width - tabPosition));
            if (width < 0) {
                tabStopPosition += width;
                width = 0;
            }
            tabStop.setPosition(tabStopPosition);
        }

        if (currentChar >= totalTextLength) {
            // there was more line than text
            return new PdfLine(0, originalWidth, width, alignment, true, createArrayOfPdfChunks(oldCurrentChar, totalTextLength - 1), isRTL);
View Full Code Here


     */
    public float getWidth(int startIdx, int lastIdx) {
        char c = 0;
        PdfChunk ck = null;
        float width = 0;
        TabStop tabStop = null;
        float tabStopAnchorPosition = Float.NaN;
        float tabPosition = Float.NaN;
        for (; startIdx <= lastIdx; ++startIdx) {
            boolean surrogate = Utilities.isSurrogatePair(text, startIdx);
            if (detailChunks[startIdx].isTab()
                    //Keep deprecated tab logic for backward compatibility...
                    && detailChunks[startIdx].isAttribute(Chunk.TABSETTINGS)) {
                if (tabStop != null) {
                    float tabStopPosition = tabStop.getPosition(tabPosition, width, tabStopAnchorPosition);
                    width = tabStopPosition + (width - tabPosition);
                    tabStop.setPosition(tabStopPosition);
                }
                tabStop = detailChunks[startIdx].getTabStop();
                if (tabStop == null) {
                    tabStop = PdfChunk.getTabStop(detailChunks[startIdx], width);
                    tabPosition = width;
                    tabStopAnchorPosition = Float.NaN;
                } else {
                    width = tabStop.getPosition();
                    tabStop = null;
                    tabPosition = Float.NaN;
                    tabStopAnchorPosition = Float.NaN;
                }
            } else if (surrogate) {
                width += detailChunks[startIdx].getCharWidth(Utilities.convertToUtf32(text, startIdx));
                ++startIdx;
            }
            else {
                c = text[startIdx];
                ck = detailChunks[startIdx];
                if (PdfChunk.noPrint(ck.getUnicodeEquivalent(c)))
                    continue;
                if (tabStop != null && tabStop.getAlignment() != TabStop.Alignment.ANCHOR && Float.isNaN(tabStopAnchorPosition) && tabStop.getAnchorChar() == (char)ck.getUnicodeEquivalent(c)) {
                    tabStopAnchorPosition = width;
                }
                width += detailChunks[startIdx].getCharWidth(c);
            }
        }
        if (tabStop != null) {
            float tabStopPosition = tabStop.getPosition(tabPosition, width, tabStopAnchorPosition);
            width = tabStopPosition + (width - tabPosition);
            tabStop.setPosition(tabStopPosition);
        }
        return width;
    }
View Full Code Here

TOP

Related Classes of com.itextpdf.text.TabStop

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.