Skip to content

Refactoring to support double sized rendering

Stephen Denne edited this page Sep 25, 2021 · 3 revisions

Double Sized Character Rendering

Notes from the developer, 2021-09-25:

I've started the work to better integrate double sized printing, and thought I'd record the process here (for anyone who is interested):

In order to try and keep program memory size to an absolute minimum, not including functions that are not needed, I had used function pointers to select whether the older ascii decoding or the newer utf-8 decoding functions is required.

The setFont and setUnicodeFont functions are where the references to the actual implementations are recorded.

As I extend this to support both double sized, and double sized smoothed display of the characters, I've been refactoring the code to separate functions that decode ascii or utf-8 character, from functions that render the selected character.

I'm adding new font selection methods, such as setFontX2 or setUnicodeFontX2Smooth to bring together the relevant implementations of decoders and renderers, and keeping the references to methods down to only those needed.

While this is working well, I've discovered complexities due to how I implemented both the proportional fonts support with the width of each character changing, and secondly with utf-8 support where I switch between older-style fonts that include the requested letter, but where I treat newlines and spaces separately.

The unicode fonts are implemented as a collection of older style fonts, each covering a contiguous range of characters. In order to not always have to switch to a font that contains the space character, the utf-8 decoding function, which selects the relevant font, includes code to render spaces instead of switching between fonts.

If I'm rendering double size, then character widths double, space characters and newlines need to be twice as big too.

I suspect it'll be smaller and simpler to store a size multiplier (only supporting 1 and 2), always used, rather than more function pointers to render spaces, get character widths, etc.

Speaking of those character width functions... getCharacterWidth and getTextWidth and the like - outside of the internal library usage, they don't currently work for utf-8 characters and unicode fonts.

Clone this wiki locally