sidorares / ntk

node.js desktop UI toolkit
91 stars 12 forks source link

Spaces show up as blocks #33

Open RossComputerGuy opened 6 years ago

RossComputerGuy commented 6 years ago

Whenever a space character is rendered, it shows up as a block. I've tried lots of different fonts and I don't think it has to do with the fonts. The 2d context is causing this. Can we please have this fixed?

sidorares commented 6 years ago

Sure, I'll have a look. A bit of documentation on how text is rendered with ntk

when you call .fillText it splits string into glyphs and calls

https://github.com/sidorares/ntk/blob/c6233582c82b51b84ed6ae2d6e9f6735e23964bd/lib/renderingcontext_2d.js#L144-L146

( "split into glyphs" is actually much difficult task in real life and would require harfbuzz library to du correctly, but for Latin scripts it mostly works juts by treating characters as glyphs )

When you specify font via something like `ctx.font = "Courier 10pt" this code is used:

https://github.com/sidorares/ntk/blob/c6233582c82b51b84ed6ae2d6e9f6735e23964bd/lib/renderingcontext_2d.js#L370-L414

"Spaces show up as blocks" problem is likely located somewhere in last two steps ^.