Source Code Cross Referenced for CSDeviceAdapter.java in  » PDF » jPod » de » intarsys » pdf » content » 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 » jPod » de.intarsys.pdf.content 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2007, intarsys consulting GmbH
003:         *
004:         * Redistribution and use in source and binary forms, with or without
005:         * modification, are permitted provided that the following conditions are met:
006:         *
007:         * - Redistributions of source code must retain the above copyright notice,
008:         *   this list of conditions and the following disclaimer.
009:         *
010:         * - Redistributions in binary form must reproduce the above copyright notice,
011:         *   this list of conditions and the following disclaimer in the documentation
012:         *   and/or other materials provided with the distribution.
013:         *
014:         * - Neither the name of intarsys nor the names of its contributors may be used
015:         *   to endorse or promote products derived from this software without specific
016:         *   prior written permission.
017:         *
018:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019:         * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
020:         * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
021:         * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
022:         * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
023:         * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
024:         * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
025:         * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
026:         * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
027:         * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
028:         * POSSIBILITY OF SUCH DAMAGE.
029:         */
030:        package de.intarsys.pdf.content;
031:
032:        import java.awt.geom.AffineTransform;
033:        import java.io.ByteArrayOutputStream;
034:        import java.io.CharArrayReader;
035:        import java.io.IOException;
036:        import java.io.Writer;
037:
038:        import de.intarsys.pdf.cds.CDSMatrix;
039:        import de.intarsys.pdf.cds.CDSRectangle;
040:        import de.intarsys.pdf.cos.COSDictionary;
041:        import de.intarsys.pdf.cos.COSName;
042:        import de.intarsys.pdf.cos.COSRuntimeException;
043:        import de.intarsys.pdf.encoding.Encoding;
044:        import de.intarsys.pdf.font.PDFont;
045:        import de.intarsys.pdf.pd.PDCSDeviceCMYK;
046:        import de.intarsys.pdf.pd.PDCSDeviceGray;
047:        import de.intarsys.pdf.pd.PDCSDeviceRGB;
048:        import de.intarsys.pdf.pd.PDColorSpace;
049:        import de.intarsys.pdf.pd.PDExtGState;
050:        import de.intarsys.pdf.pd.PDForm;
051:        import de.intarsys.pdf.pd.PDImage;
052:        import de.intarsys.pdf.pd.PDPattern;
053:        import de.intarsys.pdf.pd.PDPostScript;
054:        import de.intarsys.pdf.pd.PDShading;
055:        import de.intarsys.pdf.pd.PDXObject;
056:        import de.intarsys.tools.stream.StreamTools;
057:
058:        /**
059:         * An adapter implementation for ICSDevice. This can be used as a simple
060:         * superclass for implementing PDF content stream aware devices.
061:         * <p>
062:         */
063:        abstract public class CSDeviceAdapter implements  ICSDevice {
064:            /**
065:             * the maximum number of nested states
066:             */
067:            public static int MAX_STACK_SIZE = 500;
068:
069:            /**
070:             * The currently active {@link GraphicsState}.
071:             */
072:            protected GraphicsState graphicsState;
073:
074:            /**
075:             * the {@link GraphicsState} stack.
076:             */
077:            private GraphicsState[] stack = new GraphicsState[MAX_STACK_SIZE];
078:
079:            /** The current stack pointer */
080:            private int stackPtr = 0;
081:
082:            private ICSInterpreter interpreter;
083:
084:            /**
085:             * Create a new {@link CSDeviceAdapter}
086:             */
087:            public CSDeviceAdapter() {
088:                //
089:            }
090:
091:            /*
092:             * (non-Javadoc)
093:             * 
094:             * @see de.intarsys.pdf.content.ICSDevice#close()
095:             */
096:            public void close() {
097:                this .interpreter = null;
098:            }
099:
100:            /*
101:             * (non-Javadoc)
102:             * 
103:             * @see de.intarsys.pdf.content.ICSDevice#compatibilityBegin()
104:             */
105:            public void compatibilityBegin() {
106:                // redefine
107:            }
108:
109:            /*
110:             * (non-Javadoc)
111:             * 
112:             * @see de.intarsys.pdf.content.ICSDevice#compatibilityEnd()
113:             */
114:            public void compatibilityEnd() {
115:                // redefine
116:            }
117:
118:            protected GraphicsState createGraphicsState() {
119:                return new GraphicsState();
120:            }
121:
122:            protected void doForm(COSName name, PDForm form) throws CSException {
123:                saveState();
124:                try {
125:                    CDSMatrix m = form.getMatrix();
126:                    if (m != null) {
127:                        transform(m.getA(), m.getB(), m.getC(), m.getD(), m
128:                                .getE(), m.getF());
129:                    }
130:                    CDSRectangle r = form.getBoundingBox();
131:                    if (r != null) {
132:                        // todo 1 clip
133:                    }
134:                    if (interpreter != null) {
135:                        interpreter.process(form.getContentStream(), form
136:                                .getResources());
137:                    }
138:                } finally {
139:                    restoreState();
140:                }
141:            }
142:
143:            protected void doImage(COSName name, PDImage image)
144:                    throws CSException {
145:                // override in subclass
146:            }
147:
148:            protected void doPostScript(COSName name, PDPostScript postscript)
149:                    throws CSException {
150:                // override in subclass
151:            }
152:
153:            /*
154:             * (non-Javadoc)
155:             * 
156:             * @see de.intarsys.pdf.content.ICSDevice#doShading(de.intarsys.pdf.cos.COSName,
157:             *      de.intarsys.pdf.pd.PDShading)
158:             */
159:            public void doShading(COSName name, PDShading shading) {
160:                // override in subclass
161:            }
162:
163:            /*
164:             * (non-Javadoc)
165:             * 
166:             * @see de.intarsys.pdf.content.ICSDevice#doXObject(de.intarsys.pdf.cos.COSName,
167:             *      de.intarsys.pdf.pd.PDXObject)
168:             */
169:            public void doXObject(COSName name, PDXObject xobject) {
170:                if (xobject == null) {
171:                    return;
172:                }
173:                if (xobject.isForm()) {
174:                    try {
175:                        doForm(name, (PDForm) xobject);
176:                    } catch (CSException e) {
177:                        throw e;
178:                    } catch (Exception e) {
179:                        throw new CSError("Unexpected error rendering form", e); //$NON-NLS-1$
180:                    }
181:                } else if (xobject.isImage()) {
182:                    try {
183:                        doImage(name, (PDImage) xobject);
184:                    } catch (CSException e) {
185:                        throw e;
186:                    } catch (Exception e) {
187:                        throw new CSError("Unexpected error rendering image", e); //$NON-NLS-1$
188:                    }
189:                } else if (xobject.isPostscript()) {
190:                    try {
191:                        doPostScript(name, (PDPostScript) xobject);
192:                    } catch (CSException e) {
193:                        throw e;
194:                    } catch (Exception e) {
195:                        throw new CSError(
196:                                "Unexpected error rendering postscript", e); //$NON-NLS-1$
197:                    }
198:                } else {
199:                    throw new CSNotSupported("unknown XObject type"); //$NON-NLS-1$
200:                }
201:            }
202:
203:            /*
204:             * (non-Javadoc)
205:             * 
206:             * @see de.intarsys.pdf.content.ICSDevice#getInterpreter()
207:             */
208:            public ICSInterpreter getInterpreter() {
209:                return interpreter;
210:            }
211:
212:            /*
213:             * (non-Javadoc)
214:             * 
215:             * @see de.intarsys.pdf.content.ICSDevice#inlineImage(de.intarsys.pdf.pd.PDImage)
216:             */
217:            public void inlineImage(PDImage img) {
218:                // redefine
219:            }
220:
221:            /*
222:             * (non-Javadoc)
223:             * 
224:             * @see de.intarsys.pdf.content.ICSDevice#markedContentBegin(de.intarsys.pdf.cos.COSName)
225:             */
226:            public void markedContentBegin(COSName tag) {
227:                // redefine
228:            }
229:
230:            /*
231:             * (non-Javadoc)
232:             * 
233:             * @see de.intarsys.pdf.content.ICSDevice#markedContentBeginProperties(de.intarsys.pdf.cos.COSName,
234:             *      de.intarsys.pdf.cos.COSName, de.intarsys.pdf.cos.COSDictionary)
235:             */
236:            public void markedContentBeginProperties(COSName tag,
237:                    COSName resourceName, COSDictionary properties) {
238:                // redefine
239:            }
240:
241:            /*
242:             * (non-Javadoc)
243:             * 
244:             * @see de.intarsys.pdf.content.ICSDevice#markedContentEnd()
245:             */
246:            public void markedContentEnd() {
247:                // redefine
248:            }
249:
250:            /*
251:             * (non-Javadoc)
252:             * 
253:             * @see de.intarsys.pdf.content.ICSDevice#markedContentPoint(de.intarsys.pdf.cos.COSName)
254:             */
255:            public void markedContentPoint(COSName tag) {
256:                // redefine
257:            }
258:
259:            /*
260:             * (non-Javadoc)
261:             * 
262:             * @see de.intarsys.pdf.content.ICSDevice#markedContentPointProperties(de.intarsys.pdf.cos.COSName,
263:             *      de.intarsys.pdf.cos.COSName, de.intarsys.pdf.cos.COSDictionary)
264:             */
265:            public void markedContentPointProperties(COSName tag,
266:                    COSName resourceName, COSDictionary properties) {
267:                // redefine
268:            }
269:
270:            /*
271:             * (non-Javadoc)
272:             * 
273:             * @see de.intarsys.pdf.content.ICSDevice#open(de.intarsys.pdf.content.ICSInterpreter)
274:             */
275:            public void open(ICSInterpreter pInterpreter) {
276:                this .interpreter = pInterpreter;
277:                this .graphicsState = createGraphicsState();
278:            }
279:
280:            /*
281:             * (non-Javadoc)
282:             * 
283:             * @see de.intarsys.pdf.content.ICSDevice#pathClipEvenOdd()
284:             */
285:            public void pathClipEvenOdd() {
286:                // redefine
287:            }
288:
289:            /*
290:             * (non-Javadoc)
291:             * 
292:             * @see de.intarsys.pdf.content.ICSDevice#pathClipNonZero()
293:             */
294:            public void pathClipNonZero() {
295:                // redefine
296:            }
297:
298:            /*
299:             * (non-Javadoc)
300:             * 
301:             * @see de.intarsys.pdf.content.ICSDevice#pathClose()
302:             */
303:            public void pathClose() {
304:                // redefine
305:            }
306:
307:            /*
308:             * (non-Javadoc)
309:             * 
310:             * @see de.intarsys.pdf.content.ICSDevice#pathCloseFillStrokeEvenOdd()
311:             */
312:            public void pathCloseFillStrokeEvenOdd() {
313:                // redefine
314:            }
315:
316:            /*
317:             * (non-Javadoc)
318:             * 
319:             * @see de.intarsys.pdf.content.ICSDevice#pathCloseFillStrokeNonZero()
320:             */
321:            public void pathCloseFillStrokeNonZero() {
322:                // redefine
323:            }
324:
325:            /*
326:             * (non-Javadoc)
327:             * 
328:             * @see de.intarsys.pdf.content.ICSDevice#pathCloseStroke()
329:             */
330:            public void pathCloseStroke() {
331:                // redefine
332:            }
333:
334:            /*
335:             * (non-Javadoc)
336:             * 
337:             * @see de.intarsys.pdf.content.ICSDevice#pathEnd()
338:             */
339:            public void pathEnd() {
340:                // redefine
341:            }
342:
343:            /*
344:             * (non-Javadoc)
345:             * 
346:             * @see de.intarsys.pdf.content.ICSDevice#pathFillEvenOdd()
347:             */
348:            public void pathFillEvenOdd() {
349:                // redefine
350:            }
351:
352:            /*
353:             * (non-Javadoc)
354:             * 
355:             * @see de.intarsys.pdf.content.ICSDevice#pathFillNonZero()
356:             */
357:            public void pathFillNonZero() {
358:                // redefine
359:            }
360:
361:            /*
362:             * (non-Javadoc)
363:             * 
364:             * @see de.intarsys.pdf.content.ICSDevice#pathFillStrokeEvenOdd()
365:             */
366:            public void pathFillStrokeEvenOdd() {
367:                // redefine
368:            }
369:
370:            /*
371:             * (non-Javadoc)
372:             * 
373:             * @see de.intarsys.pdf.content.ICSDevice#pathFillStrokeNonZero()
374:             */
375:            public void pathFillStrokeNonZero() {
376:                // redefine
377:            }
378:
379:            /*
380:             * (non-Javadoc)
381:             * 
382:             * @see de.intarsys.pdf.content.ICSDevice#pathStroke()
383:             */
384:            public void pathStroke() {
385:                // redefine
386:            }
387:
388:            /*
389:             * (non-Javadoc)
390:             * 
391:             * @see de.intarsys.pdf.content.ICSDevice#penCurveToC(float, float, float,
392:             *      float, float, float)
393:             */
394:            public void penCurveToC(float x1, float y1, float x2, float y2,
395:                    float x3, float y3) {
396:                // redefine
397:            }
398:
399:            /*
400:             * (non-Javadoc)
401:             * 
402:             * @see de.intarsys.pdf.content.ICSDevice#penCurveToV(float, float, float,
403:             *      float)
404:             */
405:            public void penCurveToV(float x2, float y2, float x3, float y3) {
406:                // redefine
407:            }
408:
409:            /*
410:             * (non-Javadoc)
411:             * 
412:             * @see de.intarsys.pdf.content.ICSDevice#penCurveToY(float, float, float,
413:             *      float)
414:             */
415:            public void penCurveToY(float x1, float y1, float x3, float y3) {
416:                // redefine
417:            }
418:
419:            /*
420:             * (non-Javadoc)
421:             * 
422:             * @see de.intarsys.pdf.content.ICSDevice#penLineTo(float, float)
423:             */
424:            public void penLineTo(float x, float y) {
425:                // redefine
426:            }
427:
428:            /*
429:             * (non-Javadoc)
430:             * 
431:             * @see de.intarsys.pdf.content.ICSDevice#penMoveTo(float, float)
432:             */
433:            public void penMoveTo(float x, float y) {
434:                // redefine
435:            }
436:
437:            /*
438:             * (non-Javadoc)
439:             * 
440:             * @see de.intarsys.pdf.content.ICSDevice#penRectangle(float, float, float,
441:             *      float)
442:             */
443:            public void penRectangle(float x, float y, float w, float h) {
444:                // redefine
445:            }
446:
447:            /*
448:             * (non-Javadoc)
449:             * 
450:             * @see de.intarsys.pdf.content.ICSDevice#restoreState()
451:             */
452:            public void restoreState() {
453:                if (stackPtr == 0) {
454:                    throw new RuntimeException("stack underflow"); //$NON-NLS-1$
455:                }
456:                stackPtr--;
457:                GraphicsState oldState = stack[stackPtr];
458:                // todo 2 @mit performance clear at end of process
459:                // oldState.clear();
460:                graphicsState = oldState;
461:            }
462:
463:            /*
464:             * (non-Javadoc)
465:             * 
466:             * @see de.intarsys.pdf.content.ICSDevice#saveState()
467:             */
468:            public void saveState() {
469:                if (stackPtr == MAX_STACK_SIZE) {
470:                    throw new RuntimeException("stack overflow"); //$NON-NLS-1$
471:                }
472:                GraphicsState newState = graphicsState.copy();
473:                stack[stackPtr++] = newState;
474:            }
475:
476:            /*
477:             * (non-Javadoc)
478:             * 
479:             * @see de.intarsys.pdf.content.ICSDevice#setExtendedState(de.intarsys.pdf.cos.COSName,
480:             *      de.intarsys.pdf.pd.PDExtGState)
481:             */
482:            public void setExtendedState(COSName name, PDExtGState gstate) {
483:                graphicsState.setExtendedState(gstate);
484:            }
485:
486:            /*
487:             * (non-Javadoc)
488:             * 
489:             * @see de.intarsys.pdf.content.ICSDevice#setFlatnessTolerance(float)
490:             */
491:            public void setFlatnessTolerance(float flatness) {
492:                // redefine
493:            }
494:
495:            /*
496:             * (non-Javadoc)
497:             * 
498:             * @see de.intarsys.pdf.content.ICSDevice#setLineCap(int)
499:             */
500:            public void setLineCap(int capStyle) {
501:                graphicsState.setCapStyle(capStyle);
502:            }
503:
504:            /*
505:             * (non-Javadoc)
506:             * 
507:             * @see de.intarsys.pdf.content.ICSDevice#setDash(float[], float)
508:             */
509:            public void setLineDash(float[] pattern, float phase) {
510:                graphicsState.setDash(pattern, phase);
511:            }
512:
513:            /*
514:             * (non-Javadoc)
515:             * 
516:             * @see de.intarsys.pdf.content.ICSDevice#setLineJoin(int)
517:             */
518:            public void setLineJoin(int joinStyle) {
519:                graphicsState.setJoinStyle(joinStyle);
520:            }
521:
522:            /*
523:             * (non-Javadoc)
524:             * 
525:             * @see de.intarsys.pdf.content.ICSDevice#setLineWidth(float)
526:             */
527:            public void setLineWidth(float lineWidth) {
528:                graphicsState.setLineWidth(lineWidth);
529:            }
530:
531:            /*
532:             * (non-Javadoc)
533:             * 
534:             * @see de.intarsys.pdf.content.ICSDevice#setMiterLimit(float)
535:             */
536:            public void setMiterLimit(float miterLimit) {
537:                graphicsState.setMiterLimit(miterLimit);
538:            }
539:
540:            /*
541:             * (non-Javadoc)
542:             * 
543:             * @see de.intarsys.pdf.content.ICSDevice#setNonStrokeColorCMYK(float,
544:             *      float, float, float)
545:             */
546:            public void setNonStrokeColorCMYK(float c, float m, float y, float k) {
547:                PDColorSpace colorSpace = PDCSDeviceCMYK.SINGLETON;
548:                setNonStrokeColorSpace(null, colorSpace);
549:                setNonStrokeColorValues(new float[] { c, m, y, k });
550:            }
551:
552:            /*
553:             * (non-Javadoc)
554:             * 
555:             * @see de.intarsys.pdf.content.ICSDevice#setNonStrokeColorGray(float)
556:             */
557:            public void setNonStrokeColorGray(float gray) {
558:                PDColorSpace colorSpace = PDCSDeviceGray.SINGLETON;
559:                setNonStrokeColorSpace(null, colorSpace);
560:                setNonStrokeColorValues(new float[] { gray });
561:            }
562:
563:            /*
564:             * (non-Javadoc)
565:             * 
566:             * @see de.intarsys.pdf.content.ICSDevice#setNonStrokeColorRGB(float, float,
567:             *      float)
568:             */
569:            public void setNonStrokeColorRGB(float r, float g, float b) {
570:                PDColorSpace colorSpace = PDCSDeviceRGB.SINGLETON;
571:                setNonStrokeColorSpace(null, colorSpace);
572:                setNonStrokeColorValues(new float[] { r, g, b });
573:            }
574:
575:            /*
576:             * (non-Javadoc)
577:             * 
578:             * @see de.intarsys.pdf.content.ICSDevice#setNonStrokeColorSpace(de.intarsys.pdf.cos.COSName,
579:             *      de.intarsys.pdf.pd.PDColorSpace)
580:             */
581:            public void setNonStrokeColorSpace(COSName name,
582:                    PDColorSpace colorSpace) {
583:                graphicsState.setNonStrokeColorSpace(colorSpace);
584:            }
585:
586:            /*
587:             * (non-Javadoc)
588:             * 
589:             * @see de.intarsys.pdf.content.ICSDevice#setNonStrokeColorValues(float[])
590:             */
591:            public void setNonStrokeColorValues(float[] values) {
592:                graphicsState.setNonStrokeColorValues(values);
593:            }
594:
595:            /*
596:             * (non-Javadoc)
597:             * 
598:             * @see de.intarsys.pdf.content.ICSDevice#setNonStrokePatternValues(float[],
599:             *      de.intarsys.pdf.pd.PDPattern)
600:             */
601:            public void setNonStrokeColorValues(float[] values, COSName name,
602:                    PDPattern pattern) {
603:                // override in subclass
604:            }
605:
606:            /*
607:             * (non-Javadoc)
608:             * 
609:             * @see de.intarsys.pdf.content.ICSDevice#setRenderingIntent(de.intarsys.pdf.cos.COSName)
610:             */
611:            public void setRenderingIntent(COSName intent) {
612:            }
613:
614:            /*
615:             * (non-Javadoc)
616:             * 
617:             * @see de.intarsys.pdf.content.ICSDevice#setStrokeColorCMYK(float, float,
618:             *      float, float)
619:             */
620:            public void setStrokeColorCMYK(float c, float m, float y, float k) {
621:                PDColorSpace colorSpace = PDCSDeviceCMYK.SINGLETON;
622:                setStrokeColorSpace(null, colorSpace);
623:                setStrokeColorValues(new float[] { c, m, y, k });
624:            }
625:
626:            /*
627:             * (non-Javadoc)
628:             * 
629:             * @see de.intarsys.pdf.content.ICSDevice#setStrokeColorGray(float)
630:             */
631:            public void setStrokeColorGray(float gray) {
632:                PDColorSpace colorSpace = PDCSDeviceGray.SINGLETON;
633:                setStrokeColorSpace(null, colorSpace);
634:                setStrokeColorValues(new float[] { gray });
635:            }
636:
637:            /*
638:             * (non-Javadoc)
639:             * 
640:             * @see de.intarsys.pdf.content.ICSDevice#setStrokeColorRGB(float, float,
641:             *      float)
642:             */
643:            public void setStrokeColorRGB(float r, float g, float b) {
644:                PDColorSpace colorSpace = PDCSDeviceRGB.SINGLETON;
645:                setStrokeColorSpace(null, colorSpace);
646:                setStrokeColorValues(new float[] { r, g, b });
647:            }
648:
649:            /*
650:             * (non-Javadoc)
651:             * 
652:             * @see de.intarsys.pdf.content.ICSDevice#setStrokeColorSpace(de.intarsys.pdf.cos.COSName,
653:             *      de.intarsys.pdf.pd.PDColorSpace)
654:             */
655:            public void setStrokeColorSpace(COSName name,
656:                    PDColorSpace colorSpace) {
657:                graphicsState.setStrokeColorSpace(colorSpace);
658:                // override in subclass
659:            }
660:
661:            /*
662:             * (non-Javadoc)
663:             * 
664:             * @see de.intarsys.pdf.content.ICSDevice#setStrokeColorValues(float[])
665:             */
666:            public void setStrokeColorValues(float[] values) {
667:                graphicsState.setStrokeColorValues(values);
668:            }
669:
670:            /*
671:             * (non-Javadoc)
672:             * 
673:             * @see de.intarsys.pdf.content.ICSDevice#setStrokePatternValues(float[],
674:             *      de.intarsys.pdf.cos.COSName, de.intarsys.pdf.pd.PDPattern)
675:             */
676:            public void setStrokeColorValues(float[] values, COSName name,
677:                    PDPattern pattern) {
678:                // override in subclass
679:            }
680:
681:            /*
682:             * (non-Javadoc)
683:             * 
684:             * @see de.intarsys.pdf.content.ICSDevice#textBegin()
685:             */
686:            public void textBegin() {
687:                graphicsState.textState.begin();
688:            }
689:
690:            /*
691:             * (non-Javadoc)
692:             * 
693:             * @see de.intarsys.pdf.content.ICSDevice#textEnd()
694:             */
695:            public void textEnd() {
696:                graphicsState.textState.end();
697:            }
698:
699:            /*
700:             * (non-Javadoc)
701:             * 
702:             * @see de.intarsys.pdf.content.ICSDevice#textLineMove(float, float)
703:             */
704:            public void textLineMove(float dex, float dy) {
705:                graphicsState.textState.tlmMove(dex, dy);
706:            }
707:
708:            /*
709:             * (non-Javadoc)
710:             * 
711:             * @see de.intarsys.pdf.content.ICSDevice#textLineNew()
712:             */
713:            public void textLineNew() {
714:                graphicsState.textState.tlmMove(0, graphicsState.textState
715:                        .getLeading());
716:            }
717:
718:            /*
719:             * (non-Javadoc)
720:             * 
721:             * @see de.intarsys.pdf.content.ICSDevice#textMove(float, float)
722:             */
723:            public void textMove(float dx, float dy) {
724:                graphicsState.textState.tmMove(dx, dy);
725:            }
726:
727:            /*
728:             * (non-Javadoc)
729:             * 
730:             * @see de.intarsys.pdf.content.ICSDevice#textMoveTo(float, float)
731:             */
732:            public void textMoveTo(float x, float y) {
733:                graphicsState.textState.tmMoveTo(x, y);
734:            }
735:
736:            /*
737:             * (non-Javadoc)
738:             * 
739:             * @see de.intarsys.pdf.content.ICSDevice#textSetCharSpacing(float)
740:             */
741:            public void textSetCharSpacing(float charSpacing) {
742:                graphicsState.textState.setCharSpacing(charSpacing);
743:            }
744:
745:            /*
746:             * (non-Javadoc)
747:             * 
748:             * @see de.intarsys.pdf.content.ICSDevice#textSetFont(de.intarsys.pdf.cos.COSName,
749:             *      de.intarsys.pdf.font.PDFont, float)
750:             */
751:            public void textSetFont(COSName name, PDFont font, float size) {
752:                graphicsState.textState.setFont(font, size);
753:            }
754:
755:            /*
756:             * (non-Javadoc)
757:             * 
758:             * @see de.intarsys.pdf.content.ICSDevice#textSetHorizontalScaling(float)
759:             */
760:            public void textSetHorizontalScaling(float scaling) {
761:                graphicsState.textState.setHorizontalScaling(scaling);
762:            }
763:
764:            /*
765:             * (non-Javadoc)
766:             * 
767:             * @see de.intarsys.pdf.content.ICSDevice#textSetLeading(float)
768:             */
769:            public void textSetLeading(float leading) {
770:                graphicsState.textState.setLeading(leading);
771:            }
772:
773:            /*
774:             * (non-Javadoc)
775:             * 
776:             * @see de.intarsys.pdf.content.ICSDevice#textSetRenderingMode(int)
777:             */
778:            public void textSetRenderingMode(int renderingMode) {
779:                graphicsState.textState.setRenderingMode(renderingMode);
780:            }
781:
782:            /*
783:             * (non-Javadoc)
784:             * 
785:             * @see de.intarsys.pdf.content.ICSDevice#textSetRise(float)
786:             */
787:            public void textSetRise(float rise) {
788:                graphicsState.textState.setRise(rise);
789:            }
790:
791:            /*
792:             * (non-Javadoc)
793:             * 
794:             * @see de.intarsys.pdf.content.ICSDevice#textSetTransform(float, float,
795:             *      float, float, float, float)
796:             */
797:            public void textSetTransform(float a, float b, float c, float d,
798:                    float e, float f) {
799:                graphicsState.textState.setTransform(a, b, c, d, e, f);
800:            }
801:
802:            /*
803:             * (non-Javadoc)
804:             * 
805:             * @see de.intarsys.pdf.content.ICSDevice#textSetWordSpacing(float)
806:             */
807:            public void textSetWordSpacing(float wordSpacing) {
808:                graphicsState.textState.setWordSpacing(wordSpacing);
809:            }
810:
811:            public void textShow(byte[] text, int offset, int length) {
812:                // override in subclass
813:            }
814:
815:            public void textShow(String text) {
816:                byte[] bytes = encode(text.toCharArray());
817:                textShow(bytes, 0, bytes.length);
818:            }
819:
820:            /*
821:             * (non-Javadoc)
822:             * 
823:             * @see de.intarsys.pdf.content.ICSDevice#textT3SetGlyphWidth(float, float)
824:             */
825:            public void textT3SetGlyphWidth(float x, float y) {
826:                // redefine
827:            }
828:
829:            /*
830:             * (non-Javadoc)
831:             * 
832:             * @see de.intarsys.pdf.content.ICSDevice#textT3SetGlyphWidthBB(float,
833:             *      float, float, float, float, float)
834:             */
835:            public void textT3SetGlyphWidthBB(float x, float y, float llx,
836:                    float lly, float urx, float ury) {
837:                // redefine
838:            }
839:
840:            /*
841:             * (non-Javadoc)
842:             * 
843:             * @see de.intarsys.pdf.content.ICSDevice#transform(float, float, float,
844:             *      float, float, float)
845:             */
846:            public void transform(float a, float b, float c, float d, float e,
847:                    float f) {
848:                AffineTransform transform = new AffineTransform(a, b, c, d, e,
849:                        f);
850:                transform.preConcatenate(graphicsState.getTransform());
851:                graphicsState.setTransform(transform);
852:            }
853:
854:            protected byte[] encode(char[] text) {
855:                Encoding encoding = graphicsState.textState.getFont()
856:                        .getEncoding();
857:                ByteArrayOutputStream bos = new ByteArrayOutputStream();
858:                Writer w = encoding.createWriter(bos);
859:                CharArrayReader r = new CharArrayReader(text);
860:                try {
861:                    StreamTools.copyEncoded(r, w);
862:                } catch (IOException e) {
863:                    throw new COSRuntimeException(e);
864:                }
865:                return bos.toByteArray();
866:            }
867:
868:            /*
869:             * (non-Javadoc)
870:             * 
871:             * @see de.intarsys.pdf.content.ICSDevice#getGraphicsState()
872:             */
873:            public ICSGraphicsState getGraphicsState() {
874:                return graphicsState.facade;
875:            }
876:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.