IsTab() приватный метод

private IsTab ( ) : bool
Результат bool
Пример #1
0
        // methods

        /**
         * Adds a <CODE>PdfChunk</CODE> to the <CODE>PdfLine</CODE>.
         *
         * @param        chunk        the <CODE>PdfChunk</CODE> to add
         * @return        <CODE>null</CODE> if the chunk could be added completely; if not
         *                a <CODE>PdfChunk</CODE> containing the part of the chunk that could
         *                not be added is returned
         */

        internal PdfChunk Add(PdfChunk chunk)
        {
            // nothing happens if the chunk is null.
            if (chunk == null || chunk.ToString().Equals(""))
            {
                return(null);
            }

            // we split the chunk to be added
            PdfChunk overflow = chunk.Split(width);

            newlineSplit = (chunk.IsNewlineSplit() || overflow == null);
            //        if (chunk.IsNewlineSplit() && alignment == Element.ALIGN_JUSTIFIED)
            //            alignment = Element.ALIGN_LEFT;
            if (chunk.IsTab())
            {
                Object[] tab = (Object[])chunk.GetAttribute(Chunk.TAB);
                if (chunk.IsAttribute(Chunk.TABSETTINGS))
                {
                    bool isWhiteSpace = (bool)tab[1];
                    if (!isWhiteSpace || line.Count > 0)
                    {
                        Flush();
                        tabStopAnchorPosition = float.NaN;
                        tabStop = PdfChunk.GetTabStop(chunk, originalWidth - width);
                        if (tabStop.Position > originalWidth)
                        {
                            width = 0;
                            if (isWhiteSpace)
                            {
                                return(null);
                            }
                            else
                            {
                                return(chunk);
                            }
                        }
                        tabStop.Position = tabStop.Position;
                        chunk.TabStop    = tabStop;
                        if (tabStop.Align == TabStop.Alignment.LEFT)
                        {
                            width       = originalWidth - tabStop.Position;
                            tabStop     = null;
                            tabPosition = float.NaN;
                        }
                        else
                        {
                            tabPosition = originalWidth - width;
                        }
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    //Keep deprecated tab logic for backward compatibility...
                    float tabStopPosition = (float)tab[1];
                    bool  newline         = (bool)tab[2];
                    if (newline && tabPosition < originalWidth - width)
                    {
                        return(chunk);
                    }
                    chunk.AdjustLeft(left);
                    width = originalWidth - tabStopPosition;
                }
                AddToLine(chunk);
            }   // if the length of the chunk > 0 we add it to the line
            else if (chunk.Length > 0 || chunk.IsImage())
            {
                if (overflow != null)
                {
                    chunk.TrimLastSpace();
                }
                width -= chunk.Width();
                AddToLine(chunk);
            }

            // if the length == 0 and there were no other chunks added to the line yet,
            // we risk to end up in an endless loop trying endlessly to add the same chunk
            else if (line.Count < 1)
            {
                chunk    = overflow;
                overflow = chunk.Truncate(width);
                width   -= chunk.Width();
                if (chunk.Length > 0)
                {
                    AddToLine(chunk);
                    return(overflow);
                }
                // if the chunck couldn't even be truncated, we add everything, so be it
                else
                {
                    if (overflow != null)
                    {
                        AddToLine(chunk);
                    }
                    return(null);
                }
            }
            else
            {
                width += line[line.Count - 1].TrimLastSpace();
            }
            return(overflow);
        }
Пример #2
0
        // methods

        /**
         * Adds a <CODE>PdfChunk</CODE> to the <CODE>PdfLine</CODE>.
         *
         * @param        chunk        the <CODE>PdfChunk</CODE> to add
         * @return        <CODE>null</CODE> if the chunk could be added completely; if not
         *                a <CODE>PdfChunk</CODE> containing the part of the chunk that could
         *                not be added is returned
         */

        internal PdfChunk Add(PdfChunk chunk)
        {
            // nothing happens if the chunk is null.
            if (chunk == null || chunk.ToString().Equals(""))
            {
                return(null);
            }

            // we split the chunk to be added
            PdfChunk overflow = chunk.Split(width);

            newlineSplit = (chunk.IsNewlineSplit() || overflow == null);
            //        if (chunk.IsNewlineSplit() && alignment == Element.ALIGN_JUSTIFIED)
            //            alignment = Element.ALIGN_LEFT;
            if (chunk.IsTab())
            {
                Object[] tab         = (Object[])chunk.GetAttribute(Chunk.TAB);
                float    tabPosition = (float)tab[1];
                bool     newline     = (bool)tab[2];
                if (newline && tabPosition < originalWidth - width)
                {
                    return(chunk);
                }
                width = originalWidth - tabPosition;
                chunk.AdjustLeft(left);
                AddToLine(chunk);
            }
            // if the length of the chunk > 0 we add it to the line
            else if (chunk.Length > 0 || chunk.IsImage())
            {
                if (overflow != null)
                {
                    chunk.TrimLastSpace();
                }
                width -= chunk.Width;
                AddToLine(chunk);
            }

            // if the length == 0 and there were no other chunks added to the line yet,
            // we risk to end up in an endless loop trying endlessly to add the same chunk
            else if (line.Count < 1)
            {
                chunk    = overflow;
                overflow = chunk.Truncate(width);
                width   -= chunk.Width;
                if (chunk.Length > 0)
                {
                    AddToLine(chunk);
                    return(overflow);
                }
                // if the chunck couldn't even be truncated, we add everything, so be it
                else
                {
                    if (overflow != null)
                    {
                        AddToLine(chunk);
                    }
                    return(null);
                }
            }
            else
            {
                width += ((PdfChunk)(line[line.Count - 1])).TrimLastSpace();
            }
            return(overflow);
        }
Пример #3
0
        // methods
        /**
         * Adds a <CODE>PdfChunk</CODE> to the <CODE>PdfLine</CODE>.
         *
         * @param        chunk        the <CODE>PdfChunk</CODE> to add
         * @return        <CODE>null</CODE> if the chunk could be added completely; if not
         *                a <CODE>PdfChunk</CODE> containing the part of the chunk that could
         *                not be added is returned
         */
        internal PdfChunk Add(PdfChunk chunk)
        {
            // nothing happens if the chunk is null.
            if (chunk == null || chunk.ToString().Equals("")) {
                return null;
            }

            // we split the chunk to be added
            PdfChunk overflow = chunk.Split(width);
            newlineSplit = (chunk.IsNewlineSplit() || overflow == null);
            //        if (chunk.IsNewlineSplit() && alignment == Element.ALIGN_JUSTIFIED)
            //            alignment = Element.ALIGN_LEFT;
            if (chunk.IsTab()) {
                Object[] tab = (Object[])chunk.GetAttribute(Chunk.TAB);
                float tabPosition = (float)tab[1];
                bool newline = (bool)tab[2];
                if (newline && tabPosition < originalWidth - width) {
                    return chunk;
                }
                width = originalWidth - tabPosition;
                chunk.AdjustLeft(left);
                AddToLine(chunk);
            }
            // if the length of the chunk > 0 we add it to the line
            else if (chunk.Length > 0 || chunk.IsImage()) {
                if (overflow != null)
                    chunk.TrimLastSpace();
                width -= chunk.Width;
                AddToLine(chunk);
            }

                // if the length == 0 and there were no other chunks added to the line yet,
                // we risk to end up in an endless loop trying endlessly to add the same chunk
            else if (line.Count < 1) {
                chunk = overflow;
                overflow = chunk.Truncate(width);
                width -= chunk.Width;
                if (chunk.Length > 0) {
                    AddToLine(chunk);
                    return overflow;
                }
                    // if the chunck couldn't even be truncated, we add everything, so be it
                else {
                    if (overflow != null)
                        AddToLine(chunk);
                    return null;
                }
            }
            else {
                width += ((PdfChunk)(line[line.Count - 1])).TrimLastSpace();
            }
            return overflow;
        }
Пример #4
0
            /**
             * Adds a <CODE>PdfChunk</CODE> to the <CODE>PdfLine</CODE>.
             *
             * @param        chunk        the <CODE>PdfChunk</CODE> to add
             * @return        <CODE>null</CODE> if the chunk could be added completely; if not
             *                a <CODE>PdfChunk</CODE> containing the part of the chunk that could
             *                not be added is returned
             */
    
        internal PdfChunk Add(PdfChunk chunk) {
            // nothing happens if the chunk is null.
            if (chunk == null || chunk.ToString().Equals("")) {
                return null;
            }
        
            // we split the chunk to be added
            PdfChunk overflow = chunk.Split(width);
            newlineSplit = (chunk.IsNewlineSplit() || overflow == null);
            //        if (chunk.IsNewlineSplit() && alignment == Element.ALIGN_JUSTIFIED)
            //            alignment = Element.ALIGN_LEFT;
            if (chunk.IsTab()) {
                Object[] tab = (Object[]) chunk.GetAttribute(Chunk.TAB);
                if (chunk.IsAttribute(Chunk.TABSETTINGS)) {
                    bool isWhiteSpace = (bool) tab[1];
                    if (!isWhiteSpace || line.Count > 0) {
                        Flush();
                        tabStopAnchorPosition = float.NaN;
                        tabStop = PdfChunk.GetTabStop(chunk, originalWidth - width);
                        if (tabStop.Position > originalWidth) {
                            if (isWhiteSpace)
                                overflow = null;
                            else if (Math.Abs(originalWidth - width) < 0.001) {
                                AddToLine(chunk);
                                overflow = null;
                            } else {
                                overflow = chunk;
                            }
							width = 0;
                        } else {
                            chunk.TabStop = tabStop;
                            if (!isRTL && tabStop.Align == TabStop.Alignment.LEFT) {
                                width = originalWidth - tabStop.Position;
                                tabStop = null;
                                tabPosition = float.NaN;
                            } else
                                tabPosition = originalWidth - width;
                            AddToLine(chunk);
                        }
                    } else
                        return null;
                } else {
                    //Keep deprecated tab logic for backward compatibility...
                    float tabStopPosition = (float) tab[1];
                    bool newline = (bool) tab[2];
                    if (newline && tabStopPosition < originalWidth - width)
                        return chunk;
                    chunk.AdjustLeft(left);
                    width = originalWidth - tabStopPosition;
                    AddToLine(chunk);
                }
            } // if the length of the chunk > 0 we add it to the line 
            else if (chunk.Length > 0 || chunk.IsImage()) {
                if (overflow != null)
                    chunk.TrimLastSpace();
                width -= chunk.Width();
                AddToLine(chunk);
            }
        
            // if the length == 0 and there were no other chunks added to the line yet,
            // we risk to end up in an endless loop trying endlessly to add the same chunk
            else if (line.Count < 1) {
                chunk = overflow;
                overflow = chunk.Truncate(width);
                width -= chunk.Width();
                if (chunk.Length > 0) {
                    AddToLine(chunk);
                    return overflow;
                }
                // if the chunck couldn't even be truncated, we add everything, so be it
                else {
                    if (overflow != null)
                        AddToLine(chunk);
                    return null;
                }
            }
            else {
                width += line[line.Count - 1].TrimLastSpace();
            }
            return overflow;
        }
        public PdfLine ProcessLine(float leftX, float width, int alignment, int runDirection, int arabicOptions)
        {
            ArabicOptions = arabicOptions;
            Save();
            var isRtl = (runDirection == PdfWriter.RUN_DIRECTION_RTL);

            if (CurrentChar >= TotalTextLength)
            {
                var hasText = GetParagraph(runDirection);
                if (!hasText)
                {
                    return(null);
                }

                if (TotalTextLength == 0)
                {
                    var ar  = new ArrayList();
                    var ckx = new PdfChunk("", DetailChunks[0]);
                    ar.Add(ckx);
                    return(new PdfLine(0, 0, 0, alignment, true, ar, isRtl));
                }
            }
            var originalWidth = width;
            var lastSplit     = -1;

            if (CurrentChar != 0)
            {
                CurrentChar = TrimLeftEx(CurrentChar, TotalTextLength - 1);
            }

            var      oldCurrentChar = CurrentChar;
            var      uniC           = 0;
            PdfChunk ck             = null;
            float    charWidth      = 0;
            PdfChunk lastValidChunk = null;
            var      splitChar      = false;
            var      surrogate      = false;

            for (; CurrentChar < TotalTextLength; ++CurrentChar)
            {
                ck        = DetailChunks[CurrentChar];
                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
                {
                    charWidth = ck.GetCharWidth(Text[CurrentChar]);
                }

                splitChar = ck.IsExtSplitCharacter(oldCurrentChar, CurrentChar, TotalTextLength, Text, DetailChunks);
                if (splitChar && char.IsWhiteSpace((char)uniC))
                {
                    lastSplit = CurrentChar;
                }

                if (width - charWidth < 0)
                {
                    break;
                }

                if (splitChar)
                {
                    lastSplit = CurrentChar;
                }

                width         -= charWidth;
                lastValidChunk = ck;
                if (surrogate)
                {
                    ++CurrentChar;
                }

                if (ck.IsTab())
                {
                    var tab         = (object[])ck.GetAttribute(Chunk.TAB);
                    var tabPosition = (float)tab[1];
                    var newLine     = (bool)tab[2];
                    if (newLine && tabPosition < originalWidth - width)
                    {
                        return(new PdfLine(0, originalWidth, width, alignment, true, CreateArrayOfPdfChunks(oldCurrentChar, CurrentChar - 1), isRtl));
                    }
                    DetailChunks[CurrentChar].AdjustLeft(leftX);
                    width = originalWidth - tabPosition;
                }
            }
            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 (CurrentChar >= TotalTextLength)
            {
                // there was more line than text
                return(new PdfLine(0, originalWidth, width, alignment, true, CreateArrayOfPdfChunks(oldCurrentChar, TotalTextLength - 1), isRtl));
            }
            var newCurrentChar = TrimRightEx(oldCurrentChar, CurrentChar - 1);

            if (newCurrentChar < oldCurrentChar)
            {
                // only WS
                return(new PdfLine(0, originalWidth, width, alignment, false, CreateArrayOfPdfChunks(oldCurrentChar, CurrentChar - 1), isRtl));
            }
            if (newCurrentChar == CurrentChar - 1)
            { // middle of word
                var he = (IHyphenationEvent)lastValidChunk.GetAttribute(Chunk.HYPHENATION);
                if (he != null)
                {
                    var word = GetWord(oldCurrentChar, newCurrentChar);
                    if (word != null)
                    {
                        var testWidth = width + GetWidth(word[0], CurrentChar - 1);
                        var pre       = he.GetHyphenatedWordPre(new string(Text, word[0], word[1] - word[0]), lastValidChunk.Font.Font, lastValidChunk.Font.Size, testWidth);
                        var post      = he.HyphenatedWordPost;
                        if (pre.Length > 0)
                        {
                            var extra = new PdfChunk(pre, lastValidChunk);
                            CurrentChar = word[1] - post.Length;
                            return(new PdfLine(0, originalWidth, testWidth - lastValidChunk.Font.Width(pre), alignment, false, CreateArrayOfPdfChunks(oldCurrentChar, word[0] - 1, extra), isRtl));
                        }
                    }
                }
            }
            if (lastSplit == -1 || lastSplit >= newCurrentChar)
            {
                // no split point or split point ahead of end
                return(new PdfLine(0, originalWidth, width + GetWidth(newCurrentChar + 1, CurrentChar - 1), alignment, false, CreateArrayOfPdfChunks(oldCurrentChar, newCurrentChar), isRtl));
            }
            // standard split
            CurrentChar    = lastSplit + 1;
            newCurrentChar = TrimRightEx(oldCurrentChar, lastSplit);
            if (newCurrentChar < oldCurrentChar)
            {
                // only WS again
                newCurrentChar = CurrentChar - 1;
            }
            return(new PdfLine(0, originalWidth, originalWidth - GetWidth(oldCurrentChar, newCurrentChar), alignment, false, CreateArrayOfPdfChunks(oldCurrentChar, newCurrentChar), isRtl));
        }
        public ArrayList CreateArrayOfPdfChunks(int startIdx, int endIdx, PdfChunk extraPdfChunk)
        {
            var bidi = (RunDirection == PdfWriter.RUN_DIRECTION_LTR || RunDirection == PdfWriter.RUN_DIRECTION_RTL);

            if (bidi)
            {
                Reorder(startIdx, endIdx);
            }

            var      ar    = new ArrayList();
            var      refCk = DetailChunks[startIdx];
            PdfChunk ck    = null;
            var      buf   = new StringBuilder();
            char     c;
            var      idx = 0;

            for (; startIdx <= endIdx; ++startIdx)
            {
                idx = bidi ? IndexChars[startIdx] : startIdx;
                c   = Text[idx];
                ck  = DetailChunks[idx];
                if (PdfChunk.NoPrint(ck.GetUnicodeEquivalent(c)))
                {
                    continue;
                }

                if (ck.IsImage() || ck.IsSeparator() || ck.IsTab())
                {
                    if (buf.Length > 0)
                    {
                        ar.Add(new PdfChunk(buf.ToString(), refCk));
                        buf = new StringBuilder();
                    }
                    ar.Add(ck);
                }
                else if (ck == refCk)
                {
                    buf.Append(c);
                }
                else
                {
                    if (buf.Length > 0)
                    {
                        ar.Add(new PdfChunk(buf.ToString(), refCk));
                        buf = new StringBuilder();
                    }
                    if (!ck.IsImage() && !ck.IsSeparator() && !ck.IsTab())
                    {
                        buf.Append(c);
                    }

                    refCk = ck;
                }
            }
            if (buf.Length > 0)
            {
                ar.Add(new PdfChunk(buf.ToString(), refCk));
            }
            if (extraPdfChunk != null)
            {
                ar.Add(extraPdfChunk);
            }

            return(ar);
        }