GNOME Bugzilla – Bug 469313
Add pango_layout_set_height()
Last modified: 2008-02-26 01:32:13 UTC
It will have effects only if a width is set too, and ellipsize is not none. The height value, if positive, is in Pango units, if negative, is in number of lines. So a default value of -1 means "ellipsize the first line". -2 will mean ellipsize the second line... The hard part of the implementation is with ellipsize modes start and middle. To do it properly will need bug 460828 fixed first.
This is in fact dup of bug 327996. Keeping open for now, I hope to fix both for 1.20.
> I hope to fix both for 1.20. Great! Thanks for all your tremendous contributions!
*** Bug 506048 has been marked as a duplicate of this bug. ***
First part (negative height) implemented: 2008-01-14 Behdad Esfahbod <behdad@gnome.org> Bug 469313 – Add pango_layout_set_height() * pango/pango-layout.h: * pango/pango-layout-private.h: * pango/pango-layout.c: * pango/ellipsize.c (_pango_layout_line_ellipsize): New public API: pango_layout_set_height() See docs for semantics. Currently only negative height values (number of lines) is implemented. * pango-view/viewer-render.c (make_layout), (output_body), (parse_options): Implement --height. * pango/pango.def: * docs/pango-sections.txt: * docs/tmpl/layout.sgml: Update. I had to change the semantics slightly. Here is what the docs say: /** * pango_layout_set_height: * @layout: a #PangoLayout. * @height: the desired height of the layout in Pango units if positive, * or desired number of lines if negative. * * Sets the height to which the #PangoLayout should be ellipsized at. There * are two different behaviors, based on whether @height is positive or * negative. * * If @height is positive, it will be the maximum height of the layout. Only * lines would be shown that would fit, and if there is any text ommitted, * an ellipsis added. At least one line is included in each paragraph regardless * of how small the height value is. A value of zero will render exactly one * line for the entire layout. * * If @height if it is negative, it will be the maximum number of lines per * paragraph. That is, the total number of lines shown may well be more than * this value if the layout contains multiple paragraphs of text. * The default value of -1 means that first line of each paragraph is ellipsized. * * The height setting only has effect if a positive width is set on @layout * and ellipsization mode of @layout is not %PANGO_ELLIPSIZE_NONE, * * Since: 1.20 **/ I'm not a huge fan of the different semantics of positive vs negative value with respect to per-layout vs per-paragraph behavior, but that's the only way I could make it both useful and backward compatible. Comments?
2008-01-15 Behdad Esfahbod <behdad@gnome.org> Bug 469313 – Add pango_layout_set_height() * pango/pango-layout.c (get_x_offset), (should_ellipsize_current_line), (add_line), (process_line), (pango_layout_check_lines), (pango_layout_line_get_width), (pango_layout_line_get_x_ranges), (justify_words), (pango_layout_line_postprocess): Implement height >= 0; There are still bugs left. Most notably, there will be at least two lines showed no matter how small height is.
I've now documented that the per-paragraph behavior of negative heights may change in the future. Time to close this one. 2008-02-25 Behdad Esfahbod <behdad@gnome.org> Bug 511172 – pango_layout_set_height() with positive height always shows at least two lines * pango/pango-layout.c (should_ellipsize_current_line), (pango_layout_check_lines), (pango_layout_get_empty_extents_at_index), (pango_layout_line_get_empty_extents): Initialize line_height using empty-line extents.