KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 /* $Id$ */
19
20 package org.apache.fop.fonts.type1;
21
22 import java.io.IOException JavaDoc;
23 import java.io.InputStream JavaDoc;
24
25 import org.apache.fop.fonts.CustomFont;
26 import org.apache.fop.fonts.FontLoader;
27 import org.apache.fop.fonts.FontResolver;
28 import org.apache.fop.fonts.FontType;
29 import org.apache.fop.fonts.SingleByteFont;
30
31 /**
32  * Loads a Type 1 font into memory directly from the original font file.
33  */

34 public class Type1FontLoader extends FontLoader {
35
36     private String JavaDoc fontFileURI;
37     private PFMFile pfm;
38     private SingleByteFont singleFont;
39     private CustomFont returnFont;
40     private FontResolver resolver;
41     
42     /**
43      * Constructs a new Type 1 font loader.
44      * @param fontFileURI the URI to the PFB file of a Type 1 font
45      * @param in the InputStream reading the PFM file of a Type 1 font
46      * @param resolver the font resolver used to resolve URIs
47      * @throws IOException In case of an I/O error
48      */

49     public Type1FontLoader(String JavaDoc fontFileURI, InputStream JavaDoc in, FontResolver resolver)
50                 throws IOException JavaDoc {
51         this.fontFileURI = fontFileURI;
52         this.resolver = resolver;
53
54         pfm = new PFMFile();
55         pfm.load(in);
56         singleFont = new SingleByteFont();
57         singleFont.setFontType(FontType.TYPE1);
58         singleFont.setResolver(this.resolver);
59         returnFont = singleFont;
60         read();
61     }
62     
63     private void read() throws IOException JavaDoc {
64         returnFont.setFontName(pfm.getPostscriptName());
65         returnFont.setCapHeight(pfm.getCapHeight());
66         returnFont.setXHeight(pfm.getXHeight());
67         returnFont.setAscender(pfm.getLowerCaseAscent());
68         returnFont.setDescender(pfm.getLowerCaseDescent());
69         returnFont.setFontBBox(pfm.getFontBBox());
70         returnFont.setFirstChar(pfm.getFirstChar());
71         returnFont.setLastChar(pfm.getFirstChar());
72         returnFont.setFlags(pfm.getFlags());
73         returnFont.setStemV(pfm.getStemV());
74         returnFont.setItalicAngle(pfm.getItalicAngle());
75         returnFont.setMissingWidth(0);
76         for (short i = pfm.getFirstChar(); i <= pfm.getLastChar(); i++) {
77             singleFont.setWidth(i, pfm.getCharWidth(i));
78         }
79         singleFont.setEmbedFileName(this.fontFileURI);
80         
81     }
82     
83     /** @see org.apache.fop.fonts.FontLoader#getFont() */
84     public CustomFont getFont() {
85         return this.returnFont;
86     }
87     
88 }
89
Popular Tags