Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

CustomFont.java 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. /*
  2. * $Id: CustomFont.java,v 1.2 2003/03/06 17:43:05 jeremias Exp $
  3. * ============================================================================
  4. * The Apache Software License, Version 1.1
  5. * ============================================================================
  6. *
  7. * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without modifica-
  10. * tion, are permitted provided that the following conditions are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright notice,
  13. * this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. *
  19. * 3. The end-user documentation included with the redistribution, if any, must
  20. * include the following acknowledgment: "This product includes software
  21. * developed by the Apache Software Foundation (http://www.apache.org/)."
  22. * Alternately, this acknowledgment may appear in the software itself, if
  23. * and wherever such third-party acknowledgments normally appear.
  24. *
  25. * 4. The names "FOP" and "Apache Software Foundation" must not be used to
  26. * endorse or promote products derived from this software without prior
  27. * written permission. For written permission, please contact
  28. * apache@apache.org.
  29. *
  30. * 5. Products derived from this software may not be called "Apache", nor may
  31. * "Apache" appear in their name, without prior written permission of the
  32. * Apache Software Foundation.
  33. *
  34. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  35. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  36. * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  37. * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  38. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
  39. * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  40. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  41. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  42. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  43. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  44. * ============================================================================
  45. *
  46. * This software consists of voluntary contributions made by many individuals
  47. * on behalf of the Apache Software Foundation and was originally created by
  48. * James Tauber <jtauber@jtauber.com>. For more information on the Apache
  49. * Software Foundation, please see <http://www.apache.org/>.
  50. */
  51. package org.apache.fop.fonts;
  52. import java.util.Map;
  53. /**
  54. * Abstract base class for custom fonts loaded from files, for example.
  55. */
  56. public abstract class CustomFont extends Font
  57. implements FontDescriptor, MutableFont {
  58. private String fontName = null;
  59. private String embedFileName = null;
  60. private String embedResourceName = null;
  61. private int capHeight = 0;
  62. private int xHeight = 0;
  63. private int ascender = 0;
  64. private int descender = 0;
  65. private int[] fontBBox = {0, 0, 0, 0};
  66. private int flags = 4;
  67. private int stemV = 0;
  68. private int italicAngle = 0;
  69. private int missingWidth = 0;
  70. private FontType fontType = FontType.TYPE1;
  71. private int firstChar = 0;
  72. private int lastChar = 255;
  73. private Map kerning = new java.util.HashMap();
  74. private boolean useKerning = true;
  75. /**
  76. * @see org.apache.fop.fonts.FontMetrics#getFontName()
  77. */
  78. public String getFontName() {
  79. return fontName;
  80. }
  81. /**
  82. * Returns an URI representing an embeddable font file. The URI will often
  83. * be a filename or an URL.
  84. * @return URI to an embeddable font file or null if not available.
  85. */
  86. public String getEmbedFileName() {
  87. return embedFileName;
  88. }
  89. /**
  90. * Returns the lookup name to an embeddable font file available as a
  91. * resource.
  92. * (todo) Remove this method, this should be done using a resource: URI.
  93. * @return the lookup name
  94. */
  95. public String getEmbedResourceName() {
  96. return embedResourceName;
  97. }
  98. /**
  99. * @see org.apache.fop.fonts.FontDescriptor#getAscender()
  100. */
  101. public int getAscender() {
  102. return ascender;
  103. }
  104. /**
  105. * @see org.apache.fop.fonts.FontDescriptor#getDescender()
  106. */
  107. public int getDescender() {
  108. return descender;
  109. }
  110. /**
  111. * @see org.apache.fop.fonts.FontDescriptor#getCapHeight()
  112. */
  113. public int getCapHeight() {
  114. return capHeight;
  115. }
  116. /**
  117. * @see org.apache.fop.fonts.FontMetrics#getAscender(int)
  118. */
  119. public int getAscender(int size) {
  120. return size * ascender;
  121. }
  122. /**
  123. * @see org.apache.fop.fonts.FontMetrics#getDescender(int)
  124. */
  125. public int getDescender(int size) {
  126. return size * descender;
  127. }
  128. /**
  129. * @see org.apache.fop.fonts.FontMetrics#getCapHeight(int)
  130. */
  131. public int getCapHeight(int size) {
  132. return size * capHeight;
  133. }
  134. /**
  135. * @see org.apache.fop.fonts.FontMetrics#getXHeight(int)
  136. */
  137. public int getXHeight(int size) {
  138. return size * xHeight;
  139. }
  140. /**
  141. * @see org.apache.fop.fonts.FontDescriptor#getFontBBox()
  142. */
  143. public int[] getFontBBox() {
  144. return fontBBox;
  145. }
  146. /**
  147. * @see org.apache.fop.fonts.FontDescriptor#getFlags()
  148. */
  149. public int getFlags() {
  150. return flags;
  151. }
  152. /**
  153. * @see org.apache.fop.fonts.FontDescriptor#getStemV()
  154. */
  155. public int getStemV() {
  156. return stemV;
  157. }
  158. /**
  159. * @see org.apache.fop.fonts.FontDescriptor#getItalicAngle()
  160. */
  161. public int getItalicAngle() {
  162. return italicAngle;
  163. }
  164. /**
  165. * Returns the width to be used when no width is available.
  166. * @return a character width
  167. */
  168. public int getMissingWidth() {
  169. return missingWidth;
  170. }
  171. /**
  172. * @see org.apache.fop.fonts.FontDescriptor#getFontType()
  173. */
  174. public FontType getFontType() {
  175. return fontType;
  176. }
  177. /**
  178. * Returns the index of the first character defined in this font.
  179. * @return the index of the first character
  180. */
  181. public int getFirstChar() {
  182. return 0;
  183. // return firstChar;
  184. /**(todo) Why is this hardcoded??? This code was in SingleByteFont.java */
  185. }
  186. /**
  187. * Returns the index of the last character defined in this font.
  188. * @return the index of the last character
  189. */
  190. public int getLastChar() {
  191. return lastChar;
  192. }
  193. /**
  194. * Used to determine if kerning is enabled.
  195. * @return True if kerning is enabled.
  196. */
  197. public boolean isKerningEnabled() {
  198. return useKerning;
  199. }
  200. /**
  201. * @see org.apache.fop.fonts.FontMetrics#hasKerningInfo()
  202. */
  203. public final boolean hasKerningInfo() {
  204. return (isKerningEnabled() & kerning.isEmpty());
  205. }
  206. /**
  207. * @see org.apache.fop.fonts.FontMetrics#getKerningInfo()
  208. */
  209. public final Map getKerningInfo() {
  210. if (isKerningEnabled()) {
  211. return kerning;
  212. } else {
  213. return java.util.Collections.EMPTY_MAP;
  214. }
  215. }
  216. /* ---- MutableFont interface ---- */
  217. /**
  218. * @see org.apache.fop.fonts.MutableFont#setFontName(String)
  219. */
  220. public void setFontName(String name) {
  221. this.fontName = name;
  222. }
  223. /**
  224. * @see org.apache.fop.fonts.MutableFont#setEmbedFileName(String)
  225. */
  226. public void setEmbedFileName(String path) {
  227. this.embedFileName = path;
  228. }
  229. /**
  230. * @see org.apache.fop.fonts.MutableFont#setEmbedResourceName(String)
  231. */
  232. public void setEmbedResourceName(String name) {
  233. this.embedResourceName = name;
  234. }
  235. /**
  236. * @see org.apache.fop.fonts.MutableFont#setCapHeight(int)
  237. */
  238. public void setCapHeight(int capHeight) {
  239. this.capHeight = capHeight;
  240. }
  241. /**
  242. * Returns the XHeight value of the font.
  243. * @param xHeight the XHeight value
  244. */
  245. public void setXHeight(int xHeight) {
  246. this.xHeight = xHeight;
  247. }
  248. /**
  249. * @see org.apache.fop.fonts.MutableFont#setAscender(int)
  250. */
  251. public void setAscender(int ascender) {
  252. this.ascender = ascender;
  253. }
  254. /**
  255. * @see org.apache.fop.fonts.MutableFont#setDescender(int)
  256. */
  257. public void setDescender(int descender) {
  258. this.descender = descender;
  259. }
  260. /**
  261. * @see org.apache.fop.fonts.MutableFont#setFontBBox(int[])
  262. */
  263. public void setFontBBox(int[] bbox) {
  264. this.fontBBox = bbox;
  265. }
  266. /**
  267. * @see org.apache.fop.fonts.MutableFont#setFlags(int)
  268. */
  269. public void setFlags(int flags) {
  270. this.flags = flags;
  271. }
  272. /**
  273. * @see org.apache.fop.fonts.MutableFont#setStemV(int)
  274. */
  275. public void setStemV(int stemV) {
  276. this.stemV = stemV;
  277. }
  278. /**
  279. * @see org.apache.fop.fonts.MutableFont#setItalicAngle(int)
  280. */
  281. public void setItalicAngle(int italicAngle) {
  282. this.italicAngle = italicAngle;
  283. }
  284. /**
  285. * @see org.apache.fop.fonts.MutableFont#setMissingWidth(int)
  286. */
  287. public void setMissingWidth(int width) {
  288. this.missingWidth = width;
  289. }
  290. /**
  291. * @see org.apache.fop.fonts.MutableFont#setFontType(FontType)
  292. */
  293. public void setFontType(FontType fontType) {
  294. this.fontType = fontType;
  295. }
  296. /**
  297. * @see org.apache.fop.fonts.MutableFont#setFirstChar(int)
  298. */
  299. public void setFirstChar(int index) {
  300. this.firstChar = index;
  301. }
  302. /**
  303. * @see org.apache.fop.fonts.MutableFont#setLastChar(int)
  304. */
  305. public void setLastChar(int index) {
  306. this.lastChar = index;
  307. }
  308. /**
  309. * @see org.apache.fop.fonts.MutableFont#setKerningEnabled(boolean)
  310. */
  311. public void setKerningEnabled(boolean enabled) {
  312. this.useKerning = enabled;
  313. }
  314. /**
  315. * @see org.apache.fop.fonts.MutableFont#putKerningEntry(Integer, Map)
  316. */
  317. public void putKerningEntry(Integer key, Map value) {
  318. this.kerning.put(key, value);
  319. }
  320. }