2014-05-16 00:33:34 +00:00
RELS . THEME = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" ;
2014-05-29 06:18:23 +00:00
/* Various RGB/HSL utility functions - might want to put these elsewhere. */
/* From http://www.javascripter.net/faq/hextorgb.htm, usage: var X = hexToX('FFFFFF') */
function cutHex ( h ) { return ( h . charAt ( 0 ) == "#" ) ? h . substring ( 1 , 7 ) : h }
function hexToR ( h ) { return parseInt ( ( cutHex ( h ) ) . substring ( 0 , 2 ) , 16 ) }
function hexToG ( h ) { return parseInt ( ( cutHex ( h ) ) . substring ( 2 , 4 ) , 16 ) }
function hexToB ( h ) { return parseInt ( ( cutHex ( h ) ) . substring ( 4 , 6 ) , 16 ) }
/* From http://www.javascripter.net/faq/rgbtohex.htm, usage: var RGB = rgbToHex(R, G, B) */
function toHex ( n ) {
n = parseInt ( n , 10 ) ;
if ( isNaN ( n ) ) return "00" ;
n = Math . max ( 0 , Math . min ( n , 255 ) ) ;
return "0123456789ABCDEF" . charAt ( ( n - n % 16 ) / 16 )
+ "0123456789ABCDEF" . charAt ( n % 16 ) ;
}
function rgbToHex ( R , G , B ) { return toHex ( R ) + toHex ( G ) + toHex ( B ) }
/* From the specification. */
var HLSMAX = 255 ;
/* From https://gist.github.com/mjackson/5311256 via http://stackoverflow.com/a/9493060 */
/ * *
* Converts an RGB color value to HSL . Conversion formula
* adapted from http : //en.wikipedia.org/wiki/HSL_color_space.
* Assumes r , g , and b are contained in the set [ 0 , 255 ] and
* returns h , s , and l in the set [ 0 , 1 ] .
*
* @ param Number r The red color value
* @ param Number g The green color value
* @ param Number b The blue color value
* @ return Array The HSL representation
* /
function rgbToHsl ( r , g , b ) {
r /= 255 , g /= 255 , b /= 255 ;
var max = Math . max ( r , g , b ) , min = Math . min ( r , g , b ) ;
var h , s , l = ( max + min ) / 2 ;
if ( max == min ) {
h = s = 0 ; // achromatic
} else {
var d = max - min ;
s = l > 0.5 ? d / ( 2 - max - min ) : d / ( max + min ) ;
switch ( max ) {
case r : h = ( g - b ) / d + ( g < b ? 6 : 0 ) ; break ;
case g : h = ( b - r ) / d + 2 ; break ;
case b : h = ( r - g ) / d + 4 ; break ;
}
h /= 6 ;
}
return [ h , s , l ] ;
}
/ * *
* Converts an HSL color value to RGB . Conversion formula
* adapted from http : //en.wikipedia.org/wiki/HSL_color_space.
* Assumes h , s , and l are contained in the set [ 0 , 1 ] and
* returns r , g , and b in the set [ 0 , 255 ] .
*
* @ param Number h The hue
* @ param Number s The saturation
* @ param Number l The lightness
* @ return Array The RGB representation
* /
function hslToRgb ( h , s , l ) {
var r , g , b ;
if ( s == 0 ) {
r = g = b = l ; // achromatic
} else {
function hue2rgb ( p , q , t ) {
if ( t < 0 ) t += 1 ;
if ( t > 1 ) t -= 1 ;
if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t ;
if ( t < 1 / 2 ) return q ;
if ( t < 2 / 3 ) return p + ( q - p ) * ( 2 / 3 - t ) * 6 ;
return p ;
}
var q = l < 0.5 ? l * ( 1 + s ) : l + s - l * s ;
var p = 2 * l - q ;
r = hue2rgb ( p , q , h + 1 / 3 ) ;
g = hue2rgb ( p , q , h ) ;
b = hue2rgb ( p , q , h - 1 / 3 ) ;
}
return [ Math . round ( r * 255 ) , Math . round ( g * 255 ) , Math . round ( b * 255 ) ] ;
}
/* Utility function to apply tint to an RGB color. */
function rgb _tint ( rgb , tint ) {
var r = hexToR ( rgb ) ,
g = hexToG ( rgb ) ,
b = hexToB ( rgb ) ,
hsl = rgbToHsl ( r , g , b ) ;
/* Apply tint as described in pages 1757-1758 of the ECMA Office Open XML specification. */
/* NOTE: This is totally messed up... see http://social.msdn.microsoft.com/Forums/en-US/e9d8c136-6d62-4098-9b1b-dac786149f43/excel-color-tint-algorithm-incorrect */
if ( tint < 0 ) {
hsl [ 2 ] = hsl [ 2 ] * ( 1.0 + tint ) ;
} else if ( tint > 0 ) {
hsl [ 2 ] = hsl [ 2 ] * ( 1.0 + tint ) ;
// XXX This doesn't work...
//hsl[2] = hsl[2] * (1.0 - tint) + (HLSMAX - HLSMAX * (1.0 - tint));
}
rgb = hslToRgb ( hsl [ 0 ] , hsl [ 1 ] , hsl [ 2 ] ) ;
return rgbToHex ( rgb [ 0 ] , rgb [ 1 ] , rgb [ 2 ] ) ;
}
function parse _clrScheme ( t , opts ) {
themes . themeElements . clrScheme = [ ] ;
var color = { } ;
t [ 0 ] . match ( /<[^>]*>/g ) . forEach ( function ( x ) {
var y = parsexmltag ( x ) ;
switch ( y [ 0 ] ) {
2014-05-29 22:30:03 +00:00
case '<a:clrScheme' : case '</a:clrScheme>' : break ;
2014-05-29 06:18:23 +00:00
/* 20.1.2.3.32 srgbClr CT_SRgbColor */
case '<a:srgbClr' : color . rgb = y . val ; break ;
/* 20.1.2.3.33 sysClr CT_SystemColor */
case '<a:sysClr' : color . rgb = y . lastClr ; break ;
/* 20.1.4.1.9 dk1 (Dark 1) */
case '<a:dk1>' :
case '</a:dk1>' :
/* 20.1.4.1.10 dk2 (Dark 2) */
case '<a:dk2>' :
case '</a:dk2>' :
/* 20.1.4.1.22 lt1 (Light 1) */
case '<a:lt1>' :
case '</a:lt1>' :
/* 20.1.4.1.23 lt2 (Light 2) */
case '<a:lt2>' :
case '</a:lt2>' :
/* 20.1.4.1.1 accent1 (Accent 1) */
case '<a:accent1>' :
case '</a:accent1>' :
/* 20.1.4.1.2 accent2 (Accent 2) */
case '<a:accent2>' :
case '</a:accent2>' :
/* 20.1.4.1.3 accent3 (Accent 3) */
case '<a:accent3>' :
case '</a:accent3>' :
/* 20.1.4.1.4 accent4 (Accent 4) */
case '<a:accent4>' :
case '</a:accent4>' :
/* 20.1.4.1.5 accent5 (Accent 5) */
case '<a:accent5>' :
case '</a:accent5>' :
/* 20.1.4.1.6 accent6 (Accent 6) */
case '<a:accent6>' :
case '</a:accent6>' :
/* 20.1.4.1.19 hlink (Hyperlink) */
case '<a:hlink>' :
case '</a:hlink>' :
/* 20.1.4.1.15 folHlink (Followed Hyperlink) */
case '<a:folHlink>' :
case '</a:folHlink>' :
if ( y [ 0 ] [ 1 ] === '/' ) {
themes . themeElements . clrScheme . push ( color ) ;
color = { } ;
} else {
color . name = y [ 0 ] . substring ( 3 , y [ 0 ] . length - 1 ) ;
}
break ;
default : if ( opts . WTF ) throw 'unrecognized ' + y [ 0 ] + ' in clrScheme' ;
}
} ) ;
}
/* 14.2.7 Theme Part */
function parse _theme _xml ( data , opts ) {
themes . themeElements = { } ;
var t ;
/* clrScheme */
if ( ( t = data . match ( /<a:clrScheme([^>]*)>.*<\/a:clrScheme>/ ) ) ) parse _clrScheme ( t , opts ) ;
return themes ;
}
2014-05-16 00:33:34 +00:00
function write _theme ( ) { return ' < ? xml version = "1.0" encoding = "UTF-8" standalone = "yes" ? > \ n < a : theme xmlns : a = "http://schemas.openxmlformats.org/drawingml/2006/main" name = "Office Theme" > < a : themeElements > < a : clrScheme name = "Office" > < a : dk1 > < a : sysClr val = "windowText" lastClr = "000000" / > < /a:dk1><a:lt1><a:sysClr val="window" lastClr="FFFFFF"/ > < /a:lt1><a:dk2><a:srgbClr val="1F497D"/ > < /a:dk2><a:lt2><a:srgbClr val="EEECE1"/ > < /a:lt2><a:accent1><a:srgbClr val="4F81BD"/ > < /a:accent1><a:accent2><a:srgbClr val="C0504D"/ > < /a:accent2><a:accent3><a:srgbClr val="9BBB59"/ > < /a:accent3><a:accent4><a:srgbClr val="8064A2"/ > < /a:accent4><a:accent5><a:srgbClr val="4BACC6"/ > < /a:accent5><a:accent6><a:srgbClr val="F79646"/ > < /a:accent6><a:hlink><a:srgbClr val="0000FF"/ > < /a:hlink><a:folHlink><a:srgbClr val="800080"/ > < / a : f o l H l i n k > < / a : c l r S c h e m e > < a : f o n t S c h e m e n a m e = " O f f i c e " > < a : m a j o r F o n t > < a : l a t i n t y p e f a c e = " C a m b r i a " / > < a : e a t y p e f a c e = " " / > < a : c s t y p e f a c e = " " / > < a : f o n t s c r i p t = " J p a n " t y p e f a c e = " M S P ゴ シ ッ ク " / > < a : f o n t s c r i p t = " H a n g " t y p e f a c e = " 맑 은 고 딕 " / > < a : f o n t s c r i p t = " H a n s " t y p e f a c e = " 宋 体 " / > < a : f o n t s c r i p t = " H a n t " t y p e f a c e = " 新 細 明 體 " / > < a : f o n t s c r i p t = " A r a b " t y p e f a c e = " T i m e s N e w R o m a n " / > < a : f o n t s c r i p t = " H e b r " t y p e f a c e = " T i m e s N e w R o m a n " / > < a : f o n t s c r i p t = " T h a i " t y p e f a c e = " T a h o m a " / > < a : f o n t s c r i p t = " E t h i " t y p e f a c e = " N y a l a " / > < a : f o n t s c r i p t = " B e n g " t y p e f a c e = " V r i n d a " / > < a : f o n t s c r i p t = " G u j r " t y p e f a c e = " S h r u t i " / > < a : f o n t s c r i p t = " K h m r " t y p e f a c e = " M o o l B o r a n " / > < a : f o n t s c r i p t = " K n d a " t y p e f a c e = " T u n g a " / > < a : f o n t s c r i p t = " G u r u " t y p e f a c e = " R a a v i " / > < a : f o n t s c r i p t = " C a n s " t y p e f a c e = " E u p h e m i a " / > < a : f o n t s c r i p t = " C h e r " t y p e f a c e = " P l a n t a g e n e t C h e r o k e e " / > < a : f o n t s c r i p t = " Y i i i " t y p e f a c e = " M i c r o s o f t Y i B a i t i " / > < a : f o n t s c r i p t = " T i b t " t y p e f a c e = " M i c r o s o f t H i m a l a y a " / > < a : f o n t s c r i p t = " T h a a " t y p e f a c e = " M V B o l i " / > < a : f o n t s c r i p t = " D e v a " t y p e f a c e = " M a n g a l " / > < a : f o n t s c r i p t = " T e l u " t y p e f a c e = " G a u t a m i " / > < a : f o n t s c r i p t = " T a m l " t y p e f a c e = " L a t h a " / > < a : f o n t s c r i p t = " S y r c " t y p e f a c e = " E s t r a n g e l o E d e s s a " / > < a : f o n t s c r i p t = " O r y a " t y p e f a c e = " K a l i n g a " / > < a : f o n t s c r i p t = " M l y m " t y p e f a c e = " K a r t i k a " / > < a : f o n t s c r i p t = " L a o o " t y p e f a c e = " D o k C h a m p a " / > < a : f o n t s c r i p t = " S i n h " t y p e f a c e = " I s k o o l a P o t a " / > < a : f o n t s c r i p t = " M o n g " t y p e f a c e = " M o n g o l i a n B a i t i " / > < a : f o n t s c r i p t = " V i e t " t y p e f a c e = " T i m e s N e w R o m a n " / > < a : f o n t s c r i p t = " U i g h " t y p e f a c e = " M i c r o s o f t U i g h u r " / > < a : f o n t s c r i p t = " G e o r " t y p e f a c e = " S y l f a e n " / > < / a : m a j o r F o n t > < a : m i n o r F o n t > < a : l a t i n t y p e f a c e = " C a l i b r i " / > < a : e a t y p e f a c e = " " / > < a : c s t y p e f a c e = " " / > < a : f o n t s c r i p t = " J p a n " t y p e f a c e = " M S P ゴ シ ッ ク " / > < a : f o n t s c r i p t = " H a n g " t y p e f a c e = " 맑 은 고 딕 " / > < a : f o n t s c r i p t = " H a n s " t y p e f a c e = " 宋 体 " / > < a : f o n t s c r i p t = " H a n t " t y p e f a c e = " 新 細 明 體 " / > < a : f o n t s c r i p t = " A r a b " t y p e f a c e = " A r i a l " / > < a : f o n t s c r i p t = " H e b r " t y p e f a c e = " A r i a l " / > < a : f o n t s c r i p t = " T h a i " t y p e f a c e = " T a h o m a " / > < a : f o n t s c r i p t = " E t h i " t y p e f a c e = " N y a l a " / > < a : f o n t s c r i p t = " B e n g " t y p e f a c e = " V r i n d a " / > < a : f o n t s c r i p t = " G u j r " t y p e f a c e = " S h r u t i " / > < a : f o n t s c r i p t = " K h m r " t y p e f a c e = " D a u n P e n h " / > < a : f o n t s c r i p t = " K n d a " t y p e f a c e = " T u n g a " / > < a : f o n t s c r i p t = " G u r u " t y p e f a c e = " R a a v i " / > < a : f o n t s c r i p t = " C a n s " t y p e f a c e = " E u p h e m i a " / > < a : f o n t s c r i p t = " C h e r " t y p e f a c e = " P l a n t a g e n e t C h e r o k e e " / > < a : f o n t s c r i p t = " Y i i i " t y p e f a c e = " M i c r o s o f t Y i B a i t i " / > < a : f o n t s c r i p t = " T i b t " t y p e f a c e = " M i c r o s o f t H i m a l a y a " / > < a : f o n t s c r i p t = " T h a a " t y p e f a c e = " M V B o l i " / > < a : f o n t s c r i p t = " D e v a " t y p e f a c e = " M a n g a l " / > < a : f o n t s c r i p t = " T e l u " t y p e f a c e = " G a u t a m i " / > < a : f o n t s c r i p t = " T a m l " t y p e f a c e = " L a t h a " / > < a : f o n t s c r i p t = " S y r c " t y p e f a c e = " E s t r a n g e l o E d e s s a " / > < a : f o n t s c r i p t = " O r y a " t y p e f a c e = " K a l i n g a " / > < a : f o n t s c r i p t = " M l y m " t y p e f a c e = " K a r t i k a " / > < a : f o n t s c r i p t = " L a o o " t y p e f a c e = " D o k C h a m p a " / > < a : f o n t s c r i p t = " S i n h " t y p e f a c e = " I s k o o l a P o t a " / > < a : f o n t s c r i p t = " M o n g " t y p e f a c e = " M o n g o l i a n B a i t i " / > < a : f o n t s c r i p t = " V i e t " t y p e f a c e = " A r i a l " / > < a : f o n t s c r i p t = " U i g h " t y p e f a c e = " M i c r o s o f t U i g h u r " / > < a : f o n t s c r i p t = " G e o r " t y p e f a c e = " S y l f a e n " / > < / a : m i n o r F o n t > < / a : f o n t S c h e m e > < a : f m t S c h e m e n a m e = " O f f i c e " > < a : f i l l S t y l e L s t > < a : s o l i d F i l l > < a : s c h e m e C l r v a l = " p h C l r " / > < / a : s o l i d F i l l > < a : g r a d F i l l r o t W i t h S h a p e = " 1 " > < a : g s L s t > < a : g s p o s = " 0 " > < a : s c h e m e C l r v a l = " p h C l r " > < a : t i n t v a l = " 5 0 0 0 0 " / > < a : s a t M o d v a l = " 3 0 0 0 0 0 " / > < / a : s c h e m e C l r > < / a : g s > < a : g s p o s = " 3 5 0 0 0 " > < a : s c h e m e C l r v a l = " p h C l r " > < a : t i n t v a l = " 3 7 0 0 0 " / > < a : s a t M o d v a l = " 3 0 0 0 0 0 " / > < / a : s c h e m e C