Source Code Cross Referenced for StreamParser.java in  » PDF » pjx » com » etymon » pj » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » PDF » pjx » com.etymon.pj 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.etymon.pj;
002:
003:        import java.io.*;
004:        import java.util.*;
005:        import com.etymon.pj.exception.*;
006:        import com.etymon.pj.object.*;
007:        import com.etymon.pj.object.pagemark.*;
008:
009:        public class StreamParser {
010:
011:            public StreamParser() {
012:            }
013:
014:            public Vector parse(PjStream stream) throws PdfFormatException {
015:                _buffer = stream.getBuffer();
016:                _stack = new Stack();
017:                int b;
018:                _counter = 0;
019:                _image = false;
020:                while (_counter < _buffer.length) {
021:                    getToken();
022:                    processToken();
023:                }
024:                Vector v = new Vector();
025:                while (!_stack.empty()) {
026:                    v.insertElementAt(_stack.pop(), 0);
027:                }
028:                return v;
029:            }
030:
031:            // sets _imageData to the inline image data
032:            private void getImageData() {
033:                boolean done = false;
034:                int start = _counter;
035:                do {
036:                    if (((_buffer[_counter] == '\n') || (_buffer[_counter] == '\r'))
037:                            && ((_counter - start) >= 3)) {
038:                        if ((_buffer[_counter - 1] == 'I')
039:                                && (_buffer[_counter - 2] == 'E')
040:                                && ((_buffer[_counter - 3] == '\n') || (_buffer[_counter - 3] == '\r'))) {
041:                            _imageData = new byte[_counter - start - 2];
042:                            System.arraycopy(_buffer, start, _imageData, 0,
043:                                    _imageData.length);
044:                            done = true;
045:                        }
046:                    }
047:                    _counter++;
048:                } while (done == false);
049:                _token = "";
050:            }
051:
052:            private void getToken() {
053:                // inline image data (BI-ID-EI) are a special case
054:                if (_image == true) {
055:                    getImageData();
056:                    return;
057:                }
058:                // otherwise do normal processing
059:                skipWhitespace();
060:                StringBuffer token = new StringBuffer();
061:                int stringMode = 0;
062:                char ch = '\0';
063:                char lastch = '\0';
064:                boolean done = false;
065:                int c;
066:                while ((!done) && ((c = _counter) < _buffer.length)) {
067:                    int b = _buffer[c];
068:                    char oldlastch = lastch;
069:                    lastch = ch;
070:                    ch = (char) b;
071:                    if (stringMode == 0) {
072:                        switch (ch) {
073:                        case '(':
074:                            if (token.length() == 0) {
075:                                stringMode = 1;
076:                                token.append('(');
077:                            } else {
078:                                _counter--;
079:                                done = true;
080:                            }
081:                            break;
082:                        case '[':
083:                        case ']':
084:                            if (token.length() == 0) {
085:                                token.append(ch);
086:                            } else {
087:                                _counter--;
088:                            }
089:                            done = true;
090:                            break;
091:                        case '/':
092:                            if (token.length() == 0) {
093:                                token.append(ch);
094:                            } else {
095:                                _counter--;
096:                                done = true;
097:                            }
098:                            break;
099:                        case '<':
100:                        case '>':
101:                            int x = token.length();
102:                            if (x == 0) {
103:                                token.append(ch);
104:                            } else {
105:                                if ((x == 1) && (token.charAt(0) == ch)) {
106:                                    token.append(ch);
107:                                    done = true;
108:                                } else {
109:                                    _counter--;
110:                                    done = true;
111:                                }
112:                            }
113:                            break;
114:                        default:
115:                            if (isWhitespace(ch)) {
116:                                done = true;
117:                            } else {
118:                                token.append(ch);
119:                            }
120:                        }
121:                    } else {
122:                        // string mode
123:                        switch (ch) {
124:                        case '(':
125:                            token.append('(');
126:                            if ((lastch != '\\') || (oldlastch == '\\')) {
127:                                stringMode++;
128:                            }
129:                            break;
130:                        case ')':
131:                            token.append(')');
132:                            if ((lastch != '\\') || (oldlastch == '\\')) {
133:                                stringMode--;
134:                                if (stringMode == 0) {
135:                                    done = true;
136:                                }
137:                            }
138:                            break;
139:                        default:
140:                            token.append(ch);
141:                        }
142:                    }
143:                    _counter++;
144:                }
145:                _token = token.toString();
146:            }
147:
148:            private void skipWhitespace() {
149:                int c;
150:                while (((c = _counter) < _buffer.length)
151:                        && (isWhitespace((char) _buffer[c]))) {
152:                    _counter++;
153:                }
154:            }
155:
156:            private static boolean isWhitespace(char c) {
157:                return ((c == ' ') || (c == '\t') || (c == '\r') || (c == '\n'));
158:            }
159:
160:            private void processToken() throws PdfFormatException {
161:                if ((_token.length() == 0) && (_image == false)) {
162:                    return;
163:                }
164:                if (_image == true) {
165:                    _image = false;
166:                    // create image object
167:                    _o1 = _stack.pop();
168:                    if (!(_o1 instanceof  PjDictionary)) {
169:                        throw new PdfFormatException(
170:                                "Dictionary expected before ID.");
171:                    }
172:                    _stack.push(new XEI((PjDictionary) _o1, _imageData));
173:                } else if (_token.equals("BI")) {
174:                    _stack.push("<<");
175:                } else if ((_token.equals(">>")) || (_token.equals("ID"))) {
176:                    _b1 = false;
177:                    _h1 = new Hashtable();
178:                    while (!_b1) {
179:                        _o2 = _stack.pop();
180:                        if ((_o2 instanceof  String)
181:                                && (((String) _o2).equals("<<"))) {
182:                            _b1 = true;
183:                        } else {
184:                            if (!(_o2 instanceof  PjObject)) {
185:                                throw new PdfFormatException(
186:                                        "PDF object expected within dictionary.");
187:                            }
188:                            _o1 = _stack.pop();
189:                            if (!(_o1 instanceof  PjName)) {
190:                                throw new PdfFormatException(
191:                                        "Name (key) expected within dictionary.");
192:                            }
193:                            _h1.put(_o1, _o2);
194:                        }
195:                    }
196:                    _stack.push(new PjDictionary(_h1));
197:                    if (_token.equals("ID")) {
198:                        _image = true;
199:                    }
200:                } else if (_token.equals("BT")) {
201:                    _stack.push(new XBT());
202:                } else if (_token.equals("ET")) {
203:                    _stack.push(new XET());
204:                } else if (_token.equals("Td")) {
205:                    _o1 = _stack.pop();
206:                    if (_o1 instanceof  PjNumber) {
207:                        _n2 = (PjNumber) (_o1);
208:                    } else {
209:                        throw new PdfFormatException(
210:                                "Number (y offset) expected before Td.");
211:                    }
212:                    _o1 = _stack.pop();
213:                    if (_o1 instanceof  PjNumber) {
214:                        _n1 = (PjNumber) (_o1);
215:                    } else {
216:                        throw new PdfFormatException(
217:                                "Number (x offset) expected before Td.");
218:                    }
219:                    _stack.push(new XTd(_n1, _n2));
220:                } else if (_token.equals("TD")) {
221:                    _o1 = _stack.pop();
222:                    if (_o1 instanceof  PjNumber) {
223:                        _n2 = (PjNumber) (_o1);
224:                    } else {
225:                        throw new PdfFormatException(
226:                                "Number (y offset) expected before TD.");
227:                    }
228:                    _o1 = _stack.pop();
229:                    if (_o1 instanceof  PjNumber) {
230:                        _n1 = (PjNumber) (_o1);
231:                    } else {
232:                        throw new PdfFormatException(
233:                                "Number (x offset) expected before TD.");
234:                    }
235:                    _stack.push(new XXTD(_n1, _n2));
236:                } else if (_token.equals("m")) {
237:                    _o1 = _stack.pop();
238:                    if (_o1 instanceof  PjNumber) {
239:                        _n2 = (PjNumber) (_o1);
240:                    } else {
241:                        throw new PdfFormatException(
242:                                "Number (y) expected before m.");
243:                    }
244:                    _o1 = _stack.pop();
245:                    if (_o1 instanceof  PjNumber) {
246:                        _n1 = (PjNumber) (_o1);
247:                    } else {
248:                        throw new PdfFormatException(
249:                                "Number (x) expected before m.");
250:                    }
251:                    _stack.push(new Xm(_n1, _n2));
252:                } else if (_token.equals("l")) {
253:                    _o1 = _stack.pop();
254:                    if (_o1 instanceof  PjNumber) {
255:                        _n2 = (PjNumber) (_o1);
256:                    } else {
257:                        throw new PdfFormatException(
258:                                "Number (y) expected before l.");
259:                    }
260:                    _o1 = _stack.pop();
261:                    if (_o1 instanceof  PjNumber) {
262:                        _n1 = (PjNumber) (_o1);
263:                    } else {
264:                        throw new PdfFormatException(
265:                                "Number (x) expected before l.");
266:                    }
267:                    _stack.push(new Xl(_n1, _n2));
268:                } else if (_token.equals("d0")) {
269:                    _o1 = _stack.pop();
270:                    if (_o1 instanceof  PjNumber) {
271:                        _n2 = (PjNumber) (_o1);
272:                    } else {
273:                        throw new PdfFormatException(
274:                                "Number (w[y]) expected before d0.");
275:                    }
276:                    _o1 = _stack.pop();
277:                    if (_o1 instanceof  PjNumber) {
278:                        _n1 = (PjNumber) (_o1);
279:                    } else {
280:                        throw new PdfFormatException(
281:                                "Number (w[x]) expected before d0.");
282:                    }
283:                    _stack.push(new Xd0(_n1, _n2));
284:                } else if (_token.equals("i")) {
285:                    _o1 = _stack.pop();
286:                    if (_o1 instanceof  PjNumber) {
287:                        _n1 = (PjNumber) (_o1);
288:                    } else {
289:                        throw new PdfFormatException(
290:                                "Number (flatness) expected before i.");
291:                    }
292:                    _stack.push(new Xi(_n1));
293:                } else if (_token.equals("g")) {
294:                    _o1 = _stack.pop();
295:                    if (_o1 instanceof  PjNumber) {
296:                        _n1 = (PjNumber) (_o1);
297:                    } else {
298:                        throw new PdfFormatException(
299:                                "Number (gray) expected before g.");
300:                    }
301:                    _stack.push(new Xg(_n1));
302:                } else if (_token.equals("G")) {
303:                    _o1 = _stack.pop();
304:                    if (_o1 instanceof  PjNumber) {
305:                        _n1 = (PjNumber) (_o1);
306:                    } else {
307:                        throw new PdfFormatException(
308:                                "Number (gray) expected before G.");
309:                    }
310:                    _stack.push(new XXG(_n1));
311:                } else if (_token.equals("w")) {
312:                    _o1 = _stack.pop();
313:                    if (_o1 instanceof  PjNumber) {
314:                        _n1 = (PjNumber) (_o1);
315:                    } else {
316:                        throw new PdfFormatException(
317:                                "Number (line width) expected before w.");
318:                    }
319:                    _stack.push(new Xw(_n1));
320:                } else if (_token.equals("Ts")) {
321:                    _o1 = _stack.pop();
322:                    if (_o1 instanceof  PjNumber) {
323:                        _n1 = (PjNumber) (_o1);
324:                    } else {
325:                        throw new PdfFormatException(
326:                                "Number (rise) expected before Ts.");
327:                    }
328:                    _stack.push(new XTs(_n1));
329:                } else if (_token.equals("TL")) {
330:                    _o1 = _stack.pop();
331:                    if (_o1 instanceof  PjNumber) {
332:                        _n1 = (PjNumber) (_o1);
333:                    } else {
334:                        throw new PdfFormatException(
335:                                "Number (leading) expected before TL.");
336:                    }
337:                    _stack.push(new XTL(_n1));
338:                } else if (_token.equals("Tz")) {
339:                    _o1 = _stack.pop();
340:                    if (_o1 instanceof  PjNumber) {
341:                        _n1 = (PjNumber) (_o1);
342:                    } else {
343:                        throw new PdfFormatException(
344:                                "Number (scale) expected before Tz.");
345:                    }
346:                    _stack.push(new XTz(_n1));
347:                } else if (_token.equals("Tw")) {
348:                    _o1 = _stack.pop();
349:                    if (_o1 instanceof  PjNumber) {
350:                        _n1 = (PjNumber) (_o1);
351:                    } else {
352:                        throw new PdfFormatException(
353:                                "Number (word space) expected before Tw.");
354:                    }
355:                    _stack.push(new XTw(_n1));
356:                } else if (_token.equals("Tc")) {
357:                    _o1 = _stack.pop();
358:                    if (_o1 instanceof  PjNumber) {
359:                        _n1 = (PjNumber) (_o1);
360:                    } else {
361:                        throw new PdfFormatException(
362:                                "Number (char space) expected before Tc.");
363:                    }
364:                    _stack.push(new XTc(_n1));
365:                } else if (_token.equals("Tr")) {
366:                    _o1 = _stack.pop();
367:                    if (_o1 instanceof  PjNumber) {
368:                        _n1 = (PjNumber) (_o1);
369:                    } else {
370:                        throw new PdfFormatException(
371:                                "Number (render) expected before Tr.");
372:                    }
373:                    _stack.push(new XTr(_n1));
374:                } else if (_token.equals("j")) {
375:                    _o1 = _stack.pop();
376:                    if (_o1 instanceof  PjNumber) {
377:                        _n1 = (PjNumber) (_o1);
378:                    } else {
379:                        throw new PdfFormatException(
380:                                "Number (line join) expected before j.");
381:                    }
382:                    _stack.push(new Xj(_n1));
383:                } else if (_token.equals("J")) {
384:                    _o1 = _stack.pop();
385:                    if (_o1 instanceof  PjNumber) {
386:                        _n1 = (PjNumber) (_o1);
387:                    } else {
388:                        throw new PdfFormatException(
389:                                "Number (line cap) expected before J.");
390:                    }
391:                    _stack.push(new XXJ(_n1));
392:                } else if (_token.equals("M")) {
393:                    _o1 = _stack.pop();
394:                    if (_o1 instanceof  PjNumber) {
395:                        _n1 = (PjNumber) (_o1);
396:                    } else {
397:                        throw new PdfFormatException(
398:                                "Number (miter limit) expected before M.");
399:                    }
400:                    _stack.push(new XXM(_n1));
401:                } else if (_token.equals("cm")) {
402:                    _o6 = _stack.pop();
403:                    _o5 = _stack.pop();
404:                    _o4 = _stack.pop();
405:                    _o3 = _stack.pop();
406:                    _o2 = _stack.pop();
407:                    _o1 = _stack.pop();
408:                    if ((_o1 instanceof  PjNumber) && (_o2 instanceof  PjNumber)
409:                            && (_o3 instanceof  PjNumber)
410:                            && (_o4 instanceof  PjNumber)
411:                            && (_o5 instanceof  PjNumber)
412:                            && (_o6 instanceof  PjNumber)) {
413:                        _n1 = (PjNumber) _o1;
414:                        _n2 = (PjNumber) _o2;
415:                        _n3 = (PjNumber) _o3;
416:                        _n4 = (PjNumber) _o4;
417:                        _n5 = (PjNumber) _o5;
418:                        _n6 = (PjNumber) _o6;
419:                    } else {
420:                        throw new PdfFormatException(
421:                                "Number expected before cm.");
422:                    }
423:                    _stack.push(new Xcm(_n1, _n2, _n3, _n4, _n5, _n6));
424:                } else if (_token.equals("d1")) {
425:                    _o6 = _stack.pop();
426:                    _o5 = _stack.pop();
427:                    _o4 = _stack.pop();
428:                    _o3 = _stack.pop();
429:                    _o2 = _stack.pop();
430:                    _o1 = _stack.pop();
431:                    if ((_o1 instanceof  PjNumber) && (_o2 instanceof  PjNumber)
432:                            && (_o3 instanceof  PjNumber)
433:                            && (_o4 instanceof  PjNumber)
434:                            && (_o5 instanceof  PjNumber)
435:                            && (_o6 instanceof  PjNumber)) {
436:                        _n1 = (PjNumber) _o1;
437:                        _n2 = (PjNumber) _o2;
438:                        _n3 = (PjNumber) _o3;
439:                        _n4 = (PjNumber) _o4;
440:                        _n5 = (PjNumber) _o5;
441:                        _n6 = (PjNumber) _o6;
442:                    } else {
443:                        throw new PdfFormatException(
444:                                "Number expected before d1.");
445:                    }
446:                    _stack.push(new Xd1(_n1, _n2, _n3, _n4, _n5, _n6));
447:                } else if (_token.equals("c")) {
448:                    _o6 = _stack.pop();
449:                    _o5 = _stack.pop();
450:                    _o4 = _stack.pop();
451:                    _o3 = _stack.pop();
452:                    _o2 = _stack.pop();
453:                    _o1 = _stack.pop();
454:                    if ((_o1 instanceof  PjNumber) && (_o2 instanceof  PjNumber)
455:                            && (_o3 instanceof  PjNumber)
456:                            && (_o4 instanceof  PjNumber)
457:                            && (_o5 instanceof  PjNumber)
458:                            && (_o6 instanceof  PjNumber)) {
459:                        _n1 = (PjNumber) _o1;
460:                        _n2 = (PjNumber) _o2;
461:                        _n3 = (PjNumber) _o3;
462:                        _n4 = (PjNumber) _o4;
463:                        _n5 = (PjNumber) _o5;
464:                        _n6 = (PjNumber) _o6;
465:                    } else {
466:                        throw new PdfFormatException(
467:                                "Number expected before c.");
468:                    }
469:                    _stack.push(new Xc(_n1, _n2, _n3, _n4, _n5, _n6));
470:                } else if (_token.equals("v")) {
471:                    _o4 = _stack.pop();
472:                    _o3 = _stack.pop();
473:                    _o2 = _stack.pop();
474:                    _o1 = _stack.pop();
475:                    if ((_o1 instanceof  PjNumber) && (_o2 instanceof  PjNumber)
476:                            && (_o3 instanceof  PjNumber)
477:                            && (_o4 instanceof  PjNumber)) {
478:                        _n1 = (PjNumber) _o1;
479:                        _n2 = (PjNumber) _o2;
480:                        _n3 = (PjNumber) _o3;
481:                        _n4 = (PjNumber) _o4;
482:                    } else {
483:                        throw new PdfFormatException(
484:                                "Number expected before v.");
485:                    }
486:                    _stack.push(new Xv(_n1, _n2, _n3, _n4));
487:                } else if (_token.equals("y")) {
488:                    _o4 = _stack.pop();
489:                    _o3 = _stack.pop();
490:                    _o2 = _stack.pop();
491:                    _o1 = _stack.pop();
492:                    if ((_o1 instanceof  PjNumber) && (_o2 instanceof  PjNumber)
493:                            && (_o3 instanceof  PjNumber)
494:                            && (_o4 instanceof  PjNumber)) {
495:                        _n1 = (PjNumber) _o1;
496:                        _n2 = (PjNumber) _o2;
497:                        _n3 = (PjNumber) _o3;
498:                        _n4 = (PjNumber) _o4;
499:                    } else {
500:                        throw new PdfFormatException(
501:                                "Number expected before y.");
502:                    }
503:                    _stack.push(new Xy(_n1, _n2, _n3, _n4));
504:                } else if (_token.equals("Tm")) {
505:                    _o6 = _stack.pop();
506:                    _o5 = _stack.pop();
507:                    _o4 = _stack.pop();
508:                    _o3 = _stack.pop();
509:                    _o2 = _stack.pop();
510:                    _o1 = _stack.pop();
511:                    if ((_o1 instanceof  PjNumber) && (_o2 instanceof  PjNumber)
512:                            && (_o3 instanceof  PjNumber)
513:                            && (_o4 instanceof  PjNumber)
514:                            && (_o5 instanceof  PjNumber)
515:                            && (_o6 instanceof  PjNumber)) {
516:                        _n1 = (PjNumber) _o1;
517:                        _n2 = (PjNumber) _o2;
518:                        _n3 = (PjNumber) _o3;
519:                        _n4 = (PjNumber) _o4;
520:                        _n5 = (PjNumber) _o5;
521:                        _n6 = (PjNumber) _o6;
522:                    } else {
523:                        throw new PdfFormatException(
524:                                "Number expected before Tm.");
525:                    }
526:                    _stack.push(new XTm(_n1, _n2, _n3, _n4, _n5, _n6));
527:                } else if (_token.equals("k")) {
528:                    _o4 = _stack.pop();
529:                    _o3 = _stack.pop();
530:                    _o2 = _stack.pop();
531:                    _o1 = _stack.pop();
532:                    if ((_o1 instanceof  PjNumber) && (_o2 instanceof  PjNumber)
533:                            && (_o3 instanceof  PjNumber)
534:                            && (_o4 instanceof  PjNumber)) {
535:                        _n1 = (PjNumber) _o1;
536:                        _n2 = (PjNumber) _o2;
537:                        _n3 = (PjNumber) _o3;
538:                        _n4 = (PjNumber) _o4;
539:                    } else {
540:                        throw new PdfFormatException(
541:                                "Number expected before k.");
542:                    }
543:                    _stack.push(new Xk(_n1, _n2, _n3, _n4));
544:                } else if (_token.equals("K")) {
545:                    _o4 = _stack.pop();
546:                    _o3 = _stack.pop();
547:                    _o2 = _stack.pop();
548:                    _o1 = _stack.pop();
549:                    if ((_o1 instanceof  PjNumber) && (_o2 instanceof  PjNumber)
550:                            && (_o3 instanceof  PjNumber)
551:                            && (_o4 instanceof  PjNumber)) {
552:                        _n1 = (PjNumber) _o1;
553:                        _n2 = (PjNumber) _o2;
554:                        _n3 = (PjNumber) _o3;
555:                        _n4 = (PjNumber) _o4;
556:                    } else {
557:                        throw new PdfFormatException(
558:                                "Number expected before K.");
559:                    }
560:                    _stack.push(new XXK(_n1, _n2, _n3, _n4));
561:                } else if (_token.equals("sc")) {
562:                    _o4 = _stack.pop();
563:                    _o3 = _stack.pop();
564:                    _o2 = _stack.pop();
565:                    if (_stack.peek() instanceof  PjNumber) {
566:                        _o1 = _stack.pop();
567:                    } else {
568:                        _o1 = null;
569:                    }
570:                    if (((_o1 == null) || (_o1 instanceof  PjNumber))
571:                            && (_o2 instanceof  PjNumber)
572:                            && (_o3 instanceof  PjNumber)
573:                            && (_o4 instanceof  PjNumber)) {
574:                        if (_o1 == null) {
575:                            _n1 = (PjNumber) _o2;
576:                            _n2 = (PjNumber) _o3;
577:                            _n3 = (PjNumber) _o4;
578:                            _stack.push(new Xsc(_n1, _n2, _n3));
579:                        } else {
580:                            _n1 = (PjNumber) _o1;
581:                            _n2 = (PjNumber) _o2;
582:                            _n3 = (PjNumber) _o3;
583:                            _n4 = (PjNumber) _o4;
584:                            _stack.push(new Xsc(_n1, _n2, _n3, _n4));
585:                        }
586:                    } else {
587:                        throw new PdfFormatException(
588:                                "Number expected before sc.");
589:                    }
590:                } else if (_token.equals("SC")) {
591:                    _o4 = _stack.pop();
592:                    _o3 = _stack.pop();
593:                    _o2 = _stack.pop();
594:                    if (_stack.peek() instanceof  PjNumber) {
595:                        _o1 = _stack.pop();
596:                    } else {
597:                        _o1 = null;
598:                    }
599:                    if (((_o1 == null) || (_o1 instanceof  PjNumber))
600:                            && (_o2 instanceof  PjNumber)
601:                            && (_o3 instanceof  PjNumber)
602:                            && (_o4 instanceof  PjNumber)) {
603:                        if (_o1 == null) {
604:                            _n1 = (PjNumber) _o2;
605:                            _n2 = (PjNumber) _o3;
606:                            _n3 = (PjNumber) _o4;
607:                            _stack.push(new XXSC(_n1, _n2, _n3));
608:                        } else {
609:                            _n1 = (PjNumber) _o1;
610:                            _n2 = (PjNumber) _o2;
611:                            _n3 = (PjNumber) _o3;
612:                            _n4 = (PjNumber) _o4;
613:                            _stack.push(new XXSC(_n1, _n2, _n3, _n4));
614:                        }
615:                    } else {
616:                        throw new PdfFormatException(
617:                                "Number expected before SC.");
618:                    }
619:                } else if (_token.equals("scn")) {
620:                    // need to handle this
621:                    if (_stack.peek() instanceof  PjName) {
622:                        _stack.pop();
623:                    }
624:                    while (_stack.peek() instanceof  PjNumber) {
625:                        _stack.pop();
626:                    }
627:                } else if (_token.equals("rg")) {
628:                    _o3 = _stack.pop();
629:                    _o2 = _stack.pop();
630:                    _o1 = _stack.pop();
631:                    if ((_o1 instanceof  PjNumber) && (_o2 instanceof  PjNumber)
632:                            && (_o3 instanceof  PjNumber)) {
633:                        _n1 = (PjNumber) _o1;
634:                        _n2 = (PjNumber) _o2;
635:                        _n3 = (PjNumber) _o3;
636:                    } else {
637:                        throw new PdfFormatException(
638:                                "Number expected before rg.");
639:                    }
640:                    _stack.push(new Xrg(_n1, _n2, _n3));
641:                } else if (_token.equals("RG")) {
642:                    _o3 = _stack.pop();
643:                    _o2 = _stack.pop();
644:                    _o1 = _stack.pop();
645:                    if ((_o1 instanceof  PjNumber) && (_o2 instanceof  PjNumber)
646:                            && (_o3 instanceof  PjNumber)) {
647:                        _n1 = (PjNumber) _o1;
648:                        _n2 = (PjNumber) _o2;
649:                        _n3 = (PjNumber) _o3;
650:                    } else {
651:                        throw new PdfFormatException(
652:                                "Number expected before RG.");
653:                    }
654:                    _stack.push(new XXRG(_n1, _n2, _n3));
655:                } else if (_token.equals("re")) {
656:                    _o4 = _stack.pop();
657:                    _o3 = _stack.pop();
658:                    _o2 = _stack.pop();
659:                    _o1 = _stack.pop();
660:                    if ((_o1 instanceof  PjNumber) && (_o2 instanceof  PjNumber)
661:                            && (_o3 instanceof  PjNumber)
662:                            && (_o4 instanceof  PjNumber)) {
663:                        _n1 = (PjNumber) _o1;
664:                        _n2 = (PjNumber) _o2;
665:                        _n3 = (PjNumber) _o3;
666:                        _n4 = (PjNumber) _o4;
667:                    } else {
668:                        throw new PdfFormatException(
669:                                "Number expected before re.");
670:                    }
671:                    _stack.push(new Xre(_n1, _n2, _n3, _n4));
672:                } else if (_token.equals("Tf")) {
673:                    _o1 = _stack.pop();
674:                    if (_o1 instanceof  PjNumber) {
675:                        _n1 = (PjNumber) (_o1);
676:                    } else {
677:                        throw new PdfFormatException(
678:                                "Number (font size) expected before Tf.");
679:                    }
680:                    _o1 = _stack.pop();
681:                    if (_o1 instanceof  PjName) {
682:                        _m1 = (PjName) (_o1);
683:                    } else {
684:                        throw new PdfFormatException(
685:                                "Name (font name) expected before Tf.");
686:                    }
687:                    _stack.push(new XTf(_m1, _n1));
688:                } else if (_token.equals("\"")) {
689:                    _o1 = _stack.pop();
690:                    if (_o1 instanceof  PjString) {
691:                        _s1 = (PjString) (_o1);
692:                    } else {
693:                        throw new PdfFormatException(
694:                                "String (text) expected before \".");
695:                    }
696:                    _o1 = _stack.pop();
697:                    if (_o1 instanceof  PjNumber) {
698:                        _n2 = (PjNumber) (_o1);
699:                    } else {
700:                        throw new PdfFormatException(
701:                                "Number (a[c]) expected before \".");
702:                    }
703:                    _o1 = _stack.pop();
704:                    if (_o1 instanceof  PjNumber) {
705:                        _n1 = (PjNumber) (_o1);
706:                    } else {
707:                        throw new PdfFormatException(
708:                                "Number (a[w]) expected before \".");
709:                    }
710:                    _stack.push(new Xquot(_n1, _n2, _s1));
711:                } else if (_token.equals("BMC")) {
712:                    _o1 = _stack.pop();
713:                    if (_o1 instanceof  PjName) {
714:                        _m1 = (PjName) (_o1);
715:                    } else {
716:                        throw new PdfFormatException(
717:                                "Name (tag) expected before BMC.");
718:                    }
719:                    _stack.push(new XBMC(_m1));
720:                } else if (_token.equals("MP")) {
721:                    _o1 = _stack.pop();
722:                    if (_o1 instanceof  PjName) {
723:                        _m1 = (PjName) (_o1);
724:                    } else {
725:                        throw new PdfFormatException(
726:                                "Name (tag) expected before MP.");
727:                    }
728:                    _stack.push(new XMP(_m1));
729:                } else if (_token.equals("gs")) {
730:                    _o1 = _stack.pop();
731:                    if (_o1 instanceof  PjName) {
732:                        _m1 = (PjName) (_o1);
733:                    } else {
734:                        throw new PdfFormatException(
735:                                "Name (name) expected before gs.");
736:                    }
737:                    _stack.push(new Xgs(_m1));
738:                } else if (_token.equals("Do")) {
739:                    _o1 = _stack.pop();
740:                    if (_o1 instanceof  PjName) {
741:                        _m1 = (PjName) (_o1);
742:                    } else {
743:                        throw new PdfFormatException(
744:                                "Name (XObject) expected before Do.");
745:                    }
746:                    _stack.push(new XDo(_m1));
747:                } else if (_token.equals("cs")) {
748:                    _o1 = _stack.pop();
749:                    if (_o1 instanceof  PjName) {
750:                        _m1 = (PjName) (_o1);
751:                    } else {
752:                        throw new PdfFormatException(
753:                                "Name (color space) expected before cs.");
754:                    }
755:                    _stack.push(new Xcs(_m1));
756:                } else if (_token.equals("CS")) {
757:                    _o1 = _stack.pop();
758:                    if (_o1 instanceof  PjName) {
759:                        _m1 = (PjName) (_o1);
760:                    } else {
761:                        throw new PdfFormatException(
762:                                "Name (color space) expected before CS.");
763:                    }
764:                    _stack.push(new XXCS(_m1));
765:                } else if (_token.equals("d")) {
766:                    _o1 = _stack.pop();
767:                    if (_o1 instanceof  PjNumber) {
768:                        _n1 = (PjNumber) (_o1);
769:                    } else {
770:                        throw new PdfFormatException(
771:                                "Number (phase) expected before d.");
772:                    }
773:                    _o1 = _stack.pop();
774:                    if (_o1 instanceof  PjArray) {
775:                        _a1 = (PjArray) (_o1);
776:                    } else {
777:                        throw new PdfFormatException(
778:                                "Array (dash pattern) expected before d.");
779:                    }
780:                    _stack.push(new Xd(_a1, _n1));
781:                } else if (_token.equals("TJ")) {
782:                    _o1 = _stack.pop();
783:                    if (_o1 instanceof  PjArray) {
784:                        _a1 = (PjArray) (_o1);
785:                    } else {
786:                        throw new PdfFormatException(
787:                                "Array expected before TJ.");
788:                    }
789:                    _stack.push(new XXTJ(_a1));
790:                } else if (_token.equals("BDC")) {
791:                    _o1 = _stack.pop();
792:                    if ((!(_o1 instanceof  PjName))
793:                            && (!(_o1 instanceof  PjDictionary))) {
794:                        throw new PdfFormatException(
795:                                "Name or dictionary (property list) expected before BDC.");
796:                    }
797:                    _o2 = _stack.pop();
798:                    if (_o2 instanceof  PjName) {
799:                        _m1 = (PjName) (_o2);
800:                    } else {
801:                        throw new PdfFormatException(
802:                                "Name (tag) expected before BDC.");
803:                    }
804:                    if (_o1 instanceof  PjName) {
805:                        _stack.push(new XBDC(_m1, (PjName) (_o1)));
806:                    } else {
807:                        _stack.push(new XBDC(_m1, (PjDictionary) (_o1)));
808:                    }
809:                } else if (_token.equals("DP")) {
810:                    _o1 = _stack.pop();
811:                    if ((!(_o1 instanceof  PjName))
812:                            && (!(_o1 instanceof  PjDictionary))) {
813:                        throw new PdfFormatException(
814:                                "Name or dictionary (property list) expected before DP.");
815:                    }
816:                    _o2 = _stack.pop();
817:                    if (_o2 instanceof  PjName) {
818:                        _m1 = (PjName) (_o2);
819:                    } else {
820:                        throw new PdfFormatException(
821:                                "Name (tag) expected before DP.");
822:                    }
823:                    if (_o1 instanceof  PjName) {
824:                        _stack.push(new XDP(_m1, (PjName) (_o1)));
825:                    } else {
826:                        _stack.push(new XDP(_m1, (PjDictionary) (_o1)));
827:                    }
828:                } else if (_token.equals("Tj")) {
829:                    _o1 = _stack.pop();
830:                    if (_o1 instanceof  PjString) {
831:                        _s1 = (PjString) (_o1);
832:                    } else {
833:                        throw new PdfFormatException(
834:                                "String (text) expected before Tj.");
835:                    }
836:                    _stack.push(new XTj(_s1));
837:                } else if (_token.equals("'")) {
838:                    _o1 = _stack.pop();
839:                    if (_o1 instanceof  PjString) {
840:                        _s1 = (PjString) (_o1);
841:                    } else {
842:                        throw new PdfFormatException(
843:                                "String (text) expected before '.");
844:                    }
845:                    _stack.push(new Xapost(_s1));
846:                } else if (_token.equals("n")) {
847:                    _stack.push(new Xn());
848:                } else if (_token.equals("s")) {
849:                    _stack.push(new Xs());
850:                } else if (_token.equals("S")) {
851:                    _stack.push(new XXS());
852:                } else if (_token.equals("T*")) {
853:                    _stack.push(new XTstar());
854:                } else if ((_token.equals("f")) || (_token.equals("F"))) {
855:                    _stack.push(new Xf());
856:                } else if (_token.equals("f*")) {
857:                    _stack.push(new Xfstar());
858:                } else if (_token.equals("b")) {
859:                    _stack.push(new Xb());
860:                } else if (_token.equals("W")) {
861:                    _stack.push(new XXW());
862:                } else if (_token.equals("W*")) {
863:                    _stack.push(new XWstar());
864:                } else if (_token.equals("b*")) {
865:                    _stack.push(new Xbstar());
866:                } else if (_token.equals("B")) {
867:                    _stack.push(new XXB());
868:                } else if (_token.equals("B*")) {
869:                    _stack.push(new XXBstar());
870:                } else if (_token.equals("h")) {
871:                    _stack.push(new Xh());
872:                } else if (_token.equals("q")) {
873:                    _stack.push(new Xq());
874:                } else if (_token.equals("Q")) {
875:                    _stack.push(new XXQ());
876:                } else if (_token.equals("BX")) {
877:                    _stack.push(new XBX());
878:                } else if (_token.equals("EX")) {
879:                    _stack.push(new XEX());
880:                } else if (_token.equals("EMC")) {
881:                    _stack.push(new XEMC());
882:                } else if (_token.charAt(0) == '/') {
883:                    _stack.push(new PjName(_token.substring(1)));
884:                } else if ((Character.isDigit(_token.charAt(0)))
885:                        || (_token.charAt(0) == '-')
886:                        || (_token.charAt(0) == '.')) {
887:                    _stack.push(new PjNumber(new Float(_token).floatValue()));
888:                } else if (_token.charAt(0) == '(') {
889:                    _stack.push(new PjString(PjString.decodePdf(_token)));
890:                } else if (_token.equals("<<")) {
891:                    _stack.push("<<");
892:                } else if (_token.equals("[")) {
893:                    _stack.push("[");
894:                } else if (_token.equals("]")) {
895:                    _b1 = false;
896:                    _v1 = new Vector();
897:                    while (!_b1) {
898:                        _o1 = _stack.pop();
899:                        if ((_o1 instanceof  String)
900:                                && (((String) _o1).equals("["))) {
901:                            _b1 = true;
902:                        } else {
903:                            if (!(_o1 instanceof  PjObject)) {
904:                                throw new PdfFormatException(
905:                                        "PDF object expected within array.");
906:                            }
907:                            _v1.insertElementAt(_o1, 0);
908:                        }
909:                    }
910:                    _stack.push(new PjArray(_v1));
911:                } else if (_token.equals("true")) {
912:                    _stack.push(new PjBoolean(true));
913:                } else if (_token.equals("false")) {
914:                    _stack.push(new PjBoolean(false));
915:                } else if ((_token.equals("scn")) || (_token.equals("SCN"))
916:                        || (_token.equals("sh")) || (_token.equals("ri"))) {
917:                    // temporary fix for these operators
918:                    _stack.pop();
919:                } else if (_token.startsWith("%%")) {
920:                    // do nothing
921:                } else {
922:                    throw new PdfFormatException("Token \"" + _token
923:                            + "\" not recognized.");
924:                }
925:            }
926:
927:            private String _token;
928:            private byte[] _imageData;
929:            private Stack _stack;
930:            private int _counter;
931:            private byte[] _buffer;
932:            private boolean _image;
933:
934:            private PjNumber _n1, _n2, _n3, _n4, _n5, _n6;
935:            private Stack _k1;
936:            private boolean _b1;
937:            private int _x1, _x2;
938:            private Vector _v1;
939:            private Object _o1, _o2, _o3, _o4, _o5, _o6;
940:            private PjName _m1;
941:            private PjString _s1;
942:            private PjArray _a1;
943:            private Hashtable _h1;
944:
945:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.