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.

FopCharacterSet.java 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. import org.apache.fop.fonts.Typeface;
  19. /**
  20. * A Character set for a normal FOP font<p/>
  21. */
  22. public class FopCharacterSet extends CharacterSet {
  23. /** The character set for this font */
  24. private Typeface _characterSet = null;
  25. private int _size = 0;
  26. /**
  27. * Constructor for the CharacterSetMetric object, the character set is used
  28. * to load the font information from the actual AFP font.
  29. * @param codePage the code page identifier
  30. * @param encoding the encoding of the font
  31. * @param name the character set name
  32. * @param size the font size
  33. * @param Typeface the fop character set
  34. */
  35. public FopCharacterSet(
  36. String codePage,
  37. String encoding,
  38. String name,
  39. int size,
  40. Typeface characterSet) {
  41. super(codePage, encoding, name, null);
  42. _characterSet = characterSet;
  43. _size = size * 1000;
  44. }
  45. /**
  46. * Ascender height is the distance from the character baseline to the
  47. * top of the character box. A negative ascender height signifies that
  48. * all of the graphic character is below the character baseline. For
  49. * a character rotation other than 0, ascender height loses its
  50. * meaning when the character is lying on its side or is upside down
  51. * with respect to normal viewing orientation. For the general case,
  52. * Ascender Height is the character�s most positive y-axis value.
  53. * For bounded character boxes, for a given character having an
  54. * ascender, ascender height and baseline offset are equal.
  55. * @return the ascender value in millipoints
  56. */
  57. public int getAscender() {
  58. return _characterSet.getAscender(_size);
  59. }
  60. /**
  61. * Cap height is the average height of the uppercase characters in
  62. * a font. This value is specified by the designer of a font and is
  63. * usually the height of the uppercase M.
  64. * @return the cap height value in millipoints
  65. */
  66. public int getCapHeight() {
  67. return _characterSet.getCapHeight(_size);
  68. }
  69. /**
  70. * Descender depth is the distance from the character baseline to
  71. * the bottom of a character box. A negative descender depth signifies
  72. * that all of the graphic character is above the character baseline.
  73. * @return the descender value in millipoints
  74. */
  75. public int getDescender() {
  76. return _characterSet.getDescender(_size);
  77. }
  78. /**
  79. * The first character in the character set
  80. * @return the first character
  81. */
  82. public int getFirstChar() {
  83. return 0;
  84. }
  85. /**
  86. * The last character in the character set
  87. * @return the last character
  88. */
  89. public int getLastChar() {
  90. return 0;
  91. }
  92. /**
  93. * Get the width (in 1/1000ths of a point size) of all characters
  94. * @return the widths of all characters
  95. */
  96. public int[] getWidths() {
  97. return _characterSet.getWidths();
  98. }
  99. /**
  100. * XHeight refers to the height of the lower case letters above the baseline.
  101. * @return the typical height of characters
  102. */
  103. public int getXHeight() {
  104. return _characterSet.getXHeight(_size);
  105. }
  106. /**
  107. * Get the width (in 1/1000ths of a point size) of the character
  108. * identified by the parameter passed.
  109. * @param character the character from which the width will be calculated
  110. * @return the width of the character
  111. */
  112. public int width(int character) {
  113. return _characterSet.getWidth(character, _size);
  114. }
  115. /**
  116. * Map a Unicode character to a code point in the font.
  117. * @param c character to map
  118. * @return the mapped character
  119. */
  120. public char mapChar(char c) {
  121. return _characterSet.mapChar(c);
  122. }
  123. }