How to determine string HEIGHT and WIDTH

How to determine string HEIGHT and WIDTH

Postby avista » Sat Mar 10, 2012 1:36 pm

Hi,
Please how can i determine string HEIGHT and WIDTH if i need to SAY it with some font on dialog.
I need that to can calculate DIALOG size where i want to SAY that string using some font too.
For example:

cString := "iiiiiiiiii"
or other solution
cString := "WWWWWWWWWW"

DEFINE DIALOG oDlg SIZE ?,?
@ 0,0 SAY cString FONT oFont

I want DIALOG to have size just to SAY string on it.

Best regards,
User avatar
avista
 
Posts: 301
Joined: Fri Jun 01, 2007 9:07 am
Location: Macedonia

Re: How to determine string HEIGHT and WIDTH

Postby Antonio Linares » Sat Mar 10, 2012 3:15 pm

Try it this way:

Code: Select all  Expand view

   local oDlg, oSay, cText := "hello world"

   DEFINE DIALOG oDlg

   @ 0, 0 SAY oSay PROMPT cText OF oDlg

   ACTIVATE DIALOG oDlg CENTERED ;
      ON INIT oDlg:SetSize( oSay:nWidth, oSay:nHeight )
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42089
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: How to determine string HEIGHT and WIDTH

Postby ukoenig » Sat Mar 10, 2012 5:00 pm

Antonio,

tested, but doesn't work.
The Result :

Image

My Test and Function returns a adjusted Dialog ( a little bit more complicated ) :

Image

Some space between Dlg-top / Text-top and Dlg-bottom / Text-bottom.
Can be adjusted to Dlg-top = Text-top and Dlg-bottom = Text-bottom

A little Test-tool, selecting any Font and changing Size and Style :
( I added only a small Space for g, j, p, q and y on Bottom )
You can change the top, left, right and bottom-space.
A INI-file is used, to save and restore a Font.

Image

For the calculated Dialog-height, some Adjustments are needed.

For the Textheight :

oFont1 := TFont():New("Arial",,-nFSize,.F.,.T. ,,,,.F. )
nTxtHeight := INT( Abs( oFont1:nHeight ) ) + 22
( nFSize is selected, 22 = Height of Dialog-title )

For the calculated Textwidth and Dialog-size I used :

Code: Select all  Expand view

// -- calculated Text-width ----------------

FUNCTION TEXT_W( oSay, nTxtHeight )

hDC := oSay:GetDC()
IF oFont1:lItalic = .F. // Italic
    nTxtWidth :=  INT( GettextWidth( hDC, ALLTRIM(cText), oFont1:hFont, ) ) + 6
ELSE
    nTxtWidth :=  INT( GettextWidth( hDC, ALLTRIM(cText), oFont1:hFont, ) ) + 8
ENDIF
oSay:ReleaseDC()
oSay:nWidth := nTxtWidth
// 15 = added Space on Bottom
// ---------------------------------
oDlg2:Move( nPosT, nPosL, nTxtWidth, nTxtHeight + 15, .T. )
oSay:Refresh()

RETURN ( NIL )
 


Best regards
Uwe :?:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany


Return to FiveWin for Harbour/xHarbour

Who is online

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