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: AFPFont.java 1679676 2015-05-16 02:10:42Z adelmelle $ */ 19 20 package org.apache.fop.afp.fonts; 21 22 import java.awt.Rectangle; 23 import java.net.URI; 24 import java.util.HashSet; 25 import java.util.Map; 26 import java.util.Set; 27 28 import org.apache.fop.fonts.FontType; 29 import org.apache.fop.fonts.Typeface; 30 31 /** 32 * All implementations of AFP fonts should extend this base class, 33 * the object implements the FontMetrics information. 34 */ 35 public abstract class AFPFont extends Typeface { 36 37 private static final double STRIKEOUT_POSITION_FACTOR = 0.45; 38 39 /** The font name */ 40 protected final String name; 41 42 private final boolean embeddable; 43 44 /** 45 * Constructor for the base font requires the name. 46 * @param name the name of the font 47 * @param embeddable whether this font is to be embedded 48 */ AFPFont(String name, boolean embeddable)49 public AFPFont(String name, boolean embeddable) { 50 this.name = name; 51 this.embeddable = embeddable; 52 } 53 54 /** {@inheritDoc} */ getFontURI()55 public URI getFontURI() { 56 return null; 57 } 58 59 /** {@inheritDoc} */ getFontName()60 public String getFontName() { 61 return this.name; 62 } 63 64 /** {@inheritDoc} */ getEmbedFontName()65 public String getEmbedFontName() { 66 return this.name; 67 } 68 69 /** {@inheritDoc} */ getFullName()70 public String getFullName() { 71 return getFontName(); 72 } 73 74 /** {@inheritDoc} */ getFamilyNames()75 public Set<String> getFamilyNames() { 76 Set<String> s = new HashSet<String>(); 77 s.add(this.name); 78 return s; 79 } 80 81 /** 82 * Returns the type of the font. 83 * @return the font type 84 */ getFontType()85 public FontType getFontType() { 86 return FontType.OTHER; 87 } 88 89 /** 90 * Indicates if the font has kerning information. 91 * @return True, if kerning is available. 92 */ hasKerningInfo()93 public boolean hasKerningInfo() { 94 return false; 95 } 96 97 /** 98 * Returns the kerning map for the font. 99 * @return the kerning map 100 */ getKerningInfo()101 public Map<Integer, Map<Integer, Integer>> getKerningInfo() { 102 return null; 103 } 104 105 /** 106 * Returns the character set for a given size 107 * @param size the font size 108 * @return the character set object 109 */ getCharacterSet(int size)110 public abstract CharacterSet getCharacterSet(int size); 111 112 /** 113 * Indicates if this font may be embedded. 114 * @return True, if embedding is possible/permitted 115 */ isEmbeddable()116 public boolean isEmbeddable() { 117 return this.embeddable; 118 } 119 120 /** 121 * Maps mapped code points to Unicode code points. 122 * @param character the mapped code point 123 * @return the corresponding Unicode code point 124 */ toUnicodeCodepoint(int character)125 protected static final char toUnicodeCodepoint(int character) { 126 //AFP fonts use Unicode directly as their mapped code points, so we can simply cast to char 127 return (char) character; 128 } 129 130 /** {@inheritDoc} */ getUnderlineThickness(int size)131 public int getUnderlineThickness(int size) { 132 // This is the FOCA recommendation in the absence of the Underline Thickness parameter 133 return getBoundingBox('-', size).height; 134 } 135 136 /** {@inheritDoc} */ getStrikeoutPosition(int size)137 public int getStrikeoutPosition(int size) { 138 //TODO This conflicts with the FOCA recommendation of 0 in the absence of the Throughscore Position 139 // parameter 140 return (int) (STRIKEOUT_POSITION_FACTOR * getCapHeight(size)); 141 } 142 143 /** {@inheritDoc} */ getStrikeoutThickness(int size)144 public int getStrikeoutThickness(int size) { 145 // This is the FOCA recommendation in the absence of the Throughscore Thickness parameter 146 return getBoundingBox('-', size).height; 147 } 148 149 /** {@inheritDoc} */ getBoundingBox(int glyphIndex, int size)150 public abstract Rectangle getBoundingBox(int glyphIndex, int size); 151 152 /** {@inheritDoc} */ getWidths()153 public int[] getWidths() { 154 throw new UnsupportedOperationException(); 155 } 156 157 /** {@inheritDoc} */ toString()158 public String toString() { 159 return "name=" + name; 160 } 161 } 162