add algorithm to generate the calendar's text color

This commit is contained in:
Georg Ehrke 2012-07-01 00:09:33 +02:00
parent ce331bd1d3
commit 601237a0c3
1 changed files with 18 additions and 1 deletions

View File

@ -267,7 +267,7 @@ class OC_Calendar_Calendar{
'url' => OCP\Util::linkTo('calendar', 'ajax/events.php').'?calendar_id='.$calendar['id'],
'backgroundColor' => $calendar['calendarcolor'],
'borderColor' => '#888',
'textColor' => 'black',
'textColor' => self::generateTextColor($calendar['calendarcolor']),
'cache' => true,
);
}
@ -287,4 +287,21 @@ class OC_Calendar_Calendar{
}
return true;
}
/*
* @brief generates the text color for the calendar
* @param integer $calendarname
* @return boolean
*/
public static function generateTextColor($calendarcolor){
if(substr_count($calendarcolor, '#') == 1){
$calendarcolor = substr($calendarcolor,1);
}
$red = hexdec(substr($calendarcolor,0,2));
$green = hexdec(substr($calendarcolor,2,2));
$blue = hexdec(substr($calendarcolor,2,2));
//recommendation by W3C
$computation = ((($red * 299) + ($green * 587) + ($blue * 114)) / 1000);
return ($computation > 130)?'black':'white';
}
}