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 4.0KB

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