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.1KB

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