Example #1
0
        /*
         * Original constructor took two variables as a parameters to initialize
         * font and character objects;
         * For testing purposes and to prevent keep opening FontTool.Window constructor
         * was changed and now its uses dummy objects;
         */
        public Editor(nFont font, nCharacter ch)
        {
            //}

            //public Editor()
            //{
            InitializeComponent();
            //_Font = testFont();
            //_Char = testCharacter();
            _Font = font;
            _Char = ch;

            propertyGrid1.SelectedObject = _Font;
            gfx = this.pictureBox1.CreateGraphics();

            timer1.Enabled = true;
            timer1.Interval = 100;

            img = Image.FromFile(_Char._Image);
            initDefaultLines();
            updatePreview();
            imgRect = new RectangleF(imageLocation.X, imageLocation.Y, img.Width, img.Height);
            this.MouseWheel +=new MouseEventHandler(Editor_MouseWheel);
        }
Example #2
0
        /*
         * Dummy testFont and testCharacter();
         * Both purposes is to make testing faster and prevent
         * going back and forward between this and FontTool to run Editor;
         * Create objects using predifined and the most important properties
         * which is some way are effecting Editor;
         */
        public nFont testFont()
        {
            nFont nfont = new nFont();
            nfont._Name = "testish";
            nfont._Space = 10;
            nfont._Kerning = 2;
            nfont._Leading = 0;
            nfont._xHeight = 18;
            nfont._capHeight = 29;
            nfont._ascenderHeight = 2;
            nfont._descenderHeight = 8;

            //Above Base
            nfont.LineXHeight = true;
            nfont.LineCapHeight = true;
            nfont.LineAscenderHeight = true;
            //Base
            nfont.LineBase = true;
            //Bellow Base
            nfont.LineLeading = true;
            nfont.LineDescenderHeight = true;

            return nfont;
        }
Example #3
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 #4
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 #5
0
 private void editCharacter(nFont font, nCharacter character)
 {
     using (Editor gc = new Editor(font, character))
     {
         DialogResult result = gc.ShowDialog();
         if (result == DialogResult.Cancel)
             this.InitViews();
     }
 }
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();
            }
        }