You are reading a single comment by @HughB and its replies. Click here to read the full conversation.
  • Hi,

    I have an app that now uses 7 custom fonts. The font is selected from a settings menu.
    So I only need one active font to be loaded when the App starts up.

    At the moment I have 7 seperate font functions that really bloat the App in terms of memory footprint.
    I guess I should really just load the one font I need from storage for the lifespan of the App.

    Just trying to get my head round how I physically do this - what code goes where and how it is loaded.

    Graphics.prototype.setFontArchitect = function() {
    // Actual height 40 (41 - 2)
    var widths = atob("CBolByEeJykkJCYhCg...==");
    var font = atob("AAAAAAAAAAAAAAMAAAAAAAAAAAAA....="­);
    var scale = 1; // size multiplier for this font
    
    g.setFontCustom(font, 46, widths, 58+(scale<<8)+(1<<16));
    };
    

    Would you recommend that I create a module for each of these fonts that basically does something similar to:

    https://www.espruino.com/modules/FontDyl­ex7x13.js

    How do I tell the apps.json file that the code has 7 custom font files ?
    I think the answer is the way that modules are loaded - example gpssetup
    The module file drops the .js from the source file name.
    Then the App does require("myfont");

      "storage": [
        {"name":"gpssetup","url":"gpssetup.js"},­
    

    Then I think I would just load settings at the top of the code and run this bit of one time code for the lifetime of the App.

     if (settings.font == "Architect")
        require("f_artitect").add(Graphics);
      else if (settings.font == "GochiHand")
        require("f_gochihand").add(Graphics);
      else if (settings.font == "CabinSketch")
        require("f_cabin").add(Graphics);
      else if (settings.font == "Orbitron")
        require("f_orbitron").add(Graphics);
    ...
    
About

Avatar for HughB @HughB started