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: FopCharacterSet.java 1694450 2015-08-06 10:59:51Z ssteiner $ */
19 
20 package org.apache.fop.afp.fonts;
21 
22 import java.awt.Rectangle;
23 
24 import org.apache.fop.afp.AFPEventProducer;
25 import org.apache.fop.afp.util.AFPResourceAccessor;
26 import org.apache.fop.fonts.Typeface;
27 
28 /**
29  * A Character set for a normal FOP font
30  */
31 public class FopCharacterSet extends CharacterSet {
32 
33     /** The character set for this font */
34     private Typeface charSet;
35 
36     /**
37      * Constructor for the CharacterSetMetric object, the character set is used
38      * to load the font information from the actual AFP font.
39      * @param codePage the code page identifier
40      * @param encoding the encoding of the font
41      * @param name the character set name
42      * @param charSet the fop character set
43      * @param eventProducer for handling AFP related events
44      */
FopCharacterSet(String codePage, String encoding, String name, Typeface charSet, AFPEventProducer eventProducer)45     public FopCharacterSet(String codePage, String encoding, String name, Typeface charSet,
46             AFPEventProducer eventProducer) {
47         super(codePage, encoding, CharacterSetType.SINGLE_BYTE, name, (AFPResourceAccessor) null,
48                 eventProducer);
49         this.charSet = charSet;
50     }
51 
FopCharacterSet(String codePage, String encoding, String name, Typeface charSet, AFPResourceAccessor accessor, AFPEventProducer eventProducer)52     public FopCharacterSet(String codePage, String encoding, String name, Typeface charSet,
53                            AFPResourceAccessor accessor, AFPEventProducer eventProducer) {
54         super(codePage, encoding, CharacterSetType.SINGLE_BYTE, name, accessor, eventProducer);
55         this.charSet = charSet;
56     }
57 
58     /**
59      * Ascender height is the distance from the character baseline to the
60      * top of the character box. A negative ascender height signifies that
61      * all of the graphic character is below the character baseline. For
62      * a character rotation other than 0, ascender height loses its
63      * meaning when the character is lying on its side or is upside down
64      * with respect to normal viewing orientation. For the general case,
65      * Ascender Height is the character's most positive y-axis value.
66      * For bounded character boxes, for a given character having an
67      * ascender, ascender height and baseline offset are equal.
68      * @return the ascender value in millipoints
69      */
getAscender()70     public int getAscender() {
71         return charSet.getAscender(1);
72     }
73 
74     /**
75      * Cap height is the average height of the uppercase characters in
76      * a font. This value is specified by the designer of a font and is
77      * usually the height of the uppercase M.
78      * @return the cap height value in millipoints
79      */
getCapHeight()80     public int getCapHeight() {
81         return charSet.getCapHeight(1);
82     }
83 
84     /**
85      * Descender depth is the distance from the character baseline to
86      * the bottom of a character box. A negative descender depth signifies
87      * that all of the graphic character is above the character baseline.
88      * @return the descender value in millipoints
89      */
getDescender()90     public int getDescender() {
91         return charSet.getDescender(1);
92     }
93 
94     /**
95      * XHeight refers to the height of the lower case letters above the baseline.
96      * @return the typical height of characters
97      */
getXHeight()98     public int getXHeight() {
99         return charSet.getXHeight(1);
100     }
101 
102     @Override
getWidth(char character, int size)103     public int getWidth(char character, int size) {
104         return charSet.getWidth(character, size);
105     }
106 
107     @Override
getCharacterBox(char character, int size)108     public Rectangle getCharacterBox(char character, int size) {
109         return charSet.getBoundingBox(character, size);
110     };
111 
112     @Override
getUnderscoreWidth()113     public int getUnderscoreWidth() {
114         return charSet.getUnderlineThickness(1);
115     }
116 
117     @Override
getUnderscorePosition()118     public int getUnderscorePosition() {
119         return charSet.getUnderlinePosition(1);
120     }
121 
122     /**
123      * Map a Unicode character to a code point in the font.
124      * @param c character to map
125      * @return the mapped character
126      */
mapChar(char c)127     public char mapChar(char c) {
128         return charSet.mapChar(c);
129     }
130 }
131