Writing an OS Kernel from Scratch – Part 31: Paint Tool and Text Rendering — Writing Text in Your Windows!

“A graphical interface can’t just be pixels — it needs text! Today, we implement a paint tool and integrate a text rendering engine so title bars, status bars, and canvas can all display text!”

In previous posts, we built a complete graphics stack:
✅ Framebuffer driver
✅ Display Server + Client architecture
✅ Window manager (keyboard/mouse support)

But everything was pure pixel drawing — window titles were hardcoded strings, and the paint tool couldn’t add text annotations.

A real graphics system needs text rendering capability!

Today we:
✅ Implement a bitmap font rendering engine
✅ Develop a Paint tool application
✅ Display dynamic text in title bars/status bars
✅ Support adding text layers on canvas


Bitmap Fonts: The Simplest Text Rendering Solution

Why bitmap fonts?

  • Simple: no complex font parsing (like TrueType)
  • Efficient: direct memory copy, no floating point
  • Compact: 8×16 font only needs 128 bytes/character

Font format (8×16 monospace):

  • ASCII 32-126 (printable characters)
  • 16 bytes per character (1 byte per row, 8 pixels)
  • 1 = pixel on, 0 = pixel off

Linux kernel’s built-in font uses the same format!


Text Rendering Engine

  1. Draw single character
  2. Draw string
  3. Measure string width

All drawing functions operate on Framebuffer direct memory!

Last modified: 2025年5月1日

Author

Comments

Write a Reply or Comment

Your email address will not be published.