Esempio n. 1
0
        private PixelFontSize mergeFonts(PixelFontSize originalSize, PixelFontSize newSize)
        {
            if (originalSize == null)
            {
                // nothing to merge, the current font size does not exist.
                return(newSize);
            }

            int newCharacterCount = 0;

            foreach (int character in newSize.Characters.Keys)
            {
                // add new characters into the existing font.
                if (!originalSize.Characters.ContainsKey(character))
                {
                    originalSize.Characters[character] = newSize.Characters[character];
                    newCharacterCount++;
                }
            }

            // associate the textures for the new font to the existing font.
            originalSize.Textures.AddRange(newSize.Textures);

            Logger.Log("PixelFont", $"==> Imported {newCharacterCount} new characters");
            return(originalSize);
        }
Esempio n. 2
0
 public PixelText(PixelFont font, string text, Color color)
     : base(false, true)
 {
     Font  = font;
     Text  = text;
     Color = color;
     Text  = text;
     size  = Font.Sizes[0];
     Refresh();
 }
Esempio n. 3
0
        public new PixelFontSize AddFontSize(string path, Atlas atlas = null, bool outline = false)
        {
            Logger.Log("PixelFont", $"Loading font: {path}");

            PixelFontSize loadedSize = null;

            // load the vanilla font if it exists.
            if (patch_Calc.orig_XMLExists(path))
            {
                Logger.Log("PixelFont", "=> vanilla font file");
                XmlElement data = patch_Calc.orig_LoadXML(path)["font"];
                loadedSize = AddFontSize(path, data, atlas, outline);
                Sizes.Remove(loadedSize);
            }

            // load custom fonts
            string modPath = FileProxy._Modize(path);

            foreach (ModAsset modAsset in Everest.Content.Mods
                     .Select(mod => mod.Map)
                     .Where(map => map.ContainsKey(modPath))
                     .Select(map => map[modPath]))
            {
                Logger.Log("PixelFont", $"=> mod font file from {modAsset.Source.Name}");
                XmlElement    data        = loadXMLFromModAsset(modAsset)["font"];
                PixelFontSize newFontSize = AddFontSize(path, data, atlas, outline);
                Sizes.Remove(newFontSize);
                loadedSize = mergeFonts(loadedSize, newFontSize);
            }

            // add the merged font into the list of existing fonts.
            Sizes.Add(loadedSize);
            Sizes.Sort((PixelFontSize a, PixelFontSize b) => Math.Sign(a.Size - b.Size));

            return(loadedSize);
        }
Esempio n. 4
0
        public PixelFontSize AddFontSize(string path, XmlElement data, Atlas atlas = null, bool outline = false)
        {
            // check if size already exists
            var size = data["info"].AttrFloat("size");

            foreach (var fs in Sizes)
            {
                if (fs.Size == size)
                {
                    return(fs);
                }
            }

            // get textures
            Textures = new List <MTexture>();
            var pages = data["pages"];

            foreach (XmlElement page in pages)
            {
                var file      = page.Attr("file");
                var atlasPath = Path.GetFileNameWithoutExtension(file);

                if (atlas != null && atlas.Has(atlasPath))
                {
                    Textures.Add(atlas[atlasPath]);
                }
                else
                {
                    var dir = Path.GetDirectoryName(path);
                    dir = dir.Substring(Engine.ContentDirectory.Length + 1);
                    Textures.Add(MTexture.FromFile(Path.Combine(dir, file)));
                }
            }

            // create font size
            var fontSize = new PixelFontSize()
            {
                Textures   = Textures,
                Characters = new Dictionary <int, PixelFontCharacter>(),
                LineHeight = data["common"].AttrInt("lineHeight"),
                Size       = size,
                Outline    = outline
            };

            // get characters
            foreach (XmlElement character in data["chars"])
            {
                int id   = character.AttrInt("id");
                int page = character.AttrInt("page", 0);
                fontSize.Characters.Add(id, new PixelFontCharacter(id, Textures[page], character));
            }

            // get kerning
            if (data["kernings"] != null)
            {
                foreach (XmlElement kerning in data["kernings"])
                {
                    var from = kerning.AttrInt("first");
                    var to   = kerning.AttrInt("second");
                    var push = kerning.AttrInt("amount");

                    PixelFontCharacter c = null;
                    if (fontSize.Characters.TryGetValue(from, out c))
                    {
                        c.Kerning.Add(to, push);
                    }
                }
            }

            // add font size
            Sizes.Add(fontSize);
            Sizes.Sort((a, b) => { return(Math.Sign(a.Size - b.Size)); });

            return(fontSize);
        }