Graphics.drawString not working on 1v98?

Posted on
  • I reflashed to 1v98 and drawString seems to not work:

    var g = Graphics.createArrayBuffer(8, 8, 1);
    
    //console
    >g.drawString("X");
    =undefined
    >g.buffer.toString()
    ="0,0,0,0,0,0,0,0" //empty??
    

    tried fillRect works fine:

    var g = Graphics.createArrayBuffer(8, 8, 1);
    
    //console
    >g.fillRect(0,0,4,4);
    =undefined
    >g.buffer.toString();
    ="31,31,31,31,31,0,0,0" //not empty
    

    Am I missing anything?

    Thanks!

  • Thanks - I'm looking into this now. That code works fine on the Linux build so all the automated tests passed.

    If you do g.setFontAlign(0,0,0); then it'll work, but all text is center-aligned.

  • Ok, now fixed in GitHub. Turns out GCC's handling of signed bit fields seems to be broken (or at the very least different) on non-x86 platforms. I never noticed because in my tests on real hardware I'd been using g.setFontAlign.

    I'll push a 1v99 version in the next hour or so.

  • Thanks! looking forward to update.

  • I flashed via the web IDE to 1v99 and seems like the problem persists (still got empty buffer like the above example). On another test on an 8x8 neopixel

    leds.setFontAlign(0,0,0);
    leds.drawString("1");
    

    actually draws the "1" character at x:-2 and y:-2, so not centered.

  • Which board are you using? I just tried here on a Pixl and also a Pico and it seems ok:

    >var g = Graphics.createArrayBuffer(8, 8, 1);
    =Graphics: {
      "buffer": new ArrayBuffer(8)
     }
    >g.drawString("X");
    =undefined
    >g.buffer.toString()
    ="5,5,2,5,5,0,0,0"
    

    I'm not quite sure I understand about the centering - the default text is normally 4x5 characters so -2,-2 sounds ok, perhaps 1 pixel off depending how you choose to round.

  • I see - I might misunderstood how the fontAlign works. I am using the original espruino board.

  • I just tried an original Espruino board and the code I posted above does work for me. Is there something else that isn't working for you?

    Have a look at http://www.espruino.com/Reference#l_Graphics_setFontAlign

    setFontAlign is new, but basically it defines how subsequent calls to drawString(txt,x,y) will align the text to x,y. In your example you've left x&y out, so it'll be using 0,0 as the centre, hence the apparent -2,-2.

    You probably wanted:

    leds.setFontAlign(0,0,0);
    leds.drawString("1",leds.getWidth()/2,leds.getHeight()/2);
    
  • Thanks Gordon - strange, I’m getting the empty buffer still. I’ll try again after work and update.

  • Looks like I was still on 1v98 when I tried the second time around. Confirmed on 1v99 that issue is fixed. Thanks!

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

Graphics.drawString not working on 1v98?

Posted by Avatar for n00b @n00b

Actions