Delegate CustomFontSource

Delegate CustomFontSource

Namespace: Aspose.Imaging
Assembly: Aspose.Imaging.dll (25.7.0)

Custom font source provider function

public delegate CustomFontData[] CustomFontSource(params object[] args);

Parameters

args object []

The arguments.

Returns

CustomFontData []

The list of specific fonts to render the image

Examples

This example demonstrates the custom font source providing to use the specific font(s) for image rendering. Unlike FontSettings.SetFontsFolders method works in the image scope and allowing to provide the fonts in multi-user scenarios.

public void CustomFontSourceTest(string inputPath, string outputPath, string fileName, string fontPath)
   {
       var loadOptions = new Aspose.Imaging.LoadOptions();
       loadOptions.AddCustomFontSource(GetFontSource, fontPath);
       using (var img = Image.Load(System.IO.Path.Combine(inputPath, fileName), loadOptions))
       {
           Aspose.Imaging.ImageOptions.VectorRasterizationOptions vectorRasterizationOptions =
               img.GetDefaultOptions<Aspose.Imaging.ImageOptions.VectorRasterizationOptions>(new object[] { Color.White, img.Width, img.Height });
           vectorRasterizationOptions.TextRenderingHint = Aspose.Imaging.TextRenderingHint.SingleBitPerPixel;
           vectorRasterizationOptions.SmoothingMode = Aspose.Imaging.SmoothingMode.None;
           img.Save(System.IO.Path.Combine(outputPath, fileName + ".png"), new Aspose.Imaging.ImageOptions.PngOptions
           {
               VectorRasterizationOptions = vectorRasterizationOptions
           });
       }
   }
   private Aspose.Imaging.CustomFontHandler.CustomFontData[] GetFontSource(params object[] args)
   {
       string fontsPath = string.Empty;
       if (args.Length > 0)
       {
           fontsPath = args[0].ToString();
       }
       var customFontData = new List<Aspose.Imaging.CustomFontHandler.CustomFontData>();
       foreach (var font in System.IO.Directory.GetFiles(fontsPath))
       {
           customFontData.Add(new Aspose.Imaging.CustomFontHandler.CustomFontData(Path.GetFileNameWithoutExtension(font), File.ReadAllBytes(font)));
       }
       return customFontData.ToArray();
   }
 English