No glyphs with local TTF file

137 views
Skip to first unread message

Andrea Cisternino

unread,
Sep 7, 2015, 10:40:30 AM9/7/15
to ControlsFX
Hi all,

I am evaluating ConstrolsFX for improving the look of an Opens Source application developed by a good friend of mine.

While adding a simple toolbar to the app, I have run into a problem with local font support in the Glyph* classes.

I tried both with IcoMoon and with Google's original Material Design Icon font (https://github.com/google/material-design-icons).

I have followed the example found in ControlsFX's HelloGlyphFont.java but I always get an empty square inside the buttons instead of the actual glyph.

I have narrowed down my example as much as possible:


public class GlyphFontTest extends Application {

    static {
        GlyphFontRegistry.register("materialfont", GlyphFontTest.class.getResourceAsStream("MaterialIcons-Regular.ttf"), 16);
    }

    private final GlyphFont materialFont = GlyphFontRegistry.font("materialfont");

    @Override
    public void start(Stage primaryStage) {

        HBox root = new HBox();
        root.getChildren().add(new Button("", materialFont.create('\ue037'))); // Play
        root.getChildren().add(new Button("", materialFont.create('\ue034'))); // Pause

        Scene scene = new Scene(root, 300, 250);

        primaryStage.setTitle("GlyphFontTest");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

The file MaterialIcons-Regular.ttf is located alongside the GlyphFontTest class in the same package.

I am working on Windows 7 and these are the versions used:

Oracle's JDK: 1.8.0_45
ControlsFX: 8.40.9

Any clue about what I am doing wrong?

Thanks a lot!
controlsfx-font-test.png

Anirvan Sarkar

unread,
Sep 9, 2015, 2:12:11 AM9/9/15
to ControlsFX
Hi,

You have used the wrong font family name for Material Font.
It should be Material Icons instead of materialfont.


i.e.

static {

    GlyphFontRegistry.register("Material Icons", GlyphFontTest.class.getResourceAsStream("MaterialIcons-Regular.ttf"), 16);
}

private final GlyphFont materialFont = GlyphFontRegistry.font("Material Icons");
Material Icons.png

Andrea Cisternino

unread,
Sep 9, 2015, 8:01:04 AM9/9/15
to ControlsFX
Hi,

Thanks for the reply Anirvan.
I tested again with you changes as you suggested and it works.

Perhaps the documentation should make clearer that the first parameter of the register() method must take the precise font name as specified in the TTF file and not user-given string.

In any case thanks again for an awesome piece of software :)

Regards,
  Andrea.
Reply all
Reply to author
Forward
0 new messages