]> git.sur5r.net Git - glabels/commitdiff
2005-02-05 Jim Evins <evins@snaught.com>
authorJim Evins <evins@snaught.com>
Sun, 6 Feb 2005 04:40:33 +0000 (04:40 +0000)
committerJim Evins <evins@snaught.com>
Sun, 6 Feb 2005 04:40:33 +0000 (04:40 +0000)
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

16 files changed:
glabels2/ChangeLog
glabels2/configure.in
glabels2/libglabels/Makefile.am
glabels2/libglabels/enums.h [new file with mode: 0644]
glabels2/libglabels/libglabels.h
glabels2/libglabels/libglabels.pc.in [new file with mode: 0644]
glabels2/libglabels/template.c
glabels2/libglabels/template.h
glabels2/libglabels/xml.c
glabels2/libglabels/xml.h
glabels2/src/prefs-dialog.c
glabels2/src/prefs-model.c
glabels2/src/prefs-model.h
glabels2/src/prefs.c
glabels2/src/prefs.h
glabels2/src/wdgt-media-select.c

index 607983afba93ccd60590602c793576fef9d2dce4..ab6230be5a70f88c76095628d7313c55136cc0b8 100644 (file)
@@ -1,3 +1,37 @@
+2005-02-05  Jim Evins  <evins@snaught.com>
+
+       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  <evins@snaught.com>
 
        * po/cs.po:
index 937467f5daaae5e5ee61210eda4e6dace4ebd1c1..14eccbbe8f0be678d719877c08c9daf32dba0657 100644 (file)
@@ -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
index d8971ae22fe0f9c5e9b77317ea83ef0554427533..4fa2909bedcd26081ca5581de3b0cdd89e10d1a6 100644 (file)
@@ -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 (file)
index 0000000..bc80a06
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ *  (LIBGLABELS) Template library for GLABELS
+ *
+ *  enums.h:  common libGLabels enumerations header file
+ *
+ *  Copyright (C) 2003, 2004  Jim Evins <evins@snaught.com>.
+ *
+ *  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 <glib.h>
+
+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__ */
index bc2ba99ac8ec9ee6cc4032aadec61cb8ae39aa8a..0ec151fcd7e80fa48e7703d66c9291ab120ad072 100644 (file)
@@ -26,6 +26,7 @@
 #ifndef __LIBGLABELS_H__
 #define __LIBGLABELS_H__
 
+#include <libglabels/enums.h>
 #include <libglabels/paper.h>
 #include <libglabels/template.h>
 #include <libglabels/xml-paper.h>
diff --git a/glabels2/libglabels/libglabels.pc.in b/glabels2/libglabels/libglabels.pc.in
new file mode 100644 (file)
index 0000000..c16e8f4
--- /dev/null
@@ -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}
+
index 92c59832547110fa7127026b17e2fac01cdcf4f1..a01bb8c483dc41381eff11cce9b26ec8c4ac124b 100644 (file)
@@ -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,
index ff8f927bd1ba6e79652de26036dca63bd08d724e..b34abd26afcc9ff159623eb20fd84552fa83b045 100644 (file)
@@ -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,
index ea483355ed9dfa0ed807293210d2aca0608bf943..cf36f056b3eba92dbd7e0f3b8ce34c350e060ecd 100644 (file)
@@ -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;
+}
+
+
index 11c3a4805382d6d91a012b982a8c9a1e4e07728d..727694672faf64ea196a048ecac0bad24cc35643 100644 (file)
@@ -29,6 +29,8 @@
 #include <glib.h>
 #include <libxml/tree.h>
 
+#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
 
 
index 36e9f4b457fbc50adf5d257445a7c0cabf8c3fc1..2f5d42ab701784551c1403244d9216daa69e2f5d 100644 (file)
@@ -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))) {
index fe2dd6bdbcc48b00950cc134fb4b3051ce5e6176..f9437c6d295b425057213ba907824e5c50439f9b 100644 (file)
@@ -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);
 
 
 \f
@@ -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:
index cd113122ddad41ae7debd6f98bd21abc6bd3ab24..469379191766c280c750944953da20f0da117f36 100644 (file)
@@ -26,6 +26,7 @@
 #include <gtk/gtk.h>
 #include <gconf/gconf-client.h>
 #include <libgnomeprint/gnome-font.h>
+#include <libglabels/enums.h>
 
 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;
index d4c6d67678e80ac44a9fee1df3553da3a3c3713c..4f5bcde9983fc9a25a8b1bce07522a8b56cf65d0 100644 (file)
@@ -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");
index f8f43a250793532c8b18c49ffe56ac2f4f483819..b406f29d6094c2d7e6033ebbfe2b047bcc37d7bb 100644 (file)
@@ -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);
 
index acc6402465e17d5b836eccfec1b245f476963fe7..6ad73a0c77e5090de9388d306fddaedc06388eb3 100644 (file)
@@ -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);