Smaller fonts for printing on 9mm label (centering problem)
abetis opened this issue · 9 comments
Hi,
Great script! I can now finally have an option to print labels from my storage management system...
But... I use 9mm labels and the font site looks too large.
I've found that I can set the _MAX_BYTES_PER_LINE to 6 to have better result (just reduced the number proportional to label height), now the font looks correct, but it's not properly centered.
The printout have more space above the font and less below it.
The font also looks a bit cut from the top, like a row of a bitmap is missing...
I can't figure out from the code what should I change...
Could you please help with that? Thanks.
I've also tried to leave the _MAX_BYTES_PER_LINE the same as for 12mm, but reduce the FONT_SIZERATIO to make the font smaller.
That works ok, but in order to center the text vertically I've changed that line:
lineposition = int(round(i * lineheight)) + (lineheight-fontsize)/2 - 1
That brings me to conclusion that there is a place in the code that hardcoded relies on the fact that the label height is 8 (or 64) and not using the _MAX_BYTES_PER_LINE. Otherwise I don't see a reason why the printed text would be cut from the top when I change that define to 6 for 9mm labels.
Will appreciate a help with that. Thanks.
Another update:
It looks like the font is cut on the top issue is related to it's size somehow...
Probably some sizes are not properly calculated somewhere (rounding?) and that cause the cutting.
I've played with different FONT_SIZERATIO, and it looks like "more generic" numbers produce non-cut printouts. For example 6/8 ratio prints ok, 6.5/8 will be cut
If any spare time, i'd like to re-factor the code to
- apply to python module best practices
- split up classes to several files and
- add e.g. "Label" class, having a width and collecting all printables
- add e.g. "LabelChunk" representing a printable QR, Text, Barcode whatever piece
The idea is: Create a new Label with a width, consecutively add Chunks, Handover the Label to the DymoPrinter which opens a device, does the scaling / margin calculation and prints.
So a Chunk may be an image with 1024x768 px resolution gets scaled down to fit exactly the given tape.
So the code gets more flexible. Also for Automation and Frontend additions
Sounds like a good plan.
Not sure I could help with Python, don't like it too much, but I could try to help.
Do you know if all the label widths have the same resolution?
The default code use 12mm tape with 64 pixels.
Those 64 pixels are printed very well on 9mm tape I use, just the font is too large for that I'm used to...
Should the code always use 64 pixels for all tape widths?
I believe that's the printhead possible resolution, so actually why not... Just need to use a smaller font.
Maybe useful here: #20
I'm ok for now with the following line change to center the font:
lineposition = int(round(i * lineheight)) + (lineheight-fontsize)/2 - 2
Can't explain the -2 at the end, but that moves the print to a more centered position.
For the 9mm I've decided to leave the _MAX_BYTES_PER_LINE = 8 (==> 64 pixels) since I think that is the correct printhead configuration.
All I did is lowered the font size to:
FONT_SIZERATIO = 6./8
The windows application limits the max font size when changing the label width, maybe that's all it actually is doing.
And I've also changed the rotation orientation to match the windows version printouts (got used to that direction already). That line changed (from 270 to 90):
labelrotated = labelbitmap.transpose(Image.ROTATE_90)
And I've also changed the rotation orientation to match the windows version printouts (got used to that direction already). That line changed (from 270 to 90):
labelrotated = labelbitmap.transpose(Image.ROTATE_90)
If possible, please provide a command-line switch, to specify the direction of printing.
Thank you for giving an open source project something back!
I think 90deg rotation should be the default to behave the same way as the original drivers do.
Rotating to 270deg should be done using a switch (or a config file with default options).