View | Details | Raw Unified | Return to bug 36180
Collapse All | Expand All

(-)src/java/org/apache/fop/fonts/FontInfo.java (-1 / +60 lines)
Lines 18-26 Link Here
18
18
19
package org.apache.fop.fonts;
19
package org.apache.fop.fonts;
20
20
21
// Java
21
import java.util.ArrayList;
22
import java.util.Collections;
23
import java.util.Iterator;
24
import java.util.List;
22
import java.util.Map;
25
import java.util.Map;
23
26
27
24
/**
28
/**
25
 * The FontInfo for the layout and rendering of a fo document.
29
 * The FontInfo for the layout and rendering of a fo document.
26
 * This stores the list of available fonts that are setup by
30
 * This stores the list of available fonts that are setup by
Lines 226-231 Link Here
226
        usedFonts.put(fontName, fonts.get(fontName));
230
        usedFonts.put(fontName, fonts.get(fontName));
227
        return (FontMetrics)fonts.get(fontName);
231
        return (FontMetrics)fonts.get(fontName);
228
    }
232
    }
233
234
    /**
235
     * Returns the first triplet matching the given font name.
236
     * As there may be multiple triplets matching the font name
237
     * the result set is sorted first to guarantee consistent results.
238
     * @param fontName The font name we are looking for
239
     * @return The first triplet for the given font name
240
     */
241
    private String getTripletFor(String fontName) {
242
        List foundTriplets = new ArrayList();
243
        for (Iterator iter = triplets.entrySet().iterator(); iter.hasNext(); ) {
244
            Map.Entry tripletEntry = (Map.Entry) iter.next();
245
            if (fontName.equals(((String)tripletEntry.getValue()))) {
246
                foundTriplets.add(tripletEntry.getKey());
247
            }
248
        }
249
        if (foundTriplets.size() > 0) {
250
            Collections.sort(foundTriplets);
251
            return (String)foundTriplets.get(0);
252
        }
253
        return null;
254
    }
255
    
256
    /**
257
     * Returns the font style for a particular font.
258
     * There may be multiple font styles matching this font. Only the first
259
     * found is returned. Searching is done on a sorted list to guarantee consistent
260
     * results.
261
     * @param fontName internal key
262
     * @return font style
263
     */
264
    public String getFontStyleFor(String fontName) {
265
        String triplet = getTripletFor(fontName);
266
        if (triplet != null) {
267
            return triplet.substring(triplet.indexOf(',') + 1, triplet.lastIndexOf(','));
268
        }
269
        return "";
270
    }
271
    
272
    /**
273
     * Returns the font weight for a particular font.
274
     * There may be multiple font weights matching this font. Only the first
275
     * found is returned. Searching is done on a sorted list to guarantee consistent
276
     * results.
277
     * @param fontName internal key
278
     * @return font weight
279
     */
280
    public String getFontWeightFor(String fontName) {
281
        String triplet = getTripletFor(fontName);
282
        if (triplet != null) {
283
            return triplet.substring(triplet.lastIndexOf(',') + 1);
284
        }
285
        return "";
286
    }
287
    
229
}
288
}
230
289
231
290
(-)src/java/org/apache/fop/render/xml/XMLRenderer.java (-11 / +8 lines)
Lines 37-43 Link Here
37
import org.xml.sax.helpers.AttributesImpl;
37
import org.xml.sax.helpers.AttributesImpl;
38
38
39
// FOP
39
// FOP
40
import org.apache.fop.render.AbstractRenderer;
40
import org.apache.fop.render.PrintRenderer;
41
import org.apache.fop.render.RendererContext;
41
import org.apache.fop.render.RendererContext;
42
import org.apache.fop.render.XMLHandler;
42
import org.apache.fop.render.XMLHandler;
43
import org.apache.fop.apps.FOUserAgent;
43
import org.apache.fop.apps.FOUserAgent;
Lines 68-73 Link Here
68
import org.apache.fop.area.inline.TextArea;
68
import org.apache.fop.area.inline.TextArea;
69
import org.apache.fop.fonts.FontSetup;
69
import org.apache.fop.fonts.FontSetup;
70
import org.apache.fop.fonts.FontInfo;
70
import org.apache.fop.fonts.FontInfo;
71
import org.apache.fop.fonts.FontMetrics;
71
72
72
/**
73
/**
73
 * Renderer that renders areas to XML for debugging purposes.
74
 * Renderer that renders areas to XML for debugging purposes.
Lines 76-82 Link Here
76
 * The output can be used to build a new area tree (@see AreaTreeBuilder)
77
 * The output can be used to build a new area tree (@see AreaTreeBuilder)
77
 * which can be rendered to any renderer.
78
 * which can be rendered to any renderer.
78
 */
79
 */
79
public class XMLRenderer extends AbstractRenderer {
80
public class XMLRenderer extends PrintRenderer {
80
81
81
    /** XML MIME type */
82
    /** XML MIME type */
82
    public static final String XML_MIME_TYPE = "application/x-fop-areatree";
83
    public static final String XML_MIME_TYPE = "application/x-fop-areatree";
Lines 130-144 Link Here
130
        this.handler = handler;
131
        this.handler = handler;
131
    }
132
    }
132
133
133
    /**
134
     * set up the font info
135
     *
136
     * @param fontInfo the font info object to set up
137
     */
138
    public void setupFontInfo(FontInfo fontInfo) {
139
        FontSetup.setup(fontInfo, null);
140
    }
141
142
    private boolean isCoarseXml() {
134
    private boolean isCoarseXml() {
143
        return ((Boolean) 
135
        return ((Boolean) 
144
            userAgent.getRendererOptions().get("fineDetail")).booleanValue();
136
            userAgent.getRendererOptions().get("fineDetail")).booleanValue();
Lines 272-277 Link Here
272
                }
264
                }
273
                String value = traitEntry.getValue().toString();
265
                String value = traitEntry.getValue().toString();
274
                addAttribute(name, value);
266
                addAttribute(name, value);
267
                if ("font-family".equals(name)) {
268
                    addAttribute("font-name", fontInfo.getMetricsFor(value).getFontName());
269
                    addAttribute("font-style", fontInfo.getFontStyleFor(value));
270
                    addAttribute("font-weight", fontInfo.getFontWeightFor(value));
271
                }
275
            }
272
            }
276
        }
273
        }
277
    }
274
    }

Return to bug 36180