Commit 935482e3 authored by Matthias Clasen's avatar Matthias Clasen Committed by Matthias Clasen

Add gtkprintutils.[hc]

2006-04-23  Matthias Clasen  <mclasen@redhat.com>

	* gtk/Makefile.am: Add gtkprintutils.[hc]

	* gtk/gtkprintutils.[hc]: New files, move the unit conversion
	functions here.

	* gtk/gtkpagesetupunixdialog.c:
	* gtk/gtkprintsettings.c:
	* gtk/gtkpagesetup.c:
	* gtk/gtkpapersize.c: Replace all static copies of to_mm/from_mm
	by the copies in gtkprintutils.c.

	* gtk/gtkpagesetup.[hc]: Use g types, add documentation.
parent 46548ae5
2006-04-23 Matthias Clasen <mclasen@redhat.com>
* gtk/Makefile.am: Add gtkprintutils.[hc]
* gtk/gtkprintutils.[hc]: New files, move the unit conversion
functions here.
* gtk/gtkpagesetupunixdialog.c:
* gtk/gtkprintsettings.c:
* gtk/gtkpagesetup.c:
* gtk/gtkpapersize.c: Replace all static copies of to_mm/from_mm
by the copies in gtkprintutils.c.
* gtk/gtkpagesetup.[hc]: Use g types, add documentation.
* gtk/gtkprintsettings.c: More documentation
2006-04-22 Tor Lillqvist <tml@novell.com>
......
2006-04-23 Matthias Clasen <mclasen@redhat.com>
* gtk/Makefile.am: Add gtkprintutils.[hc]
* gtk/gtkprintutils.[hc]: New files, move the unit conversion
functions here.
* gtk/gtkpagesetupunixdialog.c:
* gtk/gtkprintsettings.c:
* gtk/gtkpagesetup.c:
* gtk/gtkpapersize.c: Replace all static copies of to_mm/from_mm
by the copies in gtkprintutils.c.
* gtk/gtkpagesetup.[hc]: Use g types, add documentation.
* gtk/gtkprintsettings.c: More documentation
2006-04-22 Tor Lillqvist <tml@novell.com>
......
......@@ -334,6 +334,7 @@ gtk_private_h_sources = \
gtkpathbar.h \
gtkplugprivate.h \
gtkprintoperation-private.h\
gtkprintutils.h \
gtkrbtree.h \
gtkrecentchooserdefault.h \
gtkrecentchooserprivate.h \
......@@ -483,6 +484,7 @@ gtk_c_sources = \
gtkprintcontext.c \
gtkprintoperation.c \
gtkprintsettings.c \
gtkprintutils.c \
gtkprogress.c \
gtkprogressbar.c \
gtkradioaction.c \
......
......@@ -21,10 +21,9 @@
#include "config.h"
#include "gtkpagesetup.h"
#include "gtkprintutils.h"
#include "gtkalias.h"
#define MM_PER_INCH 25.4
#define POINTS_PER_INCH 72
typedef struct _GtkPageSetupClass GtkPageSetupClass;
......@@ -49,44 +48,6 @@ struct _GtkPageSetupClass
G_DEFINE_TYPE (GtkPageSetup, gtk_page_setup, G_TYPE_OBJECT)
static double
to_mm (double len, GtkUnit unit)
{
switch (unit)
{
case GTK_UNIT_MM:
return len;
case GTK_UNIT_INCH:
return len * MM_PER_INCH;
default:
case GTK_UNIT_PIXEL:
g_warning ("Unsupported unit");
/* Fall through */
case GTK_UNIT_POINTS:
return len * (MM_PER_INCH / POINTS_PER_INCH);
break;
}
}
static double
from_mm (double len, GtkUnit unit)
{
switch (unit)
{
case GTK_UNIT_MM:
return len;
case GTK_UNIT_INCH:
return len / MM_PER_INCH;
default:
case GTK_UNIT_PIXEL:
g_warning ("Unsupported unit");
/* Fall through */
case GTK_UNIT_POINTS:
return len / (MM_PER_INCH / POINTS_PER_INCH);
break;
}
}
static void
gtk_page_setup_finalize (GObject *object)
{
......@@ -115,13 +76,32 @@ gtk_page_setup_class_init (GtkPageSetupClass *class)
gobject_class->finalize = gtk_page_setup_finalize;
}
/**
* gtk_page_setup_new:
*
* Creates a new #GtkPageSetup.
*
* Return value: a new #GtkPageSetup.
*
* Since: 2.10
*/
GtkPageSetup *
gtk_page_setup_new (void)
{
return g_object_new (GTK_TYPE_PAGE_SETUP, NULL);
}
/**
* gtk_page_setup_copy:
* @other: the #GtkPageSetup to copy
*
* Copies a #GtkPageSetup.
*
* Return value: a copy of @other
*
* Since: 2.10
*/
GtkPageSetup *
gtk_page_setup_copy (GtkPageSetup *other)
{
......@@ -138,25 +118,65 @@ gtk_page_setup_copy (GtkPageSetup *other)
return copy;
}
/**
* gtk_page_setup_get_orientation:
* @setup: a #GtkPageSetup
*
* Gets the page orientation of the #GtkPageSetup.
*
* Return value: the page orientation
*
* Since: 2.10
*/
GtkPageOrientation
gtk_page_setup_get_orientation (GtkPageSetup *setup)
{
return setup->orientation;
}
/**
* gtk_page_setup_set_orientation:
* @setup: a #GtkPageSetup
* @orientation: a #GtkPageOrientation value
*
* Sets the page orientation of the #GtkPageSetup.
*
* Since: 2.10
*/
void
gtk_page_setup_set_orientation (GtkPageSetup *setup,
GtkPageOrientation orientation)
gtk_page_setup_set_orientation (GtkPageSetup *setup,
GtkPageOrientation orientation)
{
setup->orientation = orientation;
}
/**
* gtk_page_setup_get_paper_size:
* @setup: a #GtkPageSetup
*
* Gets the paper size of the #GtkPageSetup.
*
* Return value: the paper size
*
* Since: 2.10
*/
GtkPaperSize *
gtk_page_setup_get_paper_size (GtkPageSetup *setup)
{
return setup->paper_size;
}
/**
* gtk_page_setup_set_paper_size:
* @setup: a #GtkPageSetup
* @size: a #GtkPaperSize
*
* Sets the paper size of the #GtkPageSetup without
* changing the margins. See
* gtk_page_setup_set_paper_size_and_default_margins().
*
* Since: 2.10
*/
void
gtk_page_setup_set_paper_size (GtkPageSetup *setup,
GtkPaperSize *size)
......@@ -164,6 +184,16 @@ gtk_page_setup_set_paper_size (GtkPageSetup *setup,
setup->paper_size = gtk_paper_size_copy (size);
}
/**
* gtk_page_setup_set_paper_size_and_default_margins:
* @setup: a #GtkPageSetup
* @size: a #GtkPaperSize
*
* Sets the paper size of the #GtkPageSetup and modifies
* the margins according to the new paper size.
*
* Since: 2.10
*/
void
gtk_page_setup_set_paper_size_and_default_margins (GtkPageSetup *setup,
GtkPaperSize *size)
......@@ -175,68 +205,166 @@ gtk_page_setup_set_paper_size_and_default_margins (GtkPageSetup *setup,
setup->right_margin = gtk_paper_size_get_default_right_margin (setup->paper_size, GTK_UNIT_MM);
}
double
/**
* gtk_page_setup_get_top_margin:
* @setup: a #GtkPageSetup
* @unit: the unit for the return value
*
* Gets the top margin in units of @unit.
*
* Return value: the top margin
*
* Since: 2.10
*/
gdouble
gtk_page_setup_get_top_margin (GtkPageSetup *setup,
GtkUnit unit)
{
return from_mm (setup->top_margin, unit);
return _gtk_print_convert_from_mm (setup->top_margin, unit);
}
/**
* gtk_page_setup_set_top_margin:
* @setup: a #GtkPageSetup
* @margin: the new top margin in units of @unit
* @unit: the units for @margin
*
* Sets the top margin of the #GtkPageSetup.
*
* Since: 2.10
*/
void
gtk_page_setup_set_top_margin (GtkPageSetup *setup,
double margin,
gdouble margin,
GtkUnit unit)
{
setup->top_margin = to_mm (margin, unit);
setup->top_margin = _gtk_print_convert_to_mm (margin, unit);
}
double
/**
* gtk_page_setup_get_bottom_margin:
* @setup: a #GtkPageSetup
* @unit: the unit for the return value
*
* Gets the bottom margin in units of @unit.
*
* Return value: the bottom margin
*
* Since: 2.10
*/
gdouble
gtk_page_setup_get_bottom_margin (GtkPageSetup *setup,
GtkUnit unit)
{
return from_mm (setup->bottom_margin, unit);
return _gtk_print_convert_from_mm (setup->bottom_margin, unit);
}
/**
* gtk_page_setup_set_bottom_margin:
* @setup: a #GtkPageSetup
* @margin: the new bottom margin in units of @unit
* @unit: the units for @margin
*
* Sets the bottom margin of the #GtkPageSetup.
*
* Since: 2.10
*/
void
gtk_page_setup_set_bottom_margin (GtkPageSetup *setup,
double margin,
gdouble margin,
GtkUnit unit)
{
setup->bottom_margin = to_mm (margin, unit);
setup->bottom_margin = _gtk_print_convert_to_mm (margin, unit);
}
double
gtk_page_setup_get_left_margin (GtkPageSetup *setup,
GtkUnit unit)
/**
* gtk_page_setup_get_left_margin:
* @setup: a #GtkPageSetup
* @unit: the unit for the return value
*
* Gets the left margin in units of @unit.
*
* Return value: the left margin
*
* Since: 2.10
*/
gdouble
gtk_page_setup_get_left_margin (GtkPageSetup *setup,
GtkUnit unit)
{
return from_mm (setup->left_margin, unit);
return _gtk_print_convert_from_mm (setup->left_margin, unit);
}
/**
* gtk_page_setup_set_left_margin:
* @setup: a #GtkPageSetup
* @margin: the new left margin in units of @unit
* @unit: the units for @margin
*
* Sets the left margin of the #GtkPageSetup.
*
* Since: 2.10
*/
void
gtk_page_setup_set_left_margin (GtkPageSetup *setup,
double margin,
GtkUnit unit)
gtk_page_setup_set_left_margin (GtkPageSetup *setup,
gdouble margin,
GtkUnit unit)
{
setup->left_margin = to_mm (margin, unit);
setup->left_margin = _gtk_print_convert_to_mm (margin, unit);
}
double
gtk_page_setup_get_right_margin (GtkPageSetup *setup,
GtkUnit unit)
/**
* gtk_page_setup_get_right_margin:
* @setup: a #GtkPageSetup
* @unit: the unit for the return value
*
* Gets the right margin in units of @unit.
*
* Return value: the right margin
*
* Since: 2.10
*/
gdouble
gtk_page_setup_get_right_margin (GtkPageSetup *setup,
GtkUnit unit)
{
return from_mm (setup->right_margin, unit);
return _gtk_print_convert_from_mm (setup->right_margin, unit);
}
/**
* gtk_page_setup_set_right_margin:
* @setup: a #GtkPageSetup
* @margin: the new right margin in units of @unit
* @unit: the units for @margin
*
* Sets the right margin of the #GtkPageSetup.
*
* Since: 2.10
*/
void
gtk_page_setup_set_right_margin (GtkPageSetup *setup,
double margin,
GtkUnit unit)
gtk_page_setup_set_right_margin (GtkPageSetup *setup,
gdouble margin,
GtkUnit unit)
{
setup->right_margin = to_mm (margin, unit);
setup->right_margin = _gtk_print_convert_to_mm (margin, unit);
}
/* These take orientation, but not margins into consideration */
double
/**
* gtk_page_setup_get_paper_width:
* @setup: a #GtkPageSetup
* @unit: the unit for the return value
*
* Returns the paper width in units of @unit.
*
* Note that this function takes orientation, but
* not margins into consideration.
* See gtk_page_setup_get_page_width().
*
* Return value: the paper width.
*
* Since: 2.10
*/
gdouble
gtk_page_setup_get_paper_width (GtkPageSetup *setup,
GtkUnit unit)
{
......@@ -247,9 +375,24 @@ gtk_page_setup_get_paper_width (GtkPageSetup *setup,
return gtk_paper_size_get_height (setup->paper_size, unit);
}
double
gtk_page_setup_get_paper_height (GtkPageSetup *setup,
GtkUnit unit)
/**
* gtk_page_setup_get_paper_height:
* @setup: a #GtkPageSetup
* @unit: the unit for the return value
*
* Returns the paper height in units of @unit.
*
* Note that this function takes orientation, but
* not margins into consideration.
* See gtk_page_setup_get_page_height().
*
* Return value: the paper height.
*
* Since: 2.10
*/
gdouble
gtk_page_setup_get_paper_height (GtkPageSetup *setup,
GtkUnit unit)
{
if (setup->orientation == GTK_PAGE_ORIENTATION_PORTRAIT ||
setup->orientation == GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT)
......@@ -258,29 +401,58 @@ gtk_page_setup_get_paper_height (GtkPageSetup *setup,
return gtk_paper_size_get_width (setup->paper_size, unit);
}
/* These take orientation, and margins into consideration */
double
gtk_page_setup_get_page_width (GtkPageSetup *setup,
GtkUnit unit)
/**
* gtk_page_setup_get_page_width:
* @setup: a #GtkPageSetup
* @unit: the unit for the return value
*
* Returns the page width in units of @unit.
*
* Note that this function takes orientation and
* margins into consideration.
* See gtk_page_setup_get_paper_width().
*
* Return value: the page width.
*
* Since: 2.10
*/
gdouble
gtk_page_setup_get_page_width (GtkPageSetup *setup,
GtkUnit unit)
{
double width;
gdouble width;
width = gtk_page_setup_get_paper_width (setup, GTK_UNIT_MM);
width -= setup->left_margin + setup->right_margin;
return from_mm (width, unit);
return _gtk_print_convert_from_mm (width, unit);
}
double
gtk_page_setup_get_page_height (GtkPageSetup *setup,
GtkUnit unit)
/**
* gtk_page_setup_get_page_height:
* @setup: a #GtkPageSetup
* @unit: the unit for the return value
*
* Returns the page height in units of @unit.
*
* Note that this function takes orientation and
* margins into consideration.
* See gtk_page_setup_get_paper_height().
*
* Return value: the page height.
*
* Since: 2.10
*/
gdouble
gtk_page_setup_get_page_height (GtkPageSetup *setup,
GtkUnit unit)
{
double height;
gdouble height;
height = gtk_page_setup_get_paper_height (setup, GTK_UNIT_MM);
height -= setup->top_margin + setup->bottom_margin;
return from_mm (height, unit);
return _gtk_print_convert_from_mm (height, unit);
}
......
......@@ -42,41 +42,41 @@ void gtk_page_setup_set_orientation (GtkPageSetup *setup,
GtkPaperSize * gtk_page_setup_get_paper_size (GtkPageSetup *setup);
void gtk_page_setup_set_paper_size (GtkPageSetup *setup,
GtkPaperSize *size);
double gtk_page_setup_get_top_margin (GtkPageSetup *setup,
gdouble gtk_page_setup_get_top_margin (GtkPageSetup *setup,
GtkUnit unit);
void gtk_page_setup_set_top_margin (GtkPageSetup *setup,
double margin,
gdouble margin,
GtkUnit unit);
double gtk_page_setup_get_bottom_margin (GtkPageSetup *setup,
gdouble gtk_page_setup_get_bottom_margin (GtkPageSetup *setup,
GtkUnit unit);
void gtk_page_setup_set_bottom_margin (GtkPageSetup *setup,
double margin,
gdouble margin,
GtkUnit unit);
double gtk_page_setup_get_left_margin (GtkPageSetup *setup,
gdouble gtk_page_setup_get_left_margin (GtkPageSetup *setup,
GtkUnit unit);
void gtk_page_setup_set_left_margin (GtkPageSetup *setup,
double margin,
gdouble margin,
GtkUnit unit);
double gtk_page_setup_get_right_margin (GtkPageSetup *setup,
gdouble gtk_page_setup_get_right_margin (GtkPageSetup *setup,
GtkUnit unit);
void gtk_page_setup_set_right_margin (GtkPageSetup *setup,
double margin,
gdouble margin,
GtkUnit unit);
void gtk_page_setup_set_paper_size_and_default_margins (GtkPageSetup *setup,
GtkPaperSize *size);
void gtk_page_setup_set_paper_size_and_default_margins (GtkPageSetup *setup,
GtkPaperSize *size);
/* These take orientation, but not margins into consideration */
double gtk_page_setup_get_paper_width (GtkPageSetup *setup,
gdouble gtk_page_setup_get_paper_width (GtkPageSetup *setup,
GtkUnit unit);
double gtk_page_setup_get_paper_height (GtkPageSetup *setup,
gdouble gtk_page_setup_get_paper_height (GtkPageSetup *setup,
GtkUnit unit);
/* These take orientation, and margins into consideration */
double gtk_page_setup_get_page_width (GtkPageSetup *setup,
gdouble gtk_page_setup_get_page_width (GtkPageSetup *setup,
GtkUnit unit);
double gtk_page_setup_get_page_height (GtkPageSetup *setup,
gdouble gtk_page_setup_get_page_height (GtkPageSetup *setup,
GtkUnit unit);
......
......@@ -52,13 +52,11 @@
#include "gtkprintbackend.h"
#include "gtkprinter-private.h"
#include "gtkpapersize.h"
#include "gtkprintutils.h"
#include "gtkalias.h"
#define CUSTOM_PAPER_FILENAME ".gtk-custom-papers"
#define MM_PER_INCH 25.4
#define POINTS_PER_INCH 72
struct GtkPageSetupUnixDialogPrivate
{
......@@ -128,44 +126,6 @@ static const char * const common_paper_sizes[] = {
"iso_a3",
};
static double
to_mm (double len, GtkUnit unit)
{
switch (unit)
{
case GTK_UNIT_MM:
return len;
case GTK_UNIT_INCH:
return len * MM_PER_INCH;
default:
case GTK_UNIT_PIXEL:
g_warning ("Unsupported unit");
/* Fall through */
case GTK_UNIT_POINTS:
return len * (MM_PER_INCH / POINTS_PER_INCH);
break;
}
}
static double
from_mm (double len, GtkUnit unit)
{
switch (unit)
{
case GTK_UNIT_MM:
return len;
case GTK_UNIT_INCH:
return len / MM_PER_INCH;
default:
case GTK_UNIT_PIXEL:
g_warning ("Unsupported unit");
/* Fall through */
case GTK_UNIT_POINTS:
return len / (MM_PER_INCH / POINTS_PER_INCH);
break;
}
}
static GtkUnit
get_default_user_units (void)
{
......@@ -1376,7 +1336,7 @@ static double
unit_widget_get (GtkWidget *unit_widget)
{
UnitWidget *data = g_object_get_data (G_OBJECT (unit_widget), "unit-data");
return to_mm (gtk_spin_button_get_value (GTK_SPIN_BUTTON (data->spin_button)),
return _gtk_print_convert_to_mm (gtk_spin_button_get_value (GTK_SPIN_BUTTON (data->spin_button)),
data->display_unit);
}
......@@ -1385,7 +1345,7 @@ unit_widget_set (GtkWidget *unit_widget, double val)
{
UnitWidget *data = g_object_get_data (G_OBJECT (unit_widget), "unit-data");
gtk_spin_button_set_value (GTK_SPIN_BUTTON (data->spin_button),
from_mm (val, data->display_unit));
_gtk_print_convert_from_mm (val, data->display_unit));
}
......@@ -1639,10 +1599,10 @@ set_margins_from_printer (CustomPaperDialog *data,
_gtk_printer_get_hard_margins (printer, &top, &bottom, &left, &right);
data->non_user_change = TRUE;
unit_widget_set (data->top_widget, to_mm (top, GTK_UNIT_POINTS));
unit_widget_set (data->bottom_widget, to_mm (bottom, GTK_UNIT_POINTS));
unit_widget_set (data->left_widget, to_mm (left, GTK_UNIT_POINTS));
unit_widget_set (data->right_widget, to_mm (right, GTK_UNIT_POINTS));
unit_widget_set (data->top_widget, _gtk_print_convert_to_mm (top, GTK_UNIT_POINTS));
unit_widget_set (data->bottom_widget, _gtk_print_convert_to_mm (bottom, GTK_UNIT_POINTS));
unit_widget_set (data->left_widget, _gtk_print_convert_to_mm (left, GTK_UNIT_POINTS));
unit_widget_set (data->right_widget, _gtk_print_convert_to_mm (right, GTK_UNIT_POINTS));
data->non_user_change = FALSE;
/* Only send one change */
......
......@@ -27,11 +27,9 @@
#endif
#include "gtkpapersize.h"
#include "gtkprintutils.h"
#include "gtkalias.h"
#define MM_PER_INCH 25.4
#define POINTS_PER_INCH 72
#include "paper_names_offsets.c"
struct _GtkPaperSize
......@@ -83,47 +81,10 @@ lookup_paper_info (const char *name)
return NULL;
}
static double
to_mm (double len, GtkUnit unit)
{
switch (unit)
{
case GTK_UNIT_MM:
return len;
case GTK_UNIT_INCH:
return len * MM_PER_INCH;
default:
case GTK_UNIT_PIXEL:
g_warning ("Unsupported unit");
/* Fall through */
case GTK_UNIT_POINTS:
return len * (MM_PER_INCH / POINTS_PER_INCH);
break;
}
}
static double
from_mm (double len, GtkUnit unit)
{
switch (unit)
{
case GTK_UNIT_MM:
return len;
case GTK_UNIT_INCH:
return len / MM_PER_INCH;
default:
case GTK_UNIT_PIXEL:
g_warning ("Unsupported unit");
/* Fall through */
case GTK_UNIT_POINTS:
return len / (MM_PER_INCH / POINTS_PER_INCH);
break;
}
}
static gboolean
parse_media_size (const char *size,
double *width_mm, double *height_mm)
gdouble *width_mm,
gdouble *height_mm)
{
const char *p;
char *e;
......@@ -162,9 +123,10 @@ parse_media_size (const char *size,
}
static gboolean
parse_full_media_size_name (const char *full_name,
char **name,
double *width_mm, double *height_mm)
parse_full_media_size_name (const char *full_name,
char **name,
gdouble *width_mm,
gdouble *height_mm)
{
const char *p;
const char *end_of_name;
......@@ -267,8 +229,8 @@ gtk_paper_size_new (const char *name)
GtkPaperSize *
gtk_paper_size_new_from_ppd (const char *ppd_name,
const char *ppd_display_name,
double width,
double height)
gdouble width,
gdouble height)
{
char *name;
const char *lookup_ppd_name;
......@@ -339,8 +301,8 @@ gtk_paper_size_new_custom (const char *name,
size->display_name = g_strdup (display_name);
size->is_custom = TRUE;
size->width = to_mm (width, unit);
size->height = to_mm (height, unit);
size->width = _gtk_print_convert_to_mm (width, unit);
size->height = _gtk_print_convert_to_mm (height, unit);
return size;
}
......@@ -418,12 +380,12 @@ gtk_paper_size_get_ppd_name (GtkPaperSize *size)
double
gtk_paper_size_get_width (GtkPaperSize *size, GtkUnit unit)
{
return from_mm (size->width