Page 1 of 2

Ignoring the DPI font settings on Windows

Posted: Thu Feb 05, 2015 11:37 am
by marcoagpinto
Hello!

I tried my PhD project on mum's computer last week and she has the font DPI above the normal (her computer has a higher resolution).

So, my text appeared too big when I ran the project.

Is there a way of overriding the settings?

Thanks!

Kind regards,
>Marco A.G.Pinto
---------------

Re: Ignoring the DPI font settings on Windows

Posted: Thu Feb 05, 2015 1:18 pm
by IdeasVacuum
If only Windows, you can use the API to get the actual DPI and then factor the font size:

Code: Select all

Global              igDpi.i = GetDeviceCaps_(GetDC_(0),#LOGPIXELSX)
Global              iFS09.i = ((09 * 100) / igDpi)
Global              iFS10.i = ((10 * 100) / igDpi)
Global              iFS12.i = ((12 * 100) / igDpi)
Global        igFontGui09.i = LoadFont(1, "Microsoft Sans Serif", iFS09, #PB_Font_HighQuality + 2)
Global        igFontGui10.i = LoadFont(2, "Microsoft Sans Serif", iFS10, #PB_Font_Bold | #PB_Font_HighQuality + 2)
Global        igFontGui12.i = LoadFont(3, "Microsoft Sans Serif", iFS12, #PB_Font_Bold | #PB_Font_HighQuality + 2)

Re: Ignoring the DPI font settings on Windows

Posted: Thu Feb 05, 2015 8:14 pm
by uwekel
marcoagpinto wrote:Is there a way of overriding the settings?
The question should be: "Is there a way to layout the gadgets properly to fulfill the needs of the user?" :) There must be a reason why a user sets a larger dpi value! In my case, i also use 125% on Windows at my office, because otherwise the very small letters are very difficult to read. Unfortunately, on Windows, the a lot of programs do not layout properly or just overwrite the customized settings. Poor :-(

Re: Ignoring the DPI font settings on Windows

Posted: Thu Feb 05, 2015 9:13 pm
by marcoagpinto
Hello!
IdeasVacuum wrote:If only Windows, you can use the API to get the actual DPI and then factor the font size:

Code: Select all

Global              igDpi.i = GetDeviceCaps_(GetDC_(0),#LOGPIXELSX)
Global              iFS09.i = ((09 * 100) / igDpi)
Global              iFS10.i = ((10 * 100) / igDpi)
Global              iFS12.i = ((12 * 100) / igDpi)
Global        igFontGui09.i = LoadFont(1, "Microsoft Sans Serif", iFS09, #PB_Font_HighQuality + 2)
Global        igFontGui10.i = LoadFont(2, "Microsoft Sans Serif", iFS10, #PB_Font_Bold | #PB_Font_HighQuality + 2)
Global        igFontGui12.i = LoadFont(3, "Microsoft Sans Serif", iFS12, #PB_Font_Bold | #PB_Font_HighQuality + 2)
How does it work?

I have the code:

Code: Select all

  ; Load the font
  t=LoadFont(1, "Arial", 10) ;Load Arial Font, Size 10 - 28/NOV/2013
  SetGadgetFont(#PB_Default, FontID(1))
  If t=0 : MessageRequester("Error", "Can't load Arial font.") : EndIf  
How can I override the DPIs on mum's laptop with the code above?

Thanks!

Kind regards,
>Marco A.G.Pinto
---------------

Re: Ignoring the DPI font settings on Windows

Posted: Thu Feb 05, 2015 9:14 pm
by marcoagpinto
uwekel wrote:
marcoagpinto wrote:Is there a way of overriding the settings?
The question should be: "Is there a way to layout the gadgets properly to fulfill the needs of the user?" :) There must be a reason why a user sets a larger dpi value! In my case, i also use 125% on Windows at my office, because otherwise the very small letters are very difficult to read. Unfortunately, on Windows, the a lot of programs do not layout properly or just overwrite the customized settings. Poor :-(
The status bar of my tool almost doesn't fit in my 1366x768 laptop resolution.

Mum has a higher resolution but her DPI settings affect the size and it doesn't fit there either.

Thanks!

Re: Ignoring the DPI font settings on Windows

Posted: Fri Feb 06, 2015 12:24 am
by IdeasVacuum
Well, is your Mum not happy with the DPI on her PC? If not, you can change it for her via Windows:
Right-mouse Desktop, Display Properties, Settings, Advanced, DPI Setting. Most commonplace is 96 DPI.

Your mum's monitor is not 4K, right? Even Windows 8.1 desktop is not actually ready for 4K yet, so none of the typical desktop apps like Office work very well. 4K is apparently fine via the Modern interface.

The code I posted showed that you can scale the font according to the dpi, and thus your intended text size in relation to your app's window will be respected. The whole app could look too small if the dpi is very high though, so you might instead want to re-size your window and the gadgets.

Re: Ignoring the DPI font settings on Windows

Posted: Fri Feb 06, 2015 9:27 pm
by marcoagpinto
IdeasVacuum wrote:Well, is your Mum not happy with the DPI on her PC? If not, you can change it for her via Windows:
Right-mouse Desktop, Display Properties, Settings, Advanced, DPI Setting. Most commonplace is 96 DPI.

Your mum's monitor is not 4K, right? Even Windows 8.1 desktop is not actually ready for 4K yet, so none of the typical desktop apps like Office work very well. 4K is apparently fine via the Modern interface.

The code I posted showed that you can scale the font according to the dpi, and thus your intended text size in relation to your app's window will be respected. The whole app could look too small if the dpi is very high though, so you might instead want to re-size your window and the gadgets.
Hello!

Her laptop is FULL-HD but I reduced the resolution in it slightly when she bought it.

I thank you for your kind help, but I don't understand your API code.

It uses 3 fonts size? And in two of them it has a BOLD option?

And, why the +2 in the High Quality?

I know mum is happy with her DPI, but I am thinking about my PhD tool which must work the same way in all COMPUTERS (edited).

If after it is ready, and I need to defend it and if the university computer to be used has a huge DPI, the entire layout will be a mess and I will fail to defend it.

:oops:

I hope you now understand why I am so annoying... :cry:

The tool must work 100% equal in all computers, no matter their specifications.

Re: Ignoring the DPI font settings on Windows

Posted: Sat Feb 07, 2015 12:05 pm
by Danilo
Try this, mister PhD:

Code: Select all

Prototype proto_SetProcessDPIAware()

If OpenLibrary(0,"user32.dll")
    SetProcessDPIAware.proto_SetProcessDPIAware = GetFunction(0,"SetProcessDPIAware")
    If SetProcessDPIAware
        ;Debug "calling SetProcessDPIAware()"
        SetProcessDPIAware() ; Windows Vista+ / Windows Server 2008+
    EndIf
EndIf

Global _dpiScaleFactorX.d = GetDeviceCaps_(GetDC_(0),#LOGPIXELSX) / 96
Global _dpiScaleFactorY.d = GetDeviceCaps_(GetDC_(0),#LOGPIXELSY) / 96

Macro dpiX(_num_) : (_num_ * _dpiScaleFactorX) : EndMacro
Macro dpiY(_num_) : (_num_ * _dpiScaleFactorY) : EndMacro


; Load the font
t=LoadFont(1, "Arial", 10, #PB_Font_HighQuality) ;Load Arial Font, Size 10 - 28/NOV/2013
SetGadgetFont(#PB_Default, FontID(1))
If t=0 : MessageRequester("Error", "Can't load Arial font.") : EndIf  

If OpenWindow(0, dpiX(0), dpiY(0), dpiX(640), dpiY(285), "DPIaware", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    ButtonGadget(0, dpiX(10),dpiY( 10),dpiX(200),dpiY(25), "Standard Button")
    ButtonGadget(1, dpiX(10),dpiY( 40),dpiX(200),dpiY(25), "Left Button", #PB_Button_Left)
    ButtonGadget(2, dpiX(10),dpiY( 70),dpiX(200),dpiY(25), "Right Button", #PB_Button_Right)
    ButtonGadget(3, dpiX(10),dpiY(100),dpiX(200),dpiY(60), "Multiline Button  (longer text gets automatically wrapped)", #PB_Button_MultiLine)
    ButtonGadget(4, dpiX(10),dpiY(170),dpiX(200),dpiY(25), "Toggle Button", #PB_Button_Toggle)
    
    ListViewGadget(5, dpiX(430),dpiY(10),dpiX(200),dpiy(185))
    For i = 0 To 100 : AddGadgetItem(5,-1,"Item "+i) : Next
    
    CanvasGadget(6, dpiX(220),dpiY(10),dpiX(200),dpiy(185))
    If StartDrawing( CanvasOutput(6) )
        Box(0,0,OutputWidth(),OutputHeight(),RGB($40,$40,$40))
        Line(dpiX( 0) ,dpiY(0), dpiX(200),dpiy(185),RGB($FF,$FF,$00))
        Line(dpiX(200),dpiY(0),-dpiX(200),dpiy(185),RGB($FF,$FF,$00))
        StopDrawing()
    EndIf
    
    If LoadImage(0,#PB_Compiler_Home+"Examples/Sources/Data/PureBasicLogo.bmp")
        ResizeImage(0,dpiX(ImageWidth(0)),dpiY(ImageHeight(0)))
        ImageGadget(7,dpiX(10),dpiY(205),dpiX(381),dpiY(68),ImageID(0))
    EndIf
    
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Fonts are automatically scaled.
Gadgets size and position must be adjusted/scaled, according to DPI settings.
Same for images, but if you use images in your application, it would be even
better if you include highDPI versions and load that images.

Hope your University has Windows Vista/7/8/8.1/+. XP isn't supported anymore anyway...

A possible future PhD should have the knowledge and brain to do something like this himself, in my opinion.

Re: Ignoring the DPI font settings on Windows

Posted: Sat Feb 07, 2015 4:17 pm
by marcoagpinto
Danilo wrote: A possible future PhD should have the knowledge and brain to do something like this himself, in my opinion.
I am little and scared :cry:

Re: Ignoring the DPI font settings on Windows

Posted: Sat Feb 07, 2015 4:31 pm
by heartbone
Danilo, I wasn't aware of the vertical scale factor and will have to investigate it further. Thanks for the code.

OT
marcoagpinto, according to the great Professor Jim McCanney... PhD stands for Piled Higher & Deeper.

With over 200 college credit hours, while not even close to the good professor, I still consider myself to be an A.D. (above doctor), and don't need or desire any validation from those in "academics".

From my life experiences, something being doctored is not a good thing.

For the past generation or so, there has been a vetting process to make sure that only those demonstrating fealty to the ruling kabbal will be granted the PhD title.

Listen to any of these lectures and perhaps you'll also begin to realize that simple truth.

Re: Ignoring the DPI font settings on Windows

Posted: Sun Feb 08, 2015 9:19 am
by JHPJHP
Hi marcoagpinto,

Keep asking questions, and looking for answers.

Don't feel bad or embarrassed by your question, those feeling should be reserved for people who forget that character is measured by how we treat each other, not by our knowledge of PureBasic.

Re: Ignoring the DPI font settings on Windows

Posted: Sun Feb 08, 2015 12:55 pm
by Danilo
Of course, keep asking questions, and looking for answers.

Re: Ignoring the DPI font settings on Windows

Posted: Sun Feb 08, 2015 3:32 pm
by Vera
@Danilo
I'm sorry to find you very offensive with your self blinding over-the-top-arrogance and pretensions.
Such a standpoint is surely the way to decline human achievements.

Are you a car mechanic?

So much for a top down friendly PureBasic forum 8)

"Even a stopped clock gives the right time twice a day"

Re: Ignoring the DPI font settings on Windows

Posted: Sun Feb 08, 2015 4:41 pm
by Little John
Vera wrote:Such a standpoint is surely the way to decline human achievements.
:?:

Re: Ignoring the DPI font settings on Windows

Posted: Sun Feb 08, 2015 4:57 pm
by skywalk
Pursuing a PhD is a worthy goal and in no way demands the student be a programming expert. We must recognize for many, future programming will not require such mundane skills as memorizing syntax or arranging bits and bytes.