| | 21 | |
|---|
| | 22 | // At first, we have to check if this shape is in 'single-side mode' |
|---|
| | 23 | // In single-side mode, we can render this shape in manner of |
|---|
| | 24 | // standard vector renderer - e.g. cairo, flash.graphics.* APIs |
|---|
| | 25 | |
|---|
| | 26 | // The other mode is 'two-side mode'. This is more complex so we have to |
|---|
| | 27 | // analyze and rebuild shape data before rendering. |
|---|
| | 28 | |
|---|
| | 29 | this.single_side = this.checkSingleSideMode(); |
|---|
| | 30 | if (this.single_side) |
|---|
| | 31 | { |
|---|
| | 32 | this.defineShape.shape[this.defineShape.shape.length-1].term = true; |
|---|
| | 33 | //console.warn(this.shape_id); |
|---|
| | 34 | } |
|---|
| | 35 | }, |
|---|
| | 36 | |
|---|
| | 37 | checkSingleSideMode: function() { |
|---|
| | 38 | // is single-side mode? |
|---|
| | 39 | |
|---|
| | 40 | // more than 1 style -> NO |
|---|
| | 41 | if (this.fillStyles.length > 1) |
|---|
| | 42 | return false; |
|---|
| | 43 | |
|---|
| | 44 | var r; |
|---|
| | 45 | var fill_flag = 0; |
|---|
| | 46 | var records = this.defineShape.shape; |
|---|
| | 47 | var len = records.length; |
|---|
| | 48 | for (var i = 0;i < len;i++) { |
|---|
| | 49 | r = records[i]; |
|---|
| | 50 | if (r.schange) return false; // has new styles -> NO |
|---|
| | 51 | if (r.f0 != undefined || r.f1 != undefined) { |
|---|
| | 52 | if (fill_flag != 0) // more than 1 style change -> NO |
|---|
| | 53 | return false; |
|---|
| | 54 | |
|---|
| | 55 | if (r.f0 != undefined) |
|---|
| | 56 | fill_flag |= 0x1; |
|---|
| | 57 | |
|---|
| | 58 | if (r.f1 != undefined) |
|---|
| | 59 | fill_flag |= 0x2; |
|---|
| | 60 | |
|---|
| | 61 | if (fill_flag == 0x3) // both side fill -> NO |
|---|
| | 62 | return false; |
|---|
| | 63 | } |
|---|
| | 64 | } |
|---|
| | 65 | |
|---|
| | 66 | // Yes, this is. |
|---|
| | 67 | return true; |
|---|
| | 128 | |
|---|
| | 129 | buildEdgeIndex_S: function() { |
|---|
| | 130 | this.displayList = []; |
|---|
| | 131 | |
|---|
| | 132 | var cur_rightFill = 0; |
|---|
| | 133 | var cur_leftFill = 0; |
|---|
| | 134 | var cur_lineStyle = 0; |
|---|
| | 135 | |
|---|
| | 136 | var records = this.defineShape.shape; |
|---|
| | 137 | var len = records.length, llen; |
|---|
| | 138 | var rcd; |
|---|
| | 139 | |
|---|
| | 140 | var _tx = 0; |
|---|
| | 141 | var _ty = 0; |
|---|
| | 142 | var _first_seg = true; |
|---|
| | 143 | var order_index = 0; |
|---|
| | 144 | var i, k; |
|---|
| | 145 | var loops = []; |
|---|
| | 146 | this.pendingEdges = null; |
|---|
| | 147 | var edge_starts = []; |
|---|
| | 148 | |
|---|
| | 149 | for (i = 0;i < len;i++) { |
|---|
| | 150 | rcd = records[i]; |
|---|
| | 151 | |
|---|
| | 152 | if (rcd.t == 0) { |
|---|
| | 153 | if (rcd.f0 != undefined || rcd.f1 != undefined || rcd.term) { |
|---|
| | 154 | if (this.pendingEdges) |
|---|
| | 155 | { |
|---|
| | 156 | llen = this.pendingEdges.length; |
|---|
| | 157 | for (k = 0;k < llen;k++) |
|---|
| | 158 | this.pendingEdges[k].self_tearOff(); |
|---|
| | 159 | |
|---|
| | 160 | loops.push(this.pendingEdges); |
|---|
| | 161 | } |
|---|
| | 162 | |
|---|
| | 163 | this.pendingEdges = []; |
|---|
| | 164 | } |
|---|
| | 165 | |
|---|
| | 166 | if (!rcd.term) |
|---|
| | 167 | { |
|---|
| | 168 | edge_starts.push(this.edgeList.length); |
|---|
| | 169 | _first_seg = true; |
|---|
| | 170 | } |
|---|
| | 171 | |
|---|
| | 172 | /* ShapeSetup */ |
|---|
| | 173 | if (rcd.p) { |
|---|
| | 174 | _tx = rcd.p[0]; |
|---|
| | 175 | _ty = rcd.p[1]; |
|---|
| | 176 | } |
|---|
| | 177 | |
|---|
| | 178 | if (rcd.f0 != undefined) cur_leftFill = rcd.f0; |
|---|
| | 179 | if (rcd.f1 != undefined) cur_rightFill = rcd.f1; |
|---|
| | 180 | if (rcd.ls != undefined) cur_lineStyle = rcd.ls; |
|---|
| | 181 | } |
|---|
| | 182 | else { |
|---|
| | 183 | var E; |
|---|
| | 184 | if (rcd.t == 2) |
|---|
| | 185 | { |
|---|
| | 186 | x1 = _tx; |
|---|
| | 187 | y1 = _ty; |
|---|
| | 188 | |
|---|
| | 189 | x2 = _tx + rcd.p[0]; |
|---|
| | 190 | y2 = _ty + rcd.p[1]; |
|---|
| | 191 | |
|---|
| | 192 | _tx = x2 + rcd.p[2]; |
|---|
| | 193 | _ty = y2 + rcd.p[3]; |
|---|
| | 194 | |
|---|
| | 195 | E = this.addCurve(order_index++, _first_seg, cur_lineStyle, x1, y1, x2, y2, _tx, _ty); |
|---|
| | 196 | } |
|---|
| | 197 | else |
|---|
| | 198 | { |
|---|
| | 199 | x1 = _tx; |
|---|
| | 200 | y1 = _ty; |
|---|
| | 201 | |
|---|
| | 202 | _tx += rcd.p[0]; |
|---|
| | 203 | _ty += rcd.p[1]; |
|---|
| | 204 | |
|---|
| | 205 | E = this.addLine(order_index++, _first_seg, cur_lineStyle, x1, y1, _tx, _ty); |
|---|
| | 206 | } |
|---|
| | 207 | |
|---|
| | 208 | _first_seg = false; |
|---|
| | 209 | } |
|---|
| | 210 | } |
|---|
| | 211 | |
|---|
| | 212 | |
|---|
| | 213 | var di; |
|---|
| | 214 | di = new JSplash.DisplayListEntry(1, loops, 0); |
|---|
| | 215 | di.fill_index = cur_rightFill || cur_leftFill; |
|---|
| | 216 | this.displayList.push( di ); |
|---|
| | 217 | |
|---|
| | 218 | len = edge_starts.length; |
|---|
| | 219 | for (i = 0;i < len;i++) { |
|---|
| | 220 | var si = edge_starts[i]; |
|---|
| | 221 | if (this.edgeList[si].lineStyle) { |
|---|
| | 222 | this.displayList.push( new JSplash.DisplayListEntry(0, si, 1) ); |
|---|
| | 223 | } |
|---|
| | 224 | } |
|---|
| | 225 | }, |
|---|
| 162 | | this.addCurve(order_index++, _first_seg, cur_lineStyle, cur_leftFill, cur_rightFill, x1, y1, x2, y2, _tx, _ty); |
|---|
| | 319 | E = this.addCurve(order_index++, _first_seg, cur_lineStyle, x1, y1, x2, y2, _tx, _ty); |
|---|
| 190 | | this.addEdge(fL, fR, E); |
|---|
| 191 | | }, |
|---|
| 192 | | |
|---|
| 193 | | addCurve: function(oi, fst, ls, fL, fR, x1, y1, cx, cy, x2, y2) { |
|---|
| | 350 | this.addEdge(E); |
|---|
| | 351 | return E; |
|---|
| | 352 | }, |
|---|
| | 353 | |
|---|
| | 354 | addCurve: function(oi, fst, ls, x1, y1, cx, cy, x2, y2) { |
|---|
| 210 | | |
|---|
| 211 | | if (fL != 0) { |
|---|
| 212 | | if (!this.leftFillEdges[fL]) |
|---|
| 213 | | this.leftFillEdges[fL] = []; |
|---|
| 214 | | list = this.leftFillEdges[fL]; |
|---|
| 215 | | list.push(E); |
|---|
| 216 | | } |
|---|
| 217 | | |
|---|
| 218 | | if (fR != 0) { |
|---|
| 219 | | if (!this.rightFillEdges[fR]) |
|---|
| 220 | | this.rightFillEdges[fR] = []; |
|---|
| 221 | | list = this.rightFillEdges[fR]; |
|---|
| 222 | | list.push(E); |
|---|
| | 372 | if (this.pendingEdges) |
|---|
| | 373 | this.pendingEdges.push(E); |
|---|
| | 374 | }, |
|---|
| | 375 | |
|---|
| | 376 | registerPendingEdges: function(fL, fR) { |
|---|
| | 377 | var edges = this.pendingEdges; |
|---|
| | 378 | if (!edges) return false; |
|---|
| | 379 | |
|---|
| | 380 | var len = edges.length; |
|---|
| | 381 | var E; |
|---|
| | 382 | |
|---|
| | 383 | for (i = 0;i < len;i++) { |
|---|
| | 384 | E = edges[i]; |
|---|
| | 385 | |
|---|
| | 386 | if (fL != 0) { |
|---|
| | 387 | if (!this.leftFillEdges[fL]) |
|---|
| | 388 | this.leftFillEdges[fL] = []; |
|---|
| | 389 | list = this.leftFillEdges[fL]; |
|---|
| | 390 | list.push(E); |
|---|
| | 391 | } |
|---|
| | 392 | |
|---|
| | 393 | if (fR != 0) { |
|---|
| | 394 | if (!this.rightFillEdges[fR]) |
|---|
| | 395 | this.rightFillEdges[fR] = []; |
|---|
| | 396 | list = this.rightFillEdges[fR]; |
|---|
| | 397 | list.push(E); |
|---|
| | 398 | } |
|---|
| | 819 | JSplash.MorphShapeRenderer = Class.create(); |
|---|
| | 820 | JSplash.MorphShapeRenderer.prototype = { |
|---|
| | 821 | initialize: function(source) { |
|---|
| | 822 | this.derived_shape = {}; |
|---|
| | 823 | |
|---|
| | 824 | this.calcShape(source.shape1, source.shape2); |
|---|
| | 825 | |
|---|
| | 826 | this.derived_shape.id = source.id; |
|---|
| | 827 | this.derived_shape.shape = source.shape2; |
|---|
| | 828 | this.derived_shape.fill_styles = this.calcFillStyles(source.fill_styles); |
|---|
| | 829 | this.derived_shape.line_styles = this.calcLineStyles(source.line_styles); |
|---|
| | 830 | |
|---|
| | 831 | this.inner_renderer = new JSplash.ShapeRenderer(this.derived_shape); |
|---|
| | 832 | }, |
|---|
| | 833 | |
|---|
| | 834 | calcShape: function(s1, s2) { |
|---|
| | 835 | var i, len = s1.length; |
|---|
| | 836 | var r1, r2; |
|---|
| | 837 | for (i = 0;i < len;i++) { |
|---|
| | 838 | r1 = s1[i]; |
|---|
| | 839 | r2 = s2[i]; |
|---|
| | 840 | |
|---|
| | 841 | if (r1.ls != undefined) r2.ls = r1.ls; |
|---|
| | 842 | if (r1.f0 != undefined) r2.f0 = r1.f0; |
|---|
| | 843 | if (r1.f1 != undefined) r2.f1 = r1.f1; |
|---|
| | 844 | } |
|---|
| | 845 | }, |
|---|
| | 846 | |
|---|
| | 847 | calcFillStyles: function(src) { |
|---|
| | 848 | var ret = []; |
|---|
| | 849 | var len, i; |
|---|
| | 850 | |
|---|
| | 851 | len = src.length; |
|---|
| | 852 | for (i = 0;i < len;i++) { |
|---|
| | 853 | var s1 = src[i][0]; |
|---|
| | 854 | var s2 = src[i][1]; |
|---|
| | 855 | ret.push(s2); |
|---|
| | 856 | } |
|---|
| | 857 | |
|---|
| | 858 | return ret; |
|---|
| | 859 | }, |
|---|
| | 860 | |
|---|
| | 861 | calcLineStyles: function(src) { |
|---|
| | 862 | var ret = []; |
|---|
| | 863 | var len, i; |
|---|
| | 864 | |
|---|
| | 865 | len = src.length; |
|---|
| | 866 | for (i = 0;i < len;i++) { |
|---|
| | 867 | var s1 = src[i][0]; |
|---|
| | 868 | var s2 = src[i][1]; |
|---|
| | 869 | ret.push(s2); |
|---|
| | 870 | } |
|---|
| | 871 | |
|---|
| | 872 | return ret; |
|---|
| | 873 | }, |
|---|
| | 874 | |
|---|
| | 875 | buildEdgeIndex: function() { |
|---|
| | 876 | return this.inner_renderer.buildEdgeIndex(); |
|---|
| | 877 | }, |
|---|
| | 878 | |
|---|
| | 879 | buildSVG: function(g) { |
|---|
| | 880 | return this.inner_renderer.buildSVG(g); |
|---|
| | 881 | } |
|---|
| | 882 | } |
|---|
| | 883 | |
|---|