How to Calculate Zebra Font 0 text width? - zebra-printers

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.

Related

Why are fonts of the same size displayed with different heights in different programs?

I am currently working on a GUI at a Windows 7 64-bit PC. While comparing the visualisation of text in different programs, I recognized, that there are differences in how big text is displayed on my monitor, given the same text style and size.
Does anyone has an idea where this comes from?
I created this behaviour by typing a text in Arial Regular 12pt containing the letter T in a program and scaling the view to 100%. Afterwards I measured the height of the letter T in pixels with the help of a screenshot.
Programs I testet:
MS Word 2010: T is 12 pixels high
LibreOffice Writer 5.2.7.2 (x64): T is 12 pixels high
Scribus 1.4.6: T is 12 pixels high
GIMP 2.8.14: T is 9 pixels high
Java 8 Update 181 (which I use for my own GUI): T is 9 pixels high
pt (point) is a unit for physical sizes, typically 1/72th of an inch.
In order to transfer this to a size in pixels, you need to know how many pixels will be in one inch on your screen. This value is known as Pixels Per Inch (PPI), sometimes somewhat ambiguously called Dots Per Inch (DPI).
Note that this value will usually be different for an application UI and the documents you are working on.
From the values you provided, it looks like MS Word, LibreOffice and Scribus assume 72 PPI (or at least the documents you are working on do), whereas GIMP and Java use 96 PPI.
It's not obvious whether you are referring to the size of text ion the respective applications' UI or documents opened in them, though, so I could be totally off.

HPDF units for text width and height

Maybe it's just my head spinning, but there seems to be no documentation on the units of measure for HPDF's HPDF_Font_TextWidth() function, nor can I figure it out.
The number I get for a particular text of 7 characters is around 3000. The rendered text seems to be around 80 pixels, which is also returned from HPDF_Page_TextWidth().
HPDF_Font_TextWidth() does not know the font size so it must use some other unit. What is it?
And is that the same unit that HPDF_Font_GetBBox() returns?
I'm actually trying to put text in the center of a rectangle, and need the width and height of the text in the units of the rectangle.
This is an old post but I just stumbled upon it because I had the same issue. As far as I know, looking into the source of HPDF_Font_GetUnicodeWidth(), the units that it returns needs to be multiplied by the font size, then divided by 1000 to get the width in points, which is what the rest of the PDF coordinate system uses.
width = (HPDF_Font_TextWidth() * font_size) / 1000.0;
All the following return EM units, which must be divided by 1000 and multiplied by the point size to get points, as stated above:
The units are relative to the baseline. Descender, BBox left & bottom are negative. The zone between caps Height and ascender is for diacritics.
To calculate the height of a slug of text, compute caps height less descender, or ascender less descender if your text has upper-case diacritics.
Keyword: Haru PDF

How to calculate the width (in dots) of this zpl barcode?

^XA
^FO0,90^AD^BY3
^BCN,100,Y,N,Y,A
^MD10
^FD1458622235534^FS
^XZ
Using Label Viewer I was able to play around with ZPL and after reading some documentation figured out that ^FO0,90 is what positions the barcode. 0 is for the number of dots from the left and 90 is for the number of dots from the top.
My question is, how can the width of the above bar code be calcuated in dots? If I know the width of the barcode, I can then center it programmatically.
The printer's resolution is 203dpi and given a 3' (width) x 2' (length) tag, that is 610 dots across.
What is the formula to calculate the width of a ZPL Barcode?
The Code 128 barcode includes three modes. The "A" in your ^BC means that the barcode algorithm will automatically select the best mode based on the placement of where the letters are mixed in with the numbers, and/or how many numbers are in a row. This results in barcodes that vary in length depending on their content.
You can change that A to an N. This will make the width easy to estimate, even if it's not the most space efficient.
For the N option: count 106 dots, total, for the bookends, and 33 dots for each digit.
For the N + Subset C option: If you can say for sure that you will always have an even number of digits (no letters, spaces, or other symbols). You can force the barcode into subset C mode. Count 104 dots for the bookends, and 33 dots for every two digits. But you must have an even number of digits.
^BCN,100,Y,N,Y,N
^FD>;1422335544^FS
The >; tells ZPL to render this as subset C.
If you know that you will need to support alphanumeric barcodes, then stick with the A. This is where things get harder.
You will need to model the barcode algorithm in your programming language of choice. Perhaps you could find an existing library, as Code 128 is a very popular barcode. Use the library to render the barcode in memory. You may have to play with the parameters to get it to produce a barcode equal to your ZPL output. Then have your program use the output of the library to determine the width of the barcode.
If your barcode is always going to be 13 digits, then automatic centering is a moot point. The barcode will always be the same width, even in automatic mode. Find the ^FO that looks like it's centered on the label, and stick with that. This barcode is 368 dots wide. Try ^FO121,90.
I didn't calculate the width of the barcode, I measured it by rendering the label to a Gif and then examining the label in a paint program that would let me count the dots.
I suggest you have a look at the Code 128 wikipedia article for the details.
The natural unit of length for code 128 is the narrow bar width noted x (in your ZPL code set to 3 dots). A code 128 barcode (excluding the two 10x quiet zones) is made up of
a start character (11x wide)
n encoded character of width 11x
a CRC (11x wide)
a stop character (12x wide)
If your data takes n encoded characters, the length of the barcode is (34 + n*11)x. In your case, x is 3 dots, so at 8dot/mm the barcode will be (12.75 + n*4.125)mm wide.
You have to look into the encoding to figure out n. Minimal encodings are not unique, but in your case the data will be encoded with 8 barcode characters: 6 code C character (for 6 pairs of digits), 1 switch code character and 1 code A character (for the last digit). The barcode should be 45.75mm / 366dot wide.
There is a little issue with your ZPL. You specified a UCC checkcode on a non UCC barcode. I am not familiar with UCC/GS1-128 barcodes but that might introduce extra barcode characters or be irrelevant.
Also you might consider padding your timestamp with a leading 0. With Code 128, pairs of digit have a better encoding. A 14-digit barcode will be be 4.125mm shorter.
I just mentionned the quiet zone, barcode readers require them.

Font Width Ratios: GetTextExtent32 versus Word and PDF

GetTextExtent32 returns different character width ratios (e.g., width of '9' versus space) than Word or Acrobat use when displaying the same font (e.g., 10-point Arial).
This matters because I'm trying to prepare clipboard strings that will get pasted into apps that don't support much formatting (no tabs or tables), but I still need to align certain columns of info. I'm trying to overcome this challenge by dynamically calculating the number of spaces I need to insert (remember, no tabs allowed!).
For example, calling GetTextExtent32 with a selected font of Arial 10-point gives a logical unit width of 7 for the digit '9', and a logical unit width of 4 for a space. This ratio proves correct when using something like DrawText.
However, when I export strings to Word or Acrobat, it turns out that 2 spaces in this example font exactly equals the width of one 9 (whether looking at a single 9, or nine contiguous 9s). I don't know much about fonts, but it doesn't appear to be any kind of juxtaposition issue; GetCharABCWidths shows 0 for both the a and c widths.
Does anyone know why Word and Acrobat are not showing the same proportions/measurements for a given font as Windows itself? Is there are a way to calculate this?

Twips, pixels, and points, oh my!

or "How I learned to stop worrying and learned to love measurement systems"
I wanted a central spot that I can refer to later to give me a quick low-down on various units of measurement used in programming. SO seemed the best place to put it, and while I could go ahead and answer the question myself, y'all are a much smarter bunch than I, so I might as well let you do it.
Please pick one unit that you're familiar with, use "#name" in the first line to give it as the heading (making it easy to find) and define it within your answer. Please do not duplicate - add comments or edit existing answers rather than adding a new answer. Similar units are still seperate - so please don't define em and en in the same answer. If a unit is exactly the same as another unit, add a line for "aliases" below the heading.
If it's a particularly obscure measurement type, please link to a second reference so people don't downvote you because they've never heard of it.
Point
Pica
Twips
Pixel
Em
En
CPI
DPI
I'm seeing a lot of downvoting - I suppose people believe this doesn't add value to StackOverflow's community. Please consider commenting below if you feel this doesn't add to the community, or if you think this is a bad question. I'm interested in improving it if you have any suggestions.
The great thing about standards is there are so many to choose from!
-Adam
I recommend to ammend the above answers using the following descriptions
PICA
Pica Typographic unit of measurement in the anglo-american point system. One pica is 1/72 Inch (0,351 mm) and equals 12 pica points. The didot equivalent of a pica is a cicero. A standard unit of measure in newspapers. There are 6 picas in one inch, 12 points in one pica.
PICA POINT
Pica Point 1/12 of a pica
POINT
996 points are equivalent to 35 centimeters, or one point is equal to .01383 inches. This means about 72.3 points to the inch. We in electronic printing use 72 points per inch
1 point (Truchet) = 0.188 mm (obsolete today)
1 point (Didot) = 0.376 mm = 1/72 of a French royal inch (27.07 mm)
1 point (ATA) = 0.3514598 mm = 0.013837 inch
1 point (TeX) = 0.3514598035 mm = 1/72.27 inch
1 point (Postscript) = 0.3527777778 mm = 1/72 inch
1 point (l’Imprimerie nationale, IN) = 0.4 mm
EM
An old printing term for a square-shaped blank space that’s as wide as the type is high; in other words, a 10-point em space will be 10 points wide.
EN
Half an em space; a 10-point en space will be 5 points wide.
DPI
The number of dots per inch a printer prints. The higher the dpi, the finer the resolution of the output.
PIXEL
The smallest dot you can draw on a computer screen
CPI
Counts per inch for Mouse properties and The number of horizontal characters that will fit in one inch for Printer properties
PITCH Alias CPI
Pitch describes the width of a character. Pitch equals the number of characters that can fit side-by-side in 1 inch; for example, 10 pitch equals 10 characters-per-inch or 10 CPI. Pitch is a term generally used with non-proportional (fixed-width) fonts.
TWIPS
A twip (derived from TWentieth of an Imperial Point) is a typographical measurement, defined as 1/20 of a typographical point. One twip is 1/1440 inch or 17.639 µm when derived from the PostScript point at 72 to the inch, and 1/1445.4 inch or 17.573 µm based on the printer's point at 72.27 to the inch
Additional Units:
LPI
The number of vertical lines of text that will fit in one inch
PPI
Thickness of paper, expressed in thousandths of an inch or pages per inch.
or sometimes no of horizontal pixels closely printed or displayed per inch.
FONT SIZE
Font size or Type size is the baseline distance for which the font was designed. A font should normally be identified and selected by this size, because the intended baseline distance is much more relevant for practical layout work than the actual dimensions of certain characters.
FONT HEIGHT
Font height is the height in mm of letters such as k or H. Typically, the font height is around 72% of the font size, but this is of course at the discretion of the font designer.
X-HEIGHT
x-height indicate typesize of lower-case letters excluding ascenders and descenders (from the height of the lower-case x)
H-HEIGHT
h-height or cap height refers to the height of a capital letter above the baseline for a particular typeface. It specifically refers to the height of capital letters that are flat—such as H or I—as opposed to round letters such as O.
Pixel
One of the little colored squares on your screen.
Pica
A typographical measure of 12 points, sometimes (incorrectly) called an Em. (in fact, an em is actually a horizontal distance the same as the point size of the type).
Twips
'Twentieth of an Imperial Point'. A measure used for marking up positions of widgets in Visual BASIC user interfaces. It was used this way so that positions could be specified precisely using integers. One Twip = 1/20 point = 1/1440 inch.
EM
An old printing term for a square-shaped blank space that’s as wide as the type is high; in other words, a 10-point em space will be 10 points wide.
DPI
Dots per inch. A dimensionless number used to measure the resolution of something in space, i.e. with respect to real occupied physical size.
dds complexity and headache since the standard/default DPI of a computer screen varies with the operating system. Macintosh screens generally have 72 DPI, while Windows favors 96. If you don't compensate for this when displaying images (and text), you will get unexpected variations.
Always amusing when people start talking of "the DPI of this image", for digital images such as PNG or JPEG. To me, they only have absolute pixels in them, unconnected to any physical size. If you want to print the image on a (for instance) 300 DPI printer, then you need to adapt and scale to get it correct, but the image itself only has pixels.
EN
Half an em space; a 10-point en space will be 5 points wide.
CPI
Counts per inch for Mouse properties and
The number of horizontal characters that will fit in one inch for Printer properties
PITCH Alias CPI
Pitch describes the width of a character. Pitch equals the number of characters that can fit side-by-side in 1 inch; for example, 10 pitch equals 10 characters-per-inch or 10 CPI. Pitch is a term generally used with non-proportional (fixed-width) fonts.
PostScript Point
1/72th of an inch.

Resources