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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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
  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. public FopCharacterSet(String codePage, String encoding, String name, Typeface charSet,
  45. AFPResourceAccessor accessor, AFPEventProducer eventProducer) {
  46. super(codePage, encoding, CharacterSetType.SINGLE_BYTE, name, accessor, eventProducer);
  47. this.charSet = charSet;
  48. }
  49. /**
  50. * Ascender height is the distance from the character baseline to the
  51. * top of the character box. A negative ascender height signifies that
  52. * all of the graphic character is below the character baseline. For
  53. * a character rotation other than 0, ascender height loses its
  54. * meaning when the character is lying on its side or is upside down
  55. * with respect to normal viewing orientation. For the general case,
  56. * Ascender Height is the character's most positive y-axis value.
  57. * For bounded character boxes, for a given character having an
  58. * ascender, ascender height and baseline offset are equal.
  59. * @return the ascender value in millipoints
  60. */
  61. public int getAscender() {
  62. return charSet.getAscender(1);
  63. }
  64. /**
  65. * Cap height is the average height of the uppercase characters in
  66. * a font. This value is specified by the designer of a font and is
  67. * usually the height of the uppercase M.
  68. * @return the cap height value in millipoints
  69. */
  70. public int getCapHeight() {
  71. return charSet.getCapHeight(1);
  72. }
  73. /**
  74. * Descender depth is the distance from the character baseline to
  75. * the bottom of a character box. A negative descender depth signifies
  76. * that all of the graphic character is above the character baseline.
  77. * @return the descender value in millipoints
  78. */
  79. public int getDescender() {
  80. return charSet.getDescender(1);
  81. }
  82. /**
  83. * XHeight refers to the height of the lower case letters above the baseline.
  84. * @return the typical height of characters
  85. */
  86. public int getXHeight() {
  87. return charSet.getXHeight(1);
  88. }
  89. @Override
  90. public int getWidth(char character, int size) {
  91. return charSet.getWidth(character, size);
  92. }
  93. @Override
  94. public Rectangle getCharacterBox(char character, int size) {
  95. return charSet.getBoundingBox(character, size);
  96. };
  97. @Override
  98. public int getUnderscoreWidth() {
  99. return charSet.getUnderlineThickness(1);
  100. }
  101. @Override
  102. public int getUnderscorePosition() {
  103. return charSet.getUnderlinePosition(1);
  104. }
  105. /**
  106. * Map a Unicode character to a code point in the font.
  107. * @param c character to map
  108. * @return the mapped character
  109. */
  110. public char mapChar(char c) {
  111. return charSet.mapChar(c);
  112. }
  113. }