diff options
author | Georg Ehrke <dev@georgswebsite.de> | 2012-07-01 00:09:33 +0200 |
---|---|---|
committer | Georg Ehrke <dev@georgswebsite.de> | 2012-07-01 00:09:33 +0200 |
commit | 601237a0c3056156e272598b853827f615be86a4 (patch) | |
tree | d0e7235021c6aa704c14f451206c083d961057d8 /apps/calendar | |
parent | ce331bd1d39192d5a062f27c2a63af581063e0b6 (diff) | |
download | nextcloud-server-601237a0c3056156e272598b853827f615be86a4.tar.gz nextcloud-server-601237a0c3056156e272598b853827f615be86a4.zip |
add algorithm to generate the calendar's text color
Diffstat (limited to 'apps/calendar')
-rw-r--r-- | apps/calendar/lib/calendar.php | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/apps/calendar/lib/calendar.php b/apps/calendar/lib/calendar.php index 3fc51e39000..c8527405964 100644 --- a/apps/calendar/lib/calendar.php +++ b/apps/calendar/lib/calendar.php @@ -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'; + } } |