選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

EmbedFontInfo.java 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. /** false, to disable kerning */
  32. protected final boolean kerning;
  33. /** false, to disable advanced typographic features */
  34. protected final boolean advanced;
  35. /** the requested encoding mode for the font */
  36. private final EncodingMode encodingMode;
  37. /** the requested embedding mode for this font */
  38. private final EmbeddingMode embeddingMode;
  39. /** simulates bold or italic on a regular font */
  40. private final boolean simulateStyle;
  41. private final boolean embedAsType1;
  42. /** the PostScript name of the font */
  43. protected String postScriptName;
  44. /** the sub-fontname of the font (used for TrueType Collections, null otherwise) */
  45. protected String subFontName;
  46. /** the list of associated font triplets */
  47. private List<FontTriplet> fontTriplets;
  48. private transient boolean embedded = true;
  49. private FontUris fontUris;
  50. /**
  51. * Main constructor
  52. * @param fontUris the URI of the XML resource containing font metrics
  53. * @param kerning True if kerning should be enabled
  54. * @param advanced true if advanced typography features should be enabled
  55. * @param fontTriplets List of font triplets to associate with this font
  56. * @param subFontName the sub-fontname used for TrueType Collections (null otherwise)
  57. * @param encodingMode the encoding mode to use for this font
  58. */
  59. public EmbedFontInfo(FontUris fontUris, boolean kerning, boolean advanced,
  60. List<FontTriplet> fontTriplets, String subFontName, EncodingMode encodingMode,
  61. EmbeddingMode embeddingMode, boolean simulateStyle, boolean embedAsType1) {
  62. this.kerning = kerning;
  63. this.advanced = advanced;
  64. this.fontTriplets = fontTriplets;
  65. this.subFontName = subFontName;
  66. this.encodingMode = encodingMode;
  67. this.embeddingMode = embeddingMode;
  68. this.fontUris = fontUris;
  69. this.simulateStyle = simulateStyle;
  70. this.embedAsType1 = embedAsType1;
  71. }
  72. /**
  73. * Main constructor
  74. * @param fontUris the URI of the XML resource containing font metrics
  75. * @param kerning True if kerning should be enabled
  76. * @param fontTriplets List of font triplets to associate with this font
  77. * @param subFontName the sub-fontname used for TrueType Collections (null otherwise)
  78. */
  79. public EmbedFontInfo(FontUris fontUris, boolean kerning, boolean advanced,
  80. List<FontTriplet> fontTriplets, String subFontName) {
  81. this(fontUris, kerning, advanced, fontTriplets, subFontName, EncodingMode.AUTO,
  82. EmbeddingMode.AUTO, false, false);
  83. }
  84. /**
  85. * Returns the URI of the metrics XML resource
  86. *
  87. * @return the metrics file path
  88. */
  89. public URI getMetricsURI() {
  90. return fontUris.getMetrics();
  91. }
  92. /**
  93. * Returns the URI to the embeddable font resource
  94. *
  95. * @return the font resource URI
  96. */
  97. public URI getEmbedURI() {
  98. return fontUris.getEmbed();
  99. }
  100. /**
  101. * Determines if kerning is enabled
  102. * @return true if enabled
  103. */
  104. public boolean getKerning() {
  105. return kerning;
  106. }
  107. /**
  108. * Determines if advanced typographic features are enabled
  109. * @return true if enabled
  110. */
  111. public boolean getAdvanced() {
  112. return advanced;
  113. }
  114. /**
  115. * Returns the sub-font name of the font. This is primarily used for TrueType Collections
  116. * to select one of the sub-fonts. For all other fonts, this is always null.
  117. * @return the sub-font name (or null)
  118. */
  119. public String getSubFontName() {
  120. return this.subFontName;
  121. }
  122. /**
  123. * Returns the PostScript name of the font.
  124. * @return the PostScript name
  125. */
  126. public String getPostScriptName() {
  127. return postScriptName;
  128. }
  129. /**
  130. * Sets the PostScript name of the font
  131. * @param postScriptName the PostScript name
  132. */
  133. public void setPostScriptName(String postScriptName) {
  134. this.postScriptName = postScriptName;
  135. }
  136. /**
  137. * Returns the list of font triplets associated with this font.
  138. * @return List of font triplets
  139. */
  140. public List<FontTriplet> getFontTriplets() {
  141. return fontTriplets;
  142. }
  143. /**
  144. * Indicates whether the font is only referenced rather than embedded.
  145. * @return true if the font is embedded, false if it is referenced.
  146. */
  147. public boolean isEmbedded() {
  148. if (fontUris.getEmbed() == null) {
  149. return false;
  150. } else {
  151. return this.embedded;
  152. }
  153. }
  154. /**
  155. * Returns the embedding mode for this font.
  156. * @return the embedding mode.
  157. */
  158. public EmbeddingMode getEmbeddingMode() {
  159. return embeddingMode;
  160. }
  161. /**
  162. * Defines whether the font is embedded or not.
  163. * @param value true to embed the font, false to reference it
  164. */
  165. public void setEmbedded(boolean value) {
  166. this.embedded = value;
  167. }
  168. /**
  169. * Returns the requested encoding mode for this font.
  170. * @return the encoding mode
  171. */
  172. public EncodingMode getEncodingMode() {
  173. return this.encodingMode;
  174. }
  175. /**
  176. * Determines whether the font can simulate a style such as bold or italic.
  177. * @return true if the font is being simulated as a different style.
  178. */
  179. public boolean getSimulateStyle() {
  180. return this.simulateStyle;
  181. }
  182. public boolean getEmbedAsType1() {
  183. return embedAsType1;
  184. }
  185. private void readObject(java.io.ObjectInputStream in)
  186. throws IOException, ClassNotFoundException {
  187. in.defaultReadObject();
  188. this.embedded = true;
  189. }
  190. /** {@inheritDoc} */
  191. public String toString() {
  192. return "metrics-uri=" + fontUris.getMetrics() + ", embed-uri=" + fontUris.getEmbed()
  193. + ", kerning=" + kerning
  194. + ", advanced=" + advanced
  195. + ", enc-mode=" + encodingMode
  196. + ", font-triplet=" + fontTriplets
  197. + (getSubFontName() != null ? ", sub-font=" + getSubFontName() : "")
  198. + (isEmbedded() ? "" : ", NOT embedded");
  199. }
  200. public FontUris getFontUris() {
  201. return fontUris;
  202. }
  203. }