View Javadoc

1   /* ========================================================================
2    * JFiglet, a free open source java implementation of figlet and the
3    * figfont specification (see http://www.figlet.org)
4    * Copyright (C) 2004 Sebastien Brunot
5    *
6    * This library is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Lesser General Public
8    * License as published by the Free Software Foundation; either
9    * version 2.1 of the License, or (at your option) any later version.
10   *
11   * This library is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14   * Lesser General Public License for more details.
15   *
16   * You should have received a copy of the GNU Lesser General Public
17   * License along with this library; if not, write to the Free Software
18   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19   * ========================================================================
20   */
21  package org.gnu.jfiglet.core;
22  
23  import java.util.ArrayList;
24  import java.util.Collection;
25  import java.util.Iterator;
26  
27  /***
28   * Informations about a FIGFont.
29   * 
30   * @version $Id: FIGFontInfo.java,v 1.1 2004/04/14 16:38:21 sbrunot Exp $
31   *
32   * @author <a href="mailto:sebastien.brunot@club-internet.fr">
33   *         Sebastien Brunot</a>
34   * 
35   */
36  public class FIGFontInfo
37  {
38      /////////////////////////////////////////////
39      // Constants
40      /////////////////////////////////////////////
41  
42      /***
43       * Value for the printDirection attributes that means a
44       * print direction from left to right.
45       */
46      public static final int PRINT_DIRECTION_LEFT_TO_RIGHT = 0;
47  
48      /***
49       * Value for the printDirection attributes that means a
50       * print direction from right to left.
51       */
52      public static final int PRINT_DIRECTION_RIGHT_TO_LEFT = 1;
53  
54      /////////////////////////////////////////////
55      // Attributes
56      /////////////////////////////////////////////
57  
58      /***
59       * The name of the FIGFont. Note that the file that holds the FIGFont
60       * data must be named <em>name</em>.flf.
61       */
62      private String name = null;
63  
64      /***
65       * The height of the FIGCharacters in the FIGFont.
66       * The Height parameter specifies the consistent height of every
67       * FIGcharacter, measured in sub-characters.  Note that ALL FIGcharacters
68       * in a given FIGfont have the same height, since this includes any empty
69       * space above or below. This is a measurement from the top of the tallest
70       * FIGcharacter to the bottom of the lowest hanging FIGcharacter, such as
71       * a lowercase g.
72       */
73      private int height = -1;
74  
75      /***
76       * The baseline of the FIGCharacters in the FIGFont. The Baseline parameter
77       * is the number of lines of sub-characters from the baseline of a
78       * FIGcharacter to the top of the tallest FIGcharacter.  The baseline of a
79       * FIGfont is an imaginary line on top of which capital letters would rest,
80       * while the tails of lowercase g, j, p, q, and y may hang below. In other
81       * words, Baseline is the height of a FIGcharacter, ignoring any descenders.
82       */
83      private int baseline = -1;
84  
85      /***
86       * The max lenght of the FIGCharacters in the FIGFont. The Max_Length
87       * parameter is the maximum length of any line describing a FIGcharacter.
88       * This is usually the width of the widest FIGcharacter, plus 2 (to
89       * accommodate FIGCharacters endmarks)
90       */
91      private int maxLength = -1;
92  
93      /***
94       * The print direction of the FIGFont. Default is left to right.
95       */
96      private int printDirection = PRINT_DIRECTION_LEFT_TO_RIGHT;
97  
98      /***
99       * The hardblank subcharacter used in the FIGCharaters of the FIGFont.
100      * 
101      */
102     private char hardblank = '$';
103 
104     /***
105      * The default layout specification of the FIGFont.
106      */
107     private FIGFontLayout layout = null;
108 
109     /***
110      * The number of lines of comments that describes the FIGFont. 
111      */
112     private int commentLinesNumber = 0;
113 
114     /***
115      * A collection of lines of comments that describes the FIGFont.
116      * ({@link String} objects).
117      */
118     private Collection commentLines = new ArrayList();
119 
120     /////////////////////////////////////////////
121     // Accessors
122     /////////////////////////////////////////////
123 
124     /***
125      * Get the baseline of the FIGCharacters in the FIGFont. The Baseline
126      * parameter
127      * is the number of lines of sub-characters from the baseline of a
128      * FIGcharacter to the top of the tallest FIGcharacter.  The baseline of a
129      * FIGfont is an imaginary line on top of which capital letters would rest,
130      * while the tails of lowercase g, j, p, q, and y may hang below. In other
131      * words, Baseline is the height of a FIGcharacter, ignoring any descenders.
132      * @return the baseline.
133      */
134     public int getBaseline()
135     {
136         return this.baseline;
137     }
138 
139     /***
140      * Get the hardblank subcharacter used in the FIGCharaters of the FIGFont.
141      * @return the hardblank subcharacter.
142      */
143     public char getHardblank()
144     {
145         return this.hardblank;
146     }
147 
148     /***
149      * Get the height of the FIGCharacters in the FIGFont.
150      * The Height parameter specifies the consistent height of every
151      * FIGcharacter, measured in sub-characters.  Note that ALL FIGcharacters
152      * in a given FIGfont have the same height, since this includes any empty
153      * space above or below. This is a measurement from the top of the tallest
154      * FIGcharacter to the bottom of the lowest hanging FIGcharacter, such as
155      * a lowercase g.
156      * @return the height.
157      */
158     public int getHeight()
159     {
160         return this.height;
161     }
162 
163     /***
164      * Get the default layout specification of the FIGFont.
165      * @return the default layout specification.
166      */
167     public FIGFontLayout getLayout()
168     {
169         return this.layout;
170     }
171 
172     /***
173      * Get the max lenght of the FIGCharacters in the FIGFont. The Max_Length
174      * parameter is the maximum length of any line describing a FIGcharacter.
175      * This is usually the width of the widest FIGcharacter, plus 2 (to
176      * accommodate FIGCharacters endmarks).
177      * @return the max length.
178      */
179     public int getMaxLength()
180     {
181         return this.maxLength;
182     }
183 
184     /***
185      * Get the name of the FIGFont. Note that the file that holds the FIGFont
186      * data must be named <em>name</em>.flf.
187      * @return the name of the FIGFont.
188      */
189     public String getName()
190     {
191         return this.name;
192     }
193 
194     /***
195      * Get the print direction of the FIGFont, which is either
196      * PRINT_DIRECTION_LEFT_TO_RIGHT or PRINT_DIRECTION_RIGHT_TO_LEFT.
197      * @return the print direction.
198      */
199     public int getPrintDirection()
200     {
201         return this.printDirection;
202     }
203 
204     /***
205      * Set the baseline of the FIGCharacters in the FIGFont. The Baseline
206      * parameter
207      * is the number of lines of sub-characters from the baseline of a
208      * FIGcharacter to the top of the tallest FIGcharacter.  The baseline of a
209      * FIGfont is an imaginary line on top of which capital letters would rest,
210      * while the tails of lowercase g, j, p, q, and y may hang below. In other
211      * words, Baseline is the height of a FIGcharacter, ignoring any descenders.
212      * @param theBaseline the baseline.
213      */
214     public void setBaseline(int theBaseline)
215     {
216         this.baseline = theBaseline;
217     }
218 
219     /***
220      * Set the hardblank subcharacter used in the FIGCharaters of the FIGFont.
221      * @param theHardblank the hardblank subcharacter.
222      */
223     public void setHardblank(char theHardblank)
224     {
225         this.hardblank = theHardblank;
226     }
227 
228     /***
229      * Set the height of the FIGCharacters in the FIGFont.
230      * The Height parameter specifies the consistent height of every
231      * FIGcharacter, measured in sub-characters.  Note that ALL FIGcharacters
232      * in a given FIGfont have the same height, since this includes any empty
233      * space above or below. This is a measurement from the top of the tallest
234      * FIGcharacter to the bottom of the lowest hanging FIGcharacter, such as
235      * a lowercase g.
236      * @param theHeight the height.
237      */
238     public void setHeight(int theHeight)
239     {
240         height = theHeight;
241     }
242 
243     /***
244      * Set the default layout specification of the FIGFont.
245      * @param theLayout the default layout specification.
246      */
247     public void setLayout(FIGFontLayout theLayout)
248     {
249         this.layout = theLayout;
250     }
251 
252     /***
253      * Get the max lenght of the FIGCharacters in the FIGFont. The Max_Length
254      * parameter is the maximum length of any line describing a FIGcharacter.
255      * This is usually the width of the widest FIGcharacter, plus 2 (to
256      * accommodate FIGCharacters endmarks).
257      * @param theMaxLength the max length.
258      */
259     public void setMaxLength(int theMaxLength)
260     {
261         this.maxLength = theMaxLength;
262     }
263 
264     /***
265      * Set the name of the FIGFont. Note that the file that holds the FIGFont
266      * data must be named <em>name</em>.flf.
267      * @param theName the name of the FIGFont.
268      */
269     public void setName(String theName)
270     {
271         this.name = theName;
272     }
273 
274     /***
275      * Set the print direction of the FIGFont, which should either be
276      * PRINT_DIRECTION_LEFT_TO_RIGHT or PRINT_DIRECTION_RIGHT_TO_LEFT.
277      * @param thePrintDirection the print direction. An IllegalArgumentException
278      * is returned if the value is not a legal one.
279      */
280     public void setPrintDirection(int thePrintDirection)
281     {
282         if ((thePrintDirection != PRINT_DIRECTION_LEFT_TO_RIGHT)
283             && (thePrintDirection != PRINT_DIRECTION_RIGHT_TO_LEFT))
284         {
285             throw new IllegalArgumentException();
286         }
287         printDirection = thePrintDirection;
288     }
289 
290     /***
291      * Set the number of lines of comments that describes the FIGFont. 
292      * @param theCommentLinesNumber the number of lines of comments
293      */
294     protected void setCommentLinesNumber(int theCommentLinesNumber)
295     {
296         this.commentLinesNumber = theCommentLinesNumber;
297     }
298 
299     /***
300      * Get the number of lines of comments that describes the FIGFont. 
301      * @return the number of lines of comments previously set using
302      * setCommentLinesNumber(int).
303      */
304     protected int getCommentLinesNumber()
305     {
306         return this.commentLinesNumber;
307     }
308 
309     /***
310      * Add a line of comments to describe the FIGFont.
311      * @param theCommentLine the line of comments to add.
312      */
313     public void addCommentLine(String theCommentLine)
314     {
315         this.commentLines.add(theCommentLine);
316     }
317 
318     /***
319      * Get an iterator through the lines of comments (String)
320      * that describes the FIGFont.
321      * @return the interator
322      */
323     public Iterator getCommentLines()
324     {
325         return this.commentLines.iterator();
326     }
327 
328 }