[cairo-bugs] [Bug 33178] Suggestions for cleaning HFONT handling
bugzilla-daemon at freedesktop.org
bugzilla-daemon at freedesktop.org
Mon Jan 17 13:59:42 PST 2011
https://bugs.freedesktop.org/show_bug.cgi?id=33178
--- Comment #5 from Andrea Canciani <ranma42 at gmail.com> 2011-01-17 13:59:41 PST ---
(In reply to comment #4)
> (In reply to comment #1)
> > We can improve the documentation to make it clear that the application needs to
> > unselect the font (either by selecting another font or with RestoreDC) before
> > calling cairo_win32_scaled_font_done_font() and then destroying the font.
> >
> > I'm not sure why cairo_win32_scaled_font_select_font() doesn't keep a reference
> > to the scaled font until cairo_win32_scaled_font_done_font() is called.
>
> I was thinking about this, too. If we assume that the DC can only be
> interacted with from a single thread, then retaining the
> previously-selected-font internally would allow us to properly select the old
> font back into the context when done_font was called.
These function allow you to:
cairo_scaled_font_t *scaled_font;
HDC hdc1, hdc2;
/* init everything */
/* I shoud really SaveDC here */
cairo_win32_scaled_font_select_font (scaled_font, hdc1);
cairo_win32_scaled_font_select_font (scaled_font, hdc2);
draw_on (hdc1);
cairo_win32_scaled_font_done_font (scaled_font);
/*
I can restore hdc1 here, but not hdc2.
How does done_font know about this?
*/
/* Restore *MUST* happen before destroying hdc1 */
destroy(hdc1);
draw_on (hdc2);
cairo_win32_scaled_font_done_font (scaled_font);
/* Restoring here would be safe in this case, but we would never restore */
How would you handle this case?
>
> I think this would be clearer than SaveDC/RestoreDC around the calls, just in
> case some kind of drawing/scaling or other transformations need to be
> interleaved with font handling.
It would be clearer, but it would require an API change (it would only be
possible if done_font accepted the HDC as input). I guess we can just fix
the incorrect select_font/done_font pairs in cairo and improve documentation
tom make the need to SaveDC/RestoreDC explicit.
--
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