Example #1
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         DisposableUtil.Free <ThreadDispatcher>(ref this.backgroundThread);
         DisposableUtil.Free <ISystemFonts>(ref this.systemFonts);
         DisposableUtil.Free <System.Windows.Forms.Timer>(ref this.clearCacheTimer);
         DisposableUtil.Free <SelectionHighlightRenderer>(ref this.selectionHighlightRenderer);
         if (this.fontPreviewRenderCache != null)
         {
             Dictionary <TupleStruct <string, float, PaintDotNet.UI.Media.Brush>, PlacedBitmap> fontPreviewRenderCache = this.fontPreviewRenderCache;
             lock (fontPreviewRenderCache)
             {
                 this.fontPreviewRenderCache.Values.ForEach <PlacedBitmap>(pb => pb.Dispose());
                 this.fontPreviewRenderCache = null;
             }
         }
         if (this.fontMap != null)
         {
             this.fontMap.CollectionChanged -= new EventHandler(this.OnFontFamilyNameCollectionChanged);
             this.fontMap.Dispose();
             this.fontMap = null;
         }
         DisposableUtil.Free <ISystemFonts>(ref this.systemFonts);
     }
     base.Dispose(disposing);
 }
Example #2
0
 public FontListComboBoxHandler(System.Windows.Forms.ComboBox comboBox, IFontMap fontMap, string defaultFontName) : base(comboBox, DrawMode.OwnerDrawVariable)
 {
     this.textBrush = new SolidColorBrush();
     this.fontPreviewRenderCache     = new Dictionary <TupleStruct <string, float, PaintDotNet.UI.Media.Brush>, PlacedBitmap>();
     this.selectionHighlightRenderer = new SelectionHighlightRenderer();
     Validate.IsNotNull <IFontMap>(fontMap, "fontMap");
     this.fontMap = fontMap.CreateRef();
     this.fontMap.CollectionChanged += new EventHandler(this.OnFontFamilyNameCollectionChanged);
     this.systemFonts     = new PaintDotNet.DirectWrite.SystemFonts();
     this.defaultFontName = defaultFontName ?? this.systemFonts.Message.FontProperties.DisplayName;
     base.ComboBox.Sorted = true;
     base.ComboBox.Items.Add(defaultFontName);
     base.ComboBox.SelectedItem  = defaultFontName;
     base.ComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
     this.fontSampleText         = PdnResources.GetString("ToolConfigStrip.FontFamilyComboBox.FontSampleText");
 }
Example #3
0
        public void AsyncPrefetchFontNames()
        {
            IFontMap fontMapP = this.fontMap.CreateRef();

            Work.QueueWorkItem(delegate {
                try
                {
                    string[] strArray = fontMapP.ToArrayEx <string>();
                }
                catch (Exception)
                {
                }
                finally
                {
                    fontMapP.Dispose();
                }
            });
        }
Example #4
0
        public static SizedFontProperties CreateSizedFontProperties(this AppSettings.ToolsSection toolSettings, IFontMap fontMap)
        {
            FontProperties fontProperties;
            FontWeight     bold;

            PaintDotNet.DirectWrite.FontStyle italic;
            string displayName = toolSettings.Text.FontFamilyName.Value;

            string[] namesToTry = new string[] { displayName, "Segoe UI", "Arial" };
            try
            {
                fontProperties = fontMap.GetFontProperties(namesToTry);
            }
            catch (NoFontException)
            {
                fontProperties = new FontProperties(displayName, string.Empty, FontWeight.Normal, FontStretch.Normal, PaintDotNet.DirectWrite.FontStyle.Normal, TextDecorations.None);
            }
            System.Drawing.FontStyle style = toolSettings.Text.FontStyle.Value;
            FontWeight weight = fontProperties.Weight;

            if (style.HasFlag(System.Drawing.FontStyle.Bold) && (weight <= FontWeight.DemiBold))
            {
                bold = FontWeight.Bold;
            }
            else
            {
                bold = weight;
            }
            FontStretch stretch = fontProperties.Stretch;

            PaintDotNet.DirectWrite.FontStyle style2 = fontProperties.Style;
            if (style.HasFlag(System.Drawing.FontStyle.Italic) && (style2 == PaintDotNet.DirectWrite.FontStyle.Normal))
            {
                italic = PaintDotNet.DirectWrite.FontStyle.Italic;
            }
            else
            {
                italic = style2;
            }
            TextDecorations decorations = (fontProperties.Decorations | (style.HasFlag(System.Drawing.FontStyle.Underline) ? TextDecorations.Underline : TextDecorations.None)) | (style.HasFlag(System.Drawing.FontStyle.Strikeout) ? TextDecorations.Strikethrough : TextDecorations.None);
            float           dipSize     = (toolSettings.Text.FontSize.Value * 96f) / 72f;

            return(new SizedFontProperties(new FontProperties(fontProperties.DisplayName, fontProperties.FontFamilyName, bold, stretch, italic, decorations), dipSize));
        }
Example #5
0
 protected override void OnComboBoxGotFocus(object sender, EventArgs e)
 {
     if (!this.isPopulated)
     {
         this.isPopulated = true;
         using (new WaitCursorChanger(base.ComboBox))
         {
             string selectedItem = (string)base.ComboBox.SelectedItem;
             string str2         = null;
             ManualResetEventSlim gotFamilies = new ManualResetEventSlim(false);
             string[]             fontNames   = null;
             VirtualTask <Unit>   task        = TaskManager.Global.CreateVirtualTask(TaskState.Running);
             IFontMap             fontMapP    = this.fontMap.CreateRef();
             Work.QueueWorkItem(delegate {
                 try
                 {
                     fontNames = fontMapP.ToArrayEx <string>();
                 }
                 finally
                 {
                     fontMapP.Dispose();
                     try
                     {
                         gotFamilies.Set();
                     }
                     finally
                     {
                         task.SetState(TaskState.Finished);
                     }
                 }
             });
             if (!gotFamilies.Wait(0x3e8))
             {
                 new TaskProgressDialog {
                     Task             = task,
                     CloseOnFinished  = true,
                     ShowCancelButton = false,
                     Text             = PdnInfo.BareProductName,
                     Icon             = PdnInfo.AppIcon,
                     Text             = PdnResources.GetString("TextConfigWidget.LoadingFontsList.Text")
                 }.ShowDialog(base.ComboBox);
             }
             gotFamilies.Wait();
             base.ComboBox.BeginUpdate();
             base.ComboBox.Items.Clear();
             foreach (string str3 in fontNames)
             {
                 int num2 = base.ComboBox.Items.Add(str3);
                 if ((selectedItem != null) && DirectWriteFactory.FontNameComparer.Equals(selectedItem, str3))
                 {
                     str2 = str3;
                 }
             }
             if (str2 != null)
             {
                 base.ComboBox.SelectedItem = str2;
             }
             else
             {
                 base.ComboBox.SelectedItem = this.defaultFontName;
             }
             base.ComboBox.EndUpdate();
         }
     }
     base.OnComboBoxGotFocus(sender, e);
 }