-
hello @allObjects,
wow, it's really hard for my poor english to understand all you're writing (and goo translate is shameful)...
what is a "streak" in this particular context?The array is the char width (of a slanted font), and the index (position in the array) is the ascii code of the letter. as i use accents, i use extended ascii table (255 members)
i use an other array, an object to be accurate, for kerning letters. (i rewrited 3 time my
algorithm, and now it's quicker)
because the font is slanted, his char width is wrong withg.stringWidth(char)
.const charWidth = [,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,3,2,,4,,,,0,4,5,4,2,1,3,0,5,4,4,4,4,,,,,,,2,2,3,3,4,3,,4,4,4,4,4,4,4,4,3,4,4,4,5,4,4,4,4,4,4,3,4,4,5,4,4,4,,,,,,,4,4,3,3,3,3,5,5,2,4,4,3,6,4,3,6,4,5,3,3,3,4,5,4,5,4,,,,,,,2,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,4,,4,,4,,,4,4,4,4,4,,,,,,,,,,,,,,,,,,,,,3,,4,,,,,3,3,3,3,3,,,3,3,,,,,3,,3,,,3,,3,3,,,2]; const aKerning = { 'a':["ad+1","al-1","af-1","ag+0","ai-1","am+0","an-1","ap-1","ar-1","au+1","as+0","av+1"] ,'b':["bi-1","bl-1","bo+0","br-1","bs-1"] ,'c':["ci-1","cl-1","cu+1"] ,'d':["de+1","di+0","dr+0","du+1","d'+1"] ,'e':["ea+1","ec+1","eg+1","ep-1","er+1","es+1","et+1","eu+2","ev+2","ez+1"] ,'é':["éâ+1","éc+1","ée+1","éj+1","éo+1","ép-1","ér+0","és+1","ét+1","év+2"] ,'è':["ès+1","èt+1"] ,'ê':["êt+1"] ,'Ê':["Êt-1"] ,'f':["fe+1","ff-1","fl+0","fo+1","fu+2"] ,'g':["gi-1","gn+0","gl-1","gu+1"] ,'h':["hi-1","hr-1"] ,'i':["iA+1","ib+1","ic+1","id+1","ie+1","ié+1","iè+1","ig+1","io+1","iq+2","ir+1","is+1","it+1","iv+2","ix+1","iz+1"] ,'j':["ju+1"] ,'k':[] ,'l':["lé+0","li-1","ll-1","lv+1","l'+1"] ,'m':["ma+0","mb+0","mi+0","mm-1","mp-1","mu+1"] ,'n':["na+1","nc+1","nd+2","ne+2","né+1","nj+1","nn+0","no+1","nt+1","nv+2","nu+2"] ,'o':["ob+1","oc+1","od+2","oe-1","oè+1","oo+1","om+1","op-1","os+1","ot+1","ou+2","ow+1"] ,'p':["pé+0","pi-1","ph-1","pl-1","po+0","pp-2","pr+0"] ,'q':["qu+0"] ,'r':["ré+0","rg-1","ri-1","rl-1","rm-1","rn+1","rr-2","rs+1","ru+1","rv+1"] ,'s':["sa+1","sc+1","se+1","so+1","sp-1","sq+1","st+1","su+1"] ,'t':["ta+0","té+0","th-1","ti-1","tr-1"] ,'u':["ud+1","ue+1","ui+0","ul+0","um-1","un-1","up-1","uq+1","ut+1","uv+1"] ,'v':["va-1","ve-1","vi-1","vo-1","vr-1"] ,'w':["wh+0","wr-1"] ,'x':[] ,'y':["yn-1","ys-1"] ,'z':["z-+1"] };
i rewrite the array
aKerning
with the comma at the beginning of the line (easier to read ;). Thanksé.
1 Attachment
Just for the sake of fun, I did annotate your- pretty sparse - array of 256 elements (bear with me, it i a lot of nothing / undefineds / u's):
Initially I had the thoughts of the following pattern:
in an initializing table, you identify the streaks, their lengths and values. For each streak you have basically these for value groups:
3.,4.,5... Values of the streak.
To make it more efficient for streaks of one, you put the value in negative and no need for the length of a streak. A simple algorithm initializes in
onInit()
called function the working arraywa
from the initialization arrayia
and then you throw the initialization array away... (withdelete ia;
).So your initialization array `
ia
would then look like this (only first few streaks)The other approach which requires less spade in the initialization array but may be a bit more investment in the initializing algorithm is to have a bit list where values go and then just a the list of the values. Since 256 bits fill exactly 2 4-byte words or integers, you need only 8 bytes to describe where something goes and where nothing goes. Since this is so efficient, you may not even go to the integer encoding but use just a hex string. Remember, source area bytes taken away from variables - of course so does code. Using data directly from flash memory can save you space as well...
So the bit list in hex - which you convert on the go nibble by nibble with LSBit first - looks like this;
For both, the initialization algorithms are simple: walking the streaks or walking the bit list and value list in parallel. Would be interesting - as a next step - to have the 'savings factor' figured out... The more arrays the more savings since the algorithm is required only once... where as the no space has to be defined for every single array.
I don't know how you came up with the initial array. Generating the streaks or bit and value lists is for sure something for a generator / translator from the raw string / original source.