Skip to content

Commit

Permalink
MDL-78785 tool_brickfield: Including rgba() processing
Browse files Browse the repository at this point in the history
  • Loading branch information
learningtechnologyservices committed Jul 31, 2024
1 parent e41e77a commit 6279e62
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -457,4 +457,4 @@ public function test_good_backgroundcssrgba() {
$results = $this->get_checker_results($html);
$this->assertEmpty($results);
}
}
}

0 comments on commit 6279e62

Please sign in to comment.