Exemple #1
0
        /*
         * Similar to saveXML method;
         * Using also Linq;?
         * Returns created Font object and also initializes it as the newFont
         * which is used as the source of info for all the windows;
         */
        private nFont loadFontXML()
        {
            nFont font = new nFont();

            using (OpenFileDialog ofd = new OpenFileDialog())
            {
                ofd.Title = "Open XML file";
                ofd.Filter = "Xml Files (.xml)|*.xml|All Files (*.*)|*.*";
                ofd.FilterIndex = 0;

                if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    XDocument xdoc = XDocument.Load(ofd.FileName);
                    oldDoc = xdoc;              //for saving later purposes
                    oldDocPath = ofd.FileName;  //for saving later purposes
                    font._Name = xdoc.Element("Font").Attribute("Name").Value;
                    font._Space = float.Parse(xdoc.Element("Font").Attribute("Space").Value);
                    font._Kerning = float.Parse(xdoc.Element("Font").Attribute("Kerning").Value);
                    font._Leading = float.Parse(xdoc.Element("Font").Attribute("Leading").Value);
                    font._xHeight = float.Parse(xdoc.Element("Font").Attribute("xHeight").Value);
                    font._capHeight = float.Parse(xdoc.Element("Font").Attribute("capHeight").Value);
                    font._ascenderHeight = float.Parse(xdoc.Element("Font").Attribute("ascenderHeight").Value);
                    font._descenderHeight = float.Parse(xdoc.Element("Font").Attribute("descenderHeight").Value);

                    foreach (XElement child in xdoc.Element("Font").Elements())
                    {
                        nCharacter c = new nCharacter(child.Attribute("unicode").Value,
                                float.Parse(child.Attribute("anchorPointX").Value),
                                float.Parse(child.Attribute("anchorPointY").Value),
                                float.Parse(child.Attribute("width").Value));
                        c._Image = Path.GetDirectoryName(ofd.FileName) + @"\" + c._Name + ".Png"; //taking xml file directory and adding to it file names;
                        c.guessValues(false, true, true, false);
                        //c.guessValues(true,true,true,true);
                        font._Characters.Add(c);
                    }
                    newFont = font;
                    refreshList();
                    newFont.guessFontValues();
                }
            }
            return font;
        }
Exemple #2
0
        /*
         * Almost identical method to the top one.
         * The only difference is that this one makes it easier for testing since it takes string and
         * loads it right away instead of waiting for me to openFileDialog;
         */
        private nFont loadFontXML(string uri)
        {
            nFont font = new nFont();
            XDocument xdoc = XDocument.Load(uri);
            string path = uri;
            oldDoc = xdoc;
            oldDocPath = path;

            font._Name = xdoc.Element("Font").Attribute("Name").Value;
            font._Space = float.Parse(xdoc.Element("Font").Attribute("Space").Value);
            font._Kerning = float.Parse(xdoc.Element("Font").Attribute("Kerning").Value);
            font._Leading = float.Parse(xdoc.Element("Font").Attribute("Leading").Value);
            font._xHeight = float.Parse(xdoc.Element("Font").Attribute("xHeight").Value);
            font._capHeight = float.Parse(xdoc.Element("Font").Attribute("capHeight").Value);
            font._ascenderHeight = float.Parse(xdoc.Element("Font").Attribute("ascenderHeight").Value);
            font._descenderHeight = float.Parse(xdoc.Element("Font").Attribute("descenderHeight").Value);

            foreach (XElement child in xdoc.Element("Font").Elements())
            {
                nCharacter c = new nCharacter(child.Attribute("unicode").Value,
                        float.Parse(child.Attribute("anchorPointX").Value),
                        float.Parse(child.Attribute("anchorPointY").Value),
                        float.Parse(child.Attribute("width").Value));
                c._Image = Path.GetDirectoryName(path) + @"\" + c._Name + ".Png"; //taking xml file directory and adding to it file names;
                c.guessValues(false, true, true, false);
                //c.guessValues(true,true,true,true);
                font._Characters.Add(c);
            }
            newFont = font;
            refreshList();
            newFont.guessFontValues();

            return font;
        }
Exemple #3
0
        /*
         * Opens fileDialog for selecting images;
         * creates new empty Font;
         * Fills font with selected images
         */
        private void createFontFromImg()
        {
            using (OpenFileDialog OFD = new OpenFileDialog())
            {
                OFD.Multiselect = true;
                OFD.Filter = "JPEG .jpeg|*.jpeg;*.jpg|PNG .png|*.png|All files (*.*)|*.*";
                OFD.FilterIndex = 2;
                OFD.Title = "Select image files";

                if (OFD.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                {
                    return;
                }

                newFont = new nFont();
                foreach (string link in OFD.FileNames)
                {
                    nCharacter _char = new nCharacter();
                    _char._Image = link;
                    _char._Name = Path.GetFileNameWithoutExtension(link);
                    _char.guessValues(true, true, true, true);
                    newFont._Characters.Add(_char);
                }
                refreshList();
                newFont.guessFontValues();
                createFontXML();
            }
        }