Exemplo n.º 1
0
 private SharpDX.DirectWrite.FontWeight WeightFromFontStyle(System.Drawing.FontStyle style)
 {
     SharpDX.DirectWrite.FontWeight ret = SharpDX.DirectWrite.FontWeight.Normal;
     if (style.HasFlag(System.Drawing.FontStyle.Bold))
     {
         ret = SharpDX.DirectWrite.FontWeight.Bold;
     }
     return(ret);
 }
Exemplo n.º 2
0
 private SharpDX.DirectWrite.FontStyle StyleFromFontStyle(System.Drawing.FontStyle style)
 {
     SharpDX.DirectWrite.FontStyle ret = SharpDX.DirectWrite.FontStyle.Normal;
     if (style.HasFlag(System.Drawing.FontStyle.Italic))
     {
         ret |= SharpDX.DirectWrite.FontStyle.Italic;
     }
     return(ret);
 }
Exemplo n.º 3
0
        private Inline GetInlineWithStyling(string line, System.Drawing.FontStyle style)
        {
            Inline styledText = new Run(line);

            if (style.HasFlag(System.Drawing.FontStyle.Bold))
            {
                styledText = new Bold(styledText);
            }

            if (style.HasFlag(System.Drawing.FontStyle.Italic))
            {
                styledText = new Italic(styledText);
            }

            if (style.HasFlag(System.Drawing.FontStyle.Underline))
            {
                styledText = new Underline(styledText);
            }

            return(styledText);
        }
Exemplo n.º 4
0
        public override bool GetFontFile(string fontName, int fontSize, System.Drawing.FontStyle style, out string fileName)
        {
            fileName = null;
            var config = FcInitLoadConfigAndFonts();

            List <string> fontStyles = new List <string>();

            foreach (var val in Enum.GetValues(typeof(System.Drawing.FontStyle)).OfType <System.Drawing.FontStyle>().Skip(1))
            {
                if (style.HasFlag(val))
                {
                    fontStyles.Add(val.ToString().ToLower());
                }
            }

            // configure the search pattern,
            // assume "name" is a std::string with the desired font name in it
            string styles = string.Join(":", fontStyles);
            var    pat    = FcNameParse(fontName + "-" + fontSize.ToString() + ":" + styles);

            FcConfigSubstitute(config, pat, FcMatchKind.FcMatchPattern);
            FcDefaultSubstitute(pat);

            // find the font
            FcResult tst;
            var      font = FcFontMatch(IntPtr.Zero, pat, out tst);

            if (font != IntPtr.Zero)
            {
                IntPtr resultPtr;
                if (FcPatternGetString(font, FC_FILE, 0, out resultPtr) == FcResult.FcResultMatch)
                {
                    // save the file to another std::string
                    fileName = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(resultPtr);
                }

                FcPatternDestroy(font);
            }

            FcPatternDestroy(pat);

            return(true);
        }