예제 #1
0
 public void CopyFrom(LexerLookup f)
 {
     Token       = f.Token;
     StringValue = f.StringValue;
 }
예제 #2
0
        public PdfObject ReadArray(String name)
        {
            var         arr  = new PdfArray();
            Int32       step = 0;
            LexerLookup s1   = new LexerLookup();
            LexerLookup s2   = new LexerLookup();

            void ResetLookup()
            {
                if (step == 0)
                {
                    return;
                }
                else if (step == 1)
                {
                    arr.Add(PlainPdfObject(s1.Token, s1.StringValue));
                }
                else if (step == 2)
                {
                    arr.Add(PlainPdfObject(s1.Token, s1.StringValue));
                    arr.Add(PlainPdfObject(s2.Token, s2.StringValue));
                }
                step = 0;
            }

            while (NextToken())
            {
                switch (Token)
                {
                case Token.EndArray:
                    ResetLookup();
                    return(arr);

                case Token.StartArray:
                    ResetLookup();
                    arr.Add(ReadArray(name));
                    break;

                case Token.Number:
                    switch (step)
                    {
                    case 0:
                        step           = 1;
                        s1.Token       = Token;
                        s1.StringValue = StringValue;
                        break;

                    case 1:
                        step           = 2;
                        s2.Token       = Token;
                        s2.StringValue = StringValue;
                        break;

                    case 2:
                        step = 2;
                        arr.Add(PlainPdfObject(s1.Token, s1.StringValue));
                        s1.CopyFrom(s2);
                        s2.Token       = Token;
                        s2.StringValue = StringValue;
                        break;
                    }
                    break;

                case Token.Ider:
                    if (StringValue == "R" && step > 0)
                    {
                        arr.Add(new PdfName($"{s1.StringValue} {s2.StringValue}"));
                        step = 0;
                    }
                    else
                    {
                        ResetLookup();
                        arr.Add(PlainPdfObject());
                    }
                    break;

                default:
                    ResetLookup();
                    arr.Add(PlainPdfObject());
                    break;
                }
            }
            throw new LexerException($"Invalid array type: {Token}");
        }