aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop/fonts/CustomFont.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/java/org/apache/fop/fonts/CustomFont.java')
-rw-r--r--src/java/org/apache/fop/fonts/CustomFont.java80
1 files changed, 37 insertions, 43 deletions
diff --git a/src/java/org/apache/fop/fonts/CustomFont.java b/src/java/org/apache/fop/fonts/CustomFont.java
index 89f515205..70961a55c 100644
--- a/src/java/org/apache/fop/fonts/CustomFont.java
+++ b/src/java/org/apache/fop/fonts/CustomFont.java
@@ -20,13 +20,15 @@
package org.apache.fop.fonts;
import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
-import javax.xml.transform.Source;
+import org.apache.fop.apps.io.InternalResourceResolver;
/**
@@ -35,27 +37,27 @@ import javax.xml.transform.Source;
public abstract class CustomFont extends Typeface
implements FontDescriptor, MutableFont {
- private String fontName = null;
- private String fullName = null;
- private Set<String> familyNames = null;
- private String fontSubName = null;
- private String embedFileName = null;
- private String embedResourceName = null;
- private FontResolver resolver = null;
+ private String fontName;
+ private String fullName;
+ private Set<String> familyNames;
+ private String fontSubName;
+ private URI embedFileURI;
+ private String embedResourceName;
+ private final InternalResourceResolver resourceResolver;
private EmbeddingMode embeddingMode = EmbeddingMode.AUTO;
- private int capHeight = 0;
- private int xHeight = 0;
- private int ascender = 0;
- private int descender = 0;
+ private int capHeight;
+ private int xHeight;
+ private int ascender;
+ private int descender;
private int[] fontBBox = {0, 0, 0, 0};
private int flags = 4;
- private int weight = 0; //0 means unknown weight
- private int stemV = 0;
- private int italicAngle = 0;
- private int missingWidth = 0;
+ private int weight; //0 means unknown weight
+ private int stemV;
+ private int italicAngle;
+ private int missingWidth;
private FontType fontType = FontType.TYPE1;
- private int firstChar = 0;
+ private int firstChar;
private int lastChar = 255;
private Map<Integer, Map<Integer, Integer>> kerning;
@@ -63,6 +65,12 @@ public abstract class CustomFont extends Typeface
private boolean useKerning = true;
private boolean useAdvanced = true;
+ /**
+ * @param resourceResolver the URI resource resolver for controlling file access
+ */
+ public CustomFont(InternalResourceResolver resourceResolver) {
+ this.resourceResolver = resourceResolver;
+ }
/** the character map, mapping Unicode ranges to glyph indices. */
protected CMapSegment[] cmap;
@@ -107,15 +115,16 @@ public abstract class CustomFont extends Typeface
}
/**
- * Returns an URI representing an embeddable font file. The URI will often
- * be a filename or an URL.
+ * Returns an URI representing an embeddable font file.
+ *
* @return URI to an embeddable font file or null if not available.
*/
- public String getEmbedFileName() {
- return embedFileName;
+ public URI getEmbedFileURI() {
+ return embedFileURI;
}
/**
+
* Returns the embedding mode for this font.
* @return embedding mode
*/
@@ -124,20 +133,13 @@ public abstract class CustomFont extends Typeface
}
/**
- * Returns a Source representing an embeddable font file.
- * @return Source for an embeddable font file
+ * Returns an {@link InputStream} representing an embeddable font file.
+ *
+ * @return {@link InputStream} for an embeddable font file
* @throws IOException if embedFileName is not null but Source is not found
*/
- public Source getEmbedFileSource() throws IOException {
- Source result = null;
- if (resolver != null && embedFileName != null) {
- result = resolver.resolve(embedFileName);
- if (result == null) {
- throw new IOException("Unable to resolve Source '"
- + embedFileName + "' for embedded font");
- }
- }
- return result;
+ public InputStream getInputStream() throws IOException {
+ return resourceResolver.getResource(embedFileURI);
}
/**
@@ -335,8 +337,8 @@ public abstract class CustomFont extends Typeface
/**
* {@inheritDoc}
*/
- public void setEmbedFileName(String path) {
- this.embedFileName = path;
+ public void setEmbedURI(URI path) {
+ this.embedFileURI = path;
}
/**
@@ -463,14 +465,6 @@ public abstract class CustomFont extends Typeface
this.useAdvanced = enabled;
}
- /**
- * Sets the font resolver. Needed for URI resolution.
- * @param resolver the font resolver
- */
- public void setResolver(FontResolver resolver) {
- this.resolver = resolver;
- }
-
/** {@inheritDoc} */
public void putKerningEntry(Integer key, Map<Integer, Integer> value) {
if (kerning == null) {