Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Calculating Text Length based on Field Object Size
Message
De
10/09/2004 16:26:21
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
10/09/2004 15:47:11
Jay Johengen
Altamahaw-Ossipee, Caroline du Nord, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire de rapports & Rapports
Divers
Thread ID:
00941206
Message ID:
00941221
Vues:
8
>Searched and found lots of stuff almost related to this, but nothing that really helped. If I know that the field object in the report has a width of 1.4 (somethings) and the font is Arial and the size is 10 and the style is regular, how can I determine the number of characters that can fit without truncating or wrapping? I've played around a bunch with FontMetric and TxtWidth, but I guess the biggest problem is not knowing what measure the reports "1.4" is. Inches? Then does 10 point mean 10 average characters per inch? Seems harder than it should be, but maybe I'm just making it that way.

Jay,
1.4 inches = 1.4 * 1440 twips (1 inch = 72 points, 1 point = 20 twips)
You should first determine pixels per inch (aspect ratio 96 but might differ - winAPI, thanks to George Tasker) :
* Form.PixelsToTwips custom method
#Define cnLOG_PIXELS_X 88
#Define cnLOG_PIXELS_Y 90
#Define cnTWIPS_PER_INCH 1440
*-- Code for PixelToTwips method
Local liHWnd, liHDC, liPixelsPerInchX, liPixelsPerInchY

* Declare some Windows API functions.
Declare Integer GetActiveWindow In WIN32API
Declare Integer GetDC In WIN32API Integer iHDC
Declare Integer GetDeviceCaps In WIN32API Integer iHDC, Integer iIndex

* Get a device context for VFP.
liHWnd = GetActiveWindow()
liHDC = GetDC(liHWnd)

* Get the pixels per inch.
liPixelsPerInchX = GetDeviceCaps(liHDC, cnLOG_PIXELS_X)
liPixelsPerInchY = GetDeviceCaps(liHDC, cnLOG_PIXELS_Y)

* Get the twips per pixel.
This.nxtwips = ( cnTWIPS_PER_INCH / liPixelsPerInchX )
This.nytwips = ( cnTWIPS_PER_INCH / liPixelsPerInchY )
Code returning width in points.
Procedure GetPts
Lparameters tcText, tnPixelsPerInch, tcFont, tnFontSize, tnStyle
Local lcStyle
lcStyle = Iif( Empty(tnStyle), 'N',;
	Iif(Bittest(tnStyle,0),'B','')+;
	Iif(Bittest(tnStyle,1),'I','')+;
	Iif(Bittest(tnStyle,2),'U','') )
lnSizeInPixels = ;
   Txtwidth(tcText, tcFont, tnFontSize,lcStyle) * Fontmetric(6, tcFont, tnFontSize,lcStyle)
Return ( lnSizeInPixels  / tnPixelsPerInch * 1440 ) / 20
* 1 Twip = 1/20 point, 567 twips 1 cm
Endproc
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform