Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

Typeface.java 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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.fonts;
  19. import java.util.HashSet;
  20. import java.util.Set;
  21. import org.apache.commons.logging.Log;
  22. import org.apache.commons.logging.LogFactory;
  23. import org.apache.xmlgraphics.fonts.Glyphs;
  24. /**
  25. * Base class for font classes
  26. */
  27. public abstract class Typeface implements FontMetrics {
  28. /**
  29. * Code point that is used if no code point for a specific character has
  30. * been found.
  31. */
  32. public static final char NOT_FOUND = '#';
  33. /** logger */
  34. private static Log log = LogFactory.getLog(Typeface.class);
  35. /**
  36. * Used to identify whether a font has been used (a character map operation
  37. * is used as the trigger). This could just as well be a boolean but is a
  38. * long out of statistical interest.
  39. */
  40. private long charMapOps;
  41. /** An optional event listener that receives events such as missing glyphs etc. */
  42. protected FontEventListener eventListener;
  43. private Set<Character> warnedChars;
  44. /**
  45. * Get the encoding of the font.
  46. * @return the encoding
  47. */
  48. public abstract String getEncodingName();
  49. /**
  50. * Map a Unicode character to a code point in the font.
  51. * @param c character to map
  52. * @return the mapped character
  53. */
  54. public abstract char mapChar(char c);
  55. /**
  56. * Used for keeping track of character mapping operations in order to determine if a font
  57. * was used at all or not.
  58. */
  59. protected void notifyMapOperation() {
  60. this.charMapOps++;
  61. }
  62. /**
  63. * Indicates whether this font had to do any character mapping operations. If that was
  64. * not the case, it's an indication that the font has never actually been used.
  65. * @return true if the font had to do any character mapping operations
  66. */
  67. public boolean hadMappingOperations() {
  68. return (this.charMapOps > 0);
  69. }
  70. /**
  71. * Determines whether this font contains a particular character/glyph.
  72. * @param c character to check
  73. * @return True if the character is supported, Falso otherwise
  74. */
  75. public abstract boolean hasChar(char c);
  76. /**
  77. * Determines whether the font is a multibyte font.
  78. * @return True if it is multibyte
  79. */
  80. public boolean isMultiByte() {
  81. return false;
  82. }
  83. public boolean isCID() {
  84. return getFontType() == FontType.TYPE1C;
  85. }
  86. /** {@inheritDoc} */
  87. public int getMaxAscent(int size) {
  88. return getAscender(size);
  89. }
  90. /** {@inheritDoc} */
  91. public boolean hasFeature(int tableType, String script, String language, String feature) {
  92. return false;
  93. }
  94. /**
  95. * Sets the font event listener that can be used to receive events about particular events
  96. * in this class.
  97. * @param listener the font event listener
  98. */
  99. public void setEventListener(FontEventListener listener) {
  100. this.eventListener = listener;
  101. }
  102. /**
  103. * Provide proper warning if a glyph is not available.
  104. *
  105. * @param c
  106. * the character which is missing.
  107. */
  108. protected void warnMissingGlyph(char c) {
  109. // Give up, character is not available
  110. Character ch = c;
  111. if (warnedChars == null) {
  112. warnedChars = new HashSet<Character>();
  113. }
  114. if (warnedChars.size() < 8 && !warnedChars.contains(ch)) {
  115. warnedChars.add(ch);
  116. if (this.eventListener != null) {
  117. this.eventListener.glyphNotAvailable(this, c, getFontName());
  118. } else {
  119. if (warnedChars.size() == 8) {
  120. log.warn("Many requested glyphs are not available in font "
  121. + getFontName());
  122. } else {
  123. log.warn("Glyph " + (int) c + " (0x"
  124. + Integer.toHexString(c) + ", "
  125. + Glyphs.charToGlyphName(c)
  126. + ") not available in font " + getFontName());
  127. }
  128. }
  129. }
  130. }
  131. /** {@inheritDoc} */
  132. public String toString() {
  133. StringBuffer sbuf = new StringBuffer(super.toString());
  134. sbuf.append('{');
  135. sbuf.append(getFullName());
  136. sbuf.append('}');
  137. return sbuf.toString();
  138. }
  139. }