iTextSharp.text.pdf.PdfContentParser.ReadPRObject C# (CSharp) Метод

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

public ReadPRObject ( ) : PdfObject
Результат PdfObject
        public PdfObject ReadPRObject()
        {
            if (!NextValidToken())
                return null;
            PRTokeniser.TokType type = tokeniser.TokenType;
            switch (type) {
                case PRTokeniser.TokType.START_DIC: {
                    PdfDictionary dic = ReadDictionary();
                    return dic;
                }
                case PRTokeniser.TokType.START_ARRAY:
                    return ReadArray();
                case PRTokeniser.TokType.STRING:
                    PdfString str = new PdfString(tokeniser.StringValue, null).SetHexWriting(tokeniser.IsHexString());
                    return str;
                case PRTokeniser.TokType.NAME:
                    return new PdfName(tokeniser.StringValue, false);
                case PRTokeniser.TokType.NUMBER:
                    return new PdfNumber(tokeniser.StringValue);
                 case PRTokeniser.TokType.OTHER:
                    return new PdfLiteral(COMMAND_TYPE, tokeniser.StringValue);
                default:
                    return new PdfLiteral(-(int)type, tokeniser.StringValue);
            }
        }

Usage Example

Пример #1
0
 private void FillMetrics(byte[] touni, IntHashtable widths, int dw) {
     PdfContentParser ps = new PdfContentParser(new PRTokeniser(touni));
     PdfObject ob = null;
     PdfObject last = null;
     bool notFound = true;
     int nestLevel = 0;
     while ((notFound || nestLevel > 0) && (ob = ps.ReadPRObject()) != null) {
         if (ob.Type == PdfContentParser.COMMAND_TYPE) {
             if (ob.ToString().Equals("begin")) {
                 notFound = false;
                 nestLevel++;
             }
             else if (ob.ToString().Equals("end")) {
                 nestLevel--;
             }
             else if (ob.ToString().Equals("beginbfchar")) {
                 int n = ((PdfNumber)last).IntValue;
                 for (int k = 0; k < n; ++k) {
                     String cid = DecodeString((PdfString)ps.ReadPRObject());
                     String uni = DecodeString((PdfString)ps.ReadPRObject());
                     if (uni.Length == 1) {
                         int cidc = (int)cid[0];
                         int unic = (int)uni[uni.Length - 1];
                         int w = dw;
                         if (widths.ContainsKey(cidc))
                             w = widths[cidc];
                         metrics[unic] = new int[]{cidc, w};
                     }
                 }
             }
             else if (ob.ToString().Equals("beginbfrange")) {
                 int n = ((PdfNumber)last).IntValue;
                 for (int k = 0; k < n; ++k) {
                     String cid1 = DecodeString((PdfString)ps.ReadPRObject());
                     String cid2 = DecodeString((PdfString)ps.ReadPRObject());
                     int cid1c = (int)cid1[0];
                     int cid2c = (int)cid2[0];
                     PdfObject ob2 = ps.ReadPRObject();
                     if (ob2.IsString()) {
                         String uni = DecodeString((PdfString)ob2);
                         if (uni.Length == 1) {
                             int unic = (int)uni[uni.Length - 1];
                             for (; cid1c <= cid2c; cid1c++, unic++) {
                                 int w = dw;
                                 if (widths.ContainsKey(cid1c))
                                     w = widths[cid1c];
                                 metrics[unic] = new int[]{cid1c, w};
                             }
                         }
                     }
                     else {
                         PdfArray a = (PdfArray)ob2;
                         for (int j = 0; j < a.Size; ++j, ++cid1c) {
                             String uni = DecodeString(a.GetAsString(j));
                             if (uni.Length == 1) {
                                 int unic = (int)uni[uni.Length - 1];
                                 int w = dw;
                                 if (widths.ContainsKey(cid1c))
                                     w = widths[cid1c];
                                 metrics[unic] = new int[]{cid1c, w};
                             }
                         }
                     }
                 }                        
             }
         }
         else
             last = ob;
     }
 }
All Usage Examples Of iTextSharp.text.pdf.PdfContentParser::ReadPRObject