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.

AbstractOutlineFont.java 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. /**
  21. * A font defined as a set of lines and curves as opposed to a bitmap font. An
  22. * outline font can be scaled to any size and otherwise transformed more easily
  23. * than a bitmap font, and with more attractive results.
  24. */
  25. public abstract class AbstractOutlineFont extends AFPFont {
  26. /** The character set for this font */
  27. protected CharacterSet charSet;
  28. private final AFPEventProducer eventProducer;
  29. /**
  30. * Constructor for an outline font.
  31. *
  32. * @param name the name of the font
  33. * @param embeddable sets whether or not this font is to be embedded
  34. * @param charSet the chracter set
  35. * @param eventProducer The object to handle any events which occur from the object.
  36. */
  37. public AbstractOutlineFont(String name, boolean embeddable, CharacterSet charSet,
  38. AFPEventProducer eventProducer) {
  39. super(name, embeddable);
  40. this.charSet = charSet;
  41. this.eventProducer = eventProducer;
  42. }
  43. AFPEventProducer getAFPEventProducer() {
  44. return eventProducer;
  45. }
  46. /**
  47. * Get the character set metrics.
  48. *
  49. * @return the character set
  50. */
  51. public CharacterSet getCharacterSet() {
  52. return charSet;
  53. }
  54. /**
  55. * Get the character set metrics.
  56. * @param size ignored
  57. * @return the character set
  58. */
  59. public CharacterSet getCharacterSet(int size) {
  60. return charSet;
  61. }
  62. /**
  63. * The ascender is the part of a lowercase letter that extends above the
  64. * "x-height" (the height of the letter "x"), such as "d", "t", or "h". Also
  65. * used to denote the part of the letter extending above the x-height.
  66. *
  67. * @param size the font size (in mpt)
  68. * @return the ascender for the given size
  69. */
  70. public int getAscender(int size) {
  71. return charSet.getAscender() * size;
  72. }
  73. /** {@inheritDoc} */
  74. public int getUnderlinePosition(int size) {
  75. return charSet.getUnderscorePosition() * size;
  76. }
  77. @Override
  78. public int getUnderlineThickness(int size) {
  79. int underscoreWidth = charSet.getUnderscoreWidth();
  80. return underscoreWidth == 0 ? super.getUnderlineThickness(size) : underscoreWidth * size;
  81. }
  82. /**
  83. * Obtains the height of capital letters for the specified point size.
  84. *
  85. * @param size the font size (in mpt)
  86. * @return the cap height for the given size
  87. */
  88. public int getCapHeight(int size) {
  89. return charSet.getCapHeight() * size;
  90. }
  91. /**
  92. * The descender is the part of a lowercase letter that extends below the
  93. * base line, such as "g", "j", or "p". Also used to denote the part of the
  94. * letter extending below the base line.
  95. *
  96. * @param size the font size (in mpt)
  97. * @return the descender for the given size
  98. */
  99. public int getDescender(int size) {
  100. return charSet.getDescender() * size;
  101. }
  102. /**
  103. * The "x-height" (the height of the letter "x").
  104. *
  105. * @param size the font size (in mpt)
  106. * @return the x height for the given size
  107. */
  108. public int getXHeight(int size) {
  109. return charSet.getXHeight() * size;
  110. }
  111. /** {@inheritDoc} */
  112. public boolean hasChar(char c) {
  113. return charSet.hasChar(c);
  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 charSet.mapChar(c);
  122. }
  123. /** {@inheritDoc} */
  124. public String getEncodingName() {
  125. return charSet.getEncoding();
  126. }
  127. }