KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > stefanochizzolini > clown > documents > contents > fonts > StandardType1Font


1 /*
2   Copyright © 2006,2007 Stefano Chizzolini. http://clown.stefanochizzolini.it
3
4   Contributors:
5     * Stefano Chizzolini (original code developer, info@stefanochizzolini.it):
6       contributed code is Copyright © 2006,2007 by Stefano Chizzolini.
7
8   This file should be part of the source code distribution of "PDF Clown library"
9   (the Program): see the accompanying README files for more info.
10
11   This Program is free software; you can redistribute it and/or modify it under
12   the terms of the GNU General Public License as published by the Free Software
13   Foundation; either version 2 of the License, or (at your option) any later version.
14
15   This Program is distributed in the hope that it will be useful, but WITHOUT ANY
16   WARRANTY, either expressed or implied; without even the implied warranty of
17   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License for more details.
18
19   You should have received a copy of the GNU General Public License along with this
20   Program (see README files); if not, go to the GNU website (http://www.gnu.org/).
21
22   Redistribution and use, with or without modification, are permitted provided that such
23   redistributions retain the above copyright notice, license and disclaimer, along with
24   this list of conditions.
25 */

26
27 package it.stefanochizzolini.clown.documents.contents.fonts;
28
29 import it.stefanochizzolini.clown.bytes.Buffer;
30 import it.stefanochizzolini.clown.documents.Document;
31 import it.stefanochizzolini.clown.objects.PdfDictionary;
32 import it.stefanochizzolini.clown.objects.PdfDirectObject;
33 import it.stefanochizzolini.clown.objects.PdfName;
34
35 import java.io.BufferedReader JavaDoc;
36 import java.io.InputStreamReader JavaDoc;
37
38 /**
39   Standard Type 1 font [PDF:1.6:5.5.1].
40 */

41 public class StandardType1Font
42   extends Type1Font
43 {
44   // <class>
45
// <classes>
46
public enum FamilyNameEnum
47   {
48     Courier,
49     Helvetica,
50     Times,
51     Symbol,
52     ZapfDingbats
53   };
54   // </classes>
55

56   // <dynamic>
57
// <constructors>
58
public StandardType1Font(
59     Document context,
60     FamilyNameEnum familyName,
61     boolean bold,
62     boolean italic
63     )
64   {
65     super(context);
66
67     // Font name.
68
String JavaDoc name = "";
69     switch(familyName)
70     {
71       case Courier:
72         name = "Courier";
73         break;
74       case Helvetica:
75         name = "Helvetica";
76         break;
77       case Times:
78         name = "Times";
79         break;
80       case Symbol:
81         name = "Symbol";
82         break;
83       case ZapfDingbats:
84         name = "ZapfDingbats";
85         break;
86     }
87
88     // Font style.
89
switch(familyName)
90     {
91       case Symbol:
92       case ZapfDingbats:
93         break;
94       case Times:
95         if(bold)
96         {
97           name = name + "-Bold";
98
99           if(italic)
100           {name = name + "Italic";}
101         }
102         else if(italic)
103         {name = name + "-Italic";}
104         else
105         {name = name + "-Roman";}
106         break;
107       default:
108         if(bold)
109         {
110           name = name + "-Bold";
111
112           if(italic)
113           {name = name + "Oblique";}
114         }
115         else if(italic)
116         {name = name + "-Oblique";}
117         break;
118     }
119
120     load(name);
121   }
122
123   /**
124     <h3>Remarks</h3>
125     <p>For internal use only.</p>
126   */

127   public StandardType1Font(
128     PdfDirectObject baseObject
129     )
130   {super(baseObject);}
131   // </constructors>
132

133   // <interface>
134
// <public>
135
// </public>
136

137   // <private>
138
/**
139     Loads the font metrics.
140   */

141   private void load(
142     String JavaDoc fontName
143     )
144   {
145     BufferedReader JavaDoc fontMetricsStream = null;
146     try
147     {
148       fontMetricsStream = new BufferedReader JavaDoc(
149         new InputStreamReader JavaDoc(
150           getClass().getResourceAsStream("/fonts/" + fontName + ".afm")
151           )
152         );
153
154       load(
155         fontMetricsStream,
156         true
157         );
158     }
159     catch(Exception JavaDoc e)
160     {throw new RuntimeException JavaDoc(e);}
161     finally
162     {
163       try
164       {
165         if(fontMetricsStream != null)
166         {fontMetricsStream.close();}
167       }
168       catch(Exception JavaDoc e)
169       {throw new RuntimeException JavaDoc(e);}
170     }
171   }
172   // </private>
173
// </interface>
174
// </dynamic>
175
// </class>
176
}
Popular Tags