KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > pdf > PDFCMap


1 /*
2  * $Id: PDFCMap.java,v 1.3.2.1 2003/02/25 14:29:37 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.pdf;
52
53 /**
54  * class representing the CMap encodings.
55  *
56  * CMaps are defined on page 215 and onwards.
57  * The predefined CMap names are drawn from Table 7.20
58  * on pages 215, 216 and 217 .
59  */

60 public class PDFCMap extends PDFStream {
61
62     /**
63      * Chinese (simplified)
64      */

65     public static final String JavaDoc GB_EUC_H = "GB-EUC-H";
66     public static final String JavaDoc GB_EUC_V = "GB_EUC_V";
67     public static final String JavaDoc GBpc_EUC_H = "GBpc-EUC-H";
68     public static final String JavaDoc GBpc_EUC_V = "GBpc-EUC-V";
69     public static final String JavaDoc GBK_EUC_H = "GBK-EUC-H";
70     public static final String JavaDoc GBK_EUC_V = "GBK-EUC-V";
71     public static final String JavaDoc UniGB_UCS2_H = "UniGB-UCS2-H";
72     public static final String JavaDoc UniGB_UCS2_V = "UniGB-UCS2-V";
73
74     /**
75      * Chinese (traditional)
76      */

77     public static final String JavaDoc B5pc_H = "B5pc-H";
78     public static final String JavaDoc B5pc_V = "B5pc-V";
79     public static final String JavaDoc ETen_B5_H = "ETen-B5-H";
80     public static final String JavaDoc ETen_B5_V = "ETen-B5-V";
81     public static final String JavaDoc ETenms_B5_H = "ETenms-B5-H";
82     public static final String JavaDoc ETenms_B5_V = "ETenms-B5-V";
83     public static final String JavaDoc CNS_EUC_H = "CNS-EUC-H";
84     public static final String JavaDoc CNS_EUC_V = "CNS-EUC-V";
85     public static final String JavaDoc UniCNS_UCS2_H = "UniCNS-UCS2-H";
86     public static final String JavaDoc UniCNS_UCS2_V = "UniCNS-UCS2-V";
87
88     /**
89      * Japanese
90      */

91     public static final String JavaDoc _83pv_RKSJ_H = "83pv-RKSJ-H"; // no V version
92
public static final String JavaDoc _90ms_RKSJ_H = "90ms-RKSJ-H";
93     public static final String JavaDoc _90ms_RKSJ_V = "90ms-RKSJ-V";
94     public static final String JavaDoc _90msp_RKSJ_H = "90msp-RKSJ-H";
95     public static final String JavaDoc _90msp_RKSJ_V = "90msp-RKSJ-V";
96     public static final String JavaDoc _90pv_RKSJ_H = "90pv-RKSJ-H"; // no V version
97
public static final String JavaDoc Add_RKSJ_H = "Add-RKSJ-H";
98     public static final String JavaDoc Add_RKSJ_V = "Add-RKSJ-V";
99     public static final String JavaDoc EUC_H = "EUC-H";
100     public static final String JavaDoc EUC_V = "EUC-V";
101     public static final String JavaDoc Ext_RKSJ_H = "Ext-RKSJ-H";
102     public static final String JavaDoc Ext_RKSJ_V = "Ext-RKSJ-V";
103     public static final String JavaDoc H = "H";
104     public static final String JavaDoc V = "V";
105     public static final String JavaDoc UniJIS_UCS2_H = "UniJIS-UCS2-H";
106     public static final String JavaDoc UniJIS_UCS2_V = "UniJIS-UCS2-V";
107     public static final String JavaDoc UniJIS_UCS2_HW_H = "UniJIS-UCS2-HW-H";
108     public static final String JavaDoc UniJIS_UCS2_HW_V = "UniJIS-UCS2-HW-V";
109
110     /**
111      * Korean
112      */

113     public static final String JavaDoc KSC_EUC_H = "KSC-EUC-H";
114     public static final String JavaDoc KSC_EUC_V = "KSC-EUC-V";
115     public static final String JavaDoc KSCms_UHC_H = "KSCms-UHC-H";
116     public static final String JavaDoc KSCms_UHC_V = "KSCms-UHC-V";
117     public static final String JavaDoc KSCms_UHC_HW_H = "KSCms-UHC-HW-H";
118     public static final String JavaDoc KSCms_UHC_HW_V = "KSCms-UHC-HW-V";
119     public static final String JavaDoc KSCpc_EUC_H = "KSCpc-EUC-H"; // no V version
120
public static final String JavaDoc UniKSC_UCS2_H = "UniKSC-UCS2-H";
121     public static final String JavaDoc UniKSC_UCS2_V = "UniKSC-UCS2-V";
122
123     /**
124      * Generic
125      */

126     public static final String JavaDoc Identity_H = "Identity-H";
127     public static final String JavaDoc Identity_V = "Identity-V";
128
129     /**
130      * /CMapName attribute, one of the predefined constants
131      */

132     protected String JavaDoc name;
133
134     /**
135      * /CIDSystemInfo attribute
136      */

137     protected PDFCIDSystemInfo sysInfo;
138
139     /**
140      * horizontal writing direction
141      */

142     public static final byte WMODE_HORIZONTAL = 0;
143
144     /**
145      * vertical writing direction
146      */

147     public static final byte WMODE_VERTICAL = 1;
148
149     /**
150      * font's writing direction
151      */

152     protected byte wMode = WMODE_HORIZONTAL;
153
154     /**
155      * base CMap (String or PDFStream)
156      */

157     protected Object JavaDoc base;
158
159     /**
160      * create the /CMap object
161      *
162      * @param name one the registered names (see Table 7.20 on p 215)
163      * @param sysInfo the attributes of the character collection of the CIDFont
164      */

165     public PDFCMap(int number, String JavaDoc name, PDFCIDSystemInfo sysInfo) {
166         super(number);
167         this.name = name;
168         this.sysInfo = sysInfo;
169         this.base = null;
170     }
171
172     /**
173      * set the writing direction
174      *
175      * @param mode is either <code>WMODE_HORIZONTAL</code>
176      * or <code>WMODE_VERTICAL</code>
177      */

178     public void setWMode(byte mode) {
179         this.wMode = mode;
180     }
181
182     public void addContents() {
183         StringBuffer JavaDoc p = new StringBuffer JavaDoc();
184         fillInPDF(p);
185         add(p.toString());
186     }
187
188     /**
189      * set the base CMap
190      *
191      * @param base the name of the base CMap (see Table 7.20)
192      */

193     public void setUseCMap(String JavaDoc base) {
194         this.base = base;
195     }
196
197     /**
198      * set the base CMap
199      *
200      * @param base the stream to be used as base CMap
201      */

202     public void setUseCMap(PDFStream base) {
203         this.base = base;
204     }
205
206     public void fillInPDF(StringBuffer JavaDoc p) {
207         // p.append("/Type /CMap\n");
208
// p.append(sysInfo.toPDFString());
209
// p.append("/CMapName /" + name);
210
// p.append("\n");
211
p.append("%!PS-Adobe-3.0 Resource-CMap\n");
212         p.append("%%DocumentNeededResources: ProcSet (CIDInit)\n");
213         p.append("%%IncludeResource: ProcSet (CIDInit)\n");
214         p.append("%%BeginResource: CMap (" + name + ")\n");
215         p.append("%%EndComments\n");
216
217         p.append("/CIDInit /ProcSet findresource begin\n");
218         p.append("12 dict begin\n");
219         p.append("begincmap\n");
220
221         p.append("/CIDSystemInfo 3 dict dup begin\n");
222         p.append(" /Registry (Adobe) def\n");
223         p.append(" /Ordering (Identity) def\n");
224         p.append(" /Supplement 0 def\n");
225         p.append("end def\n");
226
227         p.append("/CMapVersion 1 def\n");
228         p.append("/CMapType 1 def\n");
229         p.append("/CMapName /" + name + " def\n");
230
231         p.append("1 begincodespacerange\n");
232         p.append("<0000> <FFFF>\n");
233         p.append("endcodespacerange\n");
234         p.append("1 begincidrange\n");
235         p.append("<0000> <FFFF> 0\n");
236         p.append("endcidrange\n");
237
238         // p.append("1 beginbfrange\n");
239
// p.append("<0020> <0100> <0000>\n");
240
// p.append("endbfrange\n");
241

242         p.append("endcmap\n");
243         p.append("CMapName currentdict /CMap defineresource pop\n");
244         p.append("end\n");
245         p.append("end\n");
246         p.append("%%EndResource\n");
247         p.append("%%EOF\n");
248         /*
249          * p.append(" /Type /CMap\n/CMapName /" + name);
250          * p.append("\n");
251          * p.append("\n/WMode "); p.append(wMode);
252          * if (base != null) {
253          * p.append("\n/UseCMap ");
254          * if (base instanceof String) {
255          * p.append("/"+base);
256          * } else { // base instanceof PDFStream
257          * p.append(((PDFStream)base).referencePDF());
258          * }
259          * }
260          */

261     }
262
263 }
264
Popular Tags