public static void ReadLegacyPreferences(TEXPreference pref, string XMLFontDef, string XMLConfigDef) { //Clean up first pref.glueTable = new int[100]; // pref.defaultTypefaces = new TexTypeFaceDictionary(); //Look up all font & sprites XmlDocument doc = new XmlDocument(); XmlNode cNode, configNodes; List <TEXConfigurationMember> configs = new List <TEXConfigurationMember>(); doc.LoadXml(XMLFontDef); //Load all configurations. (the thing with bunch of sliders) configNodes = doc.SelectSingleNode("/TexFont/Params"); for (int i = 0; i < configNodes.ChildNodes.Count; i++) { cNode = configNodes.ChildNodes[i]; configs.Add(new TEXConfigurationMember(cNode.Attributes["name"].Value, cNode.Attributes["desc"].Value, float.Parse(cNode.Attributes["value"].Value), float.Parse(cNode.Attributes["min"].Value), float.Parse(cNode.Attributes["max"].Value))); } //pref.configs = configs.ToArray(); doc.LoadXml(XMLConfigDef); // No longer importing config via XML /*XmlNode Params = doc.SelectSingleNode("/TEXConfigurations/Parameters"); * for (int i = 0; i < Params.ChildNodes.Count; i++) { * var att = Params.ChildNodes[i].Attributes[0]; * pref.preferences[att.Name] = float.Parse(att.Value); * pref.configs.First(x => x.name == att.Name).value = pref.preferences[att.Name]; * }*/ /* XmlNode Typefaces = doc.SelectSingleNode("/TEXConfigurations/DefaultTypefaces"); * foreach (XmlNode node in Typefaces.ChildNodes) { * pref.defaultTypefaces.Add((TexCharKind)int.Parse(node.Attributes["code"].Value), int.Parse(node.Attributes["fontId"].Value)); * }*/ XmlNode GlueTables = doc.SelectSingleNode("/TexConfigurations/GlueTable"); foreach (XmlNode node in GlueTables.ChildNodes) { pref.glueTable[int.Parse(node.Attributes["leftType"].Value) * 10 + int.Parse(node.Attributes["rightType"].Value)] = int.Parse(node.Attributes["glueSize"].Value); } pref.PushToDictionaries(); }
public static void ReadLegacyXMLSymbols(TEXPreference pref, bool isMath, string XMLData) { XmlDocument doc = new XmlDocument(); doc.LoadXml(XMLData); TexChar c; XmlNode SyncMap = doc.SelectSingleNode("/TexSymbols/FontIDs"); List <int> sMap = new List <int>(); for (int i = 0; i < SyncMap.ChildNodes.Count; i++) { XmlAttributeCollection attr = SyncMap.ChildNodes[i].Attributes; int idx = pref.GetFontIndexByID(attr["id"].Value); var max = int.Parse(attr["index"].Value); if (max > sMap.Count) { for (int j = 0; j < max; j++) { sMap.Add(j); } } sMap.Add(idx); if (idx >= 0) { var font = pref.fontData[idx]; bool catalogChange = false; for (int j = 0; j < attr.Count; j++) { switch (attr[j].Name) { case "xLength": font.sprite_xLength = int.Parse(attr[j].Value); break; case "yLength": font.sprite_yLength = int.Parse(attr[j].Value); break; case "scale": font.sprite_scale = float.Parse(attr[j].Value); break; case "lineOffset": font.sprite_lineOffset = float.Parse(attr[j].Value); break; case "alphaOnly": font.sprite_alphaOnly = int.Parse(attr[j].Value) > 0; break; case "importCatalog": if (catalogChange |= !string.IsNullOrEmpty(attr[j].Value)) { font.importCatalog = attr[j].Value; } break; } } font.importCatalog = font.importCatalog == null ? TexCharPresets.legacyChars : font.importCatalog; font.Populate(false); } } XmlNode SymbolMap = doc.SelectSingleNode("/TexSymbols/SymbolMap"); foreach (XmlNode node in SymbolMap.ChildNodes) { int hash = int.Parse(node.Attributes["hash"].Value); if (!isMath && hash >> 8 < pref.header_mathCount) { continue; } hash = SyncHash(hash, sMap); if (hash >= 0) { c = pref.GetChar(hash); var attr = node.Attributes; for (int j = 0; j < attr.Count; j++) { switch (attr[j].Name) { case "name": c.symbolName = attr[j].Value; break; case "nameAlt": c.symbolAlt = attr[j].Value; break; case "typeId": c.type = (CharType)int.Parse(attr[j].Value); break; } } // pref.symbolData.Add(c.symbolName, c.ToHash()); // if (!string.IsNullOrEmpty(c.symbolAlt)) // pref.symbolData.Add(c.symbolAlt, c.ToHash()); } } XmlNode LargerMap = doc.SelectSingleNode("/TexSymbols/LargerMap"); foreach (XmlNode node in LargerMap.ChildNodes) { int hash = int.Parse(node.Attributes["hash"].Value); if (!isMath && hash >> 8 < pref.header_mathCount) { continue; } hash = SyncHash(hash, sMap); if (hash >= 0) { c = pref.GetChar(hash); c.nextLarger = pref.GetChar(SyncHash(int.Parse(node.Attributes["targetHash"].Value), sMap)); } } XmlNode ExtensionMap = doc.SelectSingleNode("/TexSymbols/ExtensionMap"); foreach (XmlNode node in ExtensionMap.ChildNodes) { int hash = int.Parse(node.Attributes["hash"].Value); if (!isMath && hash >> 8 < pref.header_mathCount) { continue; } hash = SyncHash(hash, sMap); if (hash >= 0) { c = pref.GetChar(hash); c.extensionExist = true; var attr = node.Attributes; for (int j = 0; j < attr.Count; j++) { switch (attr[j].Name) { case "top": c.extentTopHash = SyncHash(int.Parse(attr[j].Value), sMap); break; case "middle": c.extentMiddleHash = SyncHash(int.Parse(attr[j].Value), sMap); break; case "bottom": c.extentBottomHash = SyncHash(int.Parse(attr[j].Value), sMap); break; case "repeat": c.extentRepeatHash = SyncHash(int.Parse(attr[j].Value), sMap); break; case "horizontal": c.extensionHorizontal = int.Parse(attr[j].Value) > 0; break; } } } } XmlNode CharMap = doc.SelectSingleNode("/TexSymbols/CharMap"); foreach (XmlNode node in CharMap.ChildNodes) { int hash = int.Parse(node.Attributes["hash"].Value); if (!isMath && hash >> 8 < pref.header_mathCount) { continue; } hash = SyncHash(hash, sMap); if (hash >= 0) { c = pref.GetChar(hash); c.characterMap = int.Parse(node.Attributes["char"].Value); // if (c.characterMap > 0) // pref.charMapData.Add(TexChar.possibleCharMaps[c.characterMap], c.ToHash()); } } pref.PushToDictionaries(); }