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.

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