summaryrefslogtreecommitdiff
path: root/pango
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@gnome.org>2007-01-16 10:36:42 +0000
committerBehdad Esfahbod <behdad@src.gnome.org>2007-01-16 10:36:42 +0000
commit9354b7f487b706ddb693a32fe01cdaf729f0b66b (patch)
tree99da184a9a6fdccd1ed480b5c4e65a9ee25d04a5 /pango
parent375cb212021277fd31142080a4ebb3fcf9b27a43 (diff)
downloadpango-9354b7f487b706ddb693a32fe01cdaf729f0b66b.tar.gz
Bug 363510 – Ability to query whether a PangoLayout is effectively
2007-01-16 Behdad Esfahbod <behdad@gnome.org> Bug 363510 – Ability to query whether a PangoLayout is effectively ellipsized (as opposed to the set_ellpisize()/get_ellipsize() methods which only set a request, or return the set request respectively) Patch from Milosz Derezynski * pango/pango-layout.h: * pango/ellipsize.c (_pango_layout_line_ellipsize): * pango/pango-layout-private.h: * pango/pango-layout.c (pango_layout_init), (pango_layout_copy), (pango_layout_is_ellipsized), (pango_layout_clear_lines), (pango_layout_line_postprocess): New public function: pango_layout_is_ellipsized() * pango/pango.def: * docs/tmpl/layout.sgml: * docs/pango-sections.txt: Update. svn path=/trunk/; revision=2150
Diffstat (limited to 'pango')
-rw-r--r--pango/ellipsize.c10
-rw-r--r--pango/pango-layout-private.h3
-rw-r--r--pango/pango-layout.c34
-rw-r--r--pango/pango-layout.h1
-rw-r--r--pango/pango.def1
5 files changed, 44 insertions, 5 deletions
diff --git a/pango/ellipsize.c b/pango/ellipsize.c
index b1523afe..e392d3c9 100644
--- a/pango/ellipsize.c
+++ b/pango/ellipsize.c
@@ -717,17 +717,20 @@ current_width (EllipsizeState *state)
*
* Given a #PangoLayoutLine with the runs still in logical order, ellipsize
* it according the layout's policy to fit within the set width of the layout.
+ *
+ * Return value: whether the line had to be ellipsized
**/
-void
+gboolean
_pango_layout_line_ellipsize (PangoLayoutLine *line,
PangoAttrList *attrs)
{
EllipsizeState state;
int goal_width;
+ gboolean is_ellipsized = FALSE;
if (line->layout->ellipsize == PANGO_ELLIPSIZE_NONE ||
line->layout->width < 0)
- return;
+ goto ret;
init_state (&state, line, attrs);
@@ -750,7 +753,10 @@ _pango_layout_line_ellipsize (PangoLayoutLine *line,
g_slist_free (line->runs);
line->runs = get_run_list (&state);
+ is_ellipsized = TRUE;
out:
free_state (&state);
+ ret:
+ return is_ellipsized;
}
diff --git a/pango/pango-layout-private.h b/pango/pango-layout-private.h
index 75913940..56370c1a 100644
--- a/pango/pango-layout-private.h
+++ b/pango/pango-layout-private.h
@@ -52,6 +52,7 @@ struct _PangoLayout
guint wrap : 2; /* PangoWrapMode */
guint ellipsize : 2; /* PangoEllipsizeMode */
+ guint is_ellipsized : 1; /* Whether the layout has any ellipsized lines */
/* some caching */
guint logical_rect_cached : 1;
@@ -72,7 +73,7 @@ struct _PangoLayout
G_END_DECLS
-void _pango_layout_line_ellipsize (PangoLayoutLine *line,
+gboolean _pango_layout_line_ellipsize (PangoLayoutLine *line,
PangoAttrList *attrs);
PangoLayoutLine* _pango_layout_iter_get_line_readonly (PangoLayoutIter *iter);
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index 52b9dccf..e708d555 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -200,6 +200,7 @@ pango_layout_init (PangoLayout *layout)
layout->wrap = PANGO_WRAP_WORD;
layout->ellipsize = PANGO_ELLIPSIZE_NONE;
+ layout->is_ellipsized = FALSE;
}
static void
@@ -306,7 +307,7 @@ pango_layout_copy (PangoLayout *src)
layout->wrap = src->wrap;
layout->ellipsize = src->ellipsize;
- /* log_attrs, lines fields are updated by check_lines */
+ /* is_ellipsized, log_attrs, lines fields are updated by check_lines */
return layout;
}
@@ -845,6 +846,32 @@ pango_layout_get_ellipsize (PangoLayout *layout)
}
/**
+ * pango_layout_is_ellipsized:
+ * @layout: a #PangoLayout
+ *
+ * Queries whether the layout had to ellipsize any paragraphs.
+ *
+ * This can only return %TRUE if the ellipsization mode for @layout
+ * is not %PANGO_ELLIPSIZE_NONE, a positive width is set on @layout,
+ * and there were paragraphs exceeding that width that had to be
+ * ellipsized.
+ *
+ * Return value: %TRUE if any paragraphs had to be ellipsized, %FALSE
+ * otherwise.
+ *
+ * Since: 1.16
+ */
+gboolean
+pango_layout_is_ellipsized (PangoLayout *layout)
+{
+ g_return_if_fail (layout != NULL);
+
+ pango_layout_check_lines (layout);
+
+ return layout->is_ellipsized;
+}
+
+/**
* pango_layout_set_text:
* @layout: a #PangoLayout
* @text: a valid UTF-8 string
@@ -2456,6 +2483,8 @@ pango_layout_get_pixel_size (PangoLayout *layout,
static void
pango_layout_clear_lines (PangoLayout *layout)
{
+ layout->is_ellipsized = FALSE;
+
if (layout->lines)
{
GSList *tmp_list = layout->lines;
@@ -4571,7 +4600,8 @@ pango_layout_line_postprocess (PangoLayoutLine *line,
/* Ellipsize the line if necessary
*/
- _pango_layout_line_ellipsize (line, state->attrs);
+ if (_pango_layout_line_ellipsize (line, state->attrs))
+ line->layout->is_ellipsized = TRUE;
/* Now convert logical to visual order
*/
diff --git a/pango/pango-layout.h b/pango/pango-layout.h
index 6e24a565..5a73c537 100644
--- a/pango/pango-layout.h
+++ b/pango/pango-layout.h
@@ -153,6 +153,7 @@ gboolean pango_layout_get_single_paragraph_mode (PangoLayout
void pango_layout_set_ellipsize (PangoLayout *layout,
PangoEllipsizeMode ellipsize);
PangoEllipsizeMode pango_layout_get_ellipsize (PangoLayout *layout);
+gboolean pango_layout_is_ellipsized (PangoLayout *layout);
void pango_layout_context_changed (PangoLayout *layout);
diff --git a/pango/pango.def b/pango/pango.def
index 7b3aa3ec..3ea0951e 100644
--- a/pango/pango.def
+++ b/pango/pango.def
@@ -238,6 +238,7 @@ EXPORTS
pango_layout_get_wrap
pango_layout_index_to_line_x
pango_layout_index_to_pos
+ pango_layout_is_ellipsized
pango_layout_iter_at_last_line
pango_layout_iter_free
pango_layout_iter_get_baseline