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.5KB

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