just a followup - I found kind of a workaround for converting big array to string - writing it to Storage :-) Hopefully there is even advantage that the font data is used directly from flash, saving RAM. Here is code snippet that creates font, writes it to Storage and then creates font from that. And it shows on screen just fine :-)
// for font offsets and sizes see https://github.com/RichardBsolut/GT24L24A2Y
function createFont(off,bs,w,h,c,isprop){
var f=require("Flash");
var fg=Graphics.createArrayBuffer(w,h,1,{vertical_byte:true}); // one letter in fontchip layout
var fnt=Graphics.createArrayBuffer(h,w*c,1,{msb:true}); // whole font in Espruino layout
fnt.setRotation(3,1); // needed to match espruino font layout
off+=0x60000000;//fix data offset, spi flash mapped here
var len=w*h/8;
var x=0,i=0;
var lw=w;
var widths=isprop ? Uint8Array(c) : w;
while(i<c){
fg.buffer=f.read(len,off);off+=bs;
if (isprop){
lw=1+fg.buffer[0];
widths[i]=lw;
fg.buffer[0]=0; // real width of letter if proportional, clear
}
fnt.drawImage(fg.asImage(),x,0);
x+=lw;
i++;
E.kickWatchdog();
}
const ret=fnt.asImage().buffer;
fg=null;fnt=null;
if (isprop){
return { font: ret, widths: widths, height:h};
}
return { font: ret, widths: w, height:h};
}
var fnt=createFont(0x199e0e,322,40,64,14,true);
//g.setFontCustom(E.toString(fnt.font),0x30,E.toString(fnt.widths),64);
flen=E.sum(fnt.widths)*8;
var s=require("Storage");
s.write("FNT-64x40.wdt",fnt.widths)
s.write("FNT-64x40.bin",new Uint8Array(fnt.font,0,flen)) // font is proportional so array is smaller
g.setFontCustom(s.read("FNT-64x40.bin"),0x30,s.read("FNT-64x40.wdt"),64)
g.drawString("01234");
g.flip();
But anyway method to change type of byte array to string in place and share same data would be nice to have.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
just a followup - I found kind of a workaround for converting big array to string - writing it to Storage :-) Hopefully there is even advantage that the font data is used directly from flash, saving RAM. Here is code snippet that creates font, writes it to Storage and then creates font from that. And it shows on screen just fine :-)
But anyway method to change type of byte array to string in place and share same data would be nice to have.