Add the possibility to truncate overlay infos displayed:
authorLaurent Monin <geeqie@norz.org>
Thu, 10 Apr 2008 10:43:15 +0000 (10:43 +0000)
committerLaurent Monin <geeqie@norz.org>
Thu, 10 Apr 2008 10:43:15 +0000 (10:43 +0000)
%fCamera:20% will truncate data displayed to 20 characters
and add 3 dots at the end.
For example, %name% -> some_file, %name:4% -> some...

src/image-overlay.c
src/preferences.c

index c6118a7..0cec98a 100644 (file)
@@ -139,19 +139,43 @@ static gchar *image_osd_mkinfo(const gchar *str, ImageWindow *imd, GHashTable *v
 
        while (TRUE)
                {
+               gint was_digit = 0;
+               gint limit = 0;
+               gchar *trunc = NULL;
+               gchar *p;
+
                start = strchr(new->str, delim);
                if (!start)
                        break;
                end = strchr(start+1, delim);
                if (!end)
                        break;
+               
+               for (p = end; p > start; p--)
+                       {
+                       if (*p == ':' && was_digit)
+                               {
+                               trunc = p;
+                               break;
+                               }
+                       was_digit = (*p >= '0' && *p <= '9');
+                       }
+
+               if (trunc) limit = atoi(trunc+1);
+
+               name = g_strndup(start+1, ((limit > 0) ? trunc : end)-start-1);
 
-               name = g_strndup(start+1, end-start-1);
                pos = start-new->str;
                data = g_strdup(g_hash_table_lookup(vars, name));
                if (!data && exif)
                        data = exif_get_data_as_text(exif, name);
-
+               if (data && *data && limit > 0)
+                       {
+                       gchar *new_data = g_strdup_printf("%-*.*s...", limit, limit, data);
+                       g_free(data);
+                       data = new_data;
+                       }
+               
                g_string_erase(new, pos, end-start+1);
                if (data)
                        g_string_insert(new, pos, data);
index 309efb6..9c412c2 100644 (file)
@@ -1354,6 +1354,7 @@ static void config_tab_advanced(GtkWidget *notebook)
          "<i>%size%</i> (filesize), <i>%width%</i>, <i>%height%</i>, <i>%res%</i> (resolution)\n"
          "To access exif data use the exif name, e. g. <i>%fCamera%</i> is the formatted camera name,\n"
          "<i>%Exif.Photo.DateTimeOriginal%</i> the date of the original shot.\n"
+         "<i>%fCamera:20</i> notation will truncate the displayed data to 20 characters and will add 3 dots at the end to denote the truncation.\n"
          "If two or more variables are connected with the |-sign, it prints available variables with a separator.\n"
          "<i>%fShutterSpeed%</i>|<i>%fISOSpeedRating%</i>|<i>%fFocalLength%</i> could show \"1/20s - 400 - 80 mm\" or \"1/200 - 80 mm\",\n"
          "if there's no ISO information in the Exif data.\n"