Windows Phone 10 - fonts not working

14 views
Skip to first unread message

Bryan Buchanan

unread,
Jul 4, 2016, 6:58:32 PM7/4/16
to CodenameOne Discussions
        final Form hi = new Form("Fonts");
        hi
.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
        hi
.setScrollableX(false);
        hi
.setScrollableY(true);

       
int[] sizes = {2, 3, 4, 6, 8};

       
String[] fonts = {"ArchitectsDaughter",
           
"Cabin-Regular",
           
"Cabin-Bold",
           
"Kalam-Regular",
           
"Kalam-Bold",
           
"Merienda-Regular",
           
"Merienda-Bold",
           
"Montserrat-Regular",
           
"Montserrat-Bold",
           
"NotoSans-Regular",
           
"NotoSans-Bold",
           
"OpenSans-Regular",
           
"PlayfairDisplay-Regular",
           
"PlayfairDisplay-Bold",
           
"Roboto-Regular",
           
"Roboto-Bold",
           
"Ubuntu-Regular",
           
"Ubuntu-Bold"};

       
for (String s : fonts) {
           
Button b = new Button(s);
            b
.addActionListener(new ActionListener() {
               
@Override
               
public void actionPerformed(ActionEvent evt) {

                   
Form f = new Form(s);
                    f
.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
                    f
.setScrollableX(true);
                    f
.setScrollableY(true);

                   
for (int i : sizes) {
                       
int fontSize = Display.getInstance().convertToPixels(i);
                       
Font ttfFont = Font.createTrueTypeFont(s, s + ".ttf").derive(fontSize, Font.STYLE_PLAIN);
                        f
.add(createForFont(ttfFont, i + "mm: The quick brown fox"));
                        f
.add(createForFont(ttfFont, i + "mm: 0123456789"));

                   
}
                    setBackCommand
(hi, f);
                    f
.show();
               
}

           
});
            hi
.add(b);
       
}

        hi
.show();
.....
   
private Label createForFont(Font fnt, String s) {
       
Label l = new Label(s);
        l
.getUnselectedStyle().setFont(fnt);
       
return l;
   
}
 
Works fine on Android, all different fonts and sizes display. On WP10 the font size changes but only the system font is displayed.

Shai Almog

unread,
Jul 5, 2016, 12:40:38 AM7/5/16
to CodenameOne Discussions
Can you file an issue on that?
It's OK to include just one TTF file that's free e.g. Roboto with the test case.

Bryan Buchanan

unread,
Jul 5, 2016, 1:13:38 AM7/5/16
to CodenameOne Discussions
Done.
Reply all
Reply to author
Forward
0 new messages