예제 #1
0
        public static FontFamily GetFontFamily(ScriptFile script, DocRange range, string name)
        {
            string filepath = Path.Combine(Program.ExeFolder, "Fonts", name + ".ttf");

            if (File.Exists(filepath))
            {
                if (LoadedFonts == null)
                {
                    LoadedFonts = new PrivateFontCollection();
                }

                FontFamily family = LoadedFonts.Families.FirstOrDefault(fam => fam.Name.ToLower() == name.ToLower());

                if (family == null)
                {
                    try
                    {
                        LoadedFonts.AddFontFile(filepath);
                    }
                    catch (ArgumentException)
                    {
                        script.Diagnostics.Error($"Failed to load the font {name} at '{filepath}'.", range);
                        return(null);
                    }
                    family = LoadedFonts.Families.FirstOrDefault(fam => fam.Name.ToLower() == name.ToLower());
                    if (family == null)
                    {
                        script.Diagnostics.Error($"Failed to load the font {name} at '{filepath}'.", range);
                        return(null);
                    }
                }

                return(family);
            }

            if (!FontFamily.Families.Any(fam => fam.Name.ToLower() == name.ToLower()))
            {
                script.Diagnostics.Error($"The font {name} does not exist.", range);
                return(null);
            }
            return(new FontFamily(name));
        }
예제 #2
0
        private static FontFamily GetFontFamily(string name, Location location)
        {
            string filepath = Path.Combine(Program.ExeFolder, "Fonts", name + ".ttf");

            if (File.Exists(filepath))
            {
                if (LoadedFonts == null)
                {
                    LoadedFonts = new PrivateFontCollection();
                }

                FontFamily family = LoadedFonts.Families.FirstOrDefault(fam => fam.Name.ToLower() == name.ToLower());

                if (family == null)
                {
                    try
                    {
                        LoadedFonts.AddFontFile(filepath);
                    }
                    catch (ArgumentException)
                    {
                        throw new SyntaxErrorException($"Failed to load the font {name} at '{filepath}'.", location);
                    }
                    family = LoadedFonts.Families.FirstOrDefault(fam => fam.Name.ToLower() == name.ToLower());
                    if (family == null)
                    {
                        throw new SyntaxErrorException($"Failed to load the font {name} at '{filepath}'.", location);
                    }
                }

                return(family);
            }

            if (!FontFamily.Families.Any(fam => fam.Name.ToLower() == name.ToLower()))
            {
                throw new SyntaxErrorException($"The font {name} does not exist.", location);
            }

            return(new FontFamily(name));
        }