From 46b4d3627f3a1af503c1433286dbe78c7e7f2d09 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Sun, 6 Feb 2005 04:40:33 +0000 Subject: [PATCH] 2005-02-05 Jim Evins Some cleanup to libglabels. * configure.in: Updated version to 2.1.1cvs. Added generation of libglabels.pc. * libglabels/libglabels.pc.in Created. * libglabels/enums.h Created. Currently only contains glUnitsType which provides enumerations for all possible units of distance. * libglabels/Makefile.am: Incorporated new files enums.h and libglabels.pc[.in]. * libglabels/libglabels.h: Include enums.h. * libglabels/template.h: * libglabels/template.c: (gl_template_layout_new): Changed parameters nx and ny to gint from gdouble. * libglabels/xml.h: * libglabels/xml.c: (gl_xml_get_prop_length), (gl_xml_set_prop_length), (gl_xml_set_default_units): Added support for different output units. * src/prefs-dialog.c: (update_locale_page_from_prefs), (update_prefs_from_locale_page): * src/prefs-model.c: (string_to_units), (units_to_string): * src/prefs-model.h: * src/prefs.c: (gl_prefs_get_units_per_point), (gl_prefs_get_units_precision), (gl_prefs_get_units_step_size), (gl_prefs_get_units_string): * src/prefs.h: * src/wdgt-media-select.c: (details_update), (get_label_size_desc): Reconciled all length enumerations with the new enumerations provided in libglabels/enums.h. git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@501 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- glabels2/ChangeLog | 34 +++++++++++++++++++ glabels2/configure.in | 3 +- glabels2/libglabels/Makefile.am | 9 +++++ glabels2/libglabels/enums.h | 49 ++++++++++++++++++++++++++++ glabels2/libglabels/libglabels.h | 1 + glabels2/libglabels/libglabels.pc.in | 12 +++++++ glabels2/libglabels/template.c | 4 +-- glabels2/libglabels/template.h | 4 +-- glabels2/libglabels/xml.c | 40 ++++++++++++++++------- glabels2/libglabels/xml.h | 4 +++ glabels2/src/prefs-dialog.c | 8 ++--- glabels2/src/prefs-model.c | 22 ++++++------- glabels2/src/prefs-model.h | 9 ++--- glabels2/src/prefs.c | 18 +++++----- glabels2/src/prefs.h | 2 +- glabels2/src/wdgt-media-select.c | 10 +++--- 16 files changed, 176 insertions(+), 53 deletions(-) create mode 100644 glabels2/libglabels/enums.h create mode 100644 glabels2/libglabels/libglabels.pc.in diff --git a/glabels2/ChangeLog b/glabels2/ChangeLog index 607983af..ab6230be 100644 --- a/glabels2/ChangeLog +++ b/glabels2/ChangeLog @@ -1,3 +1,37 @@ +2005-02-05 Jim Evins + + Some cleanup to libglabels. + + * configure.in: + Updated version to 2.1.1cvs. Added generation of libglabels.pc. + * libglabels/libglabels.pc.in + Created. + * libglabels/enums.h + Created. Currently only contains glUnitsType which provides enumerations + for all possible units of distance. + * libglabels/Makefile.am: + Incorporated new files enums.h and libglabels.pc[.in]. + * libglabels/libglabels.h: + Include enums.h. + * libglabels/template.h: + * libglabels/template.c: (gl_template_layout_new): + Changed parameters nx and ny to gint from gdouble. + * libglabels/xml.h: + * libglabels/xml.c: (gl_xml_get_prop_length), + (gl_xml_set_prop_length), (gl_xml_set_default_units): + Added support for different output units. + * src/prefs-dialog.c: (update_locale_page_from_prefs), + (update_prefs_from_locale_page): + * src/prefs-model.c: (string_to_units), (units_to_string): + * src/prefs-model.h: + * src/prefs.c: (gl_prefs_get_units_per_point), + (gl_prefs_get_units_precision), (gl_prefs_get_units_step_size), + (gl_prefs_get_units_string): + * src/prefs.h: + * src/wdgt-media-select.c: (details_update), (get_label_size_desc): + Reconciled all length enumerations with the new enumerations provided + in libglabels/enums.h. + 2005-02-03 Jim Evins * po/cs.po: diff --git a/glabels2/configure.in b/glabels2/configure.in index 937467f5..14eccbbe 100644 --- a/glabels2/configure.in +++ b/glabels2/configure.in @@ -2,7 +2,7 @@ dnl Process this file with autoconf to produce a configure script. AC_PREREQ(2.52) -AC_INIT(glabels, 2.1.0, http://sourceforge.net/tracker/?func=add&group_id=46122&atid=445116) +AC_INIT(glabels, 2.1.1cvs, http://sourceforge.net/tracker/?func=add&group_id=46122&atid=445116) AC_CONFIG_SRCDIR(src/glabels.c) AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION) @@ -146,6 +146,7 @@ AC_OUTPUT([ Makefile barcode-0.98/Makefile libglabels/Makefile +libglabels/libglabels.pc src/Makefile src/pixmaps/Makefile src/stock-pixmaps/Makefile diff --git a/glabels2/libglabels/Makefile.am b/glabels2/libglabels/Makefile.am index d8971ae2..4fa2909b 100644 --- a/glabels2/libglabels/Makefile.am +++ b/glabels2/libglabels/Makefile.am @@ -16,6 +16,7 @@ libglabelsincludedir=$(includedir)/libglabels libglabels_la_SOURCES = \ libglabels-private.h \ + enums.h \ paper.h \ paper.c \ template.h \ @@ -29,8 +30,16 @@ libglabels_la_SOURCES = \ libglabelsinclude_HEADERS = \ libglabels.h \ + enums.h \ paper.h \ template.h \ xml-paper.h \ xml-template.h \ xml.h + +EXTRA_DIST = \ + libglabels.pc.in + +pkgconfigdir = $(libdir)/pkgconfig +pkgconfig_DATA = libglabels.pc + diff --git a/glabels2/libglabels/enums.h b/glabels2/libglabels/enums.h new file mode 100644 index 00000000..bc80a06f --- /dev/null +++ b/glabels2/libglabels/enums.h @@ -0,0 +1,49 @@ +/* + * (LIBGLABELS) Template library for GLABELS + * + * enums.h: common libGLabels enumerations header file + * + * Copyright (C) 2003, 2004 Jim Evins . + * + * This file is part of the LIBGLABELS library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library 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 __ENUMS_H__ +#define __ENUMS_H__ + +#include + +G_BEGIN_DECLS + +/* Units of distance */ +typedef enum { + GL_UNITS_POINT, + GL_UNITS_INCH, + GL_UNITS_MM, + GL_UNITS_CM, + GL_UNITS_PICA, + + GL_UNITS_FIRST = GL_UNITS_POINT, + GL_UNITS_LAST = GL_UNITS_PICA, +} glUnitsType; + + +G_END_DECLS + + +#endif /* __ENUMS_H__ */ diff --git a/glabels2/libglabels/libglabels.h b/glabels2/libglabels/libglabels.h index bc2ba99a..0ec151fc 100644 --- a/glabels2/libglabels/libglabels.h +++ b/glabels2/libglabels/libglabels.h @@ -26,6 +26,7 @@ #ifndef __LIBGLABELS_H__ #define __LIBGLABELS_H__ +#include #include #include #include diff --git a/glabels2/libglabels/libglabels.pc.in b/glabels2/libglabels/libglabels.pc.in new file mode 100644 index 00000000..c16e8f47 --- /dev/null +++ b/glabels2/libglabels/libglabels.pc.in @@ -0,0 +1,12 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: libglabels +Description: GLabels Template Library +Requires: glib-2.0 libxml-2.0 +Version: @VERSION@ +Libs: -L${libdir} -lglabels +Cflags: -I${includedir} + diff --git a/glabels2/libglabels/template.c b/glabels2/libglabels/template.c index 92c59832..a01bb8c4 100644 --- a/glabels2/libglabels/template.c +++ b/glabels2/libglabels/template.c @@ -505,8 +505,8 @@ gl_template_add_markup (glTemplateLabelType *label_type, /* Create new layout structure. */ /*****************************************************************************/ glTemplateLayout * -gl_template_layout_new (gdouble nx, - gdouble ny, +gl_template_layout_new (gint nx, + gint ny, gdouble x0, gdouble y0, gdouble dx, diff --git a/glabels2/libglabels/template.h b/glabels2/libglabels/template.h index ff8f927b..b34abd26 100644 --- a/glabels2/libglabels/template.h +++ b/glabels2/libglabels/template.h @@ -252,8 +252,8 @@ void gl_template_add_layout (glTemplateLabelType *labe void gl_template_add_markup (glTemplateLabelType *label_type, glTemplateMarkup *markup); -glTemplateLayout *gl_template_layout_new (gdouble nx, - gdouble ny, +glTemplateLayout *gl_template_layout_new (gint nx, + gint ny, gdouble x0, gdouble y0, gdouble dx, diff --git a/glabels2/libglabels/xml.c b/glabels2/libglabels/xml.c index ea483355..cf36f056 100644 --- a/glabels2/libglabels/xml.c +++ b/glabels2/libglabels/xml.c @@ -42,8 +42,8 @@ /*========================================================*/ typedef struct { - gchar *name; - gdouble points_per_unit; + gchar *name; + gdouble points_per_unit; } UnitTableEntry; /*========================================================*/ @@ -55,15 +55,18 @@ static UnitTableEntry unit_table[] = { /* These names are identical to the absolute length units supported in the CSS2 Specification (Section 4.3.2) */ - {"pt", POINTS_PER_POINT}, - {"in", POINTS_PER_INCH}, - {"mm", POINTS_PER_MM}, - {"cm", POINTS_PER_CM}, - {"pc", POINTS_PER_PICA}, + /* This table must be sorted exactly as the enumerations in glUnitsType */ + + /* [GL_UNITS_POINT] */ {"pt", POINTS_PER_POINT}, + /* [GL_UNITS_INCH] */ {"in", POINTS_PER_INCH}, + /* [GL_UNITS_MM] */ {"mm", POINTS_PER_MM}, + /* [GL_UNITS_CM] */ {"cm", POINTS_PER_CM}, + /* [GL_UNITS_PICA] */ {"pc", POINTS_PER_PICA}, - {NULL, 0} }; +static glUnitsType default_units = GL_UNITS_POINT; + /*========================================================*/ /* Private function prototypes. */ /*========================================================*/ @@ -177,13 +180,13 @@ gl_xml_get_prop_length (xmlNodePtr node, if (unit != string) { unit = g_strchug (unit); if (strlen (unit) > 0 ) { - for (i=0; unit_table[i].name != NULL; i++) { + for (i=GL_UNITS_FIRST; i<=GL_UNITS_LAST; i++) { if (xmlStrcasecmp (unit, unit_table[i].name) == 0) { val *= unit_table[i].points_per_unit; break; } } - if (unit_table[i].name == NULL) { + if (i>GL_UNITS_LAST) { g_warning ("Line %d, Node \"%s\", Property \"%s\": Unknown unit \"%s\", assuming points", xmlGetLineNo (node), node->name, property, unit); @@ -269,11 +272,26 @@ gl_xml_set_prop_length (xmlNodePtr node, gchar *string, buffer[G_ASCII_DTOSTR_BUF_SIZE]; gchar *string_unit; + /* Convert to default units */ + val /= unit_table[default_units].points_per_unit; + /* Guarantee "C" locale by use of g_ascii_formatd */ string = g_ascii_formatd (buffer, G_ASCII_DTOSTR_BUF_SIZE, "%g", val); - string_unit = g_strdup_printf ("%spt", string); + string_unit = g_strdup_printf ("%s%s", string, unit_table[default_units].name); xmlSetProp (node, property, string_unit); g_free (string_unit); } +/****************************************************************************/ +/* Set default length units. */ +/****************************************************************************/ +void +gl_xml_set_default_units (glUnitsType units) +{ + g_return_if_fail ((units >= GL_UNITS_FIRST) && (units <= GL_UNITS_LAST)); + + default_units = units; +} + + diff --git a/glabels2/libglabels/xml.h b/glabels2/libglabels/xml.h index 11c3a480..72769467 100644 --- a/glabels2/libglabels/xml.h +++ b/glabels2/libglabels/xml.h @@ -29,6 +29,8 @@ #include #include +#include "enums.h" + #define GL_XML_NAME_SPACE "http://snaught.com/glabels/2.0/" G_BEGIN_DECLS @@ -74,6 +76,8 @@ void gl_xml_set_prop_length (xmlNodePtr node, const gchar *property, gdouble val); +void gl_xml_set_default_units (glUnitsType units); + G_END_DECLS diff --git a/glabels2/src/prefs-dialog.c b/glabels2/src/prefs-dialog.c index 36e9f4b4..2f5d42ab 100644 --- a/glabels2/src/prefs-dialog.c +++ b/glabels2/src/prefs-dialog.c @@ -477,12 +477,12 @@ update_locale_page_from_prefs (glPrefsDialog *dlg) G_CALLBACK(update_prefs_from_locale_page), G_OBJECT(dlg)); switch (gl_prefs->units) { - case GL_UNITS_PTS: + case GL_UNITS_POINT: gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON(dlg->priv->units_points_radio), TRUE); break; - case GL_UNITS_INCHES: + case GL_UNITS_INCH: gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON(dlg->priv->units_inches_radio), TRUE); @@ -673,11 +673,11 @@ update_prefs_from_locale_page (glPrefsDialog *dlg) { if (gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON(dlg->priv->units_points_radio))) { - gl_prefs->units = GL_UNITS_PTS; + gl_prefs->units = GL_UNITS_POINT; } if (gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON(dlg->priv->units_inches_radio))) { - gl_prefs->units = GL_UNITS_INCHES; + gl_prefs->units = GL_UNITS_INCH; } if (gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON(dlg->priv->units_mm_radio))) { diff --git a/glabels2/src/prefs-model.c b/glabels2/src/prefs-model.c index fe2dd6bd..f9437c6d 100644 --- a/glabels2/src/prefs-model.c +++ b/glabels2/src/prefs-model.c @@ -69,7 +69,7 @@ #define PREF_MAX_RECENTS "/max-recents" /* Default values */ -#define DEFAULT_UNITS_STRING units_to_string (GL_UNITS_INCHES) +#define DEFAULT_UNITS_STRING units_to_string (GL_UNITS_INCH) #define DEFAULT_PAGE_SIZE "US-Letter" #define DEFAULT_FONT_FAMILY "Sans" @@ -133,8 +133,8 @@ static gdouble get_float (GConfClient *client, const gchar *key, gdouble def); -static glPrefsUnits string_to_units (const gchar *string); -static const gchar *units_to_string (glPrefsUnits units); +static glUnitsType string_to_units (const gchar *string); +static const gchar *units_to_string (glUnitsType units); @@ -672,32 +672,32 @@ get_float (GConfClient *client, /*---------------------------------------------------------------------------*/ /* PRIVATE. Utilities to deal with units. */ /*---------------------------------------------------------------------------*/ -static glPrefsUnits +static glUnitsType string_to_units (const gchar *string) { - glPrefsUnits units; + glUnitsType units; if (g_strcasecmp (string, "Points") == 0) { - units = GL_UNITS_PTS; + units = GL_UNITS_POINT; } else if (g_strcasecmp (string, "Inches") == 0) { - units = GL_UNITS_INCHES; + units = GL_UNITS_INCH; } else if (g_strcasecmp (string, "Millimeters") == 0) { units = GL_UNITS_MM; } else { - units = GL_UNITS_INCHES; + units = GL_UNITS_INCH; } return units; } static const -gchar *units_to_string (glPrefsUnits units) +gchar *units_to_string (glUnitsType units) { switch (units) { - case GL_UNITS_PTS: + case GL_UNITS_POINT: return "Points"; break; - case GL_UNITS_INCHES: + case GL_UNITS_INCH: return "Inches"; break; case GL_UNITS_MM: diff --git a/glabels2/src/prefs-model.h b/glabels2/src/prefs-model.h index cd113122..46937919 100644 --- a/glabels2/src/prefs-model.h +++ b/glabels2/src/prefs-model.h @@ -26,6 +26,7 @@ #include #include #include +#include G_BEGIN_DECLS @@ -35,12 +36,6 @@ typedef enum { GL_TOOLBAR_ICONS_AND_TEXT } glToolbarSetting; -typedef enum { - GL_UNITS_PTS, - GL_UNITS_INCHES, - GL_UNITS_MM, -} glPrefsUnits; - #define GL_TYPE_PREFS_MODEL (gl_prefs_model_get_type ()) #define GL_PREFS_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GL_TYPE_PREFS_MODEL, glPrefsModel)) #define GL_PREFS_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GL_TYPE_PREFS_MODEL, glPrefsModelClass)) @@ -61,7 +56,7 @@ struct _glPrefsModel { GConfClient *gconf_client; /* Units */ - glPrefsUnits units; + glUnitsType units; /* Page size */ gchar *default_page_size; diff --git a/glabels2/src/prefs.c b/glabels2/src/prefs.c index d4c6d676..4f5bcde9 100644 --- a/glabels2/src/prefs.c +++ b/glabels2/src/prefs.c @@ -78,7 +78,7 @@ gl_prefs_get_page_size (void) /****************************************************************************/ /* Get desired units. */ /****************************************************************************/ -glPrefsUnits +glUnitsType gl_prefs_get_units (void) { return gl_prefs->units; @@ -92,9 +92,9 @@ gl_prefs_get_units_per_point (void) { switch (gl_prefs->units) { - case GL_UNITS_PTS: + case GL_UNITS_POINT: return 1.0; /* points */ - case GL_UNITS_INCHES: + case GL_UNITS_INCH: return 1.0 / 72.0; /* inches */ case GL_UNITS_MM: return 0.35277778; /* mm */ @@ -112,9 +112,9 @@ gl_prefs_get_units_precision (void) { switch (gl_prefs->units) { - case GL_UNITS_PTS: + case GL_UNITS_POINT: return 1; /* points */ - case GL_UNITS_INCHES: + case GL_UNITS_INCH: return 3; /* inches */ case GL_UNITS_MM: return 1; /* mm */ @@ -132,9 +132,9 @@ gl_prefs_get_units_step_size (void) { switch (gl_prefs->units) { - case GL_UNITS_PTS: + case GL_UNITS_POINT: return 0.1; /* points */ - case GL_UNITS_INCHES: + case GL_UNITS_INCH: return 0.001; /* inches */ case GL_UNITS_MM: return 0.1; /* mm */ @@ -152,9 +152,9 @@ gl_prefs_get_units_string (void) { switch (gl_prefs->units) { - case GL_UNITS_PTS: + case GL_UNITS_POINT: return _("points"); - case GL_UNITS_INCHES: + case GL_UNITS_INCH: return _("inches"); case GL_UNITS_MM: return _("mm"); diff --git a/glabels2/src/prefs.h b/glabels2/src/prefs.h index f8f43a25..b406f29d 100644 --- a/glabels2/src/prefs.h +++ b/glabels2/src/prefs.h @@ -36,7 +36,7 @@ void gl_prefs_init (void); const gchar *gl_prefs_get_page_size (void); -glPrefsUnits gl_prefs_get_units (void); +glUnitsType gl_prefs_get_units (void); const gchar *gl_prefs_get_units_string (void); diff --git a/glabels2/src/wdgt-media-select.c b/glabels2/src/wdgt-media-select.c index acc64024..6ad73a0c 100644 --- a/glabels2/src/wdgt-media-select.c +++ b/glabels2/src/wdgt-media-select.c @@ -434,7 +434,7 @@ details_update (glWdgtMediaSelect *media_select, { glTemplate *template; gchar *text; - glPrefsUnits units; + glUnitsType units; const gchar *units_string; gdouble units_per_point; @@ -592,7 +592,7 @@ get_layout_desc (const glTemplate *template) static gchar * get_label_size_desc (const glTemplate *template) { - glPrefsUnits units; + glUnitsType units; const gchar *units_string; gdouble units_per_point; const glTemplateLabelType *label_type; @@ -606,7 +606,7 @@ get_label_size_desc (const glTemplate *template) switch (label_type->shape) { case GL_TEMPLATE_SHAPE_RECT: - if ( units == GL_UNITS_INCHES ) { + if ( units == GL_UNITS_INCH ) { gchar *xstr, *ystr; xstr = gl_util_fraction (label_type->size.rect.w*units_per_point); @@ -623,7 +623,7 @@ get_label_size_desc (const glTemplate *template) } break; case GL_TEMPLATE_SHAPE_ROUND: - if ( units == GL_UNITS_INCHES ) { + if ( units == GL_UNITS_INCH ) { gchar *dstr; dstr = gl_util_fraction (2.0*label_type->size.round.r*units_per_point); @@ -637,7 +637,7 @@ get_label_size_desc (const glTemplate *template) } break; case GL_TEMPLATE_SHAPE_CD: - if ( units == GL_UNITS_INCHES ) { + if ( units == GL_UNITS_INCH ) { gchar *dstr; dstr = gl_util_fraction (2.0*label_type->size.cd.r1*units_per_point); -- 2.39.5