Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Aligning decimals in porportional fonts 1

Status
Not open for further replies.

swxmike

Programmer
Feb 21, 2005
2
US
I'm trying to figure out how to generate an aligned column of numbers on an invoice.

I figured there is either a escape command that can set a right tab? If so what would it be?

Or do I have to calculate the width of each number and comma and decimal, then set the cursor to the appropiate dot?

Anyone have any easy ways to do this?
 
1. Consult character width table of font metrics. TFM files.

2. Use LO function and print from HP-GL/2

3. If you don't have any leading minus(-) signs, you can set the horizontal motion index so a space is the same as a numeral.



Jim Asman
 
Lining up numbers using proportional fonts will always
be a nightmare. I suggest instead using a fixed font
for your numbers (i assume dollars and cents).
You can use any method you like to line up the starting position, though I recommend using H or X for horizontal
alignment then you can pad the numbers with spaces and use
the appropriate number of digits.

10,12,16.66 CPI sizes are available on most HP compatible
printers these days which should cover most situations.

for PCL5 and below, Ec(s0p10h12v0s0b0T
for 10CPI
Ec(s0p12h0s0b0T
for 12 CPI
Ec (s0p16.66h8.5v0s0b0T
for 16.66

now the 0p is fixed (1p proportional)
0b is medium weigh (4b dark)
0T is line printer typeface
 
But on most modern LaserJet printers and clones (certainly LaserJet IV and later), the LinePrinter typeface is available in only one size, because the only resident font using this typeface is a bitmap font; so the examples given above will almost certainly select the (default) Courier typeface.

Standard resident scalable fixed-pitch typefaces are:

Courier: serif, contour width 60%, typeface ID = 4099

LetterGothic: sans-serif, contour width 50%, typeface ID = 4102

[Contour width indicates the approximate ratio of width to height of the characters in the typeface]

Also, with most (but not all) standard resident fonts, the Bold variant is selected with a stroke weight of 3 (not 4).
 
Thanks for all the input. I used the input that all of the numerals in Arial were the same width. This made the process significantly easier.

With that, I determined the number of dots that a numeral was, and how many dots a comma was in the font and size that I was going to use. (in my case it was 23 and 12).

Then I determined the length of the number I was going to print, and based on the length, I calculated the number of dots past my base start point, and set the following string to the beginning of my number Ec*p[num]X where [num] was my calculated number. I added some | to the end for testing to make sure everything lined up.

For example, my start point was 2000 dots, and my number size was 9 digits. Smallest number I had was 0.00 so I didn't have to worry about the decimal.

If the number was 9 characters (99,999.99), I set Ec*p2000X to the beginning of the number.

If the number was 8 characters (9,999.99), I set Ec*p20023X.
If the number was 6 (no 7 was allowed 999.99), I set the width of 2 plus a comma or Ec*p2058X. etc.

I see if I used jlasman's idea of changing the HMI for spaces, it would have meant that I only needed to add spaces for each characters, but I couldn't figure an easy way to get past the comma.

Thanks again for all the ideas.
 
Arial fonts...

If the numerals are an even number of dots wide, then the space AND the comma are 1/2 the numeral width.
If numeral = 20 then space,comma = 20/2 = 10

If the numerals are an odd number of dots wide, then the space AND comma widths are 1/2 the numeral width rounded up.
If numeral = 21 then space, comma = (21/2)+.5 = 11

Tell me your point size and I'll give you the numeric width.

Jim Asman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top