• Hello,
    I'm newb with espruino (i love using javascript for produce string... So gorgeous in front arduino...)
    Sorry for the stupid question.
    I've customized DennisFont8 to produce a DennisFont16, it works, but there is only 1 px (one pixel) between each letter, is there a way to had one more?
    To have 2 pix in fact.
    Best regards

    éric


    1 Attachment

    • 2017-03-18 11.37.20.jpg
  • Looks really nice! There's no 'padding' in drawString - I'm pretty sure it puts each character one after the other. I guess you have 2 options:

    • Change your font to add another column or 2 of pixels after each character
    • Override drawString - you should be able to do something like:

    g._ds = g.drawString;
    g.drawString = function(s,x,y) {
      s=s.toString();
      for (var i=0;i<s.length;i++)
        g._ds(s[i],x+i*10,y);
    }
    
  • thanks @Gordon, and if i follow, the "10" is the step for letter width + kerning?

    The other way:
    i've used the online tool to convert and check the autoWidth, i should try with a fixed width with a double pixel as kerning...

  • I've try to compile with static width but the font doesnot seems to work, i've got an error with setDennisFont16() fonction...
    works with the js with automatic width, not with the fixed width...
    i'll try to ovewrite the default drawString().

  • @gordon, it works, BUT, the DennisFont has no fixed width. there is less width for an "i" or "l" than a "e"... and there is a gap...
    i've tried that

    g._ds = g.drawString;
      g.drawString = function(s,x,y) {
      s=s.toString();
      for (var i=0;i<s.length;i++)
        g._ds(s[i],x+=(g.stringWidth(s[i])+2),y)­;
      };
    

    it does not work for fine letter as i, l

    any idea?
    regards

  • I guess the font tool adds just 1px of padding, and it isn't configurable. Unfortunately it looks like it's server-side so you can't easily fix that. You could use the command-line tool that i originally made, and could modify the place where that adds an extra column? github.com/espruino/Espruino/blo­b/master/scripts/create_custom_font.js#L­58

    I guess what you could do is use Espruino to re-encode the fonts yourself. I'll see if I can come up with an example.

    Your use of g.stringWidth looks like it should work fine - could you maybe print the values you're getting from it and see if they are changing?

  • Ok, so this is more for your interest than anything else. Using an Espruino Pico with a PCD8544 display, this code actually creates a new double-size font (with spaces) on the Espruino itself:

    A5.write(0); // GND
    A7.write(1); // VCC
    
    var charFrom = 32;
    var charTo = 126;
    var charHeight;
    var charWidths, charData;
    
    function doFont() {
      var height = 6;
      var gbig;
      var gsmall = Graphics.createArrayBuffer(height*2, height, 1);
      var totalWidth = 0;
      for (var i=charFrom;i<=charTo;i++)
        totalWidth += gsmall.stringWidth(String.fromCharCode(i­)*2);
      charWidths = "";
      charHeight = height*2;
      charData = "";
      for (i=charFrom;i<=charTo;i++) {
        console.log("Char "+i);
        var ch = String.fromCharCode(i);
        gsmall.clear();
        gsmall.drawString(ch);
        var w = gsmall.stringWidth(ch);
        gbig = Graphics.createArrayBuffer(charHeight, w*2, 1,{msb:true});
        gbig.setRotation(3,true);
        for (var y=0;y<height;y++)
          for (var x=0;x<w;x++)
            if (gsmall.getPixel(x,y))
              gbig.fillRect(x*2,y*2,x*2+1,y*2+1);
        charWidths+=String.fromCharCode(gbig.get­Width());
        charData += E.toString(gbig.buffer);
      }  
    }
    
    
    // Setup SPI
    var spi = new SPI();
    spi.setup({ sck:B1, mosi:B10 });
    // Initialise the LCD
    var g = require("PCD8544").connect(spi,B13,B14,B­15, function() {
      // When it's initialised, clear it and write some text
      g.clear();
      doFont();
      g.setFontCustom(charData, charFrom, charWidths, charHeight);
      g.drawString("Hello",0,0);
      g.flip();
    });
    

    You could then re-encode it with btoa and make your own custom font again.

    It'll only work if width*height of each character in the new font is a multiple of 8, but for your case that should be fine.

    You should be able to modify that to just print your existing font (not doubling the size) while also adding a blank column.

    Honestly though - I'd just use the code I linked above and change the number for padding :)

  • Many Thanks @Gordon, it works great!
    I use it with DennisFont (cause i'm writing in french, have to had more chars, count until 255) with a height of height (arf)
    i keep line 4 to 34 and modifying as follow after

    require("FontDennis8").add(Graphics);
    
    function centre(text, y) {
      g.drawString(text, (g.getWidth() - g.stringWidth(text))/2, y);
    }
    
    function init() {
      g.clear();
      g.setFontDennis8();
      centre("en attendant",22);
      g.flip();
      doFont();
      g.clear();
      g.setColor(1);
      g.setFontDennis8();
      centre("en short",22);
      g.fillRect(10,0, g.getWidth()-20, 18);
      g.setColor(0);
      g.setFontCustom(charData, charFrom, charWidths, charHeight);
      centre("Ta m\xe8re",2);
      // affiche
      g.flip();
    }
    
    var g;
    function onInit() {
      // initialise l'écran oled
      I2C1.setup({scl:B6,sda:B7});
      g = require("SSD1306").connect(I2C1, init, { height : 32 });
    }
    
    

    regards

    éric


    1 Attachment

    • 2017-03-27 23.38.25.jpg
  • Looks great!

    I quite like the pixellated look, but if you did want to do your own font it should be possible to find/make some tool that created a higher resolution font tile that you could then import.

  • Hi @Mrbbp,

    like the small oleds you are using, can you please share where you ordered them?

    @Gordon this is what I was thinking about for #978 - thanks for sharing!

  • Hi @MaBe,
    They come from ebay, hongkong
    0,98" 128x32 i2c oled display they are in white and blue. Be aware in the description
    Regards

  • And i discovered that the é was 1pix larger. I redesign minus with 1 pix larger.
    The fontDennisAlternate

    /* Copyright (c) 2015 Dennis Bemmann. See the file LICENSE for copying permission. */
    /*
    FontDennis8Alt.js
    ==============
    
    from fontDennis8
    Redesign mrbbp
    
    Usage:
    
    

    require("FontDennis8Alt").add(Graphics);­
    g.setFontDennis8Alt();
    g.drawString("\x90 \x91\x92\x93\x94\x95\x96\x97 Dennis8 \x9f \x8c \x8d \x89",0,0);
    g.drawString("ça ¿s� \xbc\xa3 \xbd\xb5\xa6 \x82\x83\x84\x85 \xac\xad\x86",0,12);
    g.drawString("\xa0 Bäh böse Ärzte in Küche\xaf",0,24);

    */
    var font = atob("AAAAAPoAwADAAFhw2HDQAGSS/5JMAGCW+D­zSDAxSolIMEsAAPEKBAIFCPABIMOAwSAAQEHwQEA­ABBgAQEBAQAAIAAwwwwAB8ipKifABA/gBChoqSYg­CEkrLSjAAYKEj+CADkoqKinAA8UpKSDACAgI6wwA­BskpKSbABgkpKUeAAiAAEmABAoRAAoKCgoKABEKB­AAQIqQYAA8WqW9RDgOOMg4DgD+kpKSbAB8goKCRA­D+goJEOAD+kpKCAP6QkIAAfIKCklwA/hAQEP4A/g­AMAgIC/AD+EChEggD+AgICAP5AIED+AP7AMAz+AH­yCgoJ8AP6QkJBgAHyChoN8AP6Qm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AAEKqpqHgAEKi­pqngAEKmqqXgAEaqqqXoAEqioqngAEKmqqXgBMUj­xSNAAYJSckCAAcqmoqGAAcKmqqGAAcaqpqGAAcqi­qqGACifgIAIn6CAGK+QgBiPkIApEqqGgwAXpCQTo­AADJJSEgwADBJSkgwADFKSUgwATJJSkgwAnCIinA­AQEFQQEAA6TFRkuAAcAoJCHgAcAkKCHgAcQoJCHg­AcQgICXgAwCkqKPACB/xUIADCKCoo8AA==");
    var widths = atob("BAIEBgYGBgIEBAYGAwUCBQYDBgYGBgYGBg­YCAwQGBAUGBgYGBgUFBgYCBgYFBgYGBgYGBgYGBg­YGBgUDBQMEBgYGBgYGBgYGBgIFBgQGBgYGBgYGBQ­YGBgYGBgQCBAYGBgQGBgYGBgYGBQUGBgYGBgYGBg­YGBgYGBgQCAwQFBgYGAgYGBgYGBgYGBgYGBgYGBQ­YFBQQGBgMEBAYGBgYGBQYGBgYGBgYGBgYGBgQEBA­QGBgYGBgYGBgYGBgYGBgYFBgYGBgYGBgYGBgYGBA­QEBAYGBgYGBgUGBgYGBgYGBQY=");
    
    exports.add = function(graphics) {
      graphics.prototype.setFontDennis8Alt = function() {
        this.setFontCustom(font, 32, widths, 8);
      }
    }
    
  • Thanks, can you please share a link, because the last one I ordered did not work(ebay.de/itm/201537040004).

  • Thanks

  • Yes, I know what you mean about #978, but I think it's a pretty rare use case when the vector fonts are available - and it's pretty easy to work around with the font that @Mrbbp has just posted.

    @Mrbbp do you want to add this as a new font library on the Espruino site?

  • @Gordon Yes, but i'm not the original designer, i just modified the minus and accents... You have to ask to DennisFont designer...

    Regards

  • By the way @Gordon, does the ide use a cache when compile with a new module?
    When update the font, i have to rename the module at each iteration to use the updated version in the espruino board.
    Is there a better/easier way to disable cache?

    Regards

  • The IDE shouldn't cache the module... Are you serving it from a website somewhere? It could be that the website doesn't transfer it with the no-cache headers so something along the line (maybe even just Chrome) is cacheing it for you.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Had space(more than 1px) between letters with custom font

Posted by Avatar for Mrbbp @Mrbbp

Actions