From eadd088d7026e249e02e8e72aadc5e24ef2d6669 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Wed, 22 Aug 2007 01:58:53 +0000 Subject: [PATCH] 2007-08-21 Jim Evins * data/dtd/glabels-2.0.dtd: * libglabels/template.c: * libglabels/template.h: * libglabels/xml-template.c: * src/cairo-markup-path.c: Added "Markup-rect" element to template format. git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@671 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- glabels2/ChangeLog | 9 +++++ glabels2/data/dtd/glabels-2.0.dtd | 11 ++++- glabels2/libglabels/template.c | 24 +++++++++++ glabels2/libglabels/template.h | 13 ++++++ glabels2/libglabels/xml-template.c | 64 ++++++++++++++++++++++++++++++ glabels2/src/cairo-markup-path.c | 38 ++++++++++++++++++ 6 files changed, 158 insertions(+), 1 deletion(-) diff --git a/glabels2/ChangeLog b/glabels2/ChangeLog index fdc8b00e..1a72aa20 100644 --- a/glabels2/ChangeLog +++ b/glabels2/ChangeLog @@ -1,3 +1,12 @@ +2007-08-21 Jim Evins + + * data/dtd/glabels-2.0.dtd: + * libglabels/template.c: + * libglabels/template.h: + * libglabels/xml-template.c: + * src/cairo-markup-path.c: + Added "Markup-rect" element to template format. + 2007-08-21 Jim Evins * configure.in: diff --git a/glabels2/data/dtd/glabels-2.0.dtd b/glabels2/data/dtd/glabels-2.0.dtd index 7bb2067a..ad2f50a2 100644 --- a/glabels2/data/dtd/glabels-2.0.dtd +++ b/glabels2/data/dtd/glabels-2.0.dtd @@ -117,7 +117,7 @@ - + + + + type = GL_TEMPLATE_MARKUP_RECT; + markup->data.rect.x1 = x1; + markup->data.rect.y1 = y1; + markup->data.rect.w = w; + markup->data.rect.h = h; + markup->data.rect.r = r; + + return markup; +} + /*****************************************************************************/ /* Copy a template. */ diff --git a/glabels2/libglabels/template.h b/glabels2/libglabels/template.h index db56f81c..bce48425 100644 --- a/glabels2/libglabels/template.h +++ b/glabels2/libglabels/template.h @@ -138,6 +138,7 @@ typedef enum { GL_TEMPLATE_MARKUP_MARGIN, GL_TEMPLATE_MARKUP_LINE, GL_TEMPLATE_MARKUP_CIRCLE, + GL_TEMPLATE_MARKUP_RECT, } glTemplateMarkupType; @@ -164,6 +165,12 @@ struct _glTemplateMarkup { gdouble r; /* Radius of circle */ } circle; + struct { + gdouble x1, y1; /* Upper left corner */ + gdouble w, h; /* Width and height. */ + gdouble r; /* Radius of corners. */ + } rect; + } data; }; @@ -286,6 +293,12 @@ glTemplateMarkup *gl_template_markup_circle_new (gdouble x0, gdouble y0, gdouble r); +glTemplateMarkup *gl_template_markup_rect_new (gdouble x1, + gdouble y1, + gdouble w, + gdouble h, + gdouble r); + glTemplate *gl_template_dup (const glTemplate *orig); void gl_template_free (glTemplate *template); diff --git a/glabels2/libglabels/xml-template.c b/glabels2/libglabels/xml-template.c index eca5c80b..e4477609 100644 --- a/glabels2/libglabels/xml-template.c +++ b/glabels2/libglabels/xml-template.c @@ -65,6 +65,8 @@ static void xml_parse_markup_line_node (xmlNodePtr markup_node glTemplateLabelType *label_type); static void xml_parse_markup_circle_node (xmlNodePtr markup_node, glTemplateLabelType *label_type); +static void xml_parse_markup_rect_node (xmlNodePtr markup_node, + glTemplateLabelType *label_type); static void xml_parse_alias_node (xmlNodePtr alias_node, glTemplate *template); @@ -86,6 +88,9 @@ static void xml_create_markup_line_node (const glTemplateMarkup *line, static void xml_create_markup_circle_node (const glTemplateMarkup *circle, xmlNodePtr root, const xmlNsPtr ns); +static void xml_create_markup_rect_node (const glTemplateMarkup *circle, + xmlNodePtr root, + const xmlNsPtr ns); static void xml_create_alias_node (const gchar *name, xmlNodePtr root, const xmlNsPtr ns); @@ -324,6 +329,8 @@ xml_parse_label_rectangle_node (xmlNodePtr label_node, xml_parse_markup_line_node (node, label_type); } else if (gl_xml_is_node (node, "Markup-circle")) { xml_parse_markup_circle_node (node, label_type); + } else if (gl_xml_is_node (node, "Markup-rect")) { + xml_parse_markup_rect_node (node, label_type); } else if (!xmlNodeIsText (node)) { if (!gl_xml_is_node (node, "comment")) { g_message ("bad node = \"%s\"",node->name); @@ -364,6 +371,8 @@ xml_parse_label_round_node (xmlNodePtr label_node, xml_parse_markup_line_node (node, label_type); } else if (gl_xml_is_node (node, "Markup-circle")) { xml_parse_markup_circle_node (node, label_type); + } else if (gl_xml_is_node (node, "Markup-rect")) { + xml_parse_markup_rect_node (node, label_type); } else if (!xmlNodeIsText (node)) { if (!gl_xml_is_node (node, "comment")) { g_message ("bad node = \"%s\"",node->name); @@ -407,6 +416,8 @@ xml_parse_label_cd_node (xmlNodePtr label_node, xml_parse_markup_line_node (node, label_type); } else if (gl_xml_is_node (node, "Markup-circle")) { xml_parse_markup_circle_node (node, label_type); + } else if (gl_xml_is_node (node, "Markup-rect")) { + xml_parse_markup_rect_node (node, label_type); } else if (!xmlNodeIsText (node)) { if (!gl_xml_is_node (node, "comment")) { g_message ("bad node = \"%s\"",node->name); @@ -534,6 +545,36 @@ xml_parse_markup_circle_node (xmlNodePtr markup_node, } +/*--------------------------------------------------------------------------*/ +/* PRIVATE. Parse XML Template->Label->Markup-rect Node. */ +/*--------------------------------------------------------------------------*/ +static void +xml_parse_markup_rect_node (xmlNodePtr markup_node, + glTemplateLabelType *label_type) +{ + gdouble x1, y1, w, h, r; + xmlNodePtr node; + + x1 = gl_xml_get_prop_length (markup_node, "x1", 0); + y1 = gl_xml_get_prop_length (markup_node, "y1", 0); + w = gl_xml_get_prop_length (markup_node, "w", 0); + h = gl_xml_get_prop_length (markup_node, "h", 0); + r = gl_xml_get_prop_length (markup_node, "r", 0); + + gl_template_add_markup (label_type, + gl_template_markup_rect_new (x1, y1, w, h, r)); + + for (node = markup_node->xmlChildrenNode; node != NULL; + node = node->next) { + if (!xmlNodeIsText (node)) { + if (!gl_xml_is_node (node, "comment")) { + g_message ("bad node = \"%s\"",node->name); + } + } + } + +} + /*--------------------------------------------------------------------------*/ /* PRIVATE. Parse XML Template->Alias Node. */ /*--------------------------------------------------------------------------*/ @@ -745,6 +786,9 @@ xml_create_label_node (const glTemplateLabelType *label_type, case GL_TEMPLATE_MARKUP_CIRCLE: xml_create_markup_circle_node (markup, node, ns); break; + case GL_TEMPLATE_MARKUP_RECT: + xml_create_markup_rect_node (markup, node, ns); + break; default: g_message ("Unknown markup type"); break; @@ -831,6 +875,26 @@ xml_create_markup_circle_node (const glTemplateMarkup *markup, } +/*--------------------------------------------------------------------------*/ +/* PRIVATE. Add XML Template->Label->Markup-rect Node. */ +/*--------------------------------------------------------------------------*/ +static void +xml_create_markup_rect_node (const glTemplateMarkup *markup, + xmlNodePtr root, + const xmlNsPtr ns) +{ + xmlNodePtr node; + + node = xmlNewChild(root, ns, (xmlChar *)"Markup-rect", NULL); + + gl_xml_set_prop_length (node, "x1", markup->data.rect.x1); + gl_xml_set_prop_length (node, "y1", markup->data.rect.y1); + gl_xml_set_prop_length (node, "w", markup->data.rect.w); + gl_xml_set_prop_length (node, "h", markup->data.rect.h); + gl_xml_set_prop_length (node, "r", markup->data.rect.r); + +} + /*--------------------------------------------------------------------------*/ /* PRIVATE. Add XML Template->Alias Node. */ /*--------------------------------------------------------------------------*/ diff --git a/glabels2/src/cairo-markup-path.c b/glabels2/src/cairo-markup-path.c index 90f30c3f..8889b376 100644 --- a/glabels2/src/cairo-markup-path.c +++ b/glabels2/src/cairo-markup-path.c @@ -65,6 +65,9 @@ static void gl_cairo_markup_line_path (cairo_t *c static void gl_cairo_markup_circle_path (cairo_t *cr, const glTemplateMarkup *markup); +static void gl_cairo_markup_rect_path (cairo_t *cr, + const glTemplateMarkup *markup); + /*--------------------------------------------------------------------------*/ /* Create markup path */ @@ -86,6 +89,9 @@ gl_cairo_markup_path (cairo_t *cr, case GL_TEMPLATE_MARKUP_CIRCLE: gl_cairo_markup_circle_path (cr, markup); break; + case GL_TEMPLATE_MARKUP_RECT: + gl_cairo_markup_rect_path (cr, markup); + break; default: g_message ("Unknown template markup type"); break; @@ -275,3 +281,35 @@ gl_cairo_markup_circle_path (cairo_t *cr, gl_debug (DEBUG_PATH, "END"); } +/*---------------------------------------------------------------------------*/ +/* PRIVATE. Draw rect markup. */ +/*---------------------------------------------------------------------------*/ +static void +gl_cairo_markup_rect_path (cairo_t *cr, + const glTemplateMarkup *markup) +{ + gdouble x1 = markup->data.rect.x1; + gdouble y1 = markup->data.rect.y1; + gdouble w = markup->data.rect.w; + gdouble h = markup->data.rect.h; + gdouble r = markup->data.rect.r; + + gl_debug (DEBUG_PATH, "START"); + + if ( r == 0.0 ) + { + cairo_rectangle (cr, x1, y1, w, h); + } + else + { + cairo_new_path (cr); + cairo_arc_negative (cr, x1+r, y1+r, r, 3*G_PI/2, G_PI); + cairo_arc_negative (cr, x1+r, y1+h-r, r, G_PI, G_PI/2); + cairo_arc_negative (cr, x1+w-r, y1+h-r, r, G_PI/2, 0.); + cairo_arc_negative (cr, x1+w-r, y1+r, r, 2*G_PI, 3*G_PI/2); + cairo_close_path (cr); + } + + gl_debug (DEBUG_PATH, "END"); +} + -- 2.39.5