You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CustomFont.java 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* $Id$ */
  17. package org.apache.fop.fonts;
  18. import java.util.Map;
  19. /**
  20. * Abstract base class for custom fonts loaded from files, for example.
  21. */
  22. public abstract class CustomFont extends Typeface
  23. implements FontDescriptor, MutableFont {
  24. private String fontName = null;
  25. private String embedFileName = null;
  26. private String embedResourceName = null;
  27. private int capHeight = 0;
  28. private int xHeight = 0;
  29. private int ascender = 0;
  30. private int descender = 0;
  31. private int[] fontBBox = {0, 0, 0, 0};
  32. private int flags = 4;
  33. private int stemV = 0;
  34. private int italicAngle = 0;
  35. private int missingWidth = 0;
  36. private FontType fontType = FontType.TYPE1;
  37. private int firstChar = 0;
  38. private int lastChar = 255;
  39. private Map kerning = new java.util.HashMap();
  40. private boolean useKerning = true;
  41. /**
  42. * @see org.apache.fop.fonts.FontMetrics#getFontName()
  43. */
  44. public String getFontName() {
  45. return fontName;
  46. }
  47. /**
  48. * Returns an URI representing an embeddable font file. The URI will often
  49. * be a filename or an URL.
  50. * @return URI to an embeddable font file or null if not available.
  51. */
  52. public String getEmbedFileName() {
  53. return embedFileName;
  54. }
  55. /**
  56. * Returns the lookup name to an embeddable font file available as a
  57. * resource.
  58. * (todo) Remove this method, this should be done using a resource: URI.
  59. * @return the lookup name
  60. */
  61. public String getEmbedResourceName() {
  62. return embedResourceName;
  63. }
  64. /**
  65. * @see org.apache.fop.fonts.FontDescriptor#getAscender()
  66. */
  67. public int getAscender() {
  68. return ascender;
  69. }
  70. /**
  71. * @see org.apache.fop.fonts.FontDescriptor#getDescender()
  72. */
  73. public int getDescender() {
  74. return descender;
  75. }
  76. /**
  77. * @see org.apache.fop.fonts.FontDescriptor#getCapHeight()
  78. */
  79. public int getCapHeight() {
  80. return capHeight;
  81. }
  82. /**
  83. * @see org.apache.fop.fonts.FontMetrics#getAscender(int)
  84. */
  85. public int getAscender(int size) {
  86. return size * ascender;
  87. }
  88. /**
  89. * @see org.apache.fop.fonts.FontMetrics#getDescender(int)
  90. */
  91. public int getDescender(int size) {
  92. return size * descender;
  93. }
  94. /**
  95. * @see org.apache.fop.fonts.FontMetrics#getCapHeight(int)
  96. */
  97. public int getCapHeight(int size) {
  98. return size * capHeight;
  99. }
  100. /**
  101. * @see org.apache.fop.fonts.FontMetrics#getXHeight(int)
  102. */
  103. public int getXHeight(int size) {
  104. return size * xHeight;
  105. }
  106. /**
  107. * @see org.apache.fop.fonts.FontDescriptor#getFontBBox()
  108. */
  109. public int[] getFontBBox() {
  110. return fontBBox;
  111. }
  112. /**
  113. * @see org.apache.fop.fonts.FontDescriptor#getFlags()
  114. */
  115. public int getFlags() {
  116. return flags;
  117. }
  118. /**
  119. * @see org.apache.fop.fonts.FontDescriptor#getStemV()
  120. */
  121. public int getStemV() {
  122. return stemV;
  123. }
  124. /**
  125. * @see org.apache.fop.fonts.FontDescriptor#getItalicAngle()
  126. */
  127. public int getItalicAngle() {
  128. return italicAngle;
  129. }
  130. /**
  131. * Returns the width to be used when no width is available.
  132. * @return a character width
  133. */
  134. public int getMissingWidth() {
  135. return missingWidth;
  136. }
  137. /**
  138. * @see org.apache.fop.fonts.FontDescriptor#getFontType()
  139. */
  140. public FontType getFontType() {
  141. return fontType;
  142. }
  143. /**
  144. * Returns the index of the first character defined in this font.
  145. * @return the index of the first character
  146. */
  147. public int getFirstChar() {
  148. return 0;
  149. // return firstChar;
  150. /**(todo) Why is this hardcoded??? This code was in SingleByteFont.java */
  151. }
  152. /**
  153. * Returns the index of the last character defined in this font.
  154. * @return the index of the last character
  155. */
  156. public int getLastChar() {
  157. return lastChar;
  158. }
  159. /**
  160. * Used to determine if kerning is enabled.
  161. * @return True if kerning is enabled.
  162. */
  163. public boolean isKerningEnabled() {
  164. return useKerning;
  165. }
  166. /**
  167. * @see org.apache.fop.fonts.FontMetrics#hasKerningInfo()
  168. */
  169. public final boolean hasKerningInfo() {
  170. return (isKerningEnabled() & kerning.isEmpty());
  171. }
  172. /**
  173. * @see org.apache.fop.fonts.FontMetrics#getKerningInfo()
  174. */
  175. public final Map getKerningInfo() {
  176. if (isKerningEnabled()) {
  177. return kerning;
  178. } else {
  179. return java.util.Collections.EMPTY_MAP;
  180. }
  181. }
  182. /* ---- MutableFont interface ---- */
  183. /**
  184. * @see org.apache.fop.fonts.MutableFont#setFontName(String)
  185. */
  186. public void setFontName(String name) {
  187. this.fontName = name;
  188. }
  189. /**
  190. * @see org.apache.fop.fonts.MutableFont#setEmbedFileName(String)
  191. */
  192. public void setEmbedFileName(String path) {
  193. this.embedFileName = path;
  194. }
  195. /**
  196. * @see org.apache.fop.fonts.MutableFont#setEmbedResourceName(String)
  197. */
  198. public void setEmbedResourceName(String name) {
  199. this.embedResourceName = name;
  200. }
  201. /**
  202. * @see org.apache.fop.fonts.MutableFont#setCapHeight(int)
  203. */
  204. public void setCapHeight(int capHeight) {
  205. this.capHeight = capHeight;
  206. }
  207. /**
  208. * Returns the XHeight value of the font.
  209. * @param xHeight the XHeight value
  210. */
  211. public void setXHeight(int xHeight) {
  212. this.xHeight = xHeight;
  213. }
  214. /**
  215. * @see org.apache.fop.fonts.MutableFont#setAscender(int)
  216. */
  217. public void setAscender(int ascender) {
  218. this.ascender = ascender;
  219. }
  220. /**
  221. * @see org.apache.fop.fonts.MutableFont#setDescender(int)
  222. */
  223. public void setDescender(int descender) {
  224. this.descender = descender;
  225. }
  226. /**
  227. * @see org.apache.fop.fonts.MutableFont#setFontBBox(int[])
  228. */
  229. public void setFontBBox(int[] bbox) {
  230. this.fontBBox = bbox;
  231. }
  232. /**
  233. * @see org.apache.fop.fonts.MutableFont#setFlags(int)
  234. */
  235. public void setFlags(int flags) {
  236. this.flags = flags;
  237. }
  238. /**
  239. * @see org.apache.fop.fonts.MutableFont#setStemV(int)
  240. */
  241. public void setStemV(int stemV) {
  242. this.stemV = stemV;
  243. }
  244. /**
  245. * @see org.apache.fop.fonts.MutableFont#setItalicAngle(int)
  246. */
  247. public void setItalicAngle(int italicAngle) {
  248. this.italicAngle = italicAngle;
  249. }
  250. /**
  251. * @see org.apache.fop.fonts.MutableFont#setMissingWidth(int)
  252. */
  253. public void setMissingWidth(int width) {
  254. this.missingWidth = width;
  255. }
  256. /**
  257. * @see org.apache.fop.fonts.MutableFont#setFontType(FontType)
  258. */
  259. public void setFontType(FontType fontType) {
  260. this.fontType = fontType;
  261. }
  262. /**
  263. * @see org.apache.fop.fonts.MutableFont#setFirstChar(int)
  264. */
  265. public void setFirstChar(int index) {
  266. this.firstChar = index;
  267. }
  268. /**
  269. * @see org.apache.fop.fonts.MutableFont#setLastChar(int)
  270. */
  271. public void setLastChar(int index) {
  272. this.lastChar = index;
  273. }
  274. /**
  275. * @see org.apache.fop.fonts.MutableFont#setKerningEnabled(boolean)
  276. */
  277. public void setKerningEnabled(boolean enabled) {
  278. this.useKerning = enabled;
  279. }
  280. /**
  281. * @see org.apache.fop.fonts.MutableFont#putKerningEntry(Integer, Map)
  282. */
  283. public void putKerningEntry(Integer key, Map value) {
  284. this.kerning.put(key, value);
  285. }
  286. }