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.

CharacterSetOrientation.java 8.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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. * The IBM Font Object Content Architecture (FOCA) supports presentation
  21. * of character shapes by defining their characteristics, which include
  22. * Font-Description information for identifying the characters, Font-Metric
  23. * information for positioning the characters, and Character-Shape
  24. * information for presenting the character images.
  25. *
  26. * Presenting a graphic character on a presentation surface requires
  27. * that you communicate this information clearly to rotate and position
  28. * characters correctly on the physical or logical page.
  29. *
  30. * This class provides font metric information for a particular font
  31. * as by the orientation.
  32. *
  33. * This information is obtained directly from the AFP font files which must
  34. * be installed in the classpath under in the location specified by the path
  35. * attribute in the afp-font.xml file.
  36. * <p/>
  37. */
  38. public class CharacterSetOrientation {
  39. /**
  40. * The ascender height for the character set
  41. */
  42. private int ascender;
  43. /**
  44. * The descender depth for the character set
  45. */
  46. private int descender;
  47. /**
  48. * The height of capital letters
  49. */
  50. private int capHeight;
  51. /**
  52. * The character widths in the character set
  53. */
  54. private int[] charsWidths = new int[256];
  55. /**
  56. * The height of lowercase letters
  57. */
  58. private int xHeight;
  59. /**
  60. * The first character
  61. */
  62. private int firstChar;
  63. /**
  64. * The last character
  65. */
  66. private int lastChar;
  67. /**
  68. * The character set orientation
  69. */
  70. private int orientation = 0;
  71. /**
  72. * Constructor for the CharacterSetOrientation, the orientation is
  73. * expressed as the degrees rotation (i.e 0, 90, 180, 270)
  74. * @param orientation the character set orientation
  75. */
  76. public CharacterSetOrientation(int orientation) {
  77. this.orientation = orientation;
  78. }
  79. /**
  80. * Ascender height is the distance from the character baseline to the
  81. * top of the character box. A negative ascender height signifies that
  82. * all of the graphic character is below the character baseline. For
  83. * a character rotation other than 0, ascender height loses its
  84. * meaning when the character is lying on its side or is upside down
  85. * with respect to normal viewing orientation. For the general case,
  86. * Ascender Height is the character�s most positive y-axis value.
  87. * For bounded character boxes, for a given character having an
  88. * ascender, ascender height and baseline offset are equal.
  89. * @return the ascender value in millipoints
  90. */
  91. public int getAscender() {
  92. return ascender;
  93. }
  94. /**
  95. * Cap height is the average height of the uppercase characters in
  96. * a font. This value is specified by the designer of a font and is
  97. * usually the height of the uppercase M.
  98. * @return the cap height value in millipoints
  99. */
  100. public int getCapHeight() {
  101. return capHeight;
  102. }
  103. /**
  104. * Descender depth is the distance from the character baseline to
  105. * the bottom of a character box. A negative descender depth signifies
  106. * that all of the graphic character is above the character baseline.
  107. * @return the descender value in millipoints
  108. */
  109. public int getDescender() {
  110. return descender;
  111. }
  112. /**
  113. * The first character in the character set
  114. * @return the first character
  115. */
  116. public int getFirstChar() {
  117. return firstChar;
  118. }
  119. /**
  120. * The last character in the character set
  121. * @return the last character
  122. */
  123. public int getLastChar() {
  124. return lastChar;
  125. }
  126. /**
  127. * The orientation for these metrics in the character set
  128. * @return the orientation
  129. */
  130. public int getOrientation() {
  131. return orientation;
  132. }
  133. /**
  134. * Get the width (in 1/1000ths of a point size) of all characters
  135. * in this character set.
  136. * @return the widths of all characters
  137. */
  138. public int[] getWidths() {
  139. int[] arr = new int[(getLastChar() - getFirstChar()) + 1];
  140. System.arraycopy(charsWidths, getFirstChar(), arr, 0, (getLastChar() - getFirstChar()) + 1);
  141. return arr;
  142. }
  143. /**
  144. * XHeight refers to the height of the lower case letters above
  145. * the baseline.
  146. * @return heightX the typical height of characters
  147. */
  148. public int getXHeight() {
  149. return xHeight;
  150. }
  151. /**
  152. * Get the width (in 1/1000ths of a point size) of the character
  153. * identified by the parameter passed.
  154. * @param characterIndex the character to evaluate
  155. * @return the widths of the character
  156. */
  157. public int getWidth(int characterIndex) {
  158. if (characterIndex >= charsWidths.length) {
  159. throw new IllegalArgumentException("Invalid character index: "
  160. + characterIndex + ", maximum is " + (charsWidths.length - 1));
  161. }
  162. return charsWidths[characterIndex];
  163. }
  164. /**
  165. * Ascender height is the distance from the character baseline to the
  166. * top of the character box. A negative ascender height signifies that
  167. * all of the graphic character is below the character baseline. For
  168. * a character rotation other than 0, ascender height loses its
  169. * meaning when the character is lying on its side or is upside down
  170. * with respect to normal viewing orientation. For the general case,
  171. * Ascender Height is the character�s most positive y-axis value.
  172. * For bounded character boxes, for a given character having an
  173. * ascender, ascender height and baseline offset are equal.
  174. * @param ascender the ascender to set
  175. */
  176. public void setAscender(int ascender) {
  177. this.ascender = ascender;
  178. }
  179. /**
  180. * Cap height is the average height of the uppercase characters in
  181. * a font. This value is specified by the designer of a font and is
  182. * usually the height of the uppercase M.
  183. * @param capHeight the cap height to set
  184. */
  185. public void setCapHeight(int capHeight) {
  186. this.capHeight = capHeight;
  187. }
  188. /**
  189. * Descender depth is the distance from the character baseline to
  190. * the bottom of a character box. A negative descender depth signifies
  191. * that all of the graphic character is above the character baseline.
  192. * @param descender the descender value in millipoints
  193. */
  194. public void setDescender(int descender) {
  195. this.descender = descender;
  196. }
  197. /**
  198. * The first character in the character set
  199. * @param firstChar the first character
  200. */
  201. public void setFirstChar(int firstChar) {
  202. this.firstChar = firstChar;
  203. }
  204. /**
  205. * The last character in the character set
  206. * @param lastChar the last character
  207. */
  208. public void setLastChar(int lastChar) {
  209. this.lastChar = lastChar;
  210. }
  211. /**
  212. * Set the width (in 1/1000ths of a point size) of the character
  213. * identified by the parameter passed.
  214. * @param character the character for which the width is being set
  215. * @param width the widths of the character
  216. */
  217. public void setWidth(int character, int width) {
  218. if (character >= charsWidths.length) {
  219. // Increase the size of the array if necessary
  220. int[] arr = new int[(character - firstChar) + 1];
  221. System.arraycopy(charsWidths, 0, arr, 0, charsWidths.length);
  222. charsWidths = arr;
  223. }
  224. charsWidths[character] = width;
  225. }
  226. /**
  227. * XHeight refers to the height of the lower case letters above
  228. * the baseline.
  229. * @param xHeight the typical height of characters
  230. */
  231. public void setXHeight(int xHeight) {
  232. this.xHeight = xHeight;
  233. }
  234. }