summaryrefslogtreecommitdiff
path: root/liveengineUnmapped/ofxSVGTiny/libs
diff options
context:
space:
mode:
Diffstat (limited to 'liveengineUnmapped/ofxSVGTiny/libs')
-rw-r--r--liveengineUnmapped/ofxSVGTiny/libs/src_colors.c891
-rw-r--r--liveengineUnmapped/ofxSVGTiny/libs/svgtiny.c1253
-rw-r--r--liveengineUnmapped/ofxSVGTiny/libs/svgtiny.h74
-rw-r--r--liveengineUnmapped/ofxSVGTiny/libs/svgtiny_gradient.c670
-rw-r--r--liveengineUnmapped/ofxSVGTiny/libs/svgtiny_internal.h95
-rw-r--r--liveengineUnmapped/ofxSVGTiny/libs/svgtiny_list.c125
6 files changed, 3108 insertions, 0 deletions
diff --git a/liveengineUnmapped/ofxSVGTiny/libs/src_colors.c b/liveengineUnmapped/ofxSVGTiny/libs/src_colors.c
new file mode 100644
index 0000000..2eeb1aa
--- /dev/null
+++ b/liveengineUnmapped/ofxSVGTiny/libs/src_colors.c
@@ -0,0 +1,891 @@
+/* ANSI-C code produced by gperf version 3.0.3 */
+/* Command-line: gperf --output-file=build-Darwin-Darwin-release-lib-static/src_colors.c.tmp src/colors.gperf */
+/* Computed positions: -k'1,3,6-8,12-13' */
+
+#if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \
+ && ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \
+ && (')' == 41) && ('*' == 42) && ('+' == 43) && (',' == 44) \
+ && ('-' == 45) && ('.' == 46) && ('/' == 47) && ('0' == 48) \
+ && ('1' == 49) && ('2' == 50) && ('3' == 51) && ('4' == 52) \
+ && ('5' == 53) && ('6' == 54) && ('7' == 55) && ('8' == 56) \
+ && ('9' == 57) && (':' == 58) && (';' == 59) && ('<' == 60) \
+ && ('=' == 61) && ('>' == 62) && ('?' == 63) && ('A' == 65) \
+ && ('B' == 66) && ('C' == 67) && ('D' == 68) && ('E' == 69) \
+ && ('F' == 70) && ('G' == 71) && ('H' == 72) && ('I' == 73) \
+ && ('J' == 74) && ('K' == 75) && ('L' == 76) && ('M' == 77) \
+ && ('N' == 78) && ('O' == 79) && ('P' == 80) && ('Q' == 81) \
+ && ('R' == 82) && ('S' == 83) && ('T' == 84) && ('U' == 85) \
+ && ('V' == 86) && ('W' == 87) && ('X' == 88) && ('Y' == 89) \
+ && ('Z' == 90) && ('[' == 91) && ('\\' == 92) && (']' == 93) \
+ && ('^' == 94) && ('_' == 95) && ('a' == 97) && ('b' == 98) \
+ && ('c' == 99) && ('d' == 100) && ('e' == 101) && ('f' == 102) \
+ && ('g' == 103) && ('h' == 104) && ('i' == 105) && ('j' == 106) \
+ && ('k' == 107) && ('l' == 108) && ('m' == 109) && ('n' == 110) \
+ && ('o' == 111) && ('p' == 112) && ('q' == 113) && ('r' == 114) \
+ && ('s' == 115) && ('t' == 116) && ('u' == 117) && ('v' == 118) \
+ && ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \
+ && ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126))
+/* The character set is not based on ISO-646. */
+#error "gperf generated tables don't work with this execution character set. Please report a bug to <bug-gnu-gperf@gnu.org>."
+#endif
+
+#line 15 "src/colors.gperf"
+
+#include <string.h>
+#include "svgtiny.h"
+#include "svgtiny_internal.h"
+#line 21 "src/colors.gperf"
+struct svgtiny_named_color;
+
+#define TOTAL_KEYWORDS 147
+#define MIN_WORD_LENGTH 3
+#define MAX_WORD_LENGTH 20
+#define MIN_HASH_VALUE 4
+#define MAX_HASH_VALUE 565
+/* maximum key range = 562, duplicates = 0 */
+
+#ifdef __GNUC__
+__inline
+#else
+#ifdef __cplusplus
+inline
+#endif
+#endif
+static unsigned int
+svgtiny_color_hash (register const char *str, register unsigned int len)
+{
+ static const unsigned short asso_values[] =
+ {
+ 566, 566, 566, 566, 566, 566, 566, 566, 566, 566,
+ 566, 566, 566, 566, 566, 566, 566, 566, 566, 566,
+ 566, 566, 566, 566, 566, 566, 566, 566, 566, 566,
+ 566, 566, 566, 566, 566, 566, 566, 566, 566, 566,
+ 566, 566, 566, 566, 566, 566, 566, 566, 566, 566,
+ 566, 566, 566, 566, 566, 566, 566, 566, 566, 566,
+ 566, 566, 566, 566, 566, 566, 566, 566, 566, 566,
+ 566, 566, 566, 566, 566, 566, 566, 566, 566, 566,
+ 566, 566, 566, 566, 566, 566, 566, 566, 566, 566,
+ 566, 566, 566, 566, 566, 566, 566, 5, 55, 0,
+ 35, 0, 75, 10, 5, 0, 566, 250, 10, 40,
+ 85, 60, 70, 144, 0, 20, 45, 10, 30, 185,
+ 95, 195, 566, 0, 566, 566, 566, 566, 566, 566,
+ 566, 566, 566, 566, 566, 566, 566, 566, 566, 566,
+ 566, 566, 566, 566, 566, 566, 566, 566, 566, 566,
+ 566, 566, 566, 566, 566, 566, 566, 566, 566, 566,
+ 566, 566, 566, 566, 566, 566, 566, 566, 566, 566,
+ 566, 566, 566, 566, 566, 566, 566, 566, 566, 566,
+ 566, 566, 566, 566, 566, 566, 566, 566, 566, 566,
+ 566, 566, 566, 566, 566, 566, 566, 566, 566, 566,
+ 566, 566, 566, 566, 566, 566, 566, 566, 566, 566,
+ 566, 566, 566, 566, 566, 566, 566, 566, 566, 566,
+ 566, 566, 566, 566, 566, 566, 566, 566, 566, 566,
+ 566, 566, 566, 566, 566, 566, 566, 566, 566, 566,
+ 566, 566, 566, 566, 566, 566, 566, 566, 566, 566,
+ 566, 566, 566, 566, 566, 566, 566, 566
+ };
+ register int hval = len;
+
+ switch (hval)
+ {
+ default:
+ hval += asso_values[(unsigned char)str[12]];
+ /*FALLTHROUGH*/
+ case 12:
+ hval += asso_values[(unsigned char)str[11]];
+ /*FALLTHROUGH*/
+ case 11:
+ case 10:
+ case 9:
+ case 8:
+ hval += asso_values[(unsigned char)str[7]];
+ /*FALLTHROUGH*/
+ case 7:
+ hval += asso_values[(unsigned char)str[6]];
+ /*FALLTHROUGH*/
+ case 6:
+ hval += asso_values[(unsigned char)str[5]];
+ /*FALLTHROUGH*/
+ case 5:
+ case 4:
+ case 3:
+ hval += asso_values[(unsigned char)str[2]+2];
+ /*FALLTHROUGH*/
+ case 2:
+ case 1:
+ hval += asso_values[(unsigned char)str[0]];
+ break;
+ }
+ return hval;
+}
+
+#ifdef __GNUC__
+__inline
+#if defined __GNUC_STDC_INLINE__ || defined __GNUC_GNU_INLINE__
+__attribute__ ((__gnu_inline__))
+#endif
+#endif
+const struct svgtiny_named_color *
+svgtiny_color_lookup (register const char *str, register unsigned int len)
+{
+ static const struct svgtiny_named_color wordlist[] =
+ {
+#line 43 "src/colors.gperf"
+ {"cyan", svgtiny_RGB( 0, 255, 255)},
+#line 76 "src/colors.gperf"
+ {"gray", svgtiny_RGB(128, 128, 128)},
+#line 37 "src/colors.gperf"
+ {"chartreuse", svgtiny_RGB(127, 255, 0)},
+#line 77 "src/colors.gperf"
+ {"grey", svgtiny_RGB(128, 128, 128)},
+#line 78 "src/colors.gperf"
+ {"green", svgtiny_RGB( 0, 128, 0)},
+#line 96 "src/colors.gperf"
+ {"lightgrey", svgtiny_RGB(211, 211, 211)},
+#line 95 "src/colors.gperf"
+ {"lightgreen", svgtiny_RGB(144, 238, 144)},
+#line 94 "src/colors.gperf"
+ {"lightgray", svgtiny_RGB(211, 211, 211)},
+#line 152 "src/colors.gperf"
+ {"skyblue", svgtiny_RGB(135, 206, 235)},
+#line 155 "src/colors.gperf"
+ {"slategrey", svgtiny_RGB(112, 128, 144)},
+#line 150 "src/colors.gperf"
+ {"sienna", svgtiny_RGB(160, 82, 45)},
+#line 154 "src/colors.gperf"
+ {"slategray", svgtiny_RGB(112, 128, 144)},
+#line 149 "src/colors.gperf"
+ {"seashell", svgtiny_RGB(255, 245, 238)},
+#line 160 "src/colors.gperf"
+ {"teal", svgtiny_RGB( 0, 128, 128)},
+#line 39 "src/colors.gperf"
+ {"coral", svgtiny_RGB(255, 127, 80)},
+#line 98 "src/colors.gperf"
+ {"lightsalmon", svgtiny_RGB(255, 160, 122)},
+#line 102 "src/colors.gperf"
+ {"lightslategrey", svgtiny_RGB(119, 136, 153)},
+#line 30 "src/colors.gperf"
+ {"black", svgtiny_RGB( 0, 0, 0)},
+#line 101 "src/colors.gperf"
+ {"lightslategray", svgtiny_RGB(119, 136, 153)},
+#line 128 "src/colors.gperf"
+ {"orange", svgtiny_RGB(255, 165, 0)},
+#line 129 "src/colors.gperf"
+ {"orangered", svgtiny_RGB(255, 69, 0)},
+#line 29 "src/colors.gperf"
+ {"bisque", svgtiny_RGB(255, 228, 196)},
+#line 105 "src/colors.gperf"
+ {"lime", svgtiny_RGB( 0, 255, 0)},
+#line 142 "src/colors.gperf"
+ {"red", svgtiny_RGB(255, 0, 0)},
+#line 106 "src/colors.gperf"
+ {"limegreen", svgtiny_RGB( 50, 205, 50)},
+#line 91 "src/colors.gperf"
+ {"lightcoral", svgtiny_RGB(240, 128, 128)},
+#line 144 "src/colors.gperf"
+ {"royalblue", svgtiny_RGB( 65, 105, 225)},
+#line 107 "src/colors.gperf"
+ {"linen", svgtiny_RGB(250, 240, 230)},
+#line 71 "src/colors.gperf"
+ {"fuchsia", svgtiny_RGB(255, 0, 255)},
+#line 48 "src/colors.gperf"
+ {"darkgreen", svgtiny_RGB( 0, 100, 0)},
+#line 90 "src/colors.gperf"
+ {"lightblue", svgtiny_RGB(173, 216, 230)},
+#line 54 "src/colors.gperf"
+ {"darkorchid", svgtiny_RGB(153, 50, 204)},
+#line 157 "src/colors.gperf"
+ {"springgreen", svgtiny_RGB( 0, 255, 127)},
+#line 108 "src/colors.gperf"
+ {"magenta", svgtiny_RGB(255, 0, 255)},
+#line 74 "src/colors.gperf"
+ {"gold", svgtiny_RGB(255, 215, 0)},
+#line 130 "src/colors.gperf"
+ {"orchid", svgtiny_RGB(218, 112, 214)},
+#line 153 "src/colors.gperf"
+ {"slateblue", svgtiny_RGB(106, 90, 205)},
+#line 51 "src/colors.gperf"
+ {"darkmagenta", svgtiny_RGB(139, 0, 139)},
+#line 44 "src/colors.gperf"
+ {"darkblue", svgtiny_RGB( 0, 0, 139)},
+#line 103 "src/colors.gperf"
+ {"lightsteelblue", svgtiny_RGB(176, 196, 222)},
+#line 151 "src/colors.gperf"
+ {"silver", svgtiny_RGB(192, 192, 192)},
+#line 148 "src/colors.gperf"
+ {"seagreen", svgtiny_RGB( 46, 139, 87)},
+#line 158 "src/colors.gperf"
+ {"steelblue", svgtiny_RGB( 70, 130, 180)},
+#line 159 "src/colors.gperf"
+ {"tan", svgtiny_RGB(210, 180, 140)},
+#line 137 "src/colors.gperf"
+ {"peru", svgtiny_RGB(205, 133, 63)},
+#line 141 "src/colors.gperf"
+ {"purple", svgtiny_RGB(128, 0, 128)},
+#line 55 "src/colors.gperf"
+ {"darkred", svgtiny_RGB(139, 0, 0)},
+#line 120 "src/colors.gperf"
+ {"mintcream", svgtiny_RGB(245, 255, 250)},
+#line 68 "src/colors.gperf"
+ {"firebrick", svgtiny_RGB(178, 34, 34)},
+#line 99 "src/colors.gperf"
+ {"lightseagreen", svgtiny_RGB( 32, 178, 170)},
+#line 52 "src/colors.gperf"
+ {"darkolivegreen", svgtiny_RGB( 85, 107, 47)},
+#line 121 "src/colors.gperf"
+ {"mistyrose", svgtiny_RGB(255, 228, 225)},
+#line 83 "src/colors.gperf"
+ {"indigo", svgtiny_RGB( 75, 0, 130)},
+#line 125 "src/colors.gperf"
+ {"oldlace", svgtiny_RGB(253, 245, 230)},
+#line 138 "src/colors.gperf"
+ {"pink", svgtiny_RGB(255, 192, 203)},
+#line 56 "src/colors.gperf"
+ {"darksalmon", svgtiny_RGB(233, 150, 122)},
+#line 86 "src/colors.gperf"
+ {"lavender", svgtiny_RGB(230, 230, 250)},
+#line 84 "src/colors.gperf"
+ {"ivory", svgtiny_RGB(255, 255, 240)},
+#line 122 "src/colors.gperf"
+ {"moccasin", svgtiny_RGB(255, 228, 181)},
+#line 36 "src/colors.gperf"
+ {"cadetblue", svgtiny_RGB( 95, 158, 160)},
+#line 62 "src/colors.gperf"
+ {"darkviolet", svgtiny_RGB(148, 0, 211)},
+#line 145 "src/colors.gperf"
+ {"saddlebrown", svgtiny_RGB(139, 69, 19)},
+#line 58 "src/colors.gperf"
+ {"darkslateblue", svgtiny_RGB( 72, 61, 139)},
+#line 132 "src/colors.gperf"
+ {"palegreen", svgtiny_RGB(152, 251, 152)},
+#line 156 "src/colors.gperf"
+ {"snow", svgtiny_RGB(255, 250, 250)},
+#line 82 "src/colors.gperf"
+ {"indianred", svgtiny_RGB(205, 92, 92)},
+#line 93 "src/colors.gperf"
+ {"lightgoldenrodyellow", svgtiny_RGB(250, 250, 210)},
+#line 162 "src/colors.gperf"
+ {"tomato", svgtiny_RGB(255, 99, 71)},
+#line 89 "src/colors.gperf"
+ {"lemonchiffon", svgtiny_RGB(255, 250, 205)},
+#line 97 "src/colors.gperf"
+ {"lightpink", svgtiny_RGB(255, 182, 193)},
+#line 109 "src/colors.gperf"
+ {"maroon", svgtiny_RGB(128, 0, 0)},
+#line 87 "src/colors.gperf"
+ {"lavenderblush", svgtiny_RGB(255, 240, 245)},
+#line 163 "src/colors.gperf"
+ {"turquoise", svgtiny_RGB( 64, 224, 208)},
+#line 53 "src/colors.gperf"
+ {"darkorange", svgtiny_RGB(255, 140, 0)},
+#line 124 "src/colors.gperf"
+ {"navy", svgtiny_RGB( 0, 0, 128)},
+#line 67 "src/colors.gperf"
+ {"dodgerblue", svgtiny_RGB( 30, 144, 255)},
+#line 70 "src/colors.gperf"
+ {"forestgreen", svgtiny_RGB( 34, 139, 34)},
+#line 119 "src/colors.gperf"
+ {"midnightblue", svgtiny_RGB( 25, 25, 112)},
+#line 114 "src/colors.gperf"
+ {"mediumseagreen", svgtiny_RGB( 60, 179, 113)},
+#line 57 "src/colors.gperf"
+ {"darkseagreen", svgtiny_RGB(143, 188, 143)},
+#line 25 "src/colors.gperf"
+ {"aqua", svgtiny_RGB( 0, 255, 255)},
+#line 27 "src/colors.gperf"
+ {"azure", svgtiny_RGB(240, 255, 255)},
+#line 146 "src/colors.gperf"
+ {"salmon", svgtiny_RGB(250, 128, 114)},
+#line 165 "src/colors.gperf"
+ {"wheat", svgtiny_RGB(245, 222, 179)},
+#line 34 "src/colors.gperf"
+ {"brown", svgtiny_RGB(165, 42, 42)},
+#line 26 "src/colors.gperf"
+ {"aquamarine", svgtiny_RGB(127, 255, 212)},
+#line 38 "src/colors.gperf"
+ {"chocolate", svgtiny_RGB(210, 105, 30)},
+#line 88 "src/colors.gperf"
+ {"lawngreen", svgtiny_RGB(124, 252, 0)},
+#line 147 "src/colors.gperf"
+ {"sandybrown", svgtiny_RGB(244, 164, 96)},
+#line 92 "src/colors.gperf"
+ {"lightcyan", svgtiny_RGB(224, 255, 255)},
+#line 164 "src/colors.gperf"
+ {"violet", svgtiny_RGB(238, 130, 238)},
+#line 104 "src/colors.gperf"
+ {"lightyellow", svgtiny_RGB(255, 255, 224)},
+#line 111 "src/colors.gperf"
+ {"mediumblue", svgtiny_RGB( 0, 0, 205)},
+#line 136 "src/colors.gperf"
+ {"peachpuff", svgtiny_RGB(255, 218, 185)},
+#line 79 "src/colors.gperf"
+ {"greenyellow", svgtiny_RGB(173, 255, 47)},
+#line 24 "src/colors.gperf"
+ {"antiquewhite", svgtiny_RGB(250, 235, 215)},
+#line 32 "src/colors.gperf"
+ {"blue", svgtiny_RGB( 0, 0, 255)},
+#line 118 "src/colors.gperf"
+ {"mediumvioletred", svgtiny_RGB(199, 21, 133)},
+#line 113 "src/colors.gperf"
+ {"mediumpurple", svgtiny_RGB(147, 112, 219)},
+#line 75 "src/colors.gperf"
+ {"goldenrod", svgtiny_RGB(218, 165, 32)},
+#line 31 "src/colors.gperf"
+ {"blanchedalmond", svgtiny_RGB(255, 235, 205)},
+#line 85 "src/colors.gperf"
+ {"khaki", svgtiny_RGB(240, 230, 140)},
+#line 139 "src/colors.gperf"
+ {"plum", svgtiny_RGB(221, 160, 221)},
+#line 112 "src/colors.gperf"
+ {"mediumorchid", svgtiny_RGB(186, 85, 211)},
+#line 143 "src/colors.gperf"
+ {"rosybrown", svgtiny_RGB(188, 143, 143)},
+#line 115 "src/colors.gperf"
+ {"mediumslateblue", svgtiny_RGB(123, 104, 238)},
+#line 61 "src/colors.gperf"
+ {"darkturquoise", svgtiny_RGB( 0, 206, 209)},
+#line 134 "src/colors.gperf"
+ {"palevioletred", svgtiny_RGB(219, 112, 147)},
+#line 135 "src/colors.gperf"
+ {"papayawhip", svgtiny_RGB(255, 239, 213)},
+#line 116 "src/colors.gperf"
+ {"mediumspringgreen", svgtiny_RGB( 0, 250, 154)},
+#line 49 "src/colors.gperf"
+ {"darkgrey", svgtiny_RGB(169, 169, 169)},
+#line 117 "src/colors.gperf"
+ {"mediumturquoise", svgtiny_RGB( 72, 209, 204)},
+#line 47 "src/colors.gperf"
+ {"darkgray", svgtiny_RGB(169, 169, 169)},
+#line 46 "src/colors.gperf"
+ {"darkgoldenrod", svgtiny_RGB(184, 134, 11)},
+#line 66 "src/colors.gperf"
+ {"dimgrey", svgtiny_RGB(105, 105, 105)},
+#line 65 "src/colors.gperf"
+ {"dimgray", svgtiny_RGB(105, 105, 105)},
+#line 80 "src/colors.gperf"
+ {"honeydew", svgtiny_RGB(240, 255, 240)},
+#line 28 "src/colors.gperf"
+ {"beige", svgtiny_RGB(245, 245, 220)},
+#line 161 "src/colors.gperf"
+ {"thistle", svgtiny_RGB(216, 191, 216)},
+#line 41 "src/colors.gperf"
+ {"cornsilk", svgtiny_RGB(255, 248, 220)},
+#line 126 "src/colors.gperf"
+ {"olive", svgtiny_RGB(128, 128, 0)},
+#line 33 "src/colors.gperf"
+ {"blueviolet", svgtiny_RGB(138, 43, 226)},
+#line 110 "src/colors.gperf"
+ {"mediumaquamarine", svgtiny_RGB(102, 205, 170)},
+#line 40 "src/colors.gperf"
+ {"cornflowerblue", svgtiny_RGB(100, 149, 237)},
+#line 23 "src/colors.gperf"
+ {"aliceblue", svgtiny_RGB(240, 248, 255)},
+#line 140 "src/colors.gperf"
+ {"powderblue", svgtiny_RGB(176, 224, 230)},
+#line 133 "src/colors.gperf"
+ {"paleturquoise", svgtiny_RGB(175, 238, 238)},
+#line 60 "src/colors.gperf"
+ {"darkslategrey", svgtiny_RGB( 47, 79, 79)},
+#line 50 "src/colors.gperf"
+ {"darkkhaki", svgtiny_RGB(189, 183, 107)},
+#line 59 "src/colors.gperf"
+ {"darkslategray", svgtiny_RGB( 47, 79, 79)},
+#line 73 "src/colors.gperf"
+ {"ghostwhite", svgtiny_RGB(248, 248, 255)},
+#line 127 "src/colors.gperf"
+ {"olivedrab", svgtiny_RGB(107, 142, 35)},
+#line 131 "src/colors.gperf"
+ {"palegoldenrod", svgtiny_RGB(238, 232, 170)},
+#line 45 "src/colors.gperf"
+ {"darkcyan", svgtiny_RGB( 0, 139, 139)},
+#line 81 "src/colors.gperf"
+ {"hotpink", svgtiny_RGB(255, 105, 180)},
+#line 72 "src/colors.gperf"
+ {"gainsboro", svgtiny_RGB(220, 220, 220)},
+#line 63 "src/colors.gperf"
+ {"deeppink", svgtiny_RGB(255, 20, 147)},
+#line 42 "src/colors.gperf"
+ {"crimson", svgtiny_RGB(220, 20, 60)},
+#line 35 "src/colors.gperf"
+ {"burlywood", svgtiny_RGB(222, 184, 135)},
+#line 69 "src/colors.gperf"
+ {"floralwhite", svgtiny_RGB(255, 250, 240)},
+#line 166 "src/colors.gperf"
+ {"white", svgtiny_RGB(255, 255, 255)},
+#line 123 "src/colors.gperf"
+ {"navajowhite", svgtiny_RGB(255, 222, 173)},
+#line 168 "src/colors.gperf"
+ {"yellow", svgtiny_RGB(255, 255, 0)},
+#line 169 "src/colors.gperf"
+ {"yellowgreen", svgtiny_RGB(154, 205, 50)},
+#line 100 "src/colors.gperf"
+ {"lightskyblue", svgtiny_RGB(135, 206, 250)},
+#line 64 "src/colors.gperf"
+ {"deepskyblue", svgtiny_RGB( 0, 191, 255)},
+#line 167 "src/colors.gperf"
+ {"whitesmoke", svgtiny_RGB(245, 245, 245)}
+ };
+
+ if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
+ {
+ register int key = svgtiny_color_hash (str, len);
+
+ if (key <= MAX_HASH_VALUE && key >= MIN_HASH_VALUE)
+ {
+ register const struct svgtiny_named_color *resword;
+
+ switch (key - 4)
+ {
+ case 0:
+ resword = &wordlist[0];
+ goto compare;
+ case 10:
+ resword = &wordlist[1];
+ goto compare;
+ case 16:
+ resword = &wordlist[2];
+ goto compare;
+ case 20:
+ resword = &wordlist[3];
+ goto compare;
+ case 21:
+ resword = &wordlist[4];
+ goto compare;
+ case 25:
+ resword = &wordlist[5];
+ goto compare;
+ case 26:
+ resword = &wordlist[6];
+ goto compare;
+ case 30:
+ resword = &wordlist[7];
+ goto compare;
+ case 33:
+ resword = &wordlist[8];
+ goto compare;
+ case 35:
+ resword = &wordlist[9];
+ goto compare;
+ case 37:
+ resword = &wordlist[10];
+ goto compare;
+ case 40:
+ resword = &wordlist[11];
+ goto compare;
+ case 44:
+ resword = &wordlist[12];
+ goto compare;
+ case 45:
+ resword = &wordlist[13];
+ goto compare;
+ case 46:
+ resword = &wordlist[14];
+ goto compare;
+ case 52:
+ resword = &wordlist[15];
+ goto compare;
+ case 55:
+ resword = &wordlist[16];
+ goto compare;
+ case 56:
+ resword = &wordlist[17];
+ goto compare;
+ case 60:
+ resword = &wordlist[18];
+ goto compare;
+ case 62:
+ resword = &wordlist[19];
+ goto compare;
+ case 65:
+ resword = &wordlist[20];
+ goto compare;
+ case 67:
+ resword = &wordlist[21];
+ goto compare;
+ case 70:
+ resword = &wordlist[22];
+ goto compare;
+ case 74:
+ resword = &wordlist[23];
+ goto compare;
+ case 75:
+ resword = &wordlist[24];
+ goto compare;
+ case 76:
+ resword = &wordlist[25];
+ goto compare;
+ case 80:
+ resword = &wordlist[26];
+ goto compare;
+ case 81:
+ resword = &wordlist[27];
+ goto compare;
+ case 83:
+ resword = &wordlist[28];
+ goto compare;
+ case 85:
+ resword = &wordlist[29];
+ goto compare;
+ case 90:
+ resword = &wordlist[30];
+ goto compare;
+ case 91:
+ resword = &wordlist[31];
+ goto compare;
+ case 92:
+ resword = &wordlist[32];
+ goto compare;
+ case 93:
+ resword = &wordlist[33];
+ goto compare;
+ case 95:
+ resword = &wordlist[34];
+ goto compare;
+ case 97:
+ resword = &wordlist[35];
+ goto compare;
+ case 100:
+ resword = &wordlist[36];
+ goto compare;
+ case 102:
+ resword = &wordlist[37];
+ goto compare;
+ case 104:
+ resword = &wordlist[38];
+ goto compare;
+ case 105:
+ resword = &wordlist[39];
+ goto compare;
+ case 107:
+ resword = &wordlist[40];
+ goto compare;
+ case 109:
+ resword = &wordlist[41];
+ goto compare;
+ case 110:
+ resword = &wordlist[42];
+ goto compare;
+ case 114:
+ resword = &wordlist[43];
+ goto compare;
+ case 115:
+ resword = &wordlist[44];
+ goto compare;
+ case 117:
+ resword = &wordlist[45];
+ goto compare;
+ case 118:
+ resword = &wordlist[46];
+ goto compare;
+ case 120:
+ resword = &wordlist[47];
+ goto compare;
+ case 125:
+ resword = &wordlist[48];
+ goto compare;
+ case 129:
+ resword = &wordlist[49];
+ goto compare;
+ case 130:
+ resword = &wordlist[50];
+ goto compare;
+ case 135:
+ resword = &wordlist[51];
+ goto compare;
+ case 137:
+ resword = &wordlist[52];
+ goto compare;
+ case 138:
+ resword = &wordlist[53];
+ goto compare;
+ case 140:
+ resword = &wordlist[54];
+ goto compare;
+ case 141:
+ resword = &wordlist[55];
+ goto compare;
+ case 144:
+ resword = &wordlist[56];
+ goto compare;
+ case 145:
+ resword = &wordlist[57];
+ goto compare;
+ case 149:
+ resword = &wordlist[58];
+ goto compare;
+ case 155:
+ resword = &wordlist[59];
+ goto compare;
+ case 156:
+ resword = &wordlist[60];
+ goto compare;
+ case 157:
+ resword = &wordlist[61];
+ goto compare;
+ case 159:
+ resword = &wordlist[62];
+ goto compare;
+ case 160:
+ resword = &wordlist[63];
+ goto compare;
+ case 164:
+ resword = &wordlist[64];
+ goto compare;
+ case 165:
+ resword = &wordlist[65];
+ goto compare;
+ case 166:
+ resword = &wordlist[66];
+ goto compare;
+ case 167:
+ resword = &wordlist[67];
+ goto compare;
+ case 168:
+ resword = &wordlist[68];
+ goto compare;
+ case 170:
+ resword = &wordlist[69];
+ goto compare;
+ case 172:
+ resword = &wordlist[70];
+ goto compare;
+ case 174:
+ resword = &wordlist[71];
+ goto compare;
+ case 175:
+ resword = &wordlist[72];
+ goto compare;
+ case 176:
+ resword = &wordlist[73];
+ goto compare;
+ case 180:
+ resword = &wordlist[74];
+ goto compare;
+ case 181:
+ resword = &wordlist[75];
+ goto compare;
+ case 182:
+ resword = &wordlist[76];
+ goto compare;
+ case 183:
+ resword = &wordlist[77];
+ goto compare;
+ case 185:
+ resword = &wordlist[78];
+ goto compare;
+ case 188:
+ resword = &wordlist[79];
+ goto compare;
+ case 190:
+ resword = &wordlist[80];
+ goto compare;
+ case 191:
+ resword = &wordlist[81];
+ goto compare;
+ case 192:
+ resword = &wordlist[82];
+ goto compare;
+ case 196:
+ resword = &wordlist[83];
+ goto compare;
+ case 200:
+ resword = &wordlist[84];
+ goto compare;
+ case 201:
+ resword = &wordlist[85];
+ goto compare;
+ case 209:
+ resword = &wordlist[86];
+ goto compare;
+ case 210:
+ resword = &wordlist[87];
+ goto compare;
+ case 211:
+ resword = &wordlist[88];
+ goto compare;
+ case 215:
+ resword = &wordlist[89];
+ goto compare;
+ case 221:
+ resword = &wordlist[90];
+ goto compare;
+ case 222:
+ resword = &wordlist[91];
+ goto compare;
+ case 226:
+ resword = &wordlist[92];
+ goto compare;
+ case 230:
+ resword = &wordlist[93];
+ goto compare;
+ case 232:
+ resword = &wordlist[94];
+ goto compare;
+ case 238:
+ resword = &wordlist[95];
+ goto compare;
+ case 240:
+ resword = &wordlist[96];
+ goto compare;
+ case 241:
+ resword = &wordlist[97];
+ goto compare;
+ case 243:
+ resword = &wordlist[98];
+ goto compare;
+ case 245:
+ resword = &wordlist[99];
+ goto compare;
+ case 250:
+ resword = &wordlist[100];
+ goto compare;
+ case 251:
+ resword = &wordlist[101];
+ goto compare;
+ case 255:
+ resword = &wordlist[102];
+ goto compare;
+ case 258:
+ resword = &wordlist[103];
+ goto compare;
+ case 260:
+ resword = &wordlist[104];
+ goto compare;
+ case 261:
+ resword = &wordlist[105];
+ goto compare;
+ case 263:
+ resword = &wordlist[106];
+ goto compare;
+ case 269:
+ resword = &wordlist[107];
+ goto compare;
+ case 271:
+ resword = &wordlist[108];
+ goto compare;
+ case 278:
+ resword = &wordlist[109];
+ goto compare;
+ case 279:
+ resword = &wordlist[110];
+ goto compare;
+ case 281:
+ resword = &wordlist[111];
+ goto compare;
+ case 284:
+ resword = &wordlist[112];
+ goto compare;
+ case 289:
+ resword = &wordlist[113];
+ goto compare;
+ case 293:
+ resword = &wordlist[114];
+ goto compare;
+ case 298:
+ resword = &wordlist[115];
+ goto compare;
+ case 299:
+ resword = &wordlist[116];
+ goto compare;
+ case 306:
+ resword = &wordlist[117];
+ goto compare;
+ case 308:
+ resword = &wordlist[118];
+ goto compare;
+ case 309:
+ resword = &wordlist[119];
+ goto compare;
+ case 311:
+ resword = &wordlist[120];
+ goto compare;
+ case 316:
+ resword = &wordlist[121];
+ goto compare;
+ case 321:
+ resword = &wordlist[122];
+ goto compare;
+ case 330:
+ resword = &wordlist[123];
+ goto compare;
+ case 335:
+ resword = &wordlist[124];
+ goto compare;
+ case 336:
+ resword = &wordlist[125];
+ goto compare;
+ case 338:
+ resword = &wordlist[126];
+ goto compare;
+ case 344:
+ resword = &wordlist[127];
+ goto compare;
+ case 345:
+ resword = &wordlist[128];
+ goto compare;
+ case 349:
+ resword = &wordlist[129];
+ goto compare;
+ case 350:
+ resword = &wordlist[130];
+ goto compare;
+ case 355:
+ resword = &wordlist[131];
+ goto compare;
+ case 364:
+ resword = &wordlist[132];
+ goto compare;
+ case 369:
+ resword = &wordlist[133];
+ goto compare;
+ case 373:
+ resword = &wordlist[134];
+ goto compare;
+ case 380:
+ resword = &wordlist[135];
+ goto compare;
+ case 384:
+ resword = &wordlist[136];
+ goto compare;
+ case 398:
+ resword = &wordlist[137];
+ goto compare;
+ case 410:
+ resword = &wordlist[138];
+ goto compare;
+ case 426:
+ resword = &wordlist[139];
+ goto compare;
+ case 436:
+ resword = &wordlist[140];
+ goto compare;
+ case 437:
+ resword = &wordlist[141];
+ goto compare;
+ case 467:
+ resword = &wordlist[142];
+ goto compare;
+ case 482:
+ resword = &wordlist[143];
+ goto compare;
+ case 483:
+ resword = &wordlist[144];
+ goto compare;
+ case 552:
+ resword = &wordlist[145];
+ goto compare;
+ case 561:
+ resword = &wordlist[146];
+ goto compare;
+ }
+ return 0;
+ compare:
+ {
+ register const char *s = resword->name;
+
+ if (*str == *s && !strcmp (str + 1, s + 1))
+ return resword;
+ }
+ }
+ }
+ return 0;
+}
diff --git a/liveengineUnmapped/ofxSVGTiny/libs/svgtiny.c b/liveengineUnmapped/ofxSVGTiny/libs/svgtiny.c
new file mode 100644
index 0000000..8fa09a5
--- /dev/null
+++ b/liveengineUnmapped/ofxSVGTiny/libs/svgtiny.c
@@ -0,0 +1,1253 @@
+/*
+ * This file is part of Libsvgtiny
+ * Licensed under the MIT License,
+ * http://opensource.org/licenses/mit-license.php
+ * Copyright 2008-2009 James Bursa <james@semichrome.net>
+ */
+
+#include <assert.h>
+#include <math.h>
+#include <setjmp.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <libxml/parser.h>
+#include <libxml/debugXML.h>
+#include "svgtiny.h"
+#include "svgtiny_internal.h"
+
+#ifndef M_PI
+#define M_PI 3.14159265358979323846
+#endif
+
+#define KAPPA 0.5522847498
+
+static svgtiny_code svgtiny_parse_svg(xmlNode *svg,
+ struct svgtiny_parse_state state);
+static svgtiny_code svgtiny_parse_path(xmlNode *path,
+ struct svgtiny_parse_state state);
+static svgtiny_code svgtiny_parse_rect(xmlNode *rect,
+ struct svgtiny_parse_state state);
+static svgtiny_code svgtiny_parse_circle(xmlNode *circle,
+ struct svgtiny_parse_state state);
+static svgtiny_code svgtiny_parse_ellipse(xmlNode *ellipse,
+ struct svgtiny_parse_state state);
+static svgtiny_code svgtiny_parse_line(xmlNode *line,
+ struct svgtiny_parse_state state);
+static svgtiny_code svgtiny_parse_poly(xmlNode *poly,
+ struct svgtiny_parse_state state, bool polygon);
+static svgtiny_code svgtiny_parse_text(xmlNode *text,
+ struct svgtiny_parse_state state);
+static void svgtiny_parse_position_attributes(const xmlNode *node,
+ const struct svgtiny_parse_state state,
+ float *x, float *y, float *width, float *height);
+static void svgtiny_parse_paint_attributes(const xmlNode *node,
+ struct svgtiny_parse_state *state);
+static void svgtiny_parse_font_attributes(const xmlNode *node,
+ struct svgtiny_parse_state *state);
+static void svgtiny_parse_transform_attributes(xmlNode *node,
+ struct svgtiny_parse_state *state);
+static svgtiny_code svgtiny_add_path(float *p, unsigned int n,
+ struct svgtiny_parse_state *state);
+
+
+/**
+ * Create a new svgtiny_diagram structure.
+ */
+
+struct svgtiny_diagram *svgtiny_create(void)
+{
+ struct svgtiny_diagram *diagram;
+
+ diagram = malloc(sizeof *diagram);
+ if (!diagram)
+ return 0;
+
+ diagram->shape = 0;
+ diagram->shape_count = 0;
+ diagram->error_line = 0;
+ diagram->error_message = 0;
+
+ return diagram;
+}
+
+
+/**
+ * Parse a block of memory into a svgtiny_diagram.
+ */
+
+svgtiny_code svgtiny_parse(struct svgtiny_diagram *diagram,
+ const char *buffer, size_t size, const char *url,
+ int viewport_width, int viewport_height)
+{
+ xmlDoc *document;
+ xmlNode *svg;
+ struct svgtiny_parse_state state;
+ float x, y, width, height;
+ svgtiny_code code;
+
+ assert(diagram);
+ assert(buffer);
+ assert(url);
+
+ /* parse XML to tree */
+ document = xmlReadMemory(buffer, size, url, 0,
+ XML_PARSE_NONET | XML_PARSE_COMPACT);
+ if (!document)
+ return svgtiny_LIBXML_ERROR;
+
+ /*xmlDebugDumpDocument(stderr, document);*/
+
+ /* find root <svg> element */
+ svg = xmlDocGetRootElement(document);
+ if (!svg)
+ return svgtiny_NOT_SVG;
+ if (strcmp((const char *) svg->name, "svg") != 0)
+ return svgtiny_NOT_SVG;
+
+ /* get graphic dimensions */
+ state.diagram = diagram;
+ state.document = document;
+ state.viewport_width = viewport_width;
+ state.viewport_height = viewport_height;
+ svgtiny_parse_position_attributes(svg, state, &x, &y, &width, &height);
+ diagram->width = width;
+ diagram->height = height;
+
+ /* set up parsing state */
+ state.viewport_width = width;
+ state.viewport_height = height;
+ state.ctm.a = 1; /*(float) viewport_width / (float) width;*/
+ state.ctm.b = 0;
+ state.ctm.c = 0;
+ state.ctm.d = 1; /*(float) viewport_height / (float) height;*/
+ state.ctm.e = 0; /*x;*/
+ state.ctm.f = 0; /*y;*/
+ /*state.style = css_base_style;
+ state.style.font_size.value.length.value = option_font_size * 0.1;*/
+ state.fill = 0x000000;
+ state.stroke = svgtiny_TRANSPARENT;
+ state.stroke_width = 1;
+ state.linear_gradient_stop_count = 0;
+
+ /* parse tree */
+ code = svgtiny_parse_svg(svg, state);
+
+ /* free XML tree */
+ xmlFreeDoc(document);
+
+ return code;
+}
+
+
+/**
+ * Parse a <svg> or <g> element node.
+ */
+
+svgtiny_code svgtiny_parse_svg(xmlNode *svg,
+ struct svgtiny_parse_state state)
+{
+ float x, y, width, height;
+ xmlAttr *view_box;
+ xmlNode *child;
+
+ svgtiny_parse_position_attributes(svg, state, &x, &y, &width, &height);
+ svgtiny_parse_paint_attributes(svg, &state);
+ svgtiny_parse_font_attributes(svg, &state);
+
+ /* parse viewBox */
+ view_box = xmlHasProp(svg, (const xmlChar *) "viewBox");
+ if (view_box) {
+ const char *s = (const char *) view_box->children->content;
+ float min_x, min_y, vwidth, vheight;
+ if (sscanf(s, "%f,%f,%f,%f",
+ &min_x, &min_y, &vwidth, &vheight) == 4 ||
+ sscanf(s, "%f %f %f %f",
+ &min_x, &min_y, &vwidth, &vheight) == 4) {
+ state.ctm.a = (float) state.viewport_width / vwidth;
+ state.ctm.d = (float) state.viewport_height / vheight;
+ state.ctm.e += -min_x * state.ctm.a;
+ state.ctm.f += -min_y * state.ctm.d;
+ }
+ }
+
+ svgtiny_parse_transform_attributes(svg, &state);
+
+ for (child = svg->children; child; child = child->next) {
+ svgtiny_code code = svgtiny_OK;
+
+ if (child->type == XML_ELEMENT_NODE) {
+ const char *name = (const char *) child->name;
+ if (strcmp(name, "svg") == 0)
+ code = svgtiny_parse_svg(child, state);
+ else if (strcmp(name, "g") == 0)
+ code = svgtiny_parse_svg(child, state);
+ else if (strcmp(name, "a") == 0)
+ code = svgtiny_parse_svg(child, state);
+ else if (strcmp(name, "path") == 0)
+ code = svgtiny_parse_path(child, state);
+ else if (strcmp(name, "rect") == 0)
+ code = svgtiny_parse_rect(child, state);
+ else if (strcmp(name, "circle") == 0)
+ code = svgtiny_parse_circle(child, state);
+ else if (strcmp(name, "ellipse") == 0)
+ code = svgtiny_parse_ellipse(child, state);
+ else if (strcmp(name, "line") == 0)
+ code = svgtiny_parse_line(child, state);
+ else if (strcmp(name, "polyline") == 0)
+ code = svgtiny_parse_poly(child, state, false);
+ else if (strcmp(name, "polygon") == 0)
+ code = svgtiny_parse_poly(child, state, true);
+ else if (strcmp(name, "text") == 0)
+ code = svgtiny_parse_text(child, state);
+ }
+
+ if (code != svgtiny_OK)
+ return code;
+ }
+
+ return svgtiny_OK;
+}
+
+
+
+/**
+ * Parse a <path> element node.
+ *
+ * http://www.w3.org/TR/SVG11/paths#PathElement
+ */
+
+svgtiny_code svgtiny_parse_path(xmlNode *path,
+ struct svgtiny_parse_state state)
+{
+ char *s, *path_d;
+ float *p;
+ unsigned int i;
+ float last_x = 0, last_y = 0;
+ float last_cubic_x = 0, last_cubic_y = 0;
+ float last_quad_x = 0, last_quad_y = 0;
+
+ svgtiny_parse_paint_attributes(path, &state);
+ svgtiny_parse_transform_attributes(path, &state);
+
+ /* read d attribute */
+ s = path_d = (char *) xmlGetProp(path, (const xmlChar *) "d");
+ if (!s) {
+ state.diagram->error_line = path->line;
+ state.diagram->error_message = "path: missing d attribute";
+ return svgtiny_SVG_ERROR;
+ }
+
+ /* allocate space for path: it will never have more elements than d */
+ p = malloc(sizeof p[0] * strlen(s));
+ if (!p)
+ return svgtiny_OUT_OF_MEMORY;
+
+ /* parse d and build path */
+ for (i = 0; s[i]; i++)
+ if (s[i] == ',')
+ s[i] = ' ';
+ i = 0;
+ while (*s) {
+ char command[2];
+ int plot_command;
+ float x, y, x1, y1, x2, y2, rx, ry, rotation, large_arc, sweep;
+ int n;
+
+ /* moveto (M, m), lineto (L, l) (2 arguments) */
+ if (sscanf(s, " %1[MmLl] %f %f %n", command, &x, &y, &n) == 3) {
+ /*LOG(("moveto or lineto"));*/
+ if (*command == 'M' || *command == 'm')
+ plot_command = svgtiny_PATH_MOVE;
+ else
+ plot_command = svgtiny_PATH_LINE;
+ do {
+ p[i++] = plot_command;
+ if ('a' <= *command) {
+ x += last_x;
+ y += last_y;
+ }
+ p[i++] = last_cubic_x = last_quad_x = last_x
+ = x;
+ p[i++] = last_cubic_y = last_quad_y = last_y
+ = y;
+ s += n;
+ plot_command = svgtiny_PATH_LINE;
+ } while (sscanf(s, "%f %f %n", &x, &y, &n) == 2);
+
+ /* closepath (Z, z) (no arguments) */
+ } else if (sscanf(s, " %1[Zz] %n", command, &n) == 1) {
+ /*LOG(("closepath"));*/
+ p[i++] = svgtiny_PATH_CLOSE;
+ s += n;
+
+ /* horizontal lineto (H, h) (1 argument) */
+ } else if (sscanf(s, " %1[Hh] %f %n", command, &x, &n) == 2) {
+ /*LOG(("horizontal lineto"));*/
+ do {
+ p[i++] = svgtiny_PATH_LINE;
+ if (*command == 'h')
+ x += last_x;
+ p[i++] = last_cubic_x = last_quad_x = last_x
+ = x;
+ p[i++] = last_cubic_y = last_quad_y = last_y;
+ s += n;
+ } while (sscanf(s, "%f %n", &x, &n) == 1);
+
+ /* vertical lineto (V, v) (1 argument) */
+ } else if (sscanf(s, " %1[Vv] %f %n", command, &y, &n) == 2) {
+ /*LOG(("vertical lineto"));*/
+ do {
+ p[i++] = svgtiny_PATH_LINE;
+ if (*command == 'v')
+ y += last_y;
+ p[i++] = last_cubic_x = last_quad_x = last_x;
+ p[i++] = last_cubic_y = last_quad_y = last_y
+ = y;
+ s += n;
+ } while (sscanf(s, "%f %n", &x, &n) == 1);
+
+ /* curveto (C, c) (6 arguments) */
+ } else if (sscanf(s, " %1[Cc] %f %f %f %f %f %f %n", command,
+ &x1, &y1, &x2, &y2, &x, &y, &n) == 7) {
+ /*LOG(("curveto"));*/
+ do {
+ p[i++] = svgtiny_PATH_BEZIER;
+ if (*command == 'c') {
+ x1 += last_x;
+ y1 += last_y;
+ x2 += last_x;
+ y2 += last_y;
+ x += last_x;
+ y += last_y;
+ }
+ p[i++] = x1;
+ p[i++] = y1;
+ p[i++] = last_cubic_x = x2;
+ p[i++] = last_cubic_y = y2;
+ p[i++] = last_quad_x = last_x = x;
+ p[i++] = last_quad_y = last_y = y;
+ s += n;
+ } while (sscanf(s, "%f %f %f %f %f %f %n",
+ &x1, &y1, &x2, &y2, &x, &y, &n) == 6);
+
+ /* shorthand/smooth curveto (S, s) (4 arguments) */
+ } else if (sscanf(s, " %1[Ss] %f %f %f %f %n", command,
+ &x2, &y2, &x, &y, &n) == 5) {
+ /*LOG(("shorthand/smooth curveto"));*/
+ do {
+ p[i++] = svgtiny_PATH_BEZIER;
+ x1 = last_x + (last_x - last_cubic_x);
+ y1 = last_y + (last_y - last_cubic_y);
+ if (*command == 's') {
+ x2 += last_x;
+ y2 += last_y;
+ x += last_x;
+ y += last_y;
+ }
+ p[i++] = x1;
+ p[i++] = y1;
+ p[i++] = last_cubic_x = x2;
+ p[i++] = last_cubic_y = y2;
+ p[i++] = last_quad_x = last_x = x;
+ p[i++] = last_quad_y = last_y = y;
+ s += n;
+ } while (sscanf(s, "%f %f %f %f %n",
+ &x2, &y2, &x, &y, &n) == 4);
+
+ /* quadratic Bezier curveto (Q, q) (4 arguments) */
+ } else if (sscanf(s, " %1[Qq] %f %f %f %f %n", command,
+ &x1, &y1, &x, &y, &n) == 5) {
+ /*LOG(("quadratic Bezier curveto"));*/
+ do {
+ p[i++] = svgtiny_PATH_BEZIER;
+ last_quad_x = x1;
+ last_quad_y = y1;
+ if (*command == 'q') {
+ x1 += last_x;
+ y1 += last_y;
+ x += last_x;
+ y += last_y;
+ }
+ p[i++] = 1./3 * last_x + 2./3 * x1;
+ p[i++] = 1./3 * last_y + 2./3 * y1;
+ p[i++] = 2./3 * x1 + 1./3 * x;
+ p[i++] = 2./3 * y1 + 1./3 * y;
+ p[i++] = last_cubic_x = last_x = x;
+ p[i++] = last_cubic_y = last_y = y;
+ s += n;
+ } while (sscanf(s, "%f %f %f %f %n",
+ &x1, &y1, &x, &y, &n) == 4);
+
+ /* shorthand/smooth quadratic Bezier curveto (T, t)
+ (2 arguments) */
+ } else if (sscanf(s, " %1[Tt] %f %f %n", command,
+ &x, &y, &n) == 3) {
+ /*LOG(("shorthand/smooth quadratic Bezier curveto"));*/
+ do {
+ p[i++] = svgtiny_PATH_BEZIER;
+ x1 = last_x + (last_x - last_quad_x);
+ y1 = last_y + (last_y - last_quad_y);
+ last_quad_x = x1;
+ last_quad_y = y1;
+ if (*command == 't') {
+ x1 += last_x;
+ y1 += last_y;
+ x += last_x;
+ y += last_y;
+ }
+ p[i++] = 1./3 * last_x + 2./3 * x1;
+ p[i++] = 1./3 * last_y + 2./3 * y1;
+ p[i++] = 2./3 * x1 + 1./3 * x;
+ p[i++] = 2./3 * y1 + 1./3 * y;
+ p[i++] = last_cubic_x = last_x = x;
+ p[i++] = last_cubic_y = last_y = y;
+ s += n;
+ } while (sscanf(s, "%f %f %n",
+ &x, &y, &n) == 2);
+
+ /* elliptical arc (A, a) (7 arguments) */
+ } else if (sscanf(s, " %1[Aa] %f %f %f %f %f %f %f %n", command,
+ &rx, &ry, &rotation, &large_arc, &sweep,
+ &x, &y, &n) == 8) {
+ do {
+ p[i++] = svgtiny_PATH_LINE;
+ if (*command == 'a') {
+ x += last_x;
+ y += last_y;
+ }
+ p[i++] = last_cubic_x = last_quad_x = last_x
+ = x;
+ p[i++] = last_cubic_y = last_quad_y = last_y
+ = y;
+ s += n;
+ } while (sscanf(s, "%f %f %f %f %f %f %f %n",
+ &rx, &ry, &rotation, &large_arc, &sweep,
+ &x, &y, &n) == 7);
+
+ } else {
+ fprintf(stderr, "parse failed at \"%s\"\n", s);
+ break;
+ }
+ }
+
+ xmlFree(path_d);
+
+ if (i <= 4) {
+ /* no real segments in path */
+ free(p);
+ return svgtiny_OK;
+ }
+
+ return svgtiny_add_path(p, i, &state);
+}
+
+
+/**
+ * Parse a <rect> element node.
+ *
+ * http://www.w3.org/TR/SVG11/shapes#RectElement
+ */
+
+svgtiny_code svgtiny_parse_rect(xmlNode *rect,
+ struct svgtiny_parse_state state)
+{
+ float x, y, width, height;
+ float *p;
+
+ svgtiny_parse_position_attributes(rect, state,
+ &x, &y, &width, &height);
+ svgtiny_parse_paint_attributes(rect, &state);
+ svgtiny_parse_transform_attributes(rect, &state);
+
+ p = malloc(13 * sizeof p[0]);
+ if (!p)
+ return svgtiny_OUT_OF_MEMORY;
+
+ p[0] = svgtiny_PATH_MOVE;
+ p[1] = x;
+ p[2] = y;
+ p[3] = svgtiny_PATH_LINE;
+ p[4] = x + width;
+ p[5] = y;
+ p[6] = svgtiny_PATH_LINE;
+ p[7] = x + width;
+ p[8] = y + height;
+ p[9] = svgtiny_PATH_LINE;
+ p[10] = x;
+ p[11] = y + height;
+ p[12] = svgtiny_PATH_CLOSE;
+
+ return svgtiny_add_path(p, 13, &state);
+}
+
+
+/**
+ * Parse a <circle> element node.
+ */
+
+svgtiny_code svgtiny_parse_circle(xmlNode *circle,
+ struct svgtiny_parse_state state)
+{
+ float x = 0, y = 0, r = -1;
+ float *p;
+ xmlAttr *attr;
+
+ for (attr = circle->properties; attr; attr = attr->next) {
+ const char *name = (const char *) attr->name;
+ const char *content = (const char *) attr->children->content;
+ if (strcmp(name, "cx") == 0)
+ x = svgtiny_parse_length(content,
+ state.viewport_width, state);
+ else if (strcmp(name, "cy") == 0)
+ y = svgtiny_parse_length(content,
+ state.viewport_height, state);
+ else if (strcmp(name, "r") == 0)
+ r = svgtiny_parse_length(content,
+ state.viewport_width, state);
+ }
+ svgtiny_parse_paint_attributes(circle, &state);
+ svgtiny_parse_transform_attributes(circle, &state);
+
+ if (r < 0) {
+ state.diagram->error_line = circle->line;
+ state.diagram->error_message = "circle: r missing or negative";
+ return svgtiny_SVG_ERROR;
+ }
+ if (r == 0)
+ return svgtiny_OK;
+
+ p = malloc(32 * sizeof p[0]);
+ if (!p)
+ return svgtiny_OUT_OF_MEMORY;
+
+ p[0] = svgtiny_PATH_MOVE;
+ p[1] = x + r;
+ p[2] = y;
+ p[3] = svgtiny_PATH_BEZIER;
+ p[4] = x + r;
+ p[5] = y + r * KAPPA;
+ p[6] = x + r * KAPPA;
+ p[7] = y + r;
+ p[8] = x;
+ p[9] = y + r;
+ p[10] = svgtiny_PATH_BEZIER;
+ p[11] = x - r * KAPPA;
+ p[12] = y + r;
+ p[13] = x - r;
+ p[14] = y + r * KAPPA;
+ p[15] = x - r;
+ p[16] = y;
+ p[17] = svgtiny_PATH_BEZIER;
+ p[18] = x - r;
+ p[19] = y - r * KAPPA;
+ p[20] = x - r * KAPPA;
+ p[21] = y - r;
+ p[22] = x;
+ p[23] = y - r;
+ p[24] = svgtiny_PATH_BEZIER;
+ p[25] = x + r * KAPPA;
+ p[26] = y - r;
+ p[27] = x + r;
+ p[28] = y - r * KAPPA;
+ p[29] = x + r;
+ p[30] = y;
+ p[31] = svgtiny_PATH_CLOSE;
+
+ return svgtiny_add_path(p, 32, &state);
+}
+
+
+/**
+ * Parse an <ellipse> element node.
+ */
+
+svgtiny_code svgtiny_parse_ellipse(xmlNode *ellipse,
+ struct svgtiny_parse_state state)
+{
+ float x = 0, y = 0, rx = -1, ry = -1;
+ float *p;
+ xmlAttr *attr;
+
+ for (attr = ellipse->properties; attr; attr = attr->next) {
+ const char *name = (const char *) attr->name;
+ const char *content = (const char *) attr->children->content;
+ if (strcmp(name, "cx") == 0)
+ x = svgtiny_parse_length(content,
+ state.viewport_width, state);
+ else if (strcmp(name, "cy") == 0)
+ y = svgtiny_parse_length(content,
+ state.viewport_height, state);
+ else if (strcmp(name, "rx") == 0)
+ rx = svgtiny_parse_length(content,
+ state.viewport_width, state);
+ else if (strcmp(name, "ry") == 0)
+ ry = svgtiny_parse_length(content,
+ state.viewport_width, state);
+ }
+ svgtiny_parse_paint_attributes(ellipse, &state);
+ svgtiny_parse_transform_attributes(ellipse, &state);
+
+ if (rx < 0 || ry < 0) {
+ state.diagram->error_line = ellipse->line;
+ state.diagram->error_message = "ellipse: rx or ry missing "
+ "or negative";
+ return svgtiny_SVG_ERROR;
+ }
+ if (rx == 0 || ry == 0)
+ return svgtiny_OK;
+
+ p = malloc(32 * sizeof p[0]);
+ if (!p)
+ return svgtiny_OUT_OF_MEMORY;
+
+ p[0] = svgtiny_PATH_MOVE;
+ p[1] = x + rx;
+ p[2] = y;
+ p[3] = svgtiny_PATH_BEZIER;
+ p[4] = x + rx;
+ p[5] = y + ry * KAPPA;
+ p[6] = x + rx * KAPPA;
+ p[7] = y + ry;
+ p[8] = x;
+ p[9] = y + ry;
+ p[10] = svgtiny_PATH_BEZIER;
+ p[11] = x - rx * KAPPA;
+ p[12] = y + ry;
+ p[13] = x - rx;
+ p[14] = y + ry * KAPPA;
+ p[15] = x - rx;
+ p[16] = y;
+ p[17] = svgtiny_PATH_BEZIER;
+ p[18] = x - rx;
+ p[19] = y - ry * KAPPA;
+ p[20] = x - rx * KAPPA;
+ p[21] = y - ry;
+ p[22] = x;
+ p[23] = y - ry;
+ p[24] = svgtiny_PATH_BEZIER;
+ p[25] = x + rx * KAPPA;
+ p[26] = y - ry;
+ p[27] = x + rx;
+ p[28] = y - ry * KAPPA;
+ p[29] = x + rx;
+ p[30] = y;
+ p[31] = svgtiny_PATH_CLOSE;
+
+ return svgtiny_add_path(p, 32, &state);
+}
+
+
+/**
+ * Parse a <line> element node.
+ */
+
+svgtiny_code svgtiny_parse_line(xmlNode *line,
+ struct svgtiny_parse_state state)
+{
+ float x1 = 0, y1 = 0, x2 = 0, y2 = 0;
+ float *p;
+ xmlAttr *attr;
+
+ for (attr = line->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)
+ x1 = svgtiny_parse_length(content,
+ state.viewport_width, state);
+ else if (strcmp(name, "y1") == 0)
+ y1 = svgtiny_parse_length(content,
+ state.viewport_height, state);
+ else if (strcmp(name, "x2") == 0)
+ x2 = svgtiny_parse_length(content,
+ state.viewport_width, state);
+ else if (strcmp(name, "y2") == 0)
+ y2 = svgtiny_parse_length(content,
+ state.viewport_height, state);
+ }
+ svgtiny_parse_paint_attributes(line, &state);
+ svgtiny_parse_transform_attributes(line, &state);
+
+ p = malloc(7 * sizeof p[0]);
+ if (!p)
+ return svgtiny_OUT_OF_MEMORY;
+
+ p[0] = svgtiny_PATH_MOVE;
+ p[1] = x1;
+ p[2] = y1;
+ p[3] = svgtiny_PATH_LINE;
+ p[4] = x2;
+ p[5] = y2;
+ p[6] = svgtiny_PATH_CLOSE;
+
+ return svgtiny_add_path(p, 7, &state);
+}
+
+
+/**
+ * Parse a <polyline> or <polygon> element node.
+ *
+ * http://www.w3.org/TR/SVG11/shapes#PolylineElement
+ * http://www.w3.org/TR/SVG11/shapes#PolygonElement
+ */
+
+svgtiny_code svgtiny_parse_poly(xmlNode *poly,
+ struct svgtiny_parse_state state, bool polygon)
+{
+ char *s, *points;
+ float *p;
+ unsigned int i;
+
+ svgtiny_parse_paint_attributes(poly, &state);
+ svgtiny_parse_transform_attributes(poly, &state);
+
+ /* read points attribute */
+ s = points = (char *) xmlGetProp(poly, (const xmlChar *) "points");
+ if (!s) {
+ state.diagram->error_line = poly->line;
+ state.diagram->error_message =
+ "polyline/polygon: missing points attribute";
+ return svgtiny_SVG_ERROR;
+ }
+
+ /* allocate space for path: it will never have more elements than s */
+ p = malloc(sizeof p[0] * strlen(s));
+ if (!p) {
+ xmlFree(points);
+ return svgtiny_OUT_OF_MEMORY;
+ }
+
+ /* parse s and build path */
+ for (i = 0; s[i]; i++)
+ if (s[i] == ',')
+ s[i] = ' ';
+ i = 0;
+ while (*s) {
+ float x, y;
+ int n;
+
+ if (sscanf(s, "%f %f %n", &x, &y, &n) == 2) {
+ if (i == 0)
+ p[i++] = svgtiny_PATH_MOVE;
+ else
+ p[i++] = svgtiny_PATH_LINE;
+ p[i++] = x;
+ p[i++] = y;
+ s += n;
+ } else {
+ break;
+ }
+ }
+ if (polygon)
+ p[i++] = svgtiny_PATH_CLOSE;
+
+ xmlFree(points);
+
+ return svgtiny_add_path(p, i, &state);
+}
+
+
+/**
+ * Parse a <text> or <tspan> element node.
+ */
+
+svgtiny_code svgtiny_parse_text(xmlNode *text,
+ struct svgtiny_parse_state state)
+{
+ float x, y, width, height;
+ float px, py;
+ xmlNode *child;
+
+ svgtiny_parse_position_attributes(text, state,
+ &x, &y, &width, &height);
+ svgtiny_parse_font_attributes(text, &state);
+ svgtiny_parse_transform_attributes(text, &state);
+
+ px = state.ctm.a * x + state.ctm.c * y + state.ctm.e;
+ py = state.ctm.b * x + state.ctm.d * y + state.ctm.f;
+/* state.ctm.e = px - state.origin_x; */
+/* state.ctm.f = py - state.origin_y; */
+
+ /*struct css_style style = state.style;
+ style.font_size.value.length.value *= state.ctm.a;*/
+
+ for (child = text->children; child; child = child->next) {
+ svgtiny_code code = svgtiny_OK;
+
+ if (child->type == XML_TEXT_NODE) {
+ struct svgtiny_shape *shape = svgtiny_add_shape(&state);
+ if (!shape)
+ return svgtiny_OUT_OF_MEMORY;
+ shape->text = strdup((const char *) child->content);
+ shape->text_x = px;
+ shape->text_y = py;
+ state.diagram->shape_count++;
+
+ } else if (child->type == XML_ELEMENT_NODE &&
+ strcmp((const char *) child->name,
+ "tspan") == 0) {
+ code = svgtiny_parse_text(child, state);
+ }
+
+ if (!code != svgtiny_OK)
+ return code;
+ }
+
+ return svgtiny_OK;
+}
+
+
+/**
+ * Parse x, y, width, and height attributes, if present.
+ */
+
+void svgtiny_parse_position_attributes(const xmlNode *node,
+ const struct svgtiny_parse_state state,
+ float *x, float *y, float *width, float *height)
+{
+ xmlAttr *attr;
+
+ *x = 0;
+ *y = 0;
+ *width = state.viewport_width;
+ *height = state.viewport_height;
+
+ for (attr = node->properties; attr; attr = attr->next) {
+ const char *name = (const char *) attr->name;
+ const char *content = (const char *) attr->children->content;
+ if (strcmp(name, "x") == 0)
+ *x = svgtiny_parse_length(content,
+ state.viewport_width, state);
+ else if (strcmp(name, "y") == 0)
+ *y = svgtiny_parse_length(content,
+ state.viewport_height, state);
+ else if (strcmp(name, "width") == 0)
+ *width = svgtiny_parse_length(content,
+ state.viewport_width, state);
+ else if (strcmp(name, "height") == 0)
+ *height = svgtiny_parse_length(content,
+ state.viewport_height, state);
+ }
+}
+
+
+/**
+ * Parse a length as a number of pixels.
+ */
+
+float svgtiny_parse_length(const char *s, int viewport_size,
+ const struct svgtiny_parse_state state)
+{
+ int num_length = strspn(s, "0123456789+-.");
+ const char *unit = s + num_length;
+ float n = atof((const char *) s);
+ float font_size = 20; /*css_len2px(&state.style.font_size.value.length, 0);*/
+
+ UNUSED(state);
+
+ if (unit[0] == 0) {
+ return n;
+ } else if (unit[0] == '%') {
+ return n / 100.0 * viewport_size;
+ } else if (unit[0] == 'e' && unit[1] == 'm') {
+ return n * font_size;
+ } else if (unit[0] == 'e' && unit[1] == 'x') {
+ return n / 2.0 * font_size;
+ } else if (unit[0] == 'p' && unit[1] == 'x') {
+ return n;
+ } else if (unit[0] == 'p' && unit[1] == 't') {
+ return n * 1.25;
+ } else if (unit[0] == 'p' && unit[1] == 'c') {
+ return n * 15.0;
+ } else if (unit[0] == 'm' && unit[1] == 'm') {
+ return n * 3.543307;
+ } else if (unit[0] == 'c' && unit[1] == 'm') {
+ return n * 35.43307;
+ } else if (unit[0] == 'i' && unit[1] == 'n') {
+ return n * 90;
+ }
+
+ return 0;
+}
+
+
+/**
+ * Parse paint attributes, if present.
+ */
+
+void svgtiny_parse_paint_attributes(const xmlNode *node,
+ struct svgtiny_parse_state *state)
+{
+ const xmlAttr *attr;
+
+ for (attr = node->properties; attr; attr = attr->next) {
+ const char *name = (const char *) attr->name;
+ const char *content = (const char *) attr->children->content;
+ if (strcmp(name, "fill") == 0)
+ svgtiny_parse_color(content, &state->fill, state);
+ else if (strcmp(name, "stroke") == 0)
+ svgtiny_parse_color(content, &state->stroke, state);
+ else if (strcmp(name, "stroke-width") == 0)
+ state->stroke_width = svgtiny_parse_length(content,
+ state->viewport_width, *state);
+ else if (strcmp(name, "style") == 0) {
+ const char *style = (const char *)
+ attr->children->content;
+ const char *s;
+ char *value;
+ if ((s = strstr(style, "fill:"))) {
+ s += 5;
+ while (*s == ' ')
+ s++;
+ value = strndup(s, strcspn(s, "; "));
+ svgtiny_parse_color(value, &state->fill, state);
+ free(value);
+ }
+ if ((s = strstr(style, "stroke:"))) {
+ s += 7;
+ while (*s == ' ')
+ s++;
+ value = strndup(s, strcspn(s, "; "));
+ svgtiny_parse_color(value, &state->stroke, state);
+ free(value);
+ }
+ if ((s = strstr(style, "stroke-width:"))) {
+ s += 13;
+ while (*s == ' ')
+ s++;
+ value = strndup(s, strcspn(s, "; "));
+ state->stroke_width = svgtiny_parse_length(value,
+ state->viewport_width, *state);
+ free(value);
+ }
+ }
+ }
+}
+
+
+/**
+ * Parse a colour.
+ */
+
+void svgtiny_parse_color(const char *s, svgtiny_colour *c,
+ struct svgtiny_parse_state *state)
+{
+ unsigned int r, g, b;
+ float rf, gf, bf;
+ size_t len = strlen(s);
+ char *id = 0, *rparen;
+
+ if (len == 4 && s[0] == '#') {
+ if (sscanf(s + 1, "%1x%1x%1x", &r, &g, &b) == 3)
+ *c = svgtiny_RGB(r | r << 4, g | g << 4, b | b << 4);
+
+ } else if (len == 7 && s[0] == '#') {
+ if (sscanf(s + 1, "%2x%2x%2x", &r, &g, &b) == 3)
+ *c = svgtiny_RGB(r, g, b);
+
+ } else if (10 <= len && s[0] == 'r' && s[1] == 'g' && s[2] == 'b' &&
+ s[3] == '(' && s[len - 1] == ')') {
+ if (sscanf(s + 4, "%u,%u,%u", &r, &g, &b) == 3)
+ *c = svgtiny_RGB(r, g, b);
+ else if (sscanf(s + 4, "%f%%,%f%%,%f%%", &rf, &gf, &bf) == 3) {
+ b = bf * 255 / 100;
+ g = gf * 255 / 100;
+ r = rf * 255 / 100;
+ *c = svgtiny_RGB(r, g, b);
+ }
+
+ } else if (len == 4 && strcmp(s, "none") == 0) {
+ *c = svgtiny_TRANSPARENT;
+
+ } else if (5 < len && s[0] == 'u' && s[1] == 'r' && s[2] == 'l' &&
+ s[3] == '(') {
+ if (s[4] == '#') {
+ id = strdup(s + 5);
+ if (!id)
+ return;
+ rparen = strchr(id, ')');
+ if (rparen)
+ *rparen = 0;
+ svgtiny_find_gradient(id, state);
+ free(id);
+ fprintf(stderr, "linear_gradient_stop_count %i\n",
+ state->linear_gradient_stop_count);
+ if (state->linear_gradient_stop_count == 0)
+ *c = svgtiny_TRANSPARENT;
+ else if (state->linear_gradient_stop_count == 1)
+ *c = state->gradient_stop[0].color;
+ else
+ *c = svgtiny_LINEAR_GRADIENT;
+ }
+
+ } else {
+ const struct svgtiny_named_color *named_color;
+ named_color = svgtiny_color_lookup(s, strlen(s));
+ if (named_color)
+ *c = named_color->color;
+ }
+}
+
+
+/**
+ * Parse font attributes, if present.
+ */
+
+void svgtiny_parse_font_attributes(const xmlNode *node,
+ struct svgtiny_parse_state *state)
+{
+ const xmlAttr *attr;
+
+ UNUSED(state);
+
+ for (attr = node->properties; attr; attr = attr->next) {
+ if (strcmp((const char *) attr->name, "font-size") == 0) {
+ /*if (css_parse_length(
+ (const char *) attr->children->content,
+ &state->style.font_size.value.length,
+ true, true)) {
+ state->style.font_size.size =
+ CSS_FONT_SIZE_LENGTH;
+ }*/
+ }
+ }
+}
+
+
+/**
+ * Parse transform attributes, if present.
+ *
+ * http://www.w3.org/TR/SVG11/coords#TransformAttribute
+ */
+
+void svgtiny_parse_transform_attributes(xmlNode *node,
+ struct svgtiny_parse_state *state)
+{
+ char *transform;
+
+ /* parse transform */
+ transform = (char *) xmlGetProp(node, (const xmlChar *) "transform");
+ if (transform) {
+ svgtiny_parse_transform(transform, &state->ctm.a, &state->ctm.b,
+ &state->ctm.c, &state->ctm.d,
+ &state->ctm.e, &state->ctm.f);
+ xmlFree(transform);
+ }
+}
+
+
+/**
+ * Parse a transform string.
+ */
+
+void svgtiny_parse_transform(char *s, float *ma, float *mb,
+ float *mc, float *md, float *me, float *mf)
+{
+ float a, b, c, d, e, f;
+ float za, zb, zc, zd, ze, zf;
+ float angle, x, y;
+ int n;
+ unsigned int i;
+
+ for (i = 0; s[i]; i++)
+ if (s[i] == ',')
+ s[i] = ' ';
+
+ while (*s) {
+ a = d = 1;
+ b = c = 0;
+ e = f = 0;
+ if (sscanf(s, "matrix (%f %f %f %f %f %f) %n",
+ &a, &b, &c, &d, &e, &f, &n) == 6)
+ ;
+ else if (sscanf(s, "translate (%f %f) %n",
+ &e, &f, &n) == 2)
+ ;
+ else if (sscanf(s, "translate (%f) %n",
+ &e, &n) == 1)
+ ;
+ else if (sscanf(s, "scale (%f %f) %n",
+ &a, &d, &n) == 2)
+ ;
+ else if (sscanf(s, "scale (%f) %n",
+ &a, &n) == 1)
+ d = a;
+ else if (sscanf(s, "rotate (%f %f %f) %n",
+ &angle, &x, &y, &n) == 3) {
+ angle = angle / 180 * M_PI;
+ a = cos(angle);
+ b = sin(angle);
+ c = -sin(angle);
+ d = cos(angle);
+ e = -x * cos(angle) + y * sin(angle) + x;
+ f = -x * sin(angle) - y * cos(angle) + y;
+ } else if (sscanf(s, "rotate (%f) %n",
+ &angle, &n) == 1) {
+ angle = angle / 180 * M_PI;
+ a = cos(angle);
+ b = sin(angle);
+ c = -sin(angle);
+ d = cos(angle);
+ } else if (sscanf(s, "skewX (%f) %n",
+ &angle, &n) == 1) {
+ angle = angle / 180 * M_PI;
+ c = tan(angle);
+ } else if (sscanf(s, "skewY (%f) %n",
+ &angle, &n) == 1) {
+ angle = angle / 180 * M_PI;
+ b = tan(angle);
+ } else
+ break;
+ za = *ma * a + *mc * b;
+ zb = *mb * a + *md * b;
+ zc = *ma * c + *mc * d;
+ zd = *mb * c + *md * d;
+ ze = *ma * e + *mc * f + *me;
+ zf = *mb * e + *md * f + *mf;
+ *ma = za;
+ *mb = zb;
+ *mc = zc;
+ *md = zd;
+ *me = ze;
+ *mf = zf;
+ s += n;
+ }
+}
+
+
+/**
+ * Add a path to the svgtiny_diagram.
+ */
+
+svgtiny_code svgtiny_add_path(float *p, unsigned int n,
+ struct svgtiny_parse_state *state)
+{
+ struct svgtiny_shape *shape;
+
+ if (state->fill == svgtiny_LINEAR_GRADIENT)
+ return svgtiny_add_path_linear_gradient(p, n, state);
+
+ svgtiny_transform_path(p, n, state);
+
+ shape = svgtiny_add_shape(state);
+ if (!shape) {
+ free(p);
+ return svgtiny_OUT_OF_MEMORY;
+ }
+ shape->path = p;
+ shape->path_length = n;
+ state->diagram->shape_count++;
+
+ return svgtiny_OK;
+}
+
+
+/**
+ * Add a svgtiny_shape to the svgtiny_diagram.
+ */
+
+struct svgtiny_shape *svgtiny_add_shape(struct svgtiny_parse_state *state)
+{
+ struct svgtiny_shape *shape = realloc(state->diagram->shape,
+ (state->diagram->shape_count + 1) *
+ sizeof (state->diagram->shape[0]));
+ if (!shape)
+ return 0;
+ state->diagram->shape = shape;
+
+ shape += state->diagram->shape_count;
+ shape->path = 0;
+ shape->path_length = 0;
+ shape->text = 0;
+ shape->fill = state->fill;
+ shape->stroke = state->stroke;
+ shape->stroke_width = lroundf((float) state->stroke_width *
+ (state->ctm.a + state->ctm.d) / 2.0);
+ if (0 < state->stroke_width && shape->stroke_width == 0)
+ shape->stroke_width = 1;
+
+ return shape;
+}
+
+
+/**
+ * Apply the current transformation matrix to a path.
+ */
+
+void svgtiny_transform_path(float *p, unsigned int n,
+ struct svgtiny_parse_state *state)
+{
+ unsigned int j;
+
+ for (j = 0; j != n; ) {
+ unsigned int points = 0;
+ unsigned int k;
+ switch ((int) p[j]) {
+ case svgtiny_PATH_MOVE:
+ case svgtiny_PATH_LINE:
+ points = 1;
+ break;
+ case svgtiny_PATH_CLOSE:
+ points = 0;
+ break;
+ case svgtiny_PATH_BEZIER:
+ points = 3;
+ break;
+ default:
+ assert(0);
+ }
+ j++;
+ for (k = 0; k != points; k++) {
+ float x0 = p[j], y0 = p[j + 1];
+ float x = state->ctm.a * x0 + state->ctm.c * y0 +
+ state->ctm.e;
+ float y = state->ctm.b * x0 + state->ctm.d * y0 +
+ state->ctm.f;
+ p[j] = x;
+ p[j + 1] = y;
+ j += 2;
+ }
+ }
+}
+
+
+/**
+ * Free all memory used by a diagram.
+ */
+
+void svgtiny_free(struct svgtiny_diagram *svg)
+{
+ unsigned int i;
+ assert(svg);
+
+ for (i = 0; i != svg->shape_count; i++) {
+ free(svg->shape[i].path);
+ free(svg->shape[i].text);
+ }
+
+ free(svg->shape);
+
+ free(svg);
+}
+
+#ifndef HAVE_STRNDUP
+char *svgtiny_strndup(const char *s, size_t n)
+{
+ size_t len;
+ char *s2;
+
+ for (len = 0; len != n && s[len]; len++)
+ continue;
+
+ s2 = malloc(len + 1);
+ if (s2 == NULL)
+ return NULL;
+
+ memcpy(s2, s, len);
+ s2[len] = '\0';
+
+ return s2;
+}
+#endif
+
diff --git a/liveengineUnmapped/ofxSVGTiny/libs/svgtiny.h b/liveengineUnmapped/ofxSVGTiny/libs/svgtiny.h
new file mode 100644
index 0000000..9d685e9
--- /dev/null
+++ b/liveengineUnmapped/ofxSVGTiny/libs/svgtiny.h
@@ -0,0 +1,74 @@
+/*
+ * This file is part of Libsvgtiny
+ * Licensed under the MIT License,
+ * http://opensource.org/licenses/mit-license.php
+ * Copyright 2008 James Bursa <james@semichrome.net>
+ */
+
+#ifndef SVGTINY_H
+#define SVGTINY_H
+
+#include <libxml/parser.h>
+
+typedef int svgtiny_colour;
+#define svgtiny_TRANSPARENT 0x1000000
+#ifdef __riscos__
+#define svgtiny_RGB(r, g, b) ((b) << 16 | (g) << 8 | (r))
+#define svgtiny_RED(c) ((c) & 0xff)
+#define svgtiny_GREEN(c) (((c) >> 8) & 0xff)
+#define svgtiny_BLUE(c) (((c) >> 16) & 0xff)
+#else
+#define svgtiny_RGB(r, g, b) ((r) << 16 | (g) << 8 | (b))
+#define svgtiny_RED(c) (((c) >> 16) & 0xff)
+#define svgtiny_GREEN(c) (((c) >> 8) & 0xff)
+#define svgtiny_BLUE(c) ((c) & 0xff)
+#endif
+
+struct svgtiny_shape {
+ float *path;
+ unsigned int path_length;
+ char *text;
+ float text_x, text_y;
+ svgtiny_colour fill;
+ svgtiny_colour stroke;
+ int stroke_width;
+};
+
+struct svgtiny_diagram {
+ int width, height;
+
+ struct svgtiny_shape *shape;
+ unsigned int shape_count;
+
+ unsigned short error_line;
+ const char *error_message;
+};
+
+typedef enum {
+ svgtiny_OK,
+ svgtiny_OUT_OF_MEMORY,
+ svgtiny_LIBXML_ERROR,
+ svgtiny_NOT_SVG,
+ svgtiny_SVG_ERROR
+} svgtiny_code;
+
+enum {
+ svgtiny_PATH_MOVE,
+ svgtiny_PATH_CLOSE,
+ svgtiny_PATH_LINE,
+ svgtiny_PATH_BEZIER
+};
+
+struct svgtiny_named_color {
+ const char *name;
+ svgtiny_colour color;
+};
+
+
+struct svgtiny_diagram *svgtiny_create(void);
+svgtiny_code svgtiny_parse(struct svgtiny_diagram *diagram,
+ const char *buffer, size_t size, const char *url,
+ int width, int height);
+void svgtiny_free(struct svgtiny_diagram *svg);
+
+#endif
diff --git a/liveengineUnmapped/ofxSVGTiny/libs/svgtiny_gradient.c b/liveengineUnmapped/ofxSVGTiny/libs/svgtiny_gradient.c
new file mode 100644
index 0000000..3a8db73
--- /dev/null
+++ b/liveengineUnmapped/ofxSVGTiny/libs/svgtiny_gradient.c
@@ -0,0 +1,670 @@
+/*
+ * This file is part of Libsvgtiny
+ * Licensed under the MIT License,
+ * http://opensource.org/licenses/mit-license.php
+ * Copyright 2008 James Bursa <james@semichrome.net>
+ */
+
+#include <assert.h>
+#include <math.h>
+#include <string.h>
+#include "svgtiny.h"
+#include "svgtiny_internal.h"
+
+#undef GRADIENT_DEBUG
+
+static svgtiny_code svgtiny_parse_linear_gradient(xmlNode *linear,
+ struct svgtiny_parse_state *state);
+static float svgtiny_parse_gradient_offset(const char *s);
+static void svgtiny_path_bbox(float *p, unsigned int n,
+ float *x0, float *y0, float *x1, float *y1);
+static void svgtiny_invert_matrix(float *m, float *inv);
+
+
+/**
+ * Find a gradient by id and parse it.
+ */
+
+void svgtiny_find_gradient(const char *id, struct svgtiny_parse_state *state)
+{
+ xmlNode *gradient;
+
+ 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%";
+ state->gradient_user_space_on_use = false;
+ state->gradient_transform.a = 1;
+ state->gradient_transform.b = 0;
+ state->gradient_transform.c = 0;
+ state->gradient_transform.d = 1;
+ state->gradient_transform.e = 0;
+ state->gradient_transform.f = 0;
+
+ gradient = svgtiny_find_element_by_id(
+ (xmlNode *) state->document, id);
+ fprintf(stderr, "gradient %p\n", (void *) gradient);
+ if (!gradient) {
+ fprintf(stderr, "gradient \"%s\" not found\n", id);
+ return;
+ }
+
+ fprintf(stderr, "gradient name \"%s\"\n", gradient->name);
+ if (strcmp((const char *) gradient->name, "linearGradient") == 0) {
+ svgtiny_parse_linear_gradient(gradient, state);
+ }
+}
+
+
+/**
+ * Parse a <linearGradient> element node.
+ *
+ * http://www.w3.org/TR/SVG11/pservers#LinearGradients
+ */
+
+svgtiny_code svgtiny_parse_linear_gradient(xmlNode *linear,
+ struct svgtiny_parse_state *state)
+{
+ unsigned int i = 0;
+ xmlNode *stop;
+ xmlAttr *attr;
+ xmlAttr *href = xmlHasProp(linear, (const xmlChar *) "href");
+ if (href && href->children->content[0] == '#')
+ svgtiny_find_gradient((const char *) href->children->content
+ + 1, state);
+
+ for (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;
+ else if (strcmp(name, "gradientUnits") == 0)
+ state->gradient_user_space_on_use =
+ strcmp(content, "userSpaceOnUse") == 0;
+ else if (strcmp(name, "gradientTransform") == 0) {
+ float a = 1, b = 0, c = 0, d = 1, e = 0, f = 0;
+ char *s = strdup(content);
+ if (!s)
+ return svgtiny_OUT_OF_MEMORY;
+ svgtiny_parse_transform(s, &a, &b, &c, &d, &e, &f);
+ free(s);
+ fprintf(stderr, "transform %g %g %g %g %g %g\n",
+ a, b, c, d, e, f);
+ state->gradient_transform.a = a;
+ state->gradient_transform.b = b;
+ state->gradient_transform.c = c;
+ state->gradient_transform.d = d;
+ state->gradient_transform.e = e;
+ state->gradient_transform.f = f;
+ }
+ }
+
+ for (stop = linear->children; stop; stop = stop->next) {
+ float offset = -1;
+ svgtiny_colour color = svgtiny_TRANSPARENT;
+
+ if (stop->type != XML_ELEMENT_NODE)
+ continue;
+ if (strcmp((const char *) stop->name, "stop") != 0)
+ continue;
+
+ for (attr = stop->properties; attr;
+ attr = attr->next) {
+ const char *name = (const char *) attr->name;
+ const char *content =
+ (const char *) attr->children->content;
+ if (strcmp(name, "offset") == 0)
+ offset = svgtiny_parse_gradient_offset(content);
+ else if (strcmp(name, "stop-color") == 0)
+ svgtiny_parse_color(content, &color, state);
+ else if (strcmp(name, "style") == 0) {
+ const char *s;
+ char *value;
+ if ((s = strstr(content, "stop-color:"))) {
+ s += 11;
+ while (*s == ' ')
+ s++;
+ value = strndup(s, strcspn(s, "; "));
+ svgtiny_parse_color(value, &color,
+ state);
+ free(value);
+ }
+ }
+ }
+
+ if (offset != -1 && color != svgtiny_TRANSPARENT) {
+ fprintf(stderr, "stop %g %x\n", offset, color);
+ state->gradient_stop[i].offset = offset;
+ state->gradient_stop[i].color = color;
+ i++;
+ }
+
+ if (i == svgtiny_MAX_STOPS)
+ break;
+ }
+
+ if (i)
+ state->linear_gradient_stop_count = i;
+
+ return svgtiny_OK;
+}
+
+
+float svgtiny_parse_gradient_offset(const char *s)
+{
+ int num_length = strspn(s, "0123456789+-.");
+ const char *unit = s + num_length;
+ float n = atof((const char *) s);
+
+ if (unit[0] == 0)
+ ;
+ else if (unit[0] == '%')
+ n /= 100.0;
+ else
+ return -1;
+
+ if (n < 0)
+ n = 0;
+ if (1 < n)
+ n = 1;
+ return n;
+}
+
+
+/**
+ * Add a path with a linear gradient fill to the svgtiny_diagram.
+ */
+
+svgtiny_code svgtiny_add_path_linear_gradient(float *p, unsigned int n,
+ struct svgtiny_parse_state *state)
+{
+ struct grad_point {
+ float x, y, r;
+ };
+ float object_x0, object_y0, object_x1, object_y1;
+ float gradient_x0, gradient_y0, gradient_x1, gradient_y1,
+ gradient_dx, gradient_dy;
+ float trans[6];
+ unsigned int steps = 10;
+ float x0 = 0, y0 = 0, x0_trans, y0_trans, r0; /* segment start point */
+ float x1, y1, x1_trans, y1_trans, r1; /* segment end point */
+ /* segment control points (beziers only) */
+ float c0x = 0, c0y = 0, c1x = 0, c1y = 0;
+ float gradient_norm_squared;
+ struct svgtiny_list *pts;
+ float min_r = 1000;
+ unsigned int min_pt = 0;
+ unsigned int j;
+ unsigned int stop_count;
+ unsigned int current_stop;
+ float last_stop_r;
+ float current_stop_r;
+ int red0, green0, blue0, red1, green1, blue1;
+ unsigned int t, a, b;
+
+ /* determine object bounding box */
+ svgtiny_path_bbox(p, n, &object_x0, &object_y0, &object_x1, &object_y1);
+ #ifdef GRADIENT_DEBUG
+ fprintf(stderr, "object bbox: (%g %g) (%g %g)\n",
+ object_x0, object_y0, object_x1, object_y1);
+ #endif
+
+ /* compute gradient vector */
+ fprintf(stderr, "x1 %s, y1 %s, x2 %s, y2 %s\n",
+ state->gradient_x1, state->gradient_y1,
+ state->gradient_x2, state->gradient_y2);
+ if (!state->gradient_user_space_on_use) {
+ 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);
+ } else {
+ gradient_x0 = svgtiny_parse_length(state->gradient_x1,
+ state->viewport_width, *state);
+ gradient_y0 = svgtiny_parse_length(state->gradient_y1,
+ state->viewport_height, *state);
+ gradient_x1 = svgtiny_parse_length(state->gradient_x2,
+ state->viewport_width, *state);
+ gradient_y1 = svgtiny_parse_length(state->gradient_y2,
+ state->viewport_height, *state);
+ }
+ gradient_dx = gradient_x1 - gradient_x0;
+ gradient_dy = gradient_y1 - gradient_y0;
+ #ifdef GRADIENT_DEBUG
+ fprintf(stderr, "gradient vector: (%g %g) => (%g %g)\n",
+ gradient_x0, gradient_y0, gradient_x1, gradient_y1);
+ #endif
+
+ /* show theoretical gradient strips for debugging */
+ /*unsigned int strips = 10;
+ for (unsigned int z = 0; z != strips; z++) {
+ float f0, fd, strip_x0, strip_y0, strip_dx, strip_dy;
+ f0 = (float) z / (float) strips;
+ fd = (float) 1 / (float) strips;
+ strip_x0 = gradient_x0 + f0 * gradient_dx;
+ strip_y0 = gradient_y0 + f0 * gradient_dy;
+ strip_dx = fd * gradient_dx;
+ strip_dy = fd * gradient_dy;
+ fprintf(stderr, "strip %i vector: (%g %g) + (%g %g)\n",
+ z, strip_x0, strip_y0, strip_dx, strip_dy);
+
+ float *p = malloc(13 * sizeof p[0]);
+ if (!p)
+ return svgtiny_OUT_OF_MEMORY;
+ p[0] = svgtiny_PATH_MOVE;
+ p[1] = strip_x0 + (strip_dy * 3);
+ p[2] = strip_y0 - (strip_dx * 3);
+ p[3] = svgtiny_PATH_LINE;
+ p[4] = p[1] + strip_dx;
+ p[5] = p[2] + strip_dy;
+ p[6] = svgtiny_PATH_LINE;
+ p[7] = p[4] - (strip_dy * 6);
+ p[8] = p[5] + (strip_dx * 6);
+ p[9] = svgtiny_PATH_LINE;
+ p[10] = p[7] - strip_dx;
+ p[11] = p[8] - strip_dy;
+ p[12] = svgtiny_PATH_CLOSE;
+ svgtiny_transform_path(p, 13, state);
+ struct svgtiny_shape *shape = svgtiny_add_shape(state);
+ if (!shape) {
+ free(p);
+ return svgtiny_OUT_OF_MEMORY;
+ }
+ shape->path = p;
+ shape->path_length = 13;
+ shape->fill = svgtiny_TRANSPARENT;
+ shape->stroke = svgtiny_RGB(0, 0xff, 0);
+ state->diagram->shape_count++;
+ }*/
+
+ /* invert gradient transform for applying to vertices */
+ svgtiny_invert_matrix(&state->gradient_transform.a, trans);
+ fprintf(stderr, "inverse transform %g %g %g %g %g %g\n",
+ trans[0], trans[1], trans[2], trans[3],
+ trans[4], trans[5]);
+
+ /* compute points on the path for triangle vertices */
+ /* r, r0, r1 are distance along gradient vector */
+ gradient_norm_squared = gradient_dx * gradient_dx +
+ gradient_dy * gradient_dy;
+ pts = svgtiny_list_create(
+ sizeof (struct grad_point));
+ if (!pts)
+ return svgtiny_OUT_OF_MEMORY;
+ for (j = 0; j != n; ) {
+ int segment_type = (int) p[j];
+ struct grad_point *point;
+ unsigned int z;
+
+ if (segment_type == svgtiny_PATH_MOVE) {
+ x0 = p[j + 1];
+ y0 = p[j + 2];
+ j += 3;
+ continue;
+ }
+
+ assert(segment_type == svgtiny_PATH_CLOSE ||
+ segment_type == svgtiny_PATH_LINE ||
+ segment_type == svgtiny_PATH_BEZIER);
+
+ /* start point (x0, y0) */
+ x0_trans = trans[0]*x0 + trans[2]*y0 + trans[4];
+ y0_trans = trans[1]*x0 + trans[3]*y0 + trans[5];
+ r0 = ((x0_trans - gradient_x0) * gradient_dx +
+ (y0_trans - gradient_y0) * gradient_dy) /
+ gradient_norm_squared;
+ point = svgtiny_list_push(pts);
+ if (!point) {
+ svgtiny_list_free(pts);
+ return svgtiny_OUT_OF_MEMORY;
+ }
+ point->x = x0;
+ point->y = y0;
+ point->r = r0;
+ if (r0 < min_r) {
+ min_r = r0;
+ min_pt = svgtiny_list_size(pts) - 1;
+ }
+
+ /* end point (x1, y1) */
+ if (segment_type == svgtiny_PATH_LINE) {
+ x1 = p[j + 1];
+ y1 = p[j + 2];
+ j += 3;
+ } else if (segment_type == svgtiny_PATH_CLOSE) {
+ x1 = p[1];
+ y1 = p[2];
+ j++;
+ } else /* svgtiny_PATH_BEZIER */ {
+ c0x = p[j + 1];
+ c0y = p[j + 2];
+ c1x = p[j + 3];
+ c1y = p[j + 4];
+ x1 = p[j + 5];
+ y1 = p[j + 6];
+ j += 7;
+ }
+ x1_trans = trans[0]*x1 + trans[2]*y1 + trans[4];
+ y1_trans = trans[1]*x1 + trans[3]*y1 + trans[5];
+ r1 = ((x1_trans - gradient_x0) * gradient_dx +
+ (y1_trans - gradient_y0) * gradient_dy) /
+ gradient_norm_squared;
+
+ /* determine steps from change in r */
+ steps = ceilf(fabsf(r1 - r0) / 0.05);
+ if (steps == 0)
+ steps = 1;
+ fprintf(stderr, "r0 %g, r1 %g, steps %i\n",
+ r0, r1, steps);
+
+ /* loop through intermediate points */
+ for (z = 1; z != steps; z++) {
+ float t, x, y, x_trans, y_trans, r;
+ struct grad_point *point;
+ t = (float) z / (float) steps;
+ if (segment_type == svgtiny_PATH_BEZIER) {
+ x = (1-t) * (1-t) * (1-t) * x0 +
+ 3 * t * (1-t) * (1-t) * c0x +
+ 3 * t * t * (1-t) * c1x +
+ t * t * t * x1;
+ y = (1-t) * (1-t) * (1-t) * y0 +
+ 3 * t * (1-t) * (1-t) * c0y +
+ 3 * t * t * (1-t) * c1y +
+ t * t * t * y1;
+ } else {
+ x = (1-t) * x0 + t * x1;
+ y = (1-t) * y0 + t * y1;
+ }
+ x_trans = trans[0]*x + trans[2]*y + trans[4];
+ y_trans = trans[1]*x + trans[3]*y + trans[5];
+ r = ((x_trans - gradient_x0) * gradient_dx +
+ (y_trans - gradient_y0) * gradient_dy) /
+ gradient_norm_squared;
+ fprintf(stderr, "(%g %g [%g]) ", x, y, r);
+ point = svgtiny_list_push(pts);
+ if (!point) {
+ svgtiny_list_free(pts);
+ return svgtiny_OUT_OF_MEMORY;
+ }
+ point->x = x;
+ point->y = y;
+ point->r = r;
+ if (r < min_r) {
+ min_r = r;
+ min_pt = svgtiny_list_size(pts) - 1;
+ }
+ }
+ fprintf(stderr, "\n");
+
+ /* next segment start point is this segment end point */
+ x0 = x1;
+ y0 = y1;
+ }
+ fprintf(stderr, "pts size %i, min_pt %i, min_r %.3f\n",
+ svgtiny_list_size(pts), min_pt, min_r);
+
+ /* render triangles */
+ stop_count = state->linear_gradient_stop_count;
+ assert(2 <= stop_count);
+ current_stop = 0;
+ last_stop_r = 0;
+ current_stop_r = state->gradient_stop[0].offset;
+ red0 = red1 = svgtiny_RED(state->gradient_stop[0].color);
+ green0 = green1 = svgtiny_GREEN(state->gradient_stop[0].color);
+ blue0 = blue1 = svgtiny_BLUE(state->gradient_stop[0].color);
+ t = min_pt;
+ a = (min_pt + 1) % svgtiny_list_size(pts);
+ b = min_pt == 0 ? svgtiny_list_size(pts) - 1 : min_pt - 1;
+ while (a != b) {
+ struct grad_point *point_t = svgtiny_list_get(pts, t);
+ struct grad_point *point_a = svgtiny_list_get(pts, a);
+ struct grad_point *point_b = svgtiny_list_get(pts, b);
+ float mean_r = (point_t->r + point_a->r + point_b->r) / 3;
+ float *p;
+ struct svgtiny_shape *shape;
+ /*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);*/
+ while (current_stop != stop_count && current_stop_r < mean_r) {
+ current_stop++;
+ if (current_stop == stop_count)
+ break;
+ red0 = red1;
+ green0 = green1;
+ blue0 = blue1;
+ red1 = svgtiny_RED(state->
+ gradient_stop[current_stop].color);
+ green1 = svgtiny_GREEN(state->
+ gradient_stop[current_stop].color);
+ blue1 = svgtiny_BLUE(state->
+ gradient_stop[current_stop].color);
+ last_stop_r = current_stop_r;
+ current_stop_r = state->
+ gradient_stop[current_stop].offset;
+ }
+ p = malloc(10 * sizeof p[0]);
+ if (!p)
+ return svgtiny_OUT_OF_MEMORY;
+ p[0] = svgtiny_PATH_MOVE;
+ p[1] = point_t->x;
+ p[2] = point_t->y;
+ p[3] = svgtiny_PATH_LINE;
+ p[4] = point_a->x;
+ p[5] = point_a->y;
+ p[6] = svgtiny_PATH_LINE;
+ p[7] = point_b->x;
+ p[8] = point_b->y;
+ p[9] = svgtiny_PATH_CLOSE;
+ svgtiny_transform_path(p, 10, state);
+ shape = svgtiny_add_shape(state);
+ if (!shape) {
+ free(p);
+ return svgtiny_OUT_OF_MEMORY;
+ }
+ shape->path = p;
+ shape->path_length = 10;
+ /*shape->fill = svgtiny_TRANSPARENT;*/
+ if (current_stop == 0)
+ shape->fill = state->gradient_stop[0].color;
+ else if (current_stop == stop_count)
+ shape->fill = state->
+ gradient_stop[stop_count - 1].color;
+ else {
+ float stop_r = (mean_r - last_stop_r) /
+ (current_stop_r - last_stop_r);
+ shape->fill = svgtiny_RGB(
+ (int) ((1 - stop_r) * red0 + stop_r * red1),
+ (int) ((1 - stop_r) * green0 + stop_r * green1),
+ (int) ((1 - stop_r) * blue0 + stop_r * blue1));
+ }
+ shape->stroke = svgtiny_TRANSPARENT;
+ #ifdef GRADIENT_DEBUG
+ shape->stroke = svgtiny_RGB(0, 0, 0xff);
+ #endif
+ state->diagram->shape_count++;
+ if (point_a->r < point_b->r) {
+ t = a;
+ a = (a + 1) % svgtiny_list_size(pts);
+ } else {
+ t = b;
+ b = b == 0 ? svgtiny_list_size(pts) - 1 : b - 1;
+ }
+ }
+
+ /* render gradient vector for debugging */
+ #ifdef GRADIENT_DEBUG
+ {
+ float *p = malloc(7 * sizeof p[0]);
+ if (!p)
+ return svgtiny_OUT_OF_MEMORY;
+ p[0] = svgtiny_PATH_MOVE;
+ p[1] = gradient_x0;
+ p[2] = gradient_y0;
+ p[3] = svgtiny_PATH_LINE;
+ p[4] = gradient_x1;
+ p[5] = gradient_y1;
+ p[6] = svgtiny_PATH_CLOSE;
+ svgtiny_transform_path(p, 7, state);
+ struct svgtiny_shape *shape = svgtiny_add_shape(state);
+ if (!shape) {
+ free(p);
+ return svgtiny_OUT_OF_MEMORY;
+ }
+ shape->path = p;
+ shape->path_length = 7;
+ shape->fill = svgtiny_TRANSPARENT;
+ shape->stroke = svgtiny_RGB(0xff, 0, 0);
+ state->diagram->shape_count++;
+ }
+ #endif
+
+ /* render triangle vertices with r values for debugging */
+ #ifdef GRADIENT_DEBUG
+ for (unsigned int i = 0; i != pts->size; i++) {
+ struct grad_point *point = svgtiny_list_get(pts, i);
+ struct svgtiny_shape *shape = svgtiny_add_shape(state);
+ if (!shape)
+ return svgtiny_OUT_OF_MEMORY;
+ char *text = malloc(20);
+ if (!text)
+ return svgtiny_OUT_OF_MEMORY;
+ sprintf(text, "%i=%.3f", i, point->r);
+ shape->text = text;
+ shape->text_x = state->ctm.a * point->x +
+ state->ctm.c * point->y + state->ctm.e;
+ shape->text_y = state->ctm.b * point->x +
+ state->ctm.d * point->y + state->ctm.f;
+ shape->fill = svgtiny_RGB(0, 0, 0);
+ shape->stroke = svgtiny_TRANSPARENT;
+ state->diagram->shape_count++;
+ }
+ #endif
+
+ /* plot actual path outline */
+ if (state->stroke != svgtiny_TRANSPARENT) {
+ struct svgtiny_shape *shape;
+ svgtiny_transform_path(p, n, state);
+
+ shape = svgtiny_add_shape(state);
+ if (!shape) {
+ free(p);
+ return svgtiny_OUT_OF_MEMORY;
+ }
+ shape->path = p;
+ shape->path_length = n;
+ shape->fill = svgtiny_TRANSPARENT;
+ state->diagram->shape_count++;
+ } else {
+ free(p);
+ }
+
+ svgtiny_list_free(pts);
+
+ return svgtiny_OK;
+}
+
+
+/**
+ * Get the bounding box of path.
+ */
+
+void svgtiny_path_bbox(float *p, unsigned int n,
+ float *x0, float *y0, float *x1, float *y1)
+{
+ unsigned int j;
+
+ *x0 = *x1 = p[1];
+ *y0 = *y1 = p[2];
+
+ for (j = 0; j != n; ) {
+ unsigned int points = 0;
+ unsigned int k;
+ switch ((int) p[j]) {
+ case svgtiny_PATH_MOVE:
+ case svgtiny_PATH_LINE:
+ points = 1;
+ break;
+ case svgtiny_PATH_CLOSE:
+ points = 0;
+ break;
+ case svgtiny_PATH_BEZIER:
+ points = 3;
+ break;
+ default:
+ assert(0);
+ }
+ j++;
+ for (k = 0; k != points; k++) {
+ float x = p[j], y = p[j + 1];
+ if (x < *x0)
+ *x0 = x;
+ else if (*x1 < x)
+ *x1 = x;
+ if (y < *y0)
+ *y0 = y;
+ else if (*y1 < y)
+ *y1 = y;
+ j += 2;
+ }
+ }
+}
+
+
+/**
+ * Invert a transformation matrix.
+ */
+void svgtiny_invert_matrix(float *m, float *inv)
+{
+ float determinant = m[0]*m[3] - m[1]*m[2];
+ inv[0] = m[3] / determinant;
+ inv[1] = -m[1] / determinant;
+ inv[2] = -m[2] / determinant;
+ inv[3] = m[0] / determinant;
+ inv[4] = (m[2]*m[5] - m[3]*m[4]) / determinant;
+ inv[5] = (m[1]*m[4] - m[0]*m[5]) / determinant;
+}
+
+
+/**
+ * Find an element in the document by id.
+ */
+
+xmlNode *svgtiny_find_element_by_id(xmlNode *node, const char *id)
+{
+ xmlNode *child;
+ xmlNode *found;
+
+ for (child = node->children; child; child = child->next) {
+ xmlAttr *attr;
+ if (child->type != XML_ELEMENT_NODE)
+ continue;
+ attr = xmlHasProp(child, (const xmlChar *) "id");
+ if (attr && strcmp(id, (const char *) attr->children->content)
+ == 0)
+ return child;
+ found = svgtiny_find_element_by_id(child, id);
+ if (found)
+ return found;
+ }
+
+ return 0;
+}
+
diff --git a/liveengineUnmapped/ofxSVGTiny/libs/svgtiny_internal.h b/liveengineUnmapped/ofxSVGTiny/libs/svgtiny_internal.h
new file mode 100644
index 0000000..eb90c5b
--- /dev/null
+++ b/liveengineUnmapped/ofxSVGTiny/libs/svgtiny_internal.h
@@ -0,0 +1,95 @@
+/*
+ * This file is part of Libsvgtiny
+ * Licensed under the MIT License,
+ * http://opensource.org/licenses/mit-license.php
+ * Copyright 2008 James Bursa <james@semichrome.net>
+ */
+
+#ifndef SVGTINY_INTERNAL_H
+#define SVGTINY_INTERNAL_H
+
+#include <stdbool.h>
+
+#ifndef UNUSED
+#define UNUSED(x) ((void) (x))
+#endif
+
+struct svgtiny_gradient_stop {
+ float offset;
+ svgtiny_colour color;
+};
+
+#define svgtiny_MAX_STOPS 10
+#define svgtiny_LINEAR_GRADIENT 0x2000000
+
+struct svgtiny_parse_state {
+ struct svgtiny_diagram *diagram;
+ xmlDoc *document;
+
+ float viewport_width;
+ float viewport_height;
+
+ /* current transformation matrix */
+ struct {
+ float a, b, c, d, e, f;
+ } ctm;
+
+ /*struct css_style style;*/
+
+ /* paint attributes */
+ svgtiny_colour fill;
+ svgtiny_colour stroke;
+ int stroke_width;
+
+ /* 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];
+ bool gradient_user_space_on_use;
+ struct {
+ float a, b, c, d, e, f;
+ } gradient_transform;
+};
+
+struct svgtiny_list;
+
+/* svgtiny.c */
+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);
+void svgtiny_parse_transform(char *s, float *ma, float *mb,
+ float *mc, float *md, float *me, float *mf);
+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);
+#if defined(_GNU_SOURCE)
+#define HAVE_STRNDUP
+#else
+#undef HAVE_STRNDUP
+char *svgtiny_strndup(const char *s, size_t n);
+#define strndup svgtiny_strndup
+#endif
+
+/* svgtiny_gradient.c */
+void svgtiny_find_gradient(const char *id, struct svgtiny_parse_state *state);
+svgtiny_code svgtiny_add_path_linear_gradient(float *p, unsigned int n,
+ struct svgtiny_parse_state *state);
+xmlNode *svgtiny_find_element_by_id(xmlNode *node, const char *id);
+
+/* svgtiny_list.c */
+struct svgtiny_list *svgtiny_list_create(size_t item_size);
+unsigned int svgtiny_list_size(struct svgtiny_list *list);
+svgtiny_code svgtiny_list_resize(struct svgtiny_list *list,
+ unsigned int new_size);
+void *svgtiny_list_get(struct svgtiny_list *list,
+ unsigned int i);
+void *svgtiny_list_push(struct svgtiny_list *list);
+void svgtiny_list_free(struct svgtiny_list *list);
+
+/* colors.gperf */
+const struct svgtiny_named_color *
+ svgtiny_color_lookup(register const char *str,
+ register unsigned int len);
+
+#endif
diff --git a/liveengineUnmapped/ofxSVGTiny/libs/svgtiny_list.c b/liveengineUnmapped/ofxSVGTiny/libs/svgtiny_list.c
new file mode 100644
index 0000000..53cfb34
--- /dev/null
+++ b/liveengineUnmapped/ofxSVGTiny/libs/svgtiny_list.c
@@ -0,0 +1,125 @@
+/*
+ * This file is part of Libsvgtiny
+ * Licensed under the MIT License,
+ * http://opensource.org/licenses/mit-license.php
+ * Copyright 2008 James Bursa <james@semichrome.net>
+ */
+
+/**
+ * A svgtiny_list is a managed array of objects. It grows in chunks to reduce
+ * calls to realloc(), but keeps wasted space low.
+ */
+
+#include <assert.h>
+#include "svgtiny.h"
+#include "svgtiny_internal.h"
+
+
+struct svgtiny_list {
+ unsigned int size; /* number of slots used */
+ unsigned int allocated; /* number of slots allocated (>= size) */
+ size_t item_size; /* size of each slot / bytes */
+ char *items; /* array of slots */
+};
+
+
+/**
+ * Create an empty svgtiny_list.
+ */
+
+struct svgtiny_list *svgtiny_list_create(size_t item_size)
+{
+ struct svgtiny_list *list = malloc(sizeof *list);
+ if (!list)
+ return 0;
+ list->size = 0;
+ list->allocated = 0;
+ list->item_size = item_size;
+ list->items = 0;
+ return list;
+}
+
+
+/**
+ * Return the number of objects in a list.
+ */
+
+unsigned int svgtiny_list_size(struct svgtiny_list *list)
+{
+ return list->size;
+}
+
+
+/**
+ * Set the number of objects in a list. If the size is increased, the new
+ * objects are not initialized in any way.
+ *
+ * The allocation size formula is taken from Python's list:
+ * http://svn.python.org/view/python/trunk/Objects/listobject.c?view=markup
+ *
+ * Objects may have moved after this call. Use svgtiny_list_get() to get new
+ * pointers.
+ */
+
+svgtiny_code svgtiny_list_resize(struct svgtiny_list *list,
+ unsigned int new_size)
+{
+ unsigned int new_allocated;
+ void *new_items;
+
+ if (new_size <= list->allocated) {
+ list->size = new_size;
+ return svgtiny_OK;
+ }
+
+ new_allocated = (new_size >> 3) + (new_size < 9 ? 3 : 6) + new_size;
+ if (new_size == 0)
+ new_allocated = 0;
+ new_items = realloc(list->items, new_allocated * list->item_size);
+ if (!new_items)
+ return svgtiny_OUT_OF_MEMORY;
+
+ list->size = new_size;
+ list->allocated = new_allocated;
+ list->items = new_items;
+
+ return svgtiny_OK;
+}
+
+
+/**
+ * Return a pointer to an object in a list.
+ */
+
+void *svgtiny_list_get(struct svgtiny_list *list,
+ unsigned int i)
+{
+ assert(i < list->size);
+ return (void *) (list->items + i * list->item_size);
+}
+
+
+/**
+ * Add space for one object to a list and return a pointer to it.
+ */
+
+void *svgtiny_list_push(struct svgtiny_list *list)
+{
+ svgtiny_code code;
+ code = svgtiny_list_resize(list, list->size + 1);
+ if (code != svgtiny_OK)
+ return 0;
+ return svgtiny_list_get(list, list->size - 1);
+}
+
+
+/**
+ * Free an entire list.
+ */
+
+void svgtiny_list_free(struct svgtiny_list *list)
+{
+ free(list->items);
+ free(list);
+}
+