26Parser::Parser(XRef *xrefA, Lexer *lexerA) {
41Object *Parser::getObj(Object *obj,
42 Guchar *fileKey,
int keyLength,
43 int objNum,
int objGen) {
45Object *Parser::getObj(Object *obj) {
68 if (buf1.isCmd(
"[")) {
71 while (!buf1.isCmd(
"]") && !buf1.isEOF())
73 obj->arrayAdd(getObj(&obj2, fileKey, keyLength, objNum, objGen));
75 obj->arrayAdd(getObj(&obj2));
78 error(getPos(),
"End of file inside array");
82 }
else if (buf1.isCmd(
"<<")) {
85 while (!buf1.isCmd(
">>") && !buf1.isEOF()) {
87 error(getPos(),
"Dictionary key must be a name object");
90 key = copyString(buf1.getName());
92 if (buf1.isEOF() || buf1.isError()) {
97 obj->dictAdd(key, getObj(&obj2, fileKey, keyLength, objNum, objGen));
99 obj->dictAdd(key, getObj(&obj2));
104 error(getPos(),
"End of file inside dictionary");
105 if (buf2.isCmd(
"stream")) {
106 if ((str = makeStream(obj))) {
107 obj->initStream(str);
110 str->getBaseStream()->doDecryption(fileKey, keyLength,
123 }
else if (buf1.isInt()) {
126 if (buf1.isInt() && buf2.isCmd(
"R")) {
127 obj->initRef(num, buf1.getInt());
136 }
else if (buf1.isString() && fileKey) {
138 s = obj->getString();
139 decrypt =
new Decrypt(fileKey, keyLength, objNum, objGen);
140 for (i = 0, p = obj->getString()->getCString();
143 *p = decrypt->decryptByte(*p);
158Stream *Parser::makeStream(Object *dict) {
161 Guint pos, endPos, length;
164 lexer->skipToNextLine();
165 pos = lexer->getPos();
168 dict->dictLookup(
"Length", &obj);
170 length = (Guint)obj.getInt();
173 error(getPos(),
"Bad 'Length' attribute in stream");
179 if (xref->getStreamEnd(pos, &endPos)) {
180 length = endPos - pos;
184 str = lexer->getStream()->getBaseStream()->makeSubStream(pos, gTrue,
188 str = str->addFilters(dict);
191 lexer->setPos(pos + length);
196 if (buf1.isCmd(
"endstream"))
199 error(getPos(),
"Missing 'endstream'");
204void Parser::shift() {
213 }
else if (buf2.isCmd(
"ID")) {
222 lexer->getObj(&buf2);