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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. * TODO: We need to remove this class and think about more intelligent design patterns
  25. * (Data classes => Procedural code)
  26. */
  27. public class EmbedFontInfo implements Serializable {
  28. /** Serialization Version UID */
  29. private static final long serialVersionUID = 8755432068669997369L;
  30. /** filename of the metrics file */
  31. protected String metricsFile;
  32. /** filename of the main font file */
  33. protected String embedFile;
  34. /** false, to disable kerning */
  35. protected boolean kerning;
  36. /** false, to disable advanced typographic features */
  37. protected boolean advanced;
  38. /** the requested encoding mode for the font */
  39. protected EncodingMode encodingMode = EncodingMode.AUTO;
  40. /** the requested embedding mode for this font */
  41. protected EmbeddingMode embeddingMode = EmbeddingMode.AUTO;
  42. /** the PostScript name of the font */
  43. protected String postScriptName = null;
  44. /** the sub-fontname of the font (used for TrueType Collections, null otherwise) */
  45. protected String subFontName = null;
  46. /** the list of associated font triplets */
  47. private List<FontTriplet> fontTriplets = null;
  48. private transient boolean embedded = true;
  49. /**
  50. * Main constructor
  51. * @param metricsFile path to the xml file containing font metrics
  52. * @param kerning true if kerning should be enabled
  53. * @param advanced true if advanced typography features should be enabled
  54. * @param fontTriplets list of font triplets to associate with this font
  55. * @param embedFile path to the embeddable font file (may be null)
  56. * @param subFontName the sub-fontname used for TrueType Collections (null otherwise)
  57. */
  58. public EmbedFontInfo(String metricsFile, boolean kerning, boolean advanced,
  59. List<FontTriplet> fontTriplets, String embedFile, String subFontName) {
  60. this.metricsFile = metricsFile;
  61. this.embedFile = embedFile;
  62. this.kerning = kerning;
  63. this.advanced = advanced;
  64. this.fontTriplets = fontTriplets;
  65. this.subFontName = subFontName;
  66. }
  67. /**
  68. * Returns the path to the metrics file
  69. * @return the metrics file path
  70. */
  71. public String getMetricsFile() {
  72. return metricsFile;
  73. }
  74. /**
  75. * Returns the path to the embeddable font file
  76. * @return the font file path
  77. */
  78. public String getEmbedFile() {
  79. return embedFile;
  80. }
  81. /**
  82. * Determines if kerning is enabled
  83. * @return true if enabled
  84. */
  85. public boolean getKerning() {
  86. return kerning;
  87. }
  88. /**
  89. * Determines if advanced typographic features are enabled
  90. * @return true if enabled
  91. */
  92. public boolean getAdvanced() {
  93. return advanced;
  94. }
  95. /**
  96. * Returns the sub-font name of the font. This is primarily used for TrueType Collections
  97. * to select one of the sub-fonts. For all other fonts, this is always null.
  98. * @return the sub-font name (or null)
  99. */
  100. public String getSubFontName() {
  101. return this.subFontName;
  102. }
  103. /**
  104. * Returns the PostScript name of the font.
  105. * @return the PostScript name
  106. */
  107. public String getPostScriptName() {
  108. return postScriptName;
  109. }
  110. /**
  111. * Sets the PostScript name of the font
  112. * @param postScriptName the PostScript name
  113. */
  114. public void setPostScriptName(String postScriptName) {
  115. this.postScriptName = postScriptName;
  116. }
  117. /**
  118. * Returns the list of font triplets associated with this font.
  119. * @return List of font triplets
  120. */
  121. public List<FontTriplet> getFontTriplets() {
  122. return fontTriplets;
  123. }
  124. /**
  125. * Indicates whether the font is only referenced rather than embedded.
  126. * @return true if the font is embedded, false if it is referenced.
  127. */
  128. public boolean isEmbedded() {
  129. if (metricsFile != null && embedFile == null) {
  130. return false;
  131. } else {
  132. return this.embedded;
  133. }
  134. }
  135. /**
  136. * Returns the embedding mode for this font.
  137. * @return the embedding mode.
  138. */
  139. public EmbeddingMode getEmbeddingMode() {
  140. return embeddingMode;
  141. }
  142. /**
  143. * Defines whether the font is embedded or not.
  144. * @param value true to embed the font, false to reference it
  145. */
  146. public void setEmbedded(boolean value) {
  147. this.embedded = value;
  148. }
  149. /**
  150. * Returns the requested encoding mode for this font.
  151. * @return the encoding mode
  152. */
  153. public EncodingMode getEncodingMode() {
  154. return this.encodingMode;
  155. }
  156. /**
  157. * Sets the requested encoding mode for this font.
  158. * @param mode the new encoding mode
  159. */
  160. public void setEncodingMode(EncodingMode mode) {
  161. if (mode == null) {
  162. throw new NullPointerException("mode must not be null");
  163. }
  164. this.encodingMode = mode;
  165. }
  166. /**
  167. * Sets the embedding mode for this font, currently not supported for Type 1 fonts.
  168. * @param embeddingMode the new embedding mode.
  169. */
  170. public void setEmbeddingMode(EmbeddingMode embeddingMode) {
  171. if (embeddingMode == null) {
  172. throw new NullPointerException("embeddingMode must not be null");
  173. }
  174. this.embeddingMode = embeddingMode;
  175. }
  176. private void readObject(java.io.ObjectInputStream in)
  177. throws IOException, ClassNotFoundException {
  178. in.defaultReadObject();
  179. this.embedded = true;
  180. }
  181. /** {@inheritDoc} */
  182. public String toString() {
  183. return "metrics-url=" + metricsFile + ", embed-url=" + embedFile
  184. + ", kerning=" + kerning
  185. + ", advanced=" + advanced
  186. + ", enc-mode=" + encodingMode
  187. + ", font-triplet=" + fontTriplets
  188. + (getSubFontName() != null ? ", sub-font=" + getSubFontName() : "")
  189. + (isEmbedded() ? "" : ", NOT embedded");
  190. }
  191. }