Know the size of a font selected - Resolved -

Post Reply
User avatar
Silvio.Falconi
Posts: 4956
Joined: Thu Oct 18, 2012 7:17 pm

Know the size of a font selected - Resolved -

Post by Silvio.Falconi »

I wish Know the size of the font selected and save on aGet[15]
it give me a bad number and then not insert it on get

Image

the test

Code: Select all

#include "fivewin.ch"
#include "constant.ch"


Function Test()
Local oDlg,oFont,oBold
Local ObtnSel[10]
Local cFont:=""
Local nSizeFont:=0

       Local nBottom   := 22
       Local nRight    := 102
       Local nWidth :=  Max( nRight * DLG_CHARPIX_W, 180 )
       Local nHeight := nBottom * DLG_CHARPIX_H
       local aGet[20]
       local oSay[10]

    DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
      DEFINE FONT oBold NAME "TAHOMA" SIZE 0,-14 BOLD


DEFINE DIALOG oDlg        ;
   TITLE "test sel  font"     ;
   SIZE nWidth, nHeight   PIXEL  FONT oFont    ;
   STYLE nOr( DS_MODALFRAME, WS_POPUP, WS_CAPTION,  4 ) ;
   COLOR CLR_BLACK,  nRgb( 245,244,234)


   @ 116, 5   SAY oSay[6] Prompt "Carattere"  SIZE 80,14 PIXEL OF oDlg  TRANSPARENT  FONT oBold

   @ 126, 5   GET aGet[14] VAR cFont SIZE 200,12  PIXEL OF oDlg

   @ 126, 208 GET aGet[15] VAR nSizeFont SIZE 18,12  PIXEL OF oDlg

   @ 126, 228 BTNBMP oBtnSel[4]  RESOURCE "font.bmp"  FLAT SIZE 14, 12 OF oDlg PIXEL ;
                  COLOR  nRgb(238,236,219),nRgb(238,236,219) BORDER;
                  ACTION (aFont:=ChooseFont(),;
                     cFont :=aFont[LF_FACENAME],;
                     nSizeFont:= aFont[LF_HEIGHT ],;
                     msginfo( nSizeFont),;
                  aGet[14]:refresh(),aGet[15]:refresh())


ACTIVATE DIALOG oDLG CENTER
RETURN NIL
 
Last edited by Silvio.Falconi on Tue Nov 03, 2020 6:59 pm, edited 1 time in total.
I use : FiveWin for Harbour August 2020 (Revision) - Harbour 3.2.0dev (r1712141320) - Bcc7.30 - xMate ver. 1.15.3 - PellesC
User avatar
Marc Venken
Posts: 727
Joined: Tue Jun 14, 2016 7:51 am

Re: Know the size of a font selected

Post by Marc Venken »

If you look into the aFont : there is no correct size from to font ? Strange...

For the save : it seems that the lenght of aGet[15] is to small to see it.
Marc Venken
Using: FWH 20.08 with Harbour
User avatar
Silvio.Falconi
Posts: 4956
Joined: Thu Oct 18, 2012 7:17 pm

Re: Know the size of a font selected

Post by Silvio.Falconi »

I solved it in another way
I use : FiveWin for Harbour August 2020 (Revision) - Harbour 3.2.0dev (r1712141320) - Bcc7.30 - xMate ver. 1.15.3 - PellesC
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Re: Know the size of a font selected

Post by Otto »

Hello Silvio,
would you be so kind to post the solution here.
Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org

********************************************************************
User avatar
Silvio.Falconi
Posts: 4956
Joined: Thu Oct 18, 2012 7:17 pm

Re: Know the size of a font selected

Post by Silvio.Falconi »

I made a combobox for the fonts and another for the size from 6 to 99
I use : FiveWin for Harbour August 2020 (Revision) - Harbour 3.2.0dev (r1712141320) - Bcc7.30 - xMate ver. 1.15.3 - PellesC
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: Know the size of a font selected

Post by nageswaragunupudi »

ChooseFont() function of FWH is a straight forward implementation of Windows function ChooseFont().

The font size displayed in the ChooseFont() dialog box is in "Points". This size in points is converted to font height with this formula.

Code: Select all

lfHeight = -MulDiv(PointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72)
 
https://docs.microsoft.com/en-us/window ... i-logfonta

To get the size in points, we need to use reverse formula.

Code: Select all

function FontHeightInPoints( nHeight )

   local nPoints, hDC

   nPoints := Round( Abs( nHeight ) * 72 / GetDeviceCaps( hDC := GetDC( 0 ), 90 ), 0 )
   ReleaseDC( 0, hDC )

return nPoints
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
Silvio.Falconi
Posts: 4956
Joined: Thu Oct 18, 2012 7:17 pm

Re: Know the size of a font selected

Post by Silvio.Falconi »

nageswaragunupudi wrote:ChooseFont() function of FWH is a straight forward implementation of Windows function ChooseFont().

The font size displayed in the ChooseFont() dialog box is in "Points". This size in points is converted to font height with this formula.

Code: Select all

lfHeight = -MulDiv(PointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72)
 
https://docs.microsoft.com/en-us/window ... i-logfonta

To get the size in points, we need to use reverse formula.

Code: Select all

function FontHeightInPoints( nHeight )

   local nPoints, hDC

   nPoints := Round( Abs( nHeight ) * 72 / GetDeviceCaps( hDC := GetDC( 0 ), 90 ), 0 )
   ReleaseDC( 0, hDC )

return nPoints
 
Thanks Rao
But I not understood How call that function

ACTION (aFont:=ChooseFont(),;
cFont :=aFont[LF_FACENAME],;
nSizeFont:=FontHeightInPoints( aFont[LF_HEIGHT ]),;
aGet[14]:refresh(),aGet[15]:refresh())

run ok


I need also to Know these parameters

Font name
Font size
Color
Bold
Italic
Underlined
Strikethrough


why I not see the color of the font ????

Image
I use : FiveWin for Harbour August 2020 (Revision) - Harbour 3.2.0dev (r1712141320) - Bcc7.30 - xMate ver. 1.15.3 - PellesC
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Re: Know the size of a font selected

Post by Otto »

Hello Silvio, please look into EasyReport. Here you see how to do. You have to change the pen before printing.

Best regards,
Otto


METHOD Say( nRow, nCol, cText, oFont, nWidth, nClrText, nBkMode, nPad ) CLASS VRD

IF ::oPrn:hDC = 0
RETURN NIL
ENDIF

DEFAULT oFont := ::oPrn:oFont
DEFAULT nBkMode := 1
DEFAULT nPad := 0

IF oFont != nil
oFont:Activate( ::oPrn:hDCOut )
ENDIF

// 1,2 transparent or Opaque
SetbkMode( ::oPrn:hDCOut, nBkMode )

IF nClrText != NIL
#IFDEF __HARBOUR__
SetTextColor( ::oPrn:hDCOut, nClrText )
#ELSE
SetTextCol( ::oPrn:hDCOut, nClrText )
#ENDIF
ENDIF

DO CASE
CASE nPad == 1 // right
nCol := Max( 0, nCol - ::GetTextWidth( cText, oFont ) )
CASE nPad == 2 // center
nCol := Max( 0, nCol - ( ::GetTextWidth( cText, oFont ) / 2 ) )
ENDCASE

TextOut( ::oPrn:hDCOut, nRow, nCol, cText )

IF oFont != nil
oFont:DeActivate( ::oPrn:hDCOut )
ENDIF

IF nClrText != NIL
#IFDEF __HARBOUR__
SetTextColor( ::oPrn:hDCOut, 0 )
#ELSE
SetTextCol( ::oPrn:hDCOut, 0 )
#ENDIF
ENDIF

RETURN ( NIL )
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org

********************************************************************
User avatar
Silvio.Falconi
Posts: 4956
Joined: Thu Oct 18, 2012 7:17 pm

Re: Know the size of a font selected

Post by Silvio.Falconi »

Otto wrote:Hello Silvio, please look into EasyReport. Here you see how to do. You have to change the pen before printing.

Best regards,
Otto

Perhaps you not understood what I mean

this Image is from web

Image

here , I not see bold... and color

when you make choosefont you must have

Font name
Font size
Color
Bold
Italic
Underlined
Strikethrough

I remember EasyReport save 20 type of font with 20 type of colors and it no good ( error )
on my app you can select any font you want and then it build a font when it print the text
I use : FiveWin for Harbour August 2020 (Revision) - Harbour 3.2.0dev (r1712141320) - Bcc7.30 - xMate ver. 1.15.3 - PellesC
User avatar
Silvio.Falconi
Posts: 4956
Joined: Thu Oct 18, 2012 7:17 pm

Re: Know the size of a font selected

Post by Silvio.Falconi »

I use : FiveWin for Harbour August 2020 (Revision) - Harbour 3.2.0dev (r1712141320) - Bcc7.30 - xMate ver. 1.15.3 - PellesC
Post Reply