How to get a font with custom width for characters? #1900
Unanswered
vgibilmanno
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to port an old application which uses GDI to draw text. It uses the LogFont struct and CreateFontIndirect + SelectObject to create a logical font which then is mapped by GDI. By using the LogFont struct you are able to set alot of different metrics for a font. I used the PickFont application to replicate what the old application is doing. Pickfont draws text by purely using GDI. See the following screenshot:

In case you want to compile the PickFont application for yourself, visit the following repo: https://github.com/recombinant/petzold-pw5e
GDI seems to support any width value I enter when using Consolas as a font. Other fonts work well too, but not every width value seems to be supported.
Now with SkiaSharp I'm able to create a Consolas font with a TextSize of 59. But how can I change the average char width to be 21 as in the example screenshot above?
I tried looking up solutions for it but the only thing I got until now is that I possibly should use HarfBuzz to solve this, but I didn't manage to get it to work. I'm not sure though if HarfBuzz can really solve my problem
Beta Was this translation helpful? Give feedback.
All reactions