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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Fontmetric Function To Justify Text

Status
Not open for further replies.

codetyko

Programmer
May 26, 2001
73
MY
I have written a routine to justify text for output using the following method:

1) SET MEMOWIDTH to the desired length
2) Use MEMLINES to get the Number of Lines
3) For each line, calculate the number of spaces between words
4) Insert extra spaces evenly based on the above calculation so that the LEN(line(1)) equals to the desired length.
5) Rearrange the "processed" lines by inserting a "CHR(13)" for single space or "CHR(13)+CHR(13)" for double space and resave the text block to the memo field.

The above method has been successful for the font of type "Courier New" of any size but when used with other fonts, the result is the normal "wrapped text" style. I come to understand that different fonts has different characteristics which will affect the end result and the function FONTMETRIC() is used to measure these characteristics.

The question is:

Is there anybody who has used FONTMETRIC()extensively for the purpose of character type data manipulation and the tricks involved to arrive at the text justification method described above.

Any suggestion would be appreciated.
 
Hi;

Your method will be successful with 'Courier New' because it is a fixed font. For example the letter "I" is just as wide as the letter "W". If you switch to a Proportional Font your math will not work. FONTMETRIC() will only give you the average character width. You need to be able to access the width table for the font you are trying to use to get the width of each character. I am not aware of any way to do that in FP. That does not mean it can't be done. There are many experts here to help.

P.S.
There is a program called BitCopy that does a lot of magic with Fonts including giving you the entire width table. Please let me know if the sugestion(s) I provide are helpful to you.
Sometimes your the windshield... Sometimes your the bug.

 
Take a look at these functions:

WCOLS()
TXTWIDTH()

They might also help you out. I have used them for centering text regularly.

Dave S.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top