/** * The WCAG specification specifies two thresholds for AA and AAA compliance. * One specifies the threshold for large text, the other is for any sized * text. AA and AAA specify different thresholds. * * @param ColorContext $color * The color to analyze. * @param float $anySizeThreshold * The minimum threshold for luminosity for any text. * @param float $largeTextThreshold * The minimum threshold for luminosity for large text. * * @return string */ private function calculateWcagCompliance(ColorContext $color, $anySizeThreshold, $largeTextThreshold) { if ($color->diffLuminosity() >= $anySizeThreshold) { return 'Yes'; } elseif ($color->diffLuminosity() >= $largeTextThreshold) { return 'Large'; } return 'No'; }
public function columnValue(ColorContext $color) { switch ($this->layer) { case self::BACKGROUND: return $this->formatClass->formatColor($this->resolveColor($color->background())); case self::FOREGROUND: return $this->formatClass->formatColor($this->resolveColor($color->foreground())); } return NULL; }
public function blendColors(\OttawaDeveloper\Tools\ColorAnalyzer\ColorContext $context) { $convertedBackgroundAlpha = $context->background()->alpha() * (1 - $context->foreground()->alpha()); $resultAlpha = $context->foreground()->alpha() + $convertedBackgroundAlpha; // Tiny result alphas means that the color is transparent, so we just // return a transparent color. if ($resultAlpha < 0.001) { return new \OttawaDeveloper\Tools\ColorAnalyzer\BlendedColor($context->foreground(), $context->background(), 0, 0, 0, 0); } return new \OttawaDeveloper\Tools\ColorAnalyzer\BlendedColor($context->foreground(), $context->background(), $this->blendColorComponent($context->foreground()->red(), $context->background()->red(), $context->foreground()->alpha(), $context->background()->alpha(), $resultAlpha), $this->blendColorComponent($context->foreground()->green(), $context->background()->green(), $context->foreground()->alpha(), $context->background()->alpha(), $resultAlpha), $this->blendColorComponent($context->foreground()->blue(), $context->background()->blue(), $context->foreground()->alpha(), $context->background()->alpha(), $resultAlpha), $resultAlpha); }
public function columnValue(ColorContext $color) { return number_format(round($color->diffLuminosity(), $this->decimals), $this->decimals); }