Code: Select all
newFont\lfHeight = -(pointSize * (deviceDPI / 72))
Here's the test code:
Code: Select all
Enumeration
#MainWindow
#dtFont
EndEnumeration
wFlags = #PB_Window_ScreenCentered | #PB_Window_SystemMenu
OpenWindow(#MainWindow, #PB_Any, #PB_Any, 500, 200, "Font Sizes", wFlags)
LoadFont(#dtFont, "Arial", 12)
If StartDrawing(WindowOutput(#MainWindow))
Box(0, 0, 500, 200, RGB(255, 255, 255))
DrawingMode(#PB_2DDrawing_Transparent)
DrawingFont(FontID(#dtFont))
DrawText(10, 10, "Hello World! drawn by PureBasic's DrawText function at 12 points", #Red)
StopDrawing()
EndIf
Define cf.LOGFONT
fontName.s = "Arial"
For lenLoop = 0 To Len(fontName) - 1
cf\lfFaceName [lenLoop] = Asc(Mid(fontName, lenloop + 1, 1))
Next lenLoop
winDPI = GetDeviceCaps_(GetDC_(WindowID(#MainWindow)), #LOGPIXELSY)
cf\lfFaceName [Len(fontName)] = 0
cf\lfHeight = -(16 * (winDPI / 72))
winDC = GetDC_(WindowID(#MainWindow))
newFont = CreateFontIndirect_(cf)
oldFont = SelectObject_(winDC, newFont)
SetTextColor_(winDC, #Blue)
outStr.s = "Hello World! drawn by Windows' TextOut function at 16 points"
TextOut_(winDC, 10, 35, outStr, Len(outStr))
cf\lfHeight = -(12 * (winDPI / 72))
newFont = CreateFontIndirect_(cf)
ignore = SelectObject_(winDC, newFont)
SetTextColor_(winDC, #Black)
outStr.s = "Hello World! drawn by Windows' TextOut function at 12 points"
TextOut_(winDC, 10, 60, outStr, Len(outStr))
dispose = SelectObject_(winDC, oldFont)
DeleteObject_(newFont)
While WaitWindowEvent() ! #PB_Event_CloseWindow : CloseWindow : Wend
Thanks.

