VintaSoft Imaging .NET SDK 14.0: Документация для .NET разработчика
Vintasoft.Imaging.Fonts Namespace / FontProgramsControllerBase Class / Default Property
Синтаксис Example Требования Смотрите также
В этом разделе
    Default Свойство (FontProgramsControllerBase)
    В этом разделе
    Возвращает или задает контроллер программы шрифта, который используется в качестве контроллера программы шрифта по умолчанию VintaSoft Imaging .NET SDK.
    Синтаксис
    'Declaration
    
    Public Shared Property Default As FontProgramsControllerBase
    
    
    public static FontProgramsControllerBase Default { get; set; }
    
    
    public: __property static FontProgramsControllerBase* get_Default();
    public: __property static void set_Default(
    FontProgramsControllerBase* value
    );

    Property Value

    Значение по умолчанию: FileFontProgramsControllerWithFallbackFont с каталогом шрифтов ".\fonts".
    Пример

    Вот пример пользовательского контроллера программы шрифта, который должен использоваться в качестве контроллера программы шрифта по умолчанию в приложениях Windows, Linux или macOS:

    
    Imports System.Collections.Generic
    Imports System.IO
    Imports System.Runtime.Serialization
    
    Imports Vintasoft.Imaging.Fonts
    
    Namespace DemosCommonCode
        ''' <summary>
        ''' Provides access to the fonts, which are located in the specified directory.
        ''' </summary>
        Public Class CustomFontProgramsController
            Inherits FileFontProgramsControllerWithFallbackFont
    
            #Region "Constants"
    
            ''' <summary>
            ''' The folder that contains the fonts.
            ''' </summary>
            Const FontsFolder As String = "fonts"
    
            ''' <summary>
            ''' The filename of serialized font programs controller.
            ''' </summary>
            Const FontProgramsControllerFilename As String = "fonts.dat"
    
            #End Region
    
    
    
            #Region "Constructors"
    
            ''' <summary>
            ''' Initializes the <see cref="CustomFontProgramsController"/> class.
            ''' </summary>
            Shared Sub New()
                RegisterSerializingType(Of CustomFontProgramsController)()
            End Sub
    
            ''' <summary>
            ''' Initializes a new instance of the <see cref="CustomFontProgramsController"/> class.
            ''' </summary>
            Public Sub New()
                MyBase.New(True, GetFontFolders())
                If FontFiles.Count = 0 Then
                    Console.WriteLine("CustomFontProgramsController: Fonts was not found!")
                Else
                    RefreshFontNames()
                End If
            End Sub
    
            ''' <summary>
            ''' Initializes a new instance of the <see cref="CustomFontProgramsController"/> class.
            ''' </summary>
            ''' <param name="info">The SerializationInfo to populate with data.</param>
            ''' <param name="context">The destination for this serialization.</param>
            Public Sub New(info As SerializationInfo, context As StreamingContext)
                MyBase.New(info, context)
            End Sub
    
            #End Region
    
    
    
            #Region "Methods"
    
            ''' <summary>
            ''' Sets <see cref="CustomFontProgramsController"/> as the default font programs controller.
            ''' </summary>
            Public Shared Sub SetDefaultFontProgramsController()
                [Default] = CreateOrDeserialize()
            End Sub
    
            ''' <summary>
            ''' Creates or deserializes the <see cref="CustomFontProgramsController"/>.
            ''' </summary>
            ''' <returns>A new instance of <see cref="CustomFontProgramsController"/>.</returns>
            Public Shared Function CreateOrDeserialize() As CustomFontProgramsController
                Dim result As CustomFontProgramsController = Nothing
    
                ' if file with serialized font program controller exists
                If File.Exists(FontProgramsControllerFilename) Then
                    Try
                        ' deserialize font program controller
                        result = DirectCast(Deserialize(FontProgramsControllerFilename), CustomFontProgramsController)
                    Catch
                    End Try
                End If
    
                ' if font program controller is not deserialized
                If result Is Nothing Then
                    ' create new font program controller
                    result = New CustomFontProgramsController()
    
                    ' if font program controller contains fonts
                    If result.FontFiles.Count > 0 Then
                        ' serialize font program controller
                        Serialize(FontProgramsControllerFilename, result)
                    End If
                End If
    
                Return result
            End Function
    
            ''' <summary>
            ''' Returns array that contains paths to the folders with fonts.
            ''' </summary>
            Private Shared Function GetFontFolders() As String()
                Dim result As New List(Of String)()
    
                Dim systemFontFolder As String
                If Vintasoft.Imaging.ImagingEnvironment.IsWindows Then
                    systemFontFolder = Path.Combine(Environment.GetEnvironmentVariable("windir"), "Fonts")
                Else
                    systemFontFolder = Environment.GetFolderPath(Environment.SpecialFolder.Fonts)
                End If
                If Not String.IsNullOrEmpty(systemFontFolder) Then
                    result.Add(systemFontFolder)
                End If
    
                result.Add(FontsFolder)
    
                Return result.ToArray()
            End Function
    
            #End Region
    
        End Class
    End Namespace
    
    
    
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Runtime.Serialization;
    
    using Vintasoft.Imaging.Fonts;
    
    namespace DemosCommonCode
    {
        /// <summary>
        /// Provides access to the fonts, which are located in the specified directory.
        /// </summary>
        public class CustomFontProgramsController : FileFontProgramsControllerWithFallbackFont
        {
    
            #region Constants
    
            /// <summary>
            /// The folder that contains the fonts.
            /// </summary>
            const string FontsFolder = "fonts";
    
            /// <summary>
            /// The filename of serialized font programs controller.
            /// </summary>
            const string FontProgramsControllerFilename = "fonts.dat";
    
            #endregion
    
    
    
            #region Constructors
    
            /// <summary>
            /// Initializes the <see cref="CustomFontProgramsController"/> class.
            /// </summary>
            static CustomFontProgramsController()
            {
                RegisterSerializingType<CustomFontProgramsController>();
            }
    
            /// <summary>
            /// Initializes a new instance of the <see cref="CustomFontProgramsController"/> class.
            /// </summary>
            public CustomFontProgramsController()
                : base(true, GetFontFolders())
            {
                if (FontFiles.Count == 0)
                {
                    Console.WriteLine("CustomFontProgramsController: Fonts was not found!");
                }
                else
                {
                    RefreshFontNames();
                }
            }
    
            /// <summary>
            /// Initializes a new instance of the <see cref="CustomFontProgramsController"/> class.
            /// </summary>
            /// <param name="info">The SerializationInfo to populate with data.</param>
            /// <param name="context">The destination for this serialization.</param>
            public CustomFontProgramsController(SerializationInfo info, StreamingContext context)
                : base(info, context)
            {
            }
    
            #endregion
    
    
    
            #region Methods
    
            /// <summary>
            /// Sets <see cref="CustomFontProgramsController"/> as the default font programs controller.
            /// </summary>
            public static void SetDefaultFontProgramsController()
            {
                Default = CreateOrDeserialize();
            }
    
            /// <summary>
            /// Creates or deserializes the <see cref="CustomFontProgramsController"/>.
            /// </summary>
            /// <returns>A new instance of <see cref="CustomFontProgramsController"/>.</returns>
            public static CustomFontProgramsController CreateOrDeserialize()
            {
                CustomFontProgramsController result = null;
    
                // if file with serialized font program controller exists
                if (File.Exists(FontProgramsControllerFilename))
                {
                    try
                    {
                        // deserialize font program controller
                        result = (CustomFontProgramsController)Deserialize(FontProgramsControllerFilename);
                    }
                    catch
                    {
                    }
                }
    
                // if font program controller is not deserialized
                if (result == null)
                {
                    // create new font program controller
                    result = new CustomFontProgramsController();
    
                    // if font program controller contains fonts
                    if (result.FontFiles.Count > 0)
                    {
                        // serialize font program controller
                        Serialize(FontProgramsControllerFilename, result);
                    }
                }
    
                return result;
            }
    
            /// <summary>
            /// Returns array that contains paths to the folders with fonts.
            /// </summary>
            private static string[] GetFontFolders()
            {
                List<string> result = new List<string>();
                
                string systemFontFolder;
                if (Vintasoft.Imaging.ImagingEnvironment.IsWindows)
                    systemFontFolder = Path.Combine(Environment.GetEnvironmentVariable("windir"), "Fonts");
                else
                    systemFontFolder = Environment.GetFolderPath(Environment.SpecialFolder.Fonts);            
                if (!string.IsNullOrEmpty(systemFontFolder))
                    result.Add(systemFontFolder);
                
                result.Add(FontsFolder);
    
                return result.ToArray();
            }
    
            #endregion
    
        }
    }
    
    

    Требования

    Целевые платформы: .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

    Смотрите также