Is there a way to calculate the total width of Zebra Font 0 given text? Consider the following ZPL command,
**^XA^FO100,150^A030,30^FDSample Text^FS^XZ**
Here both character height and width is 30 dots. I want to calculate the actual width of this text in mm. Please note that printer DPI is 300..............
Font 0 is a variable-width font (not monospaced like some of the others), so the width of the text will depend on the text itself.
One option would be to switch to a built-in monospaced font like font C, where each character is always 10 dots wide and the intercharacter gap is 2 dots wide (see the Zebra Programming Guide, page 1212 table 32 and page 1216 table 35). If your printer is 300 DPI, then it's 12 dpmm (dots per millimeter), and you can just do the math from there based on how many characters you have (and how many gaps between them):
"Sample Text" length = 11 characters
Intercharacter gaps = 11 - 1 = 10 intercharacter gaps
(11 characters * 10 character width) + (10 intercharacter gaps * 2 gap width) = 130 dots
130 dots / 12 dpmm = 10.8 mm
However, if you really want to use font 0, and if you know what text you want to measure, then you can try drawing a box around it using ^GB to get a rough approximation of the width.
Here's an example using your sample text, which seems to indicate that it's about 112 dots wide. At your density (12 dots per millimeter), that's a little over 9 millimeters.
来源:https://stackoverflow.com/questions/24603194/how-to-calculate-zebra-font-0-text-width