Mercurial > geeqie.yaz
comparison src/image-overlay.c @ 298:cb93a982fcdd
Add the possibility to truncate overlay infos displayed:
%fCamera:20% will truncate data displayed to 20 characters
and add 3 dots at the end.
For example, %name% -> some_file, %name:4% -> some...
author | zas_ |
---|---|
date | Thu, 10 Apr 2008 10:43:15 +0000 |
parents | 4bbde8a38ad4 |
children | 49eaa6463492 |
comparison
equal
deleted
inserted
replaced
297:76cdc3f1fe34 | 298:cb93a982fcdd |
---|---|
137 prev = 0; | 137 prev = 0; |
138 last = FALSE; | 138 last = FALSE; |
139 | 139 |
140 while (TRUE) | 140 while (TRUE) |
141 { | 141 { |
142 gint was_digit = 0; | |
143 gint limit = 0; | |
144 gchar *trunc = NULL; | |
145 gchar *p; | |
146 | |
142 start = strchr(new->str, delim); | 147 start = strchr(new->str, delim); |
143 if (!start) | 148 if (!start) |
144 break; | 149 break; |
145 end = strchr(start+1, delim); | 150 end = strchr(start+1, delim); |
146 if (!end) | 151 if (!end) |
147 break; | 152 break; |
148 | 153 |
149 name = g_strndup(start+1, end-start-1); | 154 for (p = end; p > start; p--) |
155 { | |
156 if (*p == ':' && was_digit) | |
157 { | |
158 trunc = p; | |
159 break; | |
160 } | |
161 was_digit = (*p >= '0' && *p <= '9'); | |
162 } | |
163 | |
164 if (trunc) limit = atoi(trunc+1); | |
165 | |
166 name = g_strndup(start+1, ((limit > 0) ? trunc : end)-start-1); | |
167 | |
150 pos = start-new->str; | 168 pos = start-new->str; |
151 data = g_strdup(g_hash_table_lookup(vars, name)); | 169 data = g_strdup(g_hash_table_lookup(vars, name)); |
152 if (!data && exif) | 170 if (!data && exif) |
153 data = exif_get_data_as_text(exif, name); | 171 data = exif_get_data_as_text(exif, name); |
154 | 172 if (data && *data && limit > 0) |
173 { | |
174 gchar *new_data = g_strdup_printf("%-*.*s...", limit, limit, data); | |
175 g_free(data); | |
176 data = new_data; | |
177 } | |
178 | |
155 g_string_erase(new, pos, end-start+1); | 179 g_string_erase(new, pos, end-start+1); |
156 if (data) | 180 if (data) |
157 g_string_insert(new, pos, data); | 181 g_string_insert(new, pos, data); |
158 if (pos-prev == 2 && new->str[pos-1] == imp) | 182 if (pos-prev == 2 && new->str[pos-1] == imp) |
159 { | 183 { |