[cairo-bugs] [Bug 33178] New: Suggestions for cleaning HFONT handling

bugzilla-daemon at freedesktop.org bugzilla-daemon at freedesktop.org
Sat Jan 15 23:09:02 PST 2011


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

           Summary: Suggestions for cleaning HFONT handling
           Product: cairo
           Version: 1.10.2
          Platform: Other
        OS/Version: Windows (All)
            Status: NEW
          Severity: normal
          Priority: medium
         Component: win32 backend
        AssignedTo: cairo-bugs at cairographics.org
        ReportedBy: bfulgham at webkit.org
         QAContact: cairo-bugs at cairographics.org


Created an attachment (id=42096)
 --> (https://bugs.freedesktop.org/attachment.cgi?id=42096)
A suggestion for cleaning up HFONT lifetime and handling

I encountered a number of error messages from BoundsChecker under the test
suite.

_cairo_win32_scaled_font_fini (void *abstract_font) attempts to delete the
scaled_hfont object, but this HFONT is still selected into an active device
context.

The cause of this specific error is that the
cairo_win32_scaled_font_select_font function calls SelectObject to bring the
passed font into active use for the device context.  SelectObject returns the
previously selected font (often a stock font).  While this may be handled in
many cases by performing a SaveDC/RestoreDC around these operations, it doesn't
seem like this is generally done in the test suite.

Later, when the program is finished with the scaled font, a call to
cairo_win32_scaled_font_done_font.  However, this operation does not remove the
font from any active device contexts into which it had been selected. 
Consequently, the later destruction of the font (when the font cache goes out
of scope) can generate errors.

I would propose the following:

1. Have the cairo_win32_scaled_font_select_font incorporate a new out parameter
to hold the previously-selected font for the passed device context.
2. Have the cairo_win32_scaled_font_done_font take two new parameters: (a) the
device context that the scaled_font is currently selected into, and the
original font (now passed back as an out parameter from (1).

The attached patch implements these changes.

The various test cases were easy to modify to handle these changes.  However,
I'm not sure how external programs using the win32 Cairo routines would be
impacted by this change.  From a pragmatic standpoint, the additional terms
could be allowed to be 'null', and revert to original behavior in those cases.

-- 
Configure bugmail: https://bugs.freedesktop.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the cairo-bugs mailing list