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.

AbstractOutlineFont.java 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. /**
  20. * A font defined as a set of lines and curves as opposed to a bitmap font. An
  21. * outline font can be scaled to any size and otherwise transformed more easily
  22. * than a bitmap font, and with more attractive results.
  23. */
  24. public abstract class AbstractOutlineFont extends AFPFont {
  25. /** The character set for this font */
  26. protected CharacterSet charSet = null;
  27. /**
  28. * Constructor for an outline font.
  29. *
  30. * @param name the name of the font
  31. * @param embeddable sets whether or not this font is to be embedded
  32. * @param charSet the chracter set
  33. */
  34. public AbstractOutlineFont(String name, boolean embeddable, CharacterSet charSet) {
  35. super(name, embeddable);
  36. this.charSet = charSet;
  37. }
  38. /**
  39. * Get the character set metrics.
  40. *
  41. * @return the character set
  42. */
  43. public CharacterSet getCharacterSet() {
  44. return charSet;
  45. }
  46. /**
  47. * Get the character set metrics.
  48. * @param size ignored
  49. * @return the character set
  50. */
  51. public CharacterSet getCharacterSet(int size) {
  52. return charSet;
  53. }
  54. /**
  55. * Get the first character in this font.
  56. * @return the first character in this font
  57. */
  58. public int getFirstChar() {
  59. return charSet.getFirstChar();
  60. }
  61. /**
  62. * Get the last character in this font.
  63. * @return the last character in this font
  64. */
  65. public int getLastChar() {
  66. return charSet.getLastChar();
  67. }
  68. /**
  69. * The ascender is the part of a lowercase letter that extends above the
  70. * "x-height" (the height of the letter "x"), such as "d", "t", or "h". Also
  71. * used to denote the part of the letter extending above the x-height.
  72. *
  73. * @param size the font size (in mpt)
  74. * @return the ascender for the given size
  75. */
  76. public int getAscender(int size) {
  77. return charSet.getAscender() * size;
  78. }
  79. /**
  80. * Obtains the height of capital letters for the specified point size.
  81. *
  82. * @param size the font size (in mpt)
  83. * @return the cap height for the given size
  84. */
  85. public int getCapHeight(int size) {
  86. return charSet.getCapHeight() * size;
  87. }
  88. /**
  89. * The descender is the part of a lowercase letter that extends below the
  90. * base line, such as "g", "j", or "p". Also used to denote the part of the
  91. * letter extending below the base line.
  92. *
  93. * @param size the font size (in mpt)
  94. * @return the descender for the given size
  95. */
  96. public int getDescender(int size) {
  97. return charSet.getDescender() * size;
  98. }
  99. /**
  100. * The "x-height" (the height of the letter "x").
  101. *
  102. * @param size the font size (in mpt)
  103. * @return the x height for the given size
  104. */
  105. public int getXHeight(int size) {
  106. return charSet.getXHeight() * size;
  107. }
  108. /**
  109. * Obtain the width of the character for the specified point size.
  110. * @param character the character
  111. * @param size the font size (in mpt)
  112. * @return the width of the character for the specified point size
  113. */
  114. public int getWidth(int character, int size) {
  115. return charSet.getWidth(toUnicodeCodepoint(character)) * size;
  116. }
  117. /**
  118. * Get the getWidth (in 1/1000ths of a point size) of all characters in this
  119. * character set.
  120. *
  121. * @param size the font size (in mpt)
  122. * @return the widths of all characters
  123. */
  124. public int[] getWidths(int size) {
  125. int[] widths = charSet.getWidths();
  126. for (int i = 0; i < widths.length; i++) {
  127. widths[i] = widths[i] * size;
  128. }
  129. return widths;
  130. }
  131. /**
  132. * Get the getWidth (in 1/1000ths of a point size) of all characters in this
  133. * character set.
  134. *
  135. * @return the widths of all characters
  136. */
  137. public int[] getWidths() {
  138. return getWidths(1000);
  139. }
  140. /** {@inheritDoc} */
  141. public boolean hasChar(char c) {
  142. return charSet.hasChar(c);
  143. }
  144. /**
  145. * Map a Unicode character to a code point in the font.
  146. * @param c character to map
  147. * @return the mapped character
  148. */
  149. public char mapChar(char c) {
  150. return charSet.mapChar(c);
  151. }
  152. /** {@inheritDoc} */
  153. public String getEncodingName() {
  154. return charSet.getEncoding();
  155. }
  156. }