예제 #1
0
        /// <summary>
        /// Generates Font Pack from CSV. Does not import generated pack.
        /// </summary>
        /// <param name="path">File to generate from. Must have comma sparated values.</param>
        /// <returns></returns>
        public static CopticFont GenerateFromCsv(string path)
        {
            var font = new CopticFont()
            {
                Name             = "Imported Font",
                FontName         = "Arial",
                IsCopticStandard = false
            };

            string[] lines = File.ReadAllLines(path);
            foreach (string line in lines)
            {
                font.Charmap.Add(line.Split(',')[0], line.Split(',')[1]);
            }

            return(font);
        }
예제 #2
0
        public static string ParseTextCommands(string input)
        {
            // Define a regular expression that captures LaTeX-style commands with 0, 1, or 2 parameters
            Regex rx = new Regex(@"(?:\\)(?<command>\w+)(?:\{(?<param1>[^\{\}]*)\})?(?:\{(?<param2>[^\{\}]*)\})+?",
                                 RegexOptions.Compiled | RegexOptions.IgnoreCase);

            // Find matches.
            MatchCollection matches = rx.Matches(input);

            // Report the number of matches found.
            Debug.WriteLine("{0} matches found in:\n\t{1}",
                            matches.Count, input);
            foreach (Match m in matches)
            {
                Debug.WriteLine($"\tCommand: {m.Groups["command"]}");
                string cmd = m.Groups["command"].Value;
                if (cmd == "language")
                {
                    string[] langParts = m.Groups["param1"].Value.Split(':');
                    Language language  = (Language)Enum.Parse(typeof(Language), langParts[0]);
                    switch (language)
                    {
                    case Language.Coptic:
                        CopticFont font = CopticFont.CsAvvaShenouda;
                        if (langParts.Length >= 2)
                        {
                            font = CopticFont.Fonts.Find(f => f.Name.ToLower() == langParts[1].ToLower()) ?? font;
                        }
                        string text = m.Groups[3].Value;
                        if (font != null)
                        {
                            input = input.Remove(m.Index, m.Length);
                            input = input.Insert(m.Index, ConvertFont(text, font, CopticFont.CopticUnicode).Replace(" ", " \u200B"));
                            // TextBlock doesn't seem to know where to break Coptic (Unicode?)
                            // lines, so insert a zero-width space at every space so
                            // word wrap actually works
                        }
                        break;
                    }
                }
            }

            return(input);
        }
예제 #3
0
        public static string ConvertFont(string input, CopticFont start, CopticFont target)
        {
            string output = "";

            // Generate a dictionary that has the start mapping as keys and the target mapping as values
            Dictionary <string, string> mergedMap = new Dictionary <string, string>();
            var sourceMap = DictionaryTools.SwitchColumns(start.Charmap);

            foreach (KeyValuePair <string, string> spair in sourceMap)
            {
                if (target.Charmap.ContainsKey(spair.Value))
                {
                    var targetChar = target.Charmap[spair.Value];
                    mergedMap.Add(spair.Key, targetChar);
                }
            }

            /*foreach (KeyValuePair<string, string> tpair in target.Charmap)
             * {
             *  if (!mergedMap.ContainsValue(tpair.Key))
             *  {
             *      var targetChar = target.Charmap[tpair.Key];
             *      mergedMap.Add(tpair.Key, targetChar);
             *  }
             * }*/

            if (start.IsJenkimBefore)
            {
                bool accent = false;
                foreach (char ch in input)
                {
                    if (mergedMap.ContainsKey(ch.ToString()))
                    {
                        // Find the source character in the target mapping and write it
                        if (ch == start.JenkimCharacter)
                        {
                            // The character is an accent; save that for later
                            accent = true;
                        }
                        else
                        {
                            output += mergedMap[ch.ToString()];
                            if (accent)
                            {
                                // It's time to write the accent
                                output += target.JenkimCharacter;
                                accent  = false;
                            }
                        }
                    }
                    else
                    {
                        // Character is not in the character map, so leave it be
                        output += ch.ToString();
                        if (accent)
                        {
                            output += target.JenkimCharacter;
                            accent  = false;
                        }
                    }
                }
                //return output;
            }
            else
            {
                bool accent = false;
                foreach (char ch in input)
                {
                    if (mergedMap.ContainsKey(ch.ToString()))
                    {
                        if (ch == start.JenkimCharacter)
                        {
                            accent = true;
                        }
                        else
                        {
                            output += mergedMap[ch.ToString()];
                            if (accent)
                            {
                                output += target.JenkimCharacter;
                                accent  = false;
                            }
                        }
                    }
                    else
                    {
                        output += ch.ToString();
                        if (accent)
                        {
                            output += target.JenkimCharacter;
                            accent  = false;
                        }
                    }
                }
                //return output;
            }

            return(output);
        }