/// <summary> /// Method which handles span tag, new version of Fieldwords giving properties to the span tag with ancestor class /// </summary> /// <param name="styleName"></param> /// <param name="tagStyleName"></param> /// <param name="clsAttrib"></param> /// <param name="isAncestor"></param> /// <returns></returns> private string HandleSpanStyles(string styleName, string tagStyleName, ClassAttrib clsAttrib, ref bool isAncestor) { if (styleName != string.Empty && (tagStyleName.IndexOf("span") == 0 || tagStyleName.IndexOf("div") == 0)) { if (isAncestor) { _classInfo.Ancestor = clsAttrib; styleName = tagStyleName + Common.SepAncestor + styleName; isAncestor = false; _classInfo.parent.Clear(); _classInfo.parent.Add(_classInfo.Ancestor); } else { styleName = tagStyleName + styleName; _classInfo.parent.Clear(); ClassAttrib cc = new ClassAttrib(); cc.ClassName = clsAttrib.ClassName; _classInfo.parent.Add(cc); } _baseClassName = tagStyleName; clsAttrib.ClassName = _baseClassName; } return(styleName); }
public void SetClassAttrib() { _classAttrib = new ClassAttrib(); string className = "testa"; ArrayList attribute = new ArrayList(); attribute.Add("eng"); attribute.Add("US1"); _classAttrib.SetClassAttrib(className, attribute); Assert.AreEqual(className, _classAttrib.ClassName, "SetClassAttrib test Failed"); Assert.AreEqual(attribute, _classAttrib.Attribute, "SetClassAttrib test Failed"); }
public static ClassAttrib GetUuidFromProperty(System.Reflection.PropertyInfo prop) { //Check if this has a UUID attached. ClassAttrib propAttr = null; foreach (var attr in prop.GetCustomAttributes(true)) { if (attr.GetType() == typeof(ClassAttrib)) { //Correct. propAttr = (ClassAttrib)attr; } } return(propAttr); }
public new void Ancestor() { _classInfo = new ClassInfo(); ClassAttrib _expectedClassAttrib = new ClassAttrib(); ClassAttrib _outputClassAttrib = new ClassAttrib(); string className = "testa"; ArrayList attribute = new ArrayList(); attribute.Add("eng"); attribute.Add("US1"); _expectedClassAttrib.SetClassAttrib(className, attribute); _classInfo.Ancestor = _expectedClassAttrib; _outputClassAttrib = _classInfo.Ancestor; Assert.AreEqual(_outputClassAttrib.ClassName, _expectedClassAttrib.ClassName, "CoreClass test Failed"); Assert.AreEqual(_outputClassAttrib.Attribute, _expectedClassAttrib.Attribute, "CoreClass test Failed"); }
public static RpDbTable ReadTable(Stream s, Type[] types, RpDbDatabase database) { //Read the table name. string name = ReaderTools.ReadString(s); //Read the type string typeName = ReaderTools.ReadString(s); //Determine the type. Type t = null; //Loop through types and find match. foreach (Type tt in types) { if (tt.ToString() == typeName) { t = tt; } } //Check if it was found. if (t == null) { throw new Exception("Failed to find type '" + typeName + "'."); } //Create the object. RpDbTable table = new RpDbTable(name, t, database); //Read the number of entries. UInt32 entryCount = ReaderTools.ReadUInt32(s); //Read number of types. UInt16 typeCount = ReaderTools.ReadUInt16(s); //Read the type table in. This'll give us the order. Writer.PropIdPair[] order = new Writer.PropIdPair[typeCount]; for (int i = 0; i < typeCount; i++) { //Read in. UInt16 typeId = ReaderTools.ReadUInt16(s); ClassAttrib attr = null; System.Reflection.PropertyInfo chosenProp = null; //Find this in the object. foreach (var prop in table.type.GetProperties()) { //Check the UUID. ClassAttrib propAttr = Writer.TableWriter.GetUuidFromProperty(prop); //If there is no UUID, skip this. if (propAttr == null) { continue; } //Add this to the order if it matches if (propAttr.uuid == typeId) { attr = propAttr; chosenProp = prop; } } if (attr != null && chosenProp != null) { order[i] = new Writer.PropIdPair(chosenProp, typeId); } else { Console.WriteLine("No attr found for ID " + typeId.ToString() + "."); } } table.typeOrder = order; //Now that we know the order of the types, we can read it in. //Skip 32 bytes of reserved data. s.Position += 32; //Read each of the offsets in. Add them to the dict as we go. for (int i = 0; i < entryCount; i++) { //Read offset UInt32 offset = ReaderTools.ReadUInt32(s); //Read UUID UInt32 uuid = ReaderTools.ReadUInt32(s); //Insert. table.uuidLookup.Add(uuid, offset); } //Now, the data begins. Add the flag. table.tableDataOffset = s.Position; //We can now continue to the next table. return(table); }
public static void WriteTable(Stream s, RpDbTable table) { //First, write the table name. WriterTools.WriteString(s, table.name); //Write the type name. WriterTools.WriteString(s, table.type.ToString()); //Now, write the number of entries. WriterTools.WriteUInt32(s, (UInt32)table.GetNumberOfEntries()); //Write the type table now. Go through each attribute in the type. //Determine the order. List <PropIdPair> order = new List <PropIdPair>(); foreach (var prop in table.type.GetProperties()) { //Check the UUID. ClassAttrib propAttr = GetUuidFromProperty(prop); //If there is no UUID, skip this. if (propAttr == null) { Console.WriteLine("(debug) Skipping because no attr."); continue; } //Add this to the order. order.Add(new PropIdPair(prop, propAttr.uuid)); } //Now, write number of types. WriterTools.WriteUInt16(s, (UInt16)order.Count); //Write the type table itself. foreach (PropIdPair o in order) { WriterTools.WriteUInt16(s, o.typeid); } //Skip 32 bytes of reserved space. s.Position += 32; //Now, we'll find all the entries and put them in a stream. //We'll create a stream for the actual data and copy it here later. MemoryStream dataStream = new MemoryStream(); //We'll now find and include data. //First, find new entries. List <UInt32> uuidsToSkip = new List <uint>(); //These are the UUIDs that we will skip when we copy directly from the unmodified enteries. foreach (RpDbTableEntry entry in table.modifyBuffer.Values) { //Check if this key exists in the uuid lookup. If it does, this is a UPDATED entry. If it doesn't, this is a NEW entry. bool existsBefore = table.uuidLookup.ContainsKey(entry.uuid); //Add this now. UInt32 offset = ValueWriter.WriteEntry(dataStream, s, entry, order); //Add this to the written dictonary, but also add it to the skipped list so we don't rewrite it. uuidsToSkip.Add(entry.uuid); entry.offset = offset; //Make sure we know the offset. if (!existsBefore) { //If this wasn't already in the lookup table, add it. table.uuidLookup.Add(entry.uuid, offset); } else { //Update the offset now. table.uuidLookup[entry.uuid] = offset; } } //Now, we'll add existing, untouched, files. foreach (var entry in table.uuidLookup) { //Check if this is in the "uuidstoskip" list. if (!uuidsToSkip.Contains(entry.Key)) { //We'll copy this to the new one. //TODO: COPY!!!!!!!!!!! throw new NotImplementedException(); } } //Now that that is done, we can copy the data stream to the main stream. dataStream.Position = 0; dataStream.CopyTo(s); }
private ClassAttrib ClassNode(TreeNode classNode) { ClassAttrib clsAtt = new ClassAttrib(); ArrayList clsAttrib = new ArrayList(); ClassAttribute classAttribute; ArrayList classCollection = new ArrayList(); string className = GetFirstChild(classNode); if (OutputType == Common.OutputType.XELATEX) { className = Common.ReplaceCSSClassName(className); } _baseClassName = className; foreach (TreeNode node in classNode.Nodes) { if (node.Text == "ATTRIB") { classAttribute = GetAttribValue(node); classCollection.Add(classAttribute); } } foreach (ClassAttribute classAttrib in classCollection) { if (string.Compare(classAttrib.AttributeSeperator, "HASVALUE") == 0) { if (OutputType != Common.OutputType.EPUB) { classAttrib.AttributeValue = classAttrib.AttributeValue.Replace("-", ""); classAttrib.AttributeValue = classAttrib.AttributeValue.Replace("_", ""); } className = className + Common.SepAncestor + classAttrib.AttributeValue; _baseClassName = _baseClassName + Common.Space + classAttrib.AttributeValue; _baseClassName = Common.SortMutiClass(_baseClassName); _specificityWeightage += 10; } else if (string.Compare(classAttrib.AttributeSeperator, "ATTRIBEQUAL") == 0) { string attribute; classAttrib.AttributeValue = classAttrib.AttributeValue.Replace("\"", ""); if (classAttrib.Name == "lang") { attribute = classAttrib.AttributeValue; // remove string "lang" } else if (classAttrib.Name == "src") { attribute = "src"; className = classAttrib.AttributeValue; } else { attribute = classAttrib.Name + classAttrib.AttributeValue; } className = className + Common.SepAttrib + attribute; clsAttrib.Add(attribute); _specificityWeightage += 10; } else if (string.Compare(classAttrib.AttributeSeperator, "BEGINSWITH") == 0) { string attribute; classAttrib.AttributeValue = classAttrib.AttributeValue.Replace("\"", ""); if (classAttrib.Name == "lang") { attribute = classAttrib.AttributeValue; // remove string "lang" } else { attribute = classAttrib.Name + classAttrib.AttributeValue; } className = className + Common.SepAttrib + attribute; clsAttrib.Add(attribute); _specificityWeightage += 10; } else if (classAttrib.AttributeSeperator.Length == 0) { className = className + Common.SepAttrib + classAttrib.Name; clsAttrib.Add(classAttrib.Name); _specificityWeightage += 10; } } clsAtt.SetClassAttrib(className, clsAttrib); return(clsAtt); }
private void ClassAndProperty(TreeNode tree) { string styleName = string.Empty; string tagName = string.Empty; string tagStyleName = string.Empty; _specificityWeightage = 0; ClassAttrib clsAttrib = new ClassAttrib(); bool isAncestor = false; try { _classInfo = new ClassInfo(); foreach (TreeNode node in tree.Nodes) { switch (node.Text) { case "TAG": _classInfo.Tag = ClassNode(node); _classInfo.CoreClass.SetClassAttrib(string.Empty, _classInfo.Tag.Attribute); _classInfo.TagName = Common.LeftString(_classInfo.Tag.ClassName, Common.SepAttrib); tagName = GetFirstChild(node) + Common.SepTag; tagStyleName = _classInfo.Tag.ClassName; tagStyleName = GetImageAttrib(tagStyleName); styleName = HandleSpanStyles(styleName, tagStyleName, clsAttrib, ref isAncestor); _specificityWeightage += 1; break; case "CLASS": if (isAncestor) { _classInfo.Ancestor = clsAttrib; styleName = Common.SepAncestor + styleName; isAncestor = false; } isAncestor = true; clsAttrib = ClassNode(node); string tagClassName = tagName + clsAttrib.ClassName; styleName = tagClassName + styleName; clsAttrib.ClassName = _baseClassName; _specificityWeightage += 10; break; case "PARENTOF": _classInfo.ParentPrecede = _classInfo.Precede; _classInfo.Precede.Clear(); _classInfo.parent.Add(clsAttrib); styleName = Common.SepParent + styleName; isAncestor = false; break; case "PRECEDES": _classInfo.Precede = clsAttrib; styleName = Common.sepPrecede + styleName; isAncestor = false; break; case "PSEUDO": _classInfo.Pseudo = GetPseudo(node); styleName = styleName + Common.SepPseudo + _classInfo.Pseudo; break; case "PROPERTY": if (clsAttrib.ClassName == string.Empty) // tag (div,span,..)without className} { styleName = tagStyleName; } else { _classInfo.CoreClass = clsAttrib; } Property(node, styleName); break; } } _classInfo.SpecificityWeightage = _specificityWeightage; _classInfo.StyleName = styleName; if (!CssClassOrder.Contains(_classInfo.CoreClass.ClassName)) { CssClassOrder.Add(_classInfo.CoreClass.ClassName); } if (_baseClassName != null) { SetSpecificityClass(_baseClassName, _classInfo); } } catch (Exception ex) { Console.Write(ex.Message); } }