選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

FontSetup.java 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. // FOP
  19. import org.apache.fop.apps.Document;
  20. // FOP (base 14 fonts)
  21. import org.apache.fop.fonts.base14.Helvetica;
  22. import org.apache.fop.fonts.base14.HelveticaBold;
  23. import org.apache.fop.fonts.base14.HelveticaOblique;
  24. import org.apache.fop.fonts.base14.HelveticaBoldOblique;
  25. import org.apache.fop.fonts.base14.TimesRoman;
  26. import org.apache.fop.fonts.base14.TimesBold;
  27. import org.apache.fop.fonts.base14.TimesItalic;
  28. import org.apache.fop.fonts.base14.TimesBoldItalic;
  29. import org.apache.fop.fonts.base14.Courier;
  30. import org.apache.fop.fonts.base14.CourierBold;
  31. import org.apache.fop.fonts.base14.CourierOblique;
  32. import org.apache.fop.fonts.base14.CourierBoldOblique;
  33. import org.apache.fop.fonts.base14.Symbol;
  34. import org.apache.fop.fonts.base14.ZapfDingbats;
  35. import org.apache.avalon.framework.configuration.Configuration;
  36. import org.apache.avalon.framework.configuration.ConfigurationException;
  37. // Java
  38. import java.util.List;
  39. /**
  40. * Default fonts for FOP application; currently this uses PDF's fonts
  41. * by default.
  42. *
  43. * Assigns the font (with metrics) to internal names like "F1" and
  44. * assigns family-style-weight triplets to the fonts
  45. */
  46. public class FontSetup {
  47. /**
  48. * Sets up the font info object.
  49. *
  50. * Adds metrics for basic fonts and useful family-style-weight
  51. * triplets for lookup.
  52. *
  53. * @param fontInfo the font info object to set up
  54. * @param embedList ???
  55. */
  56. public static void setup(Document fontInfo, List embedList) {
  57. fontInfo.addMetrics("F1", new Helvetica());
  58. fontInfo.addMetrics("F2", new HelveticaOblique());
  59. fontInfo.addMetrics("F3", new HelveticaBold());
  60. fontInfo.addMetrics("F4", new HelveticaBoldOblique());
  61. fontInfo.addMetrics("F5", new TimesRoman());
  62. fontInfo.addMetrics("F6", new TimesItalic());
  63. fontInfo.addMetrics("F7", new TimesBold());
  64. fontInfo.addMetrics("F8", new TimesBoldItalic());
  65. fontInfo.addMetrics("F9", new Courier());
  66. fontInfo.addMetrics("F10", new CourierOblique());
  67. fontInfo.addMetrics("F11", new CourierBold());
  68. fontInfo.addMetrics("F12", new CourierBoldOblique());
  69. fontInfo.addMetrics("F13", new Symbol());
  70. fontInfo.addMetrics("F14", new ZapfDingbats());
  71. // Custom type 1 fonts step 1/2
  72. // fontInfo.addMetrics("F15", new OMEP());
  73. // fontInfo.addMetrics("F16", new GaramondLightCondensed());
  74. // fontInfo.addMetrics("F17", new BauerBodoniBoldItalic());
  75. /* any is treated as serif */
  76. fontInfo.addFontProperties("F5", "any", "normal", Font.NORMAL);
  77. fontInfo.addFontProperties("F6", "any", "italic", Font.NORMAL);
  78. fontInfo.addFontProperties("F6", "any", "oblique", Font.NORMAL);
  79. fontInfo.addFontProperties("F7", "any", "normal", Font.BOLD);
  80. fontInfo.addFontProperties("F8", "any", "italic", Font.BOLD);
  81. fontInfo.addFontProperties("F8", "any", "oblique", Font.BOLD);
  82. fontInfo.addFontProperties("F1", "sans-serif", "normal", Font.NORMAL);
  83. fontInfo.addFontProperties("F2", "sans-serif", "oblique", Font.NORMAL);
  84. fontInfo.addFontProperties("F2", "sans-serif", "italic", Font.NORMAL);
  85. fontInfo.addFontProperties("F3", "sans-serif", "normal", Font.BOLD);
  86. fontInfo.addFontProperties("F4", "sans-serif", "oblique", Font.BOLD);
  87. fontInfo.addFontProperties("F4", "sans-serif", "italic", Font.BOLD);
  88. fontInfo.addFontProperties("F5", "serif", "normal", Font.NORMAL);
  89. fontInfo.addFontProperties("F6", "serif", "oblique", Font.NORMAL);
  90. fontInfo.addFontProperties("F6", "serif", "italic", Font.NORMAL);
  91. fontInfo.addFontProperties("F7", "serif", "normal", Font.BOLD);
  92. fontInfo.addFontProperties("F8", "serif", "oblique", Font.BOLD);
  93. fontInfo.addFontProperties("F8", "serif", "italic", Font.BOLD);
  94. fontInfo.addFontProperties("F9", "monospace", "normal", Font.NORMAL);
  95. fontInfo.addFontProperties("F10", "monospace", "oblique", Font.NORMAL);
  96. fontInfo.addFontProperties("F10", "monospace", "italic", Font.NORMAL);
  97. fontInfo.addFontProperties("F11", "monospace", "normal", Font.BOLD);
  98. fontInfo.addFontProperties("F12", "monospace", "oblique", Font.BOLD);
  99. fontInfo.addFontProperties("F12", "monospace", "italic", Font.BOLD);
  100. fontInfo.addFontProperties("F1", "Helvetica", "normal", Font.NORMAL);
  101. fontInfo.addFontProperties("F2", "Helvetica", "oblique", Font.NORMAL);
  102. fontInfo.addFontProperties("F2", "Helvetica", "italic", Font.NORMAL);
  103. fontInfo.addFontProperties("F3", "Helvetica", "normal", Font.BOLD);
  104. fontInfo.addFontProperties("F4", "Helvetica", "oblique", Font.BOLD);
  105. fontInfo.addFontProperties("F4", "Helvetica", "italic", Font.BOLD);
  106. fontInfo.addFontProperties("F5", "Times", "normal", Font.NORMAL);
  107. fontInfo.addFontProperties("F6", "Times", "oblique", Font.NORMAL);
  108. fontInfo.addFontProperties("F6", "Times", "italic", Font.NORMAL);
  109. fontInfo.addFontProperties("F7", "Times", "normal", Font.BOLD);
  110. fontInfo.addFontProperties("F8", "Times", "oblique", Font.BOLD);
  111. fontInfo.addFontProperties("F8", "Times", "italic", Font.BOLD);
  112. fontInfo.addFontProperties("F9", "Courier", "normal", Font.NORMAL);
  113. fontInfo.addFontProperties("F10", "Courier", "oblique", Font.NORMAL);
  114. fontInfo.addFontProperties("F10", "Courier", "italic", Font.NORMAL);
  115. fontInfo.addFontProperties("F11", "Courier", "normal", Font.BOLD);
  116. fontInfo.addFontProperties("F12", "Courier", "oblique", Font.BOLD);
  117. fontInfo.addFontProperties("F12", "Courier", "italic", Font.BOLD);
  118. fontInfo.addFontProperties("F13", "Symbol", "normal", Font.NORMAL);
  119. fontInfo.addFontProperties("F14", "ZapfDingbats", "normal", Font.NORMAL);
  120. // Custom type 1 fonts step 2/2
  121. // fontInfo.addFontProperties("F15", "OMEP", "normal", FontInfo.NORMAL);
  122. // fontInfo.addFontProperties("F16", "Garamond-LightCondensed", "normal", FontInfo.NORMAL);
  123. // fontInfo.addFontProperties("F17", "BauerBodoni", "italic", FontInfo.BOLD);
  124. /* for compatibility with PassiveTex */
  125. fontInfo.addFontProperties("F5", "Times-Roman", "normal", Font.NORMAL);
  126. fontInfo.addFontProperties("F6", "Times-Roman", "oblique", Font.NORMAL);
  127. fontInfo.addFontProperties("F6", "Times-Roman", "italic", Font.NORMAL);
  128. fontInfo.addFontProperties("F7", "Times-Roman", "normal", Font.BOLD);
  129. fontInfo.addFontProperties("F8", "Times-Roman", "oblique", Font.BOLD);
  130. fontInfo.addFontProperties("F8", "Times-Roman", "italic", Font.BOLD);
  131. fontInfo.addFontProperties("F5", "Times Roman", "normal", Font.NORMAL);
  132. fontInfo.addFontProperties("F6", "Times Roman", "oblique", Font.NORMAL);
  133. fontInfo.addFontProperties("F6", "Times Roman", "italic", Font.NORMAL);
  134. fontInfo.addFontProperties("F7", "Times Roman", "normal", Font.BOLD);
  135. fontInfo.addFontProperties("F8", "Times Roman", "oblique", Font.BOLD);
  136. fontInfo.addFontProperties("F8", "Times Roman", "italic", Font.BOLD);
  137. fontInfo.addFontProperties("F9", "Computer-Modern-Typewriter",
  138. "normal", Font.NORMAL);
  139. /* Add configured fonts */
  140. addConfiguredFonts(fontInfo, embedList, 15);
  141. }
  142. /**
  143. * Add fonts from configuration file starting with
  144. * internalnames F<num>
  145. * @param fontInfo the font info object to set up
  146. * @param fontInfos ???
  147. * @param num starting index for internal font numbering
  148. */
  149. public static void addConfiguredFonts(Document fontInfo, List fontInfos, int num) {
  150. if (fontInfos == null) {
  151. return; //No fonts to process
  152. }
  153. String internalName = null;
  154. //FontReader reader = null;
  155. for (int i = 0; i < fontInfos.size(); i++) {
  156. EmbedFontInfo configFontInfo = (EmbedFontInfo)fontInfos.get(i);
  157. String metricsFile = configFontInfo.getMetricsFile();
  158. if (metricsFile != null) {
  159. internalName = "F" + num;
  160. num++;
  161. /*
  162. reader = new FontReader(metricsFile);
  163. reader.useKerning(configFontInfo.getKerning());
  164. reader.setFontEmbedPath(configFontInfo.getEmbedFile());
  165. fontInfo.addMetrics(internalName, reader.getFont());
  166. */
  167. LazyFont font = new LazyFont(configFontInfo.getEmbedFile(),
  168. metricsFile,
  169. configFontInfo.getKerning());
  170. fontInfo.addMetrics(internalName, font);
  171. List triplets = configFontInfo.getFontTriplets();
  172. for (int c = 0; c < triplets.size(); c++) {
  173. FontTriplet triplet = (FontTriplet)triplets.get(c);
  174. int weight = FontUtil.parseCSS2FontWeight(triplet.getWeight());
  175. //System.out.println("Registering: "+triplet+" weight="+weight);
  176. fontInfo.addFontProperties(internalName,
  177. triplet.getName(),
  178. triplet.getStyle(),
  179. weight);
  180. }
  181. }
  182. }
  183. }
  184. /**
  185. * Builds a list of EmbedFontInfo objects for use with the setup() method.
  186. * @param cfg Configuration object
  187. * @return List the newly created list of fonts
  188. * @throws ConfigurationException if something's wrong with the config data
  189. */
  190. public static List buildFontListFromConfiguration(Configuration cfg)
  191. throws ConfigurationException {
  192. List fontList = new java.util.ArrayList();
  193. Configuration[] font = cfg.getChildren("font");
  194. for (int i = 0; i < font.length; i++) {
  195. Configuration[] triple = font[i].getChildren("font-triplet");
  196. List tripleList = new java.util.ArrayList();
  197. for (int j = 0; j < triple.length; j++) {
  198. tripleList.add(new FontTriplet(triple[j].getAttribute("name"),
  199. triple[j].getAttribute("weight"),
  200. triple[j].getAttribute("style")));
  201. }
  202. EmbedFontInfo efi;
  203. efi = new EmbedFontInfo(font[i].getAttribute("metrics-url"),
  204. font[i].getAttributeAsBoolean("kerning", false),
  205. tripleList, font[i].getAttribute("embed-url", null));
  206. fontList.add(efi);
  207. }
  208. return fontList;
  209. }
  210. }