Ejemplo n.º 1
0
        private void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listBox1.SelectedIndex < 0)
            {
                return;
            }
            if (listBox1.SelectedItem is AtlasItemSourceFile atlasItemFile)
            {
                _selectedAtlasItemSourceFile = atlasItemFile;
                //check if it is image file or not
                DisposeExistingPictureBoxImage(pictureBox1);
                switch (atlasItemFile.Extension)
                {
                case ".png":
                    pictureBox1.Image = new Bitmap(atlasItemFile.AbsoluteFilename);
                    break;

                default:
                    break;
                }
            }
        }
Ejemplo n.º 2
0
        static void TryReadConfigFile(AtlasItemSourceFile atlasSrcItem)
        {
            XmlDocument xmldoc = new XmlDocument();

            xmldoc.Load(atlasSrcItem.AbsoluteFilename);
            XmlElement docElem = xmldoc.DocumentElement;

            switch (docElem.Name)
            {
            case "typeface_builder_config":
                //this  typeface config
                ReadFontBuilderConfig(atlasSrcItem, docElem);
                //change item kind to config
                atlasSrcItem.Kind     = AtlasItemSourceKind.FontAtlasConfig;
                atlasSrcItem.IsConfig = true;
                break;

            case "resource_builder_config":
                atlasSrcItem.Kind     = AtlasItemSourceKind.ResourceConfig;
                atlasSrcItem.IsConfig = true;
                break;
            }
        }
Ejemplo n.º 3
0
        static void ReadFontBuilderConfig(AtlasItemSourceFile atlasSrcItem, XmlElement docElem)
        {
            FontBuilderConfig fontBuilderConfig = new FontBuilderConfig();

            //cut 1 extension
            //if font filename=aaa.ttf
            //configure must be aaa.ttf.xml

            fontBuilderConfig.FontFilename = Path.GetFileNameWithoutExtension(atlasSrcItem.AbsoluteFilename);
            atlasSrcItem.FontBuilderConfig = fontBuilderConfig;

            foreach (XmlElement setElem in docElem.SelectNodes("set"))
            {
                //defail
                fontBuilderConfig.SetTextureKind(setElem.GetAttribute("texture_kind"));
                foreach (XmlNode cc in setElem.ChildNodes)
                {
                    if (cc is XmlElement childElem)
                    {
                        switch (childElem.Name)
                        {
                        case "script_lang":
                            fontBuilderConfig.AddScriptLangAndHint(
                                childElem.GetAttribute("lang"),
                                childElem.GetAttribute("hint"));
                            break;

                        case "size":
                            fontBuilderConfig.SetSizeList(childElem.InnerText);
                            break;
                        }
                    }
                }
            }
            fontBuilderConfig.BuildConfigDetail();
        }
Ejemplo n.º 4
0
        public void LoadProjectDetail()
        {
            //we support bitmap font atlas
            //and font-atlas

            Items = new List <AtlasItemSourceFile>();

            string dir = Path.GetDirectoryName(FullFilename);

            OutputFilename = dir + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(FullFilename);

            XmlDocument xmldoc = new XmlDocument();

            xmldoc.Load(FullFilename);
            string xmlNs = xmldoc.DocumentElement.GetAttribute("xmlns");

            XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmldoc.NameTable);

            //xml note: check if project file has namespace or not
            //if it has namespace=> we need to add namespace manager too

            string onlyDirName = Path.GetDirectoryName(FullFilename);
            string ns          = "";

            if (xmlNs != "")
            {
                ns = "cs";
                nsmgr.AddNamespace(ns, xmlNs);
                ns += ":";
            }

            foreach (XmlElement content in xmldoc.DocumentElement.SelectNodes("//" + ns + "Content", nsmgr))
            {
                //content node
                string include   = content.GetAttribute("Include");
                string extension = Path.GetExtension(include);
                switch (extension)
                {
                case ".css":
                case ".html":
                case ".htm":
                case ".svg":
                case ".txt":
                case ".xml":     //data or config
                case ".png":
                {
                    var atlasItemFile = new AtlasItemSourceFile();
                    atlasItemFile.Include          = include;
                    atlasItemFile.Extension        = extension;
                    atlasItemFile.AbsoluteFilename = PathUtils.GetAbsolutePathRelativeTo(include, onlyDirName);
                    atlasItemFile.FileExist        = File.Exists(atlasItemFile.AbsoluteFilename);
                    if (content.SelectSingleNode(ns + "Link", nsmgr) is XmlElement linkNode)
                    {
                        atlasItemFile.Link = linkNode.InnerText;
                    }
                    else
                    {
                        //no link node, use include
                        atlasItemFile.Link = include;
                    }
                    Items.Add(atlasItemFile);
                }
                break;
                }
            }

            foreach (XmlElement content in xmldoc.DocumentElement.SelectNodes("//" + ns + "None", nsmgr))
            {
                string include   = content.GetAttribute("Include");
                string extension = Path.GetExtension(include);
                switch (extension)
                {
                case ".ttf":
                case ".otf":
                {
                    //TODO: include webfont (woff2, woff1), ttc,otc
                    var atlasItemFile = new AtlasItemSourceFile();
                    atlasItemFile.Include          = include;
                    atlasItemFile.Extension        = extension;
                    atlasItemFile.AbsoluteFilename = PathUtils.GetAbsolutePathRelativeTo(include, onlyDirName);
                    atlasItemFile.FileExist        = File.Exists(atlasItemFile.AbsoluteFilename);
                    if (content.SelectSingleNode(ns + "Link", nsmgr) is XmlElement linkNode)
                    {
                        atlasItemFile.Link = linkNode.InnerText;
                    }
                    else
                    {
                        //no link node, use include
                        atlasItemFile.Link = include;
                    }
                    Items.Add(atlasItemFile);
                }
                break;
                }
            }
            Isloaded = true;

            //------
            //then resolve for absolute filename
            foreach (AtlasItemSourceFile atlasItem in Items)
            {
                string include = atlasItem.Include;
                if (Path.IsPathRooted(include))
                {
                    atlasItem.AbsoluteFilename = include;
                }
                else
                {
                    //relative to the project file
                }
            }

            string onlyFilename = Path.GetFileNameWithoutExtension(Filename);

            CsSourceNamespace = "Atlas_AUTOGEN_." + onlyFilename;
            //------
            //check for config data

            ResolveItems();
        }