Beispiel #1
0
        public Face LoadSystemFace(Library library, string face, ref FontStyles style)
        {
            string file = null;

            //TODO: Implement style matching on Linux
            using (var pat = FcPattern.FromFamilyName(face)) {
                //Match Exactly
                using (var objset = new FcObjectSet())
                {
                    objset.Add(Fc.FC_FAMILY);
                    objset.Add(Fc.FC_STYLE);
                    objset.Add(Fc.FC_FILE);
                    using (var fset = FcFontSet.FromList(fcconfig, pat, objset))
                    {
                        for (int i = 0; i < fset.Count; i++)
                        {
                            if (fset[i].GetString(Fc.FC_FILE, 0, ref file) == FcResult.Match)
                            {
                                var fc = new Face(library, file);
                                var fs = FontStyles.Regular;
                                if ((fc.StyleFlags & StyleFlags.Bold) != 0)
                                {
                                    fs |= FontStyles.Bold;
                                }
                                if ((fc.StyleFlags & StyleFlags.Italic) != 0)
                                {
                                    fs |= FontStyles.Italic;
                                }
                                if (fs == style)
                                {
                                    return(fc);
                                }
                                else
                                {
                                    fc.Dispose();
                                }
                            }
                        }
                    }
                }
                //Match normally
                style = FontStyles.Regular;
                pat.ConfigSubstitute(fcconfig, FcMatchKind.Pattern);
                pat.DefaultSubstitute();
                FcResult result;
                using (var font = pat.Match(fcconfig, out result)) {
                    if (font.GetString(Fc.FC_FILE, 0, ref file) == FcResult.Match)
                    {
                        return(new Face(library, file));
                    }
                }
            }
            //This shouldn't be thrown since fontconfig substitutes, but have this just in case
            throw new Exception("Font not found: " + face);
        }
Beispiel #2
0
 public static FcFontSet FromList(FcConfig config, FcPattern pat, FcObjectSet os)
 {
     return(new FcFontSet(Native.FcFontList(config.Handle, pat.Handle, os.Handle)));
 }