/*===========================================*/
/* Local function prototypes */
/*===========================================*/
-static glTemplate *template_full_page (const gchar *page_size);
+static glTemplate *template_full_page (const gchar *page_size);
static GList *read_templates (void);
static gchar *get_home_data_dir (void);
-static GList *read_template_files_from_dir (GList *templates,
- const gchar *dirname);
-static GList *read_templates_from_file (GList *templates,
- gchar *xml_filename);
-
-static void xml_parse_label (xmlNodePtr label_node,
- glTemplate *template);
-static void xml_parse_layout (xmlNodePtr layout_node,
- glTemplate *template);
-static void xml_parse_markup (xmlNodePtr markup_node,
- glTemplate *template);
-static void xml_parse_alias (xmlNodePtr alias_node,
- glTemplate *template);
-
-static void xml_add_label (const glTemplate *template,
- xmlNodePtr root,
- xmlNsPtr ns);
-static void xml_add_layout (glTemplateLayout *layout,
- xmlNodePtr root,
- xmlNsPtr ns);
+static GList *read_template_files_from_dir (GList *templates,
+ const gchar *dirname);
+static GList *read_templates_from_file (GList *templates,
+ gchar *xml_filename);
+
+static void xml_parse_label (xmlNodePtr label_node,
+ glTemplate *template);
+static void xml_parse_layout (xmlNodePtr layout_node,
+ glTemplate *template);
+static void xml_parse_markup (xmlNodePtr markup_node,
+ glTemplate *template);
+static void xml_parse_alias (xmlNodePtr alias_node,
+ glTemplate *template);
+
+static void xml_add_label (const glTemplate *template,
+ xmlNodePtr root,
+ xmlNsPtr ns);
+static void xml_add_layout (glTemplateLayout *layout,
+ xmlNodePtr root,
+ xmlNsPtr ns);
static void xml_add_markup_margin (glTemplateMarkupMargin *margin,
- xmlNodePtr root,
- xmlNsPtr ns);
-static void xml_add_markup_line (glTemplateMarkupLine *line,
- xmlNodePtr root,
- xmlNsPtr ns);
-static void xml_add_alias (gchar *name,
- xmlNodePtr root,
- xmlNsPtr ns);
-
-static gint compare_origins (gconstpointer a,
- gconstpointer b,
- gpointer user_data);
-
-static glTemplateLayout *layout_new (gdouble nx,
- gdouble ny,
- gdouble x0,
- gdouble y0,
- gdouble dx,
- gdouble dy);
-static glTemplateLayout *layout_dup (glTemplateLayout *orig_layout);
-static void layout_free (glTemplateLayout **layout);
-
-static glTemplateMarkup *markup_margin_new (gdouble size);
-static glTemplateMarkup *markup_line_new (gdouble x1,
- gdouble y1,
- gdouble x2,
- gdouble y2);
-static glTemplateMarkup *markup_dup (glTemplateMarkup *orig_markup);
-static void markup_free (glTemplateMarkup **markup);
+ xmlNodePtr root,
+ xmlNsPtr ns);
+static void xml_add_markup_line (glTemplateMarkupLine *line,
+ xmlNodePtr root,
+ xmlNsPtr ns);
+static void xml_add_alias (gchar *name,
+ xmlNodePtr root,
+ xmlNsPtr ns);
+
+static gint compare_origins (gconstpointer a,
+ gconstpointer b,
+ gpointer user_data);
+
+static glTemplateLayout *layout_new (gdouble nx,
+ gdouble ny,
+ gdouble x0,
+ gdouble y0,
+ gdouble dx,
+ gdouble dy);
+static glTemplateLayout *layout_dup (glTemplateLayout *orig_layout);
+static void layout_free (glTemplateLayout **layout);
+
+static glTemplateMarkup *markup_margin_new (gdouble size);
+static glTemplateMarkup *markup_line_new (gdouble x1,
+ gdouble y1,
+ gdouble x2,
+ gdouble y2);
+static glTemplateMarkup *markup_dup (glTemplateMarkup *orig_markup);
+static void markup_free (glTemplateMarkup **markup);
/*****************************************************************************/
/* Initialize module. */
page_sizes = gl_template_get_page_size_list ();
for ( p=page_sizes; p != NULL; p=p->next ) {
- templates = g_list_append (templates,
- template_full_page (p->data));
+ if ( g_strcasecmp(p->data, "Other") != 0 ) {
+ templates = g_list_append (templates,
+ template_full_page (p->data));
+ }
}
gl_template_free_page_size_list (&page_sizes);
GList *
gl_template_get_page_size_list (void)
{
- GList *names = NULL;
- GList *p, *paper_list;
+ GList *names = NULL;
+ GList *p, *paper_list;
GnomePrintPaper *paper;
gl_debug (DEBUG_TEMPLATE, "START");
}
}
+ names = g_list_append (names, g_strdup ("Other"));
+
gl_debug (DEBUG_TEMPLATE, "END");
return names;
}
/* Free a list of page size names. */
/*****************************************************************************/
void
-gl_template_free_page_size_list (GList ** names)
+gl_template_free_page_size_list (GList **names)
{
GList *p_name;
/* Get a list of valid template names for given page size */
/*****************************************************************************/
GList *
-gl_template_get_name_list (const gchar * page_size)
+gl_template_get_name_list (const gchar *page_size)
{
- GList *p_tmplt, *p_name;
+ GList *p_tmplt, *p_name;
glTemplate *template;
- gchar *str;
- GList *names = NULL;
+ gchar *str;
+ GList *names = NULL;
gl_debug (DEBUG_TEMPLATE, "START");
/* Free a list of template names. */
/*****************************************************************************/
void
-gl_template_free_name_list (GList ** names)
+gl_template_free_name_list (GList **names)
{
GList *p_name;
/* Return a template structure from a name. */
/*****************************************************************************/
glTemplate *
-gl_template_from_name (const gchar * name)
+gl_template_from_name (const gchar *name)
{
- GList *p_tmplt, *p_name;
- glTemplate *template;
- gchar **split_name;
+ GList *p_tmplt, *p_name;
+ glTemplate *template;
+ gchar **split_name;
gl_debug (DEBUG_TEMPLATE, "START");
}
template->description = g_strdup (orig_template->description);
template->page_size = g_strdup (orig_template->page_size);
+ template->page_width = orig_template->page_width;
+ template->page_height = orig_template->page_height;
template->label = orig_template->label;
template_full_page (const gchar *page_size)
{
const GnomePrintPaper *paper;
- glTemplate *template;
+ glTemplate *template;
paper = gnome_print_paper_get_by_name (page_size);
if ( paper == NULL ) {
g_strdup_printf(_("Generic %s full page"),
page_size));
template->page_size = g_strdup(page_size);
+ template->page_width = paper->width;
+ template->page_height = paper->height;
template->description = g_strdup(FULL_PAGE);
template->label.style = GL_TEMPLATE_STYLE_RECT;
/* PRIVATE. Read all template files from given directory. Append to list. */
/*--------------------------------------------------------------------------*/
static GList *
-read_template_files_from_dir (GList * templates,
- const gchar * dirname)
+read_template_files_from_dir (GList *templates,
+ const gchar *dirname)
{
- GDir *dp;
+ GDir *dp;
const gchar *filename, *extension;
- gchar *full_filename = NULL;
- GError *gerror = NULL;
+ gchar *full_filename = NULL;
+ GError *gerror = NULL;
gl_debug (DEBUG_TEMPLATE, "START");
/* PRIVATE. Read templates from template file. */
/*--------------------------------------------------------------------------*/
static GList *
-read_templates_from_file (GList * templates,
- gchar * xml_filename)
+read_templates_from_file (GList *templates,
+ gchar *xml_filename)
{
- xmlDocPtr doc;
- xmlNodePtr root, node;
+ xmlDocPtr doc;
+ xmlNodePtr root, node;
glTemplate *template;
gl_debug (DEBUG_TEMPLATE, "START");
glTemplate *
gl_template_xml_parse_sheet (xmlNodePtr sheet_node)
{
- glTemplate *template;
- xmlNodePtr node;
+ glTemplate *template;
+ xmlNodePtr node;
+ const GnomePrintPaper *paper;
gl_debug (DEBUG_TEMPLATE, "START");
template->page_size = xmlGetProp (sheet_node, "size");
if ( strcmp (template->page_size,"US-Letter") == 0 ) {
- /* Compatibility with old pre-1.0 template files.*/
template->page_size = "US Letter";
}
+ if (g_strcasecmp (template->page_size, "Other") == 0) {
+ template->page_width =
+ g_strtod (xmlGetProp (sheet_node, "width"), NULL);
+ template->page_height =
+ g_strtod (xmlGetProp (sheet_node, "height"), NULL);
+ } else {
+ paper = gnome_print_paper_get_by_name (template->page_size);
+ if (paper != NULL) {
+ template->page_width = paper->width;
+ template->page_height = paper->height;
+ } else {
+ g_warning (_("Unknown page size \"%s\""), template->page_size);
+ }
+ }
+
template->description = xmlGetProp (sheet_node, "description");
for (node = sheet_node->xmlChildrenNode; node != NULL;
/* PRIVATE. Parse XML Sheet->Label Node. */
/*--------------------------------------------------------------------------*/
static void
-xml_parse_label (xmlNodePtr label_node,
- glTemplate * template)
+xml_parse_label (xmlNodePtr label_node,
+ glTemplate *template)
{
xmlNodePtr node;
gchar *style;
/* PRIVATE. Parse XML Sheet->Label->Layout Node. */
/*--------------------------------------------------------------------------*/
static void
-xml_parse_layout (xmlNodePtr layout_node,
- glTemplate * template)
+xml_parse_layout (xmlNodePtr layout_node,
+ glTemplate *template)
{
- gint nx, ny;
- gdouble x0, y0, dx, dy;
+ gint nx, ny;
+ gdouble x0, y0, dx, dy;
xmlNodePtr node;
gl_debug (DEBUG_TEMPLATE, "START");
/* PRIVATE. Parse XML Sheet->Label->Markup Node. */
/*--------------------------------------------------------------------------*/
static void
-xml_parse_markup (xmlNodePtr markup_node,
- glTemplate * template)
+xml_parse_markup (xmlNodePtr markup_node,
+ glTemplate *template)
{
- gchar *type;
- gdouble size;
- gdouble x1, y1, x2, y2;
- xmlNodePtr node;
+ gchar *type;
+ gdouble size;
+ gdouble x1, y1, x2, y2;
+ xmlNodePtr node;
gl_debug (DEBUG_TEMPLATE, "START");
/* PRIVATE. Parse XML Sheet->Alias Node. */
/*--------------------------------------------------------------------------*/
static void
-xml_parse_alias (xmlNodePtr alias_node,
- glTemplate * template)
+xml_parse_alias (xmlNodePtr alias_node,
+ glTemplate *template)
{
gl_debug (DEBUG_TEMPLATE, "START");
/* Add XML Template Node */
/****************************************************************************/
void
-gl_template_xml_add_sheet (const glTemplate * template,
- xmlNodePtr root,
- xmlNsPtr ns)
+gl_template_xml_add_sheet (const glTemplate *template,
+ xmlNodePtr root,
+ xmlNsPtr ns)
{
- xmlNodePtr node;
- GList *p;
+ xmlNodePtr node;
+ GList *p;
+ gchar *string;
gl_debug (DEBUG_TEMPLATE, "START");
node = xmlNewChild (root, ns, "Sheet", NULL);
xmlSetProp (node, "name", template->name->data);
+
xmlSetProp (node, "size", template->page_size);
+ if (g_strcasecmp (template->page_size, "Other") == 0) {
+
+ string = g_strdup_printf ("%g", template->page_width);
+ xmlSetProp (node, "width", string);
+ g_free (string);
+
+ string = g_strdup_printf ("%g", template->page_height);
+ xmlSetProp (node, "height", string);
+ g_free (string);
+ }
+
xmlSetProp (node, "description", template->description);
xml_add_label (template, node, ns);
/*--------------------------------------------------------------------------*/
static void
xml_add_label (const glTemplate *template,
- xmlNodePtr root,
- xmlNsPtr ns)
+ xmlNodePtr root,
+ xmlNsPtr ns)
{
- xmlNodePtr node;
- gchar *string;
- GList *p;
+ xmlNodePtr node;
+ gchar *string;
+ GList *p;
glTemplateMarkup *markup;
glTemplateLayout *layout;
/*--------------------------------------------------------------------------*/
static void
xml_add_layout (glTemplateLayout *layout,
- xmlNodePtr root,
- xmlNsPtr ns)
+ xmlNodePtr root,
+ xmlNsPtr ns)
{
- xmlNodePtr node;
- gchar *string;
+ xmlNodePtr node;
+ gchar *string;
gl_debug (DEBUG_TEMPLATE, "START");
/*--------------------------------------------------------------------------*/
static void
xml_add_markup_margin (glTemplateMarkupMargin *margin,
- xmlNodePtr root,
- xmlNsPtr ns)
+ xmlNodePtr root,
+ xmlNsPtr ns)
{
- xmlNodePtr node;
- gchar *string;
+ xmlNodePtr node;
+ gchar *string;
gl_debug (DEBUG_TEMPLATE, "START");
/*--------------------------------------------------------------------------*/
static void
xml_add_markup_line (glTemplateMarkupLine *line,
- xmlNodePtr root,
- xmlNsPtr ns)
+ xmlNodePtr root,
+ xmlNsPtr ns)
{
- xmlNodePtr node;
- gchar *string;
+ xmlNodePtr node;
+ gchar *string;
gl_debug (DEBUG_TEMPLATE, "START");
/* PRIVATE. Add XML Sheet->Alias Node. */
/*--------------------------------------------------------------------------*/
static void
-xml_add_alias (gchar *name,
- xmlNodePtr root,
- xmlNsPtr ns)
+xml_add_alias (gchar *name,
+ xmlNodePtr root,
+ xmlNsPtr ns)
{
xmlNodePtr node;
gchar *
gl_template_get_label_size_desc (const glTemplate *template)
{
- glPrefsUnits units;
- const gchar *units_string;
- gdouble units_per_point;
- gchar *string = NULL;
+ glPrefsUnits units;
+ const gchar *units_string;
+ gdouble units_per_point;
+ gchar *string = NULL;
units = gl_prefs_get_units ();
units_string = gl_prefs_get_units_string ();
gint
gl_template_get_n_labels (const glTemplate *template)
{
- gint n_labels = 0;
- GList *p;
+ gint n_labels = 0;
+ GList *p;
glTemplateLayout *layout;
for ( p=template->label.any.layouts; p != NULL; p=p->next ) {
glTemplateOrigin *
gl_template_get_origins (const glTemplate *template)
{
- gint i_label, n_labels, ix, iy;
+ gint i_label, n_labels, ix, iy;
glTemplateOrigin *origins;
- GList *p;
+ GList *p;
glTemplateLayout *layout;
n_labels = gl_template_get_n_labels (template);
static gint
compare_origins (gconstpointer a,
gconstpointer b,
- gpointer user_data)
+ gpointer user_data)
{
const glTemplateOrigin *a_origin = a, *b_origin = b;
gchar *
gl_template_get_layout_desc (const glTemplate *template)
{
- gint n_labels;
+ gint n_labels;
glTemplateLayout *layout;
- gchar *string;
+ gchar *string;
n_labels = gl_template_get_n_labels (template);
/* Local function prototypes */
/*===========================================*/
-static void gl_wdgt_media_select_class_init (glWdgtMediaSelectClass * class);
-static void gl_wdgt_media_select_instance_init (glWdgtMediaSelect * media_select);
-static void gl_wdgt_media_select_finalize (GObject * object);
+static void gl_wdgt_media_select_class_init (glWdgtMediaSelectClass *class);
+static void gl_wdgt_media_select_instance_init (glWdgtMediaSelect *media_select);
+static void gl_wdgt_media_select_finalize (GObject *object);
-static void gl_wdgt_media_select_construct (glWdgtMediaSelect * media_select);
+static void gl_wdgt_media_select_construct (glWdgtMediaSelect *media_select);
-static void page_size_entry_changed_cb (GtkEntry * entry,
- gpointer user_data);
-static void template_entry_changed_cb (GtkEntry * entry,
- gpointer user_data);
+static void page_size_entry_changed_cb (GtkEntry *entry,
+ gpointer user_data);
+static void template_entry_changed_cb (GtkEntry *entry,
+ gpointer user_data);
-static void details_update (glWdgtMediaSelect * media_select,
- gchar * name);
+static void details_update (glWdgtMediaSelect *media_select,
+ gchar *name);
\f
/****************************************************************************/
/* Boilerplate Object stuff. */
}
static void
-gl_wdgt_media_select_class_init (glWdgtMediaSelectClass * class)
+gl_wdgt_media_select_class_init (glWdgtMediaSelectClass *class)
{
GObjectClass *object_class;
}
static void
-gl_wdgt_media_select_instance_init (glWdgtMediaSelect * media_select)
+gl_wdgt_media_select_instance_init (glWdgtMediaSelect *media_select)
{
gl_debug (DEBUG_MEDIA_SELECT, "START");
}
static void
-gl_wdgt_media_select_finalize (GObject * object)
+gl_wdgt_media_select_finalize (GObject *object)
{
glWdgtMediaSelect *media_select;
glWdgtMediaSelectClass *class;
/* PRIVATE. Construct composite widget. */
/*--------------------------------------------------------------------------*/
static void
-gl_wdgt_media_select_construct (glWdgtMediaSelect * media_select)
+gl_wdgt_media_select_construct (glWdgtMediaSelect *media_select)
{
- GtkWidget *whbox, *wvbox, *wcombo, *wvbox1, *whbox1, *wlabel;
+ GtkWidget *whbox, *wvbox, *wcombo, *wvbox1, *whbox1, *wlabel;
GtkSizeGroup *label_size_group;
- gchar *name;
- GList *template_names, *page_sizes = NULL;
- const gchar *page_size;
+ gchar *name;
+ GList *template_names, *page_sizes = NULL;
+ const gchar *page_size;
gl_debug (DEBUG_MEDIA_SELECT, "START");
/* PRIVATE. modify widget due to change in selection */
/*--------------------------------------------------------------------------*/
static void
-page_size_entry_changed_cb (GtkEntry * entry,
- gpointer user_data)
+page_size_entry_changed_cb (GtkEntry *entry,
+ gpointer user_data)
{
glWdgtMediaSelect *media_select = GL_WDGT_MEDIA_SELECT (user_data);
- gchar *page_size;
- GList *template_names;
+ gchar *page_size;
+ GList *template_names;
gl_debug (DEBUG_MEDIA_SELECT, "START");
if ( strlen(page_size) ) {
gl_debug (DEBUG_MEDIA_SELECT, "page_size = \"%s\"", page_size);
template_names = gl_template_get_name_list (page_size);
+ if (template_names == NULL) {
+ template_names = g_list_append (template_names, g_strdup(""));
+ }
gtk_combo_set_popdown_strings (GTK_COMBO (media_select->template_combo),
template_names);
gtk_entry_set_text (GTK_ENTRY (media_select->template_entry),
/* PRIVATE. modify widget due to change in selection */
/*--------------------------------------------------------------------------*/
static void
-template_entry_changed_cb (GtkEntry * entry,
- gpointer user_data)
+template_entry_changed_cb (GtkEntry *entry,
+ gpointer user_data)
{
glWdgtMediaSelect *media_select = GL_WDGT_MEDIA_SELECT (user_data);
gchar *name;
/* PRIVATE. update "details" widgets from new template. */
/*--------------------------------------------------------------------------*/
static void
-details_update (glWdgtMediaSelect * media_select,
- gchar * name)
+details_update (glWdgtMediaSelect *media_select,
+ gchar *name)
{
glTemplate *template;
gchar *text;
/* query selected label template name. */
/****************************************************************************/
gchar *
-gl_wdgt_media_select_get_name (glWdgtMediaSelect * media_select)
+gl_wdgt_media_select_get_name (glWdgtMediaSelect *media_select)
{
gl_debug (DEBUG_MEDIA_SELECT, "");
return
/* set selected label template name. */
/****************************************************************************/
void
-gl_wdgt_media_select_set_name (glWdgtMediaSelect * media_select,
- gchar * name)
+gl_wdgt_media_select_set_name (glWdgtMediaSelect *media_select,
+ gchar *name)
{
gint pos;
/* query selected label template page size. */
/****************************************************************************/
gchar *
-gl_wdgt_media_select_get_page_size (glWdgtMediaSelect * media_select)
+gl_wdgt_media_select_get_page_size (glWdgtMediaSelect *media_select)
{
gl_debug (DEBUG_MEDIA_SELECT, "");
/* set selected label template page size. */
/****************************************************************************/
void
-gl_wdgt_media_select_set_page_size (glWdgtMediaSelect * media_select,
- gchar * page_size)
+gl_wdgt_media_select_set_page_size (glWdgtMediaSelect *media_select,
+ gchar *page_size)
{
gint pos;
/****************************************************************************/
/* Set label for mini-preview to determine geometry. */
/****************************************************************************/
-void gl_wdgt_mini_preview_set_label (glWdgtMiniPreview * preview,
- gchar *name)
+void gl_wdgt_mini_preview_set_label (glWdgtMiniPreview *preview,
+ gchar *name)
{
glTemplate *template;
- gchar *page_size;
- const GnomePrintPaper *paper = NULL;
- gdouble paper_width, paper_height;
- gdouble canvas_scale;
- gdouble w, h;
- gdouble shadow_x, shadow_y;
+ gchar *page_size;
+ gdouble canvas_scale;
+ gdouble w, h;
+ gdouble shadow_x, shadow_y;
gl_debug (DEBUG_MINI_PREVIEW, "START");
/* Fetch template */
template = gl_template_from_name (name);
+ gl_debug (DEBUG_MINI_PREVIEW, "page_size = %s, page_width = %g, page_height = %g",
+ template->page_size, template->page_width, template->page_height);
+
/* get paper size and set scale */
- paper = gnome_print_paper_get_by_name (template->page_size);
- paper_width = paper->width;
- paper_height = paper->height;
w = preview->width - 4 - 2*SHADOW_X_OFFSET;
h = preview->height - 4 - 2*SHADOW_Y_OFFSET;
- if ( (w/paper_width) > (h/paper_height) ) {
- canvas_scale = h / paper_height;
+ if ( (w/template->page_width) > (h/template->page_height) ) {
+ canvas_scale = h / template->page_height;
} else {
- canvas_scale = w / paper_width;
+ canvas_scale = w / template->page_width;
}
gnome_canvas_set_pixels_per_unit (GNOME_CANVAS (preview->canvas),
canvas_scale);
#if 0
gnome_canvas_set_scroll_region (GNOME_CANVAS (preview->canvas),
- 0.0, 0.0, paper_width, paper_height);
+ 0.0, 0.0,
+ template->page_width, template->page_height);
#else
gnome_canvas_set_scroll_region (GNOME_CANVAS (preview->canvas),
0.0, 0.0,
gnome_canvas_item_set (preview->shadow_item,
"x1", shadow_x,
"y1", shadow_y,
- "x2", shadow_x + paper_width,
- "y2", shadow_y + paper_height,
+ "x2", shadow_x + template->page_width,
+ "y2", shadow_y + template->page_height,
NULL);
/* update paper outline */
gnome_canvas_item_set (preview->paper_item,
- "x2", paper_width,
- "y2", paper_height,
+ "x2", template->page_width,
+ "y2", template->page_height,
NULL);
/* update label items */
gint i, n_labels;
glTemplateOrigin *origins;
gdouble x1, y1, x2, y2, w, h;
- const GnomePrintPaper *paper = NULL;
- gdouble paper_height;
gl_debug (DEBUG_MINI_PREVIEW, "START");
- /* get paper height */
- paper = gnome_print_paper_get_by_name (template->page_size);
- paper_height = paper->height;
-
group = gnome_canvas_root (canvas);
/* draw mini label outlines */