Repository navigation
Conversation
|
Very nice. Is there a way to make it not look blurry, though? |
LaurenzV
left a comment
There was a problem hiding this comment.
Not sure if I need to add a test for this :-)
If you have access to an AI tool, it should be easy enough to just have it generate a py script that generates such a font (see the existing sbix example ). Otherwise, happy to do this myself if you prefer. :)
| let width = g.width; | ||
| let height = g.height; | ||
| if let Ok(data) = mask.decode(width, height) { | ||
| let rgba = data.iter().flat_map(|&x| [x, x, x, x]).collect::<Vec<_>>(); |
There was a problem hiding this comment.
Since the glyphs represent an alpha mask, I think the read value should only be applied to the alpha channel, not to the RGB ones. In addition, we should also take the context_color into consideration.
So something like this probably?
let [r, g, b, a] = context_color.to_rgba8().to_u8_array();
let rgba = data
.iter()
.flat_map(|&m| [r, g, b, ((u16::from(a) * u16::from(m) + 127) / 255) as u8])
.collect::<Vec<_>>();
We also need to change the cache key of bitmap glyphs so they are not hardcoded to black, but the actual context color.
There was a problem hiding this comment.
That makes sense to me, I didn't even know that was available. The one thing I don't understand though is the math:
255 (context) * 128 (mask) = 128. Okay, makes sense.
But if we include the + 127 then everything drifts positive by 0.498039215686275. It actually becomes 128.498039215686275?
There was a problem hiding this comment.
Nevermind I did a little bit of searching and it is for rounding, I was typing all of the math into a calculator that doesn't truncate like the integers would do here
That's likely because we are scaling the bitmaps with bilinear filtering. I'm not sure if using nearest-neighbor is better though, as it will lead to aliasing artifacts in case the font size doesn't exactly match... |
In Qt and GTK the font size is set to the real sizes of the bitmap font. There's no in-between and thus no scaling. Is something like that possible here too? |
This is used by legacy bitmap fonts like Terminus, all we need to do it seems is expand the 8-bit mask into RGBA data.
1f57be4 to
93be70a
Compare
I took a look and didn't understand a single lick of it, so it's probably better if you do it! |
This is used by legacy bitmap fonts like Terminus, all we need to do it seems is expand the 8-bit mask into RGBA data.
Here's the font now working in the parley text editor example:
Not sure if I need to add a test for this :-)