cache the image size to avoid roundtrips
This commit is contained in:
@ -18,6 +18,8 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include <libgimp/gimp.h>
|
#include <libgimp/gimp.h>
|
||||||
#include <libgimp/gimpui.h>
|
#include <libgimp/gimpui.h>
|
||||||
|
|
||||||
@ -30,6 +32,8 @@
|
|||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
PrintData *data;
|
PrintData *data;
|
||||||
|
gint image_width;
|
||||||
|
gint image_height;
|
||||||
GimpSizeEntry *size_entry;
|
GimpSizeEntry *size_entry;
|
||||||
GimpSizeEntry *resolution_entry;
|
GimpSizeEntry *resolution_entry;
|
||||||
GimpChainButton *chain;
|
GimpChainButton *chain;
|
||||||
@ -72,6 +76,12 @@ print_page_layout_gui (PrintData *data)
|
|||||||
GtkWidget *label;
|
GtkWidget *label;
|
||||||
GtkWidget *frame;
|
GtkWidget *frame;
|
||||||
|
|
||||||
|
memset (&info, 0, sizeof (PrintSizeInfo));
|
||||||
|
|
||||||
|
info.data = data;
|
||||||
|
info.image_width = gimp_image_width (data->image_id);
|
||||||
|
info.image_height = gimp_image_height (data->image_id);
|
||||||
|
|
||||||
main_vbox = gtk_vbox_new (FALSE, 12);
|
main_vbox = gtk_vbox_new (FALSE, 12);
|
||||||
gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
|
gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
|
||||||
|
|
||||||
@ -187,11 +197,9 @@ print_size_frame (PrintData *data)
|
|||||||
gdouble image_width;
|
gdouble image_width;
|
||||||
gdouble image_height;
|
gdouble image_height;
|
||||||
|
|
||||||
info.data = data;
|
image_width = (info.image_width *
|
||||||
|
|
||||||
image_width = (gimp_image_width (data->image_id) *
|
|
||||||
gimp_unit_get_factor (data->unit) / data->xres);
|
gimp_unit_get_factor (data->unit) / data->xres);
|
||||||
image_height = (gimp_image_height (data->image_id) *
|
image_height = (info.image_height *
|
||||||
gimp_unit_get_factor (data->unit) / data->yres);
|
gimp_unit_get_factor (data->unit) / data->yres);
|
||||||
|
|
||||||
frame = gimp_frame_new (_("Image Size"));
|
frame = gimp_frame_new (_("Image Size"));
|
||||||
@ -320,22 +328,19 @@ print_size_frame (PrintData *data)
|
|||||||
static void
|
static void
|
||||||
print_size_info_size_changed (GtkWidget *widget)
|
print_size_info_size_changed (GtkWidget *widget)
|
||||||
{
|
{
|
||||||
gdouble width;
|
gdouble width;
|
||||||
gdouble height;
|
gdouble height;
|
||||||
gdouble xres;
|
gdouble xres;
|
||||||
gdouble yres;
|
gdouble yres;
|
||||||
gdouble scale;
|
gdouble scale;
|
||||||
PrintData *data = info.data;
|
|
||||||
gint image_width = gimp_image_width (data->image_id);
|
|
||||||
gint image_height = gimp_image_height (data->image_id);
|
|
||||||
|
|
||||||
scale = gimp_unit_get_factor (gimp_size_entry_get_unit (info.size_entry));
|
scale = gimp_unit_get_factor (gimp_size_entry_get_unit (info.size_entry));
|
||||||
|
|
||||||
width = gimp_size_entry_get_value (info.size_entry, 0);
|
width = gimp_size_entry_get_value (info.size_entry, 0);
|
||||||
height = gimp_size_entry_get_value (info.size_entry, 1);
|
height = gimp_size_entry_get_value (info.size_entry, 1);
|
||||||
|
|
||||||
xres = scale * image_width / MAX (0.0001, width);
|
xres = scale * info.image_width / MAX (0.0001, width);
|
||||||
yres = scale * image_height / MAX (0.0001, height);
|
yres = scale * info.image_height / MAX (0.0001, height);
|
||||||
|
|
||||||
print_size_info_set_resolution (&info, xres, yres);
|
print_size_info_set_resolution (&info, xres, yres);
|
||||||
}
|
}
|
||||||
@ -438,10 +443,10 @@ print_size_info_set_resolution (PrintSizeInfo *info,
|
|||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
gimp_size_entry_set_value (info->size_entry, 0,
|
gimp_size_entry_set_value (info->size_entry, 0,
|
||||||
gimp_image_width (data->image_id) *
|
info->image_width *
|
||||||
gimp_unit_get_factor (data->unit) / xres);
|
gimp_unit_get_factor (data->unit) / xres);
|
||||||
gimp_size_entry_set_value (info->size_entry, 1,
|
gimp_size_entry_set_value (info->size_entry, 1,
|
||||||
gimp_image_height (data->image_id) *
|
info->image_height *
|
||||||
gimp_unit_get_factor (data->unit) / yres);
|
gimp_unit_get_factor (data->unit) / yres);
|
||||||
|
|
||||||
g_signal_handlers_unblock_by_func (info->size_entry,
|
g_signal_handlers_unblock_by_func (info->size_entry,
|
||||||
@ -455,8 +460,6 @@ print_size_info_set_page_setup (PrintSizeInfo *info,
|
|||||||
{
|
{
|
||||||
PrintData *data = info->data;
|
PrintData *data = info->data;
|
||||||
gchar *text;
|
gchar *text;
|
||||||
gint image_width = gimp_image_width (data->image_id);
|
|
||||||
gint image_height = gimp_image_height (data->image_id);
|
|
||||||
gdouble page_width;
|
gdouble page_width;
|
||||||
gdouble page_height;
|
gdouble page_height;
|
||||||
gdouble x;
|
gdouble x;
|
||||||
@ -478,7 +481,9 @@ print_size_info_set_page_setup (PrintSizeInfo *info,
|
|||||||
|
|
||||||
if (info->chain && gimp_chain_button_get_active (info->chain))
|
if (info->chain && gimp_chain_button_get_active (info->chain))
|
||||||
{
|
{
|
||||||
gdouble ratio = (gdouble) image_width / (gdouble) image_height;
|
gdouble ratio;
|
||||||
|
|
||||||
|
ratio = (gdouble) info->image_width / (gdouble) info->image_height;
|
||||||
|
|
||||||
if (ratio < 1.0)
|
if (ratio < 1.0)
|
||||||
x = y * ratio;
|
x = y * ratio;
|
||||||
@ -489,8 +494,8 @@ print_size_info_set_page_setup (PrintSizeInfo *info,
|
|||||||
gimp_size_entry_set_value_boundaries (info->size_entry, 0, 0.0, x);
|
gimp_size_entry_set_value_boundaries (info->size_entry, 0, 0.0, x);
|
||||||
gimp_size_entry_set_value_boundaries (info->size_entry, 1, 0.0, y);
|
gimp_size_entry_set_value_boundaries (info->size_entry, 1, 0.0, y);
|
||||||
|
|
||||||
x = image_width / page_width;
|
x = info->image_width / page_width;
|
||||||
y = image_height / page_height;
|
y = info->image_height / page_height;
|
||||||
|
|
||||||
if (info->chain && gimp_chain_button_get_active (info->chain))
|
if (info->chain && gimp_chain_button_get_active (info->chain))
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user