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

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