Monospace optimization

13 views
Skip to first unread message

Neil Hodgson

unread,
Jul 31, 2021, 1:03:56 AM7/31/21
to Scintilla mailing list
When fonts are monospaced, layout can be simplified for restricted sets of characters. Choosing a monospaced font does not, in general, result in all characters being the same width. Often, Arabic, Chinese, and Emoji characters are wider than Roman characters.

The ASCII graphics characters ‘ ‘ - ‘~’, including the Roman upper and lower case letters, digits and most of the punctuation used in programming and markup languages, are often uniformly spaced.

The SCI_STYLESETCHECKMONOSPACED API can be used to ask for Scintilla to check whether the font with attributes (bold, italic, …) of a style appears to be monospaced. If the check passes, layout speed and memory use is optimized. Only the ASCII graphical characters are tested and only runs exclusively in those characters are optimized. This is mostly useful for huge data files like SQL dumps or XML which often use ASCII for structure as well as a proportion of data.

The speed up on actions like wrapping is often around 6x on Win32 using DirectWrite.

SciTE uses a semi-colon separated list of font names to enable this:
font.monospaced.list=Noto Mono;Menlo;Lucida Console
Applications may choose different criteria such as setting every style as ‘check monospaced’ thus trusting Scintilla's checks.

The checks currently consist of a text example containing each ASCII graphics character and a likely kerning pair “Ay” and ligature “fi”. If any character width deviates by a factor of more than 0.000001 from the average then it is deemed proportional. More checks could be added if they distinguish cases and the deviation factor could be increased or decreased if that helps some situations.

Available from the repositories
hg clone http://hg.code.sf.net/p/scintilla/code scintilla
hg clone http://hg.code.sf.net/p/scintilla/scite

Neil
Reply all
Reply to author
Forward
0 new messages