After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 469313 - Add pango_layout_set_height()
Add pango_layout_set_height()
Status: RESOLVED FIXED
Product: pango
Classification: Platform
Component: general
unspecified
Other Linux
: Normal enhancement
: Medium API
Assigned To: pango-maint
pango-maint
: 506048 (view as bug list)
Depends on: 460828
Blocks: 84390 506049
 
 
Reported: 2007-08-22 16:47 UTC by Behdad Esfahbod
Modified: 2008-02-26 01:32 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Behdad Esfahbod 2007-08-22 16:47:05 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.
Comment 1 Behdad Esfahbod 2007-09-09 19:59:18 UTC
This is in fact dup of bug 327996.  Keeping open for now, I hope to fix both for 1.20.
Comment 2 Christian Neumair 2007-09-09 20:42:37 UTC
> I hope to fix both for 1.20.

Great! Thanks for all your tremendous contributions!
Comment 3 Behdad Esfahbod 2007-12-28 18:28:17 UTC
*** Bug 506048 has been marked as a duplicate of this bug. ***
Comment 4 Behdad Esfahbod 2008-01-15 01:23:48 UTC
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?
Comment 5 Behdad Esfahbod 2008-01-15 23:34:30 UTC
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.

Comment 6 Behdad Esfahbod 2008-02-26 01:32:13 UTC
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.