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
+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:
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)
Makefile
barcode-0.98/Makefile
libglabels/Makefile
+libglabels/libglabels.pc
src/Makefile
src/pixmaps/Makefile
src/stock-pixmaps/Makefile
libglabels_la_SOURCES = \
libglabels-private.h \
+ enums.h \
paper.h \
paper.c \
template.h \
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
+
--- /dev/null
+/*
+ * (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__ */
#ifndef __LIBGLABELS_H__
#define __LIBGLABELS_H__
+#include <libglabels/enums.h>
#include <libglabels/paper.h>
#include <libglabels/template.h>
#include <libglabels/xml-paper.h>
--- /dev/null
+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}
+
/* 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,
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,
/*========================================================*/
typedef struct {
- gchar *name;
- gdouble points_per_unit;
+ gchar *name;
+ gdouble points_per_unit;
} UnitTableEntry;
/*========================================================*/
/* 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. */
/*========================================================*/
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);
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;
+}
+
+
#include <glib.h>
#include <libxml/tree.h>
+#include "enums.h"
+
#define GL_XML_NAME_SPACE "http://snaught.com/glabels/2.0/"
G_BEGIN_DECLS
const gchar *property,
gdouble val);
+void gl_xml_set_default_units (glUnitsType units);
+
G_END_DECLS
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);
{
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))) {
#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"
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
/*---------------------------------------------------------------------------*/
/* 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:
#include <gtk/gtk.h>
#include <gconf/gconf-client.h>
#include <libgnomeprint/gnome-font.h>
+#include <libglabels/enums.h>
G_BEGIN_DECLS
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))
GConfClient *gconf_client;
/* Units */
- glPrefsUnits units;
+ glUnitsType units;
/* Page size */
gchar *default_page_size;
/****************************************************************************/
/* Get desired units. */
/****************************************************************************/
-glPrefsUnits
+glUnitsType
gl_prefs_get_units (void)
{
return gl_prefs->units;
{
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 */
{
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 */
{
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 */
{
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");
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);
{
glTemplate *template;
gchar *text;
- glPrefsUnits units;
+ glUnitsType units;
const gchar *units_string;
gdouble units_per_point;
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;
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);
}
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);
}
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);