예제 #1
0
 protected function colorSequence($hex, $background = false)
 {
     $rgb = ColorUtils::hex2rgb($hex);
     $escSeq = "[" . ($background ? "48;" : "38;");
     if ($this->colorDistanceAlgorithm !== 'none') {
         $lab = ColorUtils::xyz2lab(ColorUtils::rgb2xyz(ColorUtils::normalizeRgb($rgb)));
         $nearestColor = ColorUtils::nearestColor(self::$XTERM256COLOR, $lab, $this->colorDistanceAlgorithm, true, "xterm256color");
         return $escSeq . "5;" . $nearestColor . "m";
     }
     return $escSeq . "2;" . implode(';', $rgb) . "m";
 }
예제 #2
0
 public function getBackgroundColour()
 {
     if (($col = $this->css->value('code', 'bgcolor', null)) !== null) {
         if (preg_match('/^#[a-f0-9]{6}$/i', $col)) {
             $rgb = ColorUtils::normalizeRgb(ColorUtils::hex2rgb($col), true);
         }
         array_map(function ($n) {
             return round($n, 2);
         }, $rgb);
         $colStr = "{$rgb[0]}, {$rgb[1]}, {$rgb['2']}";
         return "\\pagecolor[rgb]{{$colStr}}";
     }
     return "";
 }