diff options
author | Chris Bowditch <cbowditch@apache.org> | 2005-08-15 13:23:27 +0000 |
---|---|---|
committer | Chris Bowditch <cbowditch@apache.org> | 2005-08-15 13:23:27 +0000 |
commit | bd3680a1e25d8c1a916fa9f58c5ab8d125bd6797 (patch) | |
tree | 0533d1b08d63f0be6f9647916962cc60ffe17e33 /src/java/org/apache/fop/fonts | |
parent | 7a7d2dd354eae700455c51cbe47cfc85f3c3f945 (diff) | |
download | xmlgraphics-fop-bd3680a1e25d8c1a916fa9f58c5ab8d125bd6797.tar.gz xmlgraphics-fop-bd3680a1e25d8c1a916fa9f58c5ab8d125bd6797.zip |
ref to bugzilla 36180
Submitted by: Manuel Mall <mm.at.arcus.com.au>
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@232810 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/fonts')
-rw-r--r-- | src/java/org/apache/fop/fonts/FontInfo.java | 61 |
1 files changed, 60 insertions, 1 deletions
diff --git a/src/java/org/apache/fop/fonts/FontInfo.java b/src/java/org/apache/fop/fonts/FontInfo.java index 29c49cd05..7b554f1c4 100644 --- a/src/java/org/apache/fop/fonts/FontInfo.java +++ b/src/java/org/apache/fop/fonts/FontInfo.java @@ -18,9 +18,13 @@ package org.apache.fop.fonts; -// Java +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; import java.util.Map; + /** * The FontInfo for the layout and rendering of a fo document. * This stores the list of available fonts that are setup by @@ -226,6 +230,61 @@ public class FontInfo { usedFonts.put(fontName, fonts.get(fontName)); return (FontMetrics)fonts.get(fontName); } + + /** + * Returns the first triplet matching the given font name. + * As there may be multiple triplets matching the font name + * the result set is sorted first to guarantee consistent results. + * @param fontName The font name we are looking for + * @return The first triplet for the given font name + */ + private String getTripletFor(String fontName) { + List foundTriplets = new ArrayList(); + for (Iterator iter = triplets.entrySet().iterator(); iter.hasNext(); ) { + Map.Entry tripletEntry = (Map.Entry) iter.next(); + if (fontName.equals(((String)tripletEntry.getValue()))) { + foundTriplets.add(tripletEntry.getKey()); + } + } + if (foundTriplets.size() > 0) { + Collections.sort(foundTriplets); + return (String)foundTriplets.get(0); + } + return null; + } + + /** + * Returns the font style for a particular font. + * There may be multiple font styles matching this font. Only the first + * found is returned. Searching is done on a sorted list to guarantee consistent + * results. + * @param fontName internal key + * @return font style + */ + public String getFontStyleFor(String fontName) { + String triplet = getTripletFor(fontName); + if (triplet != null) { + return triplet.substring(triplet.indexOf(',') + 1, triplet.lastIndexOf(',')); + } + return ""; + } + + /** + * Returns the font weight for a particular font. + * There may be multiple font weights matching this font. Only the first + * found is returned. Searching is done on a sorted list to guarantee consistent + * results. + * @param fontName internal key + * @return font weight + */ + public String getFontWeightFor(String fontName) { + String triplet = getTripletFor(fontName); + if (triplet != null) { + return triplet.substring(triplet.lastIndexOf(',') + 1); + } + return ""; + } + } |