Know the size of a font selected - Resolved -
Posted:
Thu Oct 29, 2020 9:17 am
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
the test
- Code: Select all Expand view
#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
Re: Know the size of a font selected
Posted:
Thu Oct 29, 2020 11:13 pm
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.
Re: Know the size of a font selected
Posted:
Fri Oct 30, 2020 7:50 am
by Silvio.Falconi
I solved it in another way
Re: Know the size of a font selected
Posted:
Fri Oct 30, 2020 8:30 am
by Otto
Hello Silvio,
would you be so kind to post the solution here.
Best regards,
Otto
Re: Know the size of a font selected
Posted:
Fri Oct 30, 2020 8:37 am
by Silvio.Falconi
I made a combobox for the fonts and another for the size from 6 to 99
Re: Know the size of a font selected
Posted:
Sun Nov 01, 2020 5:32 pm
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 Expand view
lfHeight = -MulDiv(PointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72)
https://docs.microsoft.com/en-us/window ... i-logfontaTo get the size in points, we need to use reverse formula.
- Code: Select all Expand view
function FontHeightInPoints( nHeight )
local nPoints, hDC
nPoints := Round( Abs( nHeight ) * 72 / GetDeviceCaps( hDC := GetDC( 0 ), 90 ), 0 )
ReleaseDC( 0, hDC )
return nPoints
Re: Know the size of a font selected
Posted:
Tue Nov 03, 2020 9:58 am
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 Expand view
lfHeight = -MulDiv(PointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72)
https://docs.microsoft.com/en-us/window ... i-logfontaTo get the size in points, we need to use reverse formula.
- Code: Select all Expand view
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 ????
Re: Know the size of a font selected
Posted:
Tue Nov 03, 2020 10:56 am
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 )
Re: Know the size of a font selected
Posted:
Tue Nov 03, 2020 12:44 pm
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
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