Learn the first lesson of pango, let GtkLabel measure the size of the returned drawing area

I didn’t find out how to make GtkLabel return the dimensions of the drawing area.

I hate the inexplicable top and bottom whitespace in single-line mode, which makes the size completely unmanageable.

I would like to know the technical term for this “top and bottom white space”.
I checked the wiki and only found “Ascender”, but that seems to be something completely different

I suggest that GtkLabel allows to return the dimensions of the painted part

Although it is easy to handle by yourself

What did you try, which didn’t work?

If you are asking the Label to measure itself, then of course it will return the padding/margin/etc. If you don’t want those, you can probably defeat them using CSS.

As to getting the size of the text without any padding/margin, have you tried getting the Pango Layout with label.get_layout() and from there trying methods like layout.get_pixel_extents() et al.?

I don’t think css is a good solution. Negative margins can be used to fix some issues, but the value is only for that font size

Yes, I’m using that function

PangoLayout*   layout      = gtk_label_get_layout( ( gpointer )child );
PangoRectangle layout_rect = {};  
pango_layout_get_pixel_extents( layout, &layout_rect, NULL );

Do you get totally wrong values? If not, try the third parameter of pango_layout_get_pixel_extents instead of the second one. You could also use a test text with oversized characters like ‘Ä’ and look where the umlaut is placed.




Thanks for pointing out the error. For “Ä” I didn’t notice the difference, but “,” can clearly see the difference.

In fact, I noticed that the “,” character was missing a half-edge, but I couldn’t fix it, so I’m already going to accept it.

After testing, only the second parameter can be used.
Although the characters may overflow the border, I want to ensure consistent line height and line spacing.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.