public void Open(string input, string output) { Console.WriteLine("Loading font file..."); var doc = new XmlDocument(); doc.Load(input); var font = doc["ttFont"]; var cmap = font["cmap"]; var cmap_4 = cmap["cmap_format_4"]; var node = cmap_4.FirstChild; Console.WriteLine("Proccessing font file..."); while (node != null) { var attrs = node.Attributes; if (attrs != null) { foreach (XmlAttribute attr in attrs) { if (attr.Name == "code") { var val = StrToChar(attr.Value); if (table.EncodeExist(val)) { attr.Value = CharToStr(table.Encode(val)); } break; } } } node = node.NextSibling; } var name = font["name"]; node = name.FirstChild; while (node != null) { if (node.Name == "namerecord") { node.InnerText = node.InnerText + "_ENC"; } node = node.NextSibling; } XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; using (var writer = XmlWriter.Create(output, settings)) { doc.WriteTo(writer); } }
public string Encode(string str) { var utf8 = Encoding.UTF8; var chars = utf8.GetChars(utf8.GetBytes(str)); char[] resultChar = new char[chars.Length]; for (int i = 0; i < chars.Length; i++) { resultChar[i] = table.Encode(chars[i]); } return(new string(resultChar)); }