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.

FontType.java 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. /**
  20. * This class enumerates all supported font types.
  21. */
  22. public class FontType {
  23. /**
  24. * Collective identifier for "other" font types
  25. */
  26. public static final FontType OTHER = new FontType("Other", 0);
  27. /**
  28. * Adobe Type 0 fonts (composite font)
  29. */
  30. public static final FontType TYPE0 = new FontType("Type0", 1);
  31. /**
  32. * Adobe Type 1 fonts
  33. */
  34. public static final FontType TYPE1 = new FontType("Type1", 2);
  35. /**
  36. * Adobe Multiple Master Type 1 fonts
  37. */
  38. public static final FontType MMTYPE1 = new FontType("MMType1", 3);
  39. /**
  40. * Adobe Type 3 fonts ("user-defined" fonts)
  41. */
  42. public static final FontType TYPE3 = new FontType("Type3", 4);
  43. /**
  44. * TrueType fonts
  45. */
  46. public static final FontType TRUETYPE = new FontType("TrueType", 5);
  47. private final String name;
  48. private final int value;
  49. /**
  50. * Construct a font type.
  51. * @param name a font type name
  52. * @param value a font type value
  53. * @see org.apache.avalon.framework.Enum#Enum(String)
  54. */
  55. protected FontType(String name, int value) {
  56. this.name = name;
  57. this.value = value;
  58. }
  59. /**
  60. * Returns the FontType by name.
  61. * @param name Name of the font type to look up
  62. * @return the font type
  63. */
  64. public static FontType byName(String name) {
  65. if (name.equalsIgnoreCase(FontType.OTHER.getName())) {
  66. return FontType.OTHER;
  67. } else if (name.equalsIgnoreCase(FontType.TYPE0.getName())) {
  68. return FontType.TYPE0;
  69. } else if (name.equalsIgnoreCase(FontType.TYPE1.getName())) {
  70. return FontType.TYPE1;
  71. } else if (name.equalsIgnoreCase(FontType.MMTYPE1.getName())) {
  72. return FontType.MMTYPE1;
  73. } else if (name.equalsIgnoreCase(FontType.TYPE3.getName())) {
  74. return FontType.TYPE3;
  75. } else if (name.equalsIgnoreCase(FontType.TRUETYPE.getName())) {
  76. return FontType.TRUETYPE;
  77. } else {
  78. throw new IllegalArgumentException("Invalid font type: " + name);
  79. }
  80. }
  81. /**
  82. * Returns the FontType by value.
  83. * @param value Value of the font type to look up
  84. * @return the font type
  85. */
  86. public static FontType byValue(int value) {
  87. if (value == FontType.OTHER.getValue()) {
  88. return FontType.OTHER;
  89. } else if (value == FontType.TYPE0.getValue()) {
  90. return FontType.TYPE0;
  91. } else if (value == FontType.TYPE1.getValue()) {
  92. return FontType.TYPE1;
  93. } else if (value == FontType.MMTYPE1.getValue()) {
  94. return FontType.MMTYPE1;
  95. } else if (value == FontType.TYPE3.getValue()) {
  96. return FontType.TYPE3;
  97. } else if (value == FontType.TRUETYPE.getValue()) {
  98. return FontType.TRUETYPE;
  99. } else {
  100. throw new IllegalArgumentException("Invalid font type: " + value);
  101. }
  102. }
  103. /**
  104. * Returns the name
  105. *
  106. * @return the name
  107. */
  108. public String getName() {
  109. return name;
  110. }
  111. /**
  112. * Returns the value
  113. *
  114. * @return the value
  115. */
  116. public int getValue() {
  117. return value;
  118. }
  119. @Override
  120. public String toString() {
  121. return name;
  122. }
  123. }