iTextSharp.text.pdf.BidiOrder.GetLevels C# (CSharp) Метод

GetLevels() публичный Метод

public GetLevels ( int linebreaks ) : byte[]
linebreaks int
Результат byte[]
        public byte[] GetLevels(int[] linebreaks)
        {
            // Note that since the previous processing has removed all
            // P, S, and WS values from resultTypes, the values referred to
            // in these rules are the initial types, before any processing
            // has been applied (including processing of overrides).
            //
            // This example implementation has reinserted explicit format codes
            // and BN, in order that the levels array correspond to the
            // initial text.  Their final placement is not normative.
            // These codes are treated like WS in this implementation,
            // so they don't interrupt sequences of WS.

            ValidateLineBreaks(linebreaks, textLength);

            byte[] result = new byte[resultLevels.Length];
            for (int k = 0; k < resultLevels.Length; ++k)
                result[k] = (byte)resultLevels[k];

            // don't worry about linebreaks since if there is a break within
            // a series of WS values preceeding S, the linebreak itself
            // causes the reset.
            for (int i = 0; i < result.Length; ++i) {
                sbyte t = initialTypes[i];
                if (t == B || t == S) {
                    // Rule L1, clauses one and two.
                    result[i] = (byte)paragraphEmbeddingLevel;

                    // Rule L1, clause three.
                    for (int j = i - 1; j >= 0; --j) {
                        if (IsWhitespace(initialTypes[j])) { // including format codes
                            result[j] = (byte)paragraphEmbeddingLevel;
                        } else {
                            break;
                        }
                    }
                }
            }

            // Rule L1, clause four.
            int start = 0;
            for (int i = 0; i < linebreaks.Length; ++i) {
                int limit = linebreaks[i];
                for (int j = limit - 1; j >= start; --j) {
                    if (IsWhitespace(initialTypes[j])) { // including format codes
                        result[j] = (byte)paragraphEmbeddingLevel;
                    } else {
                        break;
                    }
                }

                start = limit;
            }

            return result;
        }

Same methods

BidiOrder::GetLevels ( ) : byte[]

Usage Example

Пример #1
0
        public bool GetParagraph(int runDirection)
        {
            this.runDirection = runDirection;
            currentChar = 0;
            totalTextLength = 0;
            bool hasText = false;
            char c;
            char uniC;
            BaseFont bf;
            for (; indexChunk < chunks.Count; ++indexChunk) {
                PdfChunk ck = (PdfChunk)chunks[indexChunk];
                bf = ck.Font.Font;
                string s = ck.ToString();
                int len = s.Length;
                for (; indexChunkChar < len; ++indexChunkChar) {
                    c = s[indexChunkChar];
                    uniC = (char)bf.GetUnicodeEquivalent(c);
                    if (uniC == '\r' || uniC == '\n') {
                        // next condition is never true for CID
                        if (uniC == '\r' && indexChunkChar + 1 < len && s[indexChunkChar + 1] == '\n')
                            ++indexChunkChar;
                        ++indexChunkChar;
                        if (indexChunkChar >= len) {
                            indexChunkChar = 0;
                            ++indexChunk;
                        }
                        hasText = true;
                        if (totalTextLength == 0)
                            detailChunks[0] = ck;
                        break;
                    }
                    AddPiece(c, ck);
                }
                if (hasText)
                    break;
                indexChunkChar = 0;
            }
            if (totalTextLength == 0)
                return hasText;

            // remove trailing WS
            totalTextLength = TrimRight(0, totalTextLength - 1) + 1;
            if (totalTextLength == 0)
                return true;

            if (runDirection == PdfWriter.RUN_DIRECTION_LTR || runDirection == PdfWriter.RUN_DIRECTION_RTL) {
                if (orderLevels.Length < totalTextLength) {
                    orderLevels = new byte[pieceSize];
                    indexChars = new int[pieceSize];
                }

                ArabicLigaturizer.ProcessNumbers(text, 0, totalTextLength, arabicOptions);
                BidiOrder order = new BidiOrder(text, 0, totalTextLength, (sbyte)(runDirection == PdfWriter.RUN_DIRECTION_RTL ? 1 : 0));
                byte[] od = order.GetLevels();
                for (int k = 0; k < totalTextLength; ++k) {
                    orderLevels[k] = od[k];
                    indexChars[k] = k;
                }
                DoArabicShapping();
                MirrorGlyphs();
            }
            totalTextLength = TrimRightEx(0, totalTextLength - 1) + 1;
            return true;
        }