|
29 | 29 |
|
30 | 30 | /** |
31 | 31 | * Character widths. |
32 | | - * |
| 32 | + * |
33 | 33 | * @author Alan Plum |
34 | 34 | * @since 4 Mar 2008 |
35 | 35 | * @version $Revision: 1.3 $ |
36 | 36 | */ |
37 | 37 | class Charwidths { |
38 | | - private final Properties props; |
39 | 38 |
|
40 | | - /** |
41 | | - * Constructor. Creates a Charwidths object for a core font. |
42 | | - * |
43 | | - * @param name |
44 | | - * name of the character widths file. |
45 | | - * @throws IOException |
46 | | - * if an error occurred when reading from the file. |
47 | | - */ |
48 | | - public Charwidths(final String name) throws IOException { |
49 | | - InputStream stream = this.getClass().getResourceAsStream( |
50 | | - "fonts/" + name + ".widths"); //$NON-NLS-1$//$NON-NLS-2$ |
51 | | - this.props = new Properties(); |
52 | | - this.props.load(stream); |
53 | | - stream.close(); |
54 | | - } |
| 39 | + private final Properties props; |
| 40 | + |
| 41 | + /** |
| 42 | + * Constructor. Creates a Charwidths object for a core font. |
| 43 | + * |
| 44 | + * @param name name of the character widths file. |
| 45 | + * @throws IOException if an error occurred when reading from the file. |
| 46 | + */ |
| 47 | + public Charwidths(final String name) throws IOException { |
| 48 | + String fontWidthResourceName = "/fonts/" + name + ".widths"; |
| 49 | + InputStream stream = Charwidths.class.getResourceAsStream(fontWidthResourceName); |
| 50 | + if ( stream == null ) { |
| 51 | + throw new IOException("resource " + fontWidthResourceName + " not found with getResourceAsStream()"); |
| 52 | + } |
| 53 | + |
| 54 | + this.props = new Properties(); |
| 55 | + this.props.load(stream); |
| 56 | + stream.close(); |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * Constructor. Creates a Charwidths object from a local file. |
| 61 | + * |
| 62 | + * @param file file containing the character widths info. |
| 63 | + * @throws IOException if an error occurred when reading from the file. |
| 64 | + */ |
| 65 | + public Charwidths(final File file) throws IOException { |
| 66 | + InputStream stream = new FileInputStream(file); |
55 | 67 |
|
56 | | - /** |
57 | | - * Constructor. Creates a Charwidths object from a local file. |
58 | | - * |
59 | | - * @param file |
60 | | - * file containing the character widths info. |
61 | | - * @throws IOException |
62 | | - * if an error occurred when reading from the file. |
63 | | - */ |
64 | | - public Charwidths(final File file) throws IOException { |
65 | | - InputStream stream = new FileInputStream(file); |
66 | | - this.props = new Properties(); |
67 | | - this.props.load(stream); |
68 | | - stream.close(); |
69 | | - } |
| 68 | + this.props = new Properties(); |
| 69 | + this.props.load(stream); |
| 70 | + stream.close(); |
| 71 | + } |
70 | 72 |
|
71 | | - /** |
72 | | - * Get the width of the given character. |
73 | | - * |
74 | | - * @param c |
75 | | - * a character |
76 | | - * @return the width of that character. |
77 | | - */ |
78 | | - public int get(final char c) { |
79 | | - String str = this.props.getProperty(Integer.valueOf(c).toString()); |
80 | | - if (str == null) { |
81 | | - return 600; |
82 | | - } |
83 | | - return Integer.parseInt(str); |
84 | | - } |
| 73 | + /** |
| 74 | + * Get the width of the given character. |
| 75 | + * |
| 76 | + * @param c a character |
| 77 | + * @return the width of that character. |
| 78 | + */ |
| 79 | + public int get(final char c) { |
| 80 | + String str = this.props.getProperty(Integer.valueOf(c).toString()); |
| 81 | + if (str == null) { |
| 82 | + return 600; |
| 83 | + } |
| 84 | + return Integer.parseInt(str); |
| 85 | + } |
85 | 86 | } |
0 commit comments