Bug 24862 - setting font fails to retain the font and later fail
Summary: setting font fails to retain the font and later fail
Status: RESOLVED FIXED
Alias: None
Product: cairo
Classification: Unclassified
Component: quartz font backend (show other bugs)
Version: 1.9.1
Hardware: x86 (IA32) Mac OS X (All)
: medium normal
Assignee: Vladimir Vukicevic
QA Contact: cairo-bugs mailing list
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-11-02 14:03 UTC by Pierre Baillargeon
Modified: 2016-05-29 17:46 UTC (History)
3 users (show)

See Also:
i915 platform:
i915 features:


Attachments
Test case reproducing the bug on MacOSX / Quartz (1.11 KB, text/plain)
2009-11-16 12:11 UTC, Pierre Baillargeon
Details
C code reproducing teh bug on MacOSX 10.5.8 with Quartz font backend (1.37 KB, text/plain)
2009-11-17 07:58 UTC, Pierre Baillargeon
Details

Description Pierre Baillargeon 2009-11-02 14:03:44 UTC
In the Python binding, when one does something like:

    cr.select_font_face("Georgia",
                cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD)
    cr.set_font_size(1.2)

The font reference is not increased. Later when one renders, on MacOSX 10.5.8 with Quartz back-end at least, Cairo crashes. If one fixes Cairo to check for null font_face in a few place in the Quartz implementaton, it no longer crashes but of cpourse the rendering fails (in my fix I returned a memory error so I get a Python MemoryError exception).

One *has* to call get_font_face() in order to make teh render works. This is annoying. Could not the context retain the font?

The tutorial about Cairo foun don the main Cairo site (http://www.cairographics.org/documentation/ ->http://www.tortall.net/mu/wiki/CairoTutorial) points to example python code that has this flaw.
Comment 1 Steve Chaplin 2009-11-16 04:34:04 UTC
A small test case would be useful.
Its not clear to me if you are describing a pycairo problem, a cairo problem, or a cairo/quartz problem (there is no pycairo/Quartz implementation).

Why should the font reference be increased. The functions
cairo_select_font_face and cairo_set_font_size do not even return a cairo_font_face_t which you would need to call cairo_font_face_reference.
Comment 2 Pierre Baillargeon 2009-11-16 07:38:10 UTC
You are correct, this is a cairo problem, not a pycairo problem. The test case is the tutorial I pointed to in the original bug report. It's a pycairo tutorial and it crashes on MacOSX / Quartz. I must have assumed the cairo and pycairo teams were closer than they really are.


> From: bugzilla-daemon@freedesktop.org
> To: pierrebai@hotmail.com
> Subject: [Bug 24862] setting font fails to retain the font and later fail
> Date: Mon, 16 Nov 2009 04:34:04 -0800
> 
> http://bugs.freedesktop.org/show_bug.cgi?id=24862
> 
> --- Comment #1 from Steve Chaplin <stevech1097@yahoo.com.au>  2009-11-16 04:34:04 PST ---
> A small test case would be useful.
> Its not clear to me if you are describing a pycairo problem, a cairo problem,
> or a cairo/quartz problem (there is no pycairo/Quartz implementation).
> 
> Why should the font reference be increased. The functions
> cairo_select_font_face and cairo_set_font_size do not even return a
> cairo_font_face_t which you would need to call cairo_font_face_reference.
> 
> 
> -- 
> Configure bugmail: http://bugs.freedesktop.org/userprefs.cgi?tab=email
> ------- You are receiving this mail because: -------
> You reported the bug.
 		 	   		  
_________________________________________________________________
Windows Live : vos amis voient plus facilement ce que vous faites sur Facebook.
http://go.microsoft.com/?linkid=9691826
Comment 3 Pierre Baillargeon 2009-11-16 12:07:26 UTC
BTW, the original "fix" I did was to add:
  {     cairo_font_face_t* ff = cairo_get_font_face (o->ctx);     if (ff)        cairo_font_face_reference (ff);  }
Around line 826 of pycairo_select_font_face(). This avoids the crash but permanently hold the font in memory, I think. It is unfortunate that the Cairo API forces one to explicitly add that code when using a font in pycairo. (i.e, after each select_font_face(), one has to get_font_face() and add a reference to it.
Here's a small pycairo program that reproduce the bug:
#! /usr/bin/env pythonimport cairo
class Diagram(object):    def __init__(self, filename, width, height):        self.surface = cairo.SVGSurface(filename + '.svg', width, height)        cr = self.cr = cairo.Context(self.surface)        cr.scale(width, height)        # Note: bug doesn't show up if no save/restore.        cr.save()        self.draw_dest(self.cr)        cr.restore()        cr.show_page()        self.surface.finish()
    def draw_dest(self, cr):        cr.set_source_rgb(1, 1, 1)        cr.rectangle(0, 0, 1, 1)        cr.fill()
class BugText(Diagram):    def draw_dest(self, cr):        Diagram.draw_dest(self, cr)        cr.set_source_rgb(0.0, 0.0, 0.0)        cr.select_font_face("Arial",                cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD)        cr.set_font_size(1.2)        # Uncomment to fix bug!        #self.ff = cr.get_font_face()        x_bearing, y_bearing, width, height = cr.text_extents("a")[:4]        cr.move_to(0.5 - width / 2 - x_bearing, 0.5 - height / 2 - y_bearing)        cr.show_text("a")
if __name__ == '__main__':    BugText('showtext', 300, 200)

--
Pierre


 		 	   		  
_________________________________________________________________
Windows Live : vos amis reçoivent vos nouveautés Facebook, Twitter et MySpace lorsqu'ils vous envoient un message électronique.
http://go.microsoft.com/?linkid=9691827
Comment 4 Pierre Baillargeon 2009-11-16 12:11:12 UTC
Created attachment 31240 [details]
Test case reproducing the bug on MacOSX / Quartz
Comment 5 Steve Chaplin 2009-11-16 20:23:53 UTC
Move from pycairo to cairo bug list.
Comment 6 Steve Chaplin 2009-11-16 20:26:08 UTC
Reassign.
Comment 7 Behdad Esfahbod 2009-11-16 20:33:54 UTC
This doesn't make any sense.  A simple C test case is appreciated.
Comment 8 Pierre Baillargeon 2009-11-17 07:58:26 UTC
Created attachment 31259 [details]
C code reproducing teh bug on MacOSX 10.5.8 with Quartz font backend

This is a translation of the Python code in C. It crashes with a bus error on MacOSX 10.5.8 because the font is freed when the rendering is done. Adding an explicit reference to teh font by hand avoids the problem, but it should not be needed, I believe.
Comment 9 Jeremy Huddleston Sequoia 2016-05-29 17:46:22 UTC
This looks to have been fixed at some point.  I'm not able to reproduce the crash on OS X 10.11 with cairo 1.14.6


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.