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.

SystemFontMetricsMapper.java 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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.render.java2d;
  19. // Java
  20. import java.awt.Rectangle;
  21. import java.util.Map;
  22. import java.util.Set;
  23. import org.apache.fop.fonts.FontType;
  24. import org.apache.fop.fonts.Typeface;
  25. /**
  26. * This class implements org.apache.fop.layout.FontMetrics and
  27. * is added to the hash table in FontInfo. It deferes the
  28. * actual calculation of the metrics to
  29. * Java2DFontMetrics. It only keeps the java name and
  30. * style as member varibles
  31. */
  32. public class SystemFontMetricsMapper extends Typeface implements FontMetricsMapper {
  33. /**
  34. * This is a Java2DFontMetrics that does the real calculation.
  35. * It is only one class that dynamically determines the font-size.
  36. */
  37. private final Java2DFontMetrics java2DFontMetrics;
  38. /**
  39. * The java name of the font.
  40. * # Make the family name immutable.
  41. */
  42. private final String family;
  43. /**
  44. * The java style of the font.
  45. * # Make the style immutable.
  46. */
  47. private final int style;
  48. /**
  49. * Constructs a new Font-metrics.
  50. * @param family the family name of the font (java value)
  51. * @param style the java type style value of the font
  52. * @param java2DFontMetrics metric calculations delegated to this
  53. */
  54. public SystemFontMetricsMapper(String family, int style, Java2DFontMetrics java2DFontMetrics) {
  55. this.family = family;
  56. this.style = style;
  57. this.java2DFontMetrics = java2DFontMetrics;
  58. }
  59. /** {@inheritDoc} */
  60. public String getFontName() {
  61. return family;
  62. }
  63. /** {@inheritDoc} */
  64. public String getEmbedFontName() {
  65. return getFontName();
  66. }
  67. /** {@inheritDoc} */
  68. public String getFullName() {
  69. return getFontName();
  70. }
  71. /** {@inheritDoc} */
  72. public Set getFamilyNames() {
  73. Set s = new java.util.HashSet();
  74. s.add(this.family);
  75. return s;
  76. }
  77. /**
  78. * {@inheritDoc}
  79. */
  80. public FontType getFontType() {
  81. return FontType.OTHER;
  82. }
  83. /**
  84. * {@inheritDoc}
  85. */
  86. public int getMaxAscent(int size) {
  87. return java2DFontMetrics.getMaxAscent(family, style, size);
  88. }
  89. /**
  90. * {@inheritDoc}
  91. */
  92. public int getAscender(int size) {
  93. return java2DFontMetrics.getAscender(family, style, size);
  94. }
  95. /**
  96. * {@inheritDoc}
  97. */
  98. public int getCapHeight(int size) {
  99. return java2DFontMetrics.getCapHeight(family, style, size);
  100. }
  101. /**
  102. * {@inheritDoc}
  103. */
  104. public int getDescender(int size) {
  105. return java2DFontMetrics.getDescender(family, style, size);
  106. }
  107. /**
  108. * {@inheritDoc}
  109. */
  110. public int getXHeight(int size) {
  111. return java2DFontMetrics.getXHeight(family, style, size);
  112. }
  113. public int getUnderlinePosition(int size) {
  114. return java2DFontMetrics.getUnderlinePosition(family, style, size);
  115. }
  116. public int getUnderlineThickness(int size) {
  117. return java2DFontMetrics.getUnderlineThickness(family, style, size);
  118. }
  119. public int getStrikeoutPosition(int size) {
  120. return java2DFontMetrics.getStrikeoutPosition(family, style, size);
  121. }
  122. public int getStrikeoutThickness(int size) {
  123. return java2DFontMetrics.getStrikeoutThickness(family, style, size);
  124. }
  125. /**
  126. * {@inheritDoc}
  127. */
  128. public int getWidth(int i, int size) {
  129. return java2DFontMetrics.width(i, family, style, size);
  130. }
  131. /**
  132. * {@inheritDoc}
  133. */
  134. public int[] getWidths() {
  135. return java2DFontMetrics.getWidths(family, style, Java2DFontMetrics.FONT_SIZE);
  136. }
  137. public Rectangle getBoundingBox(int glyphIndex, int size) {
  138. throw new UnsupportedOperationException("Not implemented");
  139. }
  140. /**
  141. * {@inheritDoc}
  142. */
  143. public java.awt.Font getFont(int size) {
  144. return java2DFontMetrics.getFont(family, style, size);
  145. }
  146. /**
  147. * {@inheritDoc}
  148. */
  149. public Map getKerningInfo() {
  150. return java.util.Collections.EMPTY_MAP;
  151. }
  152. /**
  153. * {@inheritDoc}
  154. */
  155. public boolean hasKerningInfo() {
  156. return false;
  157. }
  158. /** {@inheritDoc} */
  159. public String getEncodingName() {
  160. return null; //Not applicable to Java2D rendering
  161. }
  162. /** {@inheritDoc} */
  163. public char mapChar(char c) {
  164. return c;
  165. }
  166. /** {@inheritDoc} */
  167. public boolean hasChar(char c) {
  168. return java2DFontMetrics.hasChar(family, style, Java2DFontMetrics.FONT_SIZE, c);
  169. }
  170. }