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.

Base14FontCollection.java 9.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. /* $Id: $ */
  18. package org.apache.fop.render.java2d;
  19. import java.awt.Graphics2D;
  20. import org.apache.fop.fonts.Font;
  21. import org.apache.fop.fonts.FontCollection;
  22. import org.apache.fop.fonts.FontInfo;
  23. /**
  24. * A base 14 font collection for graphics 2D
  25. */
  26. public class Base14FontCollection implements FontCollection {
  27. private Graphics2D graphics2d = null;
  28. /**
  29. * Main constructor
  30. * @param graphics2d a graphics 2D
  31. */
  32. public Base14FontCollection(Graphics2D graphics2d) {
  33. this.graphics2d = graphics2d;
  34. }
  35. /**
  36. * {@inheritDoc}
  37. */
  38. public int setup(int start, FontInfo fontInfo) {
  39. /*
  40. * available java fonts are:
  41. * Serif - bold, normal, italic, bold-italic
  42. * SansSerif - bold, normal, italic, bold-italic
  43. * MonoSpaced - bold, normal, italic, bold-italic
  44. */
  45. final int normal = java.awt.Font.PLAIN;
  46. final int bold = java.awt.Font.BOLD;
  47. final int italic = java.awt.Font.ITALIC;
  48. final int bolditalic = java.awt.Font.BOLD + java.awt.Font.ITALIC;
  49. FontMetricsMapper metric;
  50. metric = new SystemFontMetricsMapper("SansSerif", normal, graphics2d);
  51. // --> goes to F1
  52. fontInfo.addMetrics("F1", metric);
  53. metric = new SystemFontMetricsMapper("SansSerif", italic, graphics2d);
  54. // --> goes to F2
  55. fontInfo.addMetrics("F2", metric);
  56. metric = new SystemFontMetricsMapper("SansSerif", bold, graphics2d);
  57. // --> goes to F3
  58. fontInfo.addMetrics("F3", metric);
  59. metric = new SystemFontMetricsMapper("SansSerif", bolditalic, graphics2d);
  60. // --> goes to F4
  61. fontInfo.addMetrics("F4", metric);
  62. metric = new SystemFontMetricsMapper("Serif", normal, graphics2d);
  63. // --> goes to F5
  64. fontInfo.addMetrics("F5", metric);
  65. metric = new SystemFontMetricsMapper("Serif", italic, graphics2d);
  66. // --> goes to F6
  67. fontInfo.addMetrics("F6", metric);
  68. metric = new SystemFontMetricsMapper("Serif", bold, graphics2d);
  69. // --> goes to F7
  70. fontInfo.addMetrics("F7", metric);
  71. metric = new SystemFontMetricsMapper("Serif", bolditalic, graphics2d);
  72. // --> goes to F8
  73. fontInfo.addMetrics("F8", metric);
  74. metric = new SystemFontMetricsMapper("MonoSpaced", normal, graphics2d);
  75. // --> goes to F9
  76. fontInfo.addMetrics("F9", metric);
  77. metric = new SystemFontMetricsMapper("MonoSpaced", italic, graphics2d);
  78. // --> goes to F10
  79. fontInfo.addMetrics("F10", metric);
  80. metric = new SystemFontMetricsMapper("MonoSpaced", bold, graphics2d);
  81. // --> goes to F11
  82. fontInfo.addMetrics("F11", metric);
  83. metric = new SystemFontMetricsMapper("MonoSpaced", bolditalic, graphics2d);
  84. // --> goes to F12
  85. fontInfo.addMetrics("F12", metric);
  86. metric = new SystemFontMetricsMapper("Serif", normal, graphics2d);
  87. //"Symbol" doesn't seem to work here, but "Serif" does the job just fine. *shrug*
  88. // --> goes to F13 and F14
  89. fontInfo.addMetrics("F13", metric);
  90. fontInfo.addMetrics("F14", metric);
  91. // Custom type 1 fonts step 1/2
  92. // fontInfo.addMetrics("F15", new OMEP());
  93. // fontInfo.addMetrics("F16", new GaramondLightCondensed());
  94. // fontInfo.addMetrics("F17", new BauerBodoniBoldItalic());
  95. /* any is treated as serif */
  96. fontInfo.addFontProperties("F5", "any", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL);
  97. fontInfo.addFontProperties("F6", "any", Font.STYLE_ITALIC, Font.WEIGHT_NORMAL);
  98. fontInfo.addFontProperties("F6", "any", Font.STYLE_OBLIQUE, Font.WEIGHT_NORMAL);
  99. fontInfo.addFontProperties("F7", "any", Font.STYLE_NORMAL, Font.WEIGHT_BOLD);
  100. fontInfo.addFontProperties("F8", "any", Font.STYLE_ITALIC, Font.WEIGHT_BOLD);
  101. fontInfo.addFontProperties("F8", "any", Font.STYLE_OBLIQUE, Font.WEIGHT_BOLD);
  102. fontInfo.addFontProperties("F1", "sans-serif", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL);
  103. fontInfo.addFontProperties("F2", "sans-serif", Font.STYLE_OBLIQUE, Font.WEIGHT_NORMAL);
  104. fontInfo.addFontProperties("F2", "sans-serif", Font.STYLE_ITALIC, Font.WEIGHT_NORMAL);
  105. fontInfo.addFontProperties("F3", "sans-serif", Font.STYLE_NORMAL, Font.WEIGHT_BOLD);
  106. fontInfo.addFontProperties("F4", "sans-serif", Font.STYLE_OBLIQUE, Font.WEIGHT_BOLD);
  107. fontInfo.addFontProperties("F4", "sans-serif", Font.STYLE_ITALIC, Font.WEIGHT_BOLD);
  108. fontInfo.addFontProperties("F5", "serif", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL);
  109. fontInfo.addFontProperties("F6", "serif", Font.STYLE_OBLIQUE, Font.WEIGHT_NORMAL);
  110. fontInfo.addFontProperties("F6", "serif", Font.STYLE_ITALIC, Font.WEIGHT_NORMAL);
  111. fontInfo.addFontProperties("F7", "serif", Font.STYLE_NORMAL, Font.WEIGHT_BOLD);
  112. fontInfo.addFontProperties("F8", "serif", Font.STYLE_OBLIQUE, Font.WEIGHT_BOLD);
  113. fontInfo.addFontProperties("F8", "serif", Font.STYLE_ITALIC, Font.WEIGHT_BOLD);
  114. fontInfo.addFontProperties("F9", "monospace", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL);
  115. fontInfo.addFontProperties("F10", "monospace", Font.STYLE_OBLIQUE, Font.WEIGHT_NORMAL);
  116. fontInfo.addFontProperties("F10", "monospace", Font.STYLE_ITALIC, Font.WEIGHT_NORMAL);
  117. fontInfo.addFontProperties("F11", "monospace", Font.STYLE_NORMAL, Font.WEIGHT_BOLD);
  118. fontInfo.addFontProperties("F12", "monospace", Font.STYLE_OBLIQUE, Font.WEIGHT_BOLD);
  119. fontInfo.addFontProperties("F12", "monospace", Font.STYLE_ITALIC, Font.WEIGHT_BOLD);
  120. fontInfo.addFontProperties("F1", "Helvetica", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL);
  121. fontInfo.addFontProperties("F2", "Helvetica", Font.STYLE_OBLIQUE, Font.WEIGHT_NORMAL);
  122. fontInfo.addFontProperties("F2", "Helvetica", Font.STYLE_ITALIC, Font.WEIGHT_NORMAL);
  123. fontInfo.addFontProperties("F3", "Helvetica", Font.STYLE_NORMAL, Font.WEIGHT_BOLD);
  124. fontInfo.addFontProperties("F4", "Helvetica", Font.STYLE_OBLIQUE, Font.WEIGHT_BOLD);
  125. fontInfo.addFontProperties("F4", "Helvetica", Font.STYLE_ITALIC, Font.WEIGHT_BOLD);
  126. fontInfo.addFontProperties("F5", "Times", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL);
  127. fontInfo.addFontProperties("F6", "Times", Font.STYLE_OBLIQUE, Font.WEIGHT_NORMAL);
  128. fontInfo.addFontProperties("F6", "Times", Font.STYLE_ITALIC, Font.WEIGHT_NORMAL);
  129. fontInfo.addFontProperties("F7", "Times", Font.STYLE_NORMAL, Font.WEIGHT_BOLD);
  130. fontInfo.addFontProperties("F8", "Times", Font.STYLE_OBLIQUE, Font.WEIGHT_BOLD);
  131. fontInfo.addFontProperties("F8", "Times", Font.STYLE_ITALIC, Font.WEIGHT_BOLD);
  132. fontInfo.addFontProperties("F9", "Courier", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL);
  133. fontInfo.addFontProperties("F10", "Courier", Font.STYLE_OBLIQUE, Font.WEIGHT_NORMAL);
  134. fontInfo.addFontProperties("F10", "Courier", Font.STYLE_ITALIC, Font.WEIGHT_NORMAL);
  135. fontInfo.addFontProperties("F11", "Courier", Font.STYLE_NORMAL, Font.WEIGHT_BOLD);
  136. fontInfo.addFontProperties("F12", "Courier", Font.STYLE_OBLIQUE, Font.WEIGHT_BOLD);
  137. fontInfo.addFontProperties("F12", "Courier", Font.STYLE_ITALIC, Font.WEIGHT_BOLD);
  138. fontInfo.addFontProperties("F13", "Symbol", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL);
  139. fontInfo.addFontProperties("F14", "ZapfDingbats", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL);
  140. // Custom type 1 fonts step 2/2
  141. // fontInfo.addFontProperties("F15", "OMEP", "normal", FontInfo.NORMAL);
  142. // fontInfo.addFontProperties("F16", "Garamond-LightCondensed", "normal", FontInfo.NORMAL);
  143. // fontInfo.addFontProperties("F17", "BauerBodoni", "italic", FontInfo.BOLD);
  144. /* for compatibility with PassiveTex */
  145. fontInfo.addFontProperties("F5", "Times-Roman", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL);
  146. fontInfo.addFontProperties("F6", "Times-Roman", Font.STYLE_OBLIQUE, Font.WEIGHT_NORMAL);
  147. fontInfo.addFontProperties("F6", "Times-Roman", Font.STYLE_ITALIC, Font.WEIGHT_NORMAL);
  148. fontInfo.addFontProperties("F7", "Times-Roman", Font.STYLE_NORMAL, Font.WEIGHT_BOLD);
  149. fontInfo.addFontProperties("F8", "Times-Roman", Font.STYLE_OBLIQUE, Font.WEIGHT_BOLD);
  150. fontInfo.addFontProperties("F8", "Times-Roman", Font.STYLE_ITALIC, Font.WEIGHT_BOLD);
  151. fontInfo.addFontProperties("F5", "Times Roman", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL);
  152. fontInfo.addFontProperties("F6", "Times Roman", Font.STYLE_OBLIQUE, Font.WEIGHT_NORMAL);
  153. fontInfo.addFontProperties("F6", "Times Roman", Font.STYLE_ITALIC, Font.WEIGHT_NORMAL);
  154. fontInfo.addFontProperties("F7", "Times Roman", Font.STYLE_NORMAL, Font.WEIGHT_BOLD);
  155. fontInfo.addFontProperties("F8", "Times Roman", Font.STYLE_OBLIQUE, Font.WEIGHT_BOLD);
  156. fontInfo.addFontProperties("F8", "Times Roman", Font.STYLE_ITALIC, Font.WEIGHT_BOLD);
  157. fontInfo.addFontProperties("F9", "Computer-Modern-Typewriter",
  158. "normal", Font.WEIGHT_NORMAL);
  159. return 15;
  160. }
  161. }