annotate console/libgnt/gntutils.c @ 14245:f64ff0c57457

[gaim-migrate @ 16927] Press alt+l to refresh the screen, useful if you resize the terminal. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Mon, 21 Aug 2006 01:44:07 +0000
parents 81648c6aa918
children fda9dc44807d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14059
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1 #include "gntutils.h"
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
2
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
3 void gnt_util_get_text_bound(const char *text, int *width, int *height)
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
4 {
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
5 const char *s = text, *last;
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
6 int count = 1, max = 0;
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
7 int len;
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
8
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
9 /* XXX: ew ... everyone look away */
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
10 last = s;
14060
81648c6aa918 [gaim-migrate @ 16678]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14059
diff changeset
11 if (s)
14059
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
12 {
14060
81648c6aa918 [gaim-migrate @ 16678]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14059
diff changeset
13 while (*s)
14059
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
14 {
14060
81648c6aa918 [gaim-migrate @ 16678]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14059
diff changeset
15 if (*s == '\n' || *s == '\r')
81648c6aa918 [gaim-migrate @ 16678]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14059
diff changeset
16 {
81648c6aa918 [gaim-migrate @ 16678]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14059
diff changeset
17 count++;
81648c6aa918 [gaim-migrate @ 16678]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14059
diff changeset
18 len = g_utf8_pointer_to_offset(last, s);
81648c6aa918 [gaim-migrate @ 16678]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14059
diff changeset
19 if (max < len)
81648c6aa918 [gaim-migrate @ 16678]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14059
diff changeset
20 max = len;
81648c6aa918 [gaim-migrate @ 16678]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14059
diff changeset
21 last = s + 1;
81648c6aa918 [gaim-migrate @ 16678]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14059
diff changeset
22 }
81648c6aa918 [gaim-migrate @ 16678]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14059
diff changeset
23 s++;
14059
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
24 }
14060
81648c6aa918 [gaim-migrate @ 16678]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14059
diff changeset
25
81648c6aa918 [gaim-migrate @ 16678]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14059
diff changeset
26 len = g_utf8_pointer_to_offset(last, s);
81648c6aa918 [gaim-migrate @ 16678]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14059
diff changeset
27 if (max < len)
81648c6aa918 [gaim-migrate @ 16678]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14059
diff changeset
28 max = len;
14059
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
29 }
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
30
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
31 if (height)
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
32 *height = count;
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
33 if (width)
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
34 *width = max + (count > 1);
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
35 }
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
36