/// <summary>
 /// Sets general properties of the style in the csd.
 /// </summary>
 /// <param name="from"></param>
 /// <param name="csd"></param>
 private static void SetGeneralProperties(IStyle from, ICssStyleDeclaration csd)
 {
     if (from.MinVisible > 0)
     {
         csd.SetProperty("zoom-min-visible", from.MinVisible.ToString(), string.Empty);
     }
     if (from.MaxVisible < double.MaxValue)
     {
         csd.SetProperty("zoom-max-visible", from.MaxVisible.ToString(), string.Empty);
     }
 }
예제 #2
0
        private void SanitizeStyleDeclaration(IElement element, ICssStyleDeclaration styles, string baseUrl)
        {
            var removeStyles = new List <Tuple <ICssProperty, RemoveReason> >();
            var setStyles    = new Dictionary <string, string>();

            foreach (var style in styles)
            {
                var key = DecodeCss(style.Name);
                var val = DecodeCss(style.Value);

                if (!AllowedCssProperties.Contains(key))
                {
                    removeStyles.Add(new Tuple <ICssProperty, RemoveReason>(style, RemoveReason.NotAllowedStyle));
                    continue;
                }

                if (CssExpression.IsMatch(val) || DisallowCssPropertyValue.IsMatch(val))
                {
                    removeStyles.Add(new Tuple <ICssProperty, RemoveReason>(style, RemoveReason.NotAllowedValue));
                    continue;
                }

                var urls = CssUrl.Matches(val);

                if (urls.Count > 0)
                {
                    if (urls.Cast <Match>().Any(m => SanitizeUrl(m.Groups[2].Value, baseUrl) == null))
                    {
                        removeStyles.Add(new Tuple <ICssProperty, RemoveReason>(style, RemoveReason.NotAllowedUrlValue));
                    }
                    else
                    {
                        var s = CssUrl.Replace(val, m => "url(" + m.Groups[1].Value + SanitizeUrl(m.Groups[2].Value, baseUrl) + m.Groups[3].Value);
                        if (s != val)
                        {
                            if (key != style.Name)
                            {
                                removeStyles.Add(new Tuple <ICssProperty, RemoveReason>(style, RemoveReason.NotAllowedUrlValue));
                            }
                            setStyles[key] = s;
                        }
                    }
                }
            }

            foreach (var style in setStyles)
            {
                styles.SetProperty(style.Key, style.Value);
            }

            foreach (var style in removeStyles)
            {
                RemoveStyle(element, styles, style.Item1, style.Item2);
            }
        }
        private static void SetVectorStyleProperties(VectorStyle vectorStyle, ICssStyleDeclaration csd)
        {
            // Copy VectorStyle properties to the CSS declaration. Serializes:
            //   border-color     Line.Color
            //   border-width     Line.Width
            //   outline-color    Outline.Color
            //   outline-width    Outline.Width
            //   outline-style    EnableOutline
            //   background-color Fill
            //   endCap           Line.EndCap
            VectorStyle vectorDefaults = new VectorStyle();

            if (vectorStyle != null)
            {
                SetColorStyleProperty(csd, "border-color", vectorStyle.Line.Color, vectorDefaults.Line.Color);
                if (vectorStyle.Line.Width != vectorDefaults.Line.Width)
                {
                    csd.SetProperty("border-width", vectorStyle.Line.Width.ToString("F0"), string.Empty);
                }
                SetColorStyleProperty(csd, "outline-color", vectorStyle.Outline.Color, vectorDefaults.Outline.Color);
                if (vectorStyle.Outline.Width != vectorDefaults.Outline.Width)
                {
                    csd.SetProperty("outline-width", vectorStyle.Outline.Width.ToString("F0"), string.Empty);
                }
                if (vectorStyle.EnableOutline)
                {
                    csd.SetProperty("outline-style", "enabled", string.Empty);
                }
                SetBrushStyleProperty(csd, "background-color", vectorStyle.Fill, vectorDefaults.Fill);
                csd.SetProperty(endcapName, vectorStyle.Line.EndCap.ToString(), string.Empty);

                if (vectorStyle.GeometryType != null)
                {
                    csd.SetProperty("geometry-type", GeometryType2CssString(vectorStyle), string.Empty);
                }

                if (vectorStyle.Shape != null)
                {
                    csd.SetProperty("symbol-shape", vectorStyle.Shape.ToString(), string.Empty);
                }

                if ((vectorStyle.Symbol != null) && (vectorStyle.HasCustomSymbol))
                {
                    // Encode a Bitmap symbol as bytes that can be included in the css as string using Codepage 1251 encoding
                    byte[] bytes = (byte[])TypeDescriptor.GetConverter(typeof(Bitmap)).ConvertTo(vectorStyle.Symbol, typeof(byte[]));
                    csd.SetProperty("symbol", Convert.ToBase64String(bytes), string.Empty);
                }
            }
        }
        private static void SetLabelStyleProperties(LabelStyle labelStyle, ICssStyleDeclaration csd)
        {
            // Copy LabelStyle properties to the CSS declaration. Serializes:
            //   font-family        Font.Family
            //   font-size          Font.Size
            //   font-color         ForeColor
            //   background-color   BackColor
            //   border-color       Halo.Color
            //   border-width       Halo.Width
            //   padding-horizontal Offset.X
            //   padding-vertical   Offset.Y
            //   text-align         HorizontalAlignment
            //   vertical-align     VerticalAlignment
            LabelStyle labelDefaults = new LabelStyle();

            if (labelStyle.Font.FontFamily != labelDefaults.Font.FontFamily)
            {
                csd.SetProperty("font-family", labelStyle.Font.FontFamily.Name, string.Empty);
            }
            if (labelStyle.Font.Size != labelDefaults.Font.Size)
            {
                csd.SetProperty("font-size", labelStyle.Font.Size.ToString("F0"), string.Empty);
            }
            SetColorStyleProperty(csd, "font-color", labelStyle.ForeColor, labelDefaults.ForeColor);
            SetBrushStyleProperty(csd, "background-color", labelStyle.BackColor, labelDefaults.BackColor);
            SetColorStyleProperty(csd, "border-color", labelStyle.Halo.Color, labelDefaults.Halo.Color);
            if (labelStyle.Halo.Width != labelDefaults.Halo.Width)
            {
                csd.SetProperty("border-width", labelStyle.Halo.Width.ToString("F0"), string.Empty);
            }
            if (labelStyle.Offset.X != labelDefaults.Offset.X)
            {
                csd.SetProperty("padding-horizontal", labelStyle.Offset.X.ToString("F0"), string.Empty);
            }
            if (labelStyle.Offset.Y != labelDefaults.Offset.Y)
            {
                csd.SetProperty("padding-vertical", labelStyle.Offset.Y.ToString("F0"), string.Empty);
            }
            if (labelStyle.HorizontalAlignment != labelDefaults.HorizontalAlignment)
            {
                csd.SetProperty("text-align", labelStyle.HorizontalAlignment.ToString(), string.Empty);
            }
            if (labelStyle.VerticalAlignment != labelDefaults.VerticalAlignment)
            {
                csd.SetProperty("vertical-align", labelStyle.VerticalAlignment.ToString(), string.Empty);
            }
        }
        /// <summary>
        /// Stores the color in a string using the name (for support known colors) and the
        /// ARGB to support the alpha channel which is not supported by ColorTranslator.
        /// </summary>
        /// <param name="color"></param>
        /// <param name="csd"></param>
        /// <param name="propertyName"></param>
        private static void SetColorToCss(Color color, ICssStyleDeclaration csd, string propertyName)
        {
            string colorString = string.Format("{0} {1}", color.IsKnownColor ? color.Name : "#", color.ToArgb());

            csd.SetProperty(propertyName, colorString, string.Empty);
        }
예제 #6
0
 /// <summary>
 /// Stores the color in a string using the name (for support known colors) and the 
 /// ARGB to support the alpha channel which is not supported by ColorTranslator.
 /// </summary>
 /// <param name="color"></param>
 /// <param name="csd"></param>
 /// <param name="propertyName"></param>
 private static void SetColorToCss(Color color, ICssStyleDeclaration csd, string propertyName)
 {
     string colorString = string.Format("{0} {1}", color.IsKnownColor ? color.Name : "#", color.ToArgb());
     csd.SetProperty(propertyName, colorString, string.Empty);
 }
예제 #7
0
 /// <summary>
 /// Sets general properties of the style in the csd.
 /// </summary>
 /// <param name="from"></param>
 /// <param name="csd"></param>
 private static void SetGeneralProperties(IStyle from, ICssStyleDeclaration csd)
 {
     if (from.MinVisible > 0)
         csd.SetProperty("zoom-min-visible", from.MinVisible.ToString(), string.Empty);
     if (from.MaxVisible < double.MaxValue)
         csd.SetProperty("zoom-max-visible", from.MaxVisible.ToString(), string.Empty);
 }
예제 #8
0
        private static void SetVectorStyleProperties(VectorStyle vectorStyle, ICssStyleDeclaration csd)
        {
            // Copy VectorStyle properties to the CSS declaration. Serializes:
            //   border-color     Line.Color
            //   border-width     Line.Width
            //   outline-color    Outline.Color
            //   outline-width    Outline.Width
            //   outline-style    EnableOutline
            //   background-color Fill
            //   endCap           Line.EndCap
            VectorStyle vectorDefaults = new VectorStyle();
            if (vectorStyle != null)
            {
                SetColorStyleProperty(csd, "border-color", vectorStyle.Line.Color, vectorDefaults.Line.Color);
                if (vectorStyle.Line.Width != vectorDefaults.Line.Width)
                    csd.SetProperty("border-width", vectorStyle.Line.Width.ToString("F0"), string.Empty);
                SetColorStyleProperty(csd, "outline-color", vectorStyle.Outline.Color, vectorDefaults.Outline.Color);
                if (vectorStyle.Outline.Width != vectorDefaults.Outline.Width)
                    csd.SetProperty("outline-width", vectorStyle.Outline.Width.ToString("F0"), string.Empty);
                if (vectorStyle.EnableOutline)
                    csd.SetProperty("outline-style", "enabled", string.Empty);
                SetBrushStyleProperty(csd, "background-color", vectorStyle.Fill, vectorDefaults.Fill);
                csd.SetProperty(endcapName, vectorStyle.Line.EndCap.ToString(), string.Empty);

                if (vectorStyle.GeometryType != null)
                {
                    csd.SetProperty("geometry-type", GeometryType2CssString(vectorStyle), string.Empty);
                }

                if (vectorStyle.Shape != null)
                {
                    csd.SetProperty("symbol-shape", vectorStyle.Shape.ToString(), string.Empty);
                }

                if ((vectorStyle.Symbol != null) && (vectorStyle.HasCustomSymbol))
                {
                    // Encode a Bitmap symbol as bytes that can be included in the css as string using Codepage 1251 encoding
                    byte[] bytes = (byte[])TypeDescriptor.GetConverter(typeof(Bitmap)).ConvertTo(vectorStyle.Symbol, typeof(byte[]));
                    csd.SetProperty("symbol", Convert.ToBase64String(bytes), string.Empty);
                }
            }
        }
예제 #9
0
 private static void SetLabelStyleProperties(LabelStyle labelStyle, ICssStyleDeclaration csd)
 {
     // Copy LabelStyle properties to the CSS declaration. Serializes:
     //   font-family        Font.Family
     //   font-size          Font.Size
     //   font-color         ForeColor
     //   background-color   BackColor
     //   border-color       Halo.Color
     //   border-width       Halo.Width
     //   padding-horizontal Offset.X
     //   padding-vertical   Offset.Y
     //   text-align         HorizontalAlignment
     //   vertical-align     VerticalAlignment
     LabelStyle labelDefaults = new LabelStyle();
     if (labelStyle.Font.FontFamily != labelDefaults.Font.FontFamily)
         csd.SetProperty("font-family", labelStyle.Font.FontFamily.Name, string.Empty);
     if (labelStyle.Font.Size != labelDefaults.Font.Size)
         csd.SetProperty("font-size", labelStyle.Font.Size.ToString("F0"), string.Empty);
     SetColorStyleProperty(csd, "font-color", labelStyle.ForeColor, labelDefaults.ForeColor);
     SetBrushStyleProperty(csd, "background-color", labelStyle.BackColor, labelDefaults.BackColor);
     SetColorStyleProperty(csd, "border-color", labelStyle.Halo.Color, labelDefaults.Halo.Color);
     if (labelStyle.Halo.Width != labelDefaults.Halo.Width)
         csd.SetProperty("border-width", labelStyle.Halo.Width.ToString("F0"), string.Empty);
     if (labelStyle.Offset.X != labelDefaults.Offset.X)
         csd.SetProperty("padding-horizontal", labelStyle.Offset.X.ToString("F0"), string.Empty);
     if (labelStyle.Offset.Y != labelDefaults.Offset.Y)
         csd.SetProperty("padding-vertical", labelStyle.Offset.Y.ToString("F0"), string.Empty);
     if (labelStyle.HorizontalAlignment != labelDefaults.HorizontalAlignment)
         csd.SetProperty("text-align", labelStyle.HorizontalAlignment.ToString(), string.Empty);
     if (labelStyle.VerticalAlignment != labelDefaults.VerticalAlignment)
         csd.SetProperty("vertical-align", labelStyle.VerticalAlignment.ToString(), string.Empty);
 }