|
My little graphics library needs to do text, and I thought "hey, I'll whip up a C# app to rasterize monospaced fonts to a monochrome bitmap."
Just add a reference to System.Drawing to a console app, and then create a Bitmap and draw to it right?
Wrong.
Even after you set all of the text rendering hints, and even using GraphicsPath.AddString() for more accuracy, you cannot turn off the padding around the fonts, nor get the font to a pixel perfect height at all sizes.
The thing is, the GDI+ code underneath is perfectly capable of doing this. They just didn't expose it.
The alternative is reinventing the entire elephanting wheel and rasterizing the fonts myself.
I found an open source project (under Apache license unfortunately) that I can use to build my tool. Fortunately that tool isn't part of my GFX package itself - it's just a utility to make files that the GFX code can read.
But this shouldn't be necessary. They actually have to parse the TTFs and draw them manually.
Real programmers use butterflies
|
|
|
|
|
Would any of these help? : The Ultimate Oldschool PC Font Pack[^]
"They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"
|
|
|
|
|
That's neat, but they're just retro font files. I guess maybe some of the formats they have are easier to use than TTF but id I went that route I'd be forced to use say, .fon files or whatever, and I'd really like the end user of my library to be able to choose their own fonts. So .ttf is pretty much what's for dinner.
I've got code to do the TTF rasterization now, I just need to modify it for my own nefarious purposes.
It will be nice to have the drawing primitives of GFX sewn up, and this is the last of it, unless i decide to add things like bilinear resampling and antialiasing.
Real programmers use butterflies
|
|
|
|
|
Those are all pre-rasterized fonts. Yes, they are old but so what? For this purpose, that is exactly what I would use. This is for an Arduino right? Do you really want to pursue much beyond bitmap fonts? I certainly wouldn't. Anti-aliasing? Nope. I would not go beyond allowing the option for a transparent background or opaque. That is, for highest performance and that should be the highest priority in my opinion. If cosmetics are that high a priority then you are on the wrong platform as far as I am concerned.
"They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"
|
|
|
|
|
I was intending to render to a monochrome bitmap. I did manage to get it to render without anti-aliasing, and with single-bit-per-pixel position.
That was not the problem. I could render any monospace font regardless of whether or not it was BMP based. Because I was rendering the font, and saving the result of the render as a bitmap.
The only problem I ran into - THE ONLY problem, was positioning. .NET has no facility to accurately position fonts to a pixel perfect grid. That's the only problem.
And yes, cosmetics are an issue, because sometimes, I'm being called on to write professional looking software, and professional looking software shouldn't look like elephant crap, even on an embedded device. They aren't always an issue in all circumstances, but they are when it comes to larger font renderings.
If I need anti-aliasing i can bump from monochrome to grayscale and then treat the grayscale like an inverted alpha channel
The ESP32 can handle displaying a small rendering of Lucida Console (for example) or I wouldn't be doing this.
Real programmers use butterflies
|
|
|
|
|
Cool. Best of luck with it.
"They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"
|
|
|
|
|
Quote: The thing is, the GDI+ code underneath is perfectly capable of doing this. They just didn't expose i Then write a C++ program using Winapi & GDI+ .
I experienced myself the problem you have with C# and found it quite annoying. Eventually I used a free tool (unfortunately I don't remember its name) to rasterize the fonts.
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
Yeah, I want to go the free tool route if possible, or otherwise whip this up quick and dirty. I just need to make a tool that's not standalone - it's just meant as a utility to generate font files my code needs.
Real programmers use butterflies
|
|
|
|
|
A C# wrapper around FreeType is another alternative?
|
|
|
|
|
I have no idea what freetype is
*googles*
I don't need a C# wrapper. I can code in pretty much anything - taught myself some python last night because i needed some code from a script =). I just had never heard of freetype before.
Thanks
Real programmers use butterflies
|
|
|
|
|
|
I think that's what GraphicsPath.AddString() calls but I could be wrong.
At any rate, I'll give it a shot down the road. I've decided to import .FON files for the time being.
Thanks! I'll bear this in mind.
Real programmers use butterflies
|
|
|
|
|
We used it back in the day under Windows 3.1 to render TrueType fonts into bitmaps for use in our commercial ink-jet printers. There are other calls in that same area that give you character metrics and other useful information for your application.
Software Zen: delete this;
|
|
|
|
|
fwiw: I wonder if what you observe is the result of the quantizing/hinting of outline-based fonts for display/rasterization at different point sizes.
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
|
|
|
|
|
I thought about that, but it doesn't seem like it, because the padding is consistent (in terms of physical proportions) as you increase the size. There seems to be some internal box layout (similar to CSS margins/padding) but I can't control it.
I could be wrong of course. Being on the outside looking in when it comes to the implementation of this there's always the possibility, but I'm more confident than not about this.
Real programmers use butterflies
|
|
|
|
|
I found these little guys in a (Oklahoma) tree. Anyone know their species?
Picture 1
Picture 2
Thank you.
DC
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
|
They're called a Nope of the genus Nopus Nopus
|
|
|
|
|
|
|
Good call. My youngster said it was a wheel bug when he first showed it to me, but when I went to search for it, all I found was the adult, which obviously looks different.
Thanks.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Good think I'm not an arachnophobe.
(at least they look like spiders to me)
Those of you who are, consider yourselves warned.
|
|
|
|
|
Shouldn't this be in the Bugs and Sugs forum?.....just kidding.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
curious how you got direct links to CP on the pictures: thought you couldn't do that in posts here. thanks !
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
|
|
|
|
|