GetTextWidth(oPrn:hDc,cText,oFont)

GetTextWidth(oPrn:hDc,cText,oFont)

Postby Frank Demont » 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



Code: Select all  Expand view
# 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
Frank Demont
 
Posts: 142
Joined: Sun Oct 09, 2005 10:59 am

Postby Antonio Linares » Sat Jan 20, 2007 6: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
User avatar
Antonio Linares
Site Admin
 
Posts: 41937
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 81 guests