I am creating an application that converts text to braille. Converting to braille is not a problem, but I do not know how to convert it.
Example 1: Converting Numbers to Braille
1 =
Example 2: Converting Capitals to Braille
Jonas = ,jonas JONAS = ,,jonas
I have a problem converting braille to normal. I cannot just convert all a to 1 and so on. The numbers can be checked with # , and then change the characters after it to the next space, but I don't know how to do it. The comma before the letter is more difficult to separate the text from other commas.
Here is my class for converting to braille:
using System; using System.Collections.Generic; using System.Text; using System.Drawing; namespace BrailleConverter { class convertingBraille { public Font getIndexBrailleFont() { return new Font("Index Braille Font", (float)28.5, FontStyle.Regular); } public Font getPrintableFontToEmbosser() { return new Font("Lucida Console", (float)28.5, FontStyle.Regular); //return new Font("Index Black Text Font", (float)28.5, FontStyle.Regular); } public string convertCapitalsToUnderscore(string text) { if (string.IsNullOrEmpty(text)) { return ""; } text = " " + text; text = text.Replace('.', '\''); text = text.Replace(',', '1'); text = text.Replace('?', '5'); text = text.Replace('!', '6'); text = text.Replace(':', '3'); text = text.Replace('=', '7'); text = text.Replace('+', '4'); text = text.Replace('*', '9'); text = text.Replace('Ă©', '='); StringBuilder newText = new StringBuilder(text.Length * 2); newText.Append(text[0]); bool firstCapLetterInWord = true; for (int i = 1; i < text.Length; i++) { char letter = text[i]; // Aktuell bokstav char nextLetter = ' '; // NĂ€sta bokstav try { nextLetter = text[i + 1]; } catch { } // Ăr det stor bokstav? if (char.IsUpper(letter)) { // Ăr nĂ€sta bokstav stor? if (char.IsUpper(nextLetter)) { // Ăr det början av ett helt ord med caps? if (firstCapLetterInWord) { newText.Append(",,"); // 2 st understrĂ€ck framför ordet firstCapLetterInWord = false; // Ăndra sĂ„ att inte nĂ€sta bokstav fĂ„r 2 st understrĂ€ck } } else // Annars bara ett understrĂ€ck { if (firstCapLetterInWord) { newText.Append(","); // SĂ€tt understrĂ€ck framför bokstav } firstCapLetterInWord = true; // Förbereda för nĂ€sta capsord } } newText.Append(text[i]); } string finishedText = newText.ToString().TrimStart(); // Ta bort mellanslaget i början finishedText = finishedText.ToLower(); finishedText = finishedText.Replace('Ă„', '*'); finishedText = finishedText.Replace('Ă€', '>'); finishedText = finishedText.Replace('ö', '['); return finishedText; } public string convertNumbersToBrailleNumbers(string text) { if (string.IsNullOrEmpty(text)) { return ""; } text = " " + text; StringBuilder newText = new StringBuilder(text.Length * 2); newText.Append(text[0]); bool firstNumberInNumber = true; for (int i = 1; i < text.Length; i++) { char letter = text[i]; // Aktuell tecken char nextLetter = ' '; // NĂ€sta tecken try { nextLetter = text[i + 1]; } catch { } char convertedChar = text[i]; // Ăr tecknet en siffra? if (char.IsNumber(letter)) { // Ăr nĂ€sta tecken en siffra? if (char.IsNumber(nextLetter)) { // Ăr det början av ett flertaligt nummer? if (firstNumberInNumber) { newText.Append('#'); // BrĂ€dkors framför nummret firstNumberInNumber = false; // Ăndra sĂ„ att inte nĂ€sta siffra fĂ„r brĂ€dkors } } else // Annars bara ett understrĂ€ck { if (firstNumberInNumber) { newText.Append('#'); // SĂ€tt brĂ€dkors framför siffran } firstNumberInNumber = true; // Förbereda för nĂ€sta flertaliga nummer } } newText.Append(convertedChar); } string finishedText = newText.ToString().TrimStart(); finishedText = finishedText.Replace('1', 'a'); finishedText = finishedText.Replace('2', 'b'); finishedText = finishedText.Replace('3', 'c'); finishedText = finishedText.Replace('4', 'd'); finishedText = finishedText.Replace('5', 'e'); finishedText = finishedText.Replace('6', 'f'); finishedText = finishedText.Replace('7', 'g'); finishedText = finishedText.Replace('8', 'h'); finishedText = finishedText.Replace('9', 'i'); finishedText = finishedText.Replace('0', 'j'); return finishedText; } public string convertBackToPrint(string oldText) { string newText = oldText.Replace(",", ""); newText = newText.Replace("#", ""); newText = newText.Replace("*", "Ă„"); newText = newText.Replace(">", "Ă€"); newText = newText.Replace("[", "ö"); newText = newText.Replace('\'', '.'); newText = newText.Replace('1', ','); newText = newText.Replace('5', '?'); newText = newText.Replace('6', '!'); newText = newText.Replace('3', ':'); newText = newText.Replace('7', '='); newText = newText.Replace('4', '+'); newText = newText.Replace('9', '*'); newText = newText.Replace('=', 'Ă©'); return newText; } } }