Mercurial > geeqie
comparison src/image-overlay.c @ 622:54e20abb5c6d
Fix display of collection in overlay info.
Due to markup escaped <i>collection</i> was displayed instead of collection's in italic.
Overlay info syntax was extended to allow the wrapping of displayed data with markup.
General syntax is: %name[:length limit][:extra]%
Extra string uses special character '*' to mark the place of the data to display.
If no '*' is present, then extra string is just appended to data.
Any "\n" is replaced by a newline on display.
Pango mark up is accepted in left and right parts.
If data is empty, nothing will be displayed.
Examples:
"%name:<i>*</i>\n%" -> name is displayed in italics ended with a newline
"%size:\n%" -> size is displayed with a newline at end
"%formatted.ISOSpeedRating:ISO *%" -> prefix iso number with "ISO " (ie. "ISO 100")
"Collection <b>*</b>\n" -> display collection name in bold prefixed by "Collection " and a newline is appended
Collection name formatting was slighly improved by not displaying the .gqv extension.
The default overlay info string was modified to use the new syntax, but older info strings should be
displayed as usual.
author | zas_ |
---|---|
date | Sat, 10 May 2008 21:29:53 +0000 |
parents | 734b6b0a3356 |
children | 02e2c135ee0c |
comparison
equal
deleted
inserted
replaced
621:734b6b0a3356 | 622:54e20abb5c6d |
---|---|
15 | 15 |
16 #include "collect.h" | 16 #include "collect.h" |
17 #include "debug.h" | 17 #include "debug.h" |
18 #include "exif.h" | 18 #include "exif.h" |
19 #include "filedata.h" | 19 #include "filedata.h" |
20 #include "histogram.h" | |
20 #include "image.h" | 21 #include "image.h" |
21 #include "img-view.h" | 22 #include "img-view.h" |
22 #include "layout.h" | 23 #include "layout.h" |
23 #include "pixbuf-renderer.h" | 24 #include "pixbuf-renderer.h" |
24 #include "pixbuf_util.h" | 25 #include "pixbuf_util.h" |
25 #include "histogram.h" | 26 #include "ui_fileops.h" |
26 | |
27 | 27 |
28 /* | 28 /* |
29 *---------------------------------------------------------------------------- | 29 *---------------------------------------------------------------------------- |
30 * image overlay | 30 * image overlay |
31 *---------------------------------------------------------------------------- | 31 *---------------------------------------------------------------------------- |
181 prev = 0; | 181 prev = 0; |
182 last = FALSE; | 182 last = FALSE; |
183 | 183 |
184 while (TRUE) | 184 while (TRUE) |
185 { | 185 { |
186 gint was_digit = 0; | |
187 gint limit = 0; | 186 gint limit = 0; |
188 gchar *trunc = NULL; | 187 gchar *trunc = NULL; |
188 gchar *limpos = NULL; | |
189 gchar *extra = NULL; | |
190 gchar *extrapos = NULL; | |
189 gchar *p; | 191 gchar *p; |
190 | 192 |
191 start = strchr(new->str, delim); | 193 start = strchr(new->str, delim); |
192 if (!start) | 194 if (!start) |
193 break; | 195 break; |
194 end = strchr(start+1, delim); | 196 end = strchr(start+1, delim); |
195 if (!end) | 197 if (!end) |
196 break; | 198 break; |
197 | 199 |
198 for (p = end; p > start; p--) | 200 /* Search for optionnal modifiers |
199 { | 201 * %name:99:extra% -> name = "name", limit=99, extra = "extra" |
200 if (*p == ':' && was_digit) | 202 */ |
201 { | 203 for (p = start + 1; p < end; p++) |
202 trunc = p; | 204 { |
203 break; | 205 if (p[0] == ':') |
204 } | 206 { |
205 was_digit = g_ascii_isdigit(*p); | 207 if (g_ascii_isdigit(p[1]) && !limpos) |
206 } | 208 { |
207 | 209 limpos = p + 1; |
208 if (trunc) limit = atoi(trunc+1); | 210 if (!trunc) trunc = p; |
209 | 211 } |
210 name = g_strndup(start+1, ((limit > 0) ? trunc : end)-start-1); | 212 else |
211 | 213 { |
214 extrapos = p + 1; | |
215 if (!trunc) trunc = p; | |
216 break; | |
217 } | |
218 } | |
219 } | |
220 | |
221 if (limpos) | |
222 limit = atoi(limpos); | |
223 | |
224 if (extrapos) | |
225 extra = g_strndup(extrapos, end - extrapos); | |
226 | |
227 name = g_strndup(start+1, (trunc ? trunc : end)-start-1); | |
228 | |
212 pos = start-new->str; | 229 pos = start-new->str; |
213 data = g_strdup(g_hash_table_lookup(vars, name)); | 230 data = g_strdup(g_hash_table_lookup(vars, name)); |
214 if (data && strcmp(name, "zoom") == 0) imd->overlay_show_zoom = TRUE; | 231 if (data && strcmp(name, "zoom") == 0) imd->overlay_show_zoom = TRUE; |
215 if (!data && exif) | 232 if (!data && exif) |
216 data = exif_get_data_as_text(exif, name); | 233 data = exif_get_data_as_text(exif, name); |
218 { | 235 { |
219 gchar *new_data = g_strdup_printf("%-*.*s...", limit, limit, data); | 236 gchar *new_data = g_strdup_printf("%-*.*s...", limit, limit, data); |
220 g_free(data); | 237 g_free(data); |
221 data = new_data; | 238 data = new_data; |
222 } | 239 } |
240 | |
223 if (data) | 241 if (data) |
224 { | 242 { |
225 /* Since we use pango markup to display, we need to escape here */ | 243 /* Since we use pango markup to display, we need to escape here */ |
226 gchar *escaped = g_markup_escape_text(data, -1); | 244 gchar *escaped = g_markup_escape_text(data, -1); |
227 g_free(data); | 245 g_free(data); |
228 data = escaped; | 246 data = escaped; |
229 } | 247 } |
248 | |
249 if (extra) | |
250 { | |
251 if (data && *data) | |
252 { | |
253 /* Display data between left and right parts of extra string | |
254 * the data is expressed by a '*' character. | |
255 * If no "*" is present, the extra string is just appended to data string. | |
256 * Pango mark up is accepted in left and right parts. | |
257 * Any \n is replaced by a newline | |
258 * Examples: | |
259 * "<i>*</i>\n" -> data is displayed in italics ended with a newline | |
260 * "\n" -> ended with newline | |
261 * "ISO *" -> prefix data with "ISO " (ie. "ISO 100") | |
262 * "Collection <b>*</b>\n" -> display data in bold prefixed by "Collection " and a newline is appended | |
263 * | |
264 * FIXME: using background / foreground colors lead to weird results. | |
265 */ | |
266 gchar *new_data; | |
267 gchar *left = NULL; | |
268 gchar *right = extra; | |
269 gchar *p; | |
270 gint len = strlen(extra); | |
271 | |
272 /* Search and replace "\n" by a newline character */ | |
273 for (p = extra; *p; p++, len--) | |
274 if (p[0] == '\\' && p[1] == 'n') | |
275 { | |
276 memmove(p+1, p+2, --len); | |
277 *p = '\n'; | |
278 } | |
279 | |
280 /* Search for left and right parts */ | |
281 for (p = extra; *p; p++) | |
282 if (*p == '*') | |
283 { | |
284 *p = '\0'; | |
285 p++; | |
286 right = p; | |
287 left = extra; | |
288 break; | |
289 } | |
290 | |
291 new_data = g_strdup_printf("%s%s%s", left ? left : "", data, right); | |
292 g_free(data); | |
293 data = new_data; | |
294 } | |
295 g_free(extra); | |
296 } | |
297 | |
230 g_string_erase(new, pos, end-start+1); | 298 g_string_erase(new, pos, end-start+1); |
231 if (data) | 299 if (data) |
232 g_string_insert(new, pos, data); | 300 g_string_insert(new, pos, data); |
301 | |
233 if (pos-prev == 2 && new->str[pos-1] == imp) | 302 if (pos-prev == 2 && new->str[pos-1] == imp) |
234 { | 303 { |
235 g_string_erase(new, --pos, 1); | 304 g_string_erase(new, --pos, 1); |
236 if (last && data) | 305 if (last && data) |
237 { | 306 { |
301 } | 370 } |
302 | 371 |
303 cd = image_get_collection(imd, &info); | 372 cd = image_get_collection(imd, &info); |
304 if (cd) | 373 if (cd) |
305 { | 374 { |
306 gchar *buf; | 375 gchar *collection_name; |
307 | 376 |
308 t = g_list_length(cd->list); | 377 t = g_list_length(cd->list); |
309 n = g_list_index(cd->list, info) + 1; | 378 n = g_list_index(cd->list, info) + 1; |
310 buf = g_markup_escape_text((cd->name) ? cd->name : _("Untitled"), -1); | 379 if (cd->name) |
311 ct = g_strdup_printf("<i>%s</i>\n", buf); | 380 { |
312 g_free(buf); | 381 if (file_extension_match(cd->name, ".gqv")) |
382 collection_name = remove_extension_from_path(cd->name); | |
383 else | |
384 collection_name = g_strdup(cd->name); | |
385 } | |
386 else | |
387 { | |
388 collection_name = g_strdup(_("Untitled")); | |
389 } | |
390 | |
391 ct = g_markup_escape_text(collection_name, -1); | |
392 g_free(collection_name); | |
313 } | 393 } |
314 else | 394 else |
315 { | 395 { |
316 lw = layout_find_by_image(imd); | 396 lw = layout_find_by_image(imd); |
317 if (lw) | 397 if (lw) |