lgl_category_new (gchar *id,
gchar *name)
{
- lglCategory *category;
+ lglCategory *category;
- category = g_new0 (lglCategory,1);
- category->id = g_strdup (id);
- category->name = g_strdup (name);
+ category = g_new0 (lglCategory,1);
+ category->id = g_strdup (id);
+ category->name = g_strdup (name);
- return category;
+ return category;
}
*/
lglCategory *lgl_category_dup (const lglCategory *orig)
{
- lglCategory *category;
+ lglCategory *category;
- g_return_val_if_fail (orig, NULL);
+ g_return_val_if_fail (orig, NULL);
- category = g_new0 (lglCategory,1);
+ category = g_new0 (lglCategory,1);
- category->id = g_strdup (orig->id);
- category->name = g_strdup (orig->name);
+ category->id = g_strdup (orig->id);
+ category->name = g_strdup (orig->name);
- return category;
+ return category;
}
void lgl_category_free (lglCategory *category)
{
- if ( category != NULL ) {
+ if ( category != NULL )
+ {
+ g_free (category->id);
+ category->id = NULL;
- g_free (category->id);
- category->id = NULL;
+ g_free (category->name);
+ category->name = NULL;
- g_free (category->name);
- category->name = NULL;
-
- g_free (category);
- }
+ g_free (category);
+ }
}
typedef struct _lglCategory lglCategory;
struct _lglCategory {
- gchar *id; /* Unique ID of category */
- gchar *name; /* Localized name of category */
+ gchar *id; /* Unique ID of category */
+ gchar *name; /* Localized name of category */
};
static GList *read_papers (void);
static GList *read_paper_files_from_dir (GList *papers,
- const gchar *dirname);
+ const gchar *dirname);
static GList *read_categories (void);
static GList *read_category_files_from_dir (GList *categories,
static GList *read_vendors (void);
static GList *read_vendor_files_from_dir (GList *vendors,
- const gchar *dirname);
+ const gchar *dirname);
static void read_templates (void);
static void read_template_files_from_dir (const gchar *dirname);
g_hash_table_unref (this->template_cache);
- for (p = this->papers; p != NULL; p = p->next)
+ for (p = this->papers; p != NULL; p = p->next)
{
- g_free (p->data);
- p->data = NULL;
- }
- g_list_free (this->papers);
+ g_free (p->data);
+ p->data = NULL;
+ }
+ g_list_free (this->papers);
- for (p = this->categories; p != NULL; p = p->next)
+ for (p = this->categories; p != NULL; p = p->next)
{
- g_free (p->data);
- p->data = NULL;
- }
- g_list_free (this->categories);
+ g_free (p->data);
+ p->data = NULL;
+ }
+ g_list_free (this->categories);
- for (p = this->vendors; p != NULL; p = p->next)
+ for (p = this->vendors; p != NULL; p = p->next)
{
- g_free (p->data);
- p->data = NULL;
- }
- g_list_free (this->vendors);
+ g_free (p->data);
+ p->data = NULL;
+ }
+ g_list_free (this->vendors);
- for (p = this->templates; p != NULL; p = p->next)
+ for (p = this->templates; p != NULL; p = p->next)
{
- lgl_template_free ((lglTemplate *)p->data);
- p->data = NULL;
- }
- g_list_free (this->templates);
+ lgl_template_free ((lglTemplate *)p->data);
+ p->data = NULL;
+ }
+ g_list_free (this->templates);
G_OBJECT_CLASS (lgl_db_model_parent_class)->finalize (object);
}
void
lgl_db_init (void)
{
- lglPaper *paper_other;
+ lglPaper *paper_other;
lglCategory *category_user_defined;
lglTemplate *template;
GList *page_sizes;
lgl_db_notify_add (lglDbNotifyFunc func,
gpointer user_data)
{
- if (!model)
+ if (!model)
{
- lgl_db_init ();
- }
+ lgl_db_init ();
+ }
return g_signal_connect_swapped (G_OBJECT (model), "changed", G_CALLBACK (func), user_data);
}
GList *
lgl_db_get_paper_id_list (void)
{
- GList *ids = NULL;
- GList *p;
- lglPaper *paper;
+ GList *ids = NULL;
+ GList *p;
+ lglPaper *paper;
- if (!model)
+ if (!model)
{
- lgl_db_init ();
- }
+ lgl_db_init ();
+ }
- for ( p=model->papers; p != NULL; p=p->next )
+ for ( p=model->papers; p != NULL; p=p->next )
{
- paper = (lglPaper *)p->data;
- ids = g_list_append (ids, g_strdup (paper->id));
- }
+ paper = (lglPaper *)p->data;
+ ids = g_list_append (ids, g_strdup (paper->id));
+ }
- return ids;
+ return ids;
}
void
lgl_db_free_paper_id_list (GList *ids)
{
- GList *p;
+ GList *p;
- for (p = ids; p != NULL; p = p->next)
+ for (p = ids; p != NULL; p = p->next)
{
- g_free (p->data);
- p->data = NULL;
- }
+ g_free (p->data);
+ p->data = NULL;
+ }
- g_list_free (ids);
+ g_list_free (ids);
}
GList *
lgl_db_get_paper_name_list (void)
{
- GList *names = NULL;
- GList *p;
- lglPaper *paper;
+ GList *names = NULL;
+ GList *p;
+ lglPaper *paper;
- if (!model)
+ if (!model)
{
- lgl_db_init ();
- }
+ lgl_db_init ();
+ }
- for ( p=model->papers; p != NULL; p=p->next )
+ for ( p=model->papers; p != NULL; p=p->next )
{
- paper = (lglPaper *)p->data;
- names = g_list_append (names, g_strdup (paper->name));
- }
+ paper = (lglPaper *)p->data;
+ names = g_list_append (names, g_strdup (paper->name));
+ }
- return names;
+ return names;
}
void
lgl_db_free_paper_name_list (GList *names)
{
- GList *p;
+ GList *p;
- for (p = names; p != NULL; p = p->next)
+ for (p = names; p != NULL; p = p->next)
{
- g_free (p->data);
- p->data = NULL;
- }
+ g_free (p->data);
+ p->data = NULL;
+ }
- g_list_free (names);
+ g_list_free (names);
}
lglPaper *
lgl_db_lookup_paper_from_name (const gchar *name)
{
- GList *p;
- lglPaper *paper;
+ GList *p;
+ lglPaper *paper;
- if (!model)
+ if (!model)
{
- lgl_db_init ();
- }
+ lgl_db_init ();
+ }
- if (name == NULL)
+ if (name == NULL)
{
- /* If no name, return first paper as a default */
- return lgl_paper_dup ((lglPaper *) model->papers->data);
- }
+ /* If no name, return first paper as a default */
+ return lgl_paper_dup ((lglPaper *) model->papers->data);
+ }
- for (p = model->papers; p != NULL; p = p->next)
+ for (p = model->papers; p != NULL; p = p->next)
{
- paper = (lglPaper *) p->data;
- if (UTF8_EQUAL (paper->name, name))
+ paper = (lglPaper *) p->data;
+ if (UTF8_EQUAL (paper->name, name))
{
- return lgl_paper_dup (paper);
- }
- }
+ return lgl_paper_dup (paper);
+ }
+ }
- return NULL;
+ return NULL;
}
lglPaper *
lgl_db_lookup_paper_from_id (const gchar *id)
{
- GList *p;
- lglPaper *paper;
+ GList *p;
+ lglPaper *paper;
- if (!model)
+ if (!model)
{
- lgl_db_init ();
- }
+ lgl_db_init ();
+ }
- if (id == NULL)
+ if (id == NULL)
{
- /* If no id, return first paper as a default */
- return lgl_paper_dup ((lglPaper *) model->papers->data);
- }
+ /* If no id, return first paper as a default */
+ return lgl_paper_dup ((lglPaper *) model->papers->data);
+ }
- for (p = model->papers; p != NULL; p = p->next)
+ for (p = model->papers; p != NULL; p = p->next)
{
- paper = (lglPaper *) p->data;
- if (ASCII_EQUAL (paper->id, id))
+ paper = (lglPaper *) p->data;
+ if (ASCII_EQUAL (paper->id, id))
{
- return lgl_paper_dup (paper);
- }
- }
+ return lgl_paper_dup (paper);
+ }
+ }
- return NULL;
+ return NULL;
}
gchar *
lgl_db_lookup_paper_id_from_name (const gchar *name)
{
- lglPaper *paper = NULL;
- gchar *id = NULL;
-
- if (name != NULL)
- {
- paper = lgl_db_lookup_paper_from_name (name);
- if ( paper != NULL )
- {
- id = g_strdup (paper->id);
- lgl_paper_free (paper);
- paper = NULL;
- }
- }
-
- return id;
+ lglPaper *paper = NULL;
+ gchar *id = NULL;
+
+ if (name != NULL)
+ {
+ paper = lgl_db_lookup_paper_from_name (name);
+ if ( paper != NULL )
+ {
+ id = g_strdup (paper->id);
+ lgl_paper_free (paper);
+ paper = NULL;
+ }
+ }
+
+ return id;
}
gchar *
lgl_db_lookup_paper_name_from_id (const gchar *id)
{
- lglPaper *paper = NULL;
- gchar *name = NULL;
-
- if (id != NULL)
- {
- paper = lgl_db_lookup_paper_from_id (id);
- if ( paper != NULL )
- {
- name = g_strdup (paper->name);
- lgl_paper_free (paper);
- paper = NULL;
- }
- }
-
- return name;
+ lglPaper *paper = NULL;
+ gchar *name = NULL;
+
+ if (id != NULL)
+ {
+ paper = lgl_db_lookup_paper_from_id (id);
+ if ( paper != NULL )
+ {
+ name = g_strdup (paper->name);
+ lgl_paper_free (paper);
+ paper = NULL;
+ }
+ }
+
+ return name;
}
gboolean
lgl_db_is_paper_id_known (const gchar *id)
{
- GList *p;
- lglPaper *paper;
+ GList *p;
+ lglPaper *paper;
- if (!model)
+ if (!model)
{
- lgl_db_init ();
- }
+ lgl_db_init ();
+ }
- if (id == NULL)
+ if (id == NULL)
{
- return FALSE;
- }
+ return FALSE;
+ }
- for (p = model->papers; p != NULL; p = p->next)
+ for (p = model->papers; p != NULL; p = p->next)
{
- paper = (lglPaper *) p->data;
- if (ASCII_EQUAL (paper->id, id))
+ paper = (lglPaper *) p->data;
+ if (ASCII_EQUAL (paper->id, id))
{
- return TRUE;
- }
- }
+ return TRUE;
+ }
+ }
- return FALSE;
+ return FALSE;
}
gboolean
lgl_db_is_paper_id_other (const gchar *id)
{
- if (id == NULL)
+ if (id == NULL)
{
- return FALSE;
- }
+ return FALSE;
+ }
- return (ASCII_EQUAL (id, "Other"));
+ return (ASCII_EQUAL (id, "Other"));
}
static GList *
read_papers (void)
{
- gchar *data_dir;
- GList *papers = NULL;
+ gchar *data_dir;
+ GList *papers = NULL;
- data_dir = SYSTEM_CONFIG_DIR;
- papers = read_paper_files_from_dir (papers, data_dir);
- g_free (data_dir);
+ data_dir = SYSTEM_CONFIG_DIR;
+ papers = read_paper_files_from_dir (papers, data_dir);
+ g_free (data_dir);
- data_dir = USER_CONFIG_DIR;
- papers = read_paper_files_from_dir (papers, data_dir);
- g_free (data_dir);
+ data_dir = USER_CONFIG_DIR;
+ papers = read_paper_files_from_dir (papers, data_dir);
+ g_free (data_dir);
- if (papers == NULL) {
- g_critical (_("Unable to locate paper size definitions. Libglabels may not be installed correctly!"));
- }
+ if (papers == NULL)
+ {
+ g_critical (_("Unable to locate paper size definitions. Libglabels may not be installed correctly!"));
+ }
- return papers;
+ return papers;
}
static GList *
read_paper_files_from_dir (GList *papers,
- const gchar *dirname)
+ const gchar *dirname)
{
- GDir *dp;
- const gchar *filename, *extension;
- gchar *full_filename = NULL;
- GError *gerror = NULL;
- GList *new_papers = NULL;
+ GDir *dp;
+ const gchar *filename, *extension;
+ gchar *full_filename = NULL;
+ GError *gerror = NULL;
+ GList *new_papers = NULL;
- if (dirname == NULL) {
- return papers;
- }
+ if (dirname == NULL)
+ {
+ return papers;
+ }
- if (!g_file_test (dirname, G_FILE_TEST_EXISTS)) {
- return papers;
- }
+ if (!g_file_test (dirname, G_FILE_TEST_EXISTS))
+ {
+ return papers;
+ }
- dp = g_dir_open (dirname, 0, &gerror);
- if (gerror != NULL) {
- g_message ("cannot open data directory: %s", gerror->message );
- return papers;
- }
+ dp = g_dir_open (dirname, 0, &gerror);
+ if (gerror != NULL)
+ {
+ g_message ("cannot open data directory: %s", gerror->message );
+ return papers;
+ }
- while ((filename = g_dir_read_name (dp)) != NULL) {
+ while ((filename = g_dir_read_name (dp)) != NULL)
+ {
- extension = strrchr (filename, '.');
+ extension = strrchr (filename, '.');
- if (extension != NULL) {
+ if (extension != NULL)
+ {
- if ( ASCII_EQUAL (filename, "paper-sizes.xml") )
+ if ( ASCII_EQUAL (filename, "paper-sizes.xml") )
{
- full_filename =
- g_build_filename (dirname, filename, NULL);
- new_papers =
- lgl_xml_paper_read_papers_from_file (full_filename);
- g_free (full_filename);
+ full_filename =
+ g_build_filename (dirname, filename, NULL);
+ new_papers =
+ lgl_xml_paper_read_papers_from_file (full_filename);
+ g_free (full_filename);
- papers = g_list_concat (papers, new_papers);
- new_papers = NULL;
+ papers = g_list_concat (papers, new_papers);
+ new_papers = NULL;
- }
+ }
- }
+ }
- }
+ }
- g_dir_close (dp);
+ g_dir_close (dp);
- return papers;
+ return papers;
}
void
lgl_db_print_known_papers (void)
{
- GList *p;
- lglPaper *paper;
-
- if (!model) {
- lgl_db_init ();
- }
+ GList *p;
+ lglPaper *paper;
- g_print ("%s():\n", __FUNCTION__);
- for (p = model->papers; p != NULL; p = p->next) {
- paper = (lglPaper *) p->data;
+ if (!model)
+ {
+ lgl_db_init ();
+ }
- g_print ("PAPER id=\"%s\", name=\"%s\", width=%gpts, height=%gpts\n",
- paper->id, paper->name, paper->width, paper->height);
+ g_print ("%s():\n", __FUNCTION__);
+ for (p = model->papers; p != NULL; p = p->next)
+ {
+ paper = (lglPaper *) p->data;
- }
- g_print ("\n");
+ g_print ("PAPER id=\"%s\", name=\"%s\", width=%gpts, height=%gpts\n",
+ paper->id, paper->name, paper->width, paper->height);
+ }
+ g_print ("\n");
}
GList *
lgl_db_get_category_id_list (void)
{
- GList *ids = NULL;
- GList *p;
- lglCategory *category;
+ GList *ids = NULL;
+ GList *p;
+ lglCategory *category;
- if (!model)
+ if (!model)
{
- lgl_db_init ();
- }
+ lgl_db_init ();
+ }
- for ( p=model->categories; p != NULL; p=p->next )
+ for ( p=model->categories; p != NULL; p=p->next )
{
- category = (lglCategory *)p->data;
- ids = g_list_append (ids, g_strdup (category->id));
- }
+ category = (lglCategory *)p->data;
+ ids = g_list_append (ids, g_strdup (category->id));
+ }
- return ids;
+ return ids;
}
void
lgl_db_free_category_id_list (GList *ids)
{
- GList *p;
+ GList *p;
- for (p = ids; p != NULL; p = p->next)
+ for (p = ids; p != NULL; p = p->next)
{
- g_free (p->data);
- p->data = NULL;
- }
+ g_free (p->data);
+ p->data = NULL;
+ }
- g_list_free (ids);
+ g_list_free (ids);
}
GList *
lgl_db_get_category_name_list (void)
{
- GList *names = NULL;
- GList *p;
- lglCategory *category;
+ GList *names = NULL;
+ GList *p;
+ lglCategory *category;
- if (!model)
+ if (!model)
{
- lgl_db_init ();
- }
+ lgl_db_init ();
+ }
- for ( p=model->categories; p != NULL; p=p->next )
+ for ( p=model->categories; p != NULL; p=p->next )
{
- category = (lglCategory *)p->data;
- names = g_list_append (names, g_strdup (category->name));
- }
+ category = (lglCategory *)p->data;
+ names = g_list_append (names, g_strdup (category->name));
+ }
- return names;
+ return names;
}
void
lgl_db_free_category_name_list (GList *names)
{
- GList *p;
+ GList *p;
- for (p = names; p != NULL; p = p->next)
+ for (p = names; p != NULL; p = p->next)
{
- g_free (p->data);
- p->data = NULL;
- }
+ g_free (p->data);
+ p->data = NULL;
+ }
- g_list_free (names);
+ g_list_free (names);
}
lglCategory *
lgl_db_lookup_category_from_name (const gchar *name)
{
- GList *p;
- lglCategory *category;
+ GList *p;
+ lglCategory *category;
- if (!model)
+ if (!model)
{
- lgl_db_init ();
- }
+ lgl_db_init ();
+ }
- if (name == NULL)
+ if (name == NULL)
{
- /* If no name, return first category as a default */
- return lgl_category_dup ((lglCategory *) model->categories->data);
- }
+ /* If no name, return first category as a default */
+ return lgl_category_dup ((lglCategory *) model->categories->data);
+ }
- for (p = model->categories; p != NULL; p = p->next)
+ for (p = model->categories; p != NULL; p = p->next)
{
- category = (lglCategory *) p->data;
- if (UTF8_EQUAL (category->name, name))
+ category = (lglCategory *) p->data;
+ if (UTF8_EQUAL (category->name, name))
{
- return lgl_category_dup (category);
- }
- }
+ return lgl_category_dup (category);
+ }
+ }
- return NULL;
+ return NULL;
}
lglCategory *
lgl_db_lookup_category_from_id (const gchar *id)
{
- GList *p;
- lglCategory *category;
+ GList *p;
+ lglCategory *category;
- if (!model)
+ if (!model)
{
- lgl_db_init ();
- }
+ lgl_db_init ();
+ }
- if (id == NULL)
+ if (id == NULL)
{
- /* If no id, return first category as a default */
- return lgl_category_dup ((lglCategory *) model->categories->data);
- }
+ /* If no id, return first category as a default */
+ return lgl_category_dup ((lglCategory *) model->categories->data);
+ }
- for (p = model->categories; p != NULL; p = p->next)
+ for (p = model->categories; p != NULL; p = p->next)
{
- category = (lglCategory *) p->data;
- if (ASCII_EQUAL (category->id, id))
+ category = (lglCategory *) p->data;
+ if (ASCII_EQUAL (category->id, id))
{
- return lgl_category_dup (category);
- }
- }
+ return lgl_category_dup (category);
+ }
+ }
- return NULL;
+ return NULL;
}
gchar *
lgl_db_lookup_category_id_from_name (const gchar *name)
{
- lglCategory *category = NULL;
- gchar *id = NULL;
-
- if (name != NULL)
- {
- category = lgl_db_lookup_category_from_name (name);
- if ( category != NULL )
- {
- id = g_strdup (category->id);
- lgl_category_free (category);
- category = NULL;
- }
- }
-
- return id;
+ lglCategory *category = NULL;
+ gchar *id = NULL;
+
+ if (name != NULL)
+ {
+ category = lgl_db_lookup_category_from_name (name);
+ if ( category != NULL )
+ {
+ id = g_strdup (category->id);
+ lgl_category_free (category);
+ category = NULL;
+ }
+ }
+
+ return id;
}
gchar *
lgl_db_lookup_category_name_from_id (const gchar *id)
{
- lglCategory *category = NULL;
- gchar *name = NULL;
-
- if (id != NULL)
- {
- category = lgl_db_lookup_category_from_id (id);
- if ( category != NULL )
- {
- name = g_strdup (category->name);
- lgl_category_free (category);
- category = NULL;
- }
- }
-
- return name;
+ lglCategory *category = NULL;
+ gchar *name = NULL;
+
+ if (id != NULL)
+ {
+ category = lgl_db_lookup_category_from_id (id);
+ if ( category != NULL )
+ {
+ name = g_strdup (category->name);
+ lgl_category_free (category);
+ category = NULL;
+ }
+ }
+
+ return name;
}
gboolean
lgl_db_is_category_id_known (const gchar *id)
{
- GList *p;
- lglCategory *category;
+ GList *p;
+ lglCategory *category;
- if (!model)
+ if (!model)
{
- lgl_db_init ();
- }
+ lgl_db_init ();
+ }
- if (id == NULL)
+ if (id == NULL)
{
- return FALSE;
- }
+ return FALSE;
+ }
- for (p = model->categories; p != NULL; p = p->next)
+ for (p = model->categories; p != NULL; p = p->next)
{
- category = (lglCategory *) p->data;
- if (ASCII_EQUAL (category->id, id))
+ category = (lglCategory *) p->data;
+ if (ASCII_EQUAL (category->id, id))
{
- return TRUE;
- }
- }
+ return TRUE;
+ }
+ }
- return FALSE;
+ return FALSE;
}
static GList *
read_categories (void)
{
- gchar *data_dir;
- GList *categories = NULL;
+ gchar *data_dir;
+ GList *categories = NULL;
- data_dir = SYSTEM_CONFIG_DIR;
- categories = read_category_files_from_dir (categories, data_dir);
- g_free (data_dir);
+ data_dir = SYSTEM_CONFIG_DIR;
+ categories = read_category_files_from_dir (categories, data_dir);
+ g_free (data_dir);
- data_dir = USER_CONFIG_DIR;
- categories = read_category_files_from_dir (categories, data_dir);
- g_free (data_dir);
+ data_dir = USER_CONFIG_DIR;
+ categories = read_category_files_from_dir (categories, data_dir);
+ g_free (data_dir);
- if (categories == NULL) {
- g_critical (_("Unable to locate category definitions. Libglabels may not be installed correctly!"));
- }
+ if (categories == NULL)
+ {
+ g_critical (_("Unable to locate category definitions. Libglabels may not be installed correctly!"));
+ }
- return categories;
+ return categories;
}
read_category_files_from_dir (GList *categories,
const gchar *dirname)
{
- GDir *dp;
- const gchar *filename, *extension;
- gchar *full_filename = NULL;
- GError *gerror = NULL;
- GList *new_categories = NULL;
+ GDir *dp;
+ const gchar *filename, *extension;
+ gchar *full_filename = NULL;
+ GError *gerror = NULL;
+ GList *new_categories = NULL;
- if (dirname == NULL) {
- return categories;
- }
+ if (dirname == NULL)
+ {
+ return categories;
+ }
- if (!g_file_test (dirname, G_FILE_TEST_EXISTS)) {
- return categories;
- }
+ if (!g_file_test (dirname, G_FILE_TEST_EXISTS))
+ {
+ return categories;
+ }
- dp = g_dir_open (dirname, 0, &gerror);
- if (gerror != NULL) {
- g_message ("cannot open data directory: %s", gerror->message );
- return categories;
- }
+ dp = g_dir_open (dirname, 0, &gerror);
+ if (gerror != NULL)
+ {
+ g_message ("cannot open data directory: %s", gerror->message );
+ return categories;
+ }
- while ((filename = g_dir_read_name (dp)) != NULL) {
+ while ((filename = g_dir_read_name (dp)) != NULL)
+ {
- extension = strrchr (filename, '.');
+ extension = strrchr (filename, '.');
- if (extension != NULL) {
+ if (extension != NULL)
+ {
- if ( ASCII_EQUAL (filename, "categories.xml") )
+ if ( ASCII_EQUAL (filename, "categories.xml") )
{
- full_filename =
- g_build_filename (dirname, filename, NULL);
- new_categories =
- lgl_xml_category_read_categories_from_file (full_filename);
- g_free (full_filename);
+ full_filename =
+ g_build_filename (dirname, filename, NULL);
+ new_categories =
+ lgl_xml_category_read_categories_from_file (full_filename);
+ g_free (full_filename);
- categories = g_list_concat (categories, new_categories);
- new_categories = NULL;
+ categories = g_list_concat (categories, new_categories);
+ new_categories = NULL;
- }
+ }
- }
+ }
- }
+ }
- g_dir_close (dp);
+ g_dir_close (dp);
- return categories;
+ return categories;
}
void
lgl_db_print_known_categories (void)
{
- GList *p;
- lglCategory *category;
-
- if (!model) {
- lgl_db_init ();
- }
+ GList *p;
+ lglCategory *category;
- g_print ("%s():\n", __FUNCTION__);
- for (p = model->categories; p != NULL; p = p->next) {
- category = (lglCategory *) p->data;
+ if (!model)
+ {
+ lgl_db_init ();
+ }
- g_print ("CATEGORY id=\"%s\", name=\"%s\"\n", category->id, category->name);
+ g_print ("%s():\n", __FUNCTION__);
+ for (p = model->categories; p != NULL; p = p->next)
+ {
+ category = (lglCategory *) p->data;
- }
- g_print ("\n");
+ g_print ("CATEGORY id=\"%s\", name=\"%s\"\n", category->id, category->name);
+ }
+ g_print ("\n");
}
GList *
lgl_db_get_vendor_name_list (void)
{
- GList *names = NULL;
- GList *p;
- lglVendor *vendor;
+ GList *names = NULL;
+ GList *p;
+ lglVendor *vendor;
- if (!model)
+ if (!model)
{
- lgl_db_init ();
- }
+ lgl_db_init ();
+ }
- for ( p=model->vendors; p != NULL; p=p->next )
+ for ( p=model->vendors; p != NULL; p=p->next )
{
- vendor = (lglVendor *)p->data;
- names = g_list_append (names, g_strdup (vendor->name));
- }
+ vendor = (lglVendor *)p->data;
+ names = g_list_append (names, g_strdup (vendor->name));
+ }
- return names;
+ return names;
}
void
lgl_db_free_vendor_name_list (GList *names)
{
- GList *p;
+ GList *p;
- for (p = names; p != NULL; p = p->next)
+ for (p = names; p != NULL; p = p->next)
{
- g_free (p->data);
- p->data = NULL;
- }
+ g_free (p->data);
+ p->data = NULL;
+ }
- g_list_free (names);
+ g_list_free (names);
}
lglVendor *
lgl_db_lookup_vendor_from_name (const gchar *name)
{
- GList *p;
- lglVendor *vendor;
+ GList *p;
+ lglVendor *vendor;
- if (!model)
+ if (!model)
{
- lgl_db_init ();
- }
+ lgl_db_init ();
+ }
- if (name == NULL)
+ if (name == NULL)
{
- /* If no name, return first vendor as a default */
- return lgl_vendor_dup ((lglVendor *) model->vendors->data);
- }
+ /* If no name, return first vendor as a default */
+ return lgl_vendor_dup ((lglVendor *) model->vendors->data);
+ }
- for (p = model->vendors; p != NULL; p = p->next)
+ for (p = model->vendors; p != NULL; p = p->next)
{
- vendor = (lglVendor *) p->data;
- if (UTF8_EQUAL (vendor->name, name))
+ vendor = (lglVendor *) p->data;
+ if (UTF8_EQUAL (vendor->name, name))
{
- return lgl_vendor_dup (vendor);
- }
- }
+ return lgl_vendor_dup (vendor);
+ }
+ }
- return NULL;
+ return NULL;
}
gboolean
lgl_db_is_vendor_name_known (const gchar *name)
{
- GList *p;
- lglVendor *vendor;
+ GList *p;
+ lglVendor *vendor;
- if (!model)
+ if (!model)
{
- lgl_db_init ();
- }
+ lgl_db_init ();
+ }
- if (name == NULL)
+ if (name == NULL)
{
- return FALSE;
- }
+ return FALSE;
+ }
- for (p = model->vendors; p != NULL; p = p->next)
+ for (p = model->vendors; p != NULL; p = p->next)
{
- vendor = (lglVendor *) p->data;
- if (UTF8_EQUAL (vendor->name, name))
+ vendor = (lglVendor *) p->data;
+ if (UTF8_EQUAL (vendor->name, name))
{
- return TRUE;
- }
- }
+ return TRUE;
+ }
+ }
- return FALSE;
+ return FALSE;
}
static GList *
read_vendors (void)
{
- gchar *data_dir;
- GList *vendors = NULL;
+ gchar *data_dir;
+ GList *vendors = NULL;
- data_dir = SYSTEM_CONFIG_DIR;
- vendors = read_vendor_files_from_dir (vendors, data_dir);
- g_free (data_dir);
+ data_dir = SYSTEM_CONFIG_DIR;
+ vendors = read_vendor_files_from_dir (vendors, data_dir);
+ g_free (data_dir);
- data_dir = USER_CONFIG_DIR;
- vendors = read_vendor_files_from_dir (vendors, data_dir);
- g_free (data_dir);
+ data_dir = USER_CONFIG_DIR;
+ vendors = read_vendor_files_from_dir (vendors, data_dir);
+ g_free (data_dir);
- return vendors;
+ return vendors;
}
static GList *
read_vendor_files_from_dir (GList *vendors,
- const gchar *dirname)
+ const gchar *dirname)
{
- GDir *dp;
- const gchar *filename, *extension;
- gchar *full_filename = NULL;
- GError *gerror = NULL;
- GList *new_vendors = NULL;
+ GDir *dp;
+ const gchar *filename, *extension;
+ gchar *full_filename = NULL;
+ GError *gerror = NULL;
+ GList *new_vendors = NULL;
- if (dirname == NULL) {
- return vendors;
- }
+ if (dirname == NULL)
+ {
+ return vendors;
+ }
- if (!g_file_test (dirname, G_FILE_TEST_EXISTS)) {
- return vendors;
- }
+ if (!g_file_test (dirname, G_FILE_TEST_EXISTS))
+ {
+ return vendors;
+ }
- dp = g_dir_open (dirname, 0, &gerror);
- if (gerror != NULL) {
- g_message ("cannot open data directory: %s", gerror->message );
- return vendors;
- }
+ dp = g_dir_open (dirname, 0, &gerror);
+ if (gerror != NULL)
+ {
+ g_message ("cannot open data directory: %s", gerror->message );
+ return vendors;
+ }
- while ((filename = g_dir_read_name (dp)) != NULL) {
+ while ((filename = g_dir_read_name (dp)) != NULL)
+ {
- extension = strrchr (filename, '.');
+ extension = strrchr (filename, '.');
- if (extension != NULL) {
+ if (extension != NULL)
+ {
- if ( ASCII_EQUAL (filename, "vendors.xml") )
+ if ( ASCII_EQUAL (filename, "vendors.xml") )
{
- full_filename =
- g_build_filename (dirname, filename, NULL);
- new_vendors =
- lgl_xml_vendor_read_vendors_from_file (full_filename);
- g_free (full_filename);
+ full_filename =
+ g_build_filename (dirname, filename, NULL);
+ new_vendors =
+ lgl_xml_vendor_read_vendors_from_file (full_filename);
+ g_free (full_filename);
- vendors = g_list_concat (vendors, new_vendors);
- new_vendors = NULL;
+ vendors = g_list_concat (vendors, new_vendors);
+ new_vendors = NULL;
- }
+ }
- }
+ }
- }
+ }
- g_dir_close (dp);
+ g_dir_close (dp);
- return vendors;
+ return vendors;
}
void
lgl_db_print_known_vendors (void)
{
- GList *p;
- lglVendor *vendor;
-
- if (!model) {
- lgl_db_init ();
- }
+ GList *p;
+ lglVendor *vendor;
- g_print ("%s():\n", __FUNCTION__);
- for (p = model->vendors; p != NULL; p = p->next) {
- vendor = (lglVendor *) p->data;
+ if (!model)
+ {
+ lgl_db_init ();
+ }
- g_print ("VENDOR name=\"%s\", url=\"%s\"\n",
- vendor->name, vendor->url);
+ g_print ("%s():\n", __FUNCTION__);
+ for (p = model->vendors; p != NULL; p = p->next)
+ {
+ vendor = (lglVendor *) p->data;
- }
- g_print ("\n");
+ g_print ("VENDOR name=\"%s\", url=\"%s\"\n",
+ vendor->name, vendor->url);
+ }
+ g_print ("\n");
}
lgl_db_get_brand_list (const gchar *paper_id,
const gchar *category_id)
{
- GList *p_tmplt;
- lglTemplate *template;
- GList *brands = NULL;
+ GList *p_tmplt;
+ lglTemplate *template;
+ GList *brands = NULL;
- if (!model)
+ if (!model)
{
- lgl_db_init ();
- }
+ lgl_db_init ();
+ }
- for (p_tmplt = model->templates; p_tmplt != NULL; p_tmplt = p_tmplt->next)
+ for (p_tmplt = model->templates; p_tmplt != NULL; p_tmplt = p_tmplt->next)
{
- template = (lglTemplate *) p_tmplt->data;
- if (lgl_template_does_page_size_match (template, paper_id) &&
+ template = (lglTemplate *) p_tmplt->data;
+ if (lgl_template_does_page_size_match (template, paper_id) &&
lgl_template_does_category_match (template, category_id))
{
g_strdup (template->brand),
(GCompareFunc)lgl_str_utf8_casecmp);
}
- }
- }
+ }
+ }
- return brands;
+ return brands;
}
void
lgl_db_free_brand_list (GList *brands)
{
- GList *p_brand;
+ GList *p_brand;
- for (p_brand = brands; p_brand != NULL; p_brand = p_brand->next)
+ for (p_brand = brands; p_brand != NULL; p_brand = p_brand->next)
{
- g_free (p_brand->data);
- p_brand->data = NULL;
- }
+ g_free (p_brand->data);
+ p_brand->data = NULL;
+ }
- g_list_free (brands);
+ g_list_free (brands);
}
}
else
{
- g_message ("Duplicate template: %s %s.", template->brand, template->part);
+ g_message ("Duplicate template: %s %s.", template->brand, template->part);
}
}
gchar *dir, *filename, *abs_filename;
gint bytes_written;
- if (!model)
+ if (!model)
{
- lgl_db_init ();
- }
+ lgl_db_init ();
+ }
if (lgl_db_does_template_exist (template->brand, template->part))
{
return LGL_DB_REG_BRAND_PART_EXISTS;
}
- if (lgl_db_is_paper_id_known (template->paper_id))
+ if (lgl_db_is_paper_id_known (template->paper_id))
{
- dir = USER_CONFIG_DIR;
- g_mkdir_with_parents (dir, 0775); /* Try to make sure directory exists. */
- filename = g_strdup_printf ("%s_%s.template", template->brand, template->part);
- abs_filename = g_build_filename (dir, filename, NULL);
- bytes_written = lgl_xml_template_write_template_to_file (template, abs_filename);
- g_free (dir);
- g_free (filename);
- g_free (abs_filename);
+ dir = USER_CONFIG_DIR;
+ g_mkdir_with_parents (dir, 0775); /* Try to make sure directory exists. */
+ filename = g_strdup_printf ("%s_%s.template", template->brand, template->part);
+ abs_filename = g_build_filename (dir, filename, NULL);
+ bytes_written = lgl_xml_template_write_template_to_file (template, abs_filename);
+ g_free (dir);
+ g_free (filename);
+ g_free (abs_filename);
if (bytes_written > 0)
{
{
return LGL_DB_REG_FILE_WRITE_ERROR;
}
- }
+ }
else
{
- g_message ("Cannot register new template with unknown page size.");
+ g_message ("Cannot register new template with unknown page size.");
return LGL_DB_REG_BAD_PAPER_ID;
- }
+ }
}
gchar *dir, *filename, *abs_filename;
GList *p;
- if (!model)
+ if (!model)
{
- lgl_db_init ();
- }
+ lgl_db_init ();
+ }
if (!lgl_db_does_template_name_exist (name))
{
template = lgl_db_lookup_template_from_name (name);
if ( lgl_template_does_category_match (template, "user-defined") )
{
- dir = USER_CONFIG_DIR;
- filename = g_strdup_printf ("%s_%s.template", template->brand, template->part);
- abs_filename = g_build_filename (dir, filename, NULL);
+ dir = USER_CONFIG_DIR;
+ filename = g_strdup_printf ("%s_%s.template", template->brand, template->part);
+ abs_filename = g_build_filename (dir, filename, NULL);
if (!g_file_test (abs_filename, G_FILE_TEST_EXISTS))
{
g_unlink (abs_filename);
- g_free (dir);
- g_free (filename);
- g_free (abs_filename);
+ g_free (dir);
+ g_free (filename);
+ g_free (abs_filename);
for ( p=model->templates; p != NULL; p=p->next )
{
lgl_db_does_template_exist (const gchar *brand,
const gchar *part)
{
- GList *p_tmplt;
- lglTemplate *template;
+ GList *p_tmplt;
+ lglTemplate *template;
- if (!model)
+ if (!model)
{
- lgl_db_init ();
- }
+ lgl_db_init ();
+ }
- if ((brand == NULL) || (part == NULL))
+ if ((brand == NULL) || (part == NULL))
{
- return FALSE;
- }
+ return FALSE;
+ }
- for (p_tmplt = model->templates; p_tmplt != NULL; p_tmplt = p_tmplt->next)
+ for (p_tmplt = model->templates; p_tmplt != NULL; p_tmplt = p_tmplt->next)
{
- template = (lglTemplate *) p_tmplt->data;
+ template = (lglTemplate *) p_tmplt->data;
if ( UTF8_EQUAL (brand, template->brand) &&
UTF8_EQUAL (part, template->part) )
{
return TRUE;
}
- }
+ }
- return FALSE;
+ return FALSE;
}
gboolean
lgl_db_does_template_name_exist (const gchar *name)
{
- GList *p_tmplt;
+ GList *p_tmplt;
lglTemplate *template;
gchar *candidate_name;
- if (!model)
+ if (!model)
{
- lgl_db_init ();
- }
+ lgl_db_init ();
+ }
- if (name == NULL)
+ if (name == NULL)
{
- return FALSE;
- }
+ return FALSE;
+ }
- for (p_tmplt = model->templates; p_tmplt != NULL; p_tmplt = p_tmplt->next)
+ for (p_tmplt = model->templates; p_tmplt != NULL; p_tmplt = p_tmplt->next)
{
- template = (lglTemplate *) p_tmplt->data;
+ template = (lglTemplate *) p_tmplt->data;
candidate_name = g_strdup_printf ("%s %s", template->brand, template->part);
if ( UTF8_EQUAL (candidate_name, name) )
return TRUE;
}
g_free (candidate_name);
- }
+ }
- return FALSE;
+ return FALSE;
}
const gchar *paper_id,
const gchar *category_id)
{
- GList *p_tmplt;
- lglTemplate *template;
+ GList *p_tmplt;
+ lglTemplate *template;
gchar *name;
- GList *names = NULL;
+ GList *names = NULL;
- if (!model)
+ if (!model)
{
- lgl_db_init ();
- }
+ lgl_db_init ();
+ }
- for (p_tmplt = model->templates; p_tmplt != NULL; p_tmplt = p_tmplt->next)
+ for (p_tmplt = model->templates; p_tmplt != NULL; p_tmplt = p_tmplt->next)
{
- template = (lglTemplate *) p_tmplt->data;
- if (lgl_template_does_brand_match (template, brand) &&
+ template = (lglTemplate *) p_tmplt->data;
+ if (lgl_template_does_brand_match (template, brand) &&
lgl_template_does_page_size_match (template, paper_id) &&
lgl_template_does_category_match (template, category_id))
{
name = g_strdup_printf ("%s %s", template->brand, template->part);
names = g_list_insert_sorted (names, name, (GCompareFunc)lgl_str_part_name_cmp);
- }
- }
+ }
+ }
- return names;
+ return names;
}
GList *
lgl_db_get_similar_template_name_list (const gchar *name)
{
- GList *p_tmplt;
- lglTemplate *template1;
- lglTemplate *template2;
+ GList *p_tmplt;
+ lglTemplate *template1;
+ lglTemplate *template2;
gchar *name2;
- GList *names = NULL;
+ GList *names = NULL;
- if (!model)
+ if (!model)
{
- lgl_db_init ();
- }
+ lgl_db_init ();
+ }
if ( !name )
{
return NULL;
}
- for (p_tmplt = model->templates; p_tmplt != NULL; p_tmplt = p_tmplt->next)
+ for (p_tmplt = model->templates; p_tmplt != NULL; p_tmplt = p_tmplt->next)
{
- template2 = (lglTemplate *) p_tmplt->data;
+ template2 = (lglTemplate *) p_tmplt->data;
if ( lgl_template_are_templates_identical (template1, template2) )
{
(GCompareFunc)lgl_str_part_name_cmp);
}
- }
- }
+ }
+ }
- return names;
+ return names;
}
void
lgl_db_free_template_name_list (GList *names)
{
- GList *p_name;
+ GList *p_name;
- for (p_name = names; p_name != NULL; p_name = p_name->next)
+ for (p_name = names; p_name != NULL; p_name = p_name->next)
{
- g_free (p_name->data);
- p_name->data = NULL;
- }
+ g_free (p_name->data);
+ p_name->data = NULL;
+ }
- g_list_free (names);
+ g_list_free (names);
}
lglTemplate *
lgl_db_lookup_template_from_name (const gchar *name)
{
- lglTemplate *template;
- lglTemplate *new_template;
+ lglTemplate *template;
+ lglTemplate *new_template;
- if (!model)
+ if (!model)
{
- lgl_db_init ();
- }
+ lgl_db_init ();
+ }
- if (name == NULL)
+ if (name == NULL)
{
- /* If no name, return first template as a default */
- return lgl_template_dup ((lglTemplate *) model->templates->data);
- }
+ /* If no name, return first template as a default */
+ return lgl_template_dup ((lglTemplate *) model->templates->data);
+ }
template = g_hash_table_lookup (model->template_cache, name);
return new_template;
}
- /* No matching template has been found so return the first template */
- return lgl_template_dup ((lglTemplate *) model->templates->data);
+ /* No matching template has been found so return the first template */
+ return lgl_template_dup ((lglTemplate *) model->templates->data);
}
const gchar *part)
{
gchar *name;
- lglTemplate *template;
- lglTemplate *new_template;
+ lglTemplate *template;
+ lglTemplate *new_template;
- if (!model)
+ if (!model)
{
- lgl_db_init ();
- }
+ lgl_db_init ();
+ }
- if ((brand == NULL) || (part == NULL))
+ if ((brand == NULL) || (part == NULL))
{
- /* If no name, return first template as a default */
- return lgl_template_dup ((lglTemplate *) model->templates->data);
- }
+ /* If no name, return first template as a default */
+ return lgl_template_dup ((lglTemplate *) model->templates->data);
+ }
name = g_strdup_printf ("%s %s", brand, part);
template = g_hash_table_lookup (model->template_cache, name);
return new_template;
}
- /* No matching template has been found so return the first template */
+ /* No matching template has been found so return the first template */
g_free (name);
- return lgl_template_dup ((lglTemplate *) model->templates->data);
+ return lgl_template_dup ((lglTemplate *) model->templates->data);
}
void
read_templates (void)
{
- gchar *data_dir;
+ gchar *data_dir;
GList *p;
lglTemplate *template;
/*
* User defined templates. Add to user-defined category.
*/
- data_dir = USER_CONFIG_DIR;
- read_template_files_from_dir (data_dir);
- g_free (data_dir);
+ data_dir = USER_CONFIG_DIR;
+ read_template_files_from_dir (data_dir);
+ g_free (data_dir);
for ( p=model->templates; p != NULL; p=p->next )
{
template = (lglTemplate *)p->data;
/*
* Alternate user defined templates. (Used for manually created templates).
*/
- data_dir = ALT_USER_CONFIG_DIR;
- read_template_files_from_dir (data_dir);
- g_free (data_dir);
+ data_dir = ALT_USER_CONFIG_DIR;
+ read_template_files_from_dir (data_dir);
+ g_free (data_dir);
/*
* System templates.
*/
- data_dir = SYSTEM_CONFIG_DIR;
- read_template_files_from_dir (data_dir);
- g_free (data_dir);
+ data_dir = SYSTEM_CONFIG_DIR;
+ read_template_files_from_dir (data_dir);
+ g_free (data_dir);
- if (model->templates == NULL)
+ if (model->templates == NULL)
{
- g_critical (_("Unable to locate any template files. Libglabels may not be installed correctly!"));
- }
+ g_critical (_("Unable to locate any template files. Libglabels may not be installed correctly!"));
+ }
}
void
read_template_files_from_dir (const gchar *dirname)
{
- GDir *dp;
- const gchar *filename, *extension, *extension2;
- gchar *full_filename = NULL;
- GError *gerror = NULL;
+ GDir *dp;
+ const gchar *filename, *extension, *extension2;
+ gchar *full_filename = NULL;
+ GError *gerror = NULL;
- if (dirname == NULL)
- return;
+ if (dirname == NULL)
+ return;
- if (!g_file_test (dirname, G_FILE_TEST_EXISTS))
+ if (!g_file_test (dirname, G_FILE_TEST_EXISTS))
{
- return;
- }
+ return;
+ }
- dp = g_dir_open (dirname, 0, &gerror);
- if (gerror != NULL)
+ dp = g_dir_open (dirname, 0, &gerror);
+ if (gerror != NULL)
{
- g_message ("cannot open data directory: %s", gerror->message );
- return;
- }
+ g_message ("cannot open data directory: %s", gerror->message );
+ return;
+ }
- while ((filename = g_dir_read_name (dp)) != NULL)
+ while ((filename = g_dir_read_name (dp)) != NULL)
{
- extension = strrchr (filename, '.');
- extension2 = strrchr (filename, '-');
+ extension = strrchr (filename, '.');
+ extension2 = strrchr (filename, '-');
- if ( (extension && ASCII_EQUAL (extension, ".template")) ||
- (extension2 && ASCII_EQUAL (extension2, "-templates.xml")) )
+ if ( (extension && ASCII_EQUAL (extension, ".template")) ||
+ (extension2 && ASCII_EQUAL (extension2, "-templates.xml")) )
{
- full_filename = g_build_filename (dirname, filename, NULL);
+ full_filename = g_build_filename (dirname, filename, NULL);
lgl_xml_template_read_templates_from_file (full_filename);
- g_free (full_filename);
- }
+ g_free (full_filename);
+ }
- }
+ }
- g_dir_close (dp);
+ g_dir_close (dp);
}
static lglTemplate *
template_full_page (const gchar *paper_id)
{
- lglPaper *paper = NULL;
- lglTemplate *template = NULL;
- lglTemplateFrame *frame = NULL;
+ lglPaper *paper = NULL;
+ lglTemplate *template = NULL;
+ lglTemplateFrame *frame = NULL;
gchar *part;
gchar *desc;
- g_return_val_if_fail (paper_id, NULL);
+ g_return_val_if_fail (paper_id, NULL);
- paper = lgl_db_lookup_paper_from_id (paper_id);
- if ( paper == NULL )
+ paper = lgl_db_lookup_paper_from_id (paper_id);
+ if ( paper == NULL )
{
- return NULL;
- }
+ return NULL;
+ }
- part = g_strdup_printf ("%s-Full-Page", paper->id);
- desc = g_strdup_printf (_("%s full page label"), paper->name);
+ part = g_strdup_printf ("%s-Full-Page", paper->id);
+ desc = g_strdup_printf (_("%s full page label"), paper->name);
- template = lgl_template_new ("Generic", part, desc,
+ template = lgl_template_new ("Generic", part, desc,
paper_id, paper->width, paper->height);
- frame = lgl_template_frame_rect_new ("0",
+ frame = lgl_template_frame_rect_new ("0",
paper->width,
paper->height,
0.0,
0.0,
0.0);
- lgl_template_add_frame (template, frame);
+ lgl_template_add_frame (template, frame);
- lgl_template_frame_add_layout (frame, lgl_template_layout_new (1, 1, 0., 0., 0., 0.));
+ lgl_template_frame_add_layout (frame, lgl_template_layout_new (1, 1, 0., 0., 0., 0.));
- lgl_template_frame_add_markup (frame, lgl_template_markup_margin_new (9.0));
+ lgl_template_frame_add_markup (frame, lgl_template_markup_margin_new (9.0));
- g_free (desc);
- desc = NULL;
- lgl_paper_free (paper);
- paper = NULL;
+ g_free (desc);
+ desc = NULL;
+ lgl_paper_free (paper);
+ paper = NULL;
- return template;
+ return template;
}
void
lgl_db_print_known_templates (void)
{
- GList *p;
- lglTemplate *template;
+ GList *p;
+ lglTemplate *template;
if (!model)
{
lgl_db_init ();
}
- g_print ("%s():\n", __FUNCTION__);
- for (p=model->templates; p!=NULL; p=p->next)
+ g_print ("%s():\n", __FUNCTION__);
+ for (p=model->templates; p!=NULL; p=p->next)
{
- template = (lglTemplate *)p->data;
+ template = (lglTemplate *)p->data;
- g_print("TEMPLATE brand=\"%s\", part=\"%s\", description=\"%s\"\n",
- template->brand, template->part, template->description);
+ g_print("TEMPLATE brand=\"%s\", part=\"%s\", description=\"%s\"\n",
+ template->brand, template->part, template->description);
- }
- g_print ("\n");
+ }
+ g_print ("\n");
}
*/
lglPaper *
lgl_paper_new (gchar *id,
- gchar *name,
- gdouble width,
- gdouble height,
- gchar *pwg_size)
+ gchar *name,
+ gdouble width,
+ gdouble height,
+ gchar *pwg_size)
{
- lglPaper *paper;
+ lglPaper *paper;
- paper = g_new0 (lglPaper,1);
+ paper = g_new0 (lglPaper,1);
- paper->id = g_strdup (id);
- paper->name = g_strdup (name);
- paper->width = width;
- paper->height = height;
- paper->pwg_size = g_strdup (pwg_size);
+ paper->id = g_strdup (id);
+ paper->name = g_strdup (name);
+ paper->width = width;
+ paper->height = height;
+ paper->pwg_size = g_strdup (pwg_size);
- return paper;
+ return paper;
}
*/
lglPaper *lgl_paper_dup (const lglPaper *orig)
{
- lglPaper *paper;
+ lglPaper *paper;
- g_return_val_if_fail (orig, NULL);
+ g_return_val_if_fail (orig, NULL);
- paper = g_new0 (lglPaper,1);
+ paper = g_new0 (lglPaper,1);
- paper->id = g_strdup (orig->id);
- paper->name = g_strdup (orig->name);
- paper->width = orig->width;
- paper->height = orig->height;
- paper->pwg_size = g_strdup (orig->pwg_size);
+ paper->id = g_strdup (orig->id);
+ paper->name = g_strdup (orig->name);
+ paper->width = orig->width;
+ paper->height = orig->height;
+ paper->pwg_size = g_strdup (orig->pwg_size);
- return paper;
+ return paper;
}
void lgl_paper_free (lglPaper *paper)
{
- if ( paper != NULL ) {
+ if ( paper != NULL )
+ {
+ g_free (paper->id);
+ paper->id = NULL;
- g_free (paper->id);
- paper->id = NULL;
+ g_free (paper->name);
+ paper->name = NULL;
- g_free (paper->name);
- paper->name = NULL;
+ g_free (paper->pwg_size);
+ paper->pwg_size = NULL;
- g_free (paper->pwg_size);
- paper->pwg_size = NULL;
-
- g_free (paper);
- }
+ g_free (paper);
+ }
}
typedef struct _lglPaper lglPaper;
struct _lglPaper {
- gchar *id; /* Unique ID of paper definition */
- gchar *name; /* Localized name of paper */
- gdouble width; /* Width (in points) */
- gdouble height; /* Height (in points) */
- gchar *pwg_size; /* PWG 5101.1-2002 size name */
+ gchar *id; /* Unique ID of paper definition */
+ gchar *name; /* Localized name of paper */
+ gdouble width; /* Width (in points) */
+ gdouble height; /* Height (in points) */
+ gchar *pwg_size; /* PWG 5101.1-2002 size name */
};
* Paper construction
*/
lglPaper *lgl_paper_new (gchar *id,
- gchar *name,
- gdouble width,
- gdouble height,
- gchar *pwg_size);
+ gchar *name,
+ gdouble width,
+ gdouble height,
+ gchar *pwg_size);
lglPaper *lgl_paper_dup (const lglPaper *orig);
gboolean done;
gint result;
- if ( s1 == s2 ) return 0;
- if (s1 == NULL) return -1;
- if (s2 == NULL) return 1;
+ if ( s1 == s2 ) return 0;
+ if (s1 == NULL) return -1;
+ if (s2 == NULL) return 1;
folded_s1 = g_utf8_casefold (s1, -1);
folded_s2 = g_utf8_casefold (s2, -1);
isnum2 = FALSE;
}
- if ( (strlen(chunk1) == 0) && (strlen(chunk2) == 0) )
+ if ( (*chunk1 == '\0') && (*chunk2 == '\0') )
{
/* Case 1: Both are empty. */
done = TRUE;
gchar *
lgl_str_format_fraction (gdouble x)
{
- static gdouble denom[] = { 1., 2., 3., 4., 8., 16., 32., 0. };
+ static gdouble denom[] = { 1., 2., 3., 4., 8., 16., 32., 0. };
static gchar *denom_string[] = { "1", "₂", "₃", "₄", "₈", "₁₆", "₃₂", NULL };
static gchar *num_string[] = { "⁰", "¹", "²", "³", "⁴", "⁵", "⁶", "⁷", "⁸", "⁹",
"¹⁰", "¹¹", "¹²", "¹³", "¹⁴", "¹⁵", "¹⁶", "¹⁷", "¹⁸", "¹⁹",
"²⁰", "²¹", "²²", "²³", "²⁴", "²⁵", "²⁶", "²⁷", "²⁸", "²⁹",
"³⁰", "³¹" };
- gint i;
- gdouble product, remainder;
- gint n, d;
-
- for ( i=0; denom[i] != 0.0; i++ ) {
- product = x * denom[i];
- remainder = fabs(product - ((gint)(product+0.5)));
- if ( remainder < FRAC_EPSILON ) break;
- }
-
- if ( denom[i] == 0.0 ) {
- /* None of our denominators work. */
- return g_strdup_printf ("%.5g", x);
- }
- if ( denom[i] == 1.0 ) {
- /* Simple integer. */
- return g_strdup_printf ("%.0f", x);
- }
- n = (gint)( x * denom[i] + 0.5 );
- d = (gint)denom[i];
- if ( n > d ) {
- return g_strdup_printf ("%d%s/%s", (n/d), num_string[n%d], denom_string[i]);
- } else {
- return g_strdup_printf ("%s/%s", num_string[n%d], denom_string[i]);
- }
+ gint i;
+ gdouble product, remainder;
+ gint n, d;
+
+ for ( i=0; denom[i] != 0.0; i++ )
+ {
+ product = x * denom[i];
+ remainder = fabs(product - ((gint)(product+0.5)));
+ if ( remainder < FRAC_EPSILON ) break;
+ }
+
+ if ( denom[i] == 0.0 )
+ {
+ /* None of our denominators work. */
+ return g_strdup_printf ("%.5g", x);
+ }
+ if ( denom[i] == 1.0 )
+ {
+ /* Simple integer. */
+ return g_strdup_printf ("%.0f", x);
+ }
+ n = (gint)( x * denom[i] + 0.5 );
+ d = (gint)denom[i];
+ if ( n > d )
+ {
+ return g_strdup_printf ("%d%s/%s", (n/d), num_string[n%d], denom_string[i]);
+ }
+ else
+ {
+ return g_strdup_printf ("%s/%s", num_string[n%d], denom_string[i]);
+ }
}
gdouble page_width,
gdouble page_height)
{
- lglTemplate *template;
+ lglTemplate *template;
- template = g_new0 (lglTemplate,1);
+ template = g_new0 (lglTemplate,1);
- template->brand = g_strdup (brand);
- template->part = g_strdup (part);
- template->description = g_strdup (description);
- template->paper_id = g_strdup (paper_id);
- template->page_width = page_width;
- template->page_height = page_height;
+ template->brand = g_strdup (brand);
+ template->part = g_strdup (part);
+ template->description = g_strdup (description);
+ template->paper_id = g_strdup (paper_id);
+ template->page_width = page_width;
+ template->page_height = page_height;
- return template;
+ return template;
}
gchar *
lgl_template_get_name (const lglTemplate *template)
{
- g_return_val_if_fail (template, NULL);
+ g_return_val_if_fail (template, NULL);
return g_strdup_printf ("%s %s", template->brand, template->part);
}
lgl_template_do_templates_match (const lglTemplate *template1,
const lglTemplate *template2)
{
- g_return_val_if_fail (template1, FALSE);
- g_return_val_if_fail (template2, FALSE);
+ g_return_val_if_fail (template1, FALSE);
+ g_return_val_if_fail (template2, FALSE);
return (UTF8_EQUAL (template1->brand, template2->brand) &&
UTF8_EQUAL (template1->part, template2->part));
lgl_template_does_brand_match (const lglTemplate *template,
const gchar *brand)
{
- g_return_val_if_fail (template, FALSE);
+ g_return_val_if_fail (template, FALSE);
/* NULL matches everything. */
if (brand == NULL)
lgl_template_does_page_size_match (const lglTemplate *template,
const gchar *paper_id)
{
- g_return_val_if_fail (template, FALSE);
+ g_return_val_if_fail (template, FALSE);
/* NULL matches everything. */
if (paper_id == NULL)
{
GList *p;
- g_return_val_if_fail (template, FALSE);
+ g_return_val_if_fail (template, FALSE);
/* NULL matches everything. */
if (category_id == NULL)
lgl_template_add_frame (lglTemplate *template,
lglTemplateFrame *frame)
{
- g_return_if_fail (template);
- g_return_if_fail (frame);
+ g_return_if_fail (template);
+ g_return_if_fail (frame);
- template->frames = g_list_append (template->frames, frame);
+ template->frames = g_list_append (template->frames, frame);
}
lgl_template_add_category (lglTemplate *template,
const gchar *category_id)
{
- g_return_if_fail (template);
- g_return_if_fail (category_id);
+ g_return_if_fail (template);
+ g_return_if_fail (category_id);
- template->category_ids = g_list_append (template->category_ids,
+ template->category_ids = g_list_append (template->category_ids,
g_strdup (category_id));
}
gdouble x_waste,
gdouble y_waste)
{
- lglTemplateFrame *frame;
+ lglTemplateFrame *frame;
- frame = g_new0 (lglTemplateFrame, 1);
+ frame = g_new0 (lglTemplateFrame, 1);
- frame->shape = LGL_TEMPLATE_FRAME_SHAPE_RECT;
- frame->rect.id = g_strdup (id);
+ frame->shape = LGL_TEMPLATE_FRAME_SHAPE_RECT;
+ frame->rect.id = g_strdup (id);
- frame->rect.w = w;
- frame->rect.h = h;
- frame->rect.r = r;
- frame->rect.x_waste = x_waste;
- frame->rect.y_waste = y_waste;
+ frame->rect.w = w;
+ frame->rect.h = h;
+ frame->rect.r = r;
+ frame->rect.x_waste = x_waste;
+ frame->rect.y_waste = y_waste;
- return frame;
+ return frame;
}
gdouble h,
gdouble waste)
{
- lglTemplateFrame *frame;
+ lglTemplateFrame *frame;
- frame = g_new0 (lglTemplateFrame, 1);
+ frame = g_new0 (lglTemplateFrame, 1);
- frame->shape = LGL_TEMPLATE_FRAME_SHAPE_ELLIPSE;
- frame->ellipse.id = g_strdup (id);
+ frame->shape = LGL_TEMPLATE_FRAME_SHAPE_ELLIPSE;
+ frame->ellipse.id = g_strdup (id);
- frame->ellipse.w = w;
- frame->ellipse.h = h;
- frame->ellipse.waste = waste;
+ frame->ellipse.w = w;
+ frame->ellipse.h = h;
+ frame->ellipse.waste = waste;
- return frame;
+ return frame;
}
gdouble r,
gdouble waste)
{
- lglTemplateFrame *frame;
+ lglTemplateFrame *frame;
- frame = g_new0 (lglTemplateFrame, 1);
+ frame = g_new0 (lglTemplateFrame, 1);
- frame->shape = LGL_TEMPLATE_FRAME_SHAPE_ROUND;
- frame->round.id = g_strdup (id);
+ frame->shape = LGL_TEMPLATE_FRAME_SHAPE_ROUND;
+ frame->round.id = g_strdup (id);
- frame->round.r = r;
- frame->round.waste = waste;
+ frame->round.r = r;
+ frame->round.waste = waste;
- return frame;
+ return frame;
}
gdouble h,
gdouble waste)
{
- lglTemplateFrame *frame;
+ lglTemplateFrame *frame;
- frame = g_new0 (lglTemplateFrame, 1);
+ frame = g_new0 (lglTemplateFrame, 1);
- frame->shape = LGL_TEMPLATE_FRAME_SHAPE_CD;
- frame->cd.id = g_strdup (id);
+ frame->shape = LGL_TEMPLATE_FRAME_SHAPE_CD;
+ frame->cd.id = g_strdup (id);
- frame->cd.r1 = r1;
- frame->cd.r2 = r2;
- frame->cd.w = w;
- frame->cd.h = h;
- frame->cd.waste = waste;
+ frame->cd.r1 = r1;
+ frame->cd.r2 = r2;
+ frame->cd.w = w;
+ frame->cd.h = h;
+ frame->cd.waste = waste;
- return frame;
+ return frame;
}
gdouble *w,
gdouble *h)
{
- g_return_if_fail (frame);
-
- switch (frame->shape) {
- case LGL_TEMPLATE_FRAME_SHAPE_RECT:
- *w = frame->rect.w;
- *h = frame->rect.h;
- break;
- case LGL_TEMPLATE_FRAME_SHAPE_ELLIPSE:
- *w = frame->ellipse.w;
- *h = frame->ellipse.h;
- break;
- case LGL_TEMPLATE_FRAME_SHAPE_ROUND:
- *w = 2.0 * frame->round.r;
- *h = 2.0 * frame->round.r;
- break;
- case LGL_TEMPLATE_FRAME_SHAPE_CD:
- if (frame->cd.w == 0.0) {
- *w = 2.0 * frame->cd.r1;
- } else {
- *w = frame->cd.w;
- }
- if (frame->cd.h == 0.0) {
- *h = 2.0 * frame->cd.r1;
- } else {
- *h = frame->cd.h;
- }
- break;
- default:
- *w = 0.0;
- *h = 0.0;
- break;
- }
+ g_return_if_fail (frame);
+
+ switch (frame->shape)
+ {
+ case LGL_TEMPLATE_FRAME_SHAPE_RECT:
+ *w = frame->rect.w;
+ *h = frame->rect.h;
+ break;
+ case LGL_TEMPLATE_FRAME_SHAPE_ELLIPSE:
+ *w = frame->ellipse.w;
+ *h = frame->ellipse.h;
+ break;
+ case LGL_TEMPLATE_FRAME_SHAPE_ROUND:
+ *w = 2.0 * frame->round.r;
+ *h = 2.0 * frame->round.r;
+ break;
+ case LGL_TEMPLATE_FRAME_SHAPE_CD:
+ if (frame->cd.w == 0.0)
+ {
+ *w = 2.0 * frame->cd.r1;
+ }
+ else
+ {
+ *w = frame->cd.w;
+ }
+ if (frame->cd.h == 0.0)
+ {
+ *h = 2.0 * frame->cd.r1;
+ }
+ else
+ {
+ *h = frame->cd.h;
+ }
+ break;
+ default:
+ *w = 0.0;
+ *h = 0.0;
+ break;
+ }
}
gint
lgl_template_frame_get_n_labels (const lglTemplateFrame *frame)
{
- gint n_labels = 0;
- GList *p;
- lglTemplateLayout *layout;
+ gint n_labels = 0;
+ GList *p;
+ lglTemplateLayout *layout;
- g_return_val_if_fail (frame, 0);
+ g_return_val_if_fail (frame, 0);
- for ( p=frame->all.layouts; p != NULL; p=p->next ) {
- layout = (lglTemplateLayout *)p->data;
+ for ( p=frame->all.layouts; p != NULL; p=p->next )
+ {
+ layout = (lglTemplateLayout *)p->data;
- n_labels += layout->nx * layout->ny;
- }
+ n_labels += layout->nx * layout->ny;
+ }
- return n_labels;
+ return n_labels;
}
units_string = lgl_units_get_name (units);
units_per_point = lgl_units_get_units_per_point (units);
- switch (frame->shape) {
+ switch (frame->shape)
+ {
+
case LGL_TEMPLATE_FRAME_SHAPE_RECT:
- if ( units == LGL_UNITS_INCH ) {
+ if ( units == LGL_UNITS_INCH )
+ {
gchar *xstr, *ystr;
xstr = lgl_str_format_fraction (frame->rect.w*units_per_point);
xstr, ystr, units_string);
g_free (xstr);
g_free (ystr);
- } else {
+ }
+ else
+ {
string = g_strdup_printf ("%.5g × %.5g %s",
frame->rect.w*units_per_point,
frame->rect.h*units_per_point,
units_string);
}
break;
+
case LGL_TEMPLATE_FRAME_SHAPE_ELLIPSE:
- if ( units == LGL_UNITS_INCH ) {
+ if ( units == LGL_UNITS_INCH )
+ {
gchar *xstr, *ystr;
xstr = lgl_str_format_fraction (frame->ellipse.w*units_per_point);
xstr, ystr, units_string);
g_free (xstr);
g_free (ystr);
- } else {
+ }
+ else
+ {
string = g_strdup_printf ("%.5g × %.5g %s",
frame->ellipse.w*units_per_point,
frame->ellipse.h*units_per_point,
units_string);
}
break;
+
case LGL_TEMPLATE_FRAME_SHAPE_ROUND:
- if ( units == LGL_UNITS_INCH ) {
+ if ( units == LGL_UNITS_INCH )
+ {
gchar *dstr;
dstr = lgl_str_format_fraction (2.0*frame->round.r*units_per_point);
dstr, units_string,
_("diameter"));
g_free (dstr);
- } else {
+ }
+ else
+ {
string = g_strdup_printf ("%.5g %s %s",
2.0*frame->round.r*units_per_point,
units_string,
_("diameter"));
}
break;
+
case LGL_TEMPLATE_FRAME_SHAPE_CD:
- if ( units == LGL_UNITS_INCH ) {
+ if ( units == LGL_UNITS_INCH )
+ {
gchar *dstr;
dstr = lgl_str_format_fraction (2.0*frame->cd.r1*units_per_point);
dstr, units_string,
_("diameter"));
g_free (dstr);
- } else {
+ }
+ else
+ {
string = g_strdup_printf ("%.5g %s %s",
2.0*frame->cd.r1*units_per_point,
units_string,
_("diameter"));
}
break;
+
default:
break;
+
}
return string;
lglTemplateOrigin *
lgl_template_frame_get_origins (const lglTemplateFrame *frame)
{
- gint i_label, n_labels, ix, iy;
- lglTemplateOrigin *origins;
- GList *p;
- lglTemplateLayout *layout;
+ gint i_label, n_labels, ix, iy;
+ lglTemplateOrigin *origins;
+ GList *p;
+ lglTemplateLayout *layout;
- g_return_val_if_fail (frame, NULL);
+ g_return_val_if_fail (frame, NULL);
- n_labels = lgl_template_frame_get_n_labels (frame);
- origins = g_new0 (lglTemplateOrigin, n_labels);
+ n_labels = lgl_template_frame_get_n_labels (frame);
+ origins = g_new0 (lglTemplateOrigin, n_labels);
- i_label = 0;
- for ( p=frame->all.layouts; p != NULL; p=p->next ) {
- layout = (lglTemplateLayout *)p->data;
+ i_label = 0;
+ for ( p=frame->all.layouts; p != NULL; p=p->next )
+ {
+ layout = (lglTemplateLayout *)p->data;
- for (iy = 0; iy < layout->ny; iy++) {
- for (ix = 0; ix < layout->nx; ix++, i_label++) {
- origins[i_label].x = ix*layout->dx + layout->x0;
- origins[i_label].y = iy*layout->dy + layout->y0;
- }
- }
- }
+ for (iy = 0; iy < layout->ny; iy++)
+ {
+ for (ix = 0; ix < layout->nx; ix++, i_label++)
+ {
+ origins[i_label].x = ix*layout->dx + layout->x0;
+ origins[i_label].y = iy*layout->dy + layout->y0;
+ }
+ }
+ }
- g_qsort_with_data (origins, n_labels, sizeof(lglTemplateOrigin),
- compare_origins, NULL);
+ g_qsort_with_data (origins, n_labels, sizeof(lglTemplateOrigin),
+ compare_origins, NULL);
- return origins;
+ return origins;
}
lgl_template_frame_add_layout (lglTemplateFrame *frame,
lglTemplateLayout *layout)
{
- g_return_if_fail (frame);
- g_return_if_fail (layout);
+ g_return_if_fail (frame);
+ g_return_if_fail (layout);
- frame->all.layouts = g_list_append (frame->all.layouts, layout);
+ frame->all.layouts = g_list_append (frame->all.layouts, layout);
}
lgl_template_frame_add_markup (lglTemplateFrame *frame,
lglTemplateMarkup *markup)
{
- g_return_if_fail (frame);
- g_return_if_fail (markup);
+ g_return_if_fail (frame);
+ g_return_if_fail (markup);
- frame->all.markups = g_list_append (frame->all.markups, markup);
+ frame->all.markups = g_list_append (frame->all.markups, markup);
}
gdouble dx,
gdouble dy)
{
- lglTemplateLayout *layout;
+ lglTemplateLayout *layout;
- layout = g_new0 (lglTemplateLayout, 1);
+ layout = g_new0 (lglTemplateLayout, 1);
- layout->nx = nx;
- layout->ny = ny;
- layout->x0 = x0;
- layout->y0 = y0;
- layout->dx = dx;
- layout->dy = dy;
+ layout->nx = nx;
+ layout->ny = ny;
+ layout->x0 = x0;
+ layout->y0 = y0;
+ layout->dx = dx;
+ layout->dy = dy;
- return layout;
+ return layout;
}
lglTemplateMarkup *
lgl_template_markup_margin_new (gdouble size)
{
- lglTemplateMarkup *markup;
+ lglTemplateMarkup *markup;
- markup = g_new0 (lglTemplateMarkup, 1);
+ markup = g_new0 (lglTemplateMarkup, 1);
- markup->type = LGL_TEMPLATE_MARKUP_MARGIN;
- markup->margin.size = size;
+ markup->type = LGL_TEMPLATE_MARKUP_MARGIN;
+ markup->margin.size = size;
- return markup;
+ return markup;
}
gdouble x2,
gdouble y2)
{
- lglTemplateMarkup *markup;
+ lglTemplateMarkup *markup;
- markup = g_new0 (lglTemplateMarkup, 1);
+ markup = g_new0 (lglTemplateMarkup, 1);
- markup->type = LGL_TEMPLATE_MARKUP_LINE;
- markup->line.x1 = x1;
- markup->line.y1 = y1;
- markup->line.x2 = x2;
- markup->line.y2 = y2;
+ markup->type = LGL_TEMPLATE_MARKUP_LINE;
+ markup->line.x1 = x1;
+ markup->line.y1 = y1;
+ markup->line.x2 = x2;
+ markup->line.y2 = y2;
- return markup;
+ return markup;
}
gdouble y0,
gdouble r)
{
- lglTemplateMarkup *markup;
+ lglTemplateMarkup *markup;
- markup = g_new0 (lglTemplateMarkup, 1);
+ markup = g_new0 (lglTemplateMarkup, 1);
- markup->type = LGL_TEMPLATE_MARKUP_CIRCLE;
- markup->circle.x0 = x0;
- markup->circle.y0 = y0;
- markup->circle.r = r;
+ markup->type = LGL_TEMPLATE_MARKUP_CIRCLE;
+ markup->circle.x0 = x0;
+ markup->circle.y0 = y0;
+ markup->circle.r = r;
- return markup;
+ return markup;
}
gdouble h,
gdouble r)
{
- lglTemplateMarkup *markup;
+ lglTemplateMarkup *markup;
- markup = g_new0 (lglTemplateMarkup, 1);
+ markup = g_new0 (lglTemplateMarkup, 1);
- markup->type = LGL_TEMPLATE_MARKUP_RECT;
- markup->rect.x1 = x1;
- markup->rect.y1 = y1;
- markup->rect.w = w;
- markup->rect.h = h;
- markup->rect.r = r;
+ markup->type = LGL_TEMPLATE_MARKUP_RECT;
+ markup->rect.x1 = x1;
+ markup->rect.y1 = y1;
+ markup->rect.w = w;
+ markup->rect.h = h;
+ markup->rect.r = r;
- return markup;
+ return markup;
}
gdouble w,
gdouble h)
{
- lglTemplateMarkup *markup;
+ lglTemplateMarkup *markup;
- markup = g_new0 (lglTemplateMarkup, 1);
+ markup = g_new0 (lglTemplateMarkup, 1);
- markup->type = LGL_TEMPLATE_MARKUP_ELLIPSE;
- markup->ellipse.x1 = x1;
- markup->ellipse.y1 = y1;
- markup->ellipse.w = w;
- markup->ellipse.h = h;
+ markup->type = LGL_TEMPLATE_MARKUP_ELLIPSE;
+ markup->ellipse.x1 = x1;
+ markup->ellipse.y1 = y1;
+ markup->ellipse.w = w;
+ markup->ellipse.h = h;
- return markup;
+ return markup;
}
lglTemplate *
lgl_template_dup (const lglTemplate *orig_template)
{
- lglTemplate *template;
- GList *p;
- lglTemplateFrame *frame;
+ lglTemplate *template;
+ GList *p;
+ lglTemplateFrame *frame;
- g_return_val_if_fail (orig_template, NULL);
+ g_return_val_if_fail (orig_template, NULL);
- template = lgl_template_new (orig_template->brand,
+ template = lgl_template_new (orig_template->brand,
orig_template->part,
orig_template->description,
orig_template->paper_id,
template->product_url = g_strdup (orig_template->product_url);
- for ( p=orig_template->category_ids; p != NULL; p=p->next )
+ for ( p=orig_template->category_ids; p != NULL; p=p->next )
{
lgl_template_add_category (template, p->data);
- }
+ }
- for ( p=orig_template->frames; p != NULL; p=p->next )
+ for ( p=orig_template->frames; p != NULL; p=p->next )
{
- frame = (lglTemplateFrame *)p->data;
+ frame = (lglTemplateFrame *)p->data;
- lgl_template_add_frame (template, lgl_template_frame_dup (frame));
- }
+ lgl_template_add_frame (template, lgl_template_frame_dup (frame));
+ }
- return template;
+ return template;
}
void
lgl_template_free (lglTemplate *template)
{
- GList *p;
- lglTemplateFrame *frame;
-
- if ( template != NULL ) {
-
- g_free (template->brand);
- template->brand = NULL;
-
- g_free (template->part);
- template->part = NULL;
+ GList *p;
+ lglTemplateFrame *frame;
- g_free (template->description);
- template->description = NULL;
-
- g_free (template->paper_id);
- template->paper_id = NULL;
+ if ( template != NULL )
+ {
+ g_free (template->brand);
+ template->brand = NULL;
- for ( p=template->category_ids; p != NULL; p=p->next ) {
+ g_free (template->part);
+ template->part = NULL;
- g_free (p->data);
- p->data = NULL;
+ g_free (template->description);
+ template->description = NULL;
- }
- g_list_free (template->category_ids);
- template->category_ids = NULL;
+ g_free (template->paper_id);
+ template->paper_id = NULL;
- for ( p=template->frames; p != NULL; p=p->next ) {
+ for ( p=template->category_ids; p != NULL; p=p->next )
+ {
+ g_free (p->data);
+ p->data = NULL;
+ }
+ g_list_free (template->category_ids);
+ template->category_ids = NULL;
- frame = (lglTemplateFrame *)p->data;
+ for ( p=template->frames; p != NULL; p=p->next )
+ {
+ frame = (lglTemplateFrame *)p->data;
- lgl_template_frame_free (frame);
- p->data = NULL;
- }
- g_list_free (template->frames);
- template->frames = NULL;
+ lgl_template_frame_free (frame);
+ p->data = NULL;
+ }
+ g_list_free (template->frames);
+ template->frames = NULL;
- g_free (template);
+ g_free (template);
- }
+ }
}
lglTemplateFrame *
lgl_template_frame_dup (const lglTemplateFrame *orig_frame)
{
- lglTemplateFrame *frame;
- GList *p;
- lglTemplateLayout *layout;
- lglTemplateMarkup *markup;
+ lglTemplateFrame *frame;
+ GList *p;
+ lglTemplateLayout *layout;
+ lglTemplateMarkup *markup;
- g_return_val_if_fail (orig_frame, NULL);
+ g_return_val_if_fail (orig_frame, NULL);
- switch (orig_frame->shape) {
+ switch (orig_frame->shape)
+ {
- case LGL_TEMPLATE_FRAME_SHAPE_RECT:
- frame =
- lgl_template_frame_rect_new (orig_frame->all.id,
+ case LGL_TEMPLATE_FRAME_SHAPE_RECT:
+ frame =
+ lgl_template_frame_rect_new (orig_frame->all.id,
orig_frame->rect.w,
orig_frame->rect.h,
orig_frame->rect.r,
orig_frame->rect.x_waste,
orig_frame->rect.y_waste);
- break;
+ break;
- case LGL_TEMPLATE_FRAME_SHAPE_ELLIPSE:
- frame =
- lgl_template_frame_ellipse_new (orig_frame->all.id,
+ case LGL_TEMPLATE_FRAME_SHAPE_ELLIPSE:
+ frame =
+ lgl_template_frame_ellipse_new (orig_frame->all.id,
orig_frame->ellipse.w,
orig_frame->ellipse.h,
orig_frame->ellipse.waste);
- break;
+ break;
- case LGL_TEMPLATE_FRAME_SHAPE_ROUND:
- frame =
- lgl_template_frame_round_new (orig_frame->all.id,
+ case LGL_TEMPLATE_FRAME_SHAPE_ROUND:
+ frame =
+ lgl_template_frame_round_new (orig_frame->all.id,
orig_frame->round.r,
orig_frame->round.waste);
- break;
+ break;
- case LGL_TEMPLATE_FRAME_SHAPE_CD:
- frame =
- lgl_template_frame_cd_new (orig_frame->all.id,
+ case LGL_TEMPLATE_FRAME_SHAPE_CD:
+ frame =
+ lgl_template_frame_cd_new (orig_frame->all.id,
orig_frame->cd.r1,
orig_frame->cd.r2,
orig_frame->cd.w,
orig_frame->cd.h,
orig_frame->cd.waste);
- break;
-
- default:
- return NULL;
- break;
- }
-
- for ( p=orig_frame->all.layouts; p != NULL; p=p->next ) {
+ break;
- layout = (lglTemplateLayout *)p->data;
+ default:
+ return NULL;
+ break;
+ }
- lgl_template_frame_add_layout (frame, lgl_template_layout_dup (layout));
- }
+ for ( p=orig_frame->all.layouts; p != NULL; p=p->next )
+ {
+ layout = (lglTemplateLayout *)p->data;
- for ( p=orig_frame->all.markups; p != NULL; p=p->next ) {
+ lgl_template_frame_add_layout (frame, lgl_template_layout_dup (layout));
+ }
- markup = (lglTemplateMarkup *)p->data;
+ for ( p=orig_frame->all.markups; p != NULL; p=p->next )
+ {
+ markup = (lglTemplateMarkup *)p->data;
- lgl_template_frame_add_markup (frame, lgl_template_markup_dup (markup));
- }
+ lgl_template_frame_add_markup (frame, lgl_template_markup_dup (markup));
+ }
- return frame;
+ return frame;
}
void
lgl_template_frame_free (lglTemplateFrame *frame)
{
- GList *p;
- lglTemplateLayout *layout;
- lglTemplateMarkup *markup;
+ GList *p;
+ lglTemplateLayout *layout;
+ lglTemplateMarkup *markup;
- if ( frame != NULL ) {
-
- g_free (frame->all.id);
- frame->all.id = NULL;
-
- for ( p=frame->all.layouts; p != NULL; p=p->next ) {
+ if ( frame != NULL )
+ {
- layout = (lglTemplateLayout *)p->data;
+ g_free (frame->all.id);
+ frame->all.id = NULL;
- lgl_template_layout_free (layout);
- p->data = NULL;
- }
- g_list_free (frame->all.layouts);
- frame->all.layouts = NULL;
+ for ( p=frame->all.layouts; p != NULL; p=p->next )
+ {
+ layout = (lglTemplateLayout *)p->data;
- for ( p=frame->all.markups; p != NULL; p=p->next ) {
+ lgl_template_layout_free (layout);
+ p->data = NULL;
+ }
+ g_list_free (frame->all.layouts);
+ frame->all.layouts = NULL;
- markup = (lglTemplateMarkup *)p->data;
+ for ( p=frame->all.markups; p != NULL; p=p->next )
+ {
+ markup = (lglTemplateMarkup *)p->data;
- lgl_template_markup_free (markup);
- p->data = NULL;
- }
- g_list_free (frame->all.markups);
- frame->all.markups = NULL;
+ lgl_template_markup_free (markup);
+ p->data = NULL;
+ }
+ g_list_free (frame->all.markups);
+ frame->all.markups = NULL;
- g_free (frame);
+ g_free (frame);
- }
+ }
}
lglTemplateLayout *
lgl_template_layout_dup (const lglTemplateLayout *orig_layout)
{
- lglTemplateLayout *layout;
+ lglTemplateLayout *layout;
- g_return_val_if_fail (orig_layout, NULL);
+ g_return_val_if_fail (orig_layout, NULL);
- layout = g_new0 (lglTemplateLayout, 1);
+ layout = g_new0 (lglTemplateLayout, 1);
- /* copy contents */
- *layout = *orig_layout;
+ /* copy contents */
+ *layout = *orig_layout;
- return layout;
+ return layout;
}
void
lgl_template_layout_free (lglTemplateLayout *layout)
{
- g_free (layout);
+ g_free (layout);
}
lglTemplateMarkup *
lgl_template_markup_dup (const lglTemplateMarkup *orig_markup)
{
- lglTemplateMarkup *markup;
+ lglTemplateMarkup *markup;
- g_return_val_if_fail (orig_markup, NULL);
+ g_return_val_if_fail (orig_markup, NULL);
- markup = g_new0 (lglTemplateMarkup, 1);
+ markup = g_new0 (lglTemplateMarkup, 1);
- *markup = *orig_markup;
+ *markup = *orig_markup;
- return markup;
+ return markup;
}
void
lgl_template_markup_free (lglTemplateMarkup *markup)
{
- g_free (markup);
+ g_free (markup);
}
static gint
compare_origins (gconstpointer a,
- gconstpointer b,
- gpointer user_data)
+ gconstpointer b,
+ gpointer user_data)
{
- const lglTemplateOrigin *a_origin = a, *b_origin = b;
-
- if ( a_origin->y < b_origin->y ) {
- return -1;
- } else if ( a_origin->y > b_origin->y ) {
- return +1;
- } else {
- if ( a_origin->x < b_origin->x ) {
- return -1;
- } else if ( a_origin->x > b_origin->x ) {
- return +1;
- } else {
- return 0; /* hopefully 2 labels won't have the same origin */
- }
- }
+ const lglTemplateOrigin *a_origin = a, *b_origin = b;
+
+ if ( a_origin->y < b_origin->y )
+ {
+ return -1;
+ }
+ else if ( a_origin->y > b_origin->y )
+ {
+ return +1;
+ }
+ else
+ {
+ if ( a_origin->x < b_origin->x )
+ {
+ return -1;
+ }
+ else if ( a_origin->x > b_origin->x )
+ {
+ return +1;
+ }
+ else
+ {
+ return 0; /* hopefully 2 labels won't have the same origin */
+ }
+ }
}
*/
struct _lglTemplate {
- gchar *brand;
+ gchar *brand;
gchar *part;
gchar *equiv_part;
- gchar *description;
- gchar *paper_id;
- gdouble page_width;
- gdouble page_height;
+ gchar *description;
+ gchar *paper_id;
+ gdouble page_width;
+ gdouble page_height;
/* Meta information. */
gchar *product_url; /* URL to manufacturer's product website. */
- GList *category_ids; /* List of (gchar *) category ids. */
+ GList *category_ids; /* List of (gchar *) category ids. */
- /* List of (lglTemplateFrame *) label frame structures.
- * Currently glabels only supports a single label frame per
- * template. */
- GList *frames;
+ /* List of (lglTemplateFrame *) label frame structures.
+ * Currently glabels only supports a single label frame per
+ * template. */
+ GList *frames;
};
* Possible Frame Shapes
*/
typedef enum {
- LGL_TEMPLATE_FRAME_SHAPE_RECT,
- LGL_TEMPLATE_FRAME_SHAPE_ELLIPSE,
- LGL_TEMPLATE_FRAME_SHAPE_ROUND,
- LGL_TEMPLATE_FRAME_SHAPE_CD,
+ LGL_TEMPLATE_FRAME_SHAPE_RECT,
+ LGL_TEMPLATE_FRAME_SHAPE_ELLIPSE,
+ LGL_TEMPLATE_FRAME_SHAPE_ROUND,
+ LGL_TEMPLATE_FRAME_SHAPE_CD,
} lglTemplateFrameShape;
struct _lglTemplateFrameAll {
/* Begin Common Fields */
- lglTemplateFrameShape shape;
+ lglTemplateFrameShape shape;
- gchar *id; /* Id, currently always "0" */
- GList *layouts; /* List of lglTemplateLayouts */
- GList *markups; /* List of lglTemplateMarkups */
+ gchar *id; /* Id, currently always "0" */
+ GList *layouts; /* List of lglTemplateLayouts */
+ GList *markups; /* List of lglTemplateMarkups */
/* End Common Fields */
};
struct _lglTemplateFrameRect {
/* Begin Common Fields */
- lglTemplateFrameShape shape; /* Always LGL_TEMPLATE_FRAME_SHAPE_RECT. */
+ lglTemplateFrameShape shape; /* Always LGL_TEMPLATE_FRAME_SHAPE_RECT. */
- gchar *id; /* Id, currently always "0" */
- GList *layouts; /* List of lglTemplateLayouts */
- GList *markups; /* List of lglTemplateMarkups */
+ gchar *id; /* Id, currently always "0" */
+ GList *layouts; /* List of lglTemplateLayouts */
+ GList *markups; /* List of lglTemplateMarkups */
/* End Common Fields */
gdouble w; /* Width */
struct _lglTemplateFrameEllipse {
/* Begin Common Fields */
- lglTemplateFrameShape shape; /* Always LGL_TEMPLATE_FRAME_SHAPE_ELLIPSE. */
+ lglTemplateFrameShape shape; /* Always LGL_TEMPLATE_FRAME_SHAPE_ELLIPSE. */
- gchar *id; /* Id, currently always "0" */
- GList *layouts; /* List of lglTemplateLayouts */
- GList *markups; /* List of lglTemplateMarkups */
+ gchar *id; /* Id, currently always "0" */
+ GList *layouts; /* List of lglTemplateLayouts */
+ GList *markups; /* List of lglTemplateMarkups */
/* End Common Fields */
gdouble w; /* Width */
struct _lglTemplateFrameRound {
/* Begin Common Fields */
- lglTemplateFrameShape shape; /* Always LGL_TEMPLATE_FRAME_SHAPE_ROUND. */
+ lglTemplateFrameShape shape; /* Always LGL_TEMPLATE_FRAME_SHAPE_ROUND. */
- gchar *id; /* Id, currently always "0" */
- GList *layouts; /* List of lglTemplateLayouts */
- GList *markups; /* List of lglTemplateMarkups */
+ gchar *id; /* Id, currently always "0" */
+ GList *layouts; /* List of lglTemplateLayouts */
+ GList *markups; /* List of lglTemplateMarkups */
/* End Common Fields */
gdouble r; /* Radius */
struct _lglTemplateFrameCD {
/* Begin Common Fields */
- lglTemplateFrameShape shape; /* Always LGL_TEMPLATE_FRAME_SHAPE_CD. */
+ lglTemplateFrameShape shape; /* Always LGL_TEMPLATE_FRAME_SHAPE_CD. */
- gchar *id; /* Id, currently always "0" */
- GList *layouts; /* List of lglTemplateLayouts */
- GList *markups; /* List of lglTemplateMarkups */
+ gchar *id; /* Id, currently always "0" */
+ GList *layouts; /* List of lglTemplateLayouts */
+ GList *markups; /* List of lglTemplateMarkups */
/* End Common Fields */
gdouble r1; /* Outer radius */
union _lglTemplateFrame{
- lglTemplateFrameShape shape;
+ lglTemplateFrameShape shape;
- lglTemplateFrameAll all;
- lglTemplateFrameRect rect;
- lglTemplateFrameEllipse ellipse;
- lglTemplateFrameRound round;
- lglTemplateFrameCD cd;
+ lglTemplateFrameAll all;
+ lglTemplateFrameRect rect;
+ lglTemplateFrameEllipse ellipse;
+ lglTemplateFrameRound round;
+ lglTemplateFrameCD cd;
};
*/
struct _lglTemplateLayout {
- gint nx; /* Number of labels across */
- gint ny; /* Number of labels up and down */
+ gint nx; /* Number of labels across */
+ gint ny; /* Number of labels up and down */
- gdouble x0; /* Left of grid from left edge of paper */
- gdouble y0; /* Top of grid from top edge of paper */
+ gdouble x0; /* Left of grid from left edge of paper */
+ gdouble y0; /* Top of grid from top edge of paper */
- gdouble dx; /* Horizontal pitch of grid */
- gdouble dy; /* Vertical pitch of grid */
+ gdouble dx; /* Horizontal pitch of grid */
+ gdouble dy; /* Vertical pitch of grid */
};
* Possible Markup Types
*/
typedef enum {
- LGL_TEMPLATE_MARKUP_MARGIN,
- LGL_TEMPLATE_MARKUP_LINE,
- LGL_TEMPLATE_MARKUP_CIRCLE,
- LGL_TEMPLATE_MARKUP_RECT,
- LGL_TEMPLATE_MARKUP_ELLIPSE,
+ LGL_TEMPLATE_MARKUP_MARGIN,
+ LGL_TEMPLATE_MARKUP_LINE,
+ LGL_TEMPLATE_MARKUP_CIRCLE,
+ LGL_TEMPLATE_MARKUP_RECT,
+ LGL_TEMPLATE_MARKUP_ELLIPSE,
} lglTemplateMarkupType;
*/
struct _lglTemplateMarkupMargin {
- lglTemplateMarkupType type; /* Always LGL_TEMPLATE_MARKUP_MARGIN */
+ lglTemplateMarkupType type; /* Always LGL_TEMPLATE_MARKUP_MARGIN */
gdouble size; /* Margin size */
};
struct _lglTemplateMarkupLine {
- lglTemplateMarkupType type; /* Always LGL_TEMPLATE_MARKUP_LINE */
+ lglTemplateMarkupType type; /* Always LGL_TEMPLATE_MARKUP_LINE */
gdouble x1, y1; /* 1st endpoint */
gdouble x2, y2; /* 2nd endpoint */
struct _lglTemplateMarkupCircle {
- lglTemplateMarkupType type; /* Always LGL_TEMPLATE_MARKUP_CIRCLE */
+ lglTemplateMarkupType type; /* Always LGL_TEMPLATE_MARKUP_CIRCLE */
gdouble x0, y0; /* Center of circle */
gdouble r; /* Radius of circle */
struct _lglTemplateMarkupRect {
- lglTemplateMarkupType type; /* Always LGL_TEMPLATE_MARKUP_RECT */
+ lglTemplateMarkupType type; /* Always LGL_TEMPLATE_MARKUP_RECT */
gdouble x1, y1; /* Upper left corner */
gdouble w, h; /* Width and height. */
struct _lglTemplateMarkupEllipse {
- lglTemplateMarkupType type; /* Always LGL_TEMPLATE_MARKUP_ELLIPSE */
+ lglTemplateMarkupType type; /* Always LGL_TEMPLATE_MARKUP_ELLIPSE */
gdouble x1, y1; /* Upper left corner */
gdouble w, h; /* Width and height. */
union _lglTemplateMarkup {
- lglTemplateMarkupType type;
+ lglTemplateMarkupType type;
- lglTemplateMarkupMargin margin;
- lglTemplateMarkupLine line;
- lglTemplateMarkupCircle circle;
- lglTemplateMarkupRect rect;
- lglTemplateMarkupEllipse ellipse;
+ lglTemplateMarkupMargin margin;
+ lglTemplateMarkupLine line;
+ lglTemplateMarkupCircle circle;
+ lglTemplateMarkupRect rect;
+ lglTemplateMarkupEllipse ellipse;
};
*/
struct _lglTemplateOrigin {
- gdouble x, y; /* Label origin relative to upper
- * upper left hand corner of paper */
+ gdouble x, y; /* Label origin relative to upper
+ * upper left hand corner of paper */
};
/*========================================================*/
typedef struct {
- gchar *id;
- gchar *name;
- gdouble points_per_unit;
+ gchar *id;
+ gchar *name;
+ gdouble points_per_unit;
} UnitTableEntry;
static UnitTableEntry unit_table[] = {
- /* The ids are identical to the absolute length units supported in
- the CSS2 Specification (Section 4.3.2) */
+ /* The ids are identical to the absolute length units supported in
+ the CSS2 Specification (Section 4.3.2) */
- /* This table must be sorted exactly as the enumerations in lglUnits */
+ /* This table must be sorted exactly as the enumerations in lglUnits */
- /* [LGL_UNITS_POINT] */ {"pt", N_("points"), POINTS_PER_POINT},
- /* [LGL_UNITS_INCH] */ {"in", N_("inches"), POINTS_PER_INCH},
- /* [LGL_UNITS_MM] */ {"mm", N_("mm"), POINTS_PER_MM},
- /* [LGL_UNITS_CM] */ {"cm", N_("cm"), POINTS_PER_CM},
- /* [LGL_UNITS_PICA] */ {"pc", N_("picas"), POINTS_PER_PICA},
+ /* [LGL_UNITS_POINT] */ {"pt", N_("points"), POINTS_PER_POINT},
+ /* [LGL_UNITS_INCH] */ {"in", N_("inches"), POINTS_PER_INCH},
+ /* [LGL_UNITS_MM] */ {"mm", N_("mm"), POINTS_PER_MM},
+ /* [LGL_UNITS_CM] */ {"cm", N_("cm"), POINTS_PER_CM},
+ /* [LGL_UNITS_PICA] */ {"pc", N_("picas"), POINTS_PER_PICA},
};
lglUnits units;
/* An empty or missing id defaults to points. */
- if ( (id == NULL) || (strlen (id) == 0) )
+ if ( (id == NULL) || (*id == '\0') )
{
return LGL_UNITS_POINT;
}
- for ( units = LGL_UNITS_FIRST; units <= LGL_UNITS_LAST; units++) {
- if (g_ascii_strcasecmp (id, unit_table[units].id) == 0) {
+ for ( units = LGL_UNITS_FIRST; units <= LGL_UNITS_LAST; units++)
+ {
+ if (g_ascii_strcasecmp (id, unit_table[units].id) == 0)
+ {
return units;
}
}
/* Try name as a fallback. (Will catch some legacy preferences.) */
- for ( units = LGL_UNITS_FIRST; units <= LGL_UNITS_LAST; units++) {
- if (g_ascii_strcasecmp (id, unit_table[units].name) == 0) {
+ for ( units = LGL_UNITS_FIRST; units <= LGL_UNITS_LAST; units++)
+ {
+ if (g_ascii_strcasecmp (id, unit_table[units].name) == 0)
+ {
return units;
}
}
/* For compatibility with old preferences. */
- if (g_ascii_strcasecmp (id, "Millimeters") == 0) {
+ if (g_ascii_strcasecmp (id, "Millimeters") == 0)
+ {
return LGL_UNITS_MM;
}
{
lglUnits units;
- for ( units = LGL_UNITS_FIRST; units <= LGL_UNITS_LAST; units++) {
- if (g_ascii_strcasecmp (name, gettext ((char *)unit_table[units].name) ) == 0) {
+ for ( units = LGL_UNITS_FIRST; units <= LGL_UNITS_LAST; units++)
+ {
+ if (g_ascii_strcasecmp (name, gettext ((char *)unit_table[units].name) ) == 0)
+ {
return units;
}
}
* Units of distance
*/
typedef enum {
- LGL_UNITS_POINT, /* encoded as "pt" */
- LGL_UNITS_INCH, /* encoded as "in" */
- LGL_UNITS_MM, /* encoded as "mm" */
- LGL_UNITS_CM, /* encoded as "cm" */
- LGL_UNITS_PICA, /* encoded as "pc" */
-
- LGL_UNITS_FIRST = LGL_UNITS_POINT,
- LGL_UNITS_LAST = LGL_UNITS_PICA,
+ LGL_UNITS_POINT, /* encoded as "pt" */
+ LGL_UNITS_INCH, /* encoded as "in" */
+ LGL_UNITS_MM, /* encoded as "mm" */
+ LGL_UNITS_CM, /* encoded as "cm" */
+ LGL_UNITS_PICA, /* encoded as "pc" */
+
+ LGL_UNITS_FIRST = LGL_UNITS_POINT,
+ LGL_UNITS_LAST = LGL_UNITS_PICA,
LGL_UNITS_INVALID = -1,
} lglUnits;
lglVendor *
lgl_vendor_new (gchar *name)
{
- lglVendor *vendor;
+ lglVendor *vendor;
- vendor = g_new0 (lglVendor,1);
+ vendor = g_new0 (lglVendor,1);
- vendor->name = g_strdup (name);
+ vendor->name = g_strdup (name);
- return vendor;
+ return vendor;
}
*/
lglVendor *lgl_vendor_dup (const lglVendor *orig)
{
- lglVendor *vendor;
+ lglVendor *vendor;
- g_return_val_if_fail (orig, NULL);
+ g_return_val_if_fail (orig, NULL);
- vendor = g_new0 (lglVendor,1);
+ vendor = g_new0 (lglVendor,1);
- vendor->name = g_strdup (orig->name);
- vendor->url = g_strdup (orig->url);
+ vendor->name = g_strdup (orig->name);
+ vendor->url = g_strdup (orig->url);
- return vendor;
+ return vendor;
}
void lgl_vendor_free (lglVendor *vendor)
{
- if ( vendor != NULL ) {
+ if ( vendor != NULL )
+ {
+ g_free (vendor->name);
+ vendor->name = NULL;
- g_free (vendor->name);
- vendor->name = NULL;
+ g_free (vendor->url);
+ vendor->url = NULL;
- g_free (vendor->url);
- vendor->url = NULL;
-
- g_free (vendor);
- }
+ g_free (vendor);
+ }
}
typedef struct _lglVendor lglVendor;
struct _lglVendor {
- gchar *name; /* Vendor name */
- gchar *url; /* Vendor URL */
+ gchar *name; /* Vendor name */
+ gchar *url; /* Vendor URL */
};
GList *
lgl_xml_category_read_categories_from_file (gchar *utf8_filename)
{
- gchar *filename;
- GList *categories;
- xmlDocPtr categories_doc;
+ gchar *filename;
+ GList *categories;
+ xmlDocPtr categories_doc;
- LIBXML_TEST_VERSION;
+ LIBXML_TEST_VERSION;
- filename = g_filename_from_utf8 (utf8_filename, -1, NULL, NULL, NULL);
- if (!filename) {
- g_message ("Utf8 filename conversion error");
- return NULL;
- }
+ filename = g_filename_from_utf8 (utf8_filename, -1, NULL, NULL, NULL);
+ if (!filename)
+ {
+ g_message ("Utf8 filename conversion error");
+ return NULL;
+ }
- categories_doc = xmlParseFile (filename);
- if (!categories_doc) {
- g_message ("\"%s\" is not a glabels category file (not XML)",
- filename);
- return NULL;
- }
+ categories_doc = xmlParseFile (filename);
+ if (!categories_doc)
+ {
+ g_message ("\"%s\" is not a glabels category file (not XML)",
+ filename);
+ return NULL;
+ }
- categories = lgl_xml_category_parse_categories_doc (categories_doc);
+ categories = lgl_xml_category_parse_categories_doc (categories_doc);
- g_free (filename);
- xmlFreeDoc (categories_doc);
+ g_free (filename);
+ xmlFreeDoc (categories_doc);
- return categories;
+ return categories;
}
GList *
lgl_xml_category_parse_categories_doc (xmlDocPtr categories_doc)
{
- GList *categories = NULL;
- xmlNodePtr root, node;
- lglCategory *category;
-
- LIBXML_TEST_VERSION;
-
- root = xmlDocGetRootElement (categories_doc);
- if (!root || !root->name) {
- g_message ("\"%s\" is not a glabels category file (no root node)",
- categories_doc->name);
- xmlFreeDoc (categories_doc);
- return categories;
- }
- if (!lgl_xml_is_node (root, "Glabels-categories")) {
- g_message ("\"%s\" is not a glabels category file (wrong root node)",
- categories_doc->name);
- xmlFreeDoc (categories_doc);
- return categories;
- }
-
- for (node = root->xmlChildrenNode; node != NULL; node = node->next) {
-
- if (lgl_xml_is_node (node, "Category")) {
- category = lgl_xml_category_parse_category_node (node);
- categories = g_list_append (categories, category);
- } else {
- if ( !xmlNodeIsText(node) ) {
- if (!lgl_xml_is_node (node, "comment")) {
- g_message ("bad node = \"%s\"",node->name);
- }
- }
- }
- }
-
- return categories;
+ GList *categories = NULL;
+ xmlNodePtr root, node;
+ lglCategory *category;
+
+ LIBXML_TEST_VERSION;
+
+ root = xmlDocGetRootElement (categories_doc);
+ if (!root || !root->name)
+ {
+ g_message ("\"%s\" is not a glabels category file (no root node)",
+ categories_doc->name);
+ xmlFreeDoc (categories_doc);
+ return categories;
+ }
+ if (!lgl_xml_is_node (root, "Glabels-categories"))
+ {
+ g_message ("\"%s\" is not a glabels category file (wrong root node)",
+ categories_doc->name);
+ xmlFreeDoc (categories_doc);
+ return categories;
+ }
+
+ for (node = root->xmlChildrenNode; node != NULL; node = node->next)
+ {
+
+ if (lgl_xml_is_node (node, "Category"))
+ {
+ category = lgl_xml_category_parse_category_node (node);
+ categories = g_list_append (categories, category);
+ }
+ else
+ {
+ if ( !xmlNodeIsText(node) )
+ {
+ if (!lgl_xml_is_node (node, "comment"))
+ {
+ g_message ("bad node = \"%s\"",node->name);
+ }
+ }
+ }
+ }
+
+ return categories;
}
lglCategory *
lgl_xml_category_parse_category_node (xmlNodePtr category_node)
{
- lglCategory *category;
- gchar *id, *name;
+ lglCategory *category;
+ gchar *id, *name;
- LIBXML_TEST_VERSION;
+ LIBXML_TEST_VERSION;
- id = lgl_xml_get_prop_string (category_node, "id", NULL);
- name = lgl_xml_get_prop_i18n_string (category_node, "name", NULL);
+ id = lgl_xml_get_prop_string (category_node, "id", NULL);
+ name = lgl_xml_get_prop_i18n_string (category_node, "name", NULL);
- category = lgl_category_new (id, name);
+ category = lgl_category_new (id, name);
- g_free (id);
- g_free (name);
+ g_free (id);
+ g_free (name);
- return category;
+ return category;
}
GList *
lgl_xml_paper_read_papers_from_file (gchar *utf8_filename)
{
- gchar *filename;
- GList *papers;
- xmlDocPtr papers_doc;
+ gchar *filename;
+ GList *papers;
+ xmlDocPtr papers_doc;
- LIBXML_TEST_VERSION;
+ LIBXML_TEST_VERSION;
- filename = g_filename_from_utf8 (utf8_filename, -1, NULL, NULL, NULL);
- if (!filename) {
- g_message ("Utf8 filename conversion error");
- return NULL;
- }
+ filename = g_filename_from_utf8 (utf8_filename, -1, NULL, NULL, NULL);
+ if (!filename)
+ {
+ g_message ("Utf8 filename conversion error");
+ return NULL;
+ }
- papers_doc = xmlParseFile (filename);
- if (!papers_doc) {
- g_message ("\"%s\" is not a glabels paper file (not XML)",
- filename);
- return NULL;
- }
+ papers_doc = xmlParseFile (filename);
+ if (!papers_doc)
+ {
+ g_message ("\"%s\" is not a glabels paper file (not XML)",
+ filename);
+ return NULL;
+ }
- papers = lgl_xml_paper_parse_papers_doc (papers_doc);
+ papers = lgl_xml_paper_parse_papers_doc (papers_doc);
- g_free (filename);
- xmlFreeDoc (papers_doc);
+ g_free (filename);
+ xmlFreeDoc (papers_doc);
- return papers;
+ return papers;
}
GList *
lgl_xml_paper_parse_papers_doc (xmlDocPtr papers_doc)
{
- GList *papers = NULL;
- xmlNodePtr root, node;
- lglPaper *paper;
-
- LIBXML_TEST_VERSION;
-
- root = xmlDocGetRootElement (papers_doc);
- if (!root || !root->name) {
- g_message ("\"%s\" is not a glabels paper file (no root node)",
- papers_doc->name);
- xmlFreeDoc (papers_doc);
- return papers;
- }
- if (!lgl_xml_is_node (root, "Glabels-paper-sizes")) {
- g_message ("\"%s\" is not a glabels paper file (wrong root node)",
- papers_doc->name);
- xmlFreeDoc (papers_doc);
- return papers;
- }
-
- for (node = root->xmlChildrenNode; node != NULL; node = node->next) {
-
- if (lgl_xml_is_node (node, "Paper-size")) {
- paper = lgl_xml_paper_parse_paper_node (node);
- papers = g_list_append (papers, paper);
- } else {
- if ( !xmlNodeIsText(node) ) {
- if (!lgl_xml_is_node (node, "comment")) {
- g_message ("bad node = \"%s\"",node->name);
- }
- }
- }
- }
-
- return papers;
+ GList *papers = NULL;
+ xmlNodePtr root, node;
+ lglPaper *paper;
+
+ LIBXML_TEST_VERSION;
+
+ root = xmlDocGetRootElement (papers_doc);
+ if (!root || !root->name)
+ {
+ g_message ("\"%s\" is not a glabels paper file (no root node)",
+ papers_doc->name);
+ xmlFreeDoc (papers_doc);
+ return papers;
+ }
+ if (!lgl_xml_is_node (root, "Glabels-paper-sizes"))
+ {
+ g_message ("\"%s\" is not a glabels paper file (wrong root node)",
+ papers_doc->name);
+ xmlFreeDoc (papers_doc);
+ return papers;
+ }
+
+ for (node = root->xmlChildrenNode; node != NULL; node = node->next)
+ {
+
+ if (lgl_xml_is_node (node, "Paper-size"))
+ {
+ paper = lgl_xml_paper_parse_paper_node (node);
+ papers = g_list_append (papers, paper);
+ }
+ else
+ {
+ if ( !xmlNodeIsText(node) )
+ {
+ if (!lgl_xml_is_node (node, "comment"))
+ {
+ g_message ("bad node = \"%s\"",node->name);
+ }
+ }
+ }
+ }
+
+ return papers;
}
lglPaper *
lgl_xml_paper_parse_paper_node (xmlNodePtr paper_node)
{
- lglPaper *paper;
- gchar *id, *name, *pwg_size;
- gdouble width, height;
+ lglPaper *paper;
+ gchar *id, *name, *pwg_size;
+ gdouble width, height;
- LIBXML_TEST_VERSION;
+ LIBXML_TEST_VERSION;
- id = lgl_xml_get_prop_string (paper_node, "id", NULL);
+ id = lgl_xml_get_prop_string (paper_node, "id", NULL);
- name = lgl_xml_get_prop_i18n_string (paper_node, "name", NULL);
+ name = lgl_xml_get_prop_i18n_string (paper_node, "name", NULL);
- width = lgl_xml_get_prop_length (paper_node, "width", 0);
- height = lgl_xml_get_prop_length (paper_node, "height", 0);
+ width = lgl_xml_get_prop_length (paper_node, "width", 0);
+ height = lgl_xml_get_prop_length (paper_node, "height", 0);
- pwg_size = lgl_xml_get_prop_string (paper_node, "pwg_size", NULL);
+ pwg_size = lgl_xml_get_prop_string (paper_node, "pwg_size", NULL);
- paper = lgl_paper_new (id, name, width, height, pwg_size);
+ paper = lgl_paper_new (id, name, width, height, pwg_size);
- g_free (id);
- g_free (name);
- g_free (pwg_size);
+ g_free (id);
+ g_free (name);
+ g_free (pwg_size);
- return paper;
+ return paper;
}
/* Local function prototypes */
/*===========================================*/
static void xml_parse_meta_node (xmlNodePtr label_node,
- lglTemplate *template);
+ lglTemplate *template);
static void xml_parse_label_rectangle_node (xmlNodePtr label_node,
- lglTemplate *template);
+ lglTemplate *template);
static void xml_parse_label_ellipse_node (xmlNodePtr label_node,
- lglTemplate *template);
+ lglTemplate *template);
static void xml_parse_label_round_node (xmlNodePtr label_node,
- lglTemplate *template);
+ lglTemplate *template);
static void xml_parse_label_cd_node (xmlNodePtr label_node,
- lglTemplate *template);
+ lglTemplate *template);
static void xml_parse_layout_node (xmlNodePtr layout_node,
- lglTemplateFrame *frame);
+ lglTemplateFrame *frame);
static void xml_parse_markup_margin_node (xmlNodePtr markup_node,
- lglTemplateFrame *frame);
+ lglTemplateFrame *frame);
static void xml_parse_markup_line_node (xmlNodePtr markup_node,
- lglTemplateFrame *frame);
+ lglTemplateFrame *frame);
static void xml_parse_markup_circle_node (xmlNodePtr markup_node,
- lglTemplateFrame *frame);
+ lglTemplateFrame *frame);
static void xml_parse_markup_rect_node (xmlNodePtr markup_node,
- lglTemplateFrame *frame);
+ lglTemplateFrame *frame);
static void xml_parse_markup_ellipse_node (xmlNodePtr markup_node,
- lglTemplateFrame *frame);
+ lglTemplateFrame *frame);
static void xml_parse_alias_node (xmlNodePtr alias_node,
- lglTemplate *template);
+ lglTemplate *template);
static void xml_create_meta_node (const gchar *attr,
const gchar *value,
- xmlNodePtr root,
- const xmlNsPtr ns);
+ xmlNodePtr root,
+ const xmlNsPtr ns);
static void xml_create_label_node (const lglTemplateFrame *frame,
- xmlNodePtr root,
- const xmlNsPtr ns);
+ xmlNodePtr root,
+ const xmlNsPtr ns);
static void xml_create_layout_node (const lglTemplateLayout *layout,
- xmlNodePtr root,
- const xmlNsPtr ns);
+ xmlNodePtr root,
+ const xmlNsPtr ns);
static void xml_create_markup_margin_node (const lglTemplateMarkup *margin,
- xmlNodePtr root,
- const xmlNsPtr ns);
+ xmlNodePtr root,
+ const xmlNsPtr ns);
static void xml_create_markup_line_node (const lglTemplateMarkup *line,
- xmlNodePtr root,
- const xmlNsPtr ns);
+ xmlNodePtr root,
+ const xmlNsPtr ns);
static void xml_create_markup_circle_node (const lglTemplateMarkup *circle,
- xmlNodePtr root,
- const xmlNsPtr ns);
+ xmlNodePtr root,
+ const xmlNsPtr ns);
static void xml_create_markup_rect_node (const lglTemplateMarkup *circle,
- xmlNodePtr root,
- const xmlNsPtr ns);
+ xmlNodePtr root,
+ const xmlNsPtr ns);
static void xml_create_markup_ellipse_node (const lglTemplateMarkup *circle,
- xmlNodePtr root,
- const xmlNsPtr ns);
+ xmlNodePtr root,
+ const xmlNsPtr ns);
/**
void
lgl_xml_template_read_templates_from_file (const gchar *utf8_filename)
{
- gchar *filename;
- xmlDocPtr templates_doc;
+ gchar *filename;
+ xmlDocPtr templates_doc;
- LIBXML_TEST_VERSION;
+ LIBXML_TEST_VERSION;
- filename = g_filename_from_utf8 (utf8_filename, -1, NULL, NULL, NULL);
- if (!filename) {
- g_message ("Utf8 filename conversion error");
- return;
- }
+ filename = g_filename_from_utf8 (utf8_filename, -1, NULL, NULL, NULL);
+ if (!filename)
+ {
+ g_message ("Utf8 filename conversion error");
+ return;
+ }
- templates_doc = xmlParseFile (filename);
- if (!templates_doc) {
- g_message ("\"%s\" is not a glabels template file (not XML)",
- filename);
- return;
- }
+ templates_doc = xmlParseFile (filename);
+ if (!templates_doc)
+ {
+ g_message ("\"%s\" is not a glabels template file (not XML)",
+ filename);
+ return;
+ }
- lgl_xml_template_parse_templates_doc (templates_doc);
+ lgl_xml_template_parse_templates_doc (templates_doc);
- g_free (filename);
- xmlFreeDoc (templates_doc);
+ g_free (filename);
+ xmlFreeDoc (templates_doc);
}
void
lgl_xml_template_parse_templates_doc (const xmlDocPtr templates_doc)
{
-
- xmlNodePtr root, node;
- lglTemplate *template;
+
+ xmlNodePtr root, node;
+ lglTemplate *template;
- LIBXML_TEST_VERSION;
+ LIBXML_TEST_VERSION;
- root = xmlDocGetRootElement (templates_doc);
- if (!root || !root->name)
+ root = xmlDocGetRootElement (templates_doc);
+ if (!root || !root->name)
{
- g_message ("\"%s\" is not a glabels template file (no root node)",
- templates_doc->URL);
- return;
- }
- if (!lgl_xml_is_node (root, "Glabels-templates"))
+ g_message ("\"%s\" is not a glabels template file (no root node)",
+ templates_doc->URL);
+ return;
+ }
+ if (!lgl_xml_is_node (root, "Glabels-templates"))
{
- g_message ("\"%s\" is not a glabels template file (wrong root node)",
- templates_doc->URL);
- return;
- }
+ g_message ("\"%s\" is not a glabels template file (wrong root node)",
+ templates_doc->URL);
+ return;
+ }
- for (node = root->xmlChildrenNode; node != NULL; node = node->next)
+ for (node = root->xmlChildrenNode; node != NULL; node = node->next)
{
- if (lgl_xml_is_node (node, "Template"))
+ if (lgl_xml_is_node (node, "Template"))
{
- template = lgl_xml_template_parse_template_node (node);
+ template = lgl_xml_template_parse_template_node (node);
if (template)
{
_lgl_db_register_template_internal (template);
lgl_template_free (template);
}
- }
+ }
else
{
- if ( !xmlNodeIsText(node) )
+ if ( !xmlNodeIsText(node) )
{
- if (!lgl_xml_is_node (node,"comment"))
+ if (!lgl_xml_is_node (node,"comment"))
{
- g_message ("bad node = \"%s\"",node->name);
- }
- }
- }
- }
+ g_message ("bad node = \"%s\"",node->name);
+ }
+ }
+ }
+ }
}
lglTemplate *
lgl_xml_template_parse_template_node (const xmlNodePtr template_node)
{
- gchar *brand;
+ gchar *brand;
gchar *part;
- gchar *name;
+ gchar *name;
gchar *equiv_part;
- gchar *description;
- gchar *paper_id;
- gdouble page_width, page_height;
- lglPaper *paper = NULL;
- lglTemplate *template;
- xmlNodePtr node;
+ gchar *description;
+ gchar *paper_id;
+ gdouble page_width, page_height;
+ lglPaper *paper = NULL;
+ lglTemplate *template;
+ xmlNodePtr node;
gchar **v;
lglTemplateFrame *frame;
- brand = lgl_xml_get_prop_string (template_node, "brand", NULL);
- part = lgl_xml_get_prop_string (template_node, "part", NULL);
+ brand = lgl_xml_get_prop_string (template_node, "brand", NULL);
+ part = lgl_xml_get_prop_string (template_node, "part", NULL);
if (!brand || !part)
{
name = lgl_xml_get_prop_string (template_node, "name", NULL);
}
else
{
- g_message ("Missing name or brand/part attributes.");
+ g_message ("Missing name or brand/part attributes.");
}
}
equiv_part = lgl_xml_get_prop_string (template_node, "equiv", NULL);
- description = lgl_xml_get_prop_i18n_string (template_node, "description", NULL);
- paper_id = lgl_xml_get_prop_string (template_node, "size", NULL);
-
- if (lgl_db_is_paper_id_other (paper_id)) {
-
- page_width = lgl_xml_get_prop_length (template_node, "width", 0);
- page_height = lgl_xml_get_prop_length (template_node, "height", 0);
-
- } else {
- paper = lgl_db_lookup_paper_from_id (paper_id);
- if (paper == NULL) {
- /* This should always be an id, but just in case a name
- slips by! */
- g_message ("Unknown page size id \"%s\", trying as name",
- paper_id);
- paper = lgl_db_lookup_paper_from_name (paper_id);
- g_free (paper_id);
- paper_id = g_strdup (paper->id);
- }
- if (paper != NULL) {
- page_width = paper->width;
- page_height = paper->height;
- } else {
- page_width = 612;
- page_height = 792;
- g_message ("Unknown page size id or name \"%s\"",
- paper_id);
- }
- lgl_paper_free (paper);
- paper = NULL;
- }
+ description = lgl_xml_get_prop_i18n_string (template_node, "description", NULL);
+ paper_id = lgl_xml_get_prop_string (template_node, "size", NULL);
+
+ if (lgl_db_is_paper_id_other (paper_id))
+ {
+
+ page_width = lgl_xml_get_prop_length (template_node, "width", 0);
+ page_height = lgl_xml_get_prop_length (template_node, "height", 0);
+
+ }
+ else
+ {
+ paper = lgl_db_lookup_paper_from_id (paper_id);
+ if (paper == NULL)
+ {
+ /* This should always be an id, but just in case a name
+ slips by! */
+ g_message ("Unknown page size id \"%s\", trying as name",
+ paper_id);
+ paper = lgl_db_lookup_paper_from_name (paper_id);
+ g_free (paper_id);
+ paper_id = g_strdup (paper->id);
+ }
+ if (paper != NULL)
+ {
+ page_width = paper->width;
+ page_height = paper->height;
+ }
+ else
+ {
+ page_width = 612;
+ page_height = 792;
+ g_message ("Unknown page size id or name \"%s\"",
+ paper_id);
+ }
+ lgl_paper_free (paper);
+ paper = NULL;
+ }
if (!equiv_part)
if (!template)
{
- g_message ("Forward references not supported.");
+ g_message ("Forward references not supported.");
return NULL;
}
}
- for (node = template_node->xmlChildrenNode; node != NULL;
- node = node->next) {
- if (lgl_xml_is_node (node, "Meta")) {
- xml_parse_meta_node (node, template);
- } else if (lgl_xml_is_node (node, "Label-rectangle")) {
- xml_parse_label_rectangle_node (node, template);
- } else if (lgl_xml_is_node (node, "Label-ellipse")) {
- xml_parse_label_ellipse_node (node, template);
- } else if (lgl_xml_is_node (node, "Label-round")) {
- xml_parse_label_round_node (node, template);
- } else if (lgl_xml_is_node (node, "Label-cd")) {
- xml_parse_label_cd_node (node, template);
- } else if (lgl_xml_is_node (node, "Alias")) {
- xml_parse_alias_node (node, template);
- } else {
- if (!xmlNodeIsText (node)) {
- if (!lgl_xml_is_node (node,"comment")) {
- g_message ("bad node = \"%s\"",node->name);
- }
- }
- }
- }
-
- g_free (brand);
- g_free (part);
- g_free (equiv_part);
- g_free (description);
- g_free (paper_id);
+ for (node = template_node->xmlChildrenNode; node != NULL; node = node->next)
+ {
+ if (lgl_xml_is_node (node, "Meta"))
+ {
+ xml_parse_meta_node (node, template);
+ }
+ else if (lgl_xml_is_node (node, "Label-rectangle"))
+ {
+ xml_parse_label_rectangle_node (node, template);
+ }
+ else if (lgl_xml_is_node (node, "Label-ellipse"))
+ {
+ xml_parse_label_ellipse_node (node, template);
+ }
+ else if (lgl_xml_is_node (node, "Label-round"))
+ {
+ xml_parse_label_round_node (node, template);
+ }
+ else if (lgl_xml_is_node (node, "Label-cd"))
+ {
+ xml_parse_label_cd_node (node, template);
+ }
+ else if (lgl_xml_is_node (node, "Alias"))
+ {
+ xml_parse_alias_node (node, template);
+ }
+ else
+ {
+ if (!xmlNodeIsText (node))
+ {
+ if (!lgl_xml_is_node (node,"comment"))
+ {
+ g_message ("bad node = \"%s\"",node->name);
+ }
+ }
+ }
+ }
+
+ g_free (brand);
+ g_free (part);
+ g_free (equiv_part);
+ g_free (description);
+ g_free (paper_id);
/*
* Create a default full-page frame, if a known frame type was not found.
lgl_template_frame_add_layout (frame, lgl_template_layout_new (1, 1, 0, 0, 0, 0));
}
- return template;
+ return template;
}
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
static void
xml_parse_meta_node (xmlNodePtr meta_node,
- lglTemplate *template)
+ lglTemplate *template)
{
gchar *product_url;
- gchar *category;
+ gchar *category;
product_url = lgl_xml_get_prop_string (meta_node, "product_url", NULL);
if ( product_url != NULL )
template->product_url = product_url;
}
- category = lgl_xml_get_prop_string (meta_node, "category", NULL);
- if ( category != NULL )
- {
- lgl_template_add_category (template, category);
- g_free (category);
- }
+ category = lgl_xml_get_prop_string (meta_node, "category", NULL);
+ if ( category != NULL )
+ {
+ lgl_template_add_category (template, category);
+ g_free (category);
+ }
}
/*--------------------------------------------------------------------------*/
static void
xml_parse_label_rectangle_node (xmlNodePtr label_node,
- lglTemplate *template)
+ lglTemplate *template)
{
- gchar *id;
- gchar *tmp;
- gdouble x_waste, y_waste;
- gdouble w, h, r;
- lglTemplateFrame *frame;
- xmlNodePtr node;
-
- id = lgl_xml_get_prop_string (label_node, "id", NULL);
-
- if ((tmp = lgl_xml_get_prop_string (label_node, "waste", NULL))) {
- /* Handle single "waste" property. */
- x_waste = y_waste = lgl_xml_get_prop_length (label_node, "waste", 0);
- g_free (tmp);
- } else {
- x_waste = lgl_xml_get_prop_length (label_node, "x_waste", 0);
- y_waste = lgl_xml_get_prop_length (label_node, "y_waste", 0);
- }
-
- w = lgl_xml_get_prop_length (label_node, "width", 0);
- h = lgl_xml_get_prop_length (label_node, "height", 0);
- r = lgl_xml_get_prop_length (label_node, "round", 0);
-
- frame = lgl_template_frame_rect_new ((gchar *)id, w, h, r, x_waste, y_waste);
- lgl_template_add_frame (template, frame);
-
- for (node = label_node->xmlChildrenNode; node != NULL;
- node = node->next) {
- if (lgl_xml_is_node (node, "Layout")) {
- xml_parse_layout_node (node, frame);
- } else if (lgl_xml_is_node (node, "Markup-margin")) {
- xml_parse_markup_margin_node (node, frame);
- } else if (lgl_xml_is_node (node, "Markup-line")) {
- xml_parse_markup_line_node (node, frame);
- } else if (lgl_xml_is_node (node, "Markup-circle")) {
- xml_parse_markup_circle_node (node, frame);
- } else if (lgl_xml_is_node (node, "Markup-rect")) {
- xml_parse_markup_rect_node (node, frame);
- } else if (lgl_xml_is_node (node, "Markup-ellipse")) {
- xml_parse_markup_ellipse_node (node, frame);
- } else if (!xmlNodeIsText (node)) {
- if (!lgl_xml_is_node (node, "comment")) {
- g_message ("bad node = \"%s\"",node->name);
- }
- }
- }
-
- g_free (id);
+ gchar *id;
+ gchar *tmp;
+ gdouble x_waste, y_waste;
+ gdouble w, h, r;
+ lglTemplateFrame *frame;
+ xmlNodePtr node;
+
+ id = lgl_xml_get_prop_string (label_node, "id", NULL);
+
+ if ((tmp = lgl_xml_get_prop_string (label_node, "waste", NULL)))
+ {
+ /* Handle single "waste" property. */
+ x_waste = y_waste = lgl_xml_get_prop_length (label_node, "waste", 0);
+ g_free (tmp);
+ }
+ else
+ {
+ x_waste = lgl_xml_get_prop_length (label_node, "x_waste", 0);
+ y_waste = lgl_xml_get_prop_length (label_node, "y_waste", 0);
+ }
+
+ w = lgl_xml_get_prop_length (label_node, "width", 0);
+ h = lgl_xml_get_prop_length (label_node, "height", 0);
+ r = lgl_xml_get_prop_length (label_node, "round", 0);
+
+ frame = lgl_template_frame_rect_new ((gchar *)id, w, h, r, x_waste, y_waste);
+ lgl_template_add_frame (template, frame);
+
+ for (node = label_node->xmlChildrenNode; node != NULL; node = node->next)
+ {
+ if (lgl_xml_is_node (node, "Layout"))
+ {
+ xml_parse_layout_node (node, frame);
+ }
+ else if (lgl_xml_is_node (node, "Markup-margin"))
+ {
+ xml_parse_markup_margin_node (node, frame);
+ }
+ else if (lgl_xml_is_node (node, "Markup-line"))
+ {
+ xml_parse_markup_line_node (node, frame);
+ }
+ else if (lgl_xml_is_node (node, "Markup-circle"))
+ {
+ xml_parse_markup_circle_node (node, frame);
+ }
+ else if (lgl_xml_is_node (node, "Markup-rect"))
+ {
+ xml_parse_markup_rect_node (node, frame);
+ }
+ else if (lgl_xml_is_node (node, "Markup-ellipse"))
+ {
+ xml_parse_markup_ellipse_node (node, frame);
+ }
+ else if (!xmlNodeIsText (node))
+ {
+ if (!lgl_xml_is_node (node, "comment"))
+ {
+ g_message ("bad node = \"%s\"",node->name);
+ }
+ }
+ }
+
+ g_free (id);
}
xml_parse_label_ellipse_node (xmlNodePtr label_node,
lglTemplate *template)
{
- gchar *id;
- gdouble waste;
- gdouble w, h;
- lglTemplateFrame *frame;
- xmlNodePtr node;
+ gchar *id;
+ gdouble waste;
+ gdouble w, h;
+ lglTemplateFrame *frame;
+ xmlNodePtr node;
- id = lgl_xml_get_prop_string (label_node, "id", NULL);
+ id = lgl_xml_get_prop_string (label_node, "id", NULL);
- w = lgl_xml_get_prop_length (label_node, "width", 0);
- h = lgl_xml_get_prop_length (label_node, "height", 0);
+ w = lgl_xml_get_prop_length (label_node, "width", 0);
+ h = lgl_xml_get_prop_length (label_node, "height", 0);
waste = lgl_xml_get_prop_length (label_node, "waste", 0);
- frame = lgl_template_frame_ellipse_new ((gchar *)id, w, h, waste);
- lgl_template_add_frame (template, frame);
-
- for (node = label_node->xmlChildrenNode; node != NULL;
- node = node->next) {
- if (lgl_xml_is_node (node, "Layout")) {
- xml_parse_layout_node (node, frame);
- } else if (lgl_xml_is_node (node, "Markup-margin")) {
- xml_parse_markup_margin_node (node, frame);
- } else if (lgl_xml_is_node (node, "Markup-line")) {
- xml_parse_markup_line_node (node, frame);
- } else if (lgl_xml_is_node (node, "Markup-circle")) {
- xml_parse_markup_circle_node (node, frame);
- } else if (lgl_xml_is_node (node, "Markup-rect")) {
- xml_parse_markup_rect_node (node, frame);
- } else if (lgl_xml_is_node (node, "Markup-ellipse")) {
- xml_parse_markup_ellipse_node (node, frame);
- } else if (!xmlNodeIsText (node)) {
- if (!lgl_xml_is_node (node, "comment")) {
- g_message ("bad node = \"%s\"",node->name);
- }
- }
- }
-
- g_free (id);
+ frame = lgl_template_frame_ellipse_new ((gchar *)id, w, h, waste);
+ lgl_template_add_frame (template, frame);
+
+ for (node = label_node->xmlChildrenNode; node != NULL; node = node->next)
+ {
+ if (lgl_xml_is_node (node, "Layout"))
+ {
+ xml_parse_layout_node (node, frame);
+ }
+ else if (lgl_xml_is_node (node, "Markup-margin"))
+ {
+ xml_parse_markup_margin_node (node, frame);
+ }
+ else if (lgl_xml_is_node (node, "Markup-line"))
+ {
+ xml_parse_markup_line_node (node, frame);
+ }
+ else if (lgl_xml_is_node (node, "Markup-circle"))
+ {
+ xml_parse_markup_circle_node (node, frame);
+ }
+ else if (lgl_xml_is_node (node, "Markup-rect"))
+ {
+ xml_parse_markup_rect_node (node, frame);
+ }
+ else if (lgl_xml_is_node (node, "Markup-ellipse"))
+ {
+ xml_parse_markup_ellipse_node (node, frame);
+ }
+ else if (!xmlNodeIsText (node))
+ {
+ if (!lgl_xml_is_node (node, "comment"))
+ {
+ g_message ("bad node = \"%s\"",node->name);
+ }
+ }
+ }
+
+ g_free (id);
}
/*--------------------------------------------------------------------------*/
static void
xml_parse_label_round_node (xmlNodePtr label_node,
- lglTemplate *template)
+ lglTemplate *template)
{
- gchar *id;
- gdouble waste;
- gdouble r;
- lglTemplateFrame *frame;
- xmlNodePtr node;
-
- id = lgl_xml_get_prop_string (label_node, "id", NULL);
- waste = lgl_xml_get_prop_length (label_node, "waste", 0);
- r = lgl_xml_get_prop_length (label_node, "radius", 0);
-
- frame = lgl_template_frame_round_new ((gchar *)id, r, waste);
- lgl_template_add_frame (template, frame);
-
- for (node = label_node->xmlChildrenNode; node != NULL;
- node = node->next) {
- if (lgl_xml_is_node (node, "Layout")) {
- xml_parse_layout_node (node, frame);
- } else if (lgl_xml_is_node (node, "Markup-margin")) {
- xml_parse_markup_margin_node (node, frame);
- } else if (lgl_xml_is_node (node, "Markup-line")) {
- xml_parse_markup_line_node (node, frame);
- } else if (lgl_xml_is_node (node, "Markup-circle")) {
- xml_parse_markup_circle_node (node, frame);
- } else if (lgl_xml_is_node (node, "Markup-rect")) {
- xml_parse_markup_rect_node (node, frame);
- } else if (lgl_xml_is_node (node, "Markup-ellipse")) {
- xml_parse_markup_ellipse_node (node, frame);
- } else if (!xmlNodeIsText (node)) {
- if (!lgl_xml_is_node (node, "comment")) {
- g_message ("bad node = \"%s\"",node->name);
- }
- }
- }
-
- g_free (id);
+ gchar *id;
+ gdouble waste;
+ gdouble r;
+ lglTemplateFrame *frame;
+ xmlNodePtr node;
+
+ id = lgl_xml_get_prop_string (label_node, "id", NULL);
+ waste = lgl_xml_get_prop_length (label_node, "waste", 0);
+ r = lgl_xml_get_prop_length (label_node, "radius", 0);
+
+ frame = lgl_template_frame_round_new ((gchar *)id, r, waste);
+ lgl_template_add_frame (template, frame);
+
+ for (node = label_node->xmlChildrenNode; node != NULL; node = node->next)
+ {
+ if (lgl_xml_is_node (node, "Layout"))
+ {
+ xml_parse_layout_node (node, frame);
+ }
+ else if (lgl_xml_is_node (node, "Markup-margin"))
+ {
+ xml_parse_markup_margin_node (node, frame);
+ }
+ else if (lgl_xml_is_node (node, "Markup-line"))
+ {
+ xml_parse_markup_line_node (node, frame);
+ }
+ else if (lgl_xml_is_node (node, "Markup-circle"))
+ {
+ xml_parse_markup_circle_node (node, frame);
+ }
+ else if (lgl_xml_is_node (node, "Markup-rect"))
+ {
+ xml_parse_markup_rect_node (node, frame);
+ }
+ else if (lgl_xml_is_node (node, "Markup-ellipse"))
+ {
+ xml_parse_markup_ellipse_node (node, frame);
+ }
+ else if (!xmlNodeIsText (node))
+ {
+ if (!lgl_xml_is_node (node, "comment"))
+ {
+ g_message ("bad node = \"%s\"",node->name);
+ }
+ }
+ }
+
+ g_free (id);
}
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
static void
xml_parse_label_cd_node (xmlNodePtr label_node,
- lglTemplate *template)
+ lglTemplate *template)
{
- gchar *id;
- gdouble waste;
- gdouble r1, r2, w, h;
- lglTemplateFrame *frame;
- xmlNodePtr node;
-
- id = lgl_xml_get_prop_string (label_node, "id", NULL);
- waste = lgl_xml_get_prop_length (label_node, "waste", 0);
- r1 = lgl_xml_get_prop_length (label_node, "radius", 0);
- r2 = lgl_xml_get_prop_length (label_node, "hole", 0);
- w = lgl_xml_get_prop_length (label_node, "width", 0);
- h = lgl_xml_get_prop_length (label_node, "height", 0);
-
- frame = lgl_template_frame_cd_new ((gchar *)id, r1, r2, w, h, waste);
- lgl_template_add_frame (template, frame);
-
- for (node = label_node->xmlChildrenNode; node != NULL;
- node = node->next) {
- if (lgl_xml_is_node (node, "Layout")) {
- xml_parse_layout_node (node, frame);
- } else if (lgl_xml_is_node (node, "Markup-margin")) {
- xml_parse_markup_margin_node (node, frame);
- } else if (lgl_xml_is_node (node, "Markup-line")) {
- xml_parse_markup_line_node (node, frame);
- } else if (lgl_xml_is_node (node, "Markup-circle")) {
- xml_parse_markup_circle_node (node, frame);
- } else if (lgl_xml_is_node (node, "Markup-rect")) {
- xml_parse_markup_rect_node (node, frame);
- } else if (lgl_xml_is_node (node, "Markup-ellipse")) {
- xml_parse_markup_ellipse_node (node, frame);
- } else if (!xmlNodeIsText (node)) {
- if (!lgl_xml_is_node (node, "comment")) {
- g_message ("bad node = \"%s\"",node->name);
- }
- }
- }
-
- g_free (id);
+ gchar *id;
+ gdouble waste;
+ gdouble r1, r2, w, h;
+ lglTemplateFrame *frame;
+ xmlNodePtr node;
+
+ id = lgl_xml_get_prop_string (label_node, "id", NULL);
+ waste = lgl_xml_get_prop_length (label_node, "waste", 0);
+ r1 = lgl_xml_get_prop_length (label_node, "radius", 0);
+ r2 = lgl_xml_get_prop_length (label_node, "hole", 0);
+ w = lgl_xml_get_prop_length (label_node, "width", 0);
+ h = lgl_xml_get_prop_length (label_node, "height", 0);
+
+ frame = lgl_template_frame_cd_new ((gchar *)id, r1, r2, w, h, waste);
+ lgl_template_add_frame (template, frame);
+
+ for (node = label_node->xmlChildrenNode; node != NULL; node = node->next)
+ {
+ if (lgl_xml_is_node (node, "Layout"))
+ {
+ xml_parse_layout_node (node, frame);
+ }
+ else if (lgl_xml_is_node (node, "Markup-margin"))
+ {
+ xml_parse_markup_margin_node (node, frame);
+ }
+ else if (lgl_xml_is_node (node, "Markup-line"))
+ {
+ xml_parse_markup_line_node (node, frame);
+ }
+ else if (lgl_xml_is_node (node, "Markup-circle"))
+ {
+ xml_parse_markup_circle_node (node, frame);
+ }
+ else if (lgl_xml_is_node (node, "Markup-rect"))
+ {
+ xml_parse_markup_rect_node (node, frame);
+ }
+ else if (lgl_xml_is_node (node, "Markup-ellipse"))
+ {
+ xml_parse_markup_ellipse_node (node, frame);
+ }
+ else if (!xmlNodeIsText (node))
+ {
+ if (!lgl_xml_is_node (node, "comment"))
+ {
+ g_message ("bad node = \"%s\"",node->name);
+ }
+ }
+ }
+
+ g_free (id);
}
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
static void
xml_parse_layout_node (xmlNodePtr layout_node,
- lglTemplateFrame *frame)
+ lglTemplateFrame *frame)
{
- gint nx, ny;
- gdouble x0, y0, dx, dy;
- xmlNodePtr node;
+ gint nx, ny;
+ gdouble x0, y0, dx, dy;
+ xmlNodePtr node;
- nx = lgl_xml_get_prop_int (layout_node, "nx", 1);
- ny = lgl_xml_get_prop_int (layout_node, "ny", 1);
+ nx = lgl_xml_get_prop_int (layout_node, "nx", 1);
+ ny = lgl_xml_get_prop_int (layout_node, "ny", 1);
- x0 = lgl_xml_get_prop_length (layout_node, "x0", 0);
- y0 = lgl_xml_get_prop_length (layout_node, "y0", 0);
+ x0 = lgl_xml_get_prop_length (layout_node, "x0", 0);
+ y0 = lgl_xml_get_prop_length (layout_node, "y0", 0);
- dx = lgl_xml_get_prop_length (layout_node, "dx", 0);
- dy = lgl_xml_get_prop_length (layout_node, "dy", 0);
+ dx = lgl_xml_get_prop_length (layout_node, "dx", 0);
+ dy = lgl_xml_get_prop_length (layout_node, "dy", 0);
- lgl_template_frame_add_layout (frame, lgl_template_layout_new (nx, ny, x0, y0, dx, dy));
+ lgl_template_frame_add_layout (frame, lgl_template_layout_new (nx, ny, x0, y0, dx, dy));
- for (node = layout_node->xmlChildrenNode; node != NULL;
- node = node->next) {
- if (!xmlNodeIsText (node)) {
- if (!lgl_xml_is_node (node, "comment")) {
- g_message ("bad node = \"%s\"",node->name);
- }
- }
- }
+ for (node = layout_node->xmlChildrenNode; node != NULL; node = node->next)
+ {
+ if (!xmlNodeIsText (node))
+ {
+ if (!lgl_xml_is_node (node, "comment"))
+ {
+ g_message ("bad node = \"%s\"",node->name);
+ }
+ }
+ }
}
/*--------------------------------------------------------------------------*/
static void
xml_parse_markup_margin_node (xmlNodePtr markup_node,
- lglTemplateFrame *frame)
+ lglTemplateFrame *frame)
{
- gdouble size;
- xmlNodePtr node;
+ gdouble size;
+ xmlNodePtr node;
- size = lgl_xml_get_prop_length (markup_node, "size", 0);
+ size = lgl_xml_get_prop_length (markup_node, "size", 0);
- lgl_template_frame_add_markup (frame, lgl_template_markup_margin_new (size));
+ lgl_template_frame_add_markup (frame, lgl_template_markup_margin_new (size));
- for (node = markup_node->xmlChildrenNode; node != NULL;
- node = node->next) {
- if (!xmlNodeIsText (node)) {
- if (!lgl_xml_is_node (node, "comment")) {
- g_message ("bad node = \"%s\"",node->name);
- }
- }
- }
+ for (node = markup_node->xmlChildrenNode; node != NULL; node = node->next)
+ {
+ if (!xmlNodeIsText (node))
+ {
+ if (!lgl_xml_is_node (node, "comment"))
+ {
+ g_message ("bad node = \"%s\"",node->name);
+ }
+ }
+ }
}
/*--------------------------------------------------------------------------*/
static void
xml_parse_markup_line_node (xmlNodePtr markup_node,
- lglTemplateFrame *frame)
+ lglTemplateFrame *frame)
{
- gdouble x1, y1, x2, y2;
- xmlNodePtr node;
+ gdouble x1, y1, x2, y2;
+ xmlNodePtr node;
- x1 = lgl_xml_get_prop_length (markup_node, "x1", 0);
- y1 = lgl_xml_get_prop_length (markup_node, "y1", 0);
- x2 = lgl_xml_get_prop_length (markup_node, "x2", 0);
- y2 = lgl_xml_get_prop_length (markup_node, "y2", 0);
+ x1 = lgl_xml_get_prop_length (markup_node, "x1", 0);
+ y1 = lgl_xml_get_prop_length (markup_node, "y1", 0);
+ x2 = lgl_xml_get_prop_length (markup_node, "x2", 0);
+ y2 = lgl_xml_get_prop_length (markup_node, "y2", 0);
- lgl_template_frame_add_markup (frame, lgl_template_markup_line_new (x1, y1, x2, y2));
+ lgl_template_frame_add_markup (frame, lgl_template_markup_line_new (x1, y1, x2, y2));
- for (node = markup_node->xmlChildrenNode; node != NULL;
- node = node->next) {
- if (!xmlNodeIsText (node)) {
- if (!lgl_xml_is_node (node, "comment")) {
- g_message ("bad node = \"%s\"",node->name);
- }
- }
- }
+ for (node = markup_node->xmlChildrenNode; node != NULL; node = node->next)
+ {
+ if (!xmlNodeIsText (node))
+ {
+ if (!lgl_xml_is_node (node, "comment"))
+ {
+ g_message ("bad node = \"%s\"",node->name);
+ }
+ }
+ }
}
/*--------------------------------------------------------------------------*/
static void
xml_parse_markup_circle_node (xmlNodePtr markup_node,
- lglTemplateFrame *frame)
+ lglTemplateFrame *frame)
{
- gdouble x0, y0, r;
- xmlNodePtr node;
+ gdouble x0, y0, r;
+ xmlNodePtr node;
- x0 = lgl_xml_get_prop_length (markup_node, "x0", 0);
- y0 = lgl_xml_get_prop_length (markup_node, "y0", 0);
- r = lgl_xml_get_prop_length (markup_node, "radius", 0);
+ x0 = lgl_xml_get_prop_length (markup_node, "x0", 0);
+ y0 = lgl_xml_get_prop_length (markup_node, "y0", 0);
+ r = lgl_xml_get_prop_length (markup_node, "radius", 0);
- lgl_template_frame_add_markup (frame, lgl_template_markup_circle_new (x0, y0, r));
+ lgl_template_frame_add_markup (frame, lgl_template_markup_circle_new (x0, y0, r));
- for (node = markup_node->xmlChildrenNode; node != NULL;
- node = node->next) {
- if (!xmlNodeIsText (node)) {
- if (!lgl_xml_is_node (node, "comment")) {
- g_message ("bad node = \"%s\"",node->name);
- }
- }
- }
+ for (node = markup_node->xmlChildrenNode; node != NULL; node = node->next)
+ {
+ if (!xmlNodeIsText (node))
+ {
+ if (!lgl_xml_is_node (node, "comment"))
+ {
+ g_message ("bad node = \"%s\"",node->name);
+ }
+ }
+ }
}
/*--------------------------------------------------------------------------*/
static void
xml_parse_markup_rect_node (xmlNodePtr markup_node,
- lglTemplateFrame *frame)
+ lglTemplateFrame *frame)
{
- gdouble x1, y1, w, h, r;
- xmlNodePtr node;
-
- x1 = lgl_xml_get_prop_length (markup_node, "x1", 0);
- y1 = lgl_xml_get_prop_length (markup_node, "y1", 0);
- w = lgl_xml_get_prop_length (markup_node, "w", 0);
- h = lgl_xml_get_prop_length (markup_node, "h", 0);
- r = lgl_xml_get_prop_length (markup_node, "r", 0);
-
- lgl_template_frame_add_markup (frame, lgl_template_markup_rect_new (x1, y1, w, h, r));
-
- for (node = markup_node->xmlChildrenNode; node != NULL;
- node = node->next) {
- if (!xmlNodeIsText (node)) {
- if (!lgl_xml_is_node (node, "comment")) {
- g_message ("bad node = \"%s\"",node->name);
- }
- }
- }
+ gdouble x1, y1, w, h, r;
+ xmlNodePtr node;
+
+ x1 = lgl_xml_get_prop_length (markup_node, "x1", 0);
+ y1 = lgl_xml_get_prop_length (markup_node, "y1", 0);
+ w = lgl_xml_get_prop_length (markup_node, "w", 0);
+ h = lgl_xml_get_prop_length (markup_node, "h", 0);
+ r = lgl_xml_get_prop_length (markup_node, "r", 0);
+
+ lgl_template_frame_add_markup (frame, lgl_template_markup_rect_new (x1, y1, w, h, r));
+
+ for (node = markup_node->xmlChildrenNode; node != NULL; node = node->next)
+ {
+ if (!xmlNodeIsText (node))
+ {
+ if (!lgl_xml_is_node (node, "comment"))
+ {
+ g_message ("bad node = \"%s\"",node->name);
+ }
+ }
+ }
}
xml_parse_markup_ellipse_node (xmlNodePtr markup_node,
lglTemplateFrame *frame)
{
- gdouble x1, y1, w, h;
- xmlNodePtr node;
+ gdouble x1, y1, w, h;
+ xmlNodePtr node;
- x1 = lgl_xml_get_prop_length (markup_node, "x1", 0);
- y1 = lgl_xml_get_prop_length (markup_node, "y1", 0);
- w = lgl_xml_get_prop_length (markup_node, "w", 0);
- h = lgl_xml_get_prop_length (markup_node, "h", 0);
+ x1 = lgl_xml_get_prop_length (markup_node, "x1", 0);
+ y1 = lgl_xml_get_prop_length (markup_node, "y1", 0);
+ w = lgl_xml_get_prop_length (markup_node, "w", 0);
+ h = lgl_xml_get_prop_length (markup_node, "h", 0);
- lgl_template_frame_add_markup (frame, lgl_template_markup_ellipse_new (x1, y1, w, h));
+ lgl_template_frame_add_markup (frame, lgl_template_markup_ellipse_new (x1, y1, w, h));
- for (node = markup_node->xmlChildrenNode; node != NULL;
- node = node->next) {
- if (!xmlNodeIsText (node)) {
- if (!lgl_xml_is_node (node, "comment")) {
- g_message ("bad node = \"%s\"",node->name);
- }
- }
- }
+ for (node = markup_node->xmlChildrenNode; node != NULL; node = node->next)
+ {
+ if (!xmlNodeIsText (node))
+ {
+ if (!lgl_xml_is_node (node, "comment"))
+ {
+ g_message ("bad node = \"%s\"",node->name);
+ }
+ }
+ }
}
/*--------------------------------------------------------------------------*/
static void
xml_parse_alias_node (xmlNodePtr alias_node,
- lglTemplate *template)
+ lglTemplate *template)
{
g_message ("Skipping deprecated \"Alias\" node.");
}
lgl_xml_template_write_templates_to_file (GList *templates,
const gchar *utf8_filename)
{
- xmlDocPtr doc;
- xmlNsPtr ns;
- gint bytes_written;
- GList *p;
- lglTemplate *template;
- gchar *filename;
-
- doc = xmlNewDoc ((xmlChar *)"1.0");
- doc->xmlRootNode = xmlNewDocNode (doc, NULL, (xmlChar *)"Glabels-templates", NULL);
-
- ns = xmlNewNs (doc->xmlRootNode, (xmlChar *)LGL_XML_NAME_SPACE, NULL);
- xmlSetNs (doc->xmlRootNode, ns);
-
- for (p=templates; p!=NULL; p=p->next) {
- template = (lglTemplate *)p->data;
- lgl_xml_template_create_template_node (template, doc->xmlRootNode, ns);
- }
-
- filename = g_filename_from_utf8 (utf8_filename, -1, NULL, NULL, NULL);
- if (!filename)
+ xmlDocPtr doc;
+ xmlNsPtr ns;
+ gint bytes_written;
+ GList *p;
+ lglTemplate *template;
+ gchar *filename;
+
+ doc = xmlNewDoc ((xmlChar *)"1.0");
+ doc->xmlRootNode = xmlNewDocNode (doc, NULL, (xmlChar *)"Glabels-templates", NULL);
+
+ ns = xmlNewNs (doc->xmlRootNode, (xmlChar *)LGL_XML_NAME_SPACE, NULL);
+ xmlSetNs (doc->xmlRootNode, ns);
+
+ for (p=templates; p!=NULL; p=p->next)
{
- g_message ("Utf8 conversion error.");
+ template = (lglTemplate *)p->data;
+ lgl_xml_template_create_template_node (template, doc->xmlRootNode, ns);
+ }
+
+ filename = g_filename_from_utf8 (utf8_filename, -1, NULL, NULL, NULL);
+ if (!filename)
+ {
+ g_message ("Utf8 conversion error.");
return -1;
}
- else
+ else
{
- xmlSetDocCompressMode (doc, 0);
- bytes_written = xmlSaveFormatFile (filename, doc, TRUE);
- xmlFreeDoc (doc);
- g_free (filename);
+ xmlSetDocCompressMode (doc, 0);
+ bytes_written = xmlSaveFormatFile (filename, doc, TRUE);
+ xmlFreeDoc (doc);
+ g_free (filename);
return bytes_written;
- }
+ }
}
lgl_xml_template_write_template_to_file (const lglTemplate *template,
const gchar *utf8_filename)
{
- GList *templates = NULL;
- gint bytes_written;
+ GList *templates = NULL;
+ gint bytes_written;
- templates = g_list_append (templates, (gpointer)template);
+ templates = g_list_append (templates, (gpointer)template);
- bytes_written = lgl_xml_template_write_templates_to_file (templates, utf8_filename);
+ bytes_written = lgl_xml_template_write_templates_to_file (templates, utf8_filename);
- g_list_free (templates);
+ g_list_free (templates);
return bytes_written;
}
xmlNodePtr root,
const xmlNsPtr ns)
{
- xmlNodePtr node;
- GList *p;
- lglTemplateFrame *frame;
+ xmlNodePtr node;
+ GList *p;
+ lglTemplateFrame *frame;
- node = xmlNewChild (root, ns, (xmlChar *)"Template", NULL);
+ node = xmlNewChild (root, ns, (xmlChar *)"Template", NULL);
- lgl_xml_set_prop_string (node, "brand", template->brand);
- lgl_xml_set_prop_string (node, "part", template->part);
+ lgl_xml_set_prop_string (node, "brand", template->brand);
+ lgl_xml_set_prop_string (node, "part", template->part);
- lgl_xml_set_prop_string (node, "size", template->paper_id);
- if (xmlStrEqual ((xmlChar *)template->paper_id, (xmlChar *)"Other"))
+ lgl_xml_set_prop_string (node, "size", template->paper_id);
+ if (xmlStrEqual ((xmlChar *)template->paper_id, (xmlChar *)"Other"))
{
- lgl_xml_set_prop_length (node, "width", template->page_width);
- lgl_xml_set_prop_length (node, "height", template->page_height);
+ lgl_xml_set_prop_length (node, "width", template->page_width);
+ lgl_xml_set_prop_length (node, "height", template->page_height);
- }
+ }
- lgl_xml_set_prop_string (node, "description", template->description);
+ lgl_xml_set_prop_string (node, "description", template->description);
xml_create_meta_node ("product_url", template->product_url, node, ns );
- for ( p=template->category_ids; p != NULL; p=p->next )
+ for ( p=template->category_ids; p != NULL; p=p->next )
{
xml_create_meta_node ( "category", p->data, node, ns );
- }
- for ( p=template->frames; p != NULL; p=p->next )
+ }
+ for ( p=template->frames; p != NULL; p=p->next )
{
- frame = (lglTemplateFrame *)p->data;
- xml_create_label_node (frame, node, ns);
- }
+ frame = (lglTemplateFrame *)p->data;
+ xml_create_label_node (frame, node, ns);
+ }
}
xmlNodePtr root,
const xmlNsPtr ns)
{
- xmlNodePtr node;
+ xmlNodePtr node;
if ( value != NULL )
{
/*--------------------------------------------------------------------------*/
static void
xml_create_label_node (const lglTemplateFrame *frame,
- xmlNodePtr root,
- const xmlNsPtr ns)
+ xmlNodePtr root,
+ const xmlNsPtr ns)
{
- xmlNodePtr node;
- GList *p;
- lglTemplateMarkup *markup;
- lglTemplateLayout *layout;
-
- switch (frame->shape) {
-
- case LGL_TEMPLATE_FRAME_SHAPE_RECT:
- node = xmlNewChild(root, ns, (xmlChar *)"Label-rectangle", NULL);
- lgl_xml_set_prop_string (node, "id", frame->all.id);
- lgl_xml_set_prop_length (node, "width", frame->rect.w);
- lgl_xml_set_prop_length (node, "height", frame->rect.h);
- lgl_xml_set_prop_length (node, "round", frame->rect.r);
- lgl_xml_set_prop_length (node, "x_waste", frame->rect.x_waste);
- lgl_xml_set_prop_length (node, "y_waste", frame->rect.y_waste);
- break;
-
- case LGL_TEMPLATE_FRAME_SHAPE_ELLIPSE:
- node = xmlNewChild(root, ns, (xmlChar *)"Label-ellipse", NULL);
- lgl_xml_set_prop_string (node, "id", frame->all.id);
- lgl_xml_set_prop_length (node, "width", frame->ellipse.w);
- lgl_xml_set_prop_length (node, "height", frame->ellipse.h);
- lgl_xml_set_prop_length (node, "waste", frame->ellipse.waste);
- break;
-
- case LGL_TEMPLATE_FRAME_SHAPE_ROUND:
- node = xmlNewChild(root, ns, (xmlChar *)"Label-round", NULL);
- lgl_xml_set_prop_string (node, "id", frame->all.id);
- lgl_xml_set_prop_length (node, "radius", frame->round.r);
- lgl_xml_set_prop_length (node, "waste", frame->round.waste);
- break;
-
- case LGL_TEMPLATE_FRAME_SHAPE_CD:
- node = xmlNewChild(root, ns, (xmlChar *)"Label-cd", NULL);
- lgl_xml_set_prop_string (node, "id", frame->all.id);
- lgl_xml_set_prop_length (node, "radius", frame->cd.r1);
- lgl_xml_set_prop_length (node, "hole", frame->cd.r2);
- if (frame->cd.w != 0.0) {
- lgl_xml_set_prop_length (node, "width", frame->cd.w);
- }
- if (frame->cd.h != 0.0) {
- lgl_xml_set_prop_length (node, "height", frame->cd.h);
- }
- lgl_xml_set_prop_length (node, "waste", frame->cd.waste);
- break;
-
- default:
- g_message ("Unknown label style");
- return;
- break;
-
- }
-
- for ( p=frame->all.markups; p != NULL; p=p->next ) {
- markup = (lglTemplateMarkup *)p->data;
- switch (markup->type) {
- case LGL_TEMPLATE_MARKUP_MARGIN:
- xml_create_markup_margin_node (markup, node, ns);
- break;
- case LGL_TEMPLATE_MARKUP_LINE:
- xml_create_markup_line_node (markup, node, ns);
- break;
- case LGL_TEMPLATE_MARKUP_CIRCLE:
- xml_create_markup_circle_node (markup, node, ns);
- break;
- case LGL_TEMPLATE_MARKUP_RECT:
- xml_create_markup_rect_node (markup, node, ns);
- break;
- case LGL_TEMPLATE_MARKUP_ELLIPSE:
- xml_create_markup_ellipse_node (markup, node, ns);
- break;
- default:
- g_message ("Unknown markup type");
- break;
- }
- }
-
- for ( p=frame->all.layouts; p != NULL; p=p->next ) {
- layout = (lglTemplateLayout *)p->data;
- xml_create_layout_node (layout, node, ns);
- }
+ xmlNodePtr node;
+ GList *p;
+ lglTemplateMarkup *markup;
+ lglTemplateLayout *layout;
+
+ switch (frame->shape)
+ {
+
+ case LGL_TEMPLATE_FRAME_SHAPE_RECT:
+ node = xmlNewChild(root, ns, (xmlChar *)"Label-rectangle", NULL);
+ lgl_xml_set_prop_string (node, "id", frame->all.id);
+ lgl_xml_set_prop_length (node, "width", frame->rect.w);
+ lgl_xml_set_prop_length (node, "height", frame->rect.h);
+ lgl_xml_set_prop_length (node, "round", frame->rect.r);
+ lgl_xml_set_prop_length (node, "x_waste", frame->rect.x_waste);
+ lgl_xml_set_prop_length (node, "y_waste", frame->rect.y_waste);
+ break;
+
+ case LGL_TEMPLATE_FRAME_SHAPE_ELLIPSE:
+ node = xmlNewChild(root, ns, (xmlChar *)"Label-ellipse", NULL);
+ lgl_xml_set_prop_string (node, "id", frame->all.id);
+ lgl_xml_set_prop_length (node, "width", frame->ellipse.w);
+ lgl_xml_set_prop_length (node, "height", frame->ellipse.h);
+ lgl_xml_set_prop_length (node, "waste", frame->ellipse.waste);
+ break;
+
+ case LGL_TEMPLATE_FRAME_SHAPE_ROUND:
+ node = xmlNewChild(root, ns, (xmlChar *)"Label-round", NULL);
+ lgl_xml_set_prop_string (node, "id", frame->all.id);
+ lgl_xml_set_prop_length (node, "radius", frame->round.r);
+ lgl_xml_set_prop_length (node, "waste", frame->round.waste);
+ break;
+
+ case LGL_TEMPLATE_FRAME_SHAPE_CD:
+ node = xmlNewChild(root, ns, (xmlChar *)"Label-cd", NULL);
+ lgl_xml_set_prop_string (node, "id", frame->all.id);
+ lgl_xml_set_prop_length (node, "radius", frame->cd.r1);
+ lgl_xml_set_prop_length (node, "hole", frame->cd.r2);
+ if (frame->cd.w != 0.0)
+ {
+ lgl_xml_set_prop_length (node, "width", frame->cd.w);
+ }
+ if (frame->cd.h != 0.0)
+ {
+ lgl_xml_set_prop_length (node, "height", frame->cd.h);
+ }
+ lgl_xml_set_prop_length (node, "waste", frame->cd.waste);
+ break;
+
+ default:
+ g_message ("Unknown label style");
+ return;
+ break;
+
+ }
+
+ for ( p=frame->all.markups; p != NULL; p=p->next )
+ {
+ markup = (lglTemplateMarkup *)p->data;
+ switch (markup->type)
+ {
+ case LGL_TEMPLATE_MARKUP_MARGIN:
+ xml_create_markup_margin_node (markup, node, ns);
+ break;
+ case LGL_TEMPLATE_MARKUP_LINE:
+ xml_create_markup_line_node (markup, node, ns);
+ break;
+ case LGL_TEMPLATE_MARKUP_CIRCLE:
+ xml_create_markup_circle_node (markup, node, ns);
+ break;
+ case LGL_TEMPLATE_MARKUP_RECT:
+ xml_create_markup_rect_node (markup, node, ns);
+ break;
+ case LGL_TEMPLATE_MARKUP_ELLIPSE:
+ xml_create_markup_ellipse_node (markup, node, ns);
+ break;
+ default:
+ g_message ("Unknown markup type");
+ break;
+ }
+ }
+
+ for ( p=frame->all.layouts; p != NULL; p=p->next )
+ {
+ layout = (lglTemplateLayout *)p->data;
+ xml_create_layout_node (layout, node, ns);
+ }
}
/*--------------------------------------------------------------------------*/
static void
xml_create_layout_node (const lglTemplateLayout *layout,
- xmlNodePtr root,
- const xmlNsPtr ns)
+ xmlNodePtr root,
+ const xmlNsPtr ns)
{
- xmlNodePtr node;
+ xmlNodePtr node;
- node = xmlNewChild(root, ns, (xmlChar *)"Layout", NULL);
- lgl_xml_set_prop_int (node, "nx", layout->nx);
- lgl_xml_set_prop_int (node, "ny", layout->ny);
- lgl_xml_set_prop_length (node, "x0", layout->x0);
- lgl_xml_set_prop_length (node, "y0", layout->y0);
- lgl_xml_set_prop_length (node, "dx", layout->dx);
- lgl_xml_set_prop_length (node, "dy", layout->dy);
+ node = xmlNewChild(root, ns, (xmlChar *)"Layout", NULL);
+ lgl_xml_set_prop_int (node, "nx", layout->nx);
+ lgl_xml_set_prop_int (node, "ny", layout->ny);
+ lgl_xml_set_prop_length (node, "x0", layout->x0);
+ lgl_xml_set_prop_length (node, "y0", layout->y0);
+ lgl_xml_set_prop_length (node, "dx", layout->dx);
+ lgl_xml_set_prop_length (node, "dy", layout->dy);
}
/*--------------------------------------------------------------------------*/
static void
xml_create_markup_margin_node (const lglTemplateMarkup *markup,
- xmlNodePtr root,
- const xmlNsPtr ns)
+ xmlNodePtr root,
+ const xmlNsPtr ns)
{
- xmlNodePtr node;
+ xmlNodePtr node;
- node = xmlNewChild(root, ns, (xmlChar *)"Markup-margin", NULL);
+ node = xmlNewChild(root, ns, (xmlChar *)"Markup-margin", NULL);
- lgl_xml_set_prop_length (node, "size", markup->margin.size);
+ lgl_xml_set_prop_length (node, "size", markup->margin.size);
}
/*--------------------------------------------------------------------------*/
static void
xml_create_markup_line_node (const lglTemplateMarkup *markup,
- xmlNodePtr root,
- const xmlNsPtr ns)
+ xmlNodePtr root,
+ const xmlNsPtr ns)
{
- xmlNodePtr node;
+ xmlNodePtr node;
- node = xmlNewChild(root, ns, (xmlChar *)"Markup-line", NULL);
+ node = xmlNewChild(root, ns, (xmlChar *)"Markup-line", NULL);
- lgl_xml_set_prop_length (node, "x1", markup->line.x1);
- lgl_xml_set_prop_length (node, "y1", markup->line.y1);
- lgl_xml_set_prop_length (node, "x2", markup->line.x2);
- lgl_xml_set_prop_length (node, "y2", markup->line.y2);
+ lgl_xml_set_prop_length (node, "x1", markup->line.x1);
+ lgl_xml_set_prop_length (node, "y1", markup->line.y1);
+ lgl_xml_set_prop_length (node, "x2", markup->line.x2);
+ lgl_xml_set_prop_length (node, "y2", markup->line.y2);
}
/*--------------------------------------------------------------------------*/
static void
xml_create_markup_circle_node (const lglTemplateMarkup *markup,
- xmlNodePtr root,
- const xmlNsPtr ns)
+ xmlNodePtr root,
+ const xmlNsPtr ns)
{
- xmlNodePtr node;
+ xmlNodePtr node;
- node = xmlNewChild(root, ns, (xmlChar *)"Markup-circle", NULL);
+ node = xmlNewChild(root, ns, (xmlChar *)"Markup-circle", NULL);
- lgl_xml_set_prop_length (node, "x0", markup->circle.x0);
- lgl_xml_set_prop_length (node, "y0", markup->circle.y0);
- lgl_xml_set_prop_length (node, "radius", markup->circle.r);
+ lgl_xml_set_prop_length (node, "x0", markup->circle.x0);
+ lgl_xml_set_prop_length (node, "y0", markup->circle.y0);
+ lgl_xml_set_prop_length (node, "radius", markup->circle.r);
}
/*--------------------------------------------------------------------------*/
static void
xml_create_markup_rect_node (const lglTemplateMarkup *markup,
- xmlNodePtr root,
- const xmlNsPtr ns)
+ xmlNodePtr root,
+ const xmlNsPtr ns)
{
- xmlNodePtr node;
+ xmlNodePtr node;
- node = xmlNewChild(root, ns, (xmlChar *)"Markup-rect", NULL);
+ node = xmlNewChild(root, ns, (xmlChar *)"Markup-rect", NULL);
- lgl_xml_set_prop_length (node, "x1", markup->rect.x1);
- lgl_xml_set_prop_length (node, "y1", markup->rect.y1);
- lgl_xml_set_prop_length (node, "w", markup->rect.w);
- lgl_xml_set_prop_length (node, "h", markup->rect.h);
- lgl_xml_set_prop_length (node, "r", markup->rect.r);
+ lgl_xml_set_prop_length (node, "x1", markup->rect.x1);
+ lgl_xml_set_prop_length (node, "y1", markup->rect.y1);
+ lgl_xml_set_prop_length (node, "w", markup->rect.w);
+ lgl_xml_set_prop_length (node, "h", markup->rect.h);
+ lgl_xml_set_prop_length (node, "r", markup->rect.r);
}
xmlNodePtr root,
const xmlNsPtr ns)
{
- xmlNodePtr node;
+ xmlNodePtr node;
- node = xmlNewChild(root, ns, (xmlChar *)"Markup-ellipse", NULL);
+ node = xmlNewChild(root, ns, (xmlChar *)"Markup-ellipse", NULL);
- lgl_xml_set_prop_length (node, "x1", markup->ellipse.x1);
- lgl_xml_set_prop_length (node, "y1", markup->ellipse.y1);
- lgl_xml_set_prop_length (node, "w", markup->ellipse.w);
- lgl_xml_set_prop_length (node, "h", markup->ellipse.h);
+ lgl_xml_set_prop_length (node, "x1", markup->ellipse.x1);
+ lgl_xml_set_prop_length (node, "y1", markup->ellipse.y1);
+ lgl_xml_set_prop_length (node, "w", markup->ellipse.w);
+ lgl_xml_set_prop_length (node, "h", markup->ellipse.h);
}
gint lgl_xml_template_write_templates_to_file (GList *templates,
- const gchar *utf8_filename);
+ const gchar *utf8_filename);
gint lgl_xml_template_write_template_to_file (const lglTemplate *template,
- const gchar *utf8_filename);
+ const gchar *utf8_filename);
void lgl_xml_template_create_template_node (const lglTemplate *template,
- xmlNodePtr root,
- const xmlNsPtr ns);
+ xmlNodePtr root,
+ const xmlNsPtr ns);
G_END_DECLS
GList *
lgl_xml_vendor_read_vendors_from_file (gchar *utf8_filename)
{
- gchar *filename;
- GList *vendors;
- xmlDocPtr vendors_doc;
+ gchar *filename;
+ GList *vendors;
+ xmlDocPtr vendors_doc;
- LIBXML_TEST_VERSION;
+ LIBXML_TEST_VERSION;
- filename = g_filename_from_utf8 (utf8_filename, -1, NULL, NULL, NULL);
- if (!filename) {
- g_message ("Utf8 filename conversion error");
- return NULL;
- }
+ filename = g_filename_from_utf8 (utf8_filename, -1, NULL, NULL, NULL);
+ if (!filename)
+ {
+ g_message ("Utf8 filename conversion error");
+ return NULL;
+ }
- vendors_doc = xmlParseFile (filename);
- if (!vendors_doc) {
- g_message ("\"%s\" is not a glabels vendor file (not XML)",
- filename);
- return NULL;
- }
+ vendors_doc = xmlParseFile (filename);
+ if (!vendors_doc)
+ {
+ g_message ("\"%s\" is not a glabels vendor file (not XML)",
+ filename);
+ return NULL;
+ }
- vendors = lgl_xml_vendor_parse_vendors_doc (vendors_doc);
+ vendors = lgl_xml_vendor_parse_vendors_doc (vendors_doc);
- g_free (filename);
- xmlFreeDoc (vendors_doc);
+ g_free (filename);
+ xmlFreeDoc (vendors_doc);
- return vendors;
+ return vendors;
}
GList *
lgl_xml_vendor_parse_vendors_doc (xmlDocPtr vendors_doc)
{
- GList *vendors = NULL;
- xmlNodePtr root, node;
- lglVendor *vendor;
-
- LIBXML_TEST_VERSION;
-
- root = xmlDocGetRootElement (vendors_doc);
- if (!root || !root->name) {
- g_message ("\"%s\" is not a glabels vendor file (no root node)",
- vendors_doc->name);
- xmlFreeDoc (vendors_doc);
- return vendors;
- }
- if (!lgl_xml_is_node (root, "Glabels-vendors")) {
- g_message ("\"%s\" is not a glabels vendor file (wrong root node)",
- vendors_doc->name);
- xmlFreeDoc (vendors_doc);
- return vendors;
- }
-
- for (node = root->xmlChildrenNode; node != NULL; node = node->next) {
-
- if (lgl_xml_is_node (node, "Vendor")) {
- vendor = lgl_xml_vendor_parse_vendor_node (node);
- vendors = g_list_append (vendors, vendor);
- } else {
- if ( !xmlNodeIsText(node) ) {
- if (!lgl_xml_is_node (node, "comment")) {
- g_message ("bad node = \"%s\"",node->name);
- }
- }
- }
- }
-
- return vendors;
+ GList *vendors = NULL;
+ xmlNodePtr root, node;
+ lglVendor *vendor;
+
+ LIBXML_TEST_VERSION;
+
+ root = xmlDocGetRootElement (vendors_doc);
+ if (!root || !root->name)
+ {
+ g_message ("\"%s\" is not a glabels vendor file (no root node)",
+ vendors_doc->name);
+ xmlFreeDoc (vendors_doc);
+ return vendors;
+ }
+ if (!lgl_xml_is_node (root, "Glabels-vendors"))
+ {
+ g_message ("\"%s\" is not a glabels vendor file (wrong root node)",
+ vendors_doc->name);
+ xmlFreeDoc (vendors_doc);
+ return vendors;
+ }
+
+ for (node = root->xmlChildrenNode; node != NULL; node = node->next)
+ {
+ if (lgl_xml_is_node (node, "Vendor"))
+ {
+ vendor = lgl_xml_vendor_parse_vendor_node (node);
+ vendors = g_list_append (vendors, vendor);
+ }
+ else
+ {
+ if ( !xmlNodeIsText(node) )
+ {
+ if (!lgl_xml_is_node (node, "comment"))
+ {
+ g_message ("bad node = \"%s\"",node->name);
+ }
+ }
+ }
+ }
+
+ return vendors;
}
lglVendor *
lgl_xml_vendor_parse_vendor_node (xmlNodePtr vendor_node)
{
- lglVendor *vendor;
- gchar *name;
+ lglVendor *vendor;
+ gchar *name;
- LIBXML_TEST_VERSION;
+ LIBXML_TEST_VERSION;
- name = lgl_xml_get_prop_i18n_string (vendor_node, "name", NULL);
+ name = lgl_xml_get_prop_i18n_string (vendor_node, "name", NULL);
- vendor = lgl_vendor_new (name);
+ vendor = lgl_vendor_new (name);
vendor->url = lgl_xml_get_prop_i18n_string (vendor_node, "url", NULL);
- g_free (name);
+ g_free (name);
- return vendor;
+ return vendor;
}
*/
gchar *
lgl_xml_get_prop_string (xmlNodePtr node,
- const gchar *property,
- const gchar *default_val)
+ const gchar *property,
+ const gchar *default_val)
{
- gchar *val;
- xmlChar *string;
-
- string = xmlGetProp (node, (xmlChar *)property);
- if ( string != NULL ) {
- val = g_strdup ((gchar *)string);
- xmlFree (string);
- return val;
- }
-
- if (default_val) {
- return g_strdup (default_val);
- }
-
- return NULL;
+ gchar *val;
+ xmlChar *string;
+
+ string = xmlGetProp (node, (xmlChar *)property);
+ if ( string != NULL )
+ {
+ val = g_strdup ((gchar *)string);
+ xmlFree (string);
+ return val;
+ }
+
+ if (default_val)
+ {
+ return g_strdup (default_val);
+ }
+
+ return NULL;
}
*/
gchar *
lgl_xml_get_prop_i18n_string (xmlNodePtr node,
- const gchar *property,
- const gchar *default_val)
+ const gchar *property,
+ const gchar *default_val)
{
- gchar *_property;
- gchar *val;
- xmlChar *string;
-
- _property = g_strdup_printf ("_%s", property);
- string = xmlGetProp (node, (xmlChar *)_property);
- g_free (_property);
-
- if ( string != NULL ) {
-
- val = g_strdup (gettext ((char *)string));
- xmlFree (string);
- return val;
-
- }
-
- string = xmlGetProp (node, (xmlChar *)property);
- if ( string != NULL ) {
- val = g_strdup ((gchar *)string);
- xmlFree (string);
- return val;
- }
-
- if (default_val) {
- return g_strdup (default_val);
- }
-
- return NULL;
+ gchar *_property;
+ gchar *val;
+ xmlChar *string;
+
+ _property = g_strdup_printf ("_%s", property);
+ string = xmlGetProp (node, (xmlChar *)_property);
+ g_free (_property);
+
+ if ( string != NULL )
+ {
+ val = g_strdup (gettext ((char *)string));
+ xmlFree (string);
+ return val;
+ }
+
+ string = xmlGetProp (node, (xmlChar *)property);
+ if ( string != NULL )
+ {
+ val = g_strdup ((gchar *)string);
+ xmlFree (string);
+ return val;
+ }
+
+ if (default_val)
+ {
+ return g_strdup (default_val);
+ }
+
+ return NULL;
}
*/
gdouble
lgl_xml_get_prop_double (xmlNodePtr node,
- const gchar *property,
- gdouble default_val)
+ const gchar *property,
+ gdouble default_val)
{
- gdouble val;
- xmlChar *string;
-
- string = xmlGetProp (node, (xmlChar *)property);
- if ( string != NULL ) {
- val = g_strtod ((gchar *)string, NULL);
- xmlFree (string);
- return val;
- }
-
- return default_val;
+ gdouble val;
+ xmlChar *string;
+
+ string = xmlGetProp (node, (xmlChar *)property);
+ if ( string != NULL )
+ {
+ val = g_strtod ((gchar *)string, NULL);
+ xmlFree (string);
+ return val;
+ }
+
+ return default_val;
}
*/
gboolean
lgl_xml_get_prop_boolean (xmlNodePtr node,
- const gchar *property,
- gboolean default_val)
+ const gchar *property,
+ gboolean default_val)
{
- gboolean val;
- xmlChar *string;
-
- string = xmlGetProp (node, (xmlChar *)property);
- if ( string != NULL ) {
- val = !((xmlStrcasecmp (string, (xmlChar *)"false") == 0) ||
- xmlStrEqual (string, (xmlChar *)"0"));;
- xmlFree (string);
- return val;
- }
-
- return default_val;
+ gboolean val;
+ xmlChar *string;
+
+ string = xmlGetProp (node, (xmlChar *)property);
+ if ( string != NULL )
+ {
+ val = !((xmlStrcasecmp (string, (xmlChar *)"false") == 0) ||
+ xmlStrEqual (string, (xmlChar *)"0"));;
+ xmlFree (string);
+ return val;
+ }
+
+ return default_val;
}
*/
gint
lgl_xml_get_prop_int (xmlNodePtr node,
- const gchar *property,
- gint default_val)
+ const gchar *property,
+ gint default_val)
{
- gint val;
- xmlChar *string;
-
- string = xmlGetProp (node, (xmlChar *)property);
- if ( string != NULL ) {
- val = strtol ((char *)string, NULL, 0);
- xmlFree (string);
- return val;
- }
-
- return default_val;
+ gint val;
+ xmlChar *string;
+
+ string = xmlGetProp (node, (xmlChar *)property);
+ if ( string != NULL )
+ {
+ val = strtol ((char *)string, NULL, 0);
+ xmlFree (string);
+ return val;
+ }
+
+ return default_val;
}
*/
guint
lgl_xml_get_prop_uint (xmlNodePtr node,
- const gchar *property,
- guint default_val)
+ const gchar *property,
+ guint default_val)
{
- guint val;
- xmlChar *string;
-
- string = xmlGetProp (node, (xmlChar *)property);
- if ( string != NULL ) {
- val = strtoul ((char *)string, NULL, 0);
- xmlFree (string);
- return val;
- }
-
- return default_val;
+ guint val;
+ xmlChar *string;
+
+ string = xmlGetProp (node, (xmlChar *)property);
+ if ( string != NULL )
+ {
+ val = strtoul ((char *)string, NULL, 0);
+ xmlFree (string);
+ return val;
+ }
+
+ return default_val;
}
*/
gdouble
lgl_xml_get_prop_length (xmlNodePtr node,
- const gchar *property,
- gdouble default_val)
+ const gchar *property,
+ gdouble default_val)
{
- gdouble val;
- xmlChar *string;
- xmlChar *unit_id;
+ gdouble val;
+ xmlChar *string;
+ xmlChar *unit_id;
lglUnits units;
- string = xmlGetProp (node, (xmlChar *)property);
- if ( string != NULL ) {
+ string = xmlGetProp (node, (xmlChar *)property);
+ if ( string != NULL )
+ {
- val = g_strtod ((gchar *)string, (gchar **)&unit_id);
+ val = g_strtod ((gchar *)string, (gchar **)&unit_id);
- if (unit_id != string) {
- unit_id = (xmlChar *)g_strchug ((gchar *)unit_id);
+ if (unit_id != string)
+ {
+ unit_id = (xmlChar *)g_strchug ((gchar *)unit_id);
units = lgl_units_from_id ((gchar *)unit_id);
if (units != LGL_UNITS_INVALID)
{
g_message ("Line %ld, Node \"%s\", Property \"%s\": Unknown unit \"%s\", assuming points",
xmlGetLineNo (node), node->name, property, unit_id);
}
- }
- else {
- val = 0.0;
- }
+ }
+ else
+ {
+ val = 0.0;
+ }
- xmlFree (string);
- return val;
- }
+ xmlFree (string);
+ return val;
+ }
- return default_val;
+ return default_val;
}
*/
void
lgl_xml_set_prop_string (xmlNodePtr node,
- const gchar *property,
- const gchar *val)
+ const gchar *property,
+ const gchar *val)
{
- if (val != NULL) {
- xmlSetProp (node, (xmlChar *)property, (xmlChar *)val);
- }
+ if (val != NULL)
+ {
+ xmlSetProp (node, (xmlChar *)property, (xmlChar *)val);
+ }
}
*/
void
lgl_xml_set_prop_double (xmlNodePtr node,
- const gchar *property,
- gdouble val)
+ const gchar *property,
+ gdouble val)
{
- gchar *string, buffer[G_ASCII_DTOSTR_BUF_SIZE];
+ gchar *string, buffer[G_ASCII_DTOSTR_BUF_SIZE];
- /* Guarantee "C" locale by use of g_ascii_formatd */
- string = g_ascii_formatd (buffer, G_ASCII_DTOSTR_BUF_SIZE, "%g", val);
+ /* Guarantee "C" locale by use of g_ascii_formatd */
+ string = g_ascii_formatd (buffer, G_ASCII_DTOSTR_BUF_SIZE, "%g", val);
- xmlSetProp (node, (xmlChar *)property, (xmlChar *)string);
+ xmlSetProp (node, (xmlChar *)property, (xmlChar *)string);
}
*/
void
lgl_xml_set_prop_boolean (xmlNodePtr node,
- const gchar *property,
- gboolean val)
+ const gchar *property,
+ gboolean val)
{
- xmlSetProp (node, (xmlChar *)property, (xmlChar *)(val ? "True" : "False"));
+ xmlSetProp (node, (xmlChar *)property, (xmlChar *)(val ? "True" : "False"));
}
/**
*/
void
lgl_xml_set_prop_int (xmlNodePtr node,
- const gchar *property,
- gint val)
+ const gchar *property,
+ gint val)
{
- gchar *string;
+ gchar *string;
- string = g_strdup_printf ("%d", val);
- xmlSetProp (node, (xmlChar *)property, (xmlChar *)string);
- g_free (string);
+ string = g_strdup_printf ("%d", val);
+ xmlSetProp (node, (xmlChar *)property, (xmlChar *)string);
+ g_free (string);
}
/**
*/
void
lgl_xml_set_prop_uint_hex (xmlNodePtr node,
- const gchar *property,
- guint val)
+ const gchar *property,
+ guint val)
{
- gchar *string;
+ gchar *string;
- string = g_strdup_printf ("0x%08x", val);
- xmlSetProp (node, (xmlChar *)property, (xmlChar *)string);
- g_free (string);
+ string = g_strdup_printf ("0x%08x", val);
+ xmlSetProp (node, (xmlChar *)property, (xmlChar *)string);
+ g_free (string);
}
/**
*/
void
lgl_xml_set_prop_length (xmlNodePtr node,
- const gchar *property,
- gdouble val)
+ const gchar *property,
+ gdouble val)
{
- gchar *string, buffer[G_ASCII_DTOSTR_BUF_SIZE];
- gchar *string_unit;
+ gchar *string, buffer[G_ASCII_DTOSTR_BUF_SIZE];
+ gchar *string_unit;
- /* Convert to default units */
- val *= lgl_units_get_units_per_point (default_units);
+ /* Convert to default units */
+ val *= lgl_units_get_units_per_point (default_units);
- /* Guarantee "C" locale by use of g_ascii_formatd */
- string = g_ascii_formatd (buffer, G_ASCII_DTOSTR_BUF_SIZE, "%g", val);
+ /* 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 ("%s%s", string, lgl_units_get_id (default_units));
- xmlSetProp (node, (xmlChar *)property, (xmlChar *)string_unit);
+ string_unit = g_strdup_printf ("%s%s", string, lgl_units_get_id (default_units));
+ xmlSetProp (node, (xmlChar *)property, (xmlChar *)string_unit);
g_free (string_unit);
}
*/
gboolean
lgl_xml_is_node (xmlNodePtr node,
- const gchar *name)
+ const gchar *name)
{
- return xmlStrEqual (node->name, (xmlChar *)name);
+ return xmlStrEqual (node->name, (xmlChar *)name);
}
gchar *
lgl_xml_get_node_content (xmlNodePtr node)
{
- xmlChar *xml_content;
- gchar *g_content;
-
- xml_content = xmlNodeGetContent (node);
-
- if (xml_content != NULL) {
+ xmlChar *xml_content;
+ gchar *g_content;
- g_content = g_strdup ((gchar *)xml_content);
- xmlFree (xml_content);
- return g_content;
+ xml_content = xmlNodeGetContent (node);
- }
+ if (xml_content != NULL)
+ {
+ g_content = g_strdup ((gchar *)xml_content);
+ xmlFree (xml_content);
+ return g_content;
+ }
- return NULL;
+ return NULL;
}
void
lgl_xml_set_default_units (lglUnits units)
{
- g_return_if_fail ((units >= LGL_UNITS_FIRST) && (units <= LGL_UNITS_LAST));
+ g_return_if_fail ((units >= LGL_UNITS_FIRST) && (units <= LGL_UNITS_LAST));
- default_units = units;
+ default_units = units;
}
* Get property functions
*/
gchar * lgl_xml_get_prop_string (xmlNodePtr node,
- const gchar *property,
- const gchar *default_val);
+ const gchar *property,
+ const gchar *default_val);
gchar * lgl_xml_get_prop_i18n_string (xmlNodePtr node,
- const gchar *property,
- const gchar *default_val);
+ const gchar *property,
+ const gchar *default_val);
gdouble lgl_xml_get_prop_double (xmlNodePtr node,
- const gchar *property,
- gdouble default_val);
+ const gchar *property,
+ gdouble default_val);
gboolean lgl_xml_get_prop_boolean (xmlNodePtr node,
- const gchar *property,
- gboolean default_val);
+ const gchar *property,
+ gboolean default_val);
gint lgl_xml_get_prop_int (xmlNodePtr node,
- const gchar *property,
- gint default_val);
+ const gchar *property,
+ gint default_val);
guint lgl_xml_get_prop_uint (xmlNodePtr node,
- const gchar *property,
- guint default_val);
+ const gchar *property,
+ guint default_val);
gdouble lgl_xml_get_prop_length (xmlNodePtr node,
- const gchar *property,
- gdouble default_val);
+ const gchar *property,
+ gdouble default_val);
/*
* Set property functions
*/
void lgl_xml_set_prop_string (xmlNodePtr node,
- const gchar *property,
- const gchar *val);
+ const gchar *property,
+ const gchar *val);
void lgl_xml_set_prop_double (xmlNodePtr node,
- const gchar *property,
- gdouble val);
+ const gchar *property,
+ gdouble val);
void lgl_xml_set_prop_boolean (xmlNodePtr node,
- const gchar *property,
- gboolean val);
+ const gchar *property,
+ gboolean val);
void lgl_xml_set_prop_int (xmlNodePtr node,
- const gchar *property,
- gint val);
+ const gchar *property,
+ gint val);
void lgl_xml_set_prop_uint_hex (xmlNodePtr node,
- const gchar *property,
- guint val);
+ const gchar *property,
+ guint val);
void lgl_xml_set_prop_length (xmlNodePtr node,
- const gchar *property,
- gdouble val);
+ const gchar *property,
+ gdouble val);
/*
* Other node functions
*/
gboolean lgl_xml_is_node (xmlNodePtr node,
- const gchar *name);
+ const gchar *name);
gchar * lgl_xml_get_node_content (xmlNodePtr node);