summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2006-04-23 05:48:04 +0000
committerMatthias Clasen <matthiasc@src.gnome.org>2006-04-23 05:48:04 +0000
commit935482e3b2fceba53fea4725c18ec4923c340837 (patch)
tree280ca9cec2db19c3d50a0f873b3db34822ba78ab
parent46548ae53ade695005ce254ce3df3649031c1966 (diff)
downloadgtk+-935482e3b2fceba53fea4725c18ec4923c340837.tar.gz
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.
-rw-r--r--ChangeLog13
-rw-r--r--ChangeLog.pre-2-1013
-rw-r--r--gtk/Makefile.am2
-rw-r--r--gtk/gtkpagesetup.c338
-rw-r--r--gtk/gtkpagesetup.h28
-rw-r--r--gtk/gtkpagesetupunixdialog.c54
-rw-r--r--gtk/gtkpapersize.c86
-rw-r--r--gtk/gtkprintsettings.c45
-rw-r--r--gtk/gtkprintutils.c62
-rw-r--r--gtk/gtkprintutils.h35
10 files changed, 428 insertions, 248 deletions
diff --git a/ChangeLog b/ChangeLog
index 0cd97954a0..a088a8a18f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
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>
diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10
index 0cd97954a0..a088a8a18f 100644
--- a/ChangeLog.pre-2-10
+++ b/ChangeLog.pre-2-10
@@ -1,5 +1,18 @@
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>
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 52815b548c..d3348ba3cf 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -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 \
diff --git a/gtk/gtkpagesetup.c b/gtk/gtkpagesetup.c
index 8406a28e88..bf9793a7c1 100644
--- a/gtk/gtkpagesetup.c
+++ b/gtk/gtkpagesetup.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);
}
diff --git a/gtk/gtkpagesetup.h b/gtk/gtkpagesetup.h
index db617a2c76..f52e0bfeda 100644
--- a/gtk/gtkpagesetup.h
+++ b/gtk/gtkpagesetup.h
@@ -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);
diff --git a/gtk/gtkpagesetupunixdialog.c b/gtk/gtkpagesetupunixdialog.c
index 0815f17a4b..e3743f56e1 100644
--- a/gtk/gtkpagesetupunixdialog.c
+++ b/gtk/gtkpagesetupunixdialog.c
@@ -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 */
diff --git a/gtk/gtkpapersize.c b/gtk/gtkpapersize.c
index 7dfeb9019a..476bcb656d 100644
--- a/gtk/gtkpapersize.c
+++ b/gtk/gtkpapersize.c
@@ -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, unit);
+ return _gtk_print_convert_from_mm (size->width, unit);
}
double
gtk_paper_size_get_height (GtkPaperSize *size, GtkUnit unit)
{
- return from_mm (size->height, unit);
+ return _gtk_print_convert_from_mm (size->height, unit);
}
gboolean
@@ -439,8 +401,8 @@ gtk_paper_size_set_size (GtkPaperSize *size, double width, double height, GtkUni
g_return_if_fail (size != NULL);
g_return_if_fail (size->is_custom);
- 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);
}
#define NL_PAPER_GET(x) \
@@ -507,8 +469,8 @@ gtk_paper_size_get_default_top_margin (GtkPaperSize *size, GtkUnit unit)
{
double margin;
- margin = to_mm (0.25, GTK_UNIT_INCH);
- return from_mm (margin, unit);
+ margin = _gtk_print_convert_to_mm (0.25, GTK_UNIT_INCH);
+ return _gtk_print_convert_from_mm (margin, unit);
}
double
@@ -517,15 +479,15 @@ gtk_paper_size_get_default_bottom_margin (GtkPaperSize *size, GtkUnit unit)
double margin;
const char *name;
- margin = to_mm (0.25, GTK_UNIT_INCH);
+ margin = _gtk_print_convert_to_mm (0.25, GTK_UNIT_INCH);
name = gtk_paper_size_get_name (size);
if (strcmp (name, "na_letter") == 0 ||
strcmp (name, "na_legal") == 0 ||
strcmp (name, "iso_a4") == 0)
- margin = to_mm (0.56, GTK_UNIT_INCH);
+ margin = _gtk_print_convert_to_mm (0.56, GTK_UNIT_INCH);
- return from_mm (margin, unit);
+ return _gtk_print_convert_from_mm (margin, unit);
}
double
@@ -533,8 +495,8 @@ gtk_paper_size_get_default_left_margin (GtkPaperSize *size, GtkUnit unit)
{
double margin;
- margin = to_mm (0.25, GTK_UNIT_INCH);
- return from_mm (margin, unit);
+ margin = _gtk_print_convert_to_mm (0.25, GTK_UNIT_INCH);
+ return _gtk_print_convert_from_mm (margin, unit);
}
double
@@ -542,8 +504,8 @@ gtk_paper_size_get_default_right_margin (GtkPaperSize *size, GtkUnit unit)
{
double margin;
- margin = to_mm (0.25, GTK_UNIT_INCH);
- return from_mm (margin, unit);
+ margin = _gtk_print_convert_to_mm (0.25, GTK_UNIT_INCH);
+ return _gtk_print_convert_from_mm (margin, unit);
}
diff --git a/gtk/gtkprintsettings.c b/gtk/gtkprintsettings.c
index 3ef6f62b9e..5bd47202c3 100644
--- a/gtk/gtkprintsettings.c
+++ b/gtk/gtkprintsettings.c
@@ -23,10 +23,9 @@
#include <stdlib.h>
#include <glib/gprintf.h>
#include "gtkprintsettings.h"
+#include "gtkprintutils.h"
#include "gtkalias.h"
-#define MM_PER_INCH 25.4
-#define POINTS_PER_INCH 72
typedef struct _GtkPrintSettingsClass GtkPrintSettingsClass;
@@ -48,44 +47,6 @@ struct _GtkPrintSettingsClass
G_DEFINE_TYPE (GtkPrintSettings, gtk_print_settings, G_TYPE_OBJECT)
-static gdouble
-to_mm (gdouble 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 gdouble
-from_mm (gdouble 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_print_settings_finalize (GObject *object)
{
@@ -417,7 +378,7 @@ gtk_print_settings_get_length (GtkPrintSettings *settings,
GtkUnit unit)
{
gdouble length = gtk_print_settings_get_double (settings, key);
- return from_mm (length, unit);
+ return _gtk_print_convert_from_mm (length, unit);
}
/**
@@ -438,7 +399,7 @@ gtk_print_settings_set_length (GtkPrintSettings *settings,
GtkUnit unit)
{
gtk_print_settings_set_double (settings, key,
- to_mm (length, unit));
+ _gtk_print_convert_to_mm (length, unit));
}
/**
diff --git a/gtk/gtkprintutils.c b/gtk/gtkprintutils.c
new file mode 100644
index 0000000000..dced6e8a4d
--- /dev/null
+++ b/gtk/gtkprintutils.c
@@ -0,0 +1,62 @@
+/* GTK - The GIMP Toolkit
+ * gtkpapersize.c: Paper Size
+ * Copyright (C) 2006, Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+#include "gtkprintutils.h"
+
+gdouble
+_gtk_print_convert_to_mm (gdouble 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;
+ }
+}
+
+gdouble
+_gtk_print_convert_from_mm (gdouble 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;
+ }
+}
diff --git a/gtk/gtkprintutils.h b/gtk/gtkprintutils.h
new file mode 100644
index 0000000000..765d1eb576
--- /dev/null
+++ b/gtk/gtkprintutils.h
@@ -0,0 +1,35 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 2006, Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GTK_PRINT_UTILS_H__
+#define __GTK_PRINT_UTILS_H__
+
+#include "gtkenums.h"
+
+G_BEGIN_DECLS
+
+#define MM_PER_INCH 25.4
+#define POINTS_PER_INCH 72
+
+gdouble _gtk_print_convert_to_mm (gdouble len, GtkUnit unit);
+gdouble _gtk_print_convert_from_mm (gdouble len, GtkUnit unit);
+
+G_END_DECLS
+
+#endif /* __GTK_PRINT_UTILS_H__ */