Redo Calculation of Color Tinting (#3580)

* Redo Calculation of Color Tinting

Fix #3550. Some colors are specified in Excel by specifying a theme color to which a tint is applied. The original PHPExcel algorithm for doing this was developed by trial and error, and is good enough a lot of the time. However, for the issue at hand, the resulting color is detectably different from the calculation that Excel makes. Searching the web, I found https://gist.github.com/Mike-Honey/b36e651e9a7f1d2e1d60ce1c63b9b633 which comes much closer for the case in hand, and for all the other cases that I've looked at. That code depends on Python colorsys package; I have adapted the code from the Python gist and package into a new Php class. This doesn't agree perfectly with Excel. However, if each of the red, green, and blue components (each a value between 0 and 255 inclusive) agree within plus or minus 3 (arbitrary choice) of Excel's result, I think that is good enough.

I have added a new test member which reads from a spreadsheet with Xml altered by hand to set up several theme/tint cells. These tests use the plus-or-minus-3 criterion. They result in 100% code coverage of the new class.

Unsuprisingly, some existing tests failed with the new code. Issue2387Test reads a theme/tint font color, and is changed to use the plus-or-minus-3 criterion, comparing against the color as Excel shows it.

ColorChangeBrightness showed 9 failures with the new code. It consists of calculations not involving a spreadsheet. For that reason, I felt it was sufficient to just do an exact match test, changing the 9 old results for new results confirmed with the Python code. I also added one new test case, the one that kicked off this entire PR.

* Scrutinizer Being Stupid

It strikes again.
This commit is contained in:
oleibman
2023-05-25 13:05:55 -07:00
committed by GitHub
parent 407479f1a2
commit 9a13f526c5
6 changed files with 245 additions and 26 deletions
@@ -9,7 +9,7 @@ return [
],
// RGBA
[
'FF99A8B7',
'FF92A8BE',
'FFAABBCC',
-0.1,
],
@@ -20,17 +20,17 @@ return [
0.1,
],
[
'99A8B7',
'92A8BE',
'AABBCC',
-0.1,
],
[
'FF1919',
'FF1A1A',
'FF0000',
0.1,
],
[
'E50000',
'E60000',
'FF0000',
-0.1,
],
@@ -40,7 +40,7 @@ return [
0.1,
],
[
'E57373',
'FF5959',
'FF8080',
-0.1,
],
@@ -50,7 +50,7 @@ return [
0.15,
],
[
'D80000',
'D90000',
'FF0000',
-0.15,
],
@@ -60,18 +60,23 @@ return [
0.15,
],
[
'D86C6C',
'FF4646',
'FF8080',
-0.15,
],
[
'FFF783',
'FFF984',
'FFF008',
0.5,
],
[
'7F7804',
'847D00',
'FFF008',
-0.5,
],
'issue 3550' => [
'558ED5',
'1F497D',
0.39997558519241921,
],
];