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.

AFPBase12FontCollection.java 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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.afp.fonts;
  19. import org.apache.fop.fonts.Base14Font;
  20. import org.apache.fop.fonts.Font;
  21. import org.apache.fop.fonts.FontCollection;
  22. import org.apache.fop.fonts.FontInfo;
  23. import org.apache.fop.fonts.base14.Courier;
  24. import org.apache.fop.fonts.base14.CourierBold;
  25. import org.apache.fop.fonts.base14.CourierBoldOblique;
  26. import org.apache.fop.fonts.base14.CourierOblique;
  27. import org.apache.fop.fonts.base14.Helvetica;
  28. import org.apache.fop.fonts.base14.HelveticaBold;
  29. import org.apache.fop.fonts.base14.HelveticaOblique;
  30. import org.apache.fop.fonts.base14.TimesBold;
  31. import org.apache.fop.fonts.base14.TimesBoldItalic;
  32. import org.apache.fop.fonts.base14.TimesItalic;
  33. import org.apache.fop.fonts.base14.TimesRoman;
  34. /**
  35. * Sets up a typical Base 12 font configuration for AFP
  36. */
  37. public class AFPBase12FontCollection implements FontCollection {
  38. /** standard raster font sizes */
  39. private static final int[] RASTER_SIZES = {6, 7, 8, 9, 10, 11, 12, 14, 16, 18, 20, 24, 30, 36};
  40. /** standard raster font charset references */
  41. private static final String[] CHARSET_REF = {
  42. "60", "70", "80", "90", "00", "A0", "B0", "D0", "F0", "H0", "J0", "N0", "T0", "Z0"};
  43. private void addCharacterSet(RasterFont font, String charsetName, Base14Font base14) {
  44. for (int i = 0; i < RASTER_SIZES.length; i++) {
  45. int size = RASTER_SIZES[i];
  46. FopCharacterSet characterSet = new FopCharacterSet(
  47. CharacterSet.DEFAULT_CODEPAGE, CharacterSet.DEFAULT_ENCODING,
  48. charsetName + CHARSET_REF[i], size, base14);
  49. font.addCharacterSet(size, characterSet);
  50. }
  51. }
  52. private int addFontProperties(FontInfo fontInfo, AFPFont font,
  53. String[] names, String style, int weight, int num) {
  54. String internalFontKey = "F" + num;
  55. fontInfo.addMetrics(internalFontKey, font);
  56. fontInfo.addFontProperties(internalFontKey, names, style, weight);
  57. num++;
  58. return num;
  59. }
  60. /** {@inheritDoc} */
  61. public int setup(int start, FontInfo fontInfo) {
  62. /**
  63. * Add the base 12 fonts (Helvetica, Times and Courier)
  64. *
  65. * Note: this default font configuration may not be available
  66. * on your AFP environment.
  67. */
  68. int num = start;
  69. RasterFont font = null;
  70. /** standard font family reference names for Helvetica font */
  71. final String[] helveticaNames = {"Helvetica", "Arial", "sans-serif"};
  72. font = new RasterFont("Helvetica");
  73. addCharacterSet(font, "C0H200", new Helvetica());
  74. num = addFontProperties(fontInfo, font, helveticaNames,
  75. Font.STYLE_NORMAL, Font.WEIGHT_NORMAL, num);
  76. font = new RasterFont("Helvetica Italic");
  77. addCharacterSet(font, "C0H300", new HelveticaOblique());
  78. num = addFontProperties(fontInfo, font, helveticaNames,
  79. Font.STYLE_ITALIC, Font.WEIGHT_NORMAL, num);
  80. font = new RasterFont("Helvetica (Semi) Bold");
  81. addCharacterSet(font, "C0H400", new HelveticaBold());
  82. num = addFontProperties(fontInfo, font, helveticaNames,
  83. Font.STYLE_NORMAL, Font.WEIGHT_BOLD, num);
  84. font = new RasterFont("Helvetica Italic (Semi) Bold");
  85. addCharacterSet(font, "C0H500", new HelveticaOblique());
  86. num = addFontProperties(fontInfo, font, helveticaNames,
  87. Font.STYLE_ITALIC, Font.WEIGHT_BOLD, num);
  88. /** standard font family reference names for Times font */
  89. /** any is treated as serif */
  90. final String[] timesNames = {"Times", "TimesRoman", "Times Roman", "Times-Roman",
  91. "Times New Roman", "TimesNewRoman", "serif", "any"};
  92. font = new RasterFont("Times Roman");
  93. addCharacterSet(font, "CON200", new TimesRoman());
  94. num = addFontProperties(fontInfo, font, timesNames,
  95. Font.STYLE_NORMAL, Font.WEIGHT_NORMAL, num);
  96. font = new RasterFont("Times Roman Italic");
  97. addCharacterSet(font, "CON300", new TimesItalic());
  98. num = addFontProperties(fontInfo, font, timesNames,
  99. Font.STYLE_ITALIC, Font.WEIGHT_NORMAL, num);
  100. font = new RasterFont("Times Roman Bold");
  101. addCharacterSet(font, "CON400", new TimesBold());
  102. num = addFontProperties(fontInfo, font, timesNames,
  103. Font.STYLE_NORMAL, Font.WEIGHT_BOLD, num);
  104. font = new RasterFont("Times Roman Italic Bold");
  105. addCharacterSet(font, "CON500", new TimesBoldItalic());
  106. num = addFontProperties(fontInfo, font, timesNames,
  107. Font.STYLE_ITALIC, Font.WEIGHT_BOLD, num);
  108. /** standard font family reference names for Courier font */
  109. final String[] courierNames = {"Courier", "monospace"};
  110. font = new RasterFont("Courier");
  111. addCharacterSet(font, "C04200", new Courier());
  112. num = addFontProperties(fontInfo, font, courierNames,
  113. Font.STYLE_NORMAL, Font.WEIGHT_NORMAL, num);
  114. font = new RasterFont("Courier Italic");
  115. addCharacterSet(font, "C04300", new CourierOblique());
  116. num = addFontProperties(fontInfo, font, courierNames,
  117. Font.STYLE_ITALIC, Font.WEIGHT_NORMAL, num);
  118. font = new RasterFont("Courier Bold");
  119. addCharacterSet(font, "C04400", new CourierBold());
  120. num = addFontProperties(fontInfo, font, courierNames,
  121. Font.STYLE_NORMAL, Font.WEIGHT_BOLD, num);
  122. font = new RasterFont("Courier Italic Bold");
  123. addCharacterSet(font, "C04500", new CourierBoldOblique());
  124. num = addFontProperties(fontInfo, font, courierNames,
  125. Font.STYLE_ITALIC, Font.WEIGHT_BOLD, num);
  126. return num;
  127. }
  128. }