Exemple #1
0
        Dictionary <string, TextStyleParameters> MergeStyles(string defaultStyleID, List <CssTag> customTags, bool mergeExistingStyles = true, bool includeExistingStyles = true)
        {
            var customCSS = new StringBuilder();

            foreach (var customTag in customTags)
            {
                customCSS.AppendLine(customTag.CSS);
            }

            var customStyles = CssTextStyleParser.Parse(customCSS.ToString());
            var defaultStyle = _textStyles[defaultStyleID];

            if (defaultStyle == null)
            {
                throw new Exception("Default Style ID not found: " + defaultStyleID);
            }

            TextStyleParameters existingStyle;

            foreach (var style in customStyles)
            {
                if (mergeExistingStyles)
                {
                    _textStyles.TryGetValue(style.Key, out existingStyle);

                    if (existingStyle != null)
                    {
                        style.Value.Merge(existingStyle, false);
                    }
                    else
                    {
                        style.Value.Merge(defaultStyle, false);
                    }
                }

                // If no font, use the default one
                if (string.IsNullOrEmpty(style.Value.Font))
                {
                    style.Value.Font = defaultStyle.Font;
                }
            }

            return(customStyles);
        }
Exemple #2
0
        /// <summary>
        /// Sets the CSS string
        /// </summary>
        /// <param name="css">Css Style Sheet</param>
        public virtual void SetCSS(string css)
        {
            var styles = CssTextStyleParser.Parse(css);

            SetStyles(styles);
        }