For TD User:
I use a method in Topdown Library (in
tdCPrn3)
//~ determine text width of a
particular string in a given font
method tdcPrn3:TextWidth(cText,nWidth)
local nLen,aPts,nTxtWd,cText2,i,nLen2
cText2 := left(cText, nWidth)
nLen := len(cText2)
whil .t.
i := len(cText2)
aPts := GraQueryTextBox(::oPs,cText2)
** nTxtWd := int(((aPts[3,1] - aPts[1,1]) /
::nPPt) + 0.5)
nTxtWd := int(((aPts[3,1] - aPts[1,1]) / ::nPt) +
0.5)
if nTxtWd >= nWidth .or. i == 0 .or. len(cText2)
>= len(cText)
nLen := i
exit
else
cText2 += subs(cText, len(cText2)+1,1)
endif
enddo
return nLen
************************************************
//~ determine font point size to print a particular string in
a given width
method tdcPrn3:TextPoint(cText,nWidth)
local aPts,nTxtWd,i,cNewFont
LOCAL cOldFont :=
tdStrnum(::oFont:nominalPointSize)+"."+::oFont:compoundName
cNewFont := cOldFont
whil .t.
::newFont(cNewFont)
aPts := GraQueryTextBox(::oPs,cText)
//nTxtWd := int(((aPts[3,1] - aPts[1,1]) / ::nPPt)
+ 0.5)
nTxtWd := int(((aPts[3,1] - aPts[1,1]) / ::nPt) +
0.5)
if nTxtWd <= nWidth .or. i == 6
exit
else
i := ::oFont:nominalPointSize -1
cNewFont :=
tdStrnum(i)+"."+::oFont:compoundName
endif
enddo
::newFont(cOldFont)
return cNewFont
Anand