News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Correct font size from LOGFONT

Started by xandaz, November 04, 2021, 08:01:35 AM

Previous topic - Next topic

xandaz

    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.

fearless

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

xandaz

    Nice tip fearless but it didn't help much. It's better to find some number rather than 72.

daydreamer

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
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

xandaz

    Thanks DayDreamer. I'll do just that.

Greenhorn

#5
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
Kole Feut un Nordenwind gift en krusen Büdel un en lütten Pint.

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
Kole Feut un Nordenwind gift en krusen Büdel un en lütten Pint.

xandaz

   Thanks Greenhorn. I'll look into it.

xandaz

    Greenhorn. Your code doesnt work. The characters get too small. Thanks anyway.

Greenhorn

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 ?
Kole Feut un Nordenwind gift en krusen Büdel un en lütten Pint.

xandaz

   i was trying to match the output font size to match the font size in the ChooseFont common dialog. Thanks

xandaz

#11
    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.

xandaz

    For furher notice:            invoke  GetDeviceCaps,chFont.hDC,LOGPIXELSY
            invoke   MulDiv,chFont.iPointSize,eax,72
     neg eax
     shl eax,1

    Works just fine.