Ejemplo n.º 1
0
 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");
 }
Ejemplo n.º 2
0
        protected ClassAttrib GetParentPrecede()
        {
            ClassAttrib result = new ClassAttrib();

            if (_allStyleInfo != null && _allStyleInfo.Count > 0)
            {
                ClassInfo classInfo = new ClassInfo();
                classInfo = _allStyleInfo.Peek();
                result.SetClassAttrib(classInfo.Precede.ClassName, classInfo.Precede.Attribute);
            }
            return(result);
        }
Ejemplo n.º 3
0
        protected ClassAttrib GetPreced()
        {
            ClassAttrib result = new ClassAttrib();

            if (_allStyleInfo != null && _allStyleInfo.Count > 0)
            {
                ClassInfo result1 = new ClassInfo();
                result1 = _allStyleInfo.Pop();
                result.SetClassAttrib(result1.CoreClass.ClassName, result1.CoreClass.Attribute);
            }
            return(result);
        }
Ejemplo n.º 4
0
        protected void EndElementBase(bool isImage)
        {
            _precedeClassAttrib = GetPreced();

            if (StackPeek(_allParagraph).CompareTo(_closeChildName) == 0)
            {
                StackPop(_allParagraph);
                ClosePara(isImage);
            }

            if (StackPeek(_allCharacter).CompareTo(_closeChildName) == 0)
            {
                StackPop(_allCharacter);
            }
        }
Ejemplo n.º 5
0
        public new void Precede()
        {
            _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.Precede = _expectedClassAttrib;
            _outputClassAttrib = _classInfo.Precede;
            Assert.AreEqual(_outputClassAttrib.ClassName, _expectedClassAttrib.ClassName, "CoreClass test Failed");
            Assert.AreEqual(_outputClassAttrib.Attribute, _expectedClassAttrib.Attribute, "CoreClass test Failed");
        }
Ejemplo n.º 6
0
        private bool CompareCoreClass(ClassAttrib classAttrib, ClassAttrib xhtmlClassInfo, string cssTagFamily)
        {
            if (_isclassNameExist == false)
            {
                if (classAttrib.ClassName == string.Empty) // Tag class
                {
                    if (_tagType != cssTagFamily)
                    {
                        return(false);
                    }
                    classAttrib.ClassName = cssTagFamily;
                }
            }

            bool match = CompareClass(classAttrib, xhtmlClassInfo);

            return(match);
        }
Ejemplo n.º 7
0
        private bool CompareClass(ClassAttrib cssClassInfo, ClassAttrib xhtmlClassInfo)
        {
            bool match = true;

            if (cssClassInfo.ClassName == string.Empty)
            {
                return(match);
            }
            match = IsSubClass(xhtmlClassInfo.ClassName, cssClassInfo.ClassName);
            if (match)
            {
                foreach (string attrib in cssClassInfo.Attribute)
                {
                    if (!xhtmlClassInfo.Attribute.Contains(attrib))
                    {
                        match = false;
                        break;
                    }
                }
            }

            return(match);
        }
Ejemplo n.º 8
0
        private bool CompareClass(ClassAttrib cssClassInfo)
        {
            bool match = true;

            if (cssClassInfo.ClassName == string.Empty)
            {
                return(match);
            }
            if (_allStyleInfo.Count == 0)
            {
                return(false);
            }

            foreach (ClassInfo xhtmlClassInfo in _allStyleInfo)
            {
                match = CompareClass(cssClassInfo, xhtmlClassInfo.CoreClass);
                if (match)
                {
                    break;
                }
            }

            return(match);
        }
Ejemplo n.º 9
0
 protected ClassAttrib GetParentPrecede()
 {
     ClassAttrib result = new ClassAttrib();
     if (_allStyleInfo != null && _allStyleInfo.Count > 0)
     {
         ClassInfo classInfo = new ClassInfo();
         classInfo = _allStyleInfo.Peek();
         result.SetClassAttrib(classInfo.Precede.ClassName, classInfo.Precede.Attribute);
     }
     return result;
 }
Ejemplo n.º 10
0
 protected ClassAttrib GetPreced()
 {
     ClassAttrib result = new ClassAttrib();
     if (_allStyleInfo != null && _allStyleInfo.Count > 0)
     {
         ClassInfo result1 = new ClassInfo();
         result1 = _allStyleInfo.Pop();
         result.SetClassAttrib(result1.CoreClass.ClassName, result1.CoreClass.Attribute);
     }
     return result;
 }
Ejemplo n.º 11
0
        private bool CompareClass(ClassAttrib cssClassInfo, ClassAttrib xhtmlClassInfo)
        {
            bool match = true;

            if (cssClassInfo.ClassName == string.Empty)
            {
                return match;
            }
            match = IsSubClass(xhtmlClassInfo.ClassName, cssClassInfo.ClassName);
            if (match)
            {
                foreach (string attrib in cssClassInfo.Attribute)
                {
                    if (!xhtmlClassInfo.Attribute.Contains(attrib))
                    {
                        match = false;
                        break;
                    }
                }
            }

            return match;
        }
Ejemplo n.º 12
0
        private bool CompareClass(ClassAttrib cssClassInfo)
        {
            bool match = true;

            if (cssClassInfo.ClassName == string.Empty)
            {
                return match;
            }
            if (_allStyleInfo.Count == 0)
            {
                return false;
            }

            foreach (ClassInfo xhtmlClassInfo in _allStyleInfo)
            {
                match = CompareClass(cssClassInfo, xhtmlClassInfo.CoreClass);
                if (match)
                {
                    break;
                }
            }

            return match;
        }
Ejemplo n.º 13
0
        private bool CompareCoreClass(ClassAttrib classAttrib, ClassAttrib xhtmlClassInfo, string cssTagFamily)
        {
            if (_isclassNameExist == false)
            {
                if (classAttrib.ClassName == string.Empty) // Tag class
                {
                    if (_tagType != cssTagFamily)
                    {
                        return false;
                    }
                    classAttrib.ClassName = cssTagFamily;
                }
            }

            bool match = CompareClass(classAttrib, xhtmlClassInfo);
            return match;
        }
Ejemplo n.º 14
0
        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 (classAttrib.AttributeSeperator.Length == 0)
                {
                    className = className + Common.SepAttrib + classAttrib.Name;
                    clsAttrib.Add(classAttrib.Name);
                    _specificityWeightage += 10;
                }
            }
            clsAtt.SetClassAttrib(className, clsAttrib);
            return clsAtt;
        }
Ejemplo n.º 15
0
        private string CreateStyle()
        {
            _parentClassAttrib        = GetParent();
            _parentPrecedeClassAttrib = GetParentPrecede();
            ArrayList multiClassList = MultiClassCombination(_className);

            //float ancestorFontSize = FindAncestorFontSize();
            float ancestorFontSize = 12.00F;

            _parentStyleName = StackPeek(_allStyle);

            string styleName = MatchCssStyle(ancestorFontSize, "null", multiClassList);

            if (styleName == string.Empty) // missing style in CSS
            {
                styleName = _className;
                if (_outputType == Common.OutputType.ODT)
                {
                    if (_lang.Length > 0)
                    {
                        styleName = _className + Common.SepAttrib + _lang;
                    }
                }
            }
            string newStyleName = GetStyleNumber(styleName);

            if (_newProperty.ContainsKey(newStyleName) == false)
            {
                _newProperty[newStyleName] = _tempStyle;
            }

            IdAllClass[newStyleName] = _tempStyle;
            string tagType = _tagType;

            if (_divType.Contains(_tagType))
            {
                tagType = "div";
            }
            ParentClass[newStyleName] = _parentStyleName + "|" + tagType;

            _psuedoBeforeStyle = _psuedoAfterStyle = _psuedoContainsStyle = null;
            string styleBefore = MatchCssStyle(ancestorFontSize, "before", multiClassList);

            if (styleBefore != string.Empty)
            {
                string tag            = "span"; //  always character styles
                string newStyleBefore = GetStyleNumber(styleBefore);
                _newProperty[newStyleBefore] = _tempStyle;
                IdAllClass[newStyleBefore]   = _tempStyle;
                _psuedoBeforeStyle.StyleName = newStyleBefore;
                ParentClass[newStyleBefore]  = _parentStyleName + "|" + tag;
            }

            string styleAfter = MatchCssStyle(ancestorFontSize, "after", multiClassList);

            if (styleAfter != string.Empty)
            {
                string tag           = "span"; //  always character styles
                string newStyleAfter = GetStyleNumber(styleAfter);
                _newProperty[newStyleAfter] = _tempStyle;
                IdAllClass[newStyleAfter]   = _tempStyle;
                _psuedoAfterStyle.StyleName = newStyleAfter;
                ParentClass[newStyleAfter]  = _parentStyleName + "|" + tag;
            }

            string styleContains = MatchCssStyle(ancestorFontSize, "contains", multiClassList);

            if (styleContains != string.Empty)
            {
                string newStyleContains = GetStyleNumber(styleContains);
                _newProperty[newStyleContains] = _tempStyle;
                IdAllClass[newStyleContains]   = _tempStyle;
                _psuedoContainsStyle.StyleName = newStyleContains;
                ParentClass[newStyleContains]  = _parentStyleName + "|" + _tagType;
            }

            return(newStyleName);
        }
Ejemplo n.º 16
0
        protected void EndElementBase(bool isImage)
        {
            _precedeClassAttrib = GetPreced();
            if (StackPeek(_allParagraph).CompareTo(_closeChildName) == 0)
            {
                StackPop(_allParagraph);
                ClosePara(isImage);
            }

            if (StackPeek(_allCharacter).CompareTo(_closeChildName) == 0)
            {
                StackPop(_allCharacter);
            }
        }
Ejemplo n.º 17
0
        private string CreateStyle()
        {
            _parentPrecedeClassAttrib = GetParentPrecede();
            ArrayList multiClassList = MultiClassCombination(_className);

            float ancestorFontSize = FindAncestorFontSize();
            _parentStyleName = StackPeek(_allStyle);

            string styleName = MatchCssStyle(ancestorFontSize, "null", multiClassList);
            if (styleName == string.Empty) // missing style in CSS
            {
                styleName = _className;
                if (_outputType == Common.OutputType.ODT || _outputType == Common.OutputType.XELATEX)
                {
                    if (_lang.Length > 0)
                        styleName = _className + Common.SepAttrib + _lang;
                }

            }
            else
            {
                if (_outputType == Common.OutputType.XELATEX)
                {
                    if (_lang.Length > 0)
                        styleName = _className + Common.SepAttrib + _lang;
                }
            }
            string newStyleName = GetStyleNumber(styleName);

            if (_newProperty.ContainsKey(newStyleName) == false)
            {
                _newProperty[newStyleName] = _tempStyle;
            }

            IdAllClass[newStyleName] = _tempStyle;
            string tagType = _tagType;
            if (_divType.Contains(_tagType)) tagType = "div";
            ParentClass[newStyleName] = _parentStyleName + "|" + tagType;

            _psuedoBeforeStyle = _psuedoAfterStyle = _psuedoContainsStyle = null;
            string styleBefore = MatchCssStyle(ancestorFontSize, "before", multiClassList);
            if (styleBefore != string.Empty)
            {
                string tag = "span"; //  always character styles
                string newStyleBefore = GetStyleNumber(styleBefore);
                _newProperty[newStyleBefore] = _tempStyle;
                IdAllClass[newStyleBefore] = _tempStyle;
                _psuedoBeforeStyle.StyleName = newStyleBefore;
                ParentClass[newStyleBefore] = _parentStyleName + "|" + tag;

            }

            string styleAfter = MatchCssStyle(ancestorFontSize, "after", multiClassList);
            if (styleAfter != string.Empty)
            {
                string tag = "span"; //  always character styles
                string newStyleAfter = GetStyleNumber(styleAfter);
                _newProperty[newStyleAfter] = _tempStyle;
                IdAllClass[newStyleAfter] = _tempStyle;
                _psuedoAfterStyle.StyleName = newStyleAfter;
                ParentClass[newStyleAfter] = _parentStyleName + "|" + tag;
            }

            string styleContains = MatchCssStyle(ancestorFontSize, "contains", multiClassList);
            if (styleContains != string.Empty)
            {
                string newStyleContains = GetStyleNumber(styleContains);
                _newProperty[newStyleContains] = _tempStyle;
                IdAllClass[newStyleContains] = _tempStyle;
                _psuedoContainsStyle.StyleName = newStyleContains;
                ParentClass[newStyleContains] = _parentStyleName + "|" + _tagType;
            }

            return newStyleName;
        }
Ejemplo n.º 18
0
 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);
                     _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;
         CssClassOrder.Add(_classInfo.CoreClass.ClassName);
         if (_baseClassName != null)
             SetSpecificityClass(_baseClassName,_classInfo);
     }
     catch (Exception ex)
     {
         Console.Write(ex.Message);
     }
 }