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

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