OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Mar 29, 2024 4:05 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: TTF font rendering
PostPosted: Tue May 25, 2021 1:46 pm 
Offline
Member
Member

Joined: Sun Jun 23, 2019 5:36 pm
Posts: 618
Location: North Dakota, United States
So I've finally managed to switch my kernel to UEFI, but along with this comes a difficulty: the UEFI framebuffer is not the VGA buffer where I could just write strings.
So now, I have to use font rendering of some kind, either using 8x8 fonts or full TTF rendering. I'm considering using fontdue (a Rust crate) to rasterize glyphs, but my confusion stems from the fact that I don't know how to write them to the buffer so they don't overlap or make other weird visual things that are unreadable. Even if I read the TTF font data manually, I imagine I'll still run into this problem. Can someone explain precisely how this exactly works?


Top
 Profile  
 
 Post subject: Re: TTF font rendering
PostPosted: Wed May 26, 2021 4:26 am 
Offline
Member
Member
User avatar

Joined: Thu Oct 13, 2016 4:55 pm
Posts: 1584
Ethin wrote:
So I've finally managed to switch my kernel to UEFI, but along with this comes a difficulty: the UEFI framebuffer is not the VGA buffer where I could just write strings.
So now, I have to use font rendering of some kind, either using 8x8 fonts or full TTF rendering.
Full TTF rendering seems like a bit over your head. You should be happy with bitmap fonts, you won't stay at UEFI land for long.

A simple way out is to use PC Screen Fonts (the same that Linux uses). My boot loader has some extremely minimal, dependency-free examples on how to display them in C and in Rust.
You can find a lot of free fonts in PSF format, they are already on your computer (if you're using Linux), or you can download many from the internet, for example this, and this etc.

Ethin wrote:
I'm considering using fontdue (a Rust crate) to rasterize glyphs, but my confusion stems from the fact that I don't know how to write them to the buffer
That's exactly the job of the rasterizer. Vector fonts can't be displayed as-is, first they are rasterized into bitmap fonts (at a requested size), and after that, well, they act exactly like any other bitmap font.

Ethin wrote:
so they don't overlap or make other weird visual things that are unreadable. Even if I read the TTF font data manually, I imagine I'll still run into this problem. Can someone explain precisely how this exactly works?
In theory, it is simple. First, you have to parse TTF font data and decode it into outlines, metrics and kerning information. Then you have to use those to rasterize a bitmap, and finally you can blit that bitmap to the screen. (Outlines define how each character should look like, metrics are the dimensions of the bitmap and pen adjustments, and kerning pairs are the relative distance between character combinations.)

But in practice, doing this correctly is EXTREMELY hard. The popular freetype2 library, which has been developed for decades, can't do it right. Also read FontForge's documentation, they are ranting pages over pages how incompatible MS and Apple fonts are, there's no standardized way to get all chunks from a TTF font reliably (specially when it comes to ligatures and character mappings). Then there's the problem of the hinting bytecode, you'll need to implement a virtual machine operating on geometrical data to interpret them. Here again, most fonts have bad, wrong or incorrect hinting bytecode, so you'll have to write that vm bullet-proof (tools that can create good hinting bytecode are patented and very expensive). Long story short, you don't want TTF, it s*cks big time, many very very experienced developers can't get it right for decades.

Cheers,
bzt


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], DotBot [Bot], Google [Bot] and 120 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group