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: AbstractOutlineFont.java 1610839 2014-07-15 20:25:58Z vhennebert $ */ 19 20 package org.apache.fop.afp.fonts; 21 22 import org.apache.fop.afp.AFPEventProducer; 23 24 /** 25 * A font defined as a set of lines and curves as opposed to a bitmap font. An 26 * outline font can be scaled to any size and otherwise transformed more easily 27 * than a bitmap font, and with more attractive results. 28 */ 29 public abstract class AbstractOutlineFont extends AFPFont { 30 31 /** The character set for this font */ 32 protected CharacterSet charSet; 33 34 private final AFPEventProducer eventProducer; 35 36 /** 37 * Constructor for an outline font. 38 * 39 * @param name the name of the font 40 * @param embeddable sets whether or not this font is to be embedded 41 * @param charSet the chracter set 42 * @param eventProducer The object to handle any events which occur from the object. 43 */ AbstractOutlineFont(String name, boolean embeddable, CharacterSet charSet, AFPEventProducer eventProducer)44 public AbstractOutlineFont(String name, boolean embeddable, CharacterSet charSet, 45 AFPEventProducer eventProducer) { 46 super(name, embeddable); 47 this.charSet = charSet; 48 this.eventProducer = eventProducer; 49 } 50 getAFPEventProducer()51 AFPEventProducer getAFPEventProducer() { 52 return eventProducer; 53 } 54 55 /** 56 * Get the character set metrics. 57 * 58 * @return the character set 59 */ getCharacterSet()60 public CharacterSet getCharacterSet() { 61 return charSet; 62 } 63 64 /** 65 * Get the character set metrics. 66 * @param size ignored 67 * @return the character set 68 */ getCharacterSet(int size)69 public CharacterSet getCharacterSet(int size) { 70 return charSet; 71 } 72 73 /** 74 * The ascender is the part of a lowercase letter that extends above the 75 * "x-height" (the height of the letter "x"), such as "d", "t", or "h". Also 76 * used to denote the part of the letter extending above the x-height. 77 * 78 * @param size the font size (in mpt) 79 * @return the ascender for the given size 80 */ getAscender(int size)81 public int getAscender(int size) { 82 return charSet.getAscender() * size; 83 } 84 85 /** {@inheritDoc} */ getUnderlinePosition(int size)86 public int getUnderlinePosition(int size) { 87 return charSet.getUnderscorePosition() * size; 88 } 89 90 @Override getUnderlineThickness(int size)91 public int getUnderlineThickness(int size) { 92 int underscoreWidth = charSet.getUnderscoreWidth(); 93 return underscoreWidth == 0 ? super.getUnderlineThickness(size) : underscoreWidth * size; 94 } 95 96 /** 97 * Obtains the height of capital letters for the specified point size. 98 * 99 * @param size the font size (in mpt) 100 * @return the cap height for the given size 101 */ getCapHeight(int size)102 public int getCapHeight(int size) { 103 return charSet.getCapHeight() * size; 104 } 105 106 /** 107 * The descender is the part of a lowercase letter that extends below the 108 * base line, such as "g", "j", or "p". Also used to denote the part of the 109 * letter extending below the base line. 110 * 111 * @param size the font size (in mpt) 112 * @return the descender for the given size 113 */ getDescender(int size)114 public int getDescender(int size) { 115 return charSet.getDescender() * size; 116 } 117 118 /** 119 * The "x-height" (the height of the letter "x"). 120 * 121 * @param size the font size (in mpt) 122 * @return the x height for the given size 123 */ getXHeight(int size)124 public int getXHeight(int size) { 125 return charSet.getXHeight() * size; 126 } 127 128 129 130 /** {@inheritDoc} */ hasChar(char c)131 public boolean hasChar(char c) { 132 return charSet.hasChar(c); 133 } 134 135 /** 136 * Map a Unicode character to a code point in the font. 137 * @param c character to map 138 * @return the mapped character 139 */ mapChar(char c)140 public char mapChar(char c) { 141 return charSet.mapChar(c); 142 } 143 144 /** {@inheritDoc} */ getEncodingName()145 public String getEncodingName() { 146 return charSet.getEncoding(); 147 } 148 149 } 150