Setting Pango.EllipsizeMode.END not ellipsizing?

Hello,
Using Pango in Vala, in a context of Gtk.PrintContext, I want to ellipsize long lines of text (longer than the width of the A4 paper page). To achieve this, I do this:

var layout = context.create_pango_layout ();
var font = settings.get_string ("print-font-desc");
var desc = Pango.FontDescription.from_string (font);
layout.set_font_description (desc);
layout.set_width ((int) context.get_width () * Pango.SCALE);
layout.set_height ((int) context.get_height () * Pango.SCALE);
layout.set_alignment (Pango.Alignment.LEFT);
layout.set_ellipsize (Pango.EllipsizeMode.END);

Unfortunately, on Print Preview, lines are not ellipsized but wrapped.
I missed something… Any hint ? Thanks!

Set wrap to false? :person_facepalming:, sorry not a thing. However the docs say:

The wrap mode only has effect if a width is set on the layout with pango_layout_set_width(). To turn off wrapping, set the width to -1.

Thanks for the reply. I tried to set -1 as width, but the text is truncated, not ellipsized.
And to ellipsize, a width must be set:

Depending on the ellipsization mode ellipsize text is removed from the start, middle, or end of text so they fit within the width and height of layout set with [method@Pango.Layout.set_width] and [method@Pango.Layout.set_height].

AH…

If the layout contains characters such as newlines that force it to be layed out in multiple paragraphs, then whether each paragraph is ellipsized separately or the entire layout is ellipsized as a whole depends on the set height of the layout.

That is the reason why: I put a height of the page height. I will try to set a height of a line.
Comming back…

Edit: yup. Removing the line with layout.set_height(...) made it work :slight_smile: \o/

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