How to evaluate and change Windows font smoothing or ClearType during exports (ArcObjects .NET 10.6 SDK)
ArcObjects Help for .NET developers > Developing with ArcGIS > Learning ArcObjects > Exporting and printing maps > Exporting maps > How to evaluate and change Windows font smoothing or ClearType during exports (ArcObjects .NET 10.6 SDK)

How to evaluate and change Windows font smoothing or ClearType during exports


Summary
Microsoft's font smoothing technology can greatly enhance the legibility of text in an on-screen display. However, it can negatively affect ArcObjects output in certain situations. This article shows how to detect if font smoothing is enabled, how to enable it, and how to disable it. To avoid unexpected behavior when using these functions, note the initial state of font smoothing and restore it when the export is complete.

Evaluating and changing font smoothing or ClearType during exports

To ensure quality output from ArcGIS image exporters, you can choose to disable the font smoothing option until the exports are complete.
  1. Define the delegate function SystemParametersInfo from the Microsoft User32 application programming interface (API) along with some API constants in the declaration section. See the following code example:
[C#]
[DllImport("user32.dll", SetLastError=true)] static extern bool
    SystemParametersInfo(uint uiAction, uint uiParam, ref int pvParam, uint fWinIni);

/* Constants used for User32 calls. */
const uint SPI_GETFONTSMOOTHING=74;
const uint SPI_SETFONTSMOOTHING=75;
const unit SPI_UPDATEINI=0x1;
[VB.NET]
Private Declare Auto Function SystemParametersInfo Lib "user32" (ByVal uiAction As UInteger, ByVal uiParam As UInteger, ByRef pvParam As UInteger, ByVal fWinIni As UInteger) As Boolean

Public Const SPI_GETFONTSMOOTHING=74
Public Const SPI_SETFONTSMOOTHING=75
Public Const SPIF_UPDATEINIFILE=&H1
  1. Define some functions to get the font smoothing value and to enable or disable it. See the following code example:
[C#]
private Boolean GetFontSmoothing()
{
    bool iResult;
    int pv=0;
    /* Call to systemparametersinfo to get the font smoothing value. */
    iResult=SystemParametersInfo(SPI_GETFONTSMOOTHING, 0, ref pv, 0);
    if (pv > 0)
    {
        //pv > 0 means font smoothing is on.
        return true;
    }
    else
    {
        //pv == 0 means font smoothing is off.
        return false;
    }
}

private void DisableFontSmoothing()
{
    bool iResult;
    int pv=0;
    /* Call to systemparametersinfo to set the font smoothing value. */
    iResult=SystemParametersInfo(SPI_SETFONTSMOOTHING, 0, ref pv,
        SPIF_UPDATEINIFILE);
}

private void EnableFontSmoothing()
{
    bool iResult;
    int pv=0;
    /* Call to systemparametersinfo to set the font smoothing value. */
    iResult=SystemParametersInfo(SPI_SETFONTSMOOTHING, 1, ref pv,
        SPIF_UPDATEINIFILE);
}
[VB.NET]
Function GetFontSmoothing() As Boolean
    Dim iResults As Boolean
    Dim PV As Integer
    'Get font smoothing value and return true if font smoothing is turned on.
    iResults=SystemParametersInfo(SPI_GETFONTSMOOTHING, 0, PV, 0)
    If PV > 0 Then
        GetFontSmoothing=True
    Else
        GetFontSmoothing=False
    End If
End Function

Sub DisableFontSmoothing()
    Dim iResults As Boolean
    Dim PV As Integer
    'Call systemparametersinfo to turn font smoothing off.
    iResults=SystemParametersInfo(SPI_SETFONTSMOOTHING, 0, PV, SPIF_UPDATEINIFILE)
End Sub

Sub EnableFontSmoothing()
    Dim iResults As Boolean
    Dim PV As Integer
    'Call systemparametersinfo to turn font smoothing on.
    iResults=SystemParametersInfo(SPI_SETFONTSMOOTHING, 1, PV, SPIF_UPDATEINIFILE)
End Sub


See Also:

Samples:




Development licensing Deployment licensing
ArcGIS for Desktop Basic ArcGIS for Desktop Basic
ArcGIS for Desktop Standard ArcGIS for Desktop Standard
ArcGIS for Desktop Advanced ArcGIS for Desktop Advanced
Engine Developer Kit Engine