"Font Quality" Patch

83 views
Skip to first unread message

Florian Balmer

unread,
Oct 16, 2009, 7:57:12 AM10/16/09
to scintilla-interest
Hello all

As a follow-up to this discussion [1], I have created a patch (posted
directly to Neil) to add a new "Font Quality" setting, to control
whether or not to enable font anti-aliasing (smoothing) through a
SCI_SETFONTQUALITY message. The rationale is that there's Windows
fonts to look good either only with or without anti-aliasing (this may
be the same on other platforms).

[1] : http://groups.google.com/group/scintilla-tracker/browse_thread/thread/e51ec92de39c9975/d6a1c75486efa692?lnk=gst

The `extraFontFlag' has been hijacked and redefined from `bool' to
`int', that's why the patch also affects the Cocoa and MacOSX
platforms (but the `extraFontFlag' is unused there, to date). The
first byte of `extraFontFlag' has been reserved for the new font
quality setting, leaving room for other uses on non-Windows platforms.
The default behaviour has not been changed, of course.

The Windows implementation introduces several possibilities, from no
anti-aliasing at all, to Win9x and ClearType anti-aliasing. It was
more complicated than I expected, mostly because of font hashing being
affected on Windows. The following details deserve special
consideration:

* Where to put #defines required in both Scintilla.h and PlatWin.cxx,
such as the new font quality options?

* Not sure if the `#if (_WIN32_WINNT >= _WIN32_WINNT_WINXP)' should be
dropped, making the Scintilla client responsible to specify only
options supported by the OS. Some options may fail due to user
settings (disabled font smoothing), anyway. And I think there's a
reasonable fallback in the Win32 font management functions, already.

* There's other spots in PlatWin.cxx to create fonts, their
LOGFONT::lfQuality setting is currently not changed. This should
probably go into the documentation?

* Please check my modifications to font hashing, they may not be
adequate.

--Florian

Neil Hodgson

unread,
Oct 18, 2009, 9:06:31 AM10/18/09
to scintilla...@googlegroups.com
Florian Balmer:

> As a follow-up to this discussion [1], I have created a patch (posted
> directly to Neil) to add a new "Font Quality" setting, to control
> whether or not to enable font anti-aliasing (smoothing) through a
> SCI_SETFONTQUALITY message. The rationale is that there's Windows
> fonts to look good either only with or without anti-aliasing (this may
> be the same on other platforms).

A single setting (per Scintilla instance) doesn't really fix the
original problem which is that particular fonts should have their
quality tweaked. Editors that only use a single font for all text will
be fine with a single setting, but when multiple fonts are used then
this would be better modeled as a per-style setting. This would be a
larger change and I don't know whether it is worth the effort.

> * Where to put #defines required in both Scintilla.h and PlatWin.cxx,
> such as the new font quality options?

If they are are attempting to provide a cross-platform enumeration
then two parallel definitions - one in Scintilla.iface and another in
a new header in the src directory. If they are trying to pass through
platform-specific values then no definitions anywhere.

> * Not sure if the `#if (_WIN32_WINNT >= _WIN32_WINNT_WINXP)' should be
> dropped, making the Scintilla client responsible to specify only
> options supported by the OS.

Probably be simplest as a more limited set of cross-platform
states. Just the minimum needed to meet current needs, with DEFAULT,
ANTIALIASED, and LCD_OPTIMIZED with these mapped to the particular
platform values.

> * There's other spots in PlatWin.cxx to create fonts, their
> LOGFONT::lfQuality setting is currently not changed. This should
> probably go into the documentation?

All of these should be copying from an existing font. There may be
minor issues if you change the setting while, for example, a list box
is on the screen.

> * Please check my modifications to font hashing, they may not be
> adequate.

Since hashes may collide the only issue would be additional clashes
if fonts differed just in their quality. Unlikely with a single
setting (I suppose there could be two windows one aliased and one not)
and not a big problem.

Neil

Florian Balmer

unread,
Oct 19, 2009, 2:00:53 PM10/19/09
to scintilla-interest
Neil Hodgson:

>    A single setting (per Scintilla instance) doesn't really fix the
> original problem which is that particular fonts should have their
> quality tweaked. Editors that only use a single font for all text will
> be fine with a single setting, but when multiple fonts are used then
> this would be better modeled as a per-style setting. This would be a
> larger change and I don't know whether it is worth the effort.

That's true, the original problem still exists. The Scintilla client
or user will have to choose a set of fonts that looks harmonic either
with or without anti-aliasing. However, there's a little more control
over which set to choose.

>    Probably be simplest as a more limited set of cross-platform
> states. Just the minimum needed to meet current needs, with DEFAULT,
> ANTIALIASED, and LCD_OPTIMIZED with these mapped to the particular
> platform values.

And also NONANTIALIASED?

Thanks for your additional explanations about the header files and
interfaces. I will do the changes you suggested, and send you a
corrected patch (it may take a while).

--Florian

Neil Hodgson

unread,
Oct 19, 2009, 8:24:46 PM10/19/09
to scintilla...@googlegroups.com
Florian Balmer:

> That's true, the original problem still exists. The Scintilla client
> or user will have to choose a set of fonts that looks harmonic either
> with or without anti-aliasing. However, there's a little more control
> over which set to choose.

ClearType isn't just anti-aliasing - it is LCD optimized
anti-aliasing and should not be turned on for CRTs.
http://en.wikipedia.org/wiki/Cleartype

I don't think it is sensible to include options no one understands.
From Microsoft's Internationalization guy Michael Kaplan
http://blogs.msdn.com/michkap/archive/2006/10/22/854820.aspx:
"""Yes, there is that extra CLEARTYPE_NATURAL_QUALITY constant which
is defined in the header file and documented all over creation except
on MSDN right now. Good luck trying to determine what it means. :-)
"""

>>    Probably be simplest as a more limited set of cross-platform
>> states. Just the minimum needed to meet current needs, with DEFAULT,
>> ANTIALIASED, and LCD_OPTIMIZED with these mapped to the particular
>> platform values.
>
> And also NONANTIALIASED?

I don't think anyone has asked for that. The wxSTC use case seems
to be that there were problems with anti-aliasing so the default on
the Mac (extraFontFlag = false) is no aliasing and on other platforms
it is true -> anti-aliased. So that is equivalent to DEFAULT=0,
ANTIALIASED=1. For Windows now we want a default and a force cleartype
(equivalent to LCD optimization on other platforms) so that fits with
DEFAULT=0, LCD_OPTIMIZED=2.

I suppose we could try to remove the '!' Pango prefix on GTK+ which
could be done with the choices DEFAULT=0, NONANTIALIASED=3 although
that could also be implemented by having vs.extraFontFlag be
ANTIALIASED by default similar to the way each platform has its own
preferred default font name. Since the '!' prefix would have to stay
for a long deprecation period, it doesn't seem like a big win.

Neil

Florian Balmer

unread,
Oct 24, 2009, 11:06:53 AM10/24/09
to scintilla-interest
I have posted a corrected "Font Quality" patch. Definitions have been
moved to a new header file, and to Scintilla.iface.

I've dropped support for CLEARTYPE_NATURAL_QUALITY. This was meant to
be a future-proof implementation ;-)

> > And also NONANTIALIASED?
>    I don't think anyone has asked for that.

I've had some requests by Notepad2 users to add an option to disable
anti-aliasing, that's why I have included it. Please feel free to drop
it if you don't like it.

--Florian

Neil Hodgson

unread,
Nov 1, 2009, 11:59:34 PM11/1/09
to scintilla...@googlegroups.com
Florian Balmer:

> As a follow-up to this discussion [1], I have created a patch (posted
> directly to Neil) to add a new "Font Quality" setting, to control
> whether or not to enable font anti-aliasing (smoothing) through a
> SCI_SETFONTQUALITY message.

This is now committed. The value of SC_EFF_QUALITY_LCD_OPTIMIZED is
now 3 rather than 4 since these can not be used as bit flags.

Maintainers of other platforms will have to make some changes to
allow extraFontFlag to be an int and may want to make other changes to
implement different quality levels. Each quality level is advisory and
a platform may choose to treat all quality levels as default. Only 4
bits of the extraFontFlag are used for quality level so these should
be masked off so that other bits can be used for other features in the
future.

Neil

Florian Balmer

unread,
Nov 2, 2009, 3:20:36 PM11/2/09
to scintilla-interest
>    This is now committed. The value of SC_EFF_QUALITY_LCD_OPTIMIZED is
> now 3 rather than 4 since these can not be used as bit flags.

Thank you very much for your additional work on this.

--Florian
Reply all
Reply to author
Forward
0 new messages