KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hssf > usermodel > TestFontDetails


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

16
17 package org.apache.poi.hssf.usermodel;
18
19 import junit.framework.TestCase;
20
21 import java.util.Properties JavaDoc;
22
23 /**
24  * Tests the implementation of the FontDetails class.
25  *
26  * @author Glen Stampoultzis (glens at apache.org)
27  */

28 public class TestFontDetails extends TestCase
29 {
30     private Properties JavaDoc properties;
31     private FontDetails fontDetails;
32
33     protected void setUp() throws Exception JavaDoc
34     {
35         properties = new Properties JavaDoc();
36         properties.setProperty("font.Arial.height", "13");
37         properties.setProperty("font.Arial.characters", "a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ");
38         properties.setProperty("font.Arial.widths", "6, 6, 6, 6, 6, 3, 6, 6, 3, 4, 6, 3, 9, 6, 6, 6, 6, 4, 6, 3, 6, 7, 9, 6, 5, 5, 7, 7, 7, 7, 7, 6, 8, 7, 3, 6, 7, 6, 9, 7, 8, 7, 8, 7, 7, 5, 7, 7, 9, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, ");
39         fontDetails = FontDetails.create("Arial", properties);
40
41     }
42
43     public void testCreate() throws Exception JavaDoc
44     {
45         assertEquals(13, fontDetails.getHeight());
46         assertEquals(6, fontDetails.getCharWidth('a'));
47         assertEquals(3, fontDetails.getCharWidth('f'));
48     }
49
50     public void testGetStringWidth() throws Exception JavaDoc
51     {
52         assertEquals(9, fontDetails.getStringWidth("af"));
53     }
54
55     public void testGetCharWidth() throws Exception JavaDoc
56     {
57         assertEquals(6, fontDetails.getCharWidth('a'));
58         assertEquals(9, fontDetails.getCharWidth('='));
59     }
60
61 }
62
Popular Tags