Alpha in Pango Color

2015-08-07 Thread William Kappler
Hello,

I am seeking a way to encode the alpha channel of color into text, so that
it can vary within a Pango layout like color. As far as I can tell, this is
not supported directly by Pango. If I set an alpha via
*cairo_set_source_rgba()* there is no way to later change it: the markup
only offers 3-component hex colors.

I took a brief look at the source and it seems a non-trivial matter to add
such functionality. I was unable to trace down where exactly the color
attribute ends up affecting the text color. As I said, though, this was a
brief look.

Ideally, *foreground* and *background* would take both three-component and
four-component colors (#NN or #), but an additional alpha tag
would be an option as well.

I ask because I am currently attempting to apply Pango-Cairo as the text
rendering engine in an open source game engine I am working on. I figure
alpha has little impact on most of Pango's applications - but in the
context of 3D, it is quite important.

Does anyone have any thoughts or advice on this topic? I would be willing
to write a patch to this effect if that is of interest.

:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-
William E. Kappler II
LinkedIn  · Blog
 · Project Website

___
gtk-i18n-list mailing list
gtk-i18n-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-i18n-list


Re: Alpha in Pango Color

2015-08-08 Thread Behdad Esfahbod
Hi William,

Currently Pango doesn't support alpha in colors.  At this point, it might make
sense to add a separate PANGO_ATTR_ALPHA, instead of an RGBA type.

I'd take a patch.  Matthias, is this something you can possibly implement?
Shouldn't take long to implement and test...

b

On 15-08-08 01:10 AM, William Kappler wrote:
> Hello,
> 
> I am seeking a way to encode the alpha channel of color into text, so that it
> can vary within a Pango layout like color. As far as I can tell, this is not
> supported directly by Pango. If I set an alpha via *cairo_set_source_rgba()*
> there is no way to later change it: the markup only offers 3-component hex
> colors.
> 
> I took a brief look at the source and it seems a non-trivial matter to add
> such functionality. I was unable to trace down where exactly the color
> attribute ends up affecting the text color. As I said, though, this was a
> brief look.
> 
> Ideally, *foreground* and *background* would take both three-component and
> four-component colors (#NN or #), but an additional alpha tag
> would be an option as well.
> 
> I ask because I am currently attempting to apply Pango-Cairo as the text
> rendering engine in an open source game engine I am working on. I figure alpha
> has little impact on most of Pango's applications - but in the context of 3D,
> it is quite important.
> 
> Does anyone have any thoughts or advice on this topic? I would be willing to
> write a patch to this effect if that is of interest.
> 
> :-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-
> William E. Kappler II
> LinkedIn  · Blog
>  · Project Website
> 
> 
> 
> ___
> gtk-i18n-list mailing list
> gtk-i18n-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/gtk-i18n-list
> 
___
gtk-i18n-list mailing list
gtk-i18n-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-i18n-list


Re: Alpha in Pango Color

2015-08-11 Thread Matthias Clasen
On Sat, 2015-08-08 at 11:36 +0200, Behdad Esfahbod wrote:
> Hi William,
> 
> Currently Pango doesn't support alpha in colors.  At this point, it 
> might make
> sense to add a separate PANGO_ATTR_ALPHA, instead of an RGBA type.
> 
> I'd take a patch.  Matthias, is this something you can possibly 
> implement?
> Shouldn't take long to implement and test...

No, sorry. Not in the short term. But I would be interested in having
alpha support in pango, and would look at making GTK+ use it if it
appears.

If we make this a separate attribute, we would need fg-alpha, bg-alpha,
strikethrough-alpha and underline-alpha. And there would be some
complication where you could end up with (say) the underline-color and
underline-alpha attributes ending at different positions. We would fall
back to fg for the underline color where underline-color has ended. But
do we combine it with the underline-alpha? Maybe that is just a corner
-case that needs clear documentation.
___
gtk-i18n-list mailing list
gtk-i18n-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-i18n-list


Re: Alpha in Pango Color

2015-08-11 Thread Behdad Esfahbod
On 15-08-11 03:58 PM, Matthias Clasen wrote:
> On Sat, 2015-08-08 at 11:36 +0200, Behdad Esfahbod wrote:
>> Hi William,
>>
>> Currently Pango doesn't support alpha in colors.  At this point, it 
>> might make
>> sense to add a separate PANGO_ATTR_ALPHA, instead of an RGBA type.
>>
>> I'd take a patch.  Matthias, is this something you can possibly 
>> implement?
>> Shouldn't take long to implement and test...
> 
> No, sorry. Not in the short term. But I would be interested in having
> alpha support in pango, and would look at making GTK+ use it if it
> appears.
> 
> If we make this a separate attribute, we would need fg-alpha, bg-alpha,
> strikethrough-alpha and underline-alpha. And there would be some
> complication where you could end up with (say) the underline-color and
> underline-alpha attributes ending at different positions. We would fall
> back to fg for the underline color where underline-color has ended. But
> do we combine it with the underline-alpha? Maybe that is just a corner
> -case that needs clear documentation.

Hum..  We definitely don't want four alpha attributes.  Are there realistic
usecases for needing different alpha for those?  I guess different alha for
background vs foreground makes a lot of sense...

b
___
gtk-i18n-list mailing list
gtk-i18n-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-i18n-list


Re: Alpha in Pango Color

2015-08-11 Thread William Kappler
I didn’t consider that when I suggested a possible separate tag – it would
seem excessive to have more than one alpha tag, and if the background and
foreground at least couldn’t be independently controlled, a lot of possible
functionality would be lost. I’m not sure about things like the
strikethrough or underline being independent. It seems it might be
inconsistent if they behaved differently. That said, let me just suggest a
case for my initial suggestion of expanding the hex color values.

First off, I didn’t realize color was supported in different precision
formats. That would cause a problem with adding a 4th parameter because of
 – which could be either 3 colors X 4 or 4 colors X 3. As such,
perhaps adding an optional marker of some sort at the end of the existing
hex color, followed by another hex value (representing only alpha) would be
a solution. For example: “#FF|5”. That should not conflict with
anything else or anyone’s expected behavior. ‘|’ isn’t necessarily the
symbol that should be used, but I can’t off the top of my head think of a
better marker.

Then, PangoColor would have to be modified to have the additionally guint16
for alpha. This of course means the alpha becomes a core part of the color,
and they have to be specified together. If the user chooses not to specify
an alpha, I think it should default to fully opaque. Typically that’s how
text systems handle color and alpha, like CSS. Unless the alpha is
specified via “rgba”, it assumes fully opaque, overriding any previous
foreground alpha.

Actually drawing the color would be as easy as switching
cairo_set_source_rgb for cairo_set_source_rgba and adding the new component.

The only downside I see is the work to implement such a change and that it
could cause some users of Pango to see text suddenly becoming fully opaque
when they use a 3-parameter color tag, if they previously set the alpha via
Cairo. Since Pango’s support for alpha is basically nonexistent now, anyone
using alpha would benefit in the long run even if some refactoring of how
they handle colors was needed.

In any case, thank you both for taking my suggestion seriously. It would be
a great help if anything like this were implemented. Again, if there’s
anything I can do to help, I’m more than willing to do what I can.



:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-
William E. Kappler II
LinkedIn  · Blog
 · Project Website


On Tue, Aug 11, 2015 at 10:37 AM, Behdad Esfahbod  wrote:

> On 15-08-11 03:58 PM, Matthias Clasen wrote:
> > On Sat, 2015-08-08 at 11:36 +0200, Behdad Esfahbod wrote:
> >> Hi William,
> >>
> >> Currently Pango doesn't support alpha in colors.  At this point, it
> >> might make
> >> sense to add a separate PANGO_ATTR_ALPHA, instead of an RGBA type.
> >>
> >> I'd take a patch.  Matthias, is this something you can possibly
> >> implement?
> >> Shouldn't take long to implement and test...
> >
> > No, sorry. Not in the short term. But I would be interested in having
> > alpha support in pango, and would look at making GTK+ use it if it
> > appears.
> >
> > If we make this a separate attribute, we would need fg-alpha, bg-alpha,
> > strikethrough-alpha and underline-alpha. And there would be some
> > complication where you could end up with (say) the underline-color and
> > underline-alpha attributes ending at different positions. We would fall
> > back to fg for the underline color where underline-color has ended. But
> > do we combine it with the underline-alpha? Maybe that is just a corner
> > -case that needs clear documentation.
>
> Hum..  We definitely don't want four alpha attributes.  Are there realistic
> usecases for needing different alpha for those?  I guess different alha for
> background vs foreground makes a lot of sense...
>
> b
>
___
gtk-i18n-list mailing list
gtk-i18n-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-i18n-list


Re: Alpha in Pango Color

2015-08-11 Thread Matthias Clasen
On Tue, 2015-08-11 at 16:37 +0200, Behdad Esfahbod wrote:

> 
> Hum..  We definitely don't want four alpha attributes.  Are there 
> realistic
> usecases for needing different alpha for those?  I guess different 
> alha for
> background vs foreground makes a lot of sense...
> 

I said I wouldn't have time, but then I took out the laptop on the
drive to flock today, and produced 

https://git.gnome.org/browse/pango/log/?h=wip/matthiasc/alpha

Review appreciated.
___
gtk-i18n-list mailing list
gtk-i18n-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-i18n-list


Re: Alpha in Pango Color

2015-08-12 Thread Behdad Esfahbod
On 15-08-12 02:45 AM, Matthias Clasen wrote:
> I said I wouldn't have time, but then I took out the laptop on the
> drive to flock today, and produced 
> 
> https://git.gnome.org/browse/pango/log/?h=wip/matthiasc/alpha

That's one legitimate approach.  My only feedback is, in PangoMarkup, support
alpha as part of the existing attributes as well.  Ie, if color is specified
as #1234 or #11223344, generate two attributes, one for color, one for alpha...

b
___
gtk-i18n-list mailing list
gtk-i18n-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-i18n-list