iTextSharp.text.pdf.BidiLine.GetParagraph C# (CSharp) Метод

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

public GetParagraph ( int runDirection ) : bool
runDirection int
Результат bool
        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 = 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;
        }

Usage Example

Пример #1
0
     /**
      * Method that changes a String with Arabic characters into a String in which the ligatures are made.
      * @param s	the original String
      * @param runDirection
      * @param arabicOptions
      * @return the String with the ligaturesc
      */
     public static String ProcessLTR(String s, int runDirection, int arabicOptions) {
 	    BidiLine bidi = new BidiLine();
 	    bidi.AddChunk(new PdfChunk(new Chunk(s), null));
 	    bidi.arabicOptions = arabicOptions;
 	    bidi.GetParagraph(runDirection);
 	    List<PdfChunk> arr = bidi.CreateArrayOfPdfChunks(0, bidi.totalTextLength - 1);
 	    StringBuilder sb = new StringBuilder();
 	    foreach (PdfChunk ck in arr) {
 		    sb.Append(ck.ToString());
 	    }
 	    return sb.ToString();
     }