From 6279e627a36ac79e889b93f865c5beb9f49b6839 Mon Sep 17 00:00:00 2001 From: Karen Holland Date: Wed, 31 Jul 2024 11:42:50 +0000 Subject: [PATCH] MDL-78785 tool_brickfield: Including rgba() processing --- .../brickfield_accessibility_color_test.php | 18 ++++++++++++++---- .../checks/css_text_has_contrast_test.php | 4 ++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/admin/tool/brickfield/classes/local/htmlchecker/common/brickfield_accessibility_color_test.php b/admin/tool/brickfield/classes/local/htmlchecker/common/brickfield_accessibility_color_test.php index 319864cb87f8c..f93e43e2abc86 100644 --- a/admin/tool/brickfield/classes/local/htmlchecker/common/brickfield_accessibility_color_test.php +++ b/admin/tool/brickfield/classes/local/htmlchecker/common/brickfield_accessibility_color_test.php @@ -245,7 +245,6 @@ public function luminosity(string $r, string $r2, string $g, string $g2, string return $luminosity; } - /** * Returns the decimal equivalents for a HEX color. Returns null if it cannot be determined. * @param string $color The hex color value @@ -304,9 +303,20 @@ public function convert_color(string $color): string { } // RGB values. if (strtolower(substr($color, 0, 3)) == 'rgb') { - $colors = explode(',', trim(str_replace('rgb(', '', $color), '()')); - if (count($colors) != 3) { - return false; + if (strpos($color, 'rgba') !== false) { + $tmpbg = $this->get_rgb($this->defaultbackground); + $colors = explode(',', trim(str_replace('rgba(', '', $color), '()')); + if (count($colors) != 4) { + return false; + } + $colors[0] = round(((1 - $colors[3]) * $tmpbg['r']) + ($colors[3] * $colors[0])); + $colors[1] = round((1 - $colors[3]) * $tmpbg['g']) + ($colors[3] * $colors[1]); + $colors[2] = round((1 - $colors[3]) * $tmpbg['b']) + ($colors[3] * $colors[2]); + } else { + $colors = explode(',', trim(str_replace('rgb(', '', $color), '()')); + if (count($colors) != 3) { + return false; + } } $r = intval($colors[0]); $g = intval($colors[1]); diff --git a/admin/tool/brickfield/tests/local/htmlchecker/common/checks/css_text_has_contrast_test.php b/admin/tool/brickfield/tests/local/htmlchecker/common/checks/css_text_has_contrast_test.php index 046483b12ba58..15c10e16e2151 100644 --- a/admin/tool/brickfield/tests/local/htmlchecker/common/checks/css_text_has_contrast_test.php +++ b/admin/tool/brickfield/tests/local/htmlchecker/common/checks/css_text_has_contrast_test.php @@ -348,7 +348,7 @@ public function test_check_for_largerbold_pass(): void { $this->assertEmpty($results); } - /** + /** * Test for rgb colors with insufficient contrast. */ public function test_bad_rgbcolor() { @@ -457,4 +457,4 @@ public function test_good_backgroundcssrgba() { $results = $this->get_checker_results($html); $this->assertEmpty($results); } -} \ No newline at end of file +}