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.

OutlineFont.java 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*
  2. * Copyright 2006 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* $Id$ */
  17. package org.apache.fop.render.afp.fonts;
  18. /**
  19. * A font defined as a set of lines and curves as opposed to a bitmap font. An
  20. * outline font can be scaled to any size and otherwise transformed more easily
  21. * than a bitmap font, and with more attractive results. <p/>
  22. *
  23. */
  24. public class OutlineFont extends AFPFont {
  25. /** The character set for this font */
  26. private CharacterSet _characterSet = null;
  27. /**
  28. * Constructor for an outline font.
  29. *
  30. * @param name
  31. * the name of the font
  32. * @param characterSet
  33. * the chracter set
  34. */
  35. public OutlineFont(String name, CharacterSet characterSet) {
  36. super(name);
  37. _characterSet = characterSet;
  38. }
  39. /**
  40. * Get the character set metrics.
  41. *
  42. * @return the character set
  43. */
  44. public CharacterSet getCharacterSet() {
  45. return _characterSet;
  46. }
  47. /**
  48. * Get the character set metrics.
  49. * @param size ignored
  50. * @return the character set
  51. */
  52. public CharacterSet getCharacterSet(int size) {
  53. return _characterSet;
  54. }
  55. /**
  56. * Get the first character in this font.
  57. */
  58. public int getFirstChar() {
  59. return _characterSet.getFirstChar();
  60. }
  61. /**
  62. * Get the last character in this font.
  63. */
  64. public int getLastChar() {
  65. return _characterSet.getLastChar();
  66. }
  67. /**
  68. * The ascender is the part of a lowercase letter that extends above the
  69. * "x-height" (the height of the letter "x"), such as "d", "t", or "h". Also
  70. * used to denote the part of the letter extending above the x-height.
  71. *
  72. * @param size
  73. * the point size
  74. */
  75. public int getAscender(int size) {
  76. return _characterSet.getAscender() / 1000 * size;
  77. }
  78. /**
  79. * Obtains the height of capital letters for the specified point size.
  80. *
  81. * @param size
  82. * the point size
  83. */
  84. public int getCapHeight(int size) {
  85. return _characterSet.getCapHeight() / 1000 * size;
  86. }
  87. /**
  88. * The descender is the part of a lowercase letter that extends below the
  89. * base line, such as "g", "j", or "p". Also used to denote the part of the
  90. * letter extending below the base line.
  91. *
  92. * @param size
  93. * the point size
  94. */
  95. public int getDescender(int size) {
  96. return _characterSet.getDescender() / 1000 * size;
  97. }
  98. /**
  99. * The "x-height" (the height of the letter "x").
  100. *
  101. * @param size
  102. * the point size
  103. */
  104. public int getXHeight(int size) {
  105. return _characterSet.getXHeight() / 1000 * size;
  106. }
  107. /**
  108. * Obtain the width of the character for the specified point size.
  109. */
  110. public int getWidth(int character, int size) {
  111. return _characterSet.width(character) / 1000 * size;
  112. }
  113. /**
  114. * Get the getWidth (in 1/1000ths of a point size) of all characters in this
  115. * character set.
  116. *
  117. * @param size
  118. * the point size
  119. * @return the widths of all characters
  120. */
  121. public int[] getWidths(int size) {
  122. int[] widths = _characterSet.getWidths();
  123. for (int i = 0 ; i < widths.length; i++) {
  124. widths[i] = widths[i] / 1000 * size;
  125. }
  126. return widths;
  127. }
  128. /**
  129. * Get the getWidth (in 1/1000ths of a point size) of all characters in this
  130. * character set.
  131. *
  132. * @return the widths of all characters
  133. */
  134. public int[] getWidths() {
  135. return getWidths(1000);
  136. }
  137. /**
  138. * Map a Unicode character to a code point in the font.
  139. * @param c character to map
  140. * @return the mapped character
  141. */
  142. public char mapChar(char c) {
  143. return _characterSet.mapChar(c);
  144. }
  145. /**
  146. * Get the encoding of the font.
  147. * @return the encoding
  148. */
  149. public String getEncoding() {
  150. return _characterSet.getEncoding();
  151. }
  152. }