Skip to content

Commit

Permalink
Fix display of collection in overlay info.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Laurent Monin committed May 10, 2008
1 parent fc25dbb commit 0cbf328
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 19 deletions.
110 changes: 95 additions & 15 deletions src/image-overlay.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
#include "debug.h"
#include "exif.h"
#include "filedata.h"
#include "histogram.h"
#include "image.h"
#include "img-view.h"
#include "layout.h"
#include "pixbuf-renderer.h"
#include "pixbuf_util.h"
#include "histogram.h"

#include "ui_fileops.h"

/*
*----------------------------------------------------------------------------
Expand Down Expand Up @@ -183,9 +183,11 @@ 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 *limpos = NULL;
gchar *extra = NULL;
gchar *extrapos = NULL;
gchar *p;

start = strchr(new->str, delim);
Expand All @@ -195,20 +197,35 @@ static gchar *image_osd_mkinfo(const gchar *str, ImageWindow *imd, GHashTable *v
if (!end)
break;

for (p = end; p > start; p--)
/* Search for optionnal modifiers
* %name:99:extra% -> name = "name", limit=99, extra = "extra"
*/
for (p = start + 1; p < end; p++)
{
if (*p == ':' && was_digit)
if (p[0] == ':')
{
trunc = p;
break;
if (g_ascii_isdigit(p[1]) && !limpos)
{
limpos = p + 1;
if (!trunc) trunc = p;
}
else
{
extrapos = p + 1;
if (!trunc) trunc = p;
break;
}
}
was_digit = g_ascii_isdigit(*p);
}

if (trunc) limit = atoi(trunc+1);

name = g_strndup(start+1, ((limit > 0) ? trunc : end)-start-1);
if (limpos)
limit = atoi(limpos);

if (extrapos)
extra = g_strndup(extrapos, end - extrapos);

name = g_strndup(start+1, (trunc ? trunc : end)-start-1);

pos = start-new->str;
data = g_strdup(g_hash_table_lookup(vars, name));
if (data && strcmp(name, "zoom") == 0) imd->overlay_show_zoom = TRUE;
Expand All @@ -220,16 +237,68 @@ static gchar *image_osd_mkinfo(const gchar *str, ImageWindow *imd, GHashTable *v
g_free(data);
data = new_data;
}

if (data)
{
/* Since we use pango markup to display, we need to escape here */
gchar *escaped = g_markup_escape_text(data, -1);
g_free(data);
data = escaped;
}

if (extra)
{
if (data && *data)
{
/* Display data between left and right parts of extra string
* the data is expressed by a '*' character.
* If no "*" is present, the extra string is just appended to data string.
* Pango mark up is accepted in left and right parts.
* Any \n is replaced by a newline
* Examples:
* "<i>*</i>\n" -> data is displayed in italics ended with a newline
* "\n" -> ended with newline
* "ISO *" -> prefix data with "ISO " (ie. "ISO 100")
* "Collection <b>*</b>\n" -> display data in bold prefixed by "Collection " and a newline is appended
*
* FIXME: using background / foreground colors lead to weird results.
*/
gchar *new_data;
gchar *left = NULL;
gchar *right = extra;
gchar *p;
gint len = strlen(extra);

/* Search and replace "\n" by a newline character */
for (p = extra; *p; p++, len--)
if (p[0] == '\\' && p[1] == 'n')
{
memmove(p+1, p+2, --len);
*p = '\n';
}

/* Search for left and right parts */
for (p = extra; *p; p++)
if (*p == '*')
{
*p = '\0';
p++;
right = p;
left = extra;
break;
}

new_data = g_strdup_printf("%s%s%s", left ? left : "", data, right);
g_free(data);
data = new_data;
}
g_free(extra);
}

g_string_erase(new, pos, end-start+1);
if (data)
g_string_insert(new, pos, data);

if (pos-prev == 2 && new->str[pos-1] == imp)
{
g_string_erase(new, --pos, 1);
Expand Down Expand Up @@ -303,13 +372,24 @@ static GdkPixbuf *image_osd_info_render(OverlayStateData *osd)
cd = image_get_collection(imd, &info);
if (cd)
{
gchar *buf;
gchar *collection_name;

t = g_list_length(cd->list);
n = g_list_index(cd->list, info) + 1;
buf = g_markup_escape_text((cd->name) ? cd->name : _("Untitled"), -1);
ct = g_strdup_printf("<i>%s</i>\n", buf);
g_free(buf);
if (cd->name)
{
if (file_extension_match(cd->name, ".gqv"))
collection_name = remove_extension_from_path(cd->name);
else
collection_name = g_strdup(cd->name);
}
else
{
collection_name = g_strdup(_("Untitled"));
}

ct = g_markup_escape_text(collection_name, -1);
g_free(collection_name);
}
else
{
Expand Down
8 changes: 4 additions & 4 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@
#define PANEL_DEFAULT_WIDTH 288
#define PANEL_MAX_WIDTH 1200

#define DEFAULT_OVERLAY_INFO "%collection%(%number%/%total%) [%zoom%] <b>%name%</b>\n" \
#define DEFAULT_OVERLAY_INFO "%collection:<i>*</i>\\n%" \
"(%number%/%total%) [%zoom%] <b>%name%</b>\n" \
"%res%|%date%|%size%\n" \
"%formatted.Aperture%|%formatted.ShutterSpeed%|%formatted.ISOSpeedRating%|%formatted.FocalLength%|%formatted.ExposureBias%\n" \
"%formatted.Camera%|%formatted.Flash%" \

"%formatted.Aperture%|%formatted.ShutterSpeed%|%formatted.ISOSpeedRating:ISO *%|%formatted.FocalLength%|%formatted.ExposureBias:* Ev%\n" \
"%formatted.Camera:40%|%formatted.Flash%"

#include "typedefs.h"
#include "options.h"
Expand Down

0 comments on commit 0cbf328

Please sign in to comment.