• strange behaviour with color.
    With source below, text is blue and rect is green
    Looks like drawString expects color from 1 to 8 and drawRect expects 0 to 7

    require("Font8x16").add(Graphics);
    var grf = Graphics.createArrayBuffer(128,32,4,{int­erleavex:true});
    grf.setBgColor(0);
    grf.clear();
    grf.setFont("8x16",size);
    grf.setColor(2);
    grf.drawString("my test",10,5);´
    grf.drawRect(0,20,127,24);
    
  • oh, cool, was fighting with this or something very similar some time ago but with bitmap vs vector font, had 4 bit buffer and last color was white and had to do setColor(16) instead of expected setColor(15) to make it really white. Can you check if using vector font in same place makes a difference? one font was white with color 15 the other needed color 16

  • Wow, this is an odd one. Thanks for letting me know!

    You can do this in the emulator:

    require("Font8x16").add(Graphics);
    var grf = Graphics.createArrayBuffer(8,16,4,{inter­leavex:true});
    grf.setBgColor(0);
    grf.clear();
    grf.setFont("8x16",1);
    grf.setColor(2);
    grf.drawString("X",0,0);
    grf.drawRect(7,0,8,8);
    
    for (var y=0;y<16;y++){
      var s = "";
      for (var x=0;x<8;x++)
        s += grf.getPixel(x,y);
      print(s);
    }
    

    I think this is related to custom fonts. If you use a built-in or vector you should be ok?

  • Thats crazy, with Vector font color is green, as expected
    So its a problem with type of font

  • strange, when I hit the issue I asked jeffmer if he can replicate and it was ok for him
    https://gitter.im/nRF51822-Arduino-Mbed-­smart-watch/Lobby?at=60477dfe44f5a454a46­5000e
    also looks like I tried on bangle emulator at that time and couldn't see it too so was thinking it was issue in my build. So I am happy someone else sees it too :-)

  • Checked with font 6x8, 4x6, Vector and all work fine.
    Looks like there's a problem with/around font 8x16 only (?)

  • Most probably it is any custom font - one made by setCustomFont. 6x8, 4x6, Vector are all built-in special cases, not custom ones.

  • There is a special handling for custom fonts in jswrap_graphics #1471 to #1476.
    graphicsBlendGfxColor is used instead of gfx->data.bgcolor
    I've no idea whats going on there.
    Let me walk on thin ice, could it support colored fonts ?

  • Ahh, ok - so custom fonts were tweaked a while back to allow the use of antialiased fonts - so rather than just 1BPP, 2 or 4. You can see what happens if you change the BPP in http://www.espruino.com/Font+Converter

    I'll see about getting a fix in now

  • Ok, if you pull now it's fixed!

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

Color difference between drawRect and drawString

Posted by Avatar for JumJum @JumJum

Actions