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 (+10 lines)
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 102-107 Link Here
102
    /** The OutputStream to write the generated XML to. */
103
    /** The OutputStream to write the generated XML to. */
103
    protected OutputStream out;
104
    protected OutputStream out;
104
    
105
    
106
    /** Font configuration */
107
    protected FontInfo fontInfo;
108
105
    /**
109
    /**
106
     * Creates a new XML renderer.
110
     * Creates a new XML renderer.
107
     */
111
     */
Lines 136-141 Link Here
136
     * @param fontInfo the font info object to set up
140
     * @param fontInfo the font info object to set up
137
     */
141
     */
138
    public void setupFontInfo(FontInfo fontInfo) {
142
    public void setupFontInfo(FontInfo fontInfo) {
143
        this.fontInfo = fontInfo;
139
        FontSetup.setup(fontInfo, null);
144
        FontSetup.setup(fontInfo, null);
140
    }
145
    }
141
146
Lines 272-277 Link Here
272
                }
277
                }
273
                String value = traitEntry.getValue().toString();
278
                String value = traitEntry.getValue().toString();
274
                addAttribute(name, value);
279
                addAttribute(name, value);
280
                if ("font-family".equals(name)) {
281
                    addAttribute("font-name", fontInfo.getMetricsFor(value).getFontName());
282
                    addAttribute("font-style", fontInfo.getFontStyleFor(value));
283
                    addAttribute("font-weight", fontInfo.getFontWeightFor(value));
284
                }
275
            }
285
            }
276
        }
286
        }
277
    }
287
    }

Return to bug 36180