/* Private macros and constants. */
/*===========================================*/
-#define MARGIN
+#define MARGIN 2
#define SHADOW_OFFSET 3
GtkWidget *canvas;
- gint height;
- gint width;
-
lglTemplate *template;
- gdouble scale;
- gdouble offset_x;
- gdouble offset_y;
gint labels_per_sheet;
LabelCenter *centers;
gdouble x,
gdouble y);
+static gdouble set_transform_and_get_scale (glMiniPreview *this,
+ cairo_t *cr);
+
/****************************************************************************/
/* Object infrastructure. */
{
gl_debug (DEBUG_MINI_PREVIEW, "START");
- this->priv->height = height;
- this->priv->width = width;
-
gtk_widget_set_size_request (GTK_WIDGET (this->priv->canvas), width, height);
gl_debug (DEBUG_MINI_PREVIEW, "END");
lgl_template_free (this->priv->template);
this->priv->template = lgl_template_dup (template);
- /*
- * Set scale and offsets
- */
- w = this->priv->width - 2*MARGIN - 2*SHADOW_OFFSET;
- h = this->priv->height - 2*MARGIN - 2*SHADOW_OFFSET;
- if ( (w/template->page_width) > (h/template->page_height) ) {
- this->priv->scale = h / template->page_height;
- } else {
- this->priv->scale = w / template->page_width;
- }
- this->priv->offset_x = (this->priv->width/this->priv->scale - template->page_width) / 2.0;
- this->priv->offset_y = (this->priv->height/this->priv->scale - template->page_height) / 2.0;
-
/*
* Set labels per sheet
*/
}
+/*--------------------------------------------------------------------------*/
+/* Set transformation and return scale. */
+/*--------------------------------------------------------------------------*/
+static gdouble
+set_transform_and_get_scale (glMiniPreview *this,
+ cairo_t *cr)
+{
+ lglTemplate *template = this->priv->template;
+ gdouble w, h;
+ gdouble w1, h1;
+ gdouble scale;
+ gdouble offset_x, offset_y;
+
+ /* Establish scale and origin. */
+ w = GTK_WIDGET (this)->allocation.width;
+ h = GTK_WIDGET (this)->allocation.height;
+
+ /* establish scale. */
+ scale = MIN( (w - 2*MARGIN - 2*SHADOW_OFFSET)/template->page_width,
+ (h - 2*MARGIN - 2*SHADOW_OFFSET)/template->page_height );
+
+ /* Find offset to center preview. */
+ offset_x = (w/scale - template->page_width) / 2.0;
+ offset_y = (h/scale - template->page_height) / 2.0;
+
+ /* Set transformation. */
+ cairo_scale (cr, scale, scale);
+ cairo_translate (cr, offset_x, offset_y);
+
+ return scale;
+}
+
+
/*--------------------------------------------------------------------------*/
/* Button press event handler */
/*--------------------------------------------------------------------------*/
{
glMiniPreview *this = GL_MINI_PREVIEW (widget);
cairo_t *cr;
+ gdouble scale;
gdouble x, y;
gint i;
{
cr = gdk_cairo_create (GTK_WIDGET (this->priv->canvas)->window);
- /* Set transformation. */
- cairo_scale (cr, this->priv->scale, this->priv->scale);
- cairo_translate (cr, this->priv->offset_x, this->priv->offset_y);
+ scale = set_transform_and_get_scale (this, cr);
x = event->x;
y = event->y;
{
glMiniPreview *this = GL_MINI_PREVIEW (widget);
cairo_t *cr;
+ gdouble scale;
gdouble x, y;
gint i;
{
cr = gdk_cairo_create (GTK_WIDGET (this->priv->canvas)->window);
- /* Set transformation. */
- cairo_scale (cr, this->priv->scale, this->priv->scale);
- cairo_translate (cr, this->priv->offset_x, this->priv->offset_y);
+ scale = set_transform_and_get_scale (this, cr);
x = event->x;
y = event->y;
cairo_t *cr)
{
lglTemplate *template = this->priv->template;
+ gdouble scale;
gdouble shadow_x, shadow_y;
+
gl_debug (DEBUG_MINI_PREVIEW, "START");
if (template)
{
- /* Set transformation. */
- cairo_scale (cr, this->priv->scale, this->priv->scale);
- cairo_translate (cr, this->priv->offset_x, this->priv->offset_y);
-
+ scale = set_transform_and_get_scale (this, cr);
/* update shadow */
- shadow_x = SHADOW_OFFSET/this->priv->scale;
- shadow_y = SHADOW_OFFSET/this->priv->scale;
+ shadow_x = SHADOW_OFFSET/scale;
+ shadow_y = SHADOW_OFFSET/scale;
draw_shadow (this, cr,
shadow_x, shadow_y,
draw_paper (this, cr,
template->page_width, template->page_height,
- 1.0/this->priv->scale);
+ 1.0/scale);
- draw_labels (this, cr, template, 1.0/this->priv->scale);
+ draw_labels (this, cr, template, 1.0/scale);
}