KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > render > mif > FontSetup


1 /*
2  * $Id: FontSetup.java,v 1.3.2.3 2003/02/25 14:39:49 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.render.mif;
52
53 // FOP
54
import org.apache.fop.render.mif.fonts.*;
55 import org.apache.fop.messaging.MessageHandler;
56 import org.apache.fop.layout.FontInfo;
57 import org.apache.fop.layout.FontDescriptor;
58 import org.apache.fop.mif.MIFDocument;
59 // import org.apache.fop.pdf.PDFResources;
60

61 // Java
62
import java.util.Iterator JavaDoc;
63 import java.util.HashMap JavaDoc;
64
65 /**
66  * sets up the PDF fonts.
67  *
68  * Assigns the font (with metrics) to internal names like "F1" and
69  * assigns family-style-weight triplets to the fonts
70  */

71 public class FontSetup {
72
73     /**
74      * sets up the font info object.
75      *
76      * adds metrics for basic fonts and useful family-style-weight
77      * triplets for lookup
78      *
79      * @param fontInfo the font info object to set up
80      */

81     public static void setup(FontInfo fontInfo) {
82         MessageHandler.logln("setting up fonts");
83
84         fontInfo.addMetrics("F1", new Helvetica());
85         fontInfo.addMetrics("F2", new HelveticaOblique());
86         fontInfo.addMetrics("F3", new HelveticaBold());
87         fontInfo.addMetrics("F4", new HelveticaBoldOblique());
88         fontInfo.addMetrics("F5", new TimesRoman());
89         fontInfo.addMetrics("F6", new TimesItalic());
90         fontInfo.addMetrics("F7", new TimesBold());
91         fontInfo.addMetrics("F8", new TimesBoldItalic());
92         fontInfo.addMetrics("F9", new Courier());
93         fontInfo.addMetrics("F10", new CourierOblique());
94         fontInfo.addMetrics("F11", new CourierBold());
95         fontInfo.addMetrics("F12", new CourierBoldOblique());
96         fontInfo.addMetrics("F13", new Symbol());
97         fontInfo.addMetrics("F14", new ZapfDingbats());
98
99         // Custom type 1 fonts step 1/2
100
// fontInfo.addMetrics("F15", new OMEP());
101
// fontInfo.addMetrics("F16", new GaramondLightCondensed());
102
// fontInfo.addMetrics("F17", new BauerBodoniBoldItalic());
103

104         /* any is treated as serif */
105         fontInfo.addFontProperties("F5", "any", "normal", "normal");
106         fontInfo.addFontProperties("F6", "any", "italic", "normal");
107         fontInfo.addFontProperties("F6", "any", "oblique", "normal");
108         fontInfo.addFontProperties("F7", "any", "normal", "bold");
109         fontInfo.addFontProperties("F8", "any", "italic", "bold");
110         fontInfo.addFontProperties("F8", "any", "oblique", "bold");
111
112         fontInfo.addFontProperties("F1", "sans-serif", "normal", "normal");
113         fontInfo.addFontProperties("F2", "sans-serif", "oblique", "normal");
114         fontInfo.addFontProperties("F2", "sans-serif", "italic", "normal");
115         fontInfo.addFontProperties("F3", "sans-serif", "normal", "bold");
116         fontInfo.addFontProperties("F4", "sans-serif", "oblique", "bold");
117         fontInfo.addFontProperties("F4", "sans-serif", "italic", "bold");
118         fontInfo.addFontProperties("F5", "serif", "normal", "normal");
119         fontInfo.addFontProperties("F6", "serif", "oblique", "normal");
120         fontInfo.addFontProperties("F6", "serif", "italic", "normal");
121         fontInfo.addFontProperties("F7", "serif", "normal", "bold");
122         fontInfo.addFontProperties("F8", "serif", "oblique", "bold");
123         fontInfo.addFontProperties("F8", "serif", "italic", "bold");
124         fontInfo.addFontProperties("F9", "monospace", "normal", "normal");
125         fontInfo.addFontProperties("F10", "monospace", "oblique", "normal");
126         fontInfo.addFontProperties("F10", "monospace", "italic", "normal");
127         fontInfo.addFontProperties("F11", "monospace", "normal", "bold");
128         fontInfo.addFontProperties("F12", "monospace", "oblique", "bold");
129         fontInfo.addFontProperties("F12", "monospace", "italic", "bold");
130
131         fontInfo.addFontProperties("F1", "Helvetica", "normal", "normal");
132         fontInfo.addFontProperties("F2", "Helvetica", "oblique", "normal");
133         fontInfo.addFontProperties("F2", "Helvetica", "italic", "normal");
134         fontInfo.addFontProperties("F3", "Helvetica", "normal", "bold");
135         fontInfo.addFontProperties("F4", "Helvetica", "oblique", "bold");
136         fontInfo.addFontProperties("F4", "Helvetica", "italic", "bold");
137         fontInfo.addFontProperties("F5", "Times", "normal", "normal");
138         fontInfo.addFontProperties("F6", "Times", "oblique", "normal");
139         fontInfo.addFontProperties("F6", "Times", "italic", "normal");
140         fontInfo.addFontProperties("F7", "Times", "normal", "bold");
141         fontInfo.addFontProperties("F8", "Times", "oblique", "bold");
142         fontInfo.addFontProperties("F8", "Times", "italic", "bold");
143         fontInfo.addFontProperties("F9", "Courier", "normal", "normal");
144         fontInfo.addFontProperties("F10", "Courier", "oblique", "normal");
145         fontInfo.addFontProperties("F10", "Courier", "italic", "normal");
146         fontInfo.addFontProperties("F11", "Courier", "normal", "bold");
147         fontInfo.addFontProperties("F12", "Courier", "oblique", "bold");
148         fontInfo.addFontProperties("F12", "Courier", "italic", "bold");
149         fontInfo.addFontProperties("F13", "Symbol", "normal", "normal");
150         fontInfo.addFontProperties("F14", "ZapfDingbats", "normal", "normal");
151
152         // Custom type 1 fonts step 2/2
153
// fontInfo.addFontProperties("F15", "OMEP", "normal", "normal");
154
// fontInfo.addFontProperties("F16", "Garamond-LightCondensed", "normal", "normal");
155
// fontInfo.addFontProperties("F17", "BauerBodoni", "italic", "bold");
156

157         /* for compatibility with PassiveTex */
158         fontInfo.addFontProperties("F5", "Times-Roman", "normal", "normal");
159         fontInfo.addFontProperties("F6", "Times-Roman", "oblique", "normal");
160         fontInfo.addFontProperties("F6", "Times-Roman", "italic", "normal");
161         fontInfo.addFontProperties("F7", "Times-Roman", "normal", "bold");
162         fontInfo.addFontProperties("F8", "Times-Roman", "oblique", "bold");
163         fontInfo.addFontProperties("F8", "Times-Roman", "italic", "bold");
164         fontInfo.addFontProperties("F5", "Times Roman", "normal", "normal");
165         fontInfo.addFontProperties("F6", "Times Roman", "oblique", "normal");
166         fontInfo.addFontProperties("F6", "Times Roman", "italic", "normal");
167         fontInfo.addFontProperties("F7", "Times Roman", "normal", "bold");
168         fontInfo.addFontProperties("F8", "Times Roman", "oblique", "bold");
169         fontInfo.addFontProperties("F8", "Times Roman", "italic", "bold");
170         fontInfo.addFontProperties("F9", "Computer-Modern-Typewriter",
171                                    "normal", "normal");
172     }
173
174     /**
175      * add the fonts in the font info to the PDF document
176      *
177      * @param doc PDF document to add fonts to
178      * @param fontInfo font info object to get font information from
179      */

180     public static void addToFontFormat(MIFDocument mifDoc,
181                                        FontInfo fontInfo) {
182
183         HashMap JavaDoc fonts = fontInfo.getFonts();
184         Iterator JavaDoc e = fonts.keySet().iterator();
185         while (e.hasNext()) {
186             String JavaDoc f = (String JavaDoc)e.next();
187             Font font = (Font)fonts.get(f);
188             FontDescriptor desc = null;
189             if (font instanceof FontDescriptor) {
190                 desc = (FontDescriptor)font;
191             }
192             /*
193              * mifDoc.makeFont(f,font.fontName(),
194              * font.encoding(),
195              * font,
196              * desc
197              * );
198              */

199
200         }
201     }
202
203 }
204
Popular Tags