Page 2 of 2

Re: Ignoring the DPI font settings on Windows

Posted: Sun Feb 08, 2015 5:48 pm
by TI-994A
marcoagpinto wrote:I am little and scared.
When another blames you or hates you, or people voice similar criticisms, go to their souls, penetrate inside and see what sort of people they are. You will realize that there is no need to be racked with anxiety that they should hold any particular opinion about you. (Marcus Aurelius)

Opinions are the cheapest commodities on earth. Everyone has a flock of opinions ready to be wished upon anyone who will accept them. If you are influenced by opinions when you reach decisions, you will not succeed in any undertaking. (Napoleon Hill)

I am not bound by the opinions of men. (Martin Luther)

And don't consult anyone's opinions but your own. (Persius)

Re: Ignoring the DPI font settings on Windows

Posted: Sun Feb 08, 2015 8:42 pm
by Danilo
Vera wrote:@Danilo
I'm sorry to find you very offensive with your self blinding over-the-top-arrogance and pretensions.
I very much apologize for the outburst. Maybe a misconception that PhD's are the old professors who know everything.

Re: Ignoring the DPI font settings on Windows

Posted: Mon Feb 09, 2015 1:57 am
by marcoagpinto
I am developing a tool and writing a thesis.

The jury (professors) will evaluate the working of the tool and the thesis foundations.

The source-code will be closed, so no member of the jury will have access to it.

It is not a coding PhD but the developing of a tool and the thesis.

The project/thesis is very delayed because I currently have two jobs (not a lot of free time), and soon I am going to apply for a 3rd one to try to get enough cash to pay the tuition without the need of a bank loan.

In the thesis I mention the PureBasic community as one of the best I have ever known... Every time I have a question, I ask it here, and someone always helps.

Thank you very much for all the kind support!

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

Re: Ignoring the DPI font settings on Windows

Posted: Mon Feb 09, 2015 8:53 am
by heartbone
TI-994A wrote:
marcoagpinto wrote:I am little and scared.
When another blames you or hates you, or people voice similar criticisms, go to their souls, penetrate inside and see what sort of people they are. You will realize that there is no need to be racked with anxiety that they should hold any particular opinion about you. (Marcus Aurelius)

Opinions are the cheapest commodities on earth. Everyone has a flock of opinions ready to be wished upon anyone who will accept them. If you are influenced by opinions when you reach decisions, you will not succeed in any undertaking. (Napoleon Hill)

I am not bound by the opinions of men. (Martin Luther)

And don't consult anyone's opinions but your own. (Persius)
I had to consult the dictionary, and ironic does not have the correct meaning.
I am having difficulty describing the classification of contradiction that post represents.

marcoagpinto, on a page seemingly full of opinions for you to ponder, I am happy to present one final opinion about this off topic.
You seem too humble to want to be a PhD.
Carry on.

Re: Ignoring the DPI font settings on Windows

Posted: Mon Feb 09, 2015 9:12 am
by TI-994A
heartbone wrote:I had to consult the dictionary, and ironic does not have the correct meaning.
I am having difficulty describing the classification of contradiction that post represents.
Sorry, but I can't help you there. :lol:

Re: Ignoring the DPI font settings on Windows

Posted: Mon Feb 09, 2015 3:02 pm
by heartbone
TI-994A wrote:
heartbone wrote:I had to consult the dictionary, and ironic does not have the correct meaning.
I am having difficulty describing the classification of contradiction that post represents.
Sorry, but I can't help you there. :lol:
I was able to locate and retrieve the data.
The most applicable word in my vocabulary is incongruous. 8)

Your post reminds me of the incident depicted in the Star Trek episode I, Mudd.
KIRK: He lied. Everything Harry tells you is a lie. Remember that. Everything Harry tells you is a lie.
MUDD: Listen to this carefully, Norman. I am lying.
NORMAN: You say you are lying, but if everything you say is a lie then you are telling the truth, but you cannot tell the truth because everything you say is a lie. You lie. You tell the truth. But you cannot for. Illogical! Illogical! Please explain.
(Smoke comes out of Norman's head.)

Re: Ignoring the DPI font settings on Windows

Posted: Mon Feb 09, 2015 4:11 pm
by TI-994A
heartbone wrote:(Smoke comes out of ... head.)
Something you could undoubtedly relate to. :wink:

Re: Ignoring the DPI font settings on Windows

Posted: Mon Feb 09, 2015 7:32 pm
by Danilo
Please see also:
MSDN: High DPI => Writing DPI-Aware Desktop and Win32 Applications

- Writing DPI Aware Applications.pdf

It covers topics like "System DPI vs. Per-Monitor DPI" and using an Application Manifest with "<dpiAware>true</dpiAware>".

- DPI-aware applications in Windows Vista and Windows 7

Re: Ignoring the DPI font settings on Windows

Posted: Mon Feb 09, 2015 8:20 pm
by heartbone
Danilo, after skimming that second msdn page that you linked, I hope that they never implement that "DPI Aware" crap in Linux.

In my intuition based opinion 8), it's probably not a good idea to muck around with such stuff at the level that M$ has implemented the change.
Permitting font sizes to change independently of the surrounding (infra)structure has to be problematic.
It will often require the text frameworks to become variable to compensate.
For my work I'd rather attempt to compensate for the unwelcome size distortions by readjusting the font size.
The fact is, that M$ has already made the change permanently, and it will have to be dealt with henceforth.

I suppose the feature might be somehow construed as useful, after all years ago I'd adjusted the DPI larger on my laptop to make it easier to see.
As a result, as soon as I started testing apps on my Vista laptop I stumbled across the phenomena of too wide text which had to be sussed out and solved.
I'm thinking that I could have simply changed the desktop theme's font size, if the Windows® desktop itself has been made font size aware.

"DPI Aware" seems more like a gimmick than anything else to force programs into the M$ way.
If font sizing was really a problem, I think it would be a more prominent option in existing software.
Perhaps over time I'll become aware of the advantages for users,
but right now the cynic in me says "save grief and time", take the approach recommended by IdeasVacuum.

The more I think about it... it would be nice if there were a setting that the application can use to tell the OS, don't do that for me.
Is there?

Re: Ignoring the DPI font settings on Windows

Posted: Mon Feb 09, 2015 9:06 pm
by Danilo
heartbone wrote:The more I think about it... it would be nice if there were a setting that the application can use to tell the OS, don't do that for me.
Is there?
Do not use SetProcessDPIAware() / SetProcessDpiAwareness() and "<dpiAware>true</dpiAware>".
Additionally, right-click the EXE > Properties > choose Compatibility Tab, and disable automatic scaling for High DPI.

If you do so, your application may look very small on HighDPI screens. Small but crisp. ;)

Re: Ignoring the DPI font settings on Windows

Posted: Mon Feb 09, 2015 9:48 pm
by heartbone
Danilo wrote:
heartbone wrote:The more I think about it... it would be nice if there were a setting that the application can use to tell the OS, don't do that for me.
Is there?
Do not use SetProcessDPIAware() / SetProcessDpiAwareness() and "<dpiAware>true</dpiAware>".
Additionally, right-click the EXE > Properties > choose Compatibility Tab, and disable automatic scaling for High DPI.

If you do so, your application may look very small on HighDPI screens. Small but crisp. ;)
That's just ugly and wrong.
Not your answer Danilo, it was informative, but the ugly possibility that my program will see the higher than traditional 96 DPI OS setting and adjust the font sizes accordingly, even though the exe's scaling was disabled by the user. :?
I just checked and it looks like the OS call returns the 96 when the scaling is disabled. (yay)
If the user can disable it, there's probably an API for it.
Again quite the BS move by M$, forcing this unneded complexity. :evil:
If this 'feature' was truly needed, it'd would have been on Linux. :idea:

Re: Ignoring the DPI font settings on Windows

Posted: Thu Mar 05, 2015 3:39 pm
by marcoagpinto
Guys,

Sorry to bring the topic back again.

I have been trying to contact people in private to avoid annoying the forum.

I have tried:

Code: Select all

  ; Load the font
  ; Attempt to have the Font DPI at normal, even in higher DPI (PureBasic forum helped)
  Global igDpi.i = GetDeviceCaps_(GetDC_(0),#LOGPIXELSX)
  Global iFS10.i = ((10 * 100) / igDpi)
  Global igFontGui10.i=LoadFont(igFontGui10,"Arial",iFS10,#PB_Font_HighQuality+2)
  SetGadgetFont(#PB_Default, igFontGui10)
It seems to work everywhere except in the menus and status bar.

I tested it on my laptop by changing "10 * 100" to "30 * 100".

The user who provided the code suggested me to contact two expert users but they never replied to my private messages.

Can someone help?

Thanks once again!

>Marco A.G.Pinto
---------------

Re: Ignoring the DPI font settings on Windows

Posted: Thu Mar 05, 2015 6:21 pm
by Num3
In all my project i force my own font and font size, because of consistency over windows DPI machines and linux...

Menus retain the OS size and are not affected ...

I use this code borrowed from the forums, it selects one of two font sizes, one for regular DPI other for Larger DPI, this way i code my entire gadgets to fit the largest size:

Code: Select all

Procedure InitScaleDPI() ;Windows 5.0 or higher needed for minimum functionality of this procedure.
  
  CompilerIf #PB_Compiler_OS = #PB_OS_Windows
    Protected dpiaware.l=#False,dc.i,lpx.i,lpy.i,dll.i,*SetProcessDPIAware,*IsProcessDPIAware,ncm.NONCLIENTMETRICS,font$,font.i
    CompilerIf #PB_Compiler_Exe ;Only use this in exes, as dlls inherit DPI from the calling process.
      dll=OpenLibrary(#PB_Any,"user32.dll")
      If dll
        *IsProcessDPIAware=GetFunction(dll,"IsProcessDPIAware")
        If *IsProcessDPIAware
          dpiaware=CallFunctionFast(*IsProcessDPIAware)
        EndIf
        If Not dpiaware
          *SetProcessDPIAware=GetFunction(dll,"SetProcessDPIAware")
          If *SetProcessDPIAware
            CallFunctionFast(*SetProcessDPIAware)
          EndIf
        EndIf
      EndIf
    CompilerEndIf
    dc=GetDC_(#Null)
    If dc
      lpx=GetDeviceCaps_(dc,#LOGPIXELSX)
      lpy=GetDeviceCaps_(dc,#LOGPIXELSY)
      
      If lpx>0
        _ScaleDPI_X_=lpx/#DefaultDPIX
      EndIf
      If lpy>0
        _ScaleDPI_Y_=lpy/#DefaultDPIY
      EndIf
      ReleaseDC_(#Null,dc)
    EndIf
    ncm\cbSize=SizeOf(NONCLIENTMETRICS)
    If SystemParametersInfo_(#SPI_GETNONCLIENTMETRICS,SizeOf(NONCLIENTMETRICS),ncm,#Null)
      font$=PeekS(@ncm\lfMessageFont\lfFaceName)
      
      ;InstallIncludedFont(?font1_start, ?font1_end-?font1_start, "Ubuntu-R.ttf")
      font$ = "Ubuntu"
      ;font$ = "Liberation Sans"
      ;font$ = "DroidSans"
      
      If lpx <= #DefaultDPIX And lpy <= #DefaultDPIY
        font=LoadFont(#PB_Any,font$,10, #PB_Font_HighQuality)
      Else
        font=LoadFont(#PB_Any,font$,9,#PB_Font_HighQuality)
      EndIf
    EndIf
  CompilerElseIf #PB_Compiler_OS = #PB_OS_Linux
    font$ = GetCurrentDirectory()+"Ubuntu-R.ttf"
    ;font$ = "Ubuntu"
    font=LoadFont(#PB_Any,font$,10,#PB_Font_HighQuality)
  CompilerEndIf
  
  If font
    SetGadgetFont(#PB_Default,FontID(font))
  EndIf
  
  Enumeration #PB_Compiler_EnumerationValue
    #Font
  EndEnumeration
  
  LoadFont(#Font,"Ubuntu", 12, #PB_Font_Bold)
  
  
EndProcedure

Re: Ignoring the DPI font settings on Windows

Posted: Thu Mar 05, 2015 8:17 pm
by Danilo
marcoagpinto wrote:It seems to work everywhere except in the menus and status bar.
Font sizes are scaled automatically, also in Menu and StatusBar.

Please see the following code, I just added Menu and StatusBar. Please note that I do not change the font size, it is always 10 - the scaling is done automatically by Windows!

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(325), "DPIaware - " + Str(_dpiScaleFactorX*100) +"%", #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)
    
    If CreateMenu(0,WindowID(0))
      MenuTitle("Project")
        MenuItem(1, "Open"   +Chr(9)+"Ctrl+O")
        MenuItem(2, "Save"   +Chr(9)+"Ctrl+S")
        MenuItem(3, "Save as"+Chr(9)+"Ctrl+A")
        MenuItem(4, "Close"  +Chr(9)+"Ctrl+C")
    EndIf
    
    CreateStatusBar(0,WindowID(0))
    AddStatusBarField(dpiX(320))
    AddStatusBarField(dpiX(320))
    StatusBarText(0, 0, "Field 1")
    StatusBarText(0, 1, "Field 2")

    
    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
Output:

Image

Image

Image

Image