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.5KB

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