Example #1
0
        public void AddImage(string ImagePath)
        {
            GlyphImage GI = new GlyphImage();

            GI.GlyphID = this.ID;
            GI.Path    = ImagePath;
            GI.Save();
            this.Images.Add(GI);
        }
Example #2
0
        public void RefreshImages()
        {
            this.Images.Clear();

            if (db.GetRows("select img_id from images where img_glyph_id = " + this.ID))
            {
                DataTable ImageTable = db.Bucket.Copy();

                for (int x = 0; x < ImageTable.Rows.Count; x++)
                {
                    if (x > 199)
                    {
                        HasMore = true;
                        break;
                    }
                    GlyphImage GI = new GlyphImage(ImageTable.Rows[x][0].ToString());
                    this.Images.Add(GI);
                }
            }
        }
Example #3
0
        private void importFontToolStripMenuItem_Click(object sender, EventArgs e)
        {
            fileBrowser.Filter = "Zip Files (*.zip)|*.zip";
            DialogResult res = fileBrowser.ShowDialog();
            string FontZipFile = "";
            string FontName = "";
            string FontDir = "";

            if (res == System.Windows.Forms.DialogResult.OK)
            {
                FontZipFile = fileBrowser.FileName;

                NewLanguage langForm = new NewLanguage(true);
                langForm.ShowDialog();

                if (langForm.NewName != "")
                {
                    FontName = langForm.NewName;
                    App_Code.Font impFont = new App_Code.Font();
                    impFont.Name = FontName;
                    impFont.Save(false);

                    FontDir = db.DataDirectory + "\\Temp\\" + impFont.ID;

                    if(!Directory.Exists(db.DataDirectory + "\\GlyphExtraction\\Output\\" + impFont.ID))
                    {
                        Directory.CreateDirectory(db.DataDirectory + "\\GlyphExtraction\\Output\\" + impFont.ID);
                    }

                    if(!Directory.Exists(db.DataDirectory + "\\TiffBoxPairs\\" + impFont.ID))
                    {
                        Directory.CreateDirectory(db.DataDirectory + "\\TiffBoxPairs\\" + impFont.ID);
                    }

                    if (!Directory.Exists(db.DataDirectory + "\\Temp"))
                    {
                        Directory.CreateDirectory(db.DataDirectory + "\\Temp");
                    }

                    if (Directory.Exists(FontDir))
                    {
                        Directory.Delete(FontDir, true);
                    }

                    ZipFile.ExtractToDirectory(FontZipFile, FontDir);

                    if (Directory.Exists(FontDir))
                    {
                        if (Directory.Exists(FontDir + "\\GlyphExtraction\\Output\\FONTNAME"))
                        {
                            string[] subDirs = Directory.GetDirectories(FontDir + "\\GlyphExtraction\\Output\\FONTNAME");

                            foreach (string subDir in subDirs)
                            {
                                string[] subDirParts = subDir.Split(new char[] { '\\' });
                                string subDirName = subDirParts[subDirParts.Length - 1];

                                DirectoryInfo From = new DirectoryInfo(subDir);
                                DirectoryInfo To = new DirectoryInfo(db.DataDirectory + "\\GlyphExtraction\\Output\\" + impFont.ID + "\\" + subDirName);
                                CopyDir(From, To);
                            }
                        }

                        if (Directory.Exists(FontDir + "\\TiffBoxPairs\\FONTNAME"))
                        {
                            string[] subDirs = Directory.GetDirectories(FontDir + "\\TiffBoxPairs\\FONTNAME");

                            foreach (string subDir in subDirs)
                            {
                                string[] subDirParts = subDir.Split(new char[] { '\\' });
                                string subDirName = subDirParts[subDirParts.Length - 1];

                                DirectoryInfo From = new DirectoryInfo(subDir);
                                DirectoryInfo To = new DirectoryInfo(db.DataDirectory + "\\TiffBoxPairs\\" + impFont.ID + "\\" + subDirName);
                                CopyDir(From, To);
                            }
                        }

                        //read font data
                        if (File.Exists(FontDir + "\\font.txt"))
                        {
                            using (StreamReader Fin = new StreamReader(FontDir + "\\font.txt"))
                            {
                                string Line = "";
                                while ((Line = Fin.ReadLine()) != null)
                                {
                                    string[] lineParts = Line.Split(new char[] { ':' });

                                    switch (lineParts[0])
                                    {
                                        case "lineheight": impFont.LineHeight = System.Convert.ToInt32(lineParts[1].Trim());
                                            break;
                                        case "bold": impFont.Bold = System.Convert.ToInt32(lineParts[1].Trim());
                                            break;
                                        case "fixed": impFont.Fixed = System.Convert.ToInt32(lineParts[1].Trim());
                                            break;
                                        case "fraktur": impFont.Fraktur = System.Convert.ToInt32(lineParts[1].Trim());
                                            break;
                                        case "italic": impFont.Italic = System.Convert.ToInt32(lineParts[1].Trim());
                                            break;
                                        case "serif": impFont.Serif = System.Convert.ToInt32(lineParts[1].Trim());
                                            break;
                                    }
                                }

                                Fin.Close();
                                impFont.Save(false);
                            }
                        }

                        //read glyphs
                        if (impFont.ID != "")
                        {
                            string[] glyphFiles = Directory.GetFiles(FontDir, "glyph*.txt");
                            foreach (string glyphFile in glyphFiles)
                            {
                                Glyph imGlyph = new Glyph();
                                imGlyph.FontID = impFont.ID;

                                using (StreamReader Fin = new StreamReader(glyphFile))
                                {
                                    string Line = "";
                                    while ((Line = Fin.ReadLine()) != null)
                                    {
                                        string[] lineParts = Line.Split(new char[] { ':' });

                                        switch (lineParts[0])
                                        {
                                            case "unicode": if (Line.Trim() == "unicode::")
                                                {
                                                    imGlyph.Unicode = ":";
                                                }
                                                else
                                                {
                                                    imGlyph.Unicode = lineParts[1].Trim();
                                                }
                                                break;
                                            case "xoffset": imGlyph.XOffset = float.Parse(lineParts[1].Trim());
                                                break;
                                            case "yoffset": imGlyph.YOffset = float.Parse(lineParts[1].Trim());
                                                imGlyph.Save(false);
                                                break;
                                            case "image": if (imGlyph.ID != "" && lineParts.Length == 3)
                                                {
                                                    GlyphImage imImg = new GlyphImage();
                                                    imImg.GlyphID = imGlyph.ID;
                                                    imImg.Path = lineParts[1].Trim().Replace("\\GlyphExtraction\\Output\\FONTNAME", "\\GlyphExtraction\\Output\\" + impFont.ID);
                                                    imImg.Status = lineParts[2].Trim();
                                                    imImg.Save();
                                                }
                                                break;
                                        }
                                    }

                                    Fin.Close();
                                }
                            }
                        }

                        //clean up
                        if (Directory.Exists(FontDir))
                        {
                            Directory.Delete(FontDir, true);
                        }

                        RefreshFontList();
                        MessageBox.Show("Font '" + FontName + "' imported successfully.");
                    }
                }
            }
        }
Example #4
0
        private void copyFontButton_Click(object sender, EventArgs e)
        {
            if (fontBox.SelectedItem != null)
            {
                NewLanguage langForm = new NewLanguage(true);
                langForm.ShowDialog();

                if (langForm.NewName != "" && langForm.NewName != (fontBox.SelectedItem as App_Code.Font).Name)
                {
                    App_Code.Font newFont = new App_Code.Font();
                    newFont.Name = langForm.NewName;
                    newFont.LineHeight = (fontBox.SelectedItem as App_Code.Font).LineHeight;
                    newFont.LangID = (fontBox.SelectedItem as App_Code.Font).LangID;
                    newFont.Bold = (fontBox.SelectedItem as App_Code.Font).Bold;
                    newFont.Fixed = (fontBox.SelectedItem as App_Code.Font).Fixed;
                    newFont.Fraktur = (fontBox.SelectedItem as App_Code.Font).Fraktur;
                    newFont.Italic = (fontBox.SelectedItem as App_Code.Font).Italic;
                    newFont.Serif = (fontBox.SelectedItem as App_Code.Font).Serif;
                    newFont.Save(false);

                    string oldDir = db.DataDirectory + "\\GlyphExtraction\\Output\\" + (fontBox.SelectedItem as App_Code.Font).ID;
                    string newDir = db.DataDirectory + "\\GlyphExtraction\\Output\\" + newFont.ID;
                    bool Copied = false;

                    if (Directory.Exists(oldDir))
                    {
                        try
                        {
                            DirectoryInfo Source = new DirectoryInfo(oldDir);
                            DirectoryInfo Target = new DirectoryInfo(newDir);
                            CopyDir(Source, Target);
                            Copied = true;
                        }
                        catch (Exception E)
                        {
                            MessageBox.Show("Unable to copy glyph images to new font!");
                        }
                    }

                    if (Copied)
                    {
                        if (db.GetRows("select * from glyphs where glyph_font_id = " + (fontBox.SelectedItem as App_Code.Font).ID))
                        {
                            using (DataTable GlyphTable = db.Bucket.Copy())
                            {
                                for (int x = 0; x < GlyphTable.Rows.Count; x++)
                                {
                                    Glyph g = new Glyph();
                                    g.FontID = newFont.ID;
                                    g.Unicode = GlyphTable.Rows[x]["glyph_unicode"].ToString();
                                    g.XOffset = float.Parse(GlyphTable.Rows[x]["glyph_x_offset"].ToString());
                                    g.YOffset = float.Parse(GlyphTable.Rows[x]["glyph_y_offset"].ToString());
                                    g.Save(false);

                                    if (db.GetRows("select * from images where img_glyph_id = " + GlyphTable.Rows[x]["glyph_id"].ToString()))
                                    {
                                        using(DataTable ImageTable = db.Bucket.Copy())
                                        {
                                            for(int y = 0; y < ImageTable.Rows.Count; y++)
                                            {
                                                GlyphImage img = new GlyphImage();
                                                img.GlyphID = g.ID;
                                                img.Path = ImageTable.Rows[y]["img_path"].ToString().Replace("\\Output\\" + (fontBox.SelectedItem as App_Code.Font).ID + "\\", "\\Output\\" + newFont.ID + "\\");
                                                img.Status = ImageTable.Rows[y]["img_status"].ToString();
                                                img.Save();
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Please enter a valid name for the new font (must be different from the one you are copying).");
                }
            }

            RefreshFontList();
        }
Example #5
0
        void imageContextShowInfo_Click(object sender, EventArgs e)
        {
            GlyphImage GI = new GlyphImage(((sender as ToolStripMenuItem).GetCurrentParent() as ContextMenuStrip).SourceControl.Name);
            using (Tiff input = Tiff.Open(db.DataDirectory + GI.Path, "r"))
            {
                int GlyphWidth = input.GetField(TiffTag.IMAGEWIDTH)[0].ToInt();
                int GlyphHeight = input.GetField(TiffTag.IMAGELENGTH)[0].ToInt();
                int GlyphScanSize = input.ScanlineSize();

                MessageBox.Show("Width: " + GlyphWidth + Environment.NewLine + "Height: " + GlyphHeight + Environment.NewLine + "Scansize: " + GlyphScanSize + Environment.NewLine + "Path: " + db.DataDirectory + GI.Path);

            }
        }
Example #6
0
        public void RefreshImages()
        {
            this.Images.Clear();

            if (db.GetRows("select img_id from images where img_glyph_id = " + this.ID))
            {
                DataTable ImageTable = db.Bucket.Copy();

                for (int x = 0; x < ImageTable.Rows.Count; x++)
                {
                    if (x > 199)
                    {
                        HasMore = true;
                        break;
                    }
                    GlyphImage GI = new GlyphImage(ImageTable.Rows[x][0].ToString());
                    this.Images.Add(GI);
                }
            }
        }
Example #7
0
 public void AddImage(string ImagePath)
 {
     GlyphImage GI = new GlyphImage();
     GI.GlyphID = this.ID;
     GI.Path = ImagePath;
     GI.Save();
     this.Images.Add(GI);
 }