]> git.sur5r.net Git - glabels/commitdiff
2007-08-21 Jim Evins <evins@snaught.com>
authorJim Evins <evins@snaught.com>
Wed, 22 Aug 2007 01:58:53 +0000 (01:58 +0000)
committerJim Evins <evins@snaught.com>
Wed, 22 Aug 2007 01:58:53 +0000 (01:58 +0000)
* 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
glabels2/data/dtd/glabels-2.0.dtd
glabels2/libglabels/template.c
glabels2/libglabels/template.h
glabels2/libglabels/xml-template.c
glabels2/src/cairo-markup-path.c

index fdc8b00eda2f170047c6bb2baf0fe6a91f33c505..1a72aa20ba61920e0645c77b21b5ad7a43c64732 100644 (file)
@@ -1,3 +1,12 @@
+2007-08-21  Jim Evins  <evins@snaught.com>
+
+       * 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  <evins@snaught.com>
 
        * configure.in:
index 7bb2067a6e409aa47f31b8949d7a9a96e68b87d7..ad2f50a2ee7be3168bc274d0c4d3e1b2a8badeb6 100644 (file)
 <!-- Template Section                                                     -->
 <!-- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -->
 <!ENTITY % label_element  "Label-rectangle | Label-round | Label-cd">
-<!ENTITY % markup_element "Markup-margin | Markup-line | Markup-circle">
+<!ENTITY % markup_element "Markup-margin | Markup-line | Markup-circle | Markup-rect">
 
 <!ELEMENT Template (Meta*, (%label_element;)+, Alias*)>
 <!ATTLIST Template
                  radius          %LENGTH_TYPE;           #REQUIRED
 >
 
+<!ELEMENT Markup-rect EMPTY>
+<!ATTLIST Markup-rect
+                 x1              %LENGTH_TYPE;           #REQUIRED
+                 y1              %LENGTH_TYPE;           #REQUIRED
+                 w               %LENGTH_TYPE;           #REQUIRED
+                 h               %LENGTH_TYPE;           #REQUIRED
+                 r               %LENGTH_TYPE;           #REQUIRED
+>
+
 <!ELEMENT Layout EMPTY>
 <!ATTLIST Layout
                  nx              %UINT_TYPE;             #REQUIRED
index 3c11288dfe287ff2de14dfeb6460f6ee6939ca40..1a10477e2162be02f23e13a76eb7cb6fa8bf7e90 100644 (file)
@@ -661,6 +661,30 @@ gl_template_markup_circle_new (gdouble x0,
        return markup;
 }
 
+/*****************************************************************************/
+/* Create new markup rect structure.                                         */
+/*****************************************************************************/
+glTemplateMarkup *
+gl_template_markup_rect_new (gdouble x1,
+                            gdouble y1,
+                            gdouble w,
+                            gdouble h,
+                             gdouble r)
+{
+       glTemplateMarkup *markup;
+
+       markup = g_new0 (glTemplateMarkup, 1);
+
+       markup->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.                                                          */
index db56f81c814bbd379592fe33875c89439b347fce..bce4842530c0cf028db540ea22f9bc5842557ea9 100644 (file)
@@ -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);
index eca5c80bf797ce34875affc83f663b3165ac9553..e4477609d2d439851166df569caaee11dbc3c533 100644 (file)
@@ -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.                                  */
 /*--------------------------------------------------------------------------*/
index 90f30c3fadd870c337e31c2c08b18e4048d9a1a3..8889b37635901d71d09bcba1bb5397c3d522bf8b 100644 (file)
@@ -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);
+
 \f
 /*--------------------------------------------------------------------------*/
 /* 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");
+}
+