diff options
author | George Lebl <jirka@5z.com> | 2003-10-09 19:32:05 +0000 |
---|---|---|
committer | George Lebl <jirka@src.gnome.org> | 2003-10-09 19:32:05 +0000 |
commit | 2ce533d742c712751f2cc831314b62d353c5bfd2 (patch) | |
tree | 1ce01409196977d85b6ad75c45f9887301e9db27 | |
parent | e5d26075b3b4abecb56efeffed0c3cd9fa551c31 (diff) | |
download | gdm-2ce533d742c712751f2cc831314b62d353c5bfd2.tar.gz |
fix the line breaking not to crash, though it is still horrible. It is in
Thu Oct 09 11:11:23 2003 George Lebl <jirka@5z.com>
* gui/greeter/greeter_canvas_item.c: fix the line breaking not to
crash, though it is still horrible. It is in fact now an even
more horrible hack.
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | gui/greeter/greeter_canvas_item.c | 67 |
2 files changed, 67 insertions, 6 deletions
@@ -1,3 +1,9 @@ +Thu Oct 09 11:11:23 2003 George Lebl <jirka@5z.com> + + * gui/greeter/greeter_canvas_item.c: fix the line breaking not to + crash, though it is still horrible. It is in fact now an even + more horrible hack. + Mon Oct 06 15:02:19 2003 George Lebl <jirka@5z.com> * daemon/gdm.[ch], daemon/auth.c, daemon/slave.c: diff --git a/gui/greeter/greeter_canvas_item.c b/gui/greeter/greeter_canvas_item.c index 5b158b41..8f1c59b8 100644 --- a/gui/greeter/greeter_canvas_item.c +++ b/gui/greeter/greeter_canvas_item.c @@ -421,17 +421,48 @@ greeter_item_create_canvas_item (GreeterItemInfo *item) item); } +/* This is so evil it hurts */ +static char * +make_ugly_long_string_with_line_breaks (const char *orig) +{ + const char *p; + int n_chars, i; + GString *foo = g_string_new (NULL); + gboolean in_element = FALSE; + + n_chars = g_utf8_strlen (orig, -1); + p = orig; + + i = 0; + while (i < n_chars) { + gunichar ch = g_utf8_get_char (p); + if (ch == '<') + in_element = TRUE; + else if (ch == '>') + in_element = FALSE; + g_string_append_unichar (foo, ch); + if ( ! in_element) + g_string_append_unichar (foo, '\n'); + p = g_utf8_next_char (p); + i++; + } + + return g_string_free (foo, FALSE); +} + +/* This function is very VERY evil */ static gboolean -append_word (GString *str, GString *line, GString *word, int max_width, const char *textattr, GnomeCanvasItem *canvas_item) +append_word (GString *str, GString *line, GString *word, const char *after, int max_width, const char *textattr, GnomeCanvasItem *canvas_item) { int width, height; - char *try = g_strconcat (line->str, word->str, NULL); + char *post = make_ugly_long_string_with_line_breaks (after); + char *try = g_strconcat (str->str, word->str, "\n", post, NULL); + g_free (post); gnome_canvas_item_set (GNOME_CANVAS_ITEM (canvas_item), textattr, try, NULL); g_free (try); pango_layout_get_pixel_size (GNOME_CANVAS_TEXT (canvas_item)->layout, &width, &height); - if (width > max_width) { if ( ! ve_string_empty (line->str)) { if (str->len > 0 && @@ -454,6 +485,11 @@ append_word (GString *str, GString *line, GString *word, int max_width, const ch } } +/* This function is very VERY evil */ +/* Note that it should just use pango and do all the right things rather then + the utter hacks it tries to do. But I couldn't figure out how to do this + simply with pango and how to interact with markup properly (it seems easy + to do if there is no markup */ void greeter_canvas_item_break_set_string (GreeterItemInfo *info, const char *orig, @@ -475,12 +511,20 @@ greeter_canvas_item_break_set_string (GreeterItemInfo *info, const char *p; int in_current_row; GnomeCanvasItem *canvas_item; - const char *textattr = markup ? "markup" : "text"; + const char *textattr; + int lwidth, lheight; str = g_string_new (NULL); word = g_string_new (NULL); line = g_string_new (NULL); + /* avoid errors and even possible crashes */ + if (markup && ! pango_parse_markup (orig, -1, 0, NULL, NULL, NULL, NULL)) { + markup = FALSE; + } + + textattr = markup ? "markup" : "text"; + /* A gross hack */ if (real_item != NULL) canvas_item = real_item; @@ -505,6 +549,17 @@ greeter_canvas_item_break_set_string (GreeterItemInfo *info, n_chars = g_utf8_strlen (orig, -1); gnome_canvas_item_set (GNOME_CANVAS_ITEM (canvas_item), textattr, orig, NULL); + pango_layout_get_pixel_size (GNOME_CANVAS_TEXT (canvas_item)->layout, &lwidth, &lheight); + if (lwidth <= max_width) { + if (width != NULL) + *width = lwidth; + if (height != NULL) + *height = lheight; + if (real_item != canvas_item) + gtk_object_destroy (GTK_OBJECT (canvas_item)); + return; + } + pango_layout_get_log_attrs (GNOME_CANVAS_TEXT (canvas_item)->layout, &attrs, &n_attrs); i = 0; @@ -534,7 +589,7 @@ greeter_canvas_item_break_set_string (GreeterItemInfo *info, } if (attrs[ia].is_line_break && in_current_row > 0) { - if (append_word (str, line, word, max_width, textattr, canvas_item)) + if (append_word (str, line, word, p, max_width, textattr, canvas_item)) in_current_row = 0; } @@ -558,7 +613,7 @@ greeter_canvas_item_break_set_string (GreeterItemInfo *info, } if ( ! ve_string_empty (word->str)) - append_word (str, line, word, max_width, textattr, canvas_item); + append_word (str, line, word, "", max_width, textattr, canvas_item); gnome_canvas_item_set (GNOME_CANVAS_ITEM (canvas_item), textattr, str->str, NULL); pango_layout_get_pixel_size (GNOME_CANVAS_TEXT (canvas_item)->layout, width, height); |