KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > fonts > SingleByteFont


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * 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 /* $Id: SingleByteFont.java 454725 2006-10-10 13:00:05Z bdelacretaz $ */
19
20 package org.apache.fop.fonts;
21
22 /**
23  * Generic SingleByte font
24  */

25 public class SingleByteFont extends CustomFont {
26
27     private CodePointMapping mapping;
28
29     private String JavaDoc encoding = "WinAnsiEncoding";
30
31     private int[] width = null;
32
33     /**
34      * Main constructor.
35      */

36     public SingleByteFont() {
37         updateMapping();
38     }
39     
40     /**
41      * Updates the mapping variable based on the encoding.
42      */

43     protected void updateMapping() {
44         mapping = CodePointMapping.getMapping(getEncoding());
45     }
46     
47     /**
48      * @see org.apache.fop.fonts.FontDescriptor#isEmbeddable()
49      */

50     public boolean isEmbeddable() {
51         return (getEmbedFileName() == null && getEmbedResourceName() == null) ? false
52                : true;
53     }
54
55     /**
56      * @see org.apache.fop.fonts.Typeface#getEncoding()
57      */

58     public String JavaDoc getEncoding() {
59         return encoding;
60     }
61
62     /**
63      * Sets the encoding of the font.
64      * @param encoding the encoding (ex. "WinAnsiEncoding" or "SymbolEncoding")
65      */

66     public void setEncoding(String JavaDoc encoding) {
67         this.encoding = encoding;
68         updateMapping();
69     }
70
71     /**
72      * @see org.apache.fop.fonts.FontMetrics#getWidth(int, int)
73      */

74     public int getWidth(int i, int size) {
75         return size * width[i];
76     }
77
78     /**
79      * @see org.apache.fop.fonts.FontMetrics#getWidths()
80      */

81     public int[] getWidths() {
82         int[] arr = new int[width.length];
83         System.arraycopy(width, 0, arr, 0, width.length - 1);
84         return arr;
85     }
86
87     /**
88      * @see org.apache.fop.fonts.Typeface#mapChar(char)
89      */

90     public char mapChar(char c) {
91         char d = mapping.mapChar(c);
92         if (d != 0) {
93             return d;
94         } else {
95             return '#';
96         }
97     }
98
99     /**
100      * @see org.apache.fop.fonts.Typeface#hasChar(char)
101      */

102     public boolean hasChar(char c) {
103         return (mapping.mapChar(c) > 0);
104     }
105
106     /* ---- single byte font specific setters --- */
107
108     /**
109      * Sets a width for a character.
110      * @param index index of the character
111      * @param width the width of the character
112      */

113     public void setWidth(int index, int width) {
114         if (this.width == null) {
115             this.width = new int[256];
116         }
117         this.width[index] = width;
118     }
119
120     public char[] getCharsUsed() {
121         return null;
122     }
123 }
124
125
Popular Tags