Example #1
0
        public nCharacter testCharacter()
        {
            nCharacter nchar = new nCharacter();
            nchar._Image = @"C:\Users\Min0\Desktop\testFont\0x0040.png";
            nchar._Name = "0x0040";
            nchar.guessValues(true, true, true, true);

            return nchar;
        }
Example #2
0
 /*
  * Methods name are self-explanationary and so there is no need
  * to write more details about it.
  * What worth mentioning that methods are using each other.
  * I.E. to updateCharacter we first will use getCharacter;
  * Every method is droped in between try\catch statement;
  * Catch statement returns MessageBox with text stating Class.Method.ErrorMessage;
  */
 public nCharacter createCharacter(string image)
 {
     try
     {
         nCharacter c = new nCharacter();
         c._Image = image;
         c.guessValues(true, true, true, true);
         return c;
     }
     catch (Exception ex)
     {
         MessageBox.Show("_Font.createCharacter() \n" + ex.Message);
     }
     return null;
 }
Example #3
0
 public void addCharacter(string image)
 {
     try
     {
         if (getCharacter(Path.GetFileNameWithoutExtension(image)) == null)
         {
             nCharacter c = new nCharacter();
             c._Image = image;
             c.guessValues(true, true, true, true);
             _Characters.Add(c);
             Helper.sortCharacterList(_Characters);
         }
         else
             MessageBox.Show("_Font.addCharacter() \n" + "Character with this 'HEX' value already exist");
     }
     catch (Exception ex)
     {
         MessageBox.Show("_Font.addCharacter() \n"+ex.Message);
     }
 }
Example #4
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;
        }
Example #5
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;
        }
Example #6
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();
            }
        }