Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

SystemFontMetricsMapper.java 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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.Graphics2D;
  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 static Java2DFontMetrics metric = null;
  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 graphics a Graphics2D object - this is needed so
  53. * that we can get an instance of java.awt.FontMetrics
  54. */
  55. public SystemFontMetricsMapper(String family, int style, Graphics2D graphics) {
  56. this.family = family;
  57. this.style = style;
  58. if (metric == null) {
  59. metric = new Java2DFontMetrics(graphics);
  60. }
  61. }
  62. /** {@inheritDoc} */
  63. public String getFontName() {
  64. return family;
  65. }
  66. /** {@inheritDoc} */
  67. public String getEmbedFontName() {
  68. return getFontName();
  69. }
  70. /** {@inheritDoc} */
  71. public String getFullName() {
  72. return getFontName();
  73. }
  74. /** {@inheritDoc} */
  75. public Set getFamilyNames() {
  76. Set s = new java.util.HashSet();
  77. s.add(this.family);
  78. return s;
  79. }
  80. /**
  81. * {@inheritDoc}
  82. */
  83. public FontType getFontType() {
  84. return FontType.OTHER;
  85. }
  86. /**
  87. * {@inheritDoc}
  88. */
  89. public int getMaxAscent(int size) {
  90. return metric.getMaxAscent(family, style, size);
  91. }
  92. /**
  93. * {@inheritDoc}
  94. */
  95. public int getAscender(int size) {
  96. return metric.getAscender(family, style, size);
  97. }
  98. /**
  99. * {@inheritDoc}
  100. */
  101. public int getCapHeight(int size) {
  102. return metric.getCapHeight(family, style, size);
  103. }
  104. /**
  105. * {@inheritDoc}
  106. */
  107. public int getDescender(int size) {
  108. return metric.getDescender(family, style, size);
  109. }
  110. /**
  111. * {@inheritDoc}
  112. */
  113. public int getXHeight(int size) {
  114. return metric.getXHeight(family, style, size);
  115. }
  116. /**
  117. * {@inheritDoc}
  118. */
  119. public int getWidth(int i, int size) {
  120. return metric.width(i, family, style, size);
  121. }
  122. /**
  123. * {@inheritDoc}
  124. */
  125. public int[] getWidths() {
  126. return metric.getWidths(family, style, Java2DFontMetrics.FONT_SIZE);
  127. }
  128. /**
  129. * {@inheritDoc}
  130. */
  131. public java.awt.Font getFont(int size) {
  132. return metric.getFont(family, style, size);
  133. }
  134. /**
  135. * {@inheritDoc}
  136. */
  137. public Map getKerningInfo() {
  138. return java.util.Collections.EMPTY_MAP;
  139. }
  140. /**
  141. * {@inheritDoc}
  142. */
  143. public boolean hasKerningInfo() {
  144. return false;
  145. }
  146. /** {@inheritDoc} */
  147. public String getEncoding() {
  148. return null; //Not applicable to Java2D rendering
  149. }
  150. /** {@inheritDoc} */
  151. public char mapChar(char c) {
  152. return c;
  153. }
  154. /** {@inheritDoc} */
  155. public boolean hasChar(char c) {
  156. return metric.hasChar(family, style, Java2DFontMetrics.FONT_SIZE, c);
  157. }
  158. }