Skip to main content

HtmlDocumentImporterOptions.FontScalingDpiValue Property

Gets or sets the DPI value that will be used to scale fonts on high DPI settings.

Namespace: DevExpress.XtraRichEdit.Import

Assembly: DevExpress.RichEdit.v23.2.Core.dll

NuGet Packages: DevExpress.RichEdit.Core, DevExpress.Win.Navigation

Declaration

[DefaultValue(-1)]
public int FontScalingDpiValue { get; set; }

Property Value

Type Default Description
Int32 -1

A positive integer that is the DPI setting used to render text.

Property Paths

You can access this nested property as listed below:

Object Type Path to FontScalingDpiValue
RichEditDocumentImportOptions
.Html .FontScalingDpiValue

Remarks

Overview

The font size specified in an HTML document can be expressed in pixels (PX) or points (PT). While PT units are interpreted in the same manner by all browsers regardless of the device resolution, PX unit interpretation may vary.

On low resolution devices, such as most displays, 1px is one device pixel (dot) of the display. For printers and high resolution screens, 1px implies multiple device pixels.

That is the reason for browsers to scale an HTML content whose font size is specified in PX units on high DPI devices.

The FontScalingDpiValue option allows you to adjust the scaling factor when importing HTML content whose font size is measured in PX units. By default, this property value is set to -1. Specify a valid positive setting to scale the font so it looks the same in RichEditControl and in the reference browser. Most likely, 96 is the best choice.

Step-by-Step Guide

  1. Add the following section to the application manifest file of your project (if the project does not contain the application manifest, add it using Add New Item… command in Visual Studio):

    <asmv3:application xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
        <asmv3:windowsSettings
             xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
          <dpiAware>true</dpiAware>
        </asmv3:windowsSettings>
      </asmv3:application>
    

    The purpose of the manifest setting is to make your application DPI-aware to get a true picture of the configuration.

  2. Set the FontScalingDpiValue property to a proper DPI value. In most situations, 96 would be fine regardless of the actual DPI setting:

    richEditControl1.Options.Import.Html.FontScalingDpiValue = 96;
    
  3. Instead of using the magic number 96, you can determine the DPI value using the Win32 GetDeviceCaps method, as illustrated in the following code snippet.

    [DllImport("gdi32.dll")]
    static extern int GetDeviceCaps(IntPtr hdc, int nIndex);
    // ...
     Graphics g = Graphics.FromHwnd(IntPtr.Zero);
     IntPtr desktop = g.GetHdc();
    // Magic number 88 is the value of the LOGPIXELSX constant which should be passed to the 
    // GetDeviceCaps method to obtain a number of pixels per logical inch along the screen width.
     richEditControl1.Options.Import.Html.FontScalingDpiValue = GetDeviceCaps(desktop, 88);
    
See Also