Discussion:
[ft] Freetype / Microsoft GDI size mismatch
Steffen R
2010-02-26 09:57:22 UTC
Permalink
Hi everyone,

I'm not sure if this is the correct forum for me to post, but I certainly
won't get much help from Microsoft for this ;-)

My problem is as follows: I have an application that uses MS GDI font
rendering, which shall be replaced by freetype while still keeping the
option to use GDI. Thus, layouting must be as close to the old version as
possible.
When I use freetype to render a text in a given size, the results look
pretty much the same as in programs such as Word or WordPad, so obviously
that is correct.
When I use GDIs functions, the results look much smaller. For GDI, the fonts
are created with a LOGFONT struct:

LOGFONT lf = {0};
lf.lfHeight = m_pointSize;
// other values...
HFONT hFont = ::CreateFontIndirect(&lf);
HDC dc = CreateCompatibleDC(NULL);
::SelectObject(dc, hFont);
::DrawTextW(dc, text, -1, rectangle, formatFlags);

The results look noticably smaller rendered with this code. I don't find
many hints for the reason apart from the logical vs. physical resolution
issue, but that does not solve it entirely. For example, with a given size
of 19, multiplication with 72 and division by 96 yields 14.25 as a font
size. Using a pixel ruler on my screen shows 12 or at most 13 pixels when
rendered with GDI, which makes a big difference in my application.

Does anyone know the reason for this? Any hints are highly appreciated.

Regards,
Steffen
--
View this message in context: http://old.nabble.com/Freetype---Microsoft-GDI-size-mismatch-tp27716380p27716380.html
Sent from the Freetype - User mailing list archive at Nabble.com.
Werner LEMBERG
2010-02-26 16:35:04 UTC
Permalink
[Greetings from Koblenz too :-)]
When I use GDIs functions, the results look much smaller. [...]
I can't give direct help since I don't use Windows. However, at such
small sizes it is possible that TrueType hinting changes the font size
considerably. Are you using FreeType with enabled bytecode
interpreter?


Werner
Steffen R
2010-02-26 22:43:26 UTC
Permalink
Hi Werner,
thanks for the advice. I think I have hinting enabled, but I'm not quite
sure and won't have the source available until Monday. I'l check that asap.
Greetings (not from Koblenz anymore, unfortunately - it's Nuremberg now)
Steffen
Post by Werner LEMBERG
[Greetings from Koblenz too :-)]
When I use GDIs functions, the results look much smaller. [...]
I can't give direct help since I don't use Windows. However, at such
small sizes it is possible that TrueType hinting changes the font size
considerably. Are you using FreeType with enabled bytecode
interpreter?
Werner
_______________________________________________
Freetype mailing list
http://lists.nongnu.org/mailman/listinfo/freetype
--
View this message in context: http://old.nabble.com/Freetype---Microsoft-GDI-size-mismatch-tp27716380p27724262.html
Sent from the Freetype - User mailing list archive at Nabble.com.
Tor Andersson
2010-02-27 23:39:02 UTC
Permalink
Steffen,
Post by Steffen R
LOGFONT lf = {0};
lf.lfHeight = m_pointSize;
// other values...
HFONT hFont = ::CreateFontIndirect(&lf);
HDC dc = CreateCompatibleDC(NULL);
::SelectObject(dc, hFont);
::DrawTextW(dc, text, -1, rectangle, formatFlags);
The results look noticably smaller rendered with this code. I don't find
many hints for the reason apart from the logical vs. physical resolution
issue, but that does not solve it entirely. For example, with a given size
of 19, multiplication with 72 and division by 96 yields 14.25 as a font
size. Using a pixel ruler on my screen shows 12 or at most 13 pixels when
rendered with GDI, which makes a big difference in my application.
Does anyone know the reason for this? Any hints are highly appreciated.
The MSDN docs for LOGFONT state that lfHeight is in device units, so
you're asking for a 19 pixel high font. At the default resolution of windows,
this is equivalent to a point size of 14.25 as you calculated. You didn't
mention which resolution you're passing to freetype.

To get a 19 pixel high font in freetype, call:

FT_Set_Char_Size(face, 19 * 64, 19 * 64, 72, 72).

To get a 14.25 point high font in freetype at 96 dpi, call:

FT_Set_Char_Size(face, 14.25 * 64, 14.25 * 64, 96, 96).

-Tor
Steffen R
2010-02-28 16:42:21 UTC
Permalink
Thank you, Tor,
I tried both of these calls and in every case the results look as I would
have expected. It's the MS GDI renderer that seems to render too small (12 -
13 pt instead of 14.25). I was hoping that someone has encountered the same
problem before and knows an explanation why GDI renders so small. I will
also try to post the problem in some GDI-related forum and post an
explanation here if I find one.
Steffen
Post by Tor Andersson
Steffen,
Post by Steffen R
LOGFONT lf = {0};
lf.lfHeight = m_pointSize;
// other values...
HFONT hFont = ::CreateFontIndirect(&lf);
HDC dc = CreateCompatibleDC(NULL);
::SelectObject(dc, hFont);
::DrawTextW(dc, text, -1, rectangle, formatFlags);
The results look noticably smaller rendered with this code. I don't find
many hints for the reason apart from the logical vs. physical resolution
issue, but that does not solve it entirely. For example, with a given size
of 19, multiplication with 72 and division by 96 yields 14.25 as a font
size. Using a pixel ruler on my screen shows 12 or at most 13 pixels when
rendered with GDI, which makes a big difference in my application.
Does anyone know the reason for this? Any hints are highly appreciated.
The MSDN docs for LOGFONT state that lfHeight is in device units, so
you're asking for a 19 pixel high font. At the default resolution of windows,
this is equivalent to a point size of 14.25 as you calculated. You didn't
mention which resolution you're passing to freetype.
FT_Set_Char_Size(face, 19 * 64, 19 * 64, 72, 72).
FT_Set_Char_Size(face, 14.25 * 64, 14.25 * 64, 96, 96).
-Tor
_______________________________________________
Freetype mailing list
http://lists.nongnu.org/mailman/listinfo/freetype
--
View this message in context: http://old.nabble.com/Freetype---Microsoft-GDI-size-mismatch-tp27716380p27736230.html
Sent from the Freetype - User mailing list archive at Nabble.com.
Steffen R
2010-03-03 18:59:35 UTC
Permalink
I think I might have found the answer. From MSDN "Background on Fonts"
When we refer to a font as being 8-point or 12-point, we're talking about
the height of the font less internal leading. The diacritics on certain
capital letters are considered to occupy the space that normally separates
lines of type. The tmHeight value of the TEXTMETRIC structure thus
actually refers to line spacing rather than the font point size. The point
size can be derived from tmHeight minus tmInternalLeading.
In my example, the font created with a size of 19 had an internal leading of
3. So the actual size was 16, which multiplied by 72 and divided by 96
yields 12, which is actually what I measured on my screen.
Steffen
Hi everyone,
I'm not sure if this is the correct forum for me to post, but I certainly
won't get much help from Microsoft for this ;-)
My problem is as follows: I have an application that uses MS GDI font
rendering, which shall be replaced by freetype while still keeping the
option to use GDI. Thus, layouting must be as close to the old version as
possible.
When I use freetype to render a text in a given size, the results look
pretty much the same as in programs such as Word or WordPad, so obviously
that is correct.
When I use GDIs functions, the results look much smaller. For GDI, the
LOGFONT lf = {0};
lf.lfHeight = m_pointSize;
// other values...
HFONT hFont = ::CreateFontIndirect(&lf);
HDC dc = CreateCompatibleDC(NULL);
::SelectObject(dc, hFont);
::DrawTextW(dc, text, -1, rectangle, formatFlags);
The results look noticably smaller rendered with this code. I don't find
many hints for the reason apart from the logical vs. physical resolution
issue, but that does not solve it entirely. For example, with a given size
of 19, multiplication with 72 and division by 96 yields 14.25 as a font
size. Using a pixel ruler on my screen shows 12 or at most 13 pixels when
rendered with GDI, which makes a big difference in my application.
Does anyone know the reason for this? Any hints are highly appreciated.
Regards,
Steffen
--
View this message in context: http://old.nabble.com/Freetype---Microsoft-GDI-size-mismatch-tp27716380p27772212.html
Sent from the Freetype - User mailing list archive at Nabble.com.
Loading...