예제 #1
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));
        }
예제 #2
0
 public void SetFontStyle(TextRange textRange, PaintDotNet.DirectWrite.FontStyle fontStyle)
 {
     base.innerRefT.SetFontStyle(textRange, fontStyle);
 }