You are not logged in.

#1 2018-12-02 04:44:56

tayis
New Member
Registered: 2018-12-02
Posts: 4

Tint2: using colors in executers with pango markup

Hello, experts!

I need the help of someone who knows C and cairo!

I use tint to display quotes on the exchange. And I want tint to display positive and negative changes in different colors: green and red. For this I use pango markup.

For example, basic executor:

echo '<sup>btc</sup>/<sub>usd</sub> 4194.07<span fgcolor="#ff0000" size="x-small">(-10.27)</span>'

Everything works perfectly. But, if I enable text shadows in tint2 config, instead of multi-colored text, I see spots.

I found the code responsible for rendering the text.

When rendering shadows, the tag <span> responsible for the text color remains active for shadow colors.

I need to teach tint2 to ignore colors when drawing shadows.

Any idea how to do this?

Last edited by tayis (2018-12-02 04:59:18)

Offline

#2 2018-12-02 07:42:21

damo
....moderator....
Registered: 2015-08-20
Posts: 4,382

Re: Tint2: using colors in executers with pango markup

@o9000 is often active here, but why not ask the developers directly? https://gitlab.com/o9000/tint2


Be Excellent to Each Other...

FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#3 2018-12-02 09:56:15

tayis
New Member
Registered: 2018-12-02
Posts: 4

Re: Tint2: using colors in executers with pango markup

damo wrote:

@o9000 is often active here, but why not ask the developers directly? https://gitlab.com/o9000/tint2

Good question!

Perhaps I lack the necessary qualifications. I know a little clang, but I'm afraid to goof off.

Although, having spent a few more hours/days trying, I can find a solution on my own.
While I see one solution, cut the fgcolor attribute from a string using a regular expression. Then parse the string again.
This will certainly affect the rendering performance of drawing all tint2.

Another solution looks no less absurd. Add shadows using ImageMagic on an already rendered image of this line.

In any case, I do not want to give up transparency of tint2. Without shadows labels blend into the background.

Offline

#4 2018-12-02 20:14:21

malm
jgmenu developer
Registered: 2016-10-13
Posts: 228
Website

Re: Tint2: using colors in executers with pango markup

Interesting problem.

I haven’t looked at the code, but may you could strdup the string with the markup and then remove any colour related attributes and use that for the shadow

Last edited by malm (2018-12-02 20:15:00)

Offline

#5 2018-12-05 11:17:25

tayis
New Member
Registered: 2018-12-02
Posts: 4

Re: Tint2: using colors in executers with pango markup

malm wrote:

Interesting problem.

I haven’t looked at the code, but may you could strdup the string with the markup and then remove any colour related attributes and use that for the shadow

See the code. The code looks pretty simple. I do not know C. But I understand this code. Click on the link to the exact place.

void draw_text(PangoLayout *layout, cairo_t *c, int posx, int posy, Color *color, int font_shadow)

The string with markup is not provided to draw_text function.

cairo_t *c

This is no longer a string, this is already a label with already calculated width and height.

To re-assign color for each element of this label, need an understanding of cairo. But it hard for me.  hmm

Last edited by tayis (2018-12-05 11:18:47)

Offline

#6 2018-12-07 18:51:29

o9000
tint2 developer
From: Network Neighborhood
Registered: 2015-10-24
Posts: 396
Website

Re: Tint2: using colors in executers with pango markup

Since you've been digging through the code, I'm not going to make this easy for you! Following the old saying about giving a man a fish...

1. Hint: pango_cairo_show_layout draws the text.
2. Question: Why is draw_text calling pango_cairo_show_layout in 2 different places?
3. Hint: cairo_set_source_rgba is also called in 2 places, with different parameters. Why?
4. Hint: pango_cairo_show_layout does not take as parameter the text, but a "layout". This contains the text and some metadata (called attributes) from the parsed markup.
5. Question: what is the effect of the first call of cairo_set_source_rgba if the layout already has color attributes?
6. Question: is this why the shadow is not working properly? (Hint: yes)
7. Question: what can we do about it?
8. Hint: let's change the attributes.
9. Hint: here is how sway is doing it: https://github.com/swaywm/sway/blob/mas … ango.c#L58
10. Hint: this is the one we need to change: https://developer.gnome.org/pango/stabl … oAttrColor
11. Question: Which color should we use? Hint: see #3.
12. Task: fix the shadow drawing.
13. Task: the text might not be drawn with correct colors anymore. Fix that.
14. Task: cleanup code. Make it pretty. Then test everything again.
15. Task: compile everything with AdressSanitizer on and check that there are no memory errors and no memory leaks.
16. Ship it.

Do you feel up for this challenge?

Last edited by o9000 (2018-12-07 18:52:51)

Offline

#7 2018-12-07 21:45:10

malm
jgmenu developer
Registered: 2016-10-13
Posts: 228
Website

Re: Tint2: using colors in executers with pango markup

I see... they provide a pango_parse_markup().

Offline

#8 2018-12-08 04:13:15

tayis
New Member
Registered: 2018-12-02
Posts: 4

Re: Tint2: using colors in executers with pango markup

o9000 wrote:

Since you've been digging through the code, I'm not going to make this easy for you! Following the old saying about giving a man a fish...

1. Hint: pango_cairo_show_layout draws the text.
2. Question: Why is draw_text calling pango_cairo_show_layout in 2 different places?
3. Hint: cairo_set_source_rgba is also called in 2 places, with different parameters. Why?
4. Hint: pango_cairo_show_layout does not take as parameter the text, but a "layout". This contains the text and some metadata (called attributes) from the parsed markup.
5. Question: what is the effect of the first call of cairo_set_source_rgba if the layout already has color attributes?
6. Question: is this why the shadow is not working properly? (Hint: yes)
7. Question: what can we do about it?
8. Hint: let's change the attributes.
9. Hint: here is how sway is doing it: https://github.com/swaywm/sway/blob/mas … ango.c#L58
10. Hint: this is the one we need to change: https://developer.gnome.org/pango/stabl … oAttrColor
11. Question: Which color should we use? Hint: see #3.
12. Task: fix the shadow drawing.
13. Task: the text might not be drawn with correct colors anymore. Fix that.
14. Task: cleanup code. Make it pretty. Then test everything again.
15. Task: compile everything with AdressSanitizer on and check that there are no memory errors and no memory leaks.
16. Ship it.

Do you feel up for this challenge?


Hello, o9000!

Thanks for the detailed answer.


Unfortunately, I am very tired in recent days.
While my bitcoin dozen is turning into a pumpkin, I am animating this process into a widget.
So that I can see in real time how much I am a dummy, regardless of what I do on the computer.

I need to sleep.

Of course, I will try to decorate tint2 in a rainbow!
You gave detailed tips. It will be a good experience for me.
The last time I wrote the C program myself for DOS, when I was a student.
As far as I remember, the entire toolkit was limited to BORLANDC3.1.

I'll try to do it after the weekend.

Last edited by tayis (2018-12-08 04:15:28)

Offline

#9 2018-12-09 14:09:19

o9000
tint2 developer
From: Network Neighborhood
Registered: 2015-10-24
Posts: 396
Website

Re: Tint2: using colors in executers with pango markup

No worries. TBH I can't gather any energy to touch tint2 code nowadays.

Offline

Board footer

Powered by FluxBB