Author Topic: Correct font size from LOGFONT  (Read 1615 times)

xandaz

  • Member
  • ****
  • Posts: 529
  • I luv you babe
    • My asm examples
Correct font size from LOGFONT
« on: November 04, 2021, 08:01:35 AM »
    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:
Code: [Select]
lfHeight = -MulDiv(PointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72)...and coded:
Code: [Select]
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

  • Member
  • ****
  • Posts: 578
    • Github
Re: Correct font size from LOGFONT
« Reply #1 on: November 04, 2021, 09:32:47 AM »
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
fearless

ASUS Crosshair 8 Hero, AMD 5950X, 32GB, MSI 5700XT, NZXT Kraken Z73, Seasonic 1000W PSU

Github Twitter Mastodon Gitbook

xandaz

  • Member
  • ****
  • Posts: 529
  • I luv you babe
    • My asm examples
Re: Correct font size from LOGFONT
« Reply #2 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.

daydreamer

  • Member
  • *****
  • Posts: 2399
  • my kind of REAL10 Blonde
Re: Correct font size from LOGFONT
« Reply #3 on: November 04, 2021, 09:11:43 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
http://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

  • Member
  • ****
  • Posts: 529
  • I luv you babe
    • My asm examples
Re: Correct font size from LOGFONT
« Reply #4 on: November 05, 2021, 12:17:31 AM »
    Thanks DayDreamer. I'll do just that.

Greenhorn

  • Member
  • ***
  • Posts: 493
Re: Correct font size from LOGFONT
« Reply #5 on: November 05, 2021, 09:38:57 AM »
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
« Last Edit: November 06, 2021, 11:44:21 AM by Greenhorn »
Kole Feut un Nordenwind gift en krusen Büdel un en lütten Pint.

Greenhorn

  • Member
  • ***
  • Posts: 493
Re: Correct font size from LOGFONT
« Reply #6 on: November 06, 2021, 11:50:09 AM »
Quote
iPointSize

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

  • Member
  • ****
  • Posts: 529
  • I luv you babe
    • My asm examples
Re: Correct font size from LOGFONT
« Reply #7 on: November 07, 2021, 03:20:27 AM »
   Thanks Greenhorn. I'll look into it.

xandaz

  • Member
  • ****
  • Posts: 529
  • I luv you babe
    • My asm examples
Re: Correct font size from LOGFONT
« Reply #8 on: November 07, 2021, 05:42:17 AM »
    Greenhorn. Your code doesnt work. The characters get too small. Thanks anyway.

Greenhorn

  • Member
  • ***
  • Posts: 493
Re: Correct font size from LOGFONT
« Reply #9 on: November 07, 2021, 12:59:00 PM »
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

  • Member
  • ****
  • Posts: 529
  • I luv you babe
    • My asm examples
Re: Correct font size from LOGFONT
« Reply #10 on: November 07, 2021, 09:25:21 PM »
   i was trying to match the output font size to match the font size in the ChooseFont common dialog. Thanks

xandaz

  • Member
  • ****
  • Posts: 529
  • I luv you babe
    • My asm examples
Re: Correct font size from LOGFONT
« Reply #11 on: November 09, 2021, 08:54:56 AM »
    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.
« Last Edit: November 09, 2021, 10:31:27 PM by xandaz »

xandaz

  • Member
  • ****
  • Posts: 529
  • I luv you babe
    • My asm examples
Re: Correct font size from LOGFONT
« Reply #12 on: November 10, 2021, 08:00:48 AM »
    For furher notice:
Code: [Select]
            invoke  GetDeviceCaps,chFont.hDC,LOGPIXELSY
            invoke   MulDiv,chFont.iPointSize,eax,72
     neg eax
     shl eax,1
    Works just fine.