Source Code Cross Referenced for PSFontUtils.java in  » Graphic-Library » xmlgraphics-commons-1.2 » org » apache » xmlgraphics » ps » 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 » Graphic Library » xmlgraphics commons 1.2 » org.apache.xmlgraphics.ps 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:
018:        /* $Id: PSFontUtils.java 512838 2007-02-28 16:42:28Z jeremias $ */
019:
020:        package org.apache.xmlgraphics.ps;
021:
022:        import java.io.BufferedReader;
023:        import java.io.IOException;
024:        import java.io.InputStream;
025:
026:        import org.apache.commons.io.EndianUtils;
027:        import org.apache.commons.io.IOUtils;
028:        import org.apache.xmlgraphics.fonts.Glyphs;
029:        import org.apache.xmlgraphics.util.io.ASCIIHexOutputStream;
030:        import org.apache.xmlgraphics.util.io.SubInputStream;
031:
032:        /**
033:         * Utility code for font handling in PostScript.
034:         */
035:        public class PSFontUtils {
036:
037:            /**
038:             * This method reads a Type 1 font from a stream and embeds it into a PostScript stream.
039:             * Note: Only the IBM PC Format as described in section 3.3 of the Adobe Technical Note #5040
040:             * is supported.
041:             * @param gen The PostScript generator
042:             * @param in the InputStream from which to read the Type 1 font
043:             * @throws IOException in case an I/O problem occurs
044:             */
045:            public static void embedType1Font(PSGenerator gen, InputStream in)
046:                    throws IOException {
047:                boolean finished = false;
048:                while (!finished) {
049:                    int segIndicator = in.read();
050:                    if (segIndicator < 0) {
051:                        throw new IOException(
052:                                "Unexpected end-of-file while reading segment indicator");
053:                    } else if (segIndicator != 128) {
054:                        throw new IOException("Expected ASCII 128, found: "
055:                                + segIndicator);
056:                    }
057:                    int segType = in.read();
058:                    if (segType < 0) {
059:                        throw new IOException(
060:                                "Unexpected end-of-file while reading segment type");
061:                    }
062:                    int dataSegLen = 0;
063:                    switch (segType) {
064:                    case 1: //ASCII
065:                        dataSegLen = EndianUtils.readSwappedInteger(in);
066:
067:                        BufferedReader reader = new BufferedReader(
068:                                new java.io.InputStreamReader(
069:                                        new SubInputStream(in, dataSegLen),
070:                                        "US-ASCII"));
071:                        String line;
072:                        while ((line = reader.readLine()) != null) {
073:                            gen.writeln(line);
074:                        }
075:                        break;
076:                    case 2: //binary
077:                        dataSegLen = EndianUtils.readSwappedInteger(in);
078:
079:                        SubInputStream sin = new SubInputStream(in, dataSegLen);
080:                        ASCIIHexOutputStream hexOut = new ASCIIHexOutputStream(
081:                                gen.getOutputStream());
082:                        IOUtils.copy(sin, hexOut);
083:                        gen.newLine();
084:                        break;
085:                    case 3: //EOF
086:                        finished = true;
087:                        break;
088:                    default:
089:                        throw new IOException("Unsupported segment type: "
090:                                + segType);
091:                    }
092:                }
093:            }
094:
095:            /**
096:             * Defines the WinAnsi encoding for use in PostScript files.
097:             * @param gen the PostScript generator
098:             * @throws IOException In case of an I/O problem
099:             */
100:            public static void defineWinAnsiEncoding(PSGenerator gen)
101:                    throws IOException {
102:                gen.writeln("/WinAnsiEncoding [");
103:                for (int i = 0; i < Glyphs.WINANSI_ENCODING.length; i++) {
104:                    if (i > 0) {
105:                        if ((i % 5) == 0) {
106:                            gen.newLine();
107:                        } else {
108:                            gen.write(" ");
109:                        }
110:                    }
111:                    final char ch = Glyphs.WINANSI_ENCODING[i];
112:                    final String glyphname = Glyphs.charToGlyphName(ch);
113:                    if ("".equals(glyphname)) {
114:                        gen.write("/" + Glyphs.NOTDEF);
115:                    } else {
116:                        gen.write("/");
117:                        gen.write(glyphname);
118:                    }
119:                }
120:                gen.newLine();
121:                gen.writeln("] def");
122:            }
123:
124:            /**
125:             * Redefines the encoding of a font.
126:             * @param gen the PostScript generator
127:             * @param fontName the font name
128:             * @param encoding the new encoding (must be predefined in the PS file)
129:             * @throws IOException In case of an I/O problem
130:             */
131:            public static void redefineFontEncoding(PSGenerator gen,
132:                    String fontName, String encoding) throws IOException {
133:                gen.writeln("/" + fontName + " findfont");
134:                gen.writeln("dup length dict begin");
135:                gen
136:                        .writeln("  {1 index /FID ne {def} {pop pop} ifelse} forall");
137:                gen.writeln("  /Encoding " + encoding + " def");
138:                gen.writeln("  currentdict");
139:                gen.writeln("end");
140:                gen.writeln("/" + fontName + " exch definefont pop");
141:            }
142:
143:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.