Closed proski closed 8 months ago
Actually, we want to update the code to map the saved darkness value to the actual percentage since someone might set the darkness from the command-line...
This fix has to happen over in PAPPL.
Fixes in PAPPL are here:
[master 5974fed] Fix printer-darkness web defaults.
[v1.4.x a40e52d] Fix printer-darkness web defaults.
I'm afraid you got the math wrong.
If we start with 53, darkness_configured
becomes 7: 100 * 7 / (16 - 1) - 7
Then the HTML form will try to select 7%.
In fact, 53 is a close representation of DENSITY 8 (for allowed levels from 0 to 15 inclusive) and should be shown as 53% in the web interface.
The fix calculates the scaled value/index and select based on the index instead of the percentage. I am not doing any rounding because I don't expect the driver to do any rounding for the percentages, so if the driver sets the default darkness to 50% then the "actual" (selected) darkness is (not rounded) 46% and not 53%.
darkness_supported = 16
darkness_configured = 50
darkness_value = darkness_configured * (darkness_supported - 1) / 100
darkness_value = 50 * (16 - 1) / 100
darkness_value = 50 * 15 / 100
darkness_value = 750 / 100
darkness_value = 7 [truncated from 7.5]
...
darkness_configured = 100 * darkness_value / (darkness_supported - 1)
darkness_configured = 100 * 7 / (16 - 1)
darkness_configured = 700 / 15
darkness_configured = 46 [truncated from 46.66666666666]
Two issues.
One is specifically on the 1.4.x
branch, where the result of the calculation (darkness_configured
) is compared to percent
, not to the index (i
or d
).
Another issue is that the values saved by the web interface (53) should be stable, they should not be rounded down like 50 is rounded down in your example. I don't have CUPS3 installed to test, but please try for yourself. The actual printer is not even needed. I suspect that 53 would become 46 after saving.
Please look at the code in lprint-tspl.c
, it does the rounding to the closest value, which would keep the selectable values (46, 53 etc) unchanged on save:
papplDevicePrintf(device, "DENSITY %d\n", (darkness * 15 + 50) / 100);
53% is a valid value in the web interface and will be selected on the configuration page. In contrast, 50% is not a valid value, so 0% is selected, which is misleading.
53% corresponds to the density 8 in the range from 0 to 15 inclusive, which is the TSPL default.