• I now just return whole Graphics from createFont and here is copy of session where E.toString fails, no asImage used this time

    >process.memory()
    ={ free: 799, usage: 1801, total: 2600, history: 147,
      gc: 0, gctime: 3.47900390625, blocksize: 16, stackEndAddress: 536926192, flash_start: 0,
      flash_binary_end: 356348, flash_code_start: 417792, flash_length: 524288 }
    >var fnt=createFont(0x199e0e,322,40,64,14,tru­e);
    ={
      font: Graphics: {
        buffer: new Uint8Array([0, 0, 0, 0, 0,  ... 0, 0, 0, 0, 0]).buffer
       },
      width: new Uint8Array([40, 34, 40, 40, 40, 40, 40, 40, 40, 40, 13, 13, 13, 13]),
      height: 64 }
    >process.memory()
    ={ free: 658, usage: 1942, total: 2600, history: 150,
      gc: 255, gctime: 3.81469726562, blocksize: 16, stackEndAddress: 536926192, flash_start: 0,
      flash_binary_end: 356348, flash_code_start: 417792, flash_length: 524288 }
    >E.toString(fnt.font.buffer)
    =undefined
    >trace(fnt.font.buffer)
    #2385[r1,l1] ArrayBuffer (offs 0, len 4480)  #2002[r1,l0] String [122 blocks] "\0\0\0\0\0\0\0\0\0\0\3\xFF\xFF\xC0\0\0\­0\0?
    ....lot of data....
    

    I guess the main issue is that https://www.espruino.com/Reference#l_E_t­oString says "Returns A String (or undefined if a Flat String cannot be created)"

    In this case I'd be happy with non flat string - the #2002[r1,l0] String [122 blocks] one. So something like E.toString(buffer,false) like E.getAddressOf() would probably do.
    Hmm but it is already taken, E.toString("Hello",false) gives "Hello\0".

About

Avatar for fanoush @fanoush started