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.

CharacterSetOrientation.java 8.2KB

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