Changeset 653:594954ba44b6
- Timestamp:
- 07/26/11 07:13:02 (14 years ago)
- Branch:
- themes
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
themes/ductile/_config.php
r649 r653 83 83 } 84 84 85 function computeContrastRatio($c ,$b)85 function computeContrastRatio($color,$background) 86 86 { 87 87 // Compute contrast ratio between two colors 88 88 89 $c = adjustColor($c);90 if (($c == '') || (strlen($c) != 7)) return 0;91 $b = adjustColor($b);92 if (($b == '') || (strlen($b) != 7)) return 0;89 $color = adjustColor($color); 90 if (($color == '') || (strlen($color) != 7)) return 0; 91 $background = adjustColor($background); 92 if (($background == '') || (strlen($background) != 7)) return 0; 93 93 94 $l1 = (0.2126 * pow(hexdec(substr($c,1,2))/255,2.2)) + (0.7152 * pow(hexdec(substr($c,3,2))/255,2.2)) + (0.0722 * pow(hexdec(substr($c,5,2))/255,2.2)); 95 $l2 = (0.2126 * pow(hexdec(substr($b,1,2))/255,2.2)) + (0.7152 * pow(hexdec(substr($b,3,2))/255,2.2)) + (0.0722 * pow(hexdec(substr($b,5,2))/255,2.2)); 94 $l1 = (0.2126 * pow(hexdec(substr($color,1,2))/255,2.2)) + 95 (0.7152 * pow(hexdec(substr($color,3,2))/255,2.2)) + 96 (0.0722 * pow(hexdec(substr($color,5,2))/255,2.2)); 97 98 $l2 = (0.2126 * pow(hexdec(substr($background,1,2))/255,2.2)) + 99 (0.7152 * pow(hexdec(substr($background,3,2))/255,2.2)) + 100 (0.0722 * pow(hexdec(substr($background,5,2))/255,2.2)); 96 101 97 102 if ($l1 > $l2) { 98 $r = ($l1 + 0.05) / ($l2 + 0.05);103 $ratio = ($l1 + 0.05) / ($l2 + 0.05); 99 104 } else { 100 $r = ($l2 + 0.05) / ($l1 + 0.05); 101 } 102 return $r; 103 } 104 105 function contrastRatio($c,$b) { 106 if (($c != '') && ($b != '')) { 107 $r = computeContrastRatio($c,$b); 108 return '<span style="position:absolute;top:0;left:23em;">('.sprintf(__('contrast ratio = %.1f:1'),$r).')</span>'; 105 $ratio = ($l2 + 0.05) / ($l1 + 0.05); 106 } 107 return $ratio; 108 } 109 110 function contrastRatioLevel($ratio,$size,$bold) 111 { 112 if ($size == '') { 113 return ''; 114 } 115 116 // Eval font size in em (assume base font size in pixels equal to 16) 117 if (preg_match('/^([0-9.]+)\s*(%|pt|px|em|ex)?$/',$size,$m)) { 118 if (empty($m[2])) { 119 $m[2] = 'em'; 120 } 121 } else { 122 return ''; 123 } 124 switch ($m[2]) { 125 case '%': 126 $s = (float) $m[1] / 100; 127 break; 128 case 'pt': 129 $s = (float) $m[1] / 12; 130 break; 131 case 'px': 132 $s = (float) $m[1] / 16; 133 break; 134 case 'em': 135 $s = (float) $m[1]; 136 break; 137 case 'ex': 138 $s = (float) $m[1] / 2; 139 break; 140 default: 141 return ''; 142 } 143 144 $large = ((($s > 1.5) && ($bold == false)) || (($s > 1.2) && ($bold == true))); 145 146 // Check ratio 147 if ($ratio > 7) { 148 return 'AAA'; 149 } elseif (($ratio > 4.5) && $large) { 150 return 'AAA'; 151 } elseif ($ratio > 4.5) { 152 return 'AA'; 153 } elseif (($ratio > 3) && $large) { 154 return 'AA'; 155 } 156 return ''; 157 } 158 159 function contrastRatio($color,$background,$size='',$bold=false) 160 { 161 if (($color != '') && ($background != '')) { 162 $ratio = computeContrastRatio($color,$background); 163 $level = contrastRatioLevel($ratio,$size,$bold); 164 return 165 '<span style="position:absolute;top:0;left:23em;">('. 166 sprintf(__('contrast ratio = %.1f:1'),$ratio). 167 ($level != '' ? ' / '.sprintf(__('WCAG %s'),$level) : ''). 168 ')</span>'; 109 169 } 110 170 return ''; … … 414 474 415 475 '<p class="field picker"><label for="blog_title_c">'.__('Color:').'</label> '. 416 form::field('blog_title_c',7,7,$ductile_user['blog_title_c'],'colorpicker').contrastRatio($ductile_user['blog_title_c'],'#ffffff').'</p>'. 476 form::field('blog_title_c',7,7,$ductile_user['blog_title_c'],'colorpicker'). 477 contrastRatio($ductile_user['blog_title_c'],'#ffffff', 478 (!empty($ductile_user['blog_title_s']) ? $ductile_user['blog_title_s'] : '2em'), 479 $ductile_user['blog_title_w']). 480 '</p>'. 417 481 '</fieldset>'; 418 482 … … 428 492 429 493 '<p class="field picker"><label for="post_title_c">'.__('Color:').'</label> '. 430 form::field('post_title_c',7,7,$ductile_user['post_title_c'],'colorpicker').contrastRatio($ductile_user['post_title_c'],'#ffffff').'</p>'. 494 form::field('post_title_c',7,7,$ductile_user['post_title_c'],'colorpicker'). 495 contrastRatio($ductile_user['post_title_c'],'#ffffff', 496 (!empty($ductile_user['post_title_s']) ? $ductile_user['post_title_s'] : '2.5em'), 497 $ductile_user['post_title_w']). 498 '</p>'. 431 499 '</fieldset>'; 432 500 … … 437 505 438 506 '<p class="field picker"><label for="post_simple_title_c">'.__('Color:').'</label> '. 439 form::field('post_simple_title_c',7,7,$ductile_user['post_simple_title_c'],'colorpicker').contrastRatio($ductile_user['post_simple_title_c'],'#ffffff').'</p>'. 507 form::field('post_simple_title_c',7,7,$ductile_user['post_simple_title_c'],'colorpicker'). 508 contrastRatio($ductile_user['post_simple_title_c'],'#ffffff', 509 '1.1em', // H5 minimum size 510 false). 511 '</p>'. 440 512 '</fieldset>'; 441 513 … … 445 517 446 518 '<p class="field picker"><label for="post_link_v_c">'.__('Normal and visited links color:').'</label> '. 447 form::field('post_link_v_c',7,7,$ductile_user['post_link_v_c'],'colorpicker').contrastRatio($ductile_user['post_link_v_c'],'#ffffff').'</p>'. 519 form::field('post_link_v_c',7,7,$ductile_user['post_link_v_c'],'colorpicker'). 520 contrastRatio($ductile_user['post_link_v_c'],'#ffffff', 521 '1em', 522 $ductile_user['post_link_w']). 523 '</p>'. 448 524 449 525 '<p class="field picker"><label for="post_link_f_c">'.__('Active, hover and focus links color:').'</label> '. 450 form::field('post_link_f_c',7,7,$ductile_user['post_link_f_c'],'colorpicker').contrastRatio($ductile_user['post_link_f_c'],'#ebebee').'</p>'. 526 form::field('post_link_f_c',7,7,$ductile_user['post_link_f_c'],'colorpicker'). 527 contrastRatio($ductile_user['post_link_f_c'],'#ebebee', 528 '1em', 529 $ductile_user['post_link_w']). 530 '</p>'. 451 531 '</fieldset>'; 452 532 … … 464 544 465 545 '<p class="field picker"><label for="blog_title_c_m">'.__('Color:').'</label> '. 466 form::field('blog_title_c_m',7,7,$ductile_user['blog_title_c_m'],'colorpicker').contrastRatio($ductile_user['blog_title_c_m'],'#d7d7dc').'</p>'. 546 form::field('blog_title_c_m',7,7,$ductile_user['blog_title_c_m'],'colorpicker'). 547 contrastRatio($ductile_user['blog_title_c_m'],'#d7d7dc', 548 (!empty($ductile_user['blog_title_s_m']) ? $ductile_user['blog_title_s_m'] : '1.8em'), 549 $ductile_user['blog_title_w_m']). 550 '</p>'. 467 551 '</fieldset>'; 468 552 … … 478 562 479 563 '<p class="field picker"><label for="post_title_c_m">'.__('Color:').'</label> '. 480 form::field('post_title_c_m',7,7,$ductile_user['post_title_c_m'],'colorpicker').contrastRatio($ductile_user['post_title_c_m'],'#ffffff').'</p>'. 564 form::field('post_title_c_m',7,7,$ductile_user['post_title_c_m'],'colorpicker'). 565 contrastRatio($ductile_user['post_title_c_m'],'#ffffff', 566 (!empty($ductile_user['post_title_s_m']) ? $ductile_user['post_title_s_m'] : '1.5em'), 567 $ductile_user['post_title_w_m']). 568 '</p>'. 481 569 '</fieldset>'; 482 570
Note: See TracChangeset
for help on using the changeset viewer.