Font height calculation to control move to a new page - OIPI (OpenInsight 32-bit Specific)
At 01 FEB 2007 08:03:49PM Mark Ford wrote:
In order to calculate the vertical space used, each time a line is printed, I need to know the height of the font and the spacing between the print line.
Is there a formula or constant that can be used to calculate the font height from the font size?
How do I set the space between print lines?
At 01 FEB 2007 10:17PM Gray Cunningham wrote:
If you are using the Set_Printer function for your printing, you can use the "CALCTEXT" message obtain the height and width of a text string (based upon the font that is currently bring used).
For example (as stolen from the online help):
stat=Set_Printer("CALCTEXT", "This is a test. ")
size=Get_Printer("CALCTEXT") ;* get the size
textWidth=size ;* width of the text
textHeight=size ;* height of the text
The interline spacing can be set using the second parameter of Set_Printer's "FONT" message.
Hope this helps…if not, then likely the regulars will jump in with assistance early next week; right now most of them are in Seattle at the conference drinking coffee (or something).
At 02 FEB 2007 11:59AM Mark Ford wrote:
Thanks Gray.
At 05 FEB 2007 10:23AM [email protected]'s Frank Tomeo wrote:
Mark,
What I use sometimes is a direct calculation of the row height. Although not exact, it does get pretty dang close. For most basic fonts (arial, times, tahoma, etc.), the formula (point-size/64) will get you close to the height of the font. Here is a simple example:
Set_Printer("FONT"[/color], [/color]"Tahoma"[/color]:[/color]@FM[/color]:[/color]11[/color]) [/color] RowHeight =[/color]11[/color]/[/color]64 [/color];[/color]* point size 11 divided by 64 [/color][/size]yPosition = 0.00 PageHeight=11.00 [/color][/size] [/color]For [/color]i=[/color]1 [/color]to [/color]NumRows Set_Printer([/color]"POS"[/color], [/color]@FM[/color]:yPosition) Set_Printer([/color]"TEXT"[/color], [/color]"My text"[/color]) yPosition += RowHeight [/color]If [/color]yPosition GE PageHeight [/color]then [/color]Set_Printer([/color]"PAGEBREAK"[/color]) yPosition=0.00 [/color]end Next [/color]i[/color][/color][/size]This eliminates the two extra Get/Set properties, which may improve performance. It also allows you to tweak the row height to get better/nicer line formating (like double or 1.5 line spacing), and allows you to keep the row height the same, even if you switch to a smaller font on any specific line.
At 06 FEB 2007 02:24PM Mark Ford wrote:
Frank,
Thanks for your excellent response. It is the solution I needed.
Mark