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.

EmbedFontInfo.java 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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.IOException;
  20. import java.io.Serializable;
  21. import java.util.List;
  22. /**
  23. * FontInfo contains meta information on fonts (where is the metrics file etc.)
  24. */
  25. public class EmbedFontInfo implements Serializable {
  26. /** Serialization Version UID */
  27. private static final long serialVersionUID = 8755432068669997368L;
  28. /** filename of the metrics file */
  29. protected String metricsFile;
  30. /** filename of the main font file */
  31. protected String embedFile;
  32. /** false, to disable kerning */
  33. protected boolean kerning;
  34. /** the requested encoding mode for the font */
  35. protected EncodingMode encodingMode = EncodingMode.AUTO;
  36. /** the PostScript name of the font */
  37. protected String postScriptName = null;
  38. /** the sub-fontname of the font (used for TrueType Collections, null otherwise) */
  39. protected String subFontName = null;
  40. /** the list of associated font triplets */
  41. private List/*<FontTriplet>*/ fontTriplets = null;
  42. private transient boolean embedded = true;
  43. /**
  44. * Main constructor
  45. * @param metricsFile Path to the xml file containing font metrics
  46. * @param kerning True if kerning should be enabled
  47. * @param fontTriplets List of font triplets to associate with this font
  48. * @param embedFile Path to the embeddable font file (may be null)
  49. * @param subFontName the sub-fontname used for TrueType Collections (null otherwise)
  50. */
  51. public EmbedFontInfo(String metricsFile, boolean kerning,
  52. List/*<FontTriplet>*/ fontTriplets, String embedFile, String subFontName) {
  53. this.metricsFile = metricsFile;
  54. this.embedFile = embedFile;
  55. this.kerning = kerning;
  56. this.fontTriplets = fontTriplets;
  57. this.subFontName = subFontName;
  58. }
  59. /**
  60. * Returns the path to the metrics file
  61. * @return the metrics file path
  62. */
  63. public String getMetricsFile() {
  64. return metricsFile;
  65. }
  66. /**
  67. * Returns the path to the embeddable font file
  68. * @return the font file path
  69. */
  70. public String getEmbedFile() {
  71. return embedFile;
  72. }
  73. /**
  74. * Determines if kerning is enabled
  75. * @return True if enabled
  76. */
  77. public boolean getKerning() {
  78. return kerning;
  79. }
  80. /**
  81. * Returns the sub-font name of the font. This is primarily used for TrueType Collections
  82. * to select one of the sub-fonts. For all other fonts, this is always null.
  83. * @return the sub-font name (or null)
  84. */
  85. public String getSubFontName() {
  86. return this.subFontName;
  87. }
  88. /**
  89. * Returns the PostScript name of the font.
  90. * @return the PostScript name
  91. */
  92. public String getPostScriptName() {
  93. return postScriptName;
  94. }
  95. /**
  96. * Sets the PostScript name of the font
  97. * @param postScriptName the PostScript name
  98. */
  99. public void setPostScriptName(String postScriptName) {
  100. this.postScriptName = postScriptName;
  101. }
  102. /**
  103. * Returns the list of font triplets associated with this font.
  104. * @return List of font triplets
  105. */
  106. public List/*<FontTriplet>*/ getFontTriplets() {
  107. return fontTriplets;
  108. }
  109. /**
  110. * Indicates whether the font is only referenced rather than embedded.
  111. * @return true if the font is embedded, false if it is referenced.
  112. */
  113. public boolean isEmbedded() {
  114. if (metricsFile != null && embedFile == null) {
  115. return false;
  116. } else {
  117. return this.embedded;
  118. }
  119. }
  120. /**
  121. * Defines whether the font is embedded or not.
  122. * @param value true to embed the font, false to reference it
  123. */
  124. public void setEmbedded(boolean value) {
  125. this.embedded = value;
  126. }
  127. /**
  128. * Returns the requested encoding mode for this font.
  129. * @return the encoding mode
  130. */
  131. public EncodingMode getEncodingMode() {
  132. return this.encodingMode;
  133. }
  134. /**
  135. * Sets the requested encoding mode for this font.
  136. * @param mode the new encoding mode
  137. */
  138. public void setEncodingMode(EncodingMode mode) {
  139. if (mode == null) {
  140. throw new NullPointerException("mode must not be null");
  141. }
  142. this.encodingMode = mode;
  143. }
  144. private void readObject(java.io.ObjectInputStream in)
  145. throws IOException, ClassNotFoundException {
  146. in.defaultReadObject();
  147. this.embedded = true;
  148. }
  149. /** {@inheritDoc} */
  150. public String toString() {
  151. return "metrics-url=" + metricsFile + ", embed-url=" + embedFile
  152. + ", kerning=" + kerning
  153. + ", enc-mode=" + encodingMode
  154. + ", font-triplet=" + fontTriplets
  155. + (getSubFontName() != null ? ", sub-font=" + getSubFontName() : "")
  156. + (isEmbedded() ? "" : ", NOT embedded");
  157. }
  158. }