public function contrastColors($backgroundColor)
 {
     $background = Color::stringToRgb24($backgroundColor);
     $this->string = preg_replace_callback('/(?<!\\$)((?:\\$[\\$])*)(\\$[0-9a-f][^\\$]{0,2})/iu', function ($matches) use($background) {
         $color = Color::stringToRgb24($matches[2]);
         $color = Color::contrast($color, $background);
         $color = Color::rgb24ToRgb12($color);
         $color = Color::rgb12ToString($color);
         return $matches[1] . '$' . $color;
     }, $this->string);
     return $this;
 }
Beispiel #2
0
 protected function none($value)
 {
     $style = '';
     if ($this->currentStyle->getColor()) {
         $color = Color::stringToRgb24($this->currentStyle->getColor());
         $style .= sprintf('color:#%s;', Color::rgb24ToString($color));
     }
     switch ($this->currentStyle->getWidth()) {
         case 0:
             $style .= 'letter-spacing:-.1em;font-size:95%;';
             break;
         case 2:
             $style .= 'letter-spacing:.1em;font-size:105%;';
             break;
         case 1:
         default:
     }
     if ($this->currentStyle->isBold()) {
         $style .= 'font-weight:bold;';
     }
     if ($this->currentStyle->isItalic()) {
         $style .= 'font-style:italic;';
     }
     if ($this->currentStyle->isShadowed()) {
         $style .= 'text-shadow:1px 1px 1px rgba(0,0,0,.5);';
     }
     if ($this->currentStyle->isUppercase()) {
         $style .= 'text-transform:uppercase;';
     }
     if ($style) {
         $value = sprintf('<span style="%s">%s</span>', $style, $value);
     }
     if ($this->link) {
         if (parse_url($this->link, PHP_URL_SCHEME) !== null) {
             $link = $this->link;
         } else {
             $link = 'http://' . $this->link;
         }
         $value = sprintf('<a href="%s" style="color:inherit;">%s</a>', $link, $value);
     }
     $this->result .= $value;
 }
Beispiel #3
0
 /**
  * @dataProvider rgb24ToStringProvider
  */
 public function testStringToRgb12String($input, $expected)
 {
     $rgb24 = Color::stringToRgb24($input);
     $rgb12 = Color::rgb24ToRgb12($rgb24);
     $this->assertEquals($expected, Color::rgb12ToString($rgb12));
 }