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

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