gui\Color::toLazarus PHP Method

toLazarus() public static method

Convert a HTML hex color (#rrggbb) to Lazarus Color (integer)
public static toLazarus ( string $color ) : integer
$color string
return integer
    public static function toLazarus($color)
    {
        $color = ltrim($color, '#');
        if (!ctype_xdigit($color)) {
            throw new \InvalidArgumentException('Color must be a hexdec string');
        }
        if (strlen($color) == 3) {
            list($r, $g, $b) = str_split($color, 1);
            $r = $r . $r;
            $g = $g . $g;
            $b = $b . $b;
        } elseif (strlen($color) == 6) {
            list($r, $g, $b) = str_split($color, 2);
        } else {
            throw new \InvalidArgumentException('Color must have a valid hexdec color format');
        }
        // Lazarus uses #bbggrr
        return hexdec($b . $g . $r);
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Set the font Color
  *
  * @param string $color Color '#123456'
  *
  * @return self
  */
 public function setFontColor($color)
 {
     $this->set('font.color', Color::toLazarus($color));
     return $this;
 }
All Usage Examples Of gui\Color::toLazarus