Changeset 7810

Show
Ignore:
Timestamp:
03/27/07 14:02:16 (20 months ago)
Author:
elazutkin
Message:

gfx: added a stroke style

Location:
trunk
Files:
1 added
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/gfx/common.js

    r7176 r7810  
    55dojo.require("dojo.lang.extras"); 
    66dojo.require("dojo.dom"); 
     7dojo.require("dojo.html.metrics"); 
    78 
    89dojo.lang.mixin(dojo.gfx, { 
     
    2324 
    2425        // default geometric attributes 
    25         defaultStroke: {type: "stroke", color: "black", width: 1, cap: "butt", join: 4}, 
     26        defaultStroke: {type: "stroke", color: "black", style: "solid", width: 1, cap: "butt", join: 4}, 
    2627        defaultLinearGradient: {type: "linear", x1: 0, y1: 0, x2: 100, y2: 100,  
    2728                colors: [{offset: 0, color: "black"}, {offset: 1, color: "white"}]}, 
     
    116117                return font;    // Object 
    117118        }, 
     119        // length operations 
     120        cm_in_pt: 72 / 2.54,    // Number: centimeters per inch 
     121        mm_in_pt: 7.2 / 2.54,   // Number: millimeters per inch 
     122        px_in_pt: function(){ 
     123                // summary: returns a number of pixels per point 
     124                return dojo.html.getCachedFontMeasurements()["12pt"] / 12;      // Number 
     125        }, 
     126        pt2px: function(len){ 
     127                // summary: converts points to pixels 
     128                // len: Number: a value in points 
     129                return len * dojo.gfx.px_in_pt();       // Number 
     130        }, 
     131        px2pt: function(len){ 
     132                // summary: converts pixels to points 
     133                // len: Number: a value in pixels 
     134                return len / dojo.gfx.px_in_pt();       // Number 
     135        }, 
     136        normalizedLength: function(len) { 
     137                // summary: converts any length value to pixels 
     138                // len: String: a length, e.g., "12pc" 
     139                if(len.length == 0) return 0; 
     140                if(len.length > 2){ 
     141                        var px_in_pt = dojo.gfx.px_in_pt(); 
     142                        var val = parseFloat(len); 
     143                        switch(len.slice(-2)){ 
     144                                case "px": return val; 
     145                                case "pt": return val * px_in_pt; 
     146                                case "in": return val * 72 * px_in_pt; 
     147                                case "pc": return val * 12 * px_in_pt; 
     148                                case "mm": return val / dojo.gfx.mm_in_pt * px_in_pt; 
     149                                case "cm": return val / dojo.gfx.cm_in_pt * px_in_pt; 
     150                        } 
     151                } 
     152                return parseFloat(len); // Number 
     153        }, 
    118154         
    119155        // a constant used to split a SVG/VML path into primitive components 
  • trunk/src/gfx/shape.js

    r7772 r7810  
    437437                        dojo.gfx.makeParameters(dojo.gfx.defaultFont, newFont); 
    438438                this._setFont(); 
    439         } 
    440 }); 
     439                return this;    // self 
     440        } 
     441}); 
  • trunk/src/gfx/svg.js

    r7772 r7810  
    2525        } 
    2626        return null;    // Node 
     27}; 
     28 
     29dojo.gfx.svg.dasharray = { 
     30        solid:                          "none", 
     31        shortdash:                      [4, 1], 
     32        shortdot:                       [1, 1], 
     33        shortdashdot:           [4, 1, 1, 1], 
     34        shortdashdotdot:        [4, 1, 1, 1, 1, 1], 
     35        dot:                            [1, 3], 
     36        dash:                           [4, 3], 
     37        longdash:                       [8, 3], 
     38        dashdot:                        [4, 3, 1, 3], 
     39        longdashdot:            [8, 3, 1, 3], 
     40        longdashdotdot:         [8, 3, 1, 3, 1, 3] 
    2741}; 
    2842 
     
    112126                                rn.setAttribute("stroke-linejoin",   s.join); 
    113127                        } 
     128                        var da = s.style.toLowerCase(); 
     129                        if(da in dojo.gfx.svg.dasharray){ da = dojo.gfx.svg.dasharray[da]; } 
     130                        if(da instanceof Array){ 
     131                                for(var i = 0; i < da.length; ++i){ 
     132                                        da[i] *= s.width; 
     133                                } 
     134                                if(s.cap != "butt"){ 
     135                                        for(var i = 0; i < da.length; i += 2){ 
     136                                                da[i] -= s.width; 
     137                                                if(da[i] < 1){ da[i] = 1; } 
     138                                        } 
     139                                        for(var i = 1; i < da.length; i += 2){ 
     140                                                da[i] += s.width; 
     141                                        } 
     142                                } 
     143                                da = da.join(","); 
     144                        } 
     145                        rn.setAttribute("stroke-dasharray", da); 
     146                        rn.setAttribute("dojoGfxStrokeStyle", s.style); 
    114147                } 
    115148                return this;    // self 
     
    309342                                strokeStyle.join = rawNode.getAttribute("stroke-miterlimit"); 
    310343                        } 
     344                        strokeStyle.style = rawNode.getAttribute("dojoGfxStrokeStyle"); 
    311345                } 
    312346                return strokeStyle;     // Object 
  • trunk/src/gfx/vml.js

    r7402 r7810  
    66dojo.require("dojo.lang.extras"); 
    77dojo.require("dojo.string.*"); 
    8 dojo.require("dojo.html.metrics"); 
    98 
    109dojo.require("dojo.gfx.color"); 
     
    144143                                        if(f.width && f.height){ 
    145144                                                // in points 
    146                                                 fo.size.x = dojo.gfx.vml.px2pt(f.width); 
    147                                                 fo.size.y = dojo.gfx.vml.px2pt(f.height); 
     145                                                fo.size.x = dojo.gfx.px2pt(f.width); 
     146                                                fo.size.y = dojo.gfx.px2pt(f.height); 
    148147                                        } 
    149148                                        fo.alignShape = false; 
     
    198197                                // rn.stroke.miterlimit = s.width; 
    199198                        } 
     199                        rn.stroke.dashstyle = s.style == "none" ? "Solid" : s.style; 
    200200                } 
    201201                return this;    // self 
     
    289289                        }else if(fo.on && fo.type == "tile"){ 
    290290                                var fillStyle = dojo.lang.shallowCopy(dojo.gfx.defaultPattern, true); 
    291                                 fillStyle.width  = dojo.gfx.vml.pt2px(fo.size.x); // from pt 
    292                                 fillStyle.height = dojo.gfx.vml.pt2px(fo.size.y); // from pt 
     291                                fillStyle.width  = dojo.gfx.pt2px(fo.size.x); // from pt 
     292                                fillStyle.height = dojo.gfx.pt2px(fo.size.y); // from pt 
    293293                                fillStyle.x = fo.origin.x * fillStyle.width; 
    294294                                fillStyle.y = fo.origin.y * fillStyle.height; 
     
    310310                        strokeStyle.color = new dojo.gfx.color.Color(rawNode.strokecolor.value); 
    311311                        dojo.debug("We are expecting an .75pt here, instead of strokeweight = " + rawNode.strokeweight ); 
    312                         strokeStyle.width = dojo.gfx.vml.normalizedLength(rawNode.strokeweight+""); 
     312                        strokeStyle.width = dojo.gfx.normalizedLength(rawNode.strokeweight+""); 
    313313                        strokeStyle.color.a = rawNode.stroke.opacity; 
    314314                        strokeStyle.cap = this._translate(this._capMapReversed, rawNode.stroke.endcap); 
    315315                        strokeStyle.join = rawNode.stroke.joinstyle == "miter" ? rawNode.stroke.miterlimit : rawNode.stroke.joinstyle; 
     316                        strokeStyle.style = rawNode.stroke.dashstyle; 
    316317                }else{ 
    317318                        return null; 
     
    330331                        matrix.yx = s.matrix.xtoy; 
    331332                        matrix.yy = s.matrix.ytoy; 
    332                         matrix.dx = dojo.gfx.vml.pt2px(s.offset.x); 
    333                         matrix.dy = dojo.gfx.vml.pt2px(s.offset.y); 
     333                        matrix.dx = dojo.gfx.pt2px(s.offset.x); 
     334                        matrix.dy = dojo.gfx.pt2px(s.offset.y); 
    334335                } 
    335336                return dojo.gfx.matrix.normalize(matrix);       // dojo.gfx.matrix.Matrix 
     
    850851                // see comments in _getRealMatrix() 
    851852                if(matrix){ 
    852                         matrix = dojo.gfx.matrix.multiply(matrix, {dy: dojo.gfx.vml.normalizedLength(this.fontStyle.size) * 0.35}); 
     853                        matrix = dojo.gfx.matrix.multiply(matrix, {dy: dojo.gfx.normalizedLength(this.fontStyle.size) * 0.35}); 
    853854                } 
    854855                return matrix;  // dojo.gfx.Matrix2D 
     
    864865                if(matrix){ 
    865866                        matrix = dojo.gfx.matrix.multiply(matrix,  
    866                                 {dy: -dojo.gfx.vml.normalizedLength(this.fontStyle ? this.fontStyle.size : "10pt") * 0.35}); 
     867                                {dy: -dojo.gfx.normalizedLength(this.fontStyle ? this.fontStyle.size : "10pt") * 0.35}); 
    867868                } 
    868869                return matrix;  // dojo.gfx.Matrix2D