Download CorelDrawPalPaletteWriter.zip, last updated 05/08/2018 (30.38 KB)

Download
  • md5: 5dc2a39ffc96357d70d670fae102a69c
  • sha1: 87cd30771c13132db0584ebbc03986265fa278dc
  • sha256: 9cc4800ea9713c1d7f95660b1deba20f3c13e9f317171b2cbc0ff358ace10f7e
using System;
using System.Drawing;

// Working with CorelDRAW Palettes part 2, writing .pal files
// https://www.cyotek.com/blog/working-with-coreldraw-palettes-part-2-writing-pal-files
// Copyright © 2018 Cyotek Ltd. All Rights Reserved.

// This work is licensed under the Creative Commons Attribution 4.0 International License.
// To view a copy of this license, visit http://creativecommons.org/licenses/by/4.0/.

// Found this example useful? 
// https://www.paypal.me/cyotek

namespace Cyotek.Demonstrations.CorelDrawPaletteWriter
{
  internal static class FontHelpers
  {
    #region Constants

    private static readonly string[] _fixedFontNames =
    {
      //"Fira Code",
      "Hack",
      "Source Code Pro",
      "Consolas",
      "Courier New"
    };

    #endregion

    #region Static Methods

    public static Font GetFixedFont()
    {
      Font font;

      font = null;

      for (int i = 0; i < _fixedFontNames.Length; i++)
      {
        font = GetFont(_fixedFontNames[i]);

        if (font != null)
        {
          break;
        }
      }

      return font ?? SystemFonts.MessageBoxFont;
    }

    private static Font GetFont(string fontFamilyName)
    {
      Font result;

      // https://www.cyotek.com/blog/detecting-if-a-given-font-style-exists-in-csharp

      try
      {
        using (FontFamily family = new FontFamily(fontFamilyName))
        {
          result = family.IsStyleAvailable(FontStyle.Regular) ? new Font(family, 10, FontStyle.Regular) : null;
        }
      }
      catch (ArgumentException)
      {
        result = null;
      }

      return result;
    }

    #endregion
  }
}

Donate

Donate