Mercurial > pidgin
comparison console/libgnt/gntutils.c @ 14420:c4a32405af68
[gaim-migrate @ 17128]
Keep things neat and clean in gnt_util_onscreen_width_to_pointer.
The only use of this function currently is to truncate a string to
make sure it fits in the drawing area, eg, the title of a window,
or in the combobox. The function is called on a newly allocated
string, which is truncated (if necessary), printed, and freed.
committer: Tailor Script <tailor@pidgin.im>
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Sat, 02 Sep 2006 18:55:27 +0000 |
parents | b50aa149e09d |
children | cfd5bcc06a7e |
comparison
equal
deleted
inserted
replaced
14419:b50aa149e09d | 14420:c4a32405af68 |
---|---|
18 while (*s) | 18 while (*s) |
19 { | 19 { |
20 if (*s == '\n' || *s == '\r') | 20 if (*s == '\n' || *s == '\r') |
21 { | 21 { |
22 count++; | 22 count++; |
23 len = g_utf8_pointer_to_offset(last, s); | 23 len = gnt_util_onscreen_width(last, s); |
24 if (max < len) | 24 if (max < len) |
25 max = len; | 25 max = len; |
26 last = s + 1; | 26 last = s + 1; |
27 } | 27 } |
28 s++; | 28 s = g_utf8_next_char(s); |
29 } | 29 } |
30 | 30 |
31 len = g_utf8_pointer_to_offset(last, s); | 31 len = gnt_util_onscreen_width(last, s); |
32 if (max < len) | 32 if (max < len) |
33 max = len; | 33 max = len; |
34 } | 34 } |
35 | 35 |
36 if (height) | 36 if (height) |
48 start = g_utf8_next_char(start); | 48 start = g_utf8_next_char(start); |
49 } | 49 } |
50 return width; | 50 return width; |
51 } | 51 } |
52 | 52 |
53 char *gnt_util_onscreen_width_to_pointer(const char *string, int len, int *w) | 53 const char *gnt_util_onscreen_width_to_pointer(const char *string, int len, int *w) |
54 { | 54 { |
55 int size; | 55 int size; |
56 int width = 0; | 56 int width = 0; |
57 char *str = (char*)string; | 57 const char *str = string; |
58 | 58 |
59 while (width < len && *str) { | 59 while (width < len && *str) { |
60 size = g_unichar_iswide(g_utf8_get_char(str)) ? 2 : 1; | 60 size = g_unichar_iswide(g_utf8_get_char(str)) ? 2 : 1; |
61 if (width + size > len) | 61 if (width + size > len) |
62 break; | 62 break; |