[cairo] Pango cairo target surface size

Bryce Harrington bryce at osg.samsung.com
Tue Mar 24 10:58:40 PDT 2015


On Tue, Mar 24, 2015 at 10:41:40AM +0800, Rob Kramer wrote:
> 
> On 03/23/2015 11:43 AM, Lawrence D'Oliveiro wrote:
> >On Mon, 23 Mar 2015 11:29:51 +0800, Rob Kramer wrote:
> >
> >>On 03/23/2015 11:20 AM, Lawrence D'Oliveiro wrote:
> >>
> >>
> >>>That’s easy. You can create an ImageSurface with 0 width and 0
> >>>height, put a cairo_t on top of that, and do your text measurements
> >>>without any drawing taking place.
> >>But how does that result in an image surface equal to the extents of
> >>the string?
> >You use it to measure the text_extents with cairo_text_extents or
> >cairo_glyph_extents
> ><http://cairographics.org/manual/cairo-text.html#cairo-text-extents>.
> 
> Ah, I think you misunderstood my question.. If all I wanted was to
> calculate extents, I could use plain Pango too.
> 
> What I want to do is paint a string to a surface the same size as
> the text's logical extents -- without doing the text layouting twice
> (once to calculate the extents, once to paint). Since I cannot
> change the target image size after it is set, or import an existing
> Pango layout into Cairo, I wondered whether anyone on this list
> would know of a method.

Can you just use masking?  Do your text extents layout and render on
surface A, create a same sized surface B as your target, then use
surface A as a mask onto B.

Bryce


More information about the cairo mailing list