Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

EmbedFontInfo.java 6.2KB

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