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.

FontTriplet.java 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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;
  19. import java.io.Serializable;
  20. /**
  21. * FontTriplet contains information on name, style and weight of one font
  22. */
  23. public class FontTriplet implements Comparable, Serializable {
  24. /** serial version UID */
  25. private static final long serialVersionUID = 1168991106658033508L;
  26. private String name;
  27. private String style;
  28. private int weight;
  29. private int priority; // priority of this triplet/font mapping
  30. //This is only a cache
  31. private transient String key;
  32. /**
  33. * Creates a new font triplet (for base14 use).
  34. * @param name font name
  35. */
  36. public FontTriplet(String name) {
  37. this.name = name;
  38. }
  39. /**
  40. * Creates a new font triplet.
  41. * @param name font name
  42. * @param style font style (normal, italic etc.)
  43. * @param weight font weight (100, 200, 300...800, 900)
  44. */
  45. public FontTriplet(String name, String style, int weight) {
  46. this(name, style, weight, Font.PRIORITY_DEFAULT);
  47. }
  48. /**
  49. * Creates a new font triplet.
  50. * @param name font name
  51. * @param style font style (normal, italic etc.)
  52. * @param weight font weight (100, 200, 300...800, 900)
  53. * @param priority priority of this triplet/font mapping
  54. */
  55. public FontTriplet(String name, String style, int weight, int priority) {
  56. this(name);
  57. this.style = style;
  58. this.weight = weight;
  59. this.priority = priority;
  60. }
  61. /** @return the font name */
  62. public String getName() {
  63. return name;
  64. }
  65. /** @return the font style */
  66. public String getStyle() {
  67. return style;
  68. }
  69. /** @return the font weight */
  70. public int getWeight() {
  71. return weight;
  72. }
  73. /** @return the priority of this triplet/font mapping */
  74. public int getPriority() {
  75. return priority;
  76. }
  77. private String getKey() {
  78. if (this.key == null) {
  79. //This caches the combined key
  80. this.key = getName() + "," + getStyle() + "," + getWeight();
  81. }
  82. return this.key;
  83. }
  84. /** {@inheritDoc} */
  85. public int compareTo(Object o) {
  86. return getKey().compareTo(((FontTriplet)o).getKey());
  87. }
  88. /** {@inheritDoc} */
  89. public int hashCode() {
  90. return toString().hashCode();
  91. }
  92. /** {@inheritDoc} */
  93. public boolean equals(Object obj) {
  94. if (obj == null) {
  95. return false;
  96. } else if (obj == this) {
  97. return true;
  98. } else {
  99. if (obj instanceof FontTriplet) {
  100. FontTriplet other = (FontTriplet)obj;
  101. return (getName().equals(other.getName())
  102. && getStyle().equals(other.getStyle())
  103. && (getWeight() == other.getWeight()));
  104. }
  105. }
  106. return false;
  107. }
  108. /** {@inheritDoc} */
  109. public String toString() {
  110. return getKey();
  111. }
  112. }