]> gitweb.michael.orlitzky.com - libsvgtiny.git/commitdiff
Add support for x1, y1, x2, y2 attributes of linearGradient.
authorJames Bursa <james@netsurf-browser.org>
Tue, 19 Feb 2008 01:13:11 +0000 (01:13 -0000)
committerJames Bursa <james@netsurf-browser.org>
Tue, 19 Feb 2008 01:13:11 +0000 (01:13 -0000)
svn path=/trunk/libsvgtiny/; revision=3862

svgtiny.c
svgtiny_gradient.c
svgtiny_internal.h

index 2b99a76615b970deba23deae688f2b1891dd25ae..09c6bdd27d059286ecd66f5350d0e24ab162239b 100644 (file)
--- a/svgtiny.c
+++ b/svgtiny.c
@@ -36,8 +36,6 @@ static svgtiny_code svgtiny_parse_text(xmlNode *text,
 static void svgtiny_parse_position_attributes(const xmlNode *node,
                const struct svgtiny_parse_state state,
                float *x, float *y, float *width, float *height);
-static float svgtiny_parse_length(const char *s, int viewport_size,
-               const struct svgtiny_parse_state state);
 static void svgtiny_parse_paint_attributes(const xmlNode *node,
                struct svgtiny_parse_state *state);
 static void svgtiny_parse_font_attributes(const xmlNode *node,
index 8317ceae83a206618d3fbac3052560b41e246460..c88c8044b75b0897f4c5938d56b946cbffaa6fb6 100644 (file)
@@ -11,7 +11,7 @@
 #include "svgtiny.h"
 #include "svgtiny_internal.h"
 
-#define GRADIENT_DEBUG
+#undef GRADIENT_DEBUG
 
 static svgtiny_code svgtiny_parse_linear_gradient(xmlNode *linear,
                struct svgtiny_parse_state *state);
@@ -29,6 +29,10 @@ void svgtiny_find_gradient(const char *id, struct svgtiny_parse_state *state)
        fprintf(stderr, "svgtiny_find_gradient: id \"%s\"\n", id);
 
        state->linear_gradient_stop_count = 0;
+       state->gradient_x1 = "0%";
+       state->gradient_y1 = "0%";
+       state->gradient_x2 = "100%";
+       state->gradient_y2 = "0%";
 
        xmlNode *gradient = svgtiny_find_element_by_id(
                        (xmlNode *) state->document, id);
@@ -59,6 +63,19 @@ svgtiny_code svgtiny_parse_linear_gradient(xmlNode *linear,
                svgtiny_find_gradient((const char *) href->children->content
                                + 1, state);
 
+       for (xmlAttr *attr = linear->properties; attr; attr = attr->next) {
+               const char *name = (const char *) attr->name;
+               const char *content = (const char *) attr->children->content;
+               if (strcmp(name, "x1") == 0)
+                       state->gradient_x1 = content;
+               else if (strcmp(name, "y1") == 0)
+                       state->gradient_y1 = content;
+               else if (strcmp(name, "x2") == 0)
+                       state->gradient_x2 = content;
+               else if (strcmp(name, "y2") == 0)
+                       state->gradient_y2 = content;
+        }
+
        unsigned int i = 0;
        for (xmlNode *stop = linear->children; stop; stop = stop->next) {
                float offset = -1;
@@ -148,13 +165,19 @@ svgtiny_code svgtiny_add_path_linear_gradient(float *p, unsigned int n,
        #endif
 
        /* compute gradient vector */
-       float gradient_x0 = 0, gradient_y0 = 0,
-             gradient_x1 = 1, gradient_y1 = 0.7,
+       fprintf(stderr, "x1 %s, y1 %s, x2 %s, y2 %s\n",
+                       state->gradient_x1, state->gradient_y1,
+                       state->gradient_x2, state->gradient_y2);
+       float gradient_x0, gradient_y0, gradient_x1, gradient_y1,
              gradient_dx, gradient_dy;
-       gradient_x0 = object_x0 + gradient_x0 * (object_x1 - object_x0);
-       gradient_y0 = object_y0 + gradient_y0 * (object_y1 - object_y0);
-       gradient_x1 = object_x0 + gradient_x1 * (object_x1 - object_x0);
-       gradient_y1 = object_y0 + gradient_y1 * (object_y1 - object_y0);
+       gradient_x0 = object_x0 + svgtiny_parse_length(state->gradient_x1,
+                       object_x1 - object_x0, *state);
+       gradient_y0 = object_y0 + svgtiny_parse_length(state->gradient_y1,
+                       object_y1 - object_y0, *state);
+       gradient_x1 = object_x0 + svgtiny_parse_length(state->gradient_x2,
+                       object_x1 - object_x0, *state);
+       gradient_y1 = object_y0 + svgtiny_parse_length(state->gradient_y2,
+                       object_y1 - object_y0, *state);
        gradient_dx = gradient_x1 - gradient_x0;
        gradient_dy = gradient_y1 - gradient_y0;
        #ifdef GRADIENT_DEBUG
@@ -199,7 +222,7 @@ svgtiny_code svgtiny_add_path_linear_gradient(float *p, unsigned int n,
                }
                shape->path = p;
                shape->path_length = 13;
-               shape->fill = svgtiny_TRANSPARENT; 
+               shape->fill = svgtiny_TRANSPARENT;
                shape->stroke = svgtiny_RGB(0, 0xff, 0);
                state->diagram->shape_count++;
        }*/
@@ -312,10 +335,10 @@ svgtiny_code svgtiny_add_path_linear_gradient(float *p, unsigned int n,
        b = min_pt == 0 ? pts_count - 1 : min_pt - 1;
        while (a != b) {
                float mean_r = (pts[t].r + pts[a].r + pts[b].r) / 3;
-               fprintf(stderr, "triangle: t %i %.3f a %i %.3f b %i %.3f "
+               /*fprintf(stderr, "triangle: t %i %.3f a %i %.3f b %i %.3f "
                                "mean_r %.3f\n",
                                t, pts[t].r, a, pts[a].r, b, pts[b].r,
-                               mean_r);
+                               mean_r);*/
                while (current_stop != stop_count && current_stop_r < mean_r) {
                        current_stop++;
                        if (current_stop == stop_count)
@@ -403,7 +426,7 @@ svgtiny_code svgtiny_add_path_linear_gradient(float *p, unsigned int n,
                }
                shape->path = p;
                shape->path_length = 7;
-               shape->fill = svgtiny_TRANSPARENT; 
+               shape->fill = svgtiny_TRANSPARENT;
                shape->stroke = svgtiny_RGB(0xff, 0, 0);
                state->diagram->shape_count++;
        }
index 171f5c07ae7eb036e620132bd4e9d170c2100d3e..84ecf5c31d43f62b2e8484f1b129d1ee228abf0d 100644 (file)
@@ -37,16 +37,19 @@ struct svgtiny_parse_state {
 
        /* gradients */
        unsigned int linear_gradient_stop_count;
+       const char *gradient_x1, *gradient_y1, *gradient_x2, *gradient_y2;
        struct svgtiny_gradient_stop gradient_stop[svgtiny_MAX_STOPS];
 };
 
 
 /* svgtiny.c */
-void svgtiny_transform_path(float *p, unsigned int n,
-               struct svgtiny_parse_state *state);
+float svgtiny_parse_length(const char *s, int viewport_size,
+               const struct svgtiny_parse_state state);
 void svgtiny_parse_color(const char *s, svgtiny_colour *c,
                struct svgtiny_parse_state *state);
 struct svgtiny_shape *svgtiny_add_shape(struct svgtiny_parse_state *state);
+void svgtiny_transform_path(float *p, unsigned int n,
+               struct svgtiny_parse_state *state);
 
 /* svgtiny_gradient.c */
 void svgtiny_find_gradient(const char *id, struct svgtiny_parse_state *state);