Пример #1
0
        internal static void ShapeToArabicDigitsWithContext(char[] dest, int start, int length, char digitBase, bool lastStrongWasAL)
        {
            digitBase -= '0'; // move common adjustment out of loop

            int limit = start + length;

            for (int i = start; i < limit; ++i)
            {
                char ch = dest[i];
                switch (BidiOrder.GetDirection(ch))
                {
                case BidiOrder.L:
                case BidiOrder.R:
                    lastStrongWasAL = false;
                    break;

                case BidiOrder.AL:
                    lastStrongWasAL = true;
                    break;

                case BidiOrder.EN:
                    if (lastStrongWasAL && ch <= '\u0039')
                    {
                        dest[i] = (char)(ch + digitBase);
                    }
                    break;

                default:
                    break;
                }
            }
        }
        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);
        }