Advertisement
Serafim

Untitled

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