public override void Prepare()
        {
            base.Prepare();

            if (FontAsset != null)
            {
                Font = BundleManager.Instance.LoadAsset <TMPro.TMP_FontAsset>(FontAsset);
            }
            else if (FontName != null)
            {
                Font = Helper.GetFont(FontName.ToLower());
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates a Font with the given parameters. A generic
 /// monospace font will be used if the name cannot be found.
 /// This program currently only works properly for monospace fonts.
 /// </summary>
 /// <param name="fontStyle">Font style</param>
 /// <returns>Font</returns>
 private void CreateFont(FontStyle fontStyle)
 {
     Font = null;
     FontFamily[] fonts = FontFamily.Families;
     // Search for the user-defined font
     for (int i = 0; i < fonts.Length; i++)
     {
         if (fonts[i].Name.ToLower() == FontName.ToLower())
         {
             Font = new System.Drawing.Font(fonts[i], FontSize, fontStyle, GraphicsUnit.Pixel);
             break;
         }
     }
     // If found, make sure it is a monospaced font
     if (Font != null)
     {
         Bitmap   tmp = new Bitmap(FontSize * 2, FontSize * 2);
         Graphics g   = Graphics.FromImage(tmp);
         if (g.MeasureString("!", Font).Width != g.MeasureString("@", Font).Width)
         {
             Program.Log(Program.LogType.Warning, "The chosen font is not monospaced. Reverting to a generic monospaced font.");
             Font.Dispose();
             Font = null;
         }
         g.Dispose();
         tmp.Dispose();
     }
     // If not found or not monospaced, use a generic font
     if (Font == null)
     {
         if (FontName != string.Empty)
         {
             Program.Log(Program.LogType.Warning, "The chosen font cannot be found. Reverting to a generic monospaced font.");
         }
         Font     = new System.Drawing.Font(FontFamily.GenericMonospace, FontSize, fontStyle, GraphicsUnit.Pixel);
         FontName = Font.FontFamily.Name;
     }
 }