System.Collections.Generic.List<GlyphKeeper> GlyphWord = new List<GlyphKeeper>(); //THE CONTAINER FOR WORDS BEFORE THEY ARE WRITTEN #endregion Fields #region Constructors public ImageWriter(ref BackgroundWorker Slave, ref string ProcessStatus, string LangName, string FontID, string TransPath, bool UseSubList) { this.myFont = new Font(FontID, true, true); this.mySubs = new SubList(); CurrentLineBottomHeight = CurrentLineTopHeight + myFont.LineHeight; this.LangName = LangName; this.TranscriptPath = TransPath; //GET BASE NAME FOR FOLDER string[] TransParts = this.TranscriptPath.Split(new char[] { '\\' }); BaseName = TransParts[TransParts.Length - 1].ToLower().Replace(".txt", ""); //MAKE FOLDER OutputPath = db.DataDirectory + "\\TiffBoxPairs\\" + myFont.ID + "\\" + BaseName; if (!System.IO.Directory.Exists(db.DataDirectory + "\\TiffBoxPairs")) { System.IO.Directory.CreateDirectory(db.DataDirectory + "\\TiffBoxPairs"); } if (!System.IO.Directory.Exists(db.DataDirectory + "\\TiffBoxPairs\\" + myFont.ID)) { System.IO.Directory.CreateDirectory(db.DataDirectory + "\\TiffBoxPairs\\" + myFont.ID); } if (System.IO.Directory.Exists(OutputPath)) { Directory.Delete(OutputPath, true); System.Threading.Thread.Sleep(3000); System.IO.Directory.CreateDirectory(OutputPath); } else { System.IO.Directory.CreateDirectory(OutputPath); } //TURN CANVAS ALL WHITE for (int h = 0; h < HEIGHT; h++) { IMAGE[h] = new byte[WIDTH / BYTESIZE]; for (int bw = 0; bw < (WIDTH / BYTESIZE); bw++) { IMAGE[h][bw] = ALL_WHITE; } } //GET TRANSCRIPT WORDS System.IO.StreamReader Fin = new System.IO.StreamReader(TranscriptPath); string wordString = Fin.ReadToEnd().Replace("\n", " ").Replace("\r", " "); if(UseSubList) wordString = mySubs.ReplaceAll(wordString); string[] Words = wordString.Split(new char[] { ' ' }); Fin.Close(); double Increment = 100 / Words.Length; //WRITE WORDS for (int x = 0; x < Words.Length; x++) { if (Slave.CancellationPending) { break; } else { ProcessStatus = "Writing word \"" + Words[x] + "\"..."; Slave.ReportProgress(((int)(x * Increment))); } if (Words[x].Trim() != "") { char[] Letters = Words[x].ToCharArray(); for (int y = 0; y < Letters.Length; y++) { //for testing purposes, test for a character /* if (Letters[y] == '-') { string nothing = "break here"; } */ if (!UnaccountedFor.Contains(Letters[y].ToString())) { bool AccountedFor = false; int gIndex = myFont.FindGlyph(Letters[y].ToString()); if (gIndex > -1) { AccountedFor = myFont.Glyphs[gIndex].HasAvailableImage(); } if (AccountedFor) { AddGlyph(myFont.Glyphs[gIndex]); } else { UnaccountedFor.Add(Letters[y].ToString()); } } } WriteGlyphWord(); } } //CHECK TO SEE IF A TIFF FILE REMAINS TO BE WRITTEN bool NeedToWrite = false; for (int h = 0; h < HEIGHT; h++) { if (!NeedToWrite) { for (int bw = 0; bw < (WIDTH / BYTESIZE); bw++) { if (IMAGE[h][bw] != ALL_WHITE) { NeedToWrite = true; break; } } } else break; } if(NeedToWrite) WriteImage(OutputPath + "\\" + this.LangName + "." + myFont.Name + ".exp" + SeriesNo.ToString() + ".tif"); //LOG THE UNACCOUNTED CHARACTERS if (UnaccountedFor.Count > 0) { System.IO.StreamWriter Fout = new System.IO.StreamWriter(OutputPath + "\\unaccounted-for-characters.txt", true); Fout.WriteLine("Transcript: " + TranscriptPath); Fout.WriteLine(System.DateTime.Now.ToShortDateString() + " " + System.DateTime.Now.ToShortTimeString()); foreach (string S in UnaccountedFor) { string Formatted = S + " ("; char[] chars = S.ToCharArray(); for (int x = 0; x < chars.Length; x++) { if (x > 0) { Formatted += " "; } Formatted += string.Format("U+{0:x4}", (int)chars[x]); } Formatted += ")"; Fout.WriteLine(Formatted); } Fout.WriteLine(" "); Fout.WriteLine(" "); Fout.Close(); } }
public ImageWriter(ref BackgroundWorker Slave, ref string ProcessStatus, string LangName, string FontID, string TransPath, bool UseSubList) { this.myFont = new Font(FontID, true, true); this.mySubs = new SubList(); CurrentLineBottomHeight = CurrentLineTopHeight + myFont.LineHeight; this.LangName = LangName; this.TranscriptPath = TransPath; //GET BASE NAME FOR FOLDER string[] TransParts = this.TranscriptPath.Split(new char[] { '\\' }); BaseName = TransParts[TransParts.Length - 1].ToLower().Replace(".txt", ""); //MAKE FOLDER OutputPath = db.DataDirectory + "\\TiffBoxPairs\\" + myFont.ID + "\\" + BaseName; if (!System.IO.Directory.Exists(db.DataDirectory + "\\TiffBoxPairs")) { System.IO.Directory.CreateDirectory(db.DataDirectory + "\\TiffBoxPairs"); } if (!System.IO.Directory.Exists(db.DataDirectory + "\\TiffBoxPairs\\" + myFont.ID)) { System.IO.Directory.CreateDirectory(db.DataDirectory + "\\TiffBoxPairs\\" + myFont.ID); } if (System.IO.Directory.Exists(OutputPath)) { Directory.Delete(OutputPath, true); System.Threading.Thread.Sleep(3000); System.IO.Directory.CreateDirectory(OutputPath); } else { System.IO.Directory.CreateDirectory(OutputPath); } //TURN CANVAS ALL WHITE for (int h = 0; h < HEIGHT; h++) { IMAGE[h] = new byte[WIDTH / BYTESIZE]; for (int bw = 0; bw < (WIDTH / BYTESIZE); bw++) { IMAGE[h][bw] = ALL_WHITE; } } //GET TRANSCRIPT WORDS System.IO.StreamReader Fin = new System.IO.StreamReader(TranscriptPath); string wordString = Fin.ReadToEnd().Replace("\n", " ").Replace("\r", " "); if (UseSubList) { wordString = mySubs.ReplaceAll(wordString); } string[] Words = wordString.Split(new char[] { ' ' }); Fin.Close(); double Increment = 100 / Words.Length; //WRITE WORDS for (int x = 0; x < Words.Length; x++) { if (Slave.CancellationPending) { break; } else { ProcessStatus = "Writing word \"" + Words[x] + "\"..."; Slave.ReportProgress(((int)(x * Increment))); } if (Words[x].Trim() != "") { char[] Letters = Words[x].ToCharArray(); for (int y = 0; y < Letters.Length; y++) { //for testing purposes, test for a character /* * if (Letters[y] == '-') * { * string nothing = "break here"; * } */ if (!UnaccountedFor.Contains(Letters[y].ToString())) { bool AccountedFor = false; int gIndex = myFont.FindGlyph(Letters[y].ToString()); if (gIndex > -1) { AccountedFor = myFont.Glyphs[gIndex].HasAvailableImage(); } if (AccountedFor) { AddGlyph(myFont.Glyphs[gIndex]); } else { UnaccountedFor.Add(Letters[y].ToString()); } } } WriteGlyphWord(); } } //CHECK TO SEE IF A TIFF FILE REMAINS TO BE WRITTEN bool NeedToWrite = false; for (int h = 0; h < HEIGHT; h++) { if (!NeedToWrite) { for (int bw = 0; bw < (WIDTH / BYTESIZE); bw++) { if (IMAGE[h][bw] != ALL_WHITE) { NeedToWrite = true; break; } } } else { break; } } if (NeedToWrite) { WriteImage(OutputPath + "\\" + this.LangName + "." + myFont.Name + ".exp" + SeriesNo.ToString() + ".tif"); } //LOG THE UNACCOUNTED CHARACTERS if (UnaccountedFor.Count > 0) { System.IO.StreamWriter Fout = new System.IO.StreamWriter(OutputPath + "\\unaccounted-for-characters.txt", true); Fout.WriteLine("Transcript: " + TranscriptPath); Fout.WriteLine(System.DateTime.Now.ToShortDateString() + " " + System.DateTime.Now.ToShortTimeString()); foreach (string S in UnaccountedFor) { string Formatted = S + " ("; char[] chars = S.ToCharArray(); for (int x = 0; x < chars.Length; x++) { if (x > 0) { Formatted += " "; } Formatted += string.Format("U+{0:x4}", (int)chars[x]); } Formatted += ")"; Fout.WriteLine(Formatted); } Fout.WriteLine(" "); Fout.WriteLine(" "); Fout.Close(); } }