iTextSharp.text.pdf.ArabicLigaturizer.ProcessNumbers C# (CSharp) Метод

ProcessNumbers() статический приватный Метод

static private ProcessNumbers ( char text, int offset, int length, int options ) : void
text char
offset int
length int
options int
Результат void
        internal static void ProcessNumbers(char[] text, int offset, int length, int options)
        {
            int limit = offset + length;
            if ((options & DIGITS_MASK) != 0) {
                char digitBase = '\u0030'; // European digits
                switch (options & DIGIT_TYPE_MASK) {
                    case DIGIT_TYPE_AN:
                        digitBase = '\u0660';  // Arabic-Indic digits
                        break;

                    case DIGIT_TYPE_AN_EXTENDED:
                        digitBase = '\u06f0';  // Eastern Arabic-Indic digits (Persian and Urdu)
                        break;

                    default:
                        break;
                }

                switch (options & DIGITS_MASK) {
                    case DIGITS_EN2AN: {
                        int digitDelta = digitBase - '\u0030';
                        for (int i = offset; i < limit; ++i) {
                            char ch = text[i];
                            if (ch <= '\u0039' && ch >= '\u0030') {
                                text[i] += (char)digitDelta;
                            }
                        }
                    }
                    break;

                    case DIGITS_AN2EN: {
                        char digitTop = (char)(digitBase + 9);
                        int digitDelta = '\u0030' - digitBase;
                        for (int i = offset; i < limit; ++i) {
                            char ch = text[i];
                            if (ch <= digitTop && ch >= digitBase) {
                                text[i] += (char)digitDelta;
                            }
                        }
                    }
                    break;

                    case DIGITS_EN2AN_INIT_LR:
                        ShapeToArabicDigitsWithContext(text, 0, length, digitBase, false);
                        break;

                    case DIGITS_EN2AN_INIT_AL:
                        ShapeToArabicDigitsWithContext(text, 0, length, digitBase, true);
                        break;

                    default:
                        break;
                }
            }
        }

Usage Example

        public bool GetParagraph(int runDirection)
        {
            RunDirection    = runDirection;
            CurrentChar     = 0;
            TotalTextLength = 0;
            var      hasText = false;
            char     c;
            char     uniC;
            BaseFont bf;

            for (; IndexChunk < Chunks.Count; ++IndexChunk)
            {
                var ck = (PdfChunk)Chunks[IndexChunk];
                bf = ck.Font.Font;
                var s   = ck.ToString();
                var 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);
                var order = new BidiOrder(Text, 0, TotalTextLength, (sbyte)(runDirection == PdfWriter.RUN_DIRECTION_RTL ? 1 : 0));
                var od    = order.GetLevels();
                for (var k = 0; k < TotalTextLength; ++k)
                {
                    OrderLevels[k] = od[k];
                    IndexChars[k]  = k;
                }
                DoArabicShapping();
                MirrorGlyphs();
            }
            TotalTextLength = TrimRightEx(0, TotalTextLength - 1) + 1;
            return(true);
        }