Discussion:
Text antialiasing.
(too old to reply)
David Webber
2012-08-13 13:35:36 UTC
Permalink
Any ideas, anyone, about what might prevent text antialiasing?

In an MDI application, I am creating fonts with CFont::CreateFontIndirect
from LOGFONTs with

logfont.lfQuality = ANTIALIASED_QUALITY;

I am selecting the fonts in turn into the CDC in the CMyView::OnDraw
member, and outputting the text with CDC::TextOut().

The heights, weights, and faces all look like what I'd expect, and the
colours chosen with CDC::SetTextColor() are fine.

But I'm not getting antialiasing!

Have I missed something? [Other MDI programs I've written don't have this
problem, but I can't remember what I might have done differently.]

Dave

-- David Webber
Mozart Music Software
http://www.mozart.co.uk
For discussion and support see
http://www.mozart.co.uk/mozartists/mailinglist.htm
David Lowndes
2012-08-13 14:05:28 UTC
Permalink
Post by David Webber
logfont.lfQuality = ANTIALIASED_QUALITY;
What else are you setting in the LOGFONT?
Perhaps some other attribute is preventing your expected choice?

Dave
David Webber
2012-08-13 15:05:54 UTC
Permalink
Post by David Lowndes
What else are you setting in the LOGFONT?
Perhaps some other attribute is preventing your expected choice?
I don't *think* there's anything amiss:

LOGFONTW logfont;

// Normal font:

int nHeight = HEIGHT_NORMAL[device]; // In points.

logfont.lfHeight = nHeight * nDpiY / 72; // In pixels
logfont.lfWidth = 0;
logfont.lfEscapement = 0;
logfont.lfOrientation = 0;
logfont.lfWeight = FW_NORMAL;
logfont.lfItalic = 0;
logfont.lfUnderline = 0;
logfont.lfStrikeOut = 0;
logfont.lfCharSet = DEFAULT_CHARSET;
logfont.lfOutPrecision = OUT_TT_PRECIS;
logfont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
logfont.lfQuality = ANTIALIASED_QUALITY;
logfont.lfPitchAndFamily = VARIABLE_PITCH|FF_SWISS;
wcscpy( logfont.lfFaceName, FONTFACE[device] );


with constants in the header:

const CStringW FONTFACE[2] = { L"Tahoma", L"Calibri" };
const int HEIGHT_NORMAL[2] = { 12, 12 }; // Text height in
points

nDpiY is dots per inch. I'm using array arguments 0 for screen, and 1 for
printer.

Dave

-- David Webber
Mozart Music Software
http://www.mozart.co.uk
For discussion and support see
http://www.mozart.co.uk/mozartists/mailinglist.htm
David Lowndes
2012-08-13 16:17:23 UTC
Permalink
Post by David Webber
Post by David Lowndes
What else are you setting in the LOGFONT?
Perhaps some other attribute is preventing your expected choice?
logfont.lfOutPrecision = OUT_TT_PRECIS;
logfont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
Try leaving them at 0.
Post by David Webber
logfont.lfQuality = ANTIALIASED_QUALITY;
I'd probably leave the above as the default too - on the grounds that
the user may not want them anti-aliased, but he default will be
anti-aliased by default.
Post by David Webber
logfont.lfPitchAndFamily = VARIABLE_PITCH|FF_SWISS;
wcscpy( logfont.lfFaceName, FONTFACE[device] );
As you're specifying a face name, I'd leave the pitchandfamily as the
default too.

Joe's ChooseFont Explorer tool may help you experiment with the
LOGFONT values. http://www.flounder.com/fontexplorer.htm

Dave
David Webber
2012-08-13 17:39:21 UTC
Permalink
Post by David Webber
logfont.lfOutPrecision = OUT_TT_PRECIS;
logfont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
Try leaving them at 0.
logfont.lfQuality = ANTIALIASED_QUALITY;
I'd probably leave the above as the default too - on the grounds that
the user may not want them anti-aliased, but he default will be
anti-aliased by default.
Post by David Webber
logfont.lfPitchAndFamily = VARIABLE_PITCH|FF_SWISS;
wcscpy( logfont.lfFaceName, FONTFACE[device] );
As you're specifying a face name, I'd leave the pitchandfamily as the
default too.
David, you're a genius.

I changed the parameters to

logfont.lfCharSet = ANSI_CHARSET;
logfont.lfOutPrecision = OUT_DEFAULT_PRECIS;
logfont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
logfont.lfQuality = DEFAULT_QUALITY;
logfont.lfPitchAndFamily = DEFAULT_PITCH|FF_DONTCARE;
wcscpy( logfont.lfFaceName, FONTFACE[device] );

(where all the defined constants are in fact zero) and I'm no getting
antialiased text!

I may have to try reinstating the pitch and family, in case the eventual
user hasn't got the specified face.

The reason I specified so many parameters (and the faces I specified really
are SWISS and VARIABLE PITCH) is that I remember from programming Windows
3.0, that he system prioritises the various fields in a logfont in a weird
order: the facename is not, IIRC, given the highest priority.

And the reason I chose 'Tahoma' for the screen as it looks particularly nice
antialiased at small sizes!

But anyway I have something looking nice now - I'll tweak from there!

Thanks,

Dave

-- David Webber
Mozart Music Software
http://www.mozart.co.uk
For discussion and support see
http://www.mozart.co.uk/mozartists/mailinglist.htm
David Webber
2012-08-13 17:39:21 UTC
Permalink
Post by David Webber
logfont.lfOutPrecision = OUT_TT_PRECIS;
logfont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
Try leaving them at 0.
logfont.lfQuality = ANTIALIASED_QUALITY;
I'd probably leave the above as the default too - on the grounds that
the user may not want them anti-aliased, but he default will be
anti-aliased by default.
Post by David Webber
logfont.lfPitchAndFamily = VARIABLE_PITCH|FF_SWISS;
wcscpy( logfont.lfFaceName, FONTFACE[device] );
As you're specifying a face name, I'd leave the pitchandfamily as the
default too.
David, you're a genius.

I changed the parameters to

logfont.lfCharSet = ANSI_CHARSET;
logfont.lfOutPrecision = OUT_DEFAULT_PRECIS;
logfont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
logfont.lfQuality = DEFAULT_QUALITY;
logfont.lfPitchAndFamily = DEFAULT_PITCH|FF_DONTCARE;
wcscpy( logfont.lfFaceName, FONTFACE[device] );

(where all the defined constants are in fact zero) and I'm no getting
antialiased text!

I may have to try reinstating the pitch and family, in case the eventual
user hasn't got the specified face.

The reason I specified so many parameters (and the faces I specified really
are SWISS and VARIABLE PITCH) is that I remember from programming Windows
3.0, that he system prioritises the various fields in a logfont in a weird
order: the facename is not, IIRC, given the highest priority.

And the reason I chose 'Tahoma' for the screen as it looks particularly nice
antialiased at small sizes!

But anyway I have something looking nice now - I'll tweak from there!

Thanks,

Dave

-- David Webber
Mozart Music Software
http://www.mozart.co.uk
For discussion and support see
http://www.mozart.co.uk/mozartists/mailinglist.htm

Continue reading on narkive:
Loading...