use NULL as the special value, not "silent".

2006-06-27  Sven Neumann  <sven@gimp.org>

	* libgimp/gimpexport.c (gimp_export_image): use NULL as the
	special value, not "silent".

	* plug-ins/print/print-draw-page.c: changed accordingly.  Also
	fixed handling of filename encoding.
This commit is contained in:
Sven Neumann 2006-06-27 06:41:38 +00:00 committed by Sven Neumann
parent d7a6a776dc
commit 824b31e454
3 changed files with 60 additions and 39 deletions

View File

@ -1,3 +1,11 @@
2006-06-27 Sven Neumann <sven@gimp.org>
* libgimp/gimpexport.c (gimp_export_image): use NULL as the
special value, not "silent".
* plug-ins/print/print-draw-page.c: changed accordingly. Also
fixed handling of filename encoding.
2006-06-26 Bill Skaggs <weskaggs@primate.ucdavis.edu> 2006-06-26 Bill Skaggs <weskaggs@primate.ucdavis.edu>
* libgimp/gimpexport.c: if format arg is "silent", export * libgimp/gimpexport.c: if format arg is "silent", export

View File

@ -645,9 +645,7 @@ gimp_export_image (gint32 *image_ID,
gboolean added_flatten = FALSE; gboolean added_flatten = FALSE;
gboolean has_layer_masks = FALSE; gboolean has_layer_masks = FALSE;
gboolean background_has_alpha = TRUE; gboolean background_has_alpha = TRUE;
ExportAction *action; GimpExportReturn retval = GIMP_EXPORT_CANCEL;
GimpExportReturn retval = GIMP_EXPORT_CANCEL;
gboolean silent = (0 == strcmp (format_name, "silent"));
g_return_val_if_fail (*image_ID > -1 && *drawable_ID > -1, FALSE); g_return_val_if_fail (*image_ID > -1 && *drawable_ID > -1, FALSE);
@ -665,7 +663,8 @@ gimp_export_image (gint32 *image_ID,
capabilities |= GIMP_EXPORT_CAN_HANDLE_ALPHA; capabilities |= GIMP_EXPORT_CAN_HANDLE_ALPHA;
/* ask for confirmation if the user is not saving a layer (see bug #51114) */ /* ask for confirmation if the user is not saving a layer (see bug #51114) */
if (! gimp_drawable_is_layer (*drawable_ID) && if (format_name &&
! gimp_drawable_is_layer (*drawable_ID) &&
! (capabilities & GIMP_EXPORT_CAN_HANDLE_LAYERS)) ! (capabilities & GIMP_EXPORT_CAN_HANDLE_LAYERS))
{ {
if (gimp_drawable_is_layer_mask (*drawable_ID)) if (gimp_drawable_is_layer_mask (*drawable_ID))
@ -867,10 +866,11 @@ gimp_export_image (gint32 *image_ID,
if (actions) if (actions)
{ {
actions = g_slist_reverse (actions); actions = g_slist_reverse (actions);
if (silent)
retval = GIMP_EXPORT_EXPORT; if (format_name)
else
retval = export_dialog (actions, format_name); retval = export_dialog (actions, format_name);
else
retval = GIMP_EXPORT_EXPORT;
} }
else else
{ {
@ -886,7 +886,7 @@ gimp_export_image (gint32 *image_ID,
for (list = actions; list; list = list->next) for (list = actions; list; list = list->next)
{ {
action = (ExportAction *) list->data; ExportAction *action = list->data;
if (action->choice == 0 && action->default_action) if (action->choice == 0 && action->default_action)
action->default_action (*image_ID, drawable_ID); action->default_action (*image_ID, drawable_ID);

View File

@ -19,6 +19,7 @@
#include "config.h" #include "config.h"
#include <string.h> #include <string.h>
#include <time.h>
#include <libgimp/gimp.h> #include <libgimp/gimp.h>
#include <libgimp/gimpui.h> #include <libgimp/gimpui.h>
@ -26,17 +27,19 @@
#include "print.h" #include "print.h"
#include "print-draw-page.h" #include "print-draw-page.h"
/* In points */ /* In points */
#define HEADER_HEIGHT (20*72/25.4) #define HEADER_HEIGHT (20*72/25.4)
static guchar * get_image_pixels (PrintData *data, static guchar * get_image_pixels (PrintData *data,
gint *width_ptr, gint *width_ptr,
gint *height_ptr, gint *height_ptr,
gint *rowstride_ptr); gint *rowstride_ptr);
static void draw_info_header (GtkPrintContext *context,
cairo_t *cr,
PrintData *data);
static void draw_info_header (GtkPrintContext *context,
cairo_t *cr,
PrintData *data);
void void
draw_page_cairo (GtkPrintContext *context, draw_page_cairo (GtkPrintContext *context,
@ -75,7 +78,7 @@ draw_page_cairo (GtkPrintContext *context,
if (scale_x * image_width > cr_width) if (scale_x * image_width > cr_width)
{ {
g_message ("Image width (%lg in) is larger than printable width (%lg in).", g_message ("Image width (%g in) is larger than printable width (%g in).",
image_width / image_xres, cr_width / cr_dpi_x); image_width / image_xres, cr_width / cr_dpi_x);
gtk_print_operation_cancel (data->operation); gtk_print_operation_cancel (data->operation);
return; return;
@ -83,7 +86,7 @@ draw_page_cairo (GtkPrintContext *context,
if (scale_y * image_height > cr_height) if (scale_y * image_height > cr_height)
{ {
g_message ("Image height (%lg in) is larger than printable height (%lg in).", g_message ("Image height (%g in) is larger than printable height (%g in).",
image_height / image_yres, cr_height / cr_dpi_y); image_height / image_yres, cr_height / cr_dpi_y);
gtk_print_operation_cancel (data->operation); gtk_print_operation_cancel (data->operation);
return; return;
@ -134,7 +137,7 @@ get_image_pixels (PrintData *data,
gint i; gint i;
/* export the image */ /* export the image */
gimp_export_image (&image_id, &drawable_id, "silent", gimp_export_image (&image_id, &drawable_id, NULL,
GIMP_EXPORT_CAN_HANDLE_RGB | GIMP_EXPORT_CAN_HANDLE_RGB |
GIMP_EXPORT_CAN_HANDLE_ALPHA | GIMP_EXPORT_CAN_HANDLE_ALPHA |
GIMP_EXPORT_NEEDS_ALPHA); GIMP_EXPORT_NEEDS_ALPHA);
@ -155,14 +158,17 @@ get_image_pixels (PrintData *data,
if (image_id != data->image_id) if (image_id != data->image_id)
gimp_image_delete (image_id); gimp_image_delete (image_id);
/* knock pixels into the shape cairo wants: /* knock pixels into the shape requested by cairo:
* CAIRO_FORMAT_ARGB32: each pixel is a 32-bit quantity, with alpha in the upper 8 bits, *
* then red, then green, then blue. The 32-bit quantities are stored native-endian. * CAIRO_FORMAT_ARGB32:
* Pre-multiplied alpha is used. * each pixel is a 32-bit quantity, with alpha in the upper 8 bits,
* then red, then green, then blue. The 32-bit quantities are
* stored native-endian. Pre-multiplied alpha is used.
* *
*/ */
cairo_data = (guint32 *) pixels; cairo_data = (guint32 *) pixels;
len = width * height; len = width * height;
for (i = 0, p = pixels; i < len; i++) for (i = 0, p = pixels; i < len; i++)
{ {
guint32 r = *p++; guint32 r = *p++;
@ -202,12 +208,12 @@ draw_info_header (GtkPrintContext *context,
gdouble fname_text_width; gdouble fname_text_width;
gint layout_height; gint layout_height;
gint layout_width; gint layout_width;
GTimeVal time_val;
gchar date_buffer[100]; gchar date_buffer[100];
GDate *date; GDate *date;
const gchar *name_str; const gchar *name_str;
GimpParasite *parasite; GimpParasite *parasite;
const gchar *end_ptr; const gchar *end_ptr;
gchar *filename;
gdouble cr_width; gdouble cr_width;
cairo_save (cr); cairo_save (cr);
@ -234,7 +240,7 @@ draw_info_header (GtkPrintContext *context,
pango_layout_set_text (layout, gimp_image_get_name (data->image_id), -1); pango_layout_set_text (layout, gimp_image_get_name (data->image_id), -1);
pango_layout_get_size (layout, &layout_width, &layout_height); pango_layout_get_size (layout, &layout_width, &layout_height);
text_height = (gdouble)layout_height / PANGO_SCALE; text_height = (gdouble) layout_height / PANGO_SCALE;
cairo_move_to (cr, 0.02 * cr_width, (HEADER_HEIGHT - text_height) / 5); cairo_move_to (cr, 0.02 * cr_width, (HEADER_HEIGHT - text_height) / 5);
pango_cairo_show_layout (cr, layout); pango_cairo_show_layout (cr, layout);
@ -246,7 +252,7 @@ draw_info_header (GtkPrintContext *context,
pango_layout_set_text (layout, name_str, -1); pango_layout_set_text (layout, name_str, -1);
pango_layout_get_size (layout, &layout_width, &layout_height); pango_layout_get_size (layout, &layout_width, &layout_height);
text_height = (gdouble)layout_height / PANGO_SCALE; text_height = (gdouble) layout_height / PANGO_SCALE;
text_width = (gdouble) layout_width / PANGO_SCALE; text_width = (gdouble) layout_width / PANGO_SCALE;
cairo_move_to (cr, 0.5 * cr_width - 0.5 * text_width, cairo_move_to (cr, 0.5 * cr_width - 0.5 * text_width,
@ -255,9 +261,8 @@ draw_info_header (GtkPrintContext *context,
} }
/* date */ /* date */
g_get_current_time (&time_val);
date = g_date_new (); date = g_date_new ();
g_date_set_time_t (date, time_val.tv_sec); g_date_set_time_t (date, time (NULL));
g_date_strftime (date_buffer, 100, "%x", date); g_date_strftime (date_buffer, 100, "%x", date);
g_date_free (date); g_date_free (date);
pango_layout_set_text (layout, date_buffer, -1); pango_layout_set_text (layout, date_buffer, -1);
@ -266,33 +271,43 @@ draw_info_header (GtkPrintContext *context,
text_height = (gdouble) layout_height / PANGO_SCALE; text_height = (gdouble) layout_height / PANGO_SCALE;
text_width = (gdouble) layout_width / PANGO_SCALE; text_width = (gdouble) layout_width / PANGO_SCALE;
cairo_move_to (cr, 0.98 * cr_width - text_width, (HEADER_HEIGHT - text_height) / 5); cairo_move_to (cr,
0.98 * cr_width - text_width,
(HEADER_HEIGHT - text_height) / 5);
pango_cairo_show_layout (cr, layout); pango_cairo_show_layout (cr, layout);
/* file name if any */ /* file name if any */
if (gimp_image_get_filename (data->image_id)) filename = gimp_image_get_filename (data->image_id);
if (filename)
{ {
pango_layout_set_text (layout, gimp_image_get_filename (data->image_id), -1); pango_layout_set_text (layout,
gimp_filename_to_uft8 (filename), -1);
g_free (filename);
pango_layout_get_size (layout, &layout_width, &layout_height); pango_layout_get_size (layout, &layout_width, &layout_height);
text_height = (gdouble)layout_height / PANGO_SCALE; text_height = (gdouble) layout_height / PANGO_SCALE;
fname_text_width = (gdouble)layout_width / PANGO_SCALE; fname_text_width = (gdouble) layout_width / PANGO_SCALE;
cairo_move_to (cr, 0.02 * cr_width, 4 * (HEADER_HEIGHT - text_height) / 5); cairo_move_to (cr,
0.02 * cr_width, 4 * (HEADER_HEIGHT - text_height) / 5);
pango_cairo_show_layout (cr, layout); pango_cairo_show_layout (cr, layout);
} }
else else
fname_text_width = 0; {
fname_text_width = 0;
}
/* image comment if it is short */ /* image comment if it is short */
parasite = gimp_image_parasite_find (data->image_id, "gimp-comment"); parasite = gimp_image_parasite_find (data->image_id, "gimp-comment");
if (parasite) if (parasite)
{ {
pango_layout_set_text (layout, gimp_parasite_data (parasite), -1); pango_layout_set_text (layout, gimp_parasite_data (parasite), -1);
pango_layout_get_size (layout, &layout_width, &layout_height); pango_layout_get_size (layout, &layout_width, &layout_height);
text_height = (gdouble)layout_height / PANGO_SCALE; text_height = (gdouble) layout_height / PANGO_SCALE;
text_width = (gdouble)layout_width / PANGO_SCALE; text_width = (gdouble) layout_width / PANGO_SCALE;
if (fname_text_width + text_width < 0.8 * cr_width && if (fname_text_width + text_width < 0.8 * cr_width &&
text_height < 0.5 * HEADER_HEIGHT) text_height < 0.5 * HEADER_HEIGHT)
@ -301,6 +316,7 @@ draw_info_header (GtkPrintContext *context,
4 * (HEADER_HEIGHT - text_height) / 5); 4 * (HEADER_HEIGHT - text_height) / 5);
pango_cairo_show_layout (cr, layout); pango_cairo_show_layout (cr, layout);
} }
gimp_parasite_free (parasite); gimp_parasite_free (parasite);
} }
@ -308,6 +324,3 @@ draw_info_header (GtkPrintContext *context,
cairo_restore (cr); cairo_restore (cr);
} }