[cairo-bugs] [Bug 94836] New: Wrong text size when using HFONT with appropriate size

bugzilla-daemon at freedesktop.org bugzilla-daemon at freedesktop.org
Wed Apr 6 08:23:41 UTC 2016


https://bugs.freedesktop.org/show_bug.cgi?id=94836

            Bug ID: 94836
           Summary: Wrong text size when using HFONT with appropriate size
           Product: cairo
           Version: 1.12.14
          Hardware: All
                OS: Windows (All)
            Status: NEW
          Severity: major
          Priority: medium
         Component: win32 backend
          Assignee: cairo-bugs at cairographics.org
          Reporter: fredbca21 at gmail.com
        QA Contact: cairo-bugs at cairographics.org

I have noticed a bug in the win32 font backend. When setting the font on a
win32 surface with the code below and using the same size as the original HFONT
for drawing, the resulting font size is extremely small (text is almost
invisible).

// assuming my_hfont was created with -12 for LOGFONT.lfHeight
cairo_font_face_t* font_face=cairo_win32_font_face_create_for_hfont(my_hfont);
cairo_set_font_face(ctx,font_face);
cairo_set_font_size(ctx,12);

The reason is that in _cairo_win32_font_face_scaled_font_create, the font
matrix is checked against -font_face->logfont.lfHeight whereas if you look in
_win32_scaled_font_get_scaled_hfont, the expected height should be multiplied
by WIN32_FONT_LOGICAL_SCALE (scaled HFONT created by cairo uses
logfont.lfHeight = -scaled_font->logical_size)

This means that using anything else than 1 for WIN32_FONT_LOGICAL_SCALE will
result in a downscaled font when using a HFONT that was created with the right
size.

However, if the check mentioned above is fixed, in order to have cairo use the
original HFONT, it should be created with a much larger size
(-WIN32_FONT_LOGICAL_SCALE*size). So this defeats the purpose of being able to
mix native win32 fonts with cairo because of this scaling factor (mixing native
and cairo code would require extra scaling everywhere).

After reading older discussions about the WIN32_FONT_LOGICAL_SCALE factor, it
seems to me that the actual problem lies in the fact that the win32 backend
uses fonts that are expected to be created with the logical scale, instead of
using fonts with the appropriate size and applying the logical scale to the
World Transform only.

See scaled font creation here:
static cairo_status_t
_win32_scaled_font_get_scaled_hfont (cairo_win32_scaled_font_t *scaled_font,
    HFONT *hfont_out)
{
    if (!scaled_font->scaled_hfont) {
LOGFONTW logfont = scaled_font->logfont;
logfont.lfHeight = -scaled_font->logical_size; // using the logical
size to create the font - why not use the actual size and scale in the world
transform?

-- 
You are receiving this mail because:
You are the assignee for the bug.
You are the QA Contact for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.cairographics.org/archives/cairo-bugs/attachments/20160406/8f9ae6d7/attachment.html>


More information about the cairo-bugs mailing list