Пример #1
0
        private void loadToolStripMenuItem_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter      = "Text Files (.txt)|*.txt|Font Worx Files (.fwx)|*.fwx|All Files(*.*)|*.*";
            openFileDialog1.Multiselect = false;
            DialogResult openFileResult = openFileDialog1.ShowDialog();

            if (openFileResult == DialogResult.OK)
            {
                CharacterSet tmp = new CharacterSet();
                filePath = openFileDialog1.FileName;
                if (tmp.loadFromFile(filePath))
                {
                    this.Text = "FontWorx " + filePath;
                    CData.Clear();
                    CData.AddRange(tmp.Chars);
                    showSelectedGlyf();
                    textBox2.Text = tmp.Name;
                }
                else
                {
                    filePath = "";
                    MessageBox.Show("Failed to load file. Is it corrupt?");
                }
                if (FontPreview != null && FontPreview.IsDisposed == false)
                {
                    FontPreview.updateData(CData);
                }
            }
        }
Пример #2
0
        public bool loadFromFile(string fileName)
        {
            try
            {
                List <string> lines = new List <string>();
                if (!File.Exists(fileName))
                {
                    MessageBox.Show("File does not exist!");
                    return(false);
                }
                if (Path.GetExtension(fileName).ToLower() == ".fwx")
                {
                    try
                    {
                        IFormatter formatter = new BinaryFormatter();
                        using (FileStream fs = File.OpenRead(fileName))
                        {
                            CharacterSet temp = (CharacterSet)formatter.Deserialize(fs);
                            Name  = temp.Name;
                            Chars = temp.Chars;
                        }
                        return(true);
                    }
                    catch
                    {
                        //MessageBox.Show("An error occured while opening the file");
                        return(false);
                    }
                }
                StreamReader SR = new StreamReader(fileName);
                string       l  = "";
                while ((l = SR.ReadLine()) != null)
                {
                    if (l.Trim() != "")
                    {
                        lines.Add(l);
                    }
                }
                if (lines[0][0] != '{')
                {
                    MessageBox.Show("Bad File Start Syntax");
                    return(false);
                }
                if (lines[1][0] != '[')
                {
                    MessageBox.Show("Missing font name or bad syntax");
                    return(false);
                }

                string name = lines[1];
                name = name.TrimStart('[').TrimEnd(']');
                name = name.Trim(' ');
                Name = name;
                int id = 0;
                foreach (string ln in lines)
                {
                    if (ln[0] == '{' || ln[0] == '[' || ln[0] == '#')
                    {
                        continue;                                              //Skip over line starts
                    }
                    Character tmp  = new Character((char)(id++));
                    string    line = "";
                    if (ln.Contains("//"))
                    {
                        line = ln.Split('/')[0];
                    }
                    else
                    {
                        line = ln;
                    }

                    string[] vals    = line.Split(',');
                    int[]    glyfDat = new int[8];
                    int      i       = 0;
                    foreach (string s in vals)
                    {
                        string tmpVal = s.Trim(',');
                        tmpVal       = tmpVal.Trim(' ');
                        tmpVal       = tmpVal.Split('x')[1];
                        glyfDat[i++] = Convert.ToInt32(tmpVal, 16);
                    }
                    tmp.glyfData = glyfDat;
                    Chars.Add(tmp);
                }
                SR.Close();
                return(true);
            }
            catch
            {
                return(false);
            }
        }