FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour GetTextWidth(oPrn:hDc,cText,oFont)
Posts: 142
Joined: Sun Oct 09, 2005 10:59 AM
GetTextWidth(oPrn:hDc,cText,oFont)
Posted: Sat Jan 20, 2007 11:18 AM
Hello

Using ARIAL as font , i noticed that Gettextwidth didn't give the right result
1) oPrn:Say(nRow,10*KolStap,LEFT(cText,71),oFont)
nKol := 10*KolStap + GetTextWidth(oPrn:hDc,LEFT(cText,71),oFont)
oPrn:Say(nRow,nKol,SUBSTR(cText,72),oFont)
Should give a text without white space , it isn't

2)tracelog(GetTextWidth(oPrn:hDc,LEFT(cText,71),oFont) , 52.9*Kolstap)
Shows the difference between calculated and real :
Type: N >>> 3218<<<
Type: N >>> 2645.0<<<

Can the real length be calculated ?

Frank



# include "FiveWin.ch"
# include "common.ch"
STATIC oPrn , oFont , Kolstap , nKol
FUNC MAIN
LOCAL  i
LOCAL cText := "Gelieve hier het e-mailadres te noteren voor ontvangst responsbestand. Indien u een andere type bestand als xls wenst, gelieve het bestandsformaat en record lay-out aan ons door te geven."

LOCAL nRowStep , nRow := 1
Kolstap := 50

PRINT oPrn NAME "Testing the printer object from FiveWin" PREVIEW MODAL
DEFINE FONT oFont NAME "ARIAL" SIZE 0, -10 OF oPrn                     

nRowStep := oPrn:nVertRes()/60

PAGE
nRow += nRowStep
oPrn:Say(nRow,10*KolStap,LEFT(cText,71),oFont)
nKol := 10*KolStap + GetTextWidth(oPrn:hDc,LEFT(cText,71),oFont)
oPrn:Say(nRow,nKol,SUBSTR(cText,72),oFont)
oPrn:Say(nRow,63.3*KolStap,"I")
tracelog(GetTextWidth(oPrn:hDc,LEFT(cText,71),oFont) , 52.9*Kolstap) 
nRow += nRowStep
nKol := 10*KolStap
FOR i := 1 TO 71
	oPrn:say(nRow,nKol,cText[i],oFont)
	nKol += GetTextWidth(oPrn:hDc,cText[i],oFont)
NEXT
ENDPAGE
ENDPRINT
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
GetTextWidth(oPrn:hDc,cText,oFont)
Posted: Sat Jan 20, 2007 06:09 PM

Frank,

FW GetTextWidth() uses WinAPI GetTextExtent(). From its docs:

"Since some devices do not place characters in regular cell arrays (that is, they kern characters), the sum of the extents of the characters in a string may not be equal to the extent of the string."

regards, saludos

Antonio Linares
www.fivetechsoft.com

Continue the discussion