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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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.fonts.type1;
  19. import java.awt.Rectangle;
  20. import org.apache.fop.fonts.NamedCharacter;
  21. /**
  22. * Holds the metrics of a single character from an AFM file.
  23. */
  24. public class AFMCharMetrics {
  25. private int charCode = -1;
  26. private NamedCharacter character;
  27. private double widthX;
  28. private double widthY;
  29. private Rectangle bBox;
  30. /**
  31. * Returns the character code.
  32. * @return the charCode (-1 if not part of the encoding)
  33. */
  34. public int getCharCode() {
  35. return charCode;
  36. }
  37. /**
  38. * Indicates whether the character has a character code, i.e. is part of the default encoding.
  39. * @return true if there is a character code.
  40. */
  41. public boolean hasCharCode() {
  42. return charCode >= 0;
  43. }
  44. /**
  45. * Sets the character code.
  46. * @param charCode the charCode to set
  47. */
  48. public void setCharCode(int charCode) {
  49. this.charCode = charCode;
  50. }
  51. /**
  52. * Returns the named character represented by this instance.
  53. * @return the named character (or null if no named character is associated)
  54. */
  55. public NamedCharacter getCharacter() {
  56. return this.character;
  57. }
  58. /**
  59. * Sets the named character represented by this instance.
  60. * @param ch the named character
  61. */
  62. public void setCharacter(NamedCharacter ch) {
  63. this.character = ch;
  64. }
  65. /**
  66. * Sets the named character represented by this instance.
  67. * @param charName the character name (as defined in the Adobe glyph list)
  68. * @param unicodeSequence the Unicode sequence
  69. */
  70. public void setCharacter(String charName, String unicodeSequence) {
  71. setCharacter(new NamedCharacter(charName, unicodeSequence));
  72. }
  73. /**
  74. * Returns the Unicode sequence for this character.
  75. * @return the Unicode characters
  76. * (or null if no such Unicode sequence exists for this character)
  77. */
  78. public String getUnicodeSequence() {
  79. return (getCharacter() != null ? getCharacter().getUnicodeSequence() : null);
  80. }
  81. /**
  82. * Returns the PostScript character name.
  83. * @return the charName (or null if no character name is associated)
  84. */
  85. public String getCharName() {
  86. return (getCharacter() != null ? getCharacter().getName() : null);
  87. }
  88. /**
  89. * Returns the progression dimension in x-direction.
  90. * @return the widthX
  91. */
  92. public double getWidthX() {
  93. return widthX;
  94. }
  95. /**
  96. * Sets the progression dimension in x-direction
  97. * @param widthX the widthX to set
  98. */
  99. public void setWidthX(double widthX) {
  100. this.widthX = widthX;
  101. }
  102. /**
  103. * Returns the progression dimension in y-direction.
  104. * @return the widthY
  105. */
  106. public double getWidthY() {
  107. return widthY;
  108. }
  109. /**
  110. * Sets the progression dimension in y-direction
  111. * @param widthY the widthY to set
  112. */
  113. public void setWidthY(double widthY) {
  114. this.widthY = widthY;
  115. }
  116. /**
  117. * Returns the character's bounding box.
  118. * @return the bounding box (or null if it isn't available)
  119. */
  120. public Rectangle getBBox() {
  121. return bBox;
  122. }
  123. /**
  124. * Sets the character's bounding box.
  125. * @param box the bounding box
  126. */
  127. public void setBBox(Rectangle box) {
  128. bBox = box;
  129. }
  130. /** {@inheritDoc} */
  131. public String toString() {
  132. StringBuffer sb = new StringBuffer("AFM Char: ");
  133. sb.append(getCharCode());
  134. sb.append(" (");
  135. if (getUnicodeSequence() != null) {
  136. for (int i = 0, c = getUnicodeSequence().length(); i < c; i++) {
  137. sb.append("0x").append(Integer.toHexString(getUnicodeSequence().charAt(i)));
  138. sb.append(", ");
  139. }
  140. }
  141. sb.append(getCharName()).append(')');
  142. return sb.toString();
  143. }
  144. }