Re: Using Cairo and Pango to scroll text on video
Leon Woestenberg <[email protected]>
| Newsgroups | gmane.comp.lib.cairo |
|---|---|
| Message-ID | <CAFKr4p-SY-HeZ-LsscouHtWjpGD4FDSLOXx-DH1K+WP50Dewkg@mail.gmail.com> |
Hello, On Mon, May 7, 2012 at 4:15 PM, <[email protected]> wrote: > >>>Another workaround is to prerender the text to a similar surface > >>>(cairo_surface_create_similar) and paint that intermediate surface to > >>>the destination surface with the correct offset. > >> > >> Would using the latter method prevent me from using semi-transparent text > >> and / or backgrounds? > > > >It would not if you pass CAIRO_CONTENT_COLOR_ALPHA to the function, see>http://cairographics.org/manual/cairo-cairo-surface-t.html#cairo-surface-create-similar > > > >Prerendering the text is much faster that having to render the text > >again in every frame. It's only really a reasonable shortcut when the > >text is only translated and perhaps rotated, but not zoomed though. > > > I would love to pre-render the text but I think my use case makes it a bit more complex. > > The video frame is a fixed size ARGB surface which makes sense. However, the text can > > be any size and often much wider than the video image. I imagine this prevents me from being > > able to use 'create similar' since this would be using the video frame's surface, no? I guess > > I could create a new ARGB image surface using the text dimensions? > > > I have done this before using cairo and pango, basically a ticker bar on a N width screen with smooth scrolling. My approach was something like this: Make a text rendering surface 2 * N + C, C = 16 or such. do { Render text in the off screen part of the surface (which is now the rightmost half of the surface). Composite that surface from X=0 at X=0 to your main surface. Composite that surface from X=2 at X=0 to your main surface (assuming your step size = 2 pixels). When you reach X = 2N render in the offscreen part of the text render surface (which is now the leftmost half of the surface). } while (true); Regards, Leon. -- cairo mailing list [email protected] http://lists.cairographics.org/mailman/listinfo/cairo