[cairo] Alpha channel for text under win32

Jason Thomas jason.thomas at onycha-blue.com
Tue Apr 12 23:49:40 PDT 2005

Just FYI, AFAIK GDI+ appears to have support.

My requirements are:
	Linux + Windows
	Quick, byte level access to a cairo generated RGBA image

I have to use the RGBA externally to cairo for blending.

The win32 alpha channel looks OK except only for fonts,
it even appears to be used in CAIRO_FORMAT_RGB24 mode.

Since other renderers use freetype? (X&Glitz) they
must also be in a similar position as I don't think
lib freetype handles an alpha channel unless you
use direct rendering which is pretty expensive.

>Can you just use an image surface?
If I understand you correctly means do my blending in cairo?
Unfortunately I don't have the option.

> and the only use of the DC would be when
> calling AlphaBlend.

Well you do have the color/alpha data in the DC's DIB, which you can setup
in the DC prior to passing to cairo,
so you can do anything you like with the color/alpha data as externally you
have access to this.

Does anyone know if pixmaps/surfaces under X suffer from the same problem?
i.e. alpha for all primatives but Text?

Jason Thomas.

-----Original Message-----
From: Owen Taylor [mailto:otaylor at redhat.com]
Sent: Wednesday, 13 April 2005 3:21 PM
To: Jason Thomas
Cc: cairo at cairographics.org
Subject: Re: [cairo] Alpha channel for text under win32

On Wed, 2005-04-13 at 13:10 +1000, Jason Thomas wrote:
> Hello
> I have been looking at the alpha channel in the win32 surface, with the
> requirement to do some alpha blending outside of cairo.
> I set the target via:
> 	cairo_set_target_win32(pCairo, DC);
> I have noticed an issue here, the primatives I am using lines/fills etc.
> generate an alpha value in the 4th byte of the DC's bitmap, but text
> rendering does not.
> My current fix is to set:
>     surface->format = CAIRO_FORMAT_ARGB32;
> in
>     cairo_win32_surface_create (HDC hdc)
> but this seems to drop the quality of the text a little on initial review.

Could be ... Windows does not how to render to a ARGB bitmap, whether
text or anything else, so rendering text to ARGB is a bit of a hack.
(Look at the code for details.) Only text rendered onto a solid
background will get the correct gamma correction.

> Is this the best solution?
> Is it possible to pass a flag into cairo_set_target_win32 to select
> CAIRO_FORMAT_ARGB32 and CAIRO_FORMAT_RGB24 for the surface formats?

I'm rather reluctant to do that... because windows doesn't have the idea
of ARGB device contexts. All the ARGB32 variant would be is an
image surface wrapped in a DC, and the only use of the DC would be when
calling AlphaBlend.

What sort of alpha blending do you need to do? Can you just use an image


More information about the cairo mailing list