\n\
",
self->priv->header);
g_data_output_stream_put_string (self->priv->imagemap_stream,
line,
gth_task_get_cancellable (GTH_TASK (self)),
&error);
g_free (line);
uri = g_file_get_uri (self->priv->destination_file);
line = g_strdup_printf ("

\n",
uri,
width,
height,
uri);
g_data_output_stream_put_string (self->priv->imagemap_stream,
line,
gth_task_get_cancellable (GTH_TASK (self)),
&error);
g_free (line);
g_data_output_stream_put_string (self->priv->imagemap_stream,
"
\n",
gth_task_get_cancellable (GTH_TASK (self)),
error))
{
return FALSE;
}
if (! g_data_output_stream_put_string (self->priv->imagemap_stream,
"\
\n\
\n\
\n\
",
gth_task_get_cancellable (GTH_TASK (self)),
error))
{
return FALSE;
}
if (! g_output_stream_close (G_OUTPUT_STREAM (self->priv->imagemap_stream),
gth_task_get_cancellable (GTH_TASK (self)),
error))
{
return FALSE;
}
self->priv->created_files = g_list_prepend (self->priv->created_files, g_object_ref (self->priv->imagemap_file));
}
return TRUE;
}
/* -- get_text -- */
static gboolean
text_template_eval_cb (TemplateFlags flags,
gunichar parent_code,
gunichar code,
char **args,
GString *result,
gpointer user_data)
{
TemplateData *template_data = user_data;
char *text = NULL;
if (parent_code == 'D') {
/* strftime code, return the code itself. */
_g_string_append_template_code (result, code, args);
return FALSE;
}
switch (code) {
case 'p':
text = g_strdup_printf ("%d", template_data->page);
break;
case 'n':
text = g_strdup_printf ("%d", template_data->creator->priv->n_pages);
break;
case 'D':
text = g_date_time_format (template_data->creator->priv->timestamp,
(args[0] != NULL) ? args[0] : DEFAULT_STRFTIME_FORMAT);
break;
case 'L':
if (template_data->creator->priv->location_name != NULL)
g_string_append (result, template_data->creator->priv->location_name);
break;
default:
break;
}
if (text != NULL) {
g_string_append (result, text);
g_free (text);
}
return FALSE;
}
static char *
get_text (GthContactSheetCreator *self,
const char *text,
int page_n)
{
TemplateData template_data;
template_data.creator = self;
template_data.page = page_n;
return _g_template_eval (text,
0,
text_template_eval_cb,
&template_data);
}
static void
paint_text (GthContactSheetCreator *self,
const char *font_name,
GdkRGBA *color,
int x,
int y,
int width,
const char *text,
int *height)
{
PangoFontDescription *font_desc;
PangoRectangle bounds;
if (font_name != NULL)
font_desc = pango_font_description_from_string (font_name);
else
font_desc = pango_font_description_from_string (DEFAULT_FONT);
pango_layout_set_font_description (self->priv->pango_layout, font_desc);
pango_layout_set_width (self->priv->pango_layout, width * PANGO_SCALE);
pango_layout_set_wrap (self->priv->pango_layout, PANGO_WRAP_WORD_CHAR);
pango_layout_set_text (self->priv->pango_layout, text, -1);
pango_layout_get_pixel_extents (self->priv->pango_layout, NULL, &bounds);
x += self->priv->theme->frame_border;
cairo_save (self->priv->cr);
gdk_cairo_set_source_rgba (self->priv->cr, color);
pango_cairo_update_layout (self->priv->cr, self->priv->pango_layout);
cairo_move_to (self->priv->cr, x, y);
pango_cairo_show_layout (self->priv->cr, self->priv->pango_layout);
cairo_restore (self->priv->cr);
#if 0
cairo_set_source_rgb (self->priv->cr, 1.0, 0.0, 0.0);
cairo_rectangle (self->priv->cr, x, y, width, bounds.height);
cairo_stroke (self->priv->cr);
#endif
if (font_desc != NULL)
pango_font_description_free (font_desc);
if (height != NULL)
*height = bounds.height;
}
static void
paint_footer (GthContactSheetCreator *self,
int page_n)
{
char *text;
if (self->priv->footer == NULL)
return;
text = get_text (self, self->priv->footer, page_n);
paint_text (self,
self->priv->theme->footer_font_name,
&self->priv->theme->footer_color,
0,
get_page_height (self, page_n) - get_footer_height (self, FALSE) - self->priv->theme->row_spacing / 2,
self->priv->page_width,
text,
NULL);
g_free (text);
}
static void
paint_frame (GthContactSheetCreator *self,
cairo_rectangle_int_t *frame_rect,
cairo_rectangle_int_t *image_rect,
GthFileData *file_data)
{
gth_contact_sheet_theme_paint_frame (self->priv->theme, self->priv->cr, frame_rect, image_rect);
if (self->priv->imagemap_stream != NULL) {
char *file;
char *destination;
char *relative_path;
char *alt_attribute;
char *line;
GError *error = NULL;
file = g_file_get_uri (file_data->file);
destination = g_file_get_uri (self->priv->destination);
relative_path = _g_uri_get_relative_path (file, destination);
alt_attribute = _g_utf8_escape_xml (relative_path);
line = g_strdup_printf ("