Fonts

  • Fonts are graphical resources that can be accessed with a call to ej.microui.display.Font.getFont(). To be displayed, these fonts have to be converted at build-time from their source format to the display raw format by the font generator tool.

  • Fonts, just like images, must be declared in a *.fonts.list file.

Creating a font

  • To create a font, go to the package you want to store your fonts in, usually Resources> fonts.

  • Then Right-Click > New > Other> MicroEJ > MicroEJ Font:

    ../../_images/microejfont.png
  • Then, type the name of the font:

    ../../_images/fontname.png
  • Click on Finish, the following window opens:

    ../../_images/fonteditor.png

    Note

    It is important to have the font that you want already installed on your system.

  • To import characters from a system font, click on Import… and the following opens:

    ../../_images/importfonts1.png
  • Click on Next and then select the font to use as shown below:

    ../../_images/importfonts2.png

    Note

    If using a latin based alphabet, just leave the settings as they are and click on Finish, don’t forget to adjust the height and baseline of the font.

  • Click Finish and save the file. The font is imported in the .ejf file.

  • Then just add the font to a myapp.fonts.list file in the src/main/resources source folder of your application:

    /fonts/NewFont.ejf
    
  • More info in the Fonts section.

Adding the Font to a Label

To add the font, choose the font in the StyleSheet:

public static void main(String[] args) {
   MicroUI.start();
   Desktop desktop = new Desktop();
   Flow flow = new Flow(LayoutOrientation.VERTICAL);
   Label label = new Label("Hello World");
   Font font = Font.getFont("/fonts/NewFont.ejf");
   CascadingStylesheet css = new CascadingStylesheet();
   EditableStyle style = css.getSelectorStyle(new ClassSelector(BUTTON));
   flow.addChild(label);
   style.setFont(font);
   desktop.setStylesheet(css);
   desktop.setWidget(flow);
   desktop.requestShow();
}

Note

Don’t forget to set the stylesheet to the desktop.

../../_images/font.png

Next step: Scroll List