01: /* ====================================================================
02: Licensed to the Apache Software Foundation (ASF) under one or more
03: contributor license agreements. See the NOTICE file distributed with
04: this work for additional information regarding copyright ownership.
05: The ASF licenses this file to You under the Apache License, Version 2.0
06: (the "License"); you may not use this file except in compliance with
07: the License. You may obtain a copy of the License at
08:
09: 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: package org.apache.poi.hssf.usermodel;
19:
20: import junit.framework.TestCase;
21:
22: import java.util.Properties;
23:
24: /**
25: * Tests the implementation of the FontDetails class.
26: *
27: * @author Glen Stampoultzis (glens at apache.org)
28: */
29: public class TestFontDetails extends TestCase {
30: private Properties properties;
31: private FontDetails fontDetails;
32:
33: protected void setUp() throws Exception {
34: properties = new Properties();
35: properties.setProperty("font.Arial.height", "13");
36: properties
37: .setProperty(
38: "font.Arial.characters",
39: "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, ");
40: properties
41: .setProperty(
42: "font.Arial.widths",
43: "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, ");
44: fontDetails = FontDetails.create("Arial", properties);
45:
46: }
47:
48: public void testCreate() throws Exception {
49: assertEquals(13, fontDetails.getHeight());
50: assertEquals(6, fontDetails.getCharWidth('a'));
51: assertEquals(3, fontDetails.getCharWidth('f'));
52: }
53:
54: public void testGetStringWidth() throws Exception {
55: assertEquals(9, fontDetails.getStringWidth("af"));
56: }
57:
58: public void testGetCharWidth() throws Exception {
59: assertEquals(6, fontDetails.getCharWidth('a'));
60: assertEquals(9, fontDetails.getCharWidth('='));
61: }
62:
63: }
|