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.

AFPFont.java 4.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 java.awt.Rectangle;
  20. import java.util.HashSet;
  21. import java.util.Map;
  22. import java.util.Set;
  23. import org.apache.fop.fonts.FontType;
  24. import org.apache.fop.fonts.Typeface;
  25. /**
  26. * All implementations of AFP fonts should extend this base class,
  27. * the object implements the FontMetrics information.
  28. * <p/>
  29. */
  30. public abstract class AFPFont extends Typeface {
  31. private static final double STRIKEOUT_POSITION_FACTOR = 0.45;
  32. /** The font name */
  33. protected final String name;
  34. private final boolean embeddable;
  35. /**
  36. * Constructor for the base font requires the name.
  37. * @param name the name of the font
  38. * @param embeddable whether this font is to be embedded
  39. */
  40. public AFPFont(String name, boolean embeddable) {
  41. this.name = name;
  42. this.embeddable = embeddable;
  43. }
  44. /** {@inheritDoc} */
  45. public String getFontName() {
  46. return this.name;
  47. }
  48. /** {@inheritDoc} */
  49. public String getEmbedFontName() {
  50. return this.name;
  51. }
  52. /** {@inheritDoc} */
  53. public String getFullName() {
  54. return getFontName();
  55. }
  56. /** {@inheritDoc} */
  57. public Set<String> getFamilyNames() {
  58. Set<String> s = new HashSet<String>();
  59. s.add(this.name);
  60. return s;
  61. }
  62. /**
  63. * Returns the type of the font.
  64. * @return the font type
  65. */
  66. public FontType getFontType() {
  67. return FontType.OTHER;
  68. }
  69. /**
  70. * Indicates if the font has kerning information.
  71. * @return True, if kerning is available.
  72. */
  73. public boolean hasKerningInfo() {
  74. return false;
  75. }
  76. /**
  77. * Returns the kerning map for the font.
  78. * @return the kerning map
  79. */
  80. public Map<Integer, Map<Integer, Integer>> getKerningInfo() {
  81. return null;
  82. }
  83. /**
  84. * Returns the character set for a given size
  85. * @param size the font size
  86. * @return the character set object
  87. */
  88. public abstract CharacterSet getCharacterSet(int size);
  89. /**
  90. * Indicates if this font may be embedded.
  91. * @return True, if embedding is possible/permitted
  92. */
  93. public boolean isEmbeddable() {
  94. return this.embeddable;
  95. }
  96. /**
  97. * Maps mapped code points to Unicode code points.
  98. * @param character the mapped code point
  99. * @return the corresponding Unicode code point
  100. */
  101. protected static final char toUnicodeCodepoint(int character) {
  102. //AFP fonts use Unicode directly as their mapped code points, so we can simply cast to char
  103. return (char) character;
  104. }
  105. /** {@inheritDoc} */
  106. public int getUnderlineThickness(int size) {
  107. // This is the FOCA recommendation in the absence of the Underline Thickness parameter
  108. return getBoundingBox('-', size).height;
  109. }
  110. /** {@inheritDoc} */
  111. public int getStrikeoutPosition(int size) {
  112. //TODO This conflicts with the FOCA recommendation of 0 in the absence of the Throughscore Position
  113. // parameter
  114. return (int) (STRIKEOUT_POSITION_FACTOR * getCapHeight(size));
  115. }
  116. /** {@inheritDoc} */
  117. public int getStrikeoutThickness(int size) {
  118. // This is the FOCA recommendation in the absence of the Throughscore Thickness parameter
  119. return getBoundingBox('-', size).height;
  120. }
  121. /** {@inheritDoc} */
  122. public abstract Rectangle getBoundingBox(int glyphIndex, int size);
  123. /** {@inheritDoc} */
  124. public int[] getWidths() {
  125. throw new UnsupportedOperationException();
  126. }
  127. /** {@inheritDoc} */
  128. public String toString() {
  129. return "name=" + name;
  130. }
  131. }