--- src/java/org/apache/fop/fonts/FontInfo.java (revision 232795) +++ src/java/org/apache/fop/fonts/FontInfo.java (working copy) @@ -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 @@ 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 ""; + } + } --- src/java/org/apache/fop/render/xml/XMLRenderer.java (revision 232795) +++ src/java/org/apache/fop/render/xml/XMLRenderer.java (working copy) @@ -37,7 +37,7 @@ import org.xml.sax.helpers.AttributesImpl; // FOP -import org.apache.fop.render.AbstractRenderer; +import org.apache.fop.render.PrintRenderer; import org.apache.fop.render.RendererContext; import org.apache.fop.render.XMLHandler; import org.apache.fop.apps.FOUserAgent; @@ -68,6 +68,7 @@ import org.apache.fop.area.inline.TextArea; import org.apache.fop.fonts.FontSetup; import org.apache.fop.fonts.FontInfo; +import org.apache.fop.fonts.FontMetrics; /** * Renderer that renders areas to XML for debugging purposes. @@ -76,7 +77,7 @@ * The output can be used to build a new area tree (@see AreaTreeBuilder) * which can be rendered to any renderer. */ -public class XMLRenderer extends AbstractRenderer { +public class XMLRenderer extends PrintRenderer { /** XML MIME type */ public static final String XML_MIME_TYPE = "application/x-fop-areatree"; @@ -130,15 +131,6 @@ this.handler = handler; } - /** - * set up the font info - * - * @param fontInfo the font info object to set up - */ - public void setupFontInfo(FontInfo fontInfo) { - FontSetup.setup(fontInfo, null); - } - private boolean isCoarseXml() { return ((Boolean) userAgent.getRendererOptions().get("fineDetail")).booleanValue(); @@ -272,6 +264,11 @@ } String value = traitEntry.getValue().toString(); addAttribute(name, value); + if ("font-family".equals(name)) { + addAttribute("font-name", fontInfo.getMetricsFor(value).getFontName()); + addAttribute("font-style", fontInfo.getFontStyleFor(value)); + addAttribute("font-weight", fontInfo.getFontWeightFor(value)); + } } } }