hey guys. I'm using ChooseFont Common-Dialog and can't get the size to match the size shown in the dialog. I found this in documentation:lfHeight = -MulDiv(PointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72)
...and coded: invoke GetDC,hWnd
mov hDC,eax
invoke GetDeviceCaps,eax,LOGPIXELSY
mov ebx,chFont.iPointSize
xor edx,edx
mul ebx
mov ebx,72
xor edx,edx
div ebx
...but still the sizes don't match the size shown in the Common Dialog. How to get the correct size for the font? Has it got something to do with the remainder members of LOGFONT? Cause i'm absolutelly certain that if i use CreateFontIndirect and put 16 for the height the font will come out ina regular size. Thanks in advance.
Might need to negate the value
https://github.com/mrfearless/ModernUI/blob/master/ModernUI/MUIPointSizeToLogicalUnit.asm
Also windows might interfere with fonts and dialog sizes when scaling - if your have a high dpi resolution monitor
Nice tip fearless but it didn't help much. It's better to find some number rather than 72.
Quote from: xandaz on November 04, 2021, 06:39:04 PM
Nice tip fearless but it didn't help much. It's better to find some number rather than 72.
Put it as variable instead of immediate 72
And loop thru several sizes and drawtext to test?
For example if the output is size 32 instead of size 16, modify div constant accordingly
Thanks DayDreamer. I'll do just that.
Hi xandaz,
try this (logical to points):
invoke GetDC,hWnd
mov hDC,eax
invoke GetDeviceCaps,eax,LOGPIXELSY
mov ebx,72
xor edx,edx
mul ebx
mov ebx,chFont.iPointSize
xor edx,edx
div ebx
Edit: This is mistaken.
Kind regards
Greenhorn
QuoteiPointSize
Type: INT
The size of the selected font, in units of 1/10 of a point. The ChooseFont function sets this value after the user closes the dialog box.
mov eax,chFont.iPointSize
xor edx,edx
div, 10
mov ebx, eax
invoke GetDC,hWnd
mov hDC,eax
invoke GetDeviceCaps,eax,LOGPIXELSY
xor edx,edx
mul ebx
mov ebx,72
xor edx,edx
div ebx
Thanks Greenhorn. I'll look into it.
Greenhorn. Your code doesnt work. The characters get too small. Thanks anyway.
It's not clear to me what you want to achieve.
Typically you use the ChooseFont dialog to create a font from the chFont.lpLogFont member just by using CreateFontIndirect.
So for what do you need chFont.iPointSize ?
i was trying to match the output font size to match the font size in the ChooseFont common dialog. Thanks
I'm using CHARFORMAT. Not WM_SETFONT. So i wanted to match CHARFORMAT.yHeight with size chosen in ChooseFont Dialog box. Still in trouble.
Thanks.
For furher notice: invoke GetDeviceCaps,chFont.hDC,LOGPIXELSY
invoke MulDiv,chFont.iPointSize,eax,72
neg eax
shl eax,1
Works just fine.