KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > fonts > type1 > PFBData


1 /*
2  * $Id: PFBData.java,v 1.1.2.3 2003/02/25 13:13:21 jeremias Exp $
3  * ============================================================================
4  * The Apache Software License, Version 1.1
5  * ============================================================================
6  *
7  * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without modifica-
10  * tion, are permitted provided that the following conditions are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  *
19  * 3. The end-user documentation included with the redistribution, if any, must
20  * include the following acknowledgment: "This product includes software
21  * developed by the Apache Software Foundation (http://www.apache.org/)."
22  * Alternately, this acknowledgment may appear in the software itself, if
23  * and wherever such third-party acknowledgments normally appear.
24  *
25  * 4. The names "FOP" and "Apache Software Foundation" must not be used to
26  * endorse or promote products derived from this software without prior
27  * written permission. For written permission, please contact
28  * apache@apache.org.
29  *
30  * 5. Products derived from this software may not be called "Apache", nor may
31  * "Apache" appear in their name, without prior written permission of the
32  * Apache Software Foundation.
33  *
34  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
35  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
36  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
37  * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
38  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
39  * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
40  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
41  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
42  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
43  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44  * ============================================================================
45  *
46  * This software consists of voluntary contributions made by many individuals
47  * on behalf of the Apache Software Foundation and was originally created by
48  * James Tauber <jtauber@jtauber.com>. For more information on the Apache
49  * Software Foundation, please see <http://www.apache.org/>.
50  */

51 package org.apache.fop.fonts.type1;
52
53 import java.io.OutputStream JavaDoc;
54 import java.io.IOException JavaDoc;
55
56 /**
57  * Class that represents the contents of a PFB file.
58  *
59  * @see PFBParser
60  */

61 public class PFBData {
62
63     /**
64      * Raw format, no special file structure
65      */

66     public static final int PFB_RAW = 0;
67     
68     /**
69      * PC format
70      */

71     public static final int PFB_PC = 1;
72     
73     /**
74      * MAC Format (unsupported, yet)
75      */

76     public static final int PFB_MAC = 2;
77
78     private int pfbFormat; //One of the PFB_* constants
79
private byte[] headerSegment;
80     private byte[] encryptedSegment;
81     private byte[] trailerSegment;
82
83
84     /**
85      * Sets the PFB format the font was loaded with.
86      * @param format one of the PFB_* constants
87      */

88     public void setPFBFormat(int format) {
89         switch (format) {
90             case PFB_RAW:
91             case PFB_PC:
92                 this.pfbFormat = format;
93                 break;
94             case PFB_MAC:
95                 throw new UnsupportedOperationException JavaDoc("Mac format is not yet implemented");
96             default:
97                 throw new IllegalArgumentException JavaDoc("Invalid value for PFB format: " + format);
98         }
99     }
100
101
102     /**
103      * Returns the format the font was loaded with.
104      * @return int one of the PFB_* constants
105      */

106     public int getPFBFormat() {
107         return this.pfbFormat;
108     }
109
110     /**
111      * Sets the header segment of the font file.
112      * @param headerSeg the header segment
113      */

114     public void setHeaderSegment(byte[] headerSeg) {
115         this.headerSegment = headerSeg;
116     }
117
118     /**
119      * Sets the encrypted segment of the font file.
120      * @param encryptedSeg the encrypted segment
121      */

122     public void setEncryptedSegment(byte[] encryptedSeg) {
123         this.encryptedSegment = encryptedSeg;
124     }
125
126     /**
127      * Sets the trailer segment of the font file.
128      * @param trailerSeg the trailer segment
129      */

130     public void setTrailerSegment(byte[] trailerSeg) {
131         this.trailerSegment = trailerSeg;
132     }
133
134     /**
135      * Returns the full length of the raw font file.
136      * @return int the raw file length
137      */

138     public int getLength() {
139         return getLength1() + getLength2() + getLength3();
140     }
141
142
143     /**
144      * Returns the Length1 (length of the header segment).
145      * @return int Length1
146      */

147     public int getLength1() {
148         return this.headerSegment.length;
149     }
150
151
152     /**
153      * Returns the Length2 (length of the encrypted segment).
154      * @return int Length2
155      */

156     public int getLength2() {
157         return this.encryptedSegment.length;
158     }
159
160
161     /**
162      * Returns the Length3 (length of the trailer segment).
163      * @return int Length3
164      */

165     public int getLength3() {
166         return this.trailerSegment.length;
167     }
168
169
170     /**
171      * Writes the PFB file in raw format to an OutputStream.
172      * @param out the OutputStream to write to
173      * @throws IOException In case of an I/O problem
174      */

175     public void outputAllParts(OutputStream JavaDoc out) throws IOException JavaDoc {
176         out.write(this.headerSegment);
177         out.write(this.encryptedSegment);
178         out.write(this.trailerSegment);
179     }
180
181
182     /**
183      * @see java.lang.Object#toString()
184      */

185     public String JavaDoc toString() {
186         return "PFB: format=" + getPFBFormat()
187                 + " len1=" + getLength1()
188                 + " len2=" + getLength2()
189                 + " len3=" + getLength3();
190     }
191
192 }
Popular Tags