GlobalAccessSoftware icon

MyFontClass.cs

GlobalAccessSoftware | PRO | 04/26/19 09:20:38 AM UTC | 0 ⭐ | 703 👁️ | Never ⏰ | []
C# |

6 KB

|

None

|

0 👍

/

0 👎

 
 
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
// MCPL.MyFontClass.cs 19-Jan-2019 by -JpE-
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
// REM: Brought in fresh to MCPL and adapted
// (MCPL=MyCustomPrintLibrary) to PB with an
// eye towards switching ME Print related
// calls to MCPL eventually, BUT NOT YET.
//\\//\\//\\ ** Design Note: ** //\\//\\//\\
// Custom Colors not needed, just use the
// colors in the Font Dialog for now and
// begin to workout RTF file Print details
// for the overall Class Library. (.dll)
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
// v5.0.5.99 19-Jan-2019 Initial Integration
// v5.0.6.00 03-Feb-2019 Simplified Perfect.
// v5.0.6.01 26-Feb-2019 Really Getin tharZ.
// v5.0.6.03 14-Mar-2019 ReSetPages Call.
// v5.1.7.10 25-Apr Instance-N Font stuff.
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
 
using System;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;
 
// Class Aliases
using MCC = MyCustomControls.CustomControl;
using MCT = MyCustomLibrary.MyToolbox;
using MPC = MyCustomPrintLibrary.MyPrintClass;
 
// Properties Aliases
using MPR = MyCustomPrintLibrary.Properties.Resources;
using MPS = MyCustomPrintLibrary.Properties.Settings;
 
namespace MyCustomPrintLibrary
{
  public static class MyFontClass // ==> MFC
  {
#region PrintFontDialog & Methods, Used by PB.
 
    /* MyCustomControls Dox
     ****************************
     * O1 = MyOpenDialog;
     * R1 = MyRichTextBox;
     * P1 = MyPrintDialog;
     * P2 = MyPreviewControl;
     * P3 = MyPreviewDialog;
     * D1 = MyPrintDoc;
     * P4 = MyPageSetup;
     * M1 = MyPreviewMenuStrip;
     * M2 = MyColorDialog;
     * F0 = MyFontDialog;
     * S1 = MySaveDialog;
     ****************************
    */
 
    private static readonly Mutex Pf =
      new Mutex(false, "PrintFontMutex");
 
    public static FontDialog MyFontDialog
    {
      get { return  Fonts; }
      private set { Fonts = value; }
    }
    // ^|
    // || All Inclusive & Eloquently simple.
    // |v
    private static FontDialog Fonts
    {
      get { return GetFontDialog(); }
      set { SetFontDialog(value);   }
    }
    // | |
    // | |
    // v v
    private static
      FontDialog GetFontDialog()
    {
      using(MPC.LockOut)
      {
        using(Pf)
        {
          //Pf.WaitOne();
          FontDialog d;
          using (var f = new MCC())
          { d = f.F0; }
          d.Font = new Font(
            MPS.Default.FntNm,
            MPS.Default.FntSz,
            MPS.Default.FntSt,
            MPS.Default.FntGu,
            MPS.Default.FntCs,
            MPS.Default.FntVr);
          d.Color = MPS.Default.PbClr;
          d.HelpRequest += MCT.FontDialogHelp;
          //Pf.ReleaseMutex();
          return d;
        }
      }
    }
    // ^ ^
    // | |
    // | |
    private static void
      SetFontDialog(FontDialog d)
    {
      using(MPC.LockOut)
      {
        using(Pf)
        {
          //Pf.WaitOne();
          MPS.Default.FntNm = d.Font.Name;
          MPS.Default.FntSz = d.Font.Size;
          MPS.Default.FntSt = d.Font.Style;
          MPS.Default.FntGu = d.Font.Unit;
          MPS.Default.FntCs = d.Font.GdiCharSet;
          MPS.Default.FntVr =
            d.Font.GdiVerticalFont;
          MPS.Default.PbClr = d.Color;
          MPS.Default.Save();
          //Pf.ReleaseMutex();
        }
      }
    }
 
    //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
    // Default Font & Color already Set,
    // So never null or void from the Start.
    //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
 
    public static void SelectPrintFont()
    {
      using (new Mutex(false,
        "MyPrintFontDialogMutex"))
      {
        // Called from PB Thread
        // and may be 1st or 2nd instance.
        var d = MyFontDialog;
        using (d)
        { if (!d.ShowDialog().Equals(
            DialogResult.OK)) return;
          d.HelpRequest -=
            MCT.FontDialogHelp; }
        MyFontDialog = d;
        MPC.ReSetPages();
      }
    }
#endregion (PB) PrintFontDialog Method Group
    //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
 
 
#region Smesa (Me) Font Property Methods
 
    public static Color MePrintColor//(Fore)
    {
      get { return Mc1;  }
      set { Mc1 = value; }
    }
 
    private static Color Mc1
    {
      get { using(MPC.LockOut) {
        return MPS.Default.MeClr; } }
      set { using(MPC.LockOut) {
        MPS.Default.MeClr = value;
        MPS.Default.Save(); } }
    }
 
    public static Font MeFont
    {
      get { return Font1;  }
      set { Font1 = value; }
    }
 
    private static Font Font1
    {
      get { return GetMeFont(); }
      set { SetMeFont(value);   }
    }
 
    private static readonly Mutex Me = new
      Mutex(false, "MeFontMutex04252019");
 
    private static Font GetMeFont()
    {
      using (MPC.LockOut)
      {
        using (Me)
        {
          //Me.WaitOne();
          var t = Control.DefaultFont;
          try { using (var f = new Font(
            MPS.Default.FtNm, MPS.Default.FtSz,
            MPS.Default.FtSt, MPS.Default.FtGu,
            MPS.Default.FtCs, MPS.Default.FtVr))
          { t = f; } }
          catch (ArgumentException)
          { try { using (var d = new MCC())
            { t = d.F0.Font; } }
              catch(ArgumentException) { } }
          //Me.ReleaseMutex();
          return t;
        }
      }
    }
 
    private static void SetMeFont(Font f)
    {
      using (MPC.LockOut)
      {
        using (Me)
        {
          //Me.WaitOne();
          MPS.Default.FtNm = f.Name;
          MPS.Default.FtSz = f.Size;
          MPS.Default.FtSt = f.Style;
          MPS.Default.FtGu = f.Unit;
          MPS.Default.FtCs = f.GdiCharSet;
          MPS.Default.FtVr = f.GdiVerticalFont;
          MPS.Default.Save();
          //Me.ReleaseMutex();
        }
      }
    }
#endregion Smesa Font Property Method Group
    //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
 
 
  }
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎