Ejemplo n.º 1
0
        public virtual IDictionary <String, String> ResolveStyles(INode node, AbstractCssContext context)
        {
            IDictionary <String, String> styles = ResolveNativeStyles(node, context);

            //Load in and merge inherited declarations from parent
            if (node.ParentNode() is IStylesContainer)
            {
                IStylesContainer             parentNode   = (IStylesContainer)node.ParentNode();
                IDictionary <String, String> parentStyles = parentNode.GetStyles();
                if (parentStyles == null && !(node.ParentNode() is IDocumentNode))
                {
                    ILog logger = LogManager.GetLogger(typeof(iText.Svg.Css.Impl.SvgStyleResolver));
                    logger.Error(iText.StyledXmlParser.LogMessageConstant.ERROR_RESOLVING_PARENT_STYLES);
                }
                if (parentStyles != null)
                {
                    foreach (KeyValuePair <String, String> entry in parentStyles)
                    {
                        String parentFontSizeString = parentStyles.Get(CommonCssConstants.FONT_SIZE);
                        if (parentFontSizeString == null)
                        {
                            parentFontSizeString = "0";
                        }
                        sru.MergeParentStyleDeclaration(styles, entry.Key, entry.Value, parentFontSizeString);
                    }
                }
            }
            return(styles);
        }
Ejemplo n.º 2
0
        public virtual IDictionary <String, String> ResolveStyles(INode node, AbstractCssContext context)
        {
            IDictionary <String, String> styles = new Dictionary <String, String>();
            //Load in from collected style sheets
            IList <CssDeclaration> styleSheetDeclarations = css.GetCssDeclarations(node, MediaDeviceDescription.CreateDefault
                                                                                       ());

            foreach (CssDeclaration ssd in styleSheetDeclarations)
            {
                styles.Put(ssd.GetProperty(), ssd.GetExpression());
            }
            //Load in attributes declarations
            if (node is IElementNode)
            {
                IElementNode eNode = (IElementNode)node;
                foreach (IAttribute attr in eNode.GetAttributes())
                {
                    ProcessAttribute(attr, styles);
                }
            }
            //Load in and merge inherited declarations from parent
            if (node.ParentNode() is IStylesContainer)
            {
                IStylesContainer             parentNode   = (IStylesContainer)node.ParentNode();
                IDictionary <String, String> parentStyles = parentNode.GetStyles();
                if (parentStyles == null && !(node.ParentNode() is IDocumentNode))
                {
                    ILog logger = LogManager.GetLogger(typeof(iText.Svg.Css.Impl.SvgStyleResolver));
                    logger.Error(iText.StyledXmlParser.LogMessageConstant.ERROR_RESOLVING_PARENT_STYLES);
                }
                if (parentStyles != null)
                {
                    foreach (KeyValuePair <String, String> entry in parentStyles)
                    {
                        String parentFontSizeString = parentStyles.Get(CommonCssConstants.FONT_SIZE);
                        if (parentFontSizeString == null)
                        {
                            parentFontSizeString = "0";
                        }
                        sru.MergeParentStyleDeclaration(styles, entry.Key, entry.Value, parentFontSizeString);
                    }
                }
            }
            return(styles);
        }
        public virtual void MergeParentDeclarationsMeasurementInheritTest()
        {
            IDictionary <String, String> styles = new Dictionary <String, String>();
            String styleProperty   = "font-size";
            String parentPropValue = "16cm";
            String parentFontSize  = "0";
            IDictionary <String, String> expectedStyles = new Dictionary <String, String>();

            expectedStyles.Put(styleProperty, parentPropValue);
            StyleResolverUtil sru = new StyleResolverUtil();

            sru.MergeParentStyleDeclaration(styles, styleProperty, parentPropValue, parentFontSize);
            bool equal = styles.Count == expectedStyles.Count;

            foreach (KeyValuePair <String, String> kvp in expectedStyles)
            {
                equal &= kvp.Value.Equals(styles.Get(kvp.Key));
            }
            NUnit.Framework.Assert.IsTrue(equal);
        }
Ejemplo n.º 4
0
 protected internal virtual void ApplyStyles(ISvgNodeRenderer parent, ISvgNodeRenderer child)
 {
     if (parent != null && child != null)
     {
         IDictionary <String, String> childStyles = child.GetAttributeMapCopy();
         if (childStyles == null)
         {
             childStyles = new Dictionary <String, String>();
         }
         IDictionary <String, String> parentStyles = parent.GetAttributeMapCopy();
         String parentFontSize = parent.GetAttribute(SvgConstants.Attributes.FONT_SIZE);
         if (parentFontSize == null)
         {
             parentFontSize = "0";
         }
         foreach (KeyValuePair <String, String> parentAttribute in parentStyles)
         {
             sru.MergeParentStyleDeclaration(childStyles, parentAttribute.Key, parentAttribute.Value, parentFontSize);
         }
         child.SetAttributesAndStyles(childStyles);
     }
 }
        public virtual void MergeParentDeclarationsTextDecorationsTest()
        {
            IDictionary <String, String> styles = new Dictionary <String, String>();
            String styleProperty = "text-decoration";

            styles.Put(styleProperty, "strikethrough");
            String parentPropValue = "underline";
            String parentFontSize  = "0";
            IDictionary <String, String> expectedStyles = new Dictionary <String, String>();

            expectedStyles.Put(styleProperty, "strikethrough underline");
            StyleResolverUtil sru = new StyleResolverUtil();

            sru.MergeParentStyleDeclaration(styles, styleProperty, parentPropValue, parentFontSize);
            bool equal = styles.Count == expectedStyles.Count;

            foreach (KeyValuePair <String, String> kvp in expectedStyles)
            {
                equal &= kvp.Value.Equals(styles.Get(kvp.Key));
            }
            NUnit.Framework.Assert.IsTrue(equal);
        }