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 4.6KB

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