Beispiel #1
0
        /// <summary>
        /// Gets the style as an HTML style
        /// </summary>
        /// <returns>HTML CSS style tags</returns>
        public Dictionary <string, Dictionary <string, string> > ToHTML()
        {
            Dictionary <string, Dictionary <string, string> > results = new Dictionary <string, Dictionary <string, string> >();
            string htmlColor;
            string id = ID;

            // The main table style
            results.Add(id, new Dictionary <string, string>());
            htmlColor = Serialize.BrushHex6(Background);
            if (htmlColor.Length > 0)
            {
                results[id].Add("background", htmlColor);
            }
            results[id].Add("border-collapse", "collapse");
            results[id].Add("border", BorderThickness.Left.ToString() + "px solid " + Serialize.BrushHex6(BorderBrush));

            // The header style
            id = ID + " th";
            results.Add(id, new Dictionary <string, string>());
            results[id].Add("padding", CellPadding.ToString(CultureInfo.InvariantCulture) + "px");
            results[id].Add("vertical-align", "top");
            results[id].Add("text-align", "left");
            htmlColor = Serialize.BrushHex6(HeaderFill);
            if (htmlColor.Length > 0)
            {
                results[id].Add("background", htmlColor);
            }
            results[id].Add("border", CellBorderThickness.Left.ToString() + "px solid " + Serialize.BrushHex6(CellBorderBrush));

            // The normal cell style
            id = ID + " td";
            results.Add(id, new Dictionary <string, string>());
            results[id].Add("padding", CellPadding.ToString(CultureInfo.InvariantCulture) + "px");
            results[id].Add("vertical-align", "top");
            results[id].Add("text-align", "left");

            htmlColor = Serialize.BrushHex6(CellFill);
            if (htmlColor.Length > 0)
            {
                results[id].Add("background", htmlColor);
            }
            results[id].Add("border", CellBorderThickness.Left.ToString() + "px solid " + Serialize.BrushHex6(CellBorderBrush));

            return(results);
        }
Beispiel #2
0
        /// <summary>
        /// Gets the style as an HTML style
        /// </summary>
        /// <returns>HTML CSS style tags</returns>
        public Dictionary <string, string> ToHTML(UIElement element)
        {
            Dictionary <string, string> keyValues = new Dictionary <string, string>();
            string tag;
            bool   isText = (element is TextBlockPlus) || element == null;

            tag = Utility.IsStyleAHeading(ID) ? string.Empty : ".";

            if (isText)
            {
                if (Family.Length > 0)
                {
                    keyValues.Add("font-family", Family);
                }
                if (Size.HasValue)
                {
                    keyValues.Add("font-size", Math.Round((double)Size, 2).ToString(CultureInfo.InvariantCulture) + "px");
                }

                if (Background != null)
                {
                    if (((SolidColorBrush)Background).Color.A > 0)
                    {
                        keyValues.Add("background", Serialize.BrushHex6(Background));
                    }
                }

                if (Foreground != null)
                {
                    if (((SolidColorBrush)Foreground).Color.A > 0)
                    {
                        keyValues.Add("color", Serialize.BrushHex6(Foreground));
                    }
                }

                if (Weight == FontWeights.Bold)
                {
                    keyValues.Add("font-weight", "bold");
                }
                if (Style == FontStyles.Italic)
                {
                    keyValues.Add("font-style", "italic");
                }
                if (Effect == TextBlockPlusEffect.Strike)
                {
                    keyValues.Add("text-decoration", "line-through");
                }
                if (Decorations == TextDecorations.Underline && !keyValues.ContainsKey("text-decoration"))
                {
                    keyValues.Add("text-decoration", "underline");
                }

                if (Special == RichTextSpecialFormatting.Subscript)
                {
                    keyValues["vertical-align"] = "sub";
                    keyValues["font-size"]      = Math.Round((double)Size * 0.6, 2).ToString(CultureInfo.InvariantCulture) + "px";
                }
                else if (Special == RichTextSpecialFormatting.Superscript)
                {
                    keyValues["vertical-align"] = "super";
                    keyValues["font-size"]      = Math.Round((double)Size * 0.6, 2).ToString(CultureInfo.InvariantCulture) + "px";
                }
            }

            if (!keyValues.ContainsKey("vertical-align"))
            {
                keyValues.Add("vertical-align", VerticalAlignment.ToString().Replace("Center", "middle"));
            }

            if (Alignment != HorizontalAlignment.Left)
            {
                keyValues.Add("text-align", Alignment.ToString());
            }

            if (Margin.Bottom != 0 || Margin.Top != 0 || Margin.Left != 0 || Margin.Right != 0)
            {
                keyValues.Add("margin", Utility.ThicknessToCSS(Margin));
            }


            return(keyValues);
        }