示例#1
0
        /*
         * Load settings
         */

        private void _btnLoad_Click(object sender, EventArgs e)
        {
            try {
                // get filename

                if (_openFileDialog.ShowDialog() == DialogResult.Cancel)
                {
                    return;
                }

                // load operation

                _sizedFont = FontReader.Load(_openFileDialog.FileName);

                _editFontFile.Text = _sizedFont.Filename;
                _fontSize.Value    = _sizedFont.Size;
                _extraLines.Value  = _sizedFont.ExtraLines;
                _xoffset.Value     = _sizedFont.XOffset;
                _yoffset.Value     = _sizedFont.YOffset;
                _charSpace.Value   = _sizedFont.CharSpace;

                EnableControls();
                RefillCharsPanel();
            }
            catch (Exception ex) {
                Util.Error(ex);
            }
        }
示例#2
0
        /*
         * Browse for font file
         */

        private void _btnBrowseFontFile_Click(object sender, EventArgs e)
        {
            try {
                // browse for font

                if (_openFontFileDialog.ShowDialog(this) == DialogResult.Cancel)
                {
                    return;
                }

                // set the filename

                _editFontFile.Text = _openFontFileDialog.FileName;

                // create the font

                _sizedFont = new SizedFont(_openFontFileDialog.FileName, Convert.ToInt32(_fontSize.Value));

                _preview.Font = _sizedFont.GdiFont;
                _preview.Invalidate();

                EnableControls();
                RefillCharsPanel();
            }
            catch (Exception ex) {
                Util.Error(ex);
            }
        }
示例#3
0
        /*
         * Constructor
         */

        protected FontWriter(SizedFont sf, StreamWriter headerWriter, StreamWriter sourceWriter, XmlElement parent, Control refControl)
        {
            _font         = sf;
            _headerWriter = headerWriter;
            _sourceWriter = sourceWriter;
            _parent       = parent;
            _refControl   = refControl;
        }
示例#4
0
 /*
  * Constructor
  */
 protected FontWriter(SizedFont sf,StreamWriter headerWriter,StreamWriter sourceWriter,XmlElement parent,Control refControl)
 {
     _font=sf;
       _headerWriter=headerWriter;
       _sourceWriter=sourceWriter;
       _parent=parent;
       _refControl=refControl;
 }
示例#5
0
        /*
           * load from XML
           */
        public static SizedFont Load(String filename)
        {
            XmlDocument doc;
              XmlNodeList charsNodes;
              char c;
              String fontfile;
              int fontsize;
              SizedFont sf;

              // read the XML

              doc=new XmlDocument();
              doc.Load(filename);

              // get file and size to create the SizedFont

              fontfile=XmlUtil.GetString(doc.DocumentElement,"Filename",null,true);
              fontsize=XmlUtil.GetInt(doc.DocumentElement,"Size",0,true);

              // give the user the chance to find missing fonts

              if(!File.Exists(fontfile)) {

            OpenFileDialog ofn;

            if(MessageBox.Show(fontfile+" does not exist. Click OK to browse for the font file or Cancel to abort","Font not found",MessageBoxButtons.OKCancel,MessageBoxIcon.Stop)==DialogResult.Cancel)
              throw new Exception("Font not found");

            ofn=new OpenFileDialog();

            ofn.FileName=fontfile;
            ofn.Filter="Font Files (*.ttf)|*.ttf|All Files (*.*)|*.*||";

            if(ofn.ShowDialog()==DialogResult.Cancel)
              throw new Exception("Font not found");

            fontfile=ofn.FileName;
              }

              sf=new SizedFont(fontfile,fontsize);

              // fill in the adjustments

              sf.XOffset=XmlUtil.GetInt(doc.DocumentElement,"XOffset",0,true);
              sf.YOffset=XmlUtil.GetInt(doc.DocumentElement,"YOffset",0,true);
              sf.ExtraLines=XmlUtil.GetInt(doc.DocumentElement,"ExtraLines",0,true);
              sf.CharSpace=XmlUtil.GetInt(doc.DocumentElement,"CharSpace",0,true);

              if((charsNodes=doc.DocumentElement.SelectNodes("Chars/Char"))!=null) {

            foreach(XmlNode charNode in charsNodes) {
              c=Convert.ToChar(UInt16.Parse(charNode.InnerText));
              sf.Add(c);
            }
              }

              return sf;
        }
示例#6
0
        /*
         * Save font
         */
        public static void Save(SizedFont sf,String xmlFilename,Control refControl,TargetDevice targetDevice)
        {
            String headerFilename,sourceFilename;
              XmlDocument doc;
              XmlElement root;
              FontWriter fw;

              // filename has .xml extension. calculate same name with .h and .cpp

              headerFilename=Path.GetFileNameWithoutExtension(xmlFilename)+".h";
              headerFilename=Path.Combine(Path.GetDirectoryName(xmlFilename),headerFilename);

              sourceFilename=Path.GetFileNameWithoutExtension(xmlFilename)+".cpp";
              sourceFilename=Path.Combine(Path.GetDirectoryName(xmlFilename),sourceFilename);

              // create header stream

              using(StreamWriter headerWriter=new StreamWriter(headerFilename)) {
            using(StreamWriter sourceWriter=new StreamWriter(sourceFilename)) {

              // create XML parent

              doc=new XmlDocument();
              root=doc.CreateElement("FontConv");
              doc.AppendChild(root);

              switch(targetDevice) {

            case TargetDevice.ARDUINO:
              fw=new ArduinoFontWriter(sf,headerWriter,sourceWriter,root,refControl);
              break;

            case TargetDevice.STM32PLUS:
              fw=new Stm32plusFontWriter(sf,headerWriter,sourceWriter,root,refControl);
              break;

            default:
              throw new Exception("Unknown device");
              }

              fw.Save();
              doc.Save(xmlFilename);
            }
              }
        }
示例#7
0
        /*
         * Save font
         */

        static public void Save(SizedFont sf, String xmlFilename, Control refControl, TargetDevice targetDevice)
        {
            String      headerFilename, sourceFilename;
            XmlDocument doc;
            XmlElement  root;
            FontWriter  fw;

            // filename has .xml extension. calculate same name with .h and .cpp

            headerFilename = Path.GetFileNameWithoutExtension(xmlFilename) + ".h";
            headerFilename = Path.Combine(Path.GetDirectoryName(xmlFilename), headerFilename);

            sourceFilename = Path.GetFileNameWithoutExtension(xmlFilename) + ".cpp";
            sourceFilename = Path.Combine(Path.GetDirectoryName(xmlFilename), sourceFilename);

            // create header stream

            using (StreamWriter headerWriter = new StreamWriter(headerFilename)) {
                using (StreamWriter sourceWriter = new StreamWriter(sourceFilename)) {
                    // create XML parent

                    doc  = new XmlDocument();
                    root = doc.CreateElement("FontConv");
                    doc.AppendChild(root);

                    switch (targetDevice)
                    {
                    case TargetDevice.ARDUINO:
                        fw = new ArduinoFontWriter(sf, headerWriter, sourceWriter, root, refControl);
                        break;

                    case TargetDevice.STM32PLUS:
                        fw = new Stm32plusFontWriter(sf, headerWriter, sourceWriter, root, refControl);
                        break;

                    default:
                        throw new Exception("Unknown device");
                    }

                    fw.Save();
                    doc.Save(xmlFilename);
                }
            }
        }
示例#8
0
        /*
         * Constructor
         */

        public ArduinoFontWriter(SizedFont sf, StreamWriter headerWriter, StreamWriter sourceWriter, XmlElement parent, Control refControl)
            : base(sf, headerWriter, sourceWriter, parent, refControl)
        {
        }
示例#9
0
        /*
         * load from XML
         */

        static public SizedFont Load(String filename)
        {
            XmlDocument doc;
            XmlNodeList charsNodes;
            char        c;
            String      fontfile;
            int         fontsize;
            SizedFont   sf;

            // read the XML

            doc = new XmlDocument();
            doc.Load(filename);

            // get file and size to create the SizedFont

            fontfile = XmlUtil.GetString(doc.DocumentElement, "Filename", null, true);
            fontsize = XmlUtil.GetInt(doc.DocumentElement, "Size", 0, true);

            // give the user the chance to find missing fonts

            if (!File.Exists(fontfile))
            {
                OpenFileDialog ofn;

                if (MessageBox.Show(fontfile + " does not exist. Click OK to browse for the font file or Cancel to abort", "Font not found", MessageBoxButtons.OKCancel, MessageBoxIcon.Stop) == DialogResult.Cancel)
                {
                    throw new Exception("Font not found");
                }

                ofn = new OpenFileDialog();

                ofn.FileName = fontfile;
                ofn.Filter   = "Font Files (*.ttf)|*.ttf|All Files (*.*)|*.*||";

                if (ofn.ShowDialog() == DialogResult.Cancel)
                {
                    throw new Exception("Font not found");
                }

                fontfile = ofn.FileName;
            }

            sf = new SizedFont(fontfile, fontsize);

            // fill in the adjustments

            sf.XOffset    = XmlUtil.GetInt(doc.DocumentElement, "XOffset", 0, true);
            sf.YOffset    = XmlUtil.GetInt(doc.DocumentElement, "YOffset", 0, true);
            sf.ExtraLines = XmlUtil.GetInt(doc.DocumentElement, "ExtraLines", 0, true);
            sf.CharSpace  = XmlUtil.GetInt(doc.DocumentElement, "CharSpace", 0, true);

            if ((charsNodes = doc.DocumentElement.SelectNodes("Chars/Char")) != null)
            {
                foreach (XmlNode charNode in charsNodes)
                {
                    c = Convert.ToChar(UInt16.Parse(charNode.InnerText));
                    sf.Add(c);
                }
            }

            return(sf);
        }
示例#10
0
 /*
  * Constructor
  */
 public ArduinoFontWriter(SizedFont sf,StreamWriter headerWriter,StreamWriter sourceWriter,XmlElement parent,Control refControl)
     : base(sf,headerWriter,sourceWriter,parent,refControl)
 {
 }
示例#11
0
        /*
         * Load settings
         */
        private void _btnLoad_Click(object sender,EventArgs e)
        {
            try {

            // get filename

            if(_openFileDialog.ShowDialog()==DialogResult.Cancel)
              return;

            // load operation

            _sizedFont=FontReader.Load(_openFileDialog.FileName);

            _editFontFile.Text=_sizedFont.Filename;
            _fontSize.Value=_sizedFont.Size;
            _extraLines.Value=_sizedFont.ExtraLines;
            _xoffset.Value=_sizedFont.XOffset;
            _yoffset.Value=_sizedFont.YOffset;
            _charSpace.Value=_sizedFont.CharSpace;

            EnableControls();
            RefillCharsPanel();
              }
              catch(Exception ex) {
            Util.Error(ex);
              }
        }
示例#12
0
        /*
         * Browse for font file
         */
        private void _btnBrowseFontFile_Click(object sender,EventArgs e)
        {
            try {
            // browse for font

            if(_openFontFileDialog.ShowDialog(this)==DialogResult.Cancel)
              return;

            // set the filename

            _editFontFile.Text=_openFontFileDialog.FileName;

            // create the font

            _sizedFont=new SizedFont(_openFontFileDialog.FileName,Convert.ToInt32(_fontSize.Value));

            _preview.Font=_sizedFont.GdiFont;
            _preview.Invalidate();

            EnableControls();
            RefillCharsPanel();
              }
              catch(Exception ex) {
            Util.Error(ex);
              }
        }