简体   繁体   中英

How to set custom font in synth style

I would like to integrate a custom font into a synth style. I found a possible answer here but the interesting part - the xml - is not visible on that site.

Could some one explain to me, how to integrate this custom object into the xml?

I figured it out by myself. For everyone searching for this topic, here's the solution. Create a new class:

public class CustomFontResource {
    public static FontUIResource createFont(String path, final int size) {
        Font font = Font.createFont(Font.TRUETYPE_FONT,
                new FileInputStream(path));

        FontUIResource fontResource = new FontUIResource(font.deriveFont(
            Font.PLAIN, size));
        return fontResource;
    }

}

Add this to the style.xml:

<object id="your_font_id" class="yourpackage.CustomFontResource"
        method="createFont">
    <string>fontpath</string>
    <int>desired size</int>
</object>

<style ...>
<font idref="your_font_id" />
</style>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM