Advertisement
WeltEnSTurm

Untitled

Jun 7th, 2011
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.     contextPrototype.stroke = function(aFill) {
  3.         var lineStr = [];
  4.         var lineOpen = false;
  5.         var a = processStyle(aFill ? this.fillStyle : this.strokeStyle);
  6.         var color = a.color;
  7.         var opacity = a.alpha * this.globalAlpha;
  8.  
  9.         var W = 10;
  10.         var H = 10;
  11.  
  12.         lineStr.push('<g_vml_:shape',
  13.                                  ' filled="', !!aFill, '"',
  14.                                  ' style="position:absolute;width:', W, 'px;height:', H, 'px;"',
  15.                                  ' coordorigin="0 0" coordsize="', Z * W, ' ', Z * H, '"',
  16.                                  ' stroked="', !aFill, '"',
  17.                                  ' path="');
  18.  
  19.         var newSeq = false;
  20.         var min = {x: null, y: null};
  21.         var max = {x: null, y: null};
  22.  
  23.         for (var i = 0; i < this.currentPath_.length; i++) {
  24.             var p = this.currentPath_[i];
  25.             var c;
  26.  
  27.             switch (p.type) {
  28.                 case 'moveTo':
  29.                     c = p;
  30.                     lineStr.push(' m ', mr(p.x), ',', mr(p.y));
  31.                     break;
  32.                 case 'lineTo':
  33.                     lineStr.push(' l ', mr(p.x), ',', mr(p.y));
  34.                     break;
  35.                 case 'close':
  36.                     lineStr.push(' x ');
  37.                     p = null;
  38.                     break;
  39.                 case 'bezierCurveTo':
  40.                     lineStr.push(' c ',
  41.                                              mr(p.cp1x), ',', mr(p.cp1y), ',',
  42.                                              mr(p.cp2x), ',', mr(p.cp2y), ',',
  43.                                              mr(p.x), ',', mr(p.y));
  44.                     break;
  45.                 case 'at':
  46.                 case 'wa':
  47.                     lineStr.push(' ', p.type, ' ',
  48.                                              mr(p.x - this.arcScaleX_ * p.radius), ',',
  49.                                              mr(p.y - this.arcScaleY_ * p.radius), ' ',
  50.                                              mr(p.x + this.arcScaleX_ * p.radius), ',',
  51.                                              mr(p.y + this.arcScaleY_ * p.radius), ' ',
  52.                                              mr(p.xStart), ',', mr(p.yStart), ' ',
  53.                                              mr(p.xEnd), ',', mr(p.yEnd));
  54.                     break;
  55.             }
  56.  
  57.  
  58.             // TODO: Following is broken for curves due to
  59.             //           move to proper paths.
  60.  
  61.             // Figure out dimensions so we can do gradient fills
  62.             // properly
  63.             if (p) {
  64.                 if (min.x == null || p.x < min.x) {
  65.                     min.x = p.x;
  66.                 }
  67.                 if (max.x == null || p.x > max.x) {
  68.                     max.x = p.x;
  69.                 }
  70.                 if (min.y == null || p.y < min.y) {
  71.                     min.y = p.y;
  72.                 }
  73.                 if (max.y == null || p.y > max.y) {
  74.                     max.y = p.y;
  75.                 }
  76.             }
  77.         }
  78.         lineStr.push(' ">');
  79.  
  80.         if (!aFill) {
  81.             var lineWidth = this.lineScale_ * this.lineWidth;
  82.  
  83.             // VML cannot correctly render a line if the width is less than 1px.
  84.             // In that case, we dilute the color to make the line look thinner.
  85.             if (lineWidth < 1) {
  86.                 opacity *= lineWidth;
  87.             }
  88.  
  89.             lineStr.push(
  90.                 '<g_vml_:stroke',
  91.                 ' opacity="', opacity, '"',
  92.                 ' joinstyle="', this.lineJoin, '"',
  93.                 ' miterlimit="', this.miterLimit, '"',
  94.                 ' endcap="', processLineCap(this.lineCap), '"',
  95.                 ' weight="', lineWidth, 'px"',
  96.                 ' color="', color, '" />'
  97.             );
  98.         } else if (typeof this.fillStyle == 'object') {
  99.             var fillStyle = this.fillStyle;
  100.             var angle = 0;
  101.             var focus = {x: 0, y: 0};
  102.  
  103.             // additional offset
  104.             var shift = 0;
  105.             // scale factor for offset
  106.             var expansion = 1;
  107.  
  108.             if (fillStyle.type_ == 'gradient') {
  109.                 var x0 = fillStyle.x0_ / this.arcScaleX_;
  110.                 var y0 = fillStyle.y0_ / this.arcScaleY_;
  111.                 var x1 = fillStyle.x1_ / this.arcScaleX_;
  112.                 var y1 = fillStyle.y1_ / this.arcScaleY_;
  113.                 var p0 = this.getCoords_(x0, y0);
  114.                 var p1 = this.getCoords_(x1, y1);
  115.                 var dx = p1.x - p0.x;
  116.                 var dy = p1.y - p0.y;
  117.                 angle = Math.atan2(dx, dy) * 180 / Math.PI;
  118.  
  119.                 // The angle should be a non-negative number.
  120.                 if (angle < 0) {
  121.                     angle += 360;
  122.                 }
  123.  
  124.                 // Very small angles produce an unexpected result because they are
  125.                 // converted to a scientific notation string.
  126.                 if (angle < 1e-6) {
  127.                     angle = 0;
  128.                 }
  129.             } else {
  130.                 var p0 = this.getCoords_(fillStyle.x0_, fillStyle.y0_);
  131.                 var width   = max.x - min.x;
  132.                 var height = max.y - min.y;
  133.                 focus = {
  134.                     x: (p0.x - min.x) / width,
  135.                     y: (p0.y - min.y) / height
  136.                 };
  137.  
  138.                 width   /= this.arcScaleX_ * Z;
  139.                 height /= this.arcScaleY_ * Z;
  140.                 var dimension = m.max(width, height);
  141.                 shift = 2 * fillStyle.r0_ / dimension;
  142.                 expansion = 2 * fillStyle.r1_ / dimension - shift;
  143.             }
  144.  
  145.             // We need to sort the color stops in ascending order by offset,
  146.             // otherwise IE won't interpret it correctly.
  147.             var stops = fillStyle.colors_;
  148.             stops.sort(function(cs1, cs2) {
  149.                 return cs1.offset - cs2.offset;
  150.             });
  151.  
  152.             var length = stops.length;
  153.             var color1 = stops[0].color;
  154.             var color2 = stops[length - 1].color;
  155.             var opacity1 = stops[0].alpha * this.globalAlpha;
  156.             var opacity2 = stops[length - 1].alpha * this.globalAlpha;
  157.  
  158.             var colors = [];
  159.             for (var i = 0; i < length; i++) {
  160.                 var stop = stops[i];
  161.                 colors.push(stop.offset * expansion + shift + ' ' + stop.color);
  162.             }
  163.  
  164.             // When colors attribute is used, the meanings of opacity and o:opacity2
  165.             // are reversed.
  166.             lineStr.push('<g_vml_:fill type="', fillStyle.type_, '"',
  167.                                      ' method="none" focus="100%"',
  168.                                      ' color="', color1, '"',
  169.                                      ' color2="', color2, '"',
  170.                                      ' colors="', colors.join(','), '"',
  171.                                      ' opacity="', opacity2, '"',
  172.                                      ' g_o_:opacity2="', opacity1, '"',
  173.                                      ' angle="', angle, '"',
  174.                                      ' focusposition="', focus.x, ',', focus.y, '" />');
  175.         } else {
  176.             lineStr.push('<g_vml_:fill color="', color, '" opacity="', opacity,
  177.                                      '" />');
  178.         }
  179.  
  180.         lineStr.push('</g_vml_:shape>');
  181.  
  182.         this.element_.insertAdjacentHTML('beforeEnd', lineStr.join(''));
  183.     };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement