Question

How to draw a text using barebones X11 connection over a socket?

I connect to x11 server via socket and handle the protocol manually. I do not use Xlib or XCB, leave alone Qt, GTK or even Freetype. I have one unresolved issue, I cannot draw fonts other than ancient bitmap fonts. I would like to draw something like FreeSans or other Unicode enabled fonts with LCD sub-pixel rendering, but using only built-in x11 functionality. Probably using some x11-extension. But which one? What function to use? How to select a font, locally or on server? Can X11 render the font for me using the provided style information, including color, background color, font name, size and decoration?

Was it helpful?

Solution

No, X does not render fonts for you, but it can render sequences of anti-aliased pixmap "Glyphs". If you only want to use core X protocol, you'll have to render everything client-side (most libraries do this anyway, usually with cairo library).

What I suggest to try: 1) pre-render all glyphs for your font locally using FreeType; 2) Upload fonts with CreateGlyphSet Xrender request; 3) Draw you string with CompositeGlyphs8/16/32 request. Read section 12 - "Glyph Rendering" of XRender documentation. Each glyph has its own offset value, however there is no way to define kerning pairs.

You'll have to handle other complexities as well (right-to left, vertical, etc). It's a very complex task to do 100% correct, but sans edge cases is doable for sure and a good educational project.

You can look at example of raw socket + xrender communication in my javascript x client library: https://github.com/sidorares/node-x11

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top