michaelrsweet / lprint

A Label Printer Application
https://www.msweet.org/lprint
Apache License 2.0
227 stars 31 forks source link

TSPL: Set initial darkness_configured to 53 #124

Closed proski closed 8 months ago

proski commented 8 months ago

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.

michaelrsweet commented 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...

michaelrsweet commented 8 months ago

This fix has to happen over in PAPPL.

michaelrsweet commented 8 months ago

Fixes in PAPPL are here:

[master 5974fed] Fix printer-darkness web defaults.

[v1.4.x a40e52d] Fix printer-darkness web defaults.

proski commented 7 months ago

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.

michaelrsweet commented 7 months ago

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]
proski commented 7 months ago

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);