Drawing TAB character

Hi, ALL,
How is the TAB character handled inside pango_cairo_create_layout()/pango_layout_set_text().

Is it expanded and just 4 spaces is drawn or the algorithm is different?
Also is there a way to change the number of spaces?

Is there a way to specify this in the documentation?

Thank you

Google “pango tab” points me to

https://developer.gnome.org/pango/stable/pango-Tab-Stops.html

Is that not helpful?

Hi, Stefan,
Thank you for the link.

I looked at it, but it doesn’t say anywhere what is the default tab stop is.

Let’s say I have a following string: “abc\tdef”. What the ‘\t’ will be expanded to by default: 4? 8? (spaces). It also says that it will use pango units by default. How does it match with the number of spaces?

See

“by default, tabs are every 8 spaces”

PangoUnits depend on the output device:

The definition of device units is dependent on the output device; it will typically be pixels for a screen, and points for a printer

If you want to match them to “spaces” you need to compute the size for a “space” glyph given the current font description, and turn it into a PangoUnit, e.g.

// the size of the tab you want to set, in "spaces"
int tab_size = 4;
// fill out a string with tab_size spaces
char *tab_string = g_strnfill (tab_size, ' ');

// layout is set elsewhere, and it's a PangoLayout instance
pango_layout_set_text (layout, tab_string, -1);

// get the width of the layout in pixels
int tab_width = -1;
pango_layout_get_pixel_size (layout, &tab_width, NULL);

// set the default tab stop at tab_width pixels with a left alignment
PangoTabArray *tab_array = pango_tab_array_new (1, TRUE);
pango_tab_array_set_tab (tab_array, 0, PANGO_TAB_LEFT, tab_width);
1 Like

Emmanuelle,
Thank you.

Stefan,
Thank you. This is very helpful.

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