How to calculate the font width, ZPL

I wanted to ask how the font width is calculated?

For example, in the ZebraDesigner program, I have a 12 pt field, the Zebra0 font

in ZPL language: ^A0I,34,33

For 203 DPI: 12 * 203 / 72 = 34

But how is the value "33" calculated?

The average character width for Zebra0 12 pt is 4 (GetTextMetrics), but I do not know how to calculate it.

Anonymous (not verified)
Hi Marius,  A font pt field

Hi Marius,  A font pt field is an approximation and differs slightly for all fonts.  This program is taking some of that variabilty into account in the calculation.  A 12pt font should (at 200DPI) be exactly 34x34 but in reality, it isn't.

It is really very difficult to determine the printed length of a string using most fonts. If you are using a monospace font, you can do it as all the characters would be the same size, but most fonts are not monospace. The font 0 in Zebra printers is not monospace. See this example:


----   -------------

The 'I' character takes up much less room than the 'M'.  If your text is natural language, it is nearly impossible to calculate the exact length.  You can either switch to a monospace font, or give yourself some allowance for the variability. If you are doing multiline, consider using the ^TB or ^FB commands to handle it for you.

Vote up!
Vote down!

Points: 0

You voted ‘up’

Mariusz P.
Thank you for your answer.

Thank you for your answer. However, I am interested in some formula to calculate the width parameter.

I do not want to determine the printed length of a string.

Let's assume that for ^A0I,34,33  x = 34 and y = 33

Parameters x and y does not depend on what I write in the text field (and from the length of the text).

According to documentation for zebra0 font matrix h x w (in dots) = 15 x 12

So for x = 34, y should be 27 not 33. Am I understand it correctly?

I want to write a program for analyzing ZPL files and I would like to detect if the user

changed the width of the text field in ZebraDesigner and how much.

I want to replace this ^A parameter with graphic field ^GF and I want to know the font width.

Vote up!
Vote down!

Points: 0

You voted ‘up’

Log in to post comments