Advertisement
Serafim

Untitled

Oct 21st, 2013
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ### STYLES #
  2.  
  3.   (info)
  4.     <int>     - Integer
  5.     <string>  - String
  6.     <color>   - #<HHH> or #<HHH> or rgb(<I>, <I>, <I>) or rgba(<I>, <I>, <I>, <float>)
  7.               -   where H = [0..F], I = [0..255]
  8.     <size>    - <N>px, where N = <int>
  9.     <float>   - Float
  10.  
  11.   font:
  12.     family  (<string>|caption|icon|menu|message-box|small-caption|status-bar)
  13.     style:  (normal|italic|oblique)
  14.     weight  (<int>|normal|bold|bolder|lighter)
  15.     variant (normal|small-caps)
  16.     size    (<int>)
  17.     align   (start|end|center|left|right)
  18.     valign  (alphabetic|top|hanging|middle|ideographic|bottom)
  19.   stroke    (<color>)
  20.   color     (<color>)
  21.   composite (source-over|source-atop|source-in|source-out|destination-over|
  22.               destination-atop|destination-in|destination-out|lighter|copy|xor)
  23.   opacity   (<float[0..1]>)
  24.   line:
  25.     cap     (butt|round|square)
  26.     join    (bevel|round|miter)
  27.     size    (<int>)
  28.     mitter  (<int>)
  29.   shadow:
  30.     color   (<color>)
  31.     top     (<int>)
  32.     left    (<int>)
  33.     size    (<int>)
  34.  
  35.   Example:
  36.     ctx.style
  37.       font: {
  38.         family: 'Arial',
  39.         weight: 'bold',
  40.         size:   15,
  41.         align:  'center'
  42.       },
  43.       color: '#fff',
  44.       shadow: {
  45.         color: '#2f0103',
  46.         top: 1
  47.       }
  48. ###
  49.  
  50. CanvasRenderingContext2D::style = (args) ->
  51.   if args.font?
  52.     if args.font.family? || args.font.style? || args.font.weight? || args.font.size? || args.font.variant?
  53.       this.font = (args.font.style || '') + ' ' +
  54.         (args.font.variant || '') + ' ' +
  55.         (args.font.weight  || '') + ' ' +
  56.         ((args.font.size|0) + 'px' || '') + ' ' +
  57.         (args.font.family  || '')
  58.     this.textAlign    = args.font.align  || 'left'
  59.     this.textBaseline = args.font.valign || 'top'
  60.  
  61.   this.strokeStyle  = args.stroke || ''
  62.   this.fillStyle    = args.color  || '#000'
  63.   this.globalCompositeOperation = args.composite || 'source-over'
  64.   this.globalAlpha  = args.opacity || 1
  65.  
  66.   if args.line?
  67.     this.lineCap    = args.line.cap   || 'butt'
  68.     this.lineJoin   = args.line.join  || 'miter'
  69.     this.lineWidth  = (args.line.size|0)    || 1
  70.     this.miterLimit = (args.line.mitter|0)  || 10
  71.  
  72.   if args.shadow?
  73.     this.shadowColor    = args.shadow.color if args.shadow.color?
  74.     this.shadowOffsetY  = (args.shadow.top|0)  || 0
  75.     this.shadowOffsetX  = (args.shadow.left|0) || 0
  76.     this.shadowBlur     = (args.shadow.size|0) || 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement