[reportlab-users] RGBA Colors

Robin Becker robin at reportlab.com
Thu Nov 26 05:31:26 EST 2009


Kevin D Smith wrote:
.........

>

>

> I think I have a solution that will work for manually setting of an

> alpha as well as supporting alpha in colors. An alpha set on the canvas

> itself is intended to make everything from that point on

> semi-transparent. Setting an alpha on a color means to only make that

> color semi-transparent. It seems to me that if you stored any alpha

> values set by setStrokeAlpha or setFillAlpha in an instance variable on

> the canvas, those could be considered the global alpha for the canvas.

> If a color was specified with an alpha, the alpha of that color would be

> multiplied by the current canvas alpha setting, but would not be stored

> in the alpha instance variables.

>

> This technique would allow any manual settings of alpha to persist while

> colors could also control the alpha level. For users who want the

> manual control, everything will work the way they want. For those who

> use the higher-level interfaces such as Platypus, there would be no

> manual alpha manipulations, so it would work correctly for them as

> well. When both are used, the effect simply combines.

>

> The only thing I'm sure about is the architectural aspect of it. Can

> colors and their alphas be popped off and have the canvas alpha value

> reset to the previous value (held in the instance variables), or is that

> just not possible? If it is possible, I think this technique would work.

.........

The only problem here is that the state calculations are quite hard. Both
colours and opacity (alpha) are canvas properties. We seem to have two inputs
for the opacity variable and a single output. Everything will be fine provided
our attempt to track the canvas properties works exactly. This kind of technique
does introduce a large amount of complexity into the setting functions and also
imposes fairly tough constraints on any re-ordering of operations. That sort of
thing is relatively easy to fix in a simple sequence of operations, but makes
life very hard for those who wish to abstract functionality into subroutines
since the authors have to take account of any possible environment.

My preference for an interaction between the canvas and colour alphas would be
something like a set of rules for the colour behaviours

a None value of color alpha means revert to whatever would be in place if no
colour alphas had been seen.

This would effectively make both alphas absolute. We do seem to need another
state for the colour alpha (to remember what it should be next time a None comes
in).
--
Robin Becker


More information about the reportlab-users mailing list