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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. public static final FontType TYPE1C = new FontType("Type1C", 6);
  48. public static final FontType CIDTYPE0 = new FontType("CIDFontType0", 7);
  49. private final String name;
  50. private final int value;
  51. /**
  52. * Construct a font type.
  53. * @param name a font type name
  54. * @param value a font type value
  55. * @see org.apache.avalon.framework.Enum#Enum(String)
  56. */
  57. protected FontType(String name, int value) {
  58. this.name = name;
  59. this.value = value;
  60. }
  61. /**
  62. * Returns the FontType by name.
  63. * @param name Name of the font type to look up
  64. * @return the font type
  65. */
  66. public static FontType byName(String name) {
  67. if (name.equalsIgnoreCase(FontType.OTHER.getName())) {
  68. return FontType.OTHER;
  69. } else if (name.equalsIgnoreCase(FontType.TYPE0.getName())) {
  70. return FontType.TYPE0;
  71. } else if (name.equalsIgnoreCase(FontType.TYPE1.getName())) {
  72. return FontType.TYPE1;
  73. } else if (name.equalsIgnoreCase(FontType.MMTYPE1.getName())) {
  74. return FontType.MMTYPE1;
  75. } else if (name.equalsIgnoreCase(FontType.TYPE3.getName())) {
  76. return FontType.TYPE3;
  77. } else if (name.equalsIgnoreCase(FontType.TRUETYPE.getName())) {
  78. return FontType.TRUETYPE;
  79. } else {
  80. throw new IllegalArgumentException("Invalid font type: " + name);
  81. }
  82. }
  83. /**
  84. * Returns the FontType by value.
  85. * @param value Value of the font type to look up
  86. * @return the font type
  87. */
  88. public static FontType byValue(int value) {
  89. if (value == FontType.OTHER.getValue()) {
  90. return FontType.OTHER;
  91. } else if (value == FontType.TYPE0.getValue()) {
  92. return FontType.TYPE0;
  93. } else if (value == FontType.TYPE1.getValue()) {
  94. return FontType.TYPE1;
  95. } else if (value == FontType.MMTYPE1.getValue()) {
  96. return FontType.MMTYPE1;
  97. } else if (value == FontType.TYPE3.getValue()) {
  98. return FontType.TYPE3;
  99. } else if (value == FontType.TRUETYPE.getValue()) {
  100. return FontType.TRUETYPE;
  101. } else {
  102. throw new IllegalArgumentException("Invalid font type: " + value);
  103. }
  104. }
  105. /**
  106. * Returns the name
  107. *
  108. * @return the name
  109. */
  110. public String getName() {
  111. return name;
  112. }
  113. /**
  114. * Returns the value
  115. *
  116. * @return the value
  117. */
  118. public int getValue() {
  119. return value;
  120. }
  121. @Override
  122. public String toString() {
  123. return name;
  124. }
  125. }