Delegate CustomFontSource

Delegate CustomFontSource

名称: Aspose.Imaging 收藏: Aspose.Imaging.dll (25.4.0)

个性化字体源提供商功能

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

Parameters

args object ( )

这些论点。

Returns

CustomFontData ( )

特定的字体列表,以使图像

Examples

此示例显示了使用特定字体(字体)为图像呈现的自定义字体来源。 不同于 FontSettings.SetFontsFolders 方法在图像范围内工作,并允许在多用户场景中提供字体。

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 =
                                                                                                                                                                                                                                                                 (Aspose.Imaging.ImageOptions.VectorRasterizationOptions)img.GetDefaultOptions(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
                                                                                                                                                                                                                                                             });
                                                                                                                                                                                                                                                         }
                                                                                                                                                                                                                                                     }

                                                                                                                                                                                                                                                     // The custom fonts provider example. 
                                                                                                                                                                                                                                                     private Aspose.Imaging.CustomFontHandler.CustomFontData[] GetFontSource(params object[] args)
                                                                                                                                                                                                                                                     {
                                                                                                                                                                                                                                                         string fontsPath = string.Empty;
                                                                                                                                                                                                                                                         if (args.Length > 0)
                                                                                                                                                                                                                                                         {
                                                                                                                                                                                                                                                             fontsPath = args[0].ToString();
                                                                                                                                                                                                                                                         }

                                                                                                                                                                                                                                                         var customFontData = new System.Collections.Generic.List<aspose.imaging.customfonthandler.customfontdata>();
                                                                                                                                                                                                                                                         foreach (var font in System.IO.Directory.GetFiles(fontsPath))
                                                                                                                                                                                                                                                         {
                                                                                                                                                                                                                                                             customFontData.Add(new Aspose.Imaging.CustomFontHandler.CustomFontData(Path.GetFileNameWithoutExtension(font), System.IO.File.ReadAllBytes(font)));
                                                                                                                                                                                                                                                         }

                                                                                                                                                                                                                                                         return customFontData.ToArray();
                                                                                                                                                                                                                                                     }</aspose.imaging.customfonthandler.customfontdata>
 中文