aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop/fonts
diff options
context:
space:
mode:
authorJeremias Maerki <jeremias@apache.org>2006-02-10 14:39:34 +0000
committerJeremias Maerki <jeremias@apache.org>2006-02-10 14:39:34 +0000
commit17094f3329733ab1e0b68b8e9b3c302382572f25 (patch)
tree848c68e3210147b900273d3a6da29825ccc3753a /src/java/org/apache/fop/fonts
parent77f908f5cce1fea0b4b5f694b31a4070bd33cfb8 (diff)
downloadxmlgraphics-fop-17094f3329733ab1e0b68b8e9b3c302382572f25.tar.gz
xmlgraphics-fop-17094f3329733ab1e0b68b8e9b3c302382572f25.zip
Creation of Font instances centralized in FontInfo and added a cache for them. This removes duplicate code in a number of places, improves speed a little and saves memory.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@376706 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/fonts')
-rw-r--r--src/java/org/apache/fop/fonts/FontInfo.java29
-rw-r--r--src/java/org/apache/fop/fonts/FontSetup.java2
2 files changed, 29 insertions, 2 deletions
diff --git a/src/java/org/apache/fop/fonts/FontInfo.java b/src/java/org/apache/fop/fonts/FontInfo.java
index 38059c6ba..4bd315941 100644
--- a/src/java/org/apache/fop/fonts/FontInfo.java
+++ b/src/java/org/apache/fop/fonts/FontInfo.java
@@ -54,6 +54,9 @@ public class FontInfo {
private Collection loggedFontKeys;
+ /** Cache for Font instances. */
+ private Map fontInstanceCache = new java.util.HashMap();
+
/**
* Main constructor
*/
@@ -80,7 +83,7 @@ public class FontInfo {
* @param weight font weight
*/
public void addFontProperties(String name, String family, String style, int weight) {
- addFontProperties(name, new FontTriplet(family, style, weight));
+ addFontProperties(name, createFontKey(family, style, weight));
}
/**
@@ -164,6 +167,30 @@ public class FontInfo {
}
/**
+ * Retrieves a (possibly cached) Font instance based on a FontTriplet and a font size.
+ * @param triplet the font triplet designating the requested font
+ * @param fontSize the font size
+ * @return the requested Font instance
+ */
+ public Font getFontInstance(FontTriplet triplet, int fontSize) {
+ Map sizes = (Map)fontInstanceCache.get(triplet);
+ if (sizes == null) {
+ sizes = new java.util.HashMap();
+ fontInstanceCache.put(triplet, sizes);
+ }
+ Integer size = new Integer(fontSize);
+ Font font = (Font)sizes.get(size);
+ if (font == null) {
+ String fname = getInternalFontKey(triplet);
+ useFont(fname);
+ FontMetrics metrics = getMetricsFor(fname);
+ font = new Font(fname, triplet, metrics, fontSize);
+ sizes.put(size, font);
+ }
+ return font;
+ }
+
+ /**
* Lookup a font.
* <br>
* Locate the font name for a given family, style and weight.
diff --git a/src/java/org/apache/fop/fonts/FontSetup.java b/src/java/org/apache/fop/fonts/FontSetup.java
index 8ac36bbd5..140fcb8b8 100644
--- a/src/java/org/apache/fop/fonts/FontSetup.java
+++ b/src/java/org/apache/fop/fonts/FontSetup.java
@@ -227,7 +227,7 @@ public class FontSetup {
List tripleList = new java.util.ArrayList();
for (int j = 0; j < triple.length; j++) {
int weight = FontUtil.parseCSS2FontWeight(triple[j].getAttribute("weight"));
- tripleList.add(new FontTriplet(triple[j].getAttribute("name"),
+ tripleList.add(FontInfo.createFontKey(triple[j].getAttribute("name"),
triple[j].getAttribute("style"),
weight));
}