Aspose.HTML for .NET 24.10 – Improving Rendering Quality

Aspose.HTML for .NET 24.10

In version 24.10, Aspose.HTML introduced updates to the public API, aimed primarily at enhancing support for Linux environments. These updates include replacing several enumerations from System.Drawing with implementations within Aspose’s own Aspose.Html.Drawing and Aspose.Html.Rendering.Image namespaces:

FontStyle Vs WebFontStyle

In version 24.10, the FontStyle enumeration, which specifies font styles like regular, bold, and italic, has been replaced by the WebFontStyle enumeration:

OldNew
FontStyle.BoldWebFontStyle.Bold
FontStyle.ItalicWebFontStyle.Italic
FontStyle.RegularWebFontStyle.Regular

Accordingly, in the GraphicContext class, the FontStyle property type has changed:

 1namespace Aspose.Html.Rendering
 2{
 3    public class GraphicContext
 4    { 
 5        //From:
 6        public virtual FontStyle FontStyle { get; set; }
 7 
 8        //To:
 9        public virtual WebFontStyle FontStyle { get; set; }
10    }
11}

SmoothingMode and TextRenderingHint Vs UseAntialiasing and UseHinting

In version 24.10,

The сorrespondence table below guides how rendering settings are applied when migrating between old and new versions of Aspose.HTML for .NET.

Correspondence Table for Different Rendering Cases

The table provides clear guidance, indicating how UseAntialiasing and UseHinting settings correspond to older properties like SmoothingMode and TextRenderingHint:

UseAntialiasingUseHintingSmoothingModeTextRenderingHint
truetrueSmoothingMode.AntiAliasTextRenderingHint.AntiAliasGridFit
falsetrueSmoothingMode.NoneTextRenderingHint.SingleBitPerPixelGridFit
truefalseSmoothingMode.AntiAliasTextRenderingHint.AntiAlias
falsefalseSmoothingMode.NoneTextRenderingHint.SingleBitPerPixel

This table shows how to convert previous anti-aliasing and text rendering settings to the new UseAntialiasing and UseHinting properties. Here’s how you can interpret and apply this table:

  1. When you decide on the required level of text clarity and shape rendering for your project, match the previous settings to the new properties.
  2. Replace the old SmoothingMode and TextRenderingHint values with the corresponding UseAntialiasing and UseHinting settings.

For example, if your previous configuration used SmoothingMode.AntiAlias and TextRenderingHint.AntiAliasGridFit, switch to UseAntialiasing = true and UseHinting = true.

This is the example we will consider below.

Using SmoothingMode and TextRenderingHint Enumerations – 24.9 and Earlier Versions


This C# code snippet demonstrates how to render HTML content to an image file using Aspose.HTML for .NET with old dependencies of System.Drawing, specifically configuring the output to optimize rendering quality with anti-aliasing options:

 1using System.IO;
 2using Aspose.Html;
 3using Aspose.Html.Rendering.Image;
 4using System.Drawing.Drawing2D;
 5using System.Drawing.Text;
 6...
 7    // Create an instance of the ImageRenderingOptions class to specify rendering quality
 8    var opt = new ImageRenderingOptions
 9    {
10        SmoothingMode = SmoothingMode.AntiAlias,
11        Text =
12        {
13            TextRenderingHint = TextRenderingHint.AntiAliasGridFit
14        }
15    };
16
17    // Create an HTML Document
18    using (var doc = new HTMLDocument("text", string.Empty))
19    // Create an ImageDevice object
20    using (var device = new ImageDevice(opt, "out-old.png"))
21    {
22        // Rendering HTML to image
23        doc.RenderTo(device);
24    }

Using new UseAntialiasing and UseHinting properties – Since Version 24.10

The following code demonstrates rendering HTML content to an image file using the new UseAntialiasing and UseHinting properties. This example is the same as the previous example, where were used the system SmoothingMode and TextRenderingHint enumerations:

 1using System.IO;
 2using Aspose.Html;
 3using Aspose.Html.Rendering.Image;
 4...
 5    // Create an instance of the ImageRenderingOptions class
 6    var opt = new ImageRenderingOptions
 7    {
 8        UseAntialiasing = true,
 9        Text =
10        {
11            UseHinting = true
12        }
13    };
14
15    // Create an HTML Document
16    using (var doc = new HTMLDocument("text", string.Empty))
17    // Create an ImageDevice object
18    using (var device = new ImageDevice(opt, "out-new.png"))
19    {
20        // Rendering HTML to image
21        doc.RenderTo(device);
22    }

Conclusions

Thus, the API changes implemented in the 24.10 release greatly affect the quality of text and image display, make it easier for users to switch between different versions of the Aspose.HTML libraries for .NET that support different HTML rendering engines, and are steps forward in Linux support.

Aspose.HTML for .NET 24.10 Release Notes – This release includes changes to the public API related to improving Linux support, rendering quality, and fixing bugs to enhance the library’s overall performance and stability.

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.