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.

FontState.java 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * $Id$
  3. * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  4. * For details on use and redistribution please refer to the
  5. * LICENSE file included with these sources.
  6. */
  7. package org.apache.fop.layout;
  8. import java.util.HashMap;
  9. import org.apache.fop.fo.properties.FontVariant;
  10. import org.apache.fop.render.pdf.CodePointMapping;
  11. public class FontState {
  12. private String _fontName;
  13. private int _fontSize;
  14. private String _fontFamily;
  15. private String _fontStyle;
  16. private int _fontWeight;
  17. /**
  18. * normal or small-caps font
  19. */
  20. private int _fontVariant;
  21. private FontMetric _metric;
  22. private static HashMap EMPTY_HASHMAP = new HashMap();
  23. public FontState(String key, FontMetric met, int fontSize) {
  24. _fontSize = fontSize;
  25. _fontName = key;
  26. _metric = met;
  27. }
  28. public int getAscender() {
  29. return _metric.getAscender(_fontSize) / 1000;
  30. }
  31. public int getCapHeight() {
  32. return _metric.getCapHeight(_fontSize) / 1000;
  33. }
  34. public int getDescender() {
  35. return _metric.getDescender(_fontSize) / 1000;
  36. }
  37. public String getFontName() {
  38. return _fontName;
  39. }
  40. public int getFontSize() {
  41. return _fontSize;
  42. }
  43. public int getXHeight() {
  44. return _metric.getXHeight(_fontSize) / 1000;
  45. }
  46. public HashMap getKerning() {
  47. if (_metric instanceof FontDescriptor) {
  48. HashMap ret = ((FontDescriptor)_metric).getKerningInfo();
  49. if (ret != null)
  50. return ret;
  51. }
  52. return EMPTY_HASHMAP;
  53. }
  54. public int width(int charnum) {
  55. // returns width of given character number in millipoints
  56. return (_metric.width(charnum, _fontSize) / 1000);
  57. }
  58. /**
  59. * Map a java character (unicode) to a font character
  60. * Default uses CodePointMapping
  61. */
  62. public char mapChar(char c) {
  63. if (_metric instanceof org.apache.fop.render.pdf.Font) {
  64. return ((org.apache.fop.render.pdf.Font)_metric).mapChar(c);
  65. }
  66. // Use default CodePointMapping
  67. char d = CodePointMapping.getMapping("WinAnsiEncoding").mapChar(c);
  68. if (d != 0) {
  69. c = d;
  70. } else {
  71. c = '#';
  72. }
  73. return c;
  74. }
  75. public String toString() {
  76. StringBuffer sbuf = new StringBuffer();
  77. sbuf.append('(');
  78. sbuf.append(_fontFamily);
  79. sbuf.append(',');
  80. sbuf.append(_fontName);
  81. sbuf.append(',');
  82. sbuf.append(_fontSize);
  83. sbuf.append(',');
  84. sbuf.append(_fontStyle);
  85. sbuf.append(',');
  86. sbuf.append(_fontWeight);
  87. sbuf.append(')');
  88. return sbuf.toString();
  89. }
  90. }