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.

FontSetup.java 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /*-- $Id$ --
  2. ============================================================================
  3. The Apache Software License, Version 1.1
  4. ============================================================================
  5. Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
  6. Redistribution and use in source and binary forms, with or without modifica-
  7. tion, are permitted provided that the following conditions are met:
  8. 1. Redistributions of source code must retain the above copyright notice,
  9. this list of conditions and the following disclaimer.
  10. 2. Redistributions in binary form must reproduce the above copyright notice,
  11. this list of conditions and the following disclaimer in the documentation
  12. and/or other materials provided with the distribution.
  13. 3. The end-user documentation included with the redistribution, if any, must
  14. include the following acknowledgment: "This product includes software
  15. developed by the Apache Software Foundation (http://www.apache.org/)."
  16. Alternately, this acknowledgment may appear in the software itself, if
  17. and wherever such third-party acknowledgments normally appear.
  18. 4. The names "Fop" and "Apache Software Foundation" must not be used to
  19. endorse or promote products derived from this software without prior
  20. written permission. For written permission, please contact
  21. apache@apache.org.
  22. 5. Products derived from this software may not be called "Apache", nor may
  23. "Apache" appear in their name, without prior written permission of the
  24. Apache Software Foundation.
  25. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  26. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  27. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  28. APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  29. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
  30. DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  31. OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  32. ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  33. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  34. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. This software consists of voluntary contributions made by many individuals
  36. on behalf of the Apache Software Foundation and was originally created by
  37. James Tauber <jtauber@jtauber.com>. For more information on the Apache
  38. Software Foundation, please see <http://www.apache.org/>.
  39. */
  40. package org.apache.fop.render.pdf;
  41. // FOP
  42. import org.apache.fop.render.pdf.fonts.*;
  43. import org.apache.fop.messaging.MessageHandler;
  44. import org.apache.fop.layout.FontInfo;
  45. import org.apache.fop.layout.FontDescriptor;
  46. import org.apache.fop.pdf.PDFDocument;
  47. import org.apache.fop.pdf.PDFResources;
  48. // Java
  49. import java.util.Enumeration;
  50. import java.util.Hashtable;
  51. // For JAPANAIZED
  52. import org.apache.fop.render.pdf.fonts.cidfont.jp.*;
  53. /**
  54. * sets up the PDF fonts.
  55. *
  56. * Assigns the font (with metrics) to internal names like "F1" and
  57. * assigns family-style-weight triplets to the fonts
  58. */
  59. public class FontSetup {
  60. /**
  61. * sets up the font info object.
  62. *
  63. * adds metrics for basic fonts and useful family-style-weight
  64. * triplets for lookup
  65. *
  66. * @param fontInfo the font info object to set up
  67. */
  68. public static void setup(FontInfo fontInfo) {
  69. MessageHandler.logln("setting up fonts");
  70. fontInfo.addMetrics("F1", new Helvetica());
  71. fontInfo.addMetrics("F2", new HelveticaOblique());
  72. fontInfo.addMetrics("F3", new HelveticaBold());
  73. fontInfo.addMetrics("F4", new HelveticaBoldOblique());
  74. fontInfo.addMetrics("F5", new TimesRoman());
  75. fontInfo.addMetrics("F6", new TimesItalic());
  76. fontInfo.addMetrics("F7", new TimesBold());
  77. fontInfo.addMetrics("F8", new TimesBoldItalic());
  78. fontInfo.addMetrics("F9", new Courier());
  79. fontInfo.addMetrics("F10", new CourierOblique());
  80. fontInfo.addMetrics("F11", new CourierBold());
  81. fontInfo.addMetrics("F12", new CourierBoldOblique());
  82. fontInfo.addMetrics("F13", new Symbol());
  83. fontInfo.addMetrics("F14", new ZapfDingbats());
  84. //Custom type 1 fonts step 1/2
  85. // For JAPANIZE
  86. fontInfo.addMetrics("F15", new MSMincho());
  87. fontInfo.addMetrics("F16", new MSMinchoBold());
  88. fontInfo.addMetrics("F17", new MSMinchoItalic());
  89. fontInfo.addMetrics("F18", new MSMinchoBoldItalic());
  90. fontInfo.addMetrics("F19", new MSGothic());
  91. fontInfo.addMetrics("F20", new MSGothicBold());
  92. fontInfo.addMetrics("F21", new MSGothicItalic());
  93. fontInfo.addMetrics("F22", new MSGothicBoldItalic());
  94. fontInfo.addMetrics("F23", new RyuminLight());
  95. fontInfo.addMetrics("F24", new GothicBBBMedium());
  96. // MS Font Aliases
  97. fontInfo.addMetrics("F25", new MSMinchoAlias());
  98. fontInfo.addMetrics("F26", new MSMinchoBoldAlias());
  99. fontInfo.addMetrics("F27", new MSMinchoItalicAlias());
  100. fontInfo.addMetrics("F28", new MSMinchoBoldItalicAlias());
  101. fontInfo.addMetrics("F29", new MSGothicAlias());
  102. fontInfo.addMetrics("F30", new MSGothicBoldAlias());
  103. fontInfo.addMetrics("F31", new MSGothicItalicAlias());
  104. fontInfo.addMetrics("F32", new MSGothicBoldItalicAlias());
  105. fontInfo.addMetrics("F33", new Osaka());
  106. /* any is treated as serif */
  107. fontInfo.addFontProperties("F5", "any", "normal", "normal");
  108. fontInfo.addFontProperties("F6", "any", "italic", "normal");
  109. fontInfo.addFontProperties("F6", "any", "oblique", "normal");
  110. fontInfo.addFontProperties("F7", "any", "normal", "bold");
  111. fontInfo.addFontProperties("F8", "any", "italic", "bold");
  112. fontInfo.addFontProperties("F8", "any", "oblique", "bold");
  113. fontInfo.addFontProperties("F1", "sans-serif", "normal",
  114. "normal");
  115. fontInfo.addFontProperties("F2", "sans-serif", "oblique",
  116. "normal");
  117. fontInfo.addFontProperties("F2", "sans-serif", "italic",
  118. "normal");
  119. fontInfo.addFontProperties("F3", "sans-serif", "normal",
  120. "bold");
  121. fontInfo.addFontProperties("F4", "sans-serif", "oblique",
  122. "bold");
  123. fontInfo.addFontProperties("F4", "sans-serif", "italic",
  124. "bold");
  125. fontInfo.addFontProperties("F5", "serif", "normal", "normal");
  126. fontInfo.addFontProperties("F6", "serif", "oblique",
  127. "normal");
  128. fontInfo.addFontProperties("F6", "serif", "italic", "normal");
  129. fontInfo.addFontProperties("F7", "serif", "normal", "bold");
  130. fontInfo.addFontProperties("F8", "serif", "oblique", "bold");
  131. fontInfo.addFontProperties("F8", "serif", "italic", "bold");
  132. fontInfo.addFontProperties("F9", "monospace", "normal",
  133. "normal");
  134. fontInfo.addFontProperties("F10", "monospace", "oblique",
  135. "normal");
  136. fontInfo.addFontProperties("F10", "monospace", "italic",
  137. "normal");
  138. fontInfo.addFontProperties("F11", "monospace", "normal",
  139. "bold");
  140. fontInfo.addFontProperties("F12", "monospace", "oblique",
  141. "bold");
  142. fontInfo.addFontProperties("F12", "monospace", "italic",
  143. "bold");
  144. fontInfo.addFontProperties("F1", "Helvetica", "normal",
  145. "normal");
  146. fontInfo.addFontProperties("F2", "Helvetica", "oblique",
  147. "normal");
  148. fontInfo.addFontProperties("F2", "Helvetica", "italic",
  149. "normal");
  150. fontInfo.addFontProperties("F3", "Helvetica", "normal",
  151. "bold");
  152. fontInfo.addFontProperties("F4", "Helvetica", "oblique",
  153. "bold");
  154. fontInfo.addFontProperties("F4", "Helvetica", "italic",
  155. "bold");
  156. fontInfo.addFontProperties("F5", "Times", "normal", "normal");
  157. fontInfo.addFontProperties("F6", "Times", "oblique",
  158. "normal");
  159. fontInfo.addFontProperties("F6", "Times", "italic", "normal");
  160. fontInfo.addFontProperties("F7", "Times", "normal", "bold");
  161. fontInfo.addFontProperties("F8", "Times", "oblique", "bold");
  162. fontInfo.addFontProperties("F8", "Times", "italic", "bold");
  163. fontInfo.addFontProperties("F9", "Courier", "normal",
  164. "normal");
  165. fontInfo.addFontProperties("F10", "Courier", "oblique",
  166. "normal");
  167. fontInfo.addFontProperties("F10", "Courier", "italic",
  168. "normal");
  169. fontInfo.addFontProperties("F11", "Courier", "normal",
  170. "bold");
  171. fontInfo.addFontProperties("F12", "Courier", "oblique",
  172. "bold");
  173. fontInfo.addFontProperties("F12", "Courier", "italic",
  174. "bold");
  175. fontInfo.addFontProperties("F13", "Symbol", "normal",
  176. "normal");
  177. fontInfo.addFontProperties("F14", "ZapfDingbats", "normal",
  178. "normal");
  179. //Custom type 1 fonts step 2/2
  180. // For JAPANIZE
  181. fontInfo.addFontProperties("F15", "\uff2d\uff33\u660e\u671d", "normal",
  182. "normal");
  183. fontInfo.addFontProperties("F16", "\uff2d\uff33\u660e\u671d", "normal",
  184. "bold");
  185. fontInfo.addFontProperties("F17", "\uff2d\uff33\u660e\u671d", "italic",
  186. "normal");
  187. fontInfo.addFontProperties("F18", "\uff2d\uff33\u660e\u671d", "italic",
  188. "bold");
  189. fontInfo.addFontProperties("F19", "\uff2d\uff33\u30b4\u30b7\u30c3\u30af", "normal",
  190. "normal");
  191. fontInfo.addFontProperties("F20", "\uff2d\uff33\u30b4\u30b7\u30c3\u30af", "normal",
  192. "bold");
  193. fontInfo.addFontProperties("F21", "\uff2d\uff33\u30b4\u30b7\u30c3\u30af", "italic",
  194. "normal");
  195. fontInfo.addFontProperties("F22", "\uff2d\uff33\u30b4\u30b7\u30c3\u30af", "italic",
  196. "bold");
  197. fontInfo.addFontProperties("F23", "Ryumin-Light", "normal",
  198. "normal");
  199. fontInfo.addFontProperties("F23", "Ryumin-Light", "normal",
  200. "bold");
  201. fontInfo.addFontProperties("F23", "Ryumin-Light", "italic",
  202. "normal");
  203. fontInfo.addFontProperties("F23", "Ryumin-Light", "italic",
  204. "bold");
  205. fontInfo.addFontProperties("F24", "GothicBBB-Medium", "normal",
  206. "normal");
  207. fontInfo.addFontProperties("F24", "GothicBBB-Medium", "normal",
  208. "bold");
  209. fontInfo.addFontProperties("F24", "GothicBBB-Medium", "italic",
  210. "normal");
  211. fontInfo.addFontProperties("F24", "GothicBBB-Medium", "italic",
  212. "bold");
  213. fontInfo.addFontProperties("F25", "MS-Mincho", "normal",
  214. "normal");
  215. fontInfo.addFontProperties("F26", "MS-Mincho", "normal",
  216. "bold");
  217. fontInfo.addFontProperties("F27", "MS-Mincho", "italic",
  218. "normal");
  219. fontInfo.addFontProperties("F28", "MS-Mincho", "italic",
  220. "bold");
  221. fontInfo.addFontProperties("F29", "MS-Gothic", "normal",
  222. "normal");
  223. fontInfo.addFontProperties("F30", "MS-Gothic", "normal",
  224. "bold");
  225. fontInfo.addFontProperties("F31", "MS-Gothic", "italic",
  226. "normal");
  227. fontInfo.addFontProperties("F32", "MS-Gothic", "italic",
  228. "bold");
  229. fontInfo.addFontProperties("F33", "Osaka", "normal",
  230. "normal");
  231. /* for compatibility with PassiveTex */
  232. fontInfo.addFontProperties("F5", "Times-Roman", "normal",
  233. "normal");
  234. fontInfo.addFontProperties("F6", "Times-Roman", "oblique",
  235. "normal");
  236. fontInfo.addFontProperties("F6", "Times-Roman", "italic",
  237. "normal");
  238. fontInfo.addFontProperties("F7", "Times-Roman", "normal",
  239. "bold");
  240. fontInfo.addFontProperties("F8", "Times-Roman", "oblique",
  241. "bold");
  242. fontInfo.addFontProperties("F8", "Times-Roman", "italic",
  243. "bold");
  244. fontInfo.addFontProperties("F5", "Times Roman", "normal",
  245. "normal");
  246. fontInfo.addFontProperties("F6", "Times Roman", "oblique",
  247. "normal");
  248. fontInfo.addFontProperties("F6", "Times Roman", "italic",
  249. "normal");
  250. fontInfo.addFontProperties("F7", "Times Roman", "normal",
  251. "bold");
  252. fontInfo.addFontProperties("F8", "Times Roman", "oblique",
  253. "bold");
  254. fontInfo.addFontProperties("F8", "Times Roman", "italic",
  255. "bold");
  256. fontInfo.addFontProperties("F9", "Computer-Modern-Typewriter",
  257. "normal", "normal");
  258. }
  259. /**
  260. * add the fonts in the font info to the PDF document
  261. *
  262. * @param doc PDF document to add fonts to
  263. * @param fontInfo font info object to get font information from
  264. */
  265. public static void addToResources(PDFDocument doc, FontInfo fontInfo) {
  266. Hashtable fonts = fontInfo.getFonts();
  267. Enumeration e = fonts.keys();
  268. PDFResources resources = doc.getResources();
  269. while (e.hasMoreElements()) {
  270. String f = (String) e.nextElement();
  271. Font font = (Font)fonts.get(f);
  272. FontDescriptor desc = null;
  273. if (font instanceof FontDescriptor) {
  274. desc = (FontDescriptor)font;
  275. }
  276. resources.addFont(doc.makeFont(f,
  277. font.fontName(),
  278. font.encoding(),
  279. font,
  280. desc
  281. )
  282. );
  283. }
  284. }
  285. }