Simple Font-Smoothing (ClearType) Program for Windows

Share your advanced PureBasic knowledge/code with the community.
ebs
Enthusiast
Enthusiast
Posts: 561
Joined: Fri Apr 25, 2003 11:08 pm

Simple Font-Smoothing (ClearType) Program for Windows

Post by ebs »

I wrote the following program for someone who wanted a way to control Windows' ClearType font-smoothing from the command line.
The font-smoothing routines may be useful even if you don't want to do it from the command line.

You use the program as follows:

Code: Select all

fs on/off c/s contrast

Examples
--------
Turn font smoothing on, set it to ClearType, and set the contrast to 1000:
fs on c 1000

Turn font smoothing on, set it to Standard:
fs on s

Turn font smoothing off:
fs off

Code: Select all

Procedure FontSmoothingOFF()
  ; turn fontsmoothing off
  SystemParametersInfo_(#SPI_SETFONTSMOOTHING, #False, 0, #SPIF_SENDWININICHANGE | #SPIF_UPDATEINIFILE)
  RedrawWindow_(0, 0, 0, #RDW_ERASE | #RDW_FRAME | #RDW_ALLCHILDREN | #RDW_INTERNALPAINT | #RDW_INVALIDATE | #RDW_ERASENOW | #RDW_UPDATENOW);
EndProcedure

Procedure FontSmoothingON(FSType.l, Contrast.l = -1)
  ; turn fontsmoothing on
  SystemParametersInfo_(#SPI_SETFONTSMOOTHING, #True, 0, #SPIF_SENDWININICHANGE | #SPIF_UPDATEINIFILE)
  ; set font smoothing type
  SystemParametersInfo_(#SPI_SETFONTSMOOTHINGTYPE, 0, FSType, #SPIF_SENDWININICHANGE | #SPIF_UPDATEINIFILE)
  ; set font smoothing contrast
  If FSType = #FE_FONTSMOOTHINGCLEARTYPE And Contrast <> -1
    If Contrast < 1000
      Contrast = 1000
    ElseIf Contrast > 2200
      Contrast = 2200
    EndIf
    SystemParametersInfo_(#SPI_SETFONTSMOOTHINGCONTRAST, 0, Contrast, #SPIF_SENDWININICHANGE | #SPIF_UPDATEINIFILE)
  EndIf
  RedrawWindow_(0, 0, 0, #RDW_ERASE | #RDW_FRAME | #RDW_ALLCHILDREN | #RDW_INTERNALPAINT | #RDW_INVALIDATE | #RDW_ERASENOW | #RDW_UPDATENOW);
EndProcedure

pOnOff.s = UCase(ProgramParameter())
pFSType.s = UCase(ProgramParameter())
pContrast.s = ProgramParameter()

If pOnOff = "ON"
  If pFSType = "C"
    If pContrast
      FontSmoothingON(#FE_FONTSMOOTHINGCLEARTYPE, Val(pContrast))
    Else
      FontSmoothingON(#FE_FONTSMOOTHINGCLEARTYPE)
    EndIf
  ElseIf pFSType = "S"
    FontSmoothingON(#FE_FONTSMOOTHINGSTANDARD)
  EndIf
ElseIf pOnOff = "OFF"
  FontSmoothingOFF()
EndIf
Regards,
Eric
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Simple Font-Smoothing (ClearType) Program for Windows

Post by PB »

Thanks!
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Post by Rook Zimbabwe »

Haven't run it yet... I will try it on my wifes computer in a moment... I use FS so I doubt I would see any difference. Heck, I will see what it does to me as well!

Silly question:

So this will enable it even if the user has it turned off?

8)
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
ebs
Enthusiast
Enthusiast
Posts: 561
Joined: Fri Apr 25, 2003 11:08 pm

Post by ebs »

So this will enable it even if the user has it turned off?
I think so. I believe this does the same thing as adjusting the Display Properties in the Control Panel.

Regards,
Eric
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Post by Rook Zimbabwe »

It does work!

OK, On my wifes cruddy LCD monitor (IBM NetVista All In One!) it looked not so hot... but that was her OBG... but it worked good.

Good Job!
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
Post Reply