Aspose.SVG for .NET 25.1 – Unified API and Enhanced Rendering Quality
Aspose.SVG for .NET 25.1
In version 25.1, Aspose.SVG 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.SVG.Drawing
and Aspose.Svg.Rendering.Image
namespaces:
- The FontStyle system enumeration was replaced with WebFontStyle one.
- The SmoothingMode system enumeration was replaced with ImageRenderingOptions.UseAntialiasing property.
- The TextRenderingHint system enumeration was replaced with TextOptions.UseHinting property.
FontStyle Vs WebFontStyle
In version 25.1, the FontStyle enumeration, which specifies font styles like regular, bold, and italic, has been replaced by the WebFontStyle enumeration:
Old | New |
---|---|
FontStyle.Bold | WebFontStyle.Bold |
FontStyle.Italic | WebFontStyle.Italic |
FontStyle.Regular | WebFontStyle.Regular |
Accordingly, in the GraphicContext class, the FontStyle property type has changed:
1namespace Aspose.Svg.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 25.1,
- the SmoothingMode system enumeration, previously used to control the antialiasing quality of rendered shapes and images, has been replaced by the ImageRenderingOptions.UseAntialiasing property;
- the TextRenderingHint system enumeration, which helps control text rendering quality, has now been replaced by the TextOptions.UseHinting property. This property maintains the clarity and readability of text.
The сorrespondence table below guides how rendering settings are applied when migrating between old and new versions of Aspose.SVG 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
:
UseAntialiasing | UseHinting | SmoothingMode | TextRenderingHint |
---|---|---|---|
true | true | SmoothingMode.AntiAlias | TextRenderingHint.AntiAliasGridFit |
false | true | SmoothingMode.None | TextRenderingHint.SingleBitPerPixelGridFit |
true | false | SmoothingMode.AntiAlias | TextRenderingHint.AntiAlias |
false | false | SmoothingMode.None | TextRenderingHint.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:
- When you decide on the required level of text clarity and shape rendering for your project, match the previous settings to the new properties.
- Replace the old
SmoothingMode
andTextRenderingHint
values with the correspondingUseAntialiasing
andUseHinting
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.12 and Earlier Versions
This C# code snippet demonstrates how to render SVG content to an image file using Aspose.SVG 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.Svg;
3using Aspose.Svg.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 // Initialize an SVG Document
17 using (var doc = new SVGDocument("source.svg"))
18 // Create an ImageDevice object
19 using (var device = new ImageDevice(options, "out-old.png"))
20 {
21 // Rendering SVG to image
22 doc.RenderTo(device);
23 }
Using new UseAntialiasing and UseHinting properties – Since Version 25.1
The following code demonstrates rendering SVG 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.Svg;
3using Aspose.Svg.Rendering.Image;
4...
5 // Create an instance of the ImageRenderingOptions class
6 var options = new ImageRenderingOptions
7 {
8 UseAntialiasing = true,
9 Text =
10 {
11 UseHinting = true
12 }
13 };
14 // Initialize an SVG Document
15 using (var doc = new SVGDocument("source.svg"))
16 // Create an ImageDevice object
17 using (var device = new ImageDevice(options, "out-new.png"))
18 {
19 // Rendering SVG to image
20 doc.RenderTo(device);
21 }
Conclusions
- The migration to
WebFontStyle
enumeration,UseAntialiasing
, andUseHinting
properties in Aspose.SVG for .NET 25.1 represents a step forward in supporting Linux environments. - The base values of the
UseAntialiasing
andUseHinting
properties have been changed, resulting in better text rendering when using the default options. - This migration also aims to unify the public API to simplify access to the different versions of the Aspose.SVG for .NET library that support different SVG rendering engines.
Thus, the API changes implemented in the 25.1 release greatly affect the quality of text and image display, make it easier for users to switch between different versions of the Aspose.SVG libraries for .NET that support different SVG rendering engines, and are steps forward in Linux support.
Aspose.SVG for .NET 25.1 Release Notes – This release includes changes to the public API related to improving rendering quality, and fixing bugs to enhance the library’s overall performance and stability.