Example #1
0
 protected void SetUp()
 {
     _input        = new StyleAttribute();
     _makeProperty = new MakeProperty();
     _expected     = new Dictionary <string, string>();
     _position     = new[] { "top", "right", "bottom", "left" };
 }
Example #2
0
        /// <summary>
        /// Creates style property from StyleAttribute
        /// </summary>
        /// <param name="attribute"></param>
        /// <returns></returns>
        public static StyleProperty FromAttribute(StyleAttribute attribute)
        {
            var value = attribute.GetDefault();

            /**
             * 1. If the value is a skin class, we should switch to string type
             * because we cannot serialize the type
             * Hopwever, both type and string are valid for skin class
             * */
            if (value is Type)
            {
                var type = (Type) value;
                if (typeof (Skin).IsAssignableFrom(type))
                {
                    /*if (null != value)
                    attribute.Type = value.GetType(); // default*/

                    attribute.Type = typeof(string); // we cannot serialize type, so switching to string
                    value = type.FullName; // using string instead (full name as default value)
                }
            }

            var prop = CreateProperty<StyleProperty>(attribute.Name, attribute.Type);
            //prop.Name = attribute.Name;

            /**
             * We cannot serialize GUIStyle generated from code as object reference
             * */
            if (null != value && !NonSerializableStyleTypes.Contains(attribute.Type))
            {
                prop.Value = value;
            }
            
            return (StyleProperty) prop;
        }
        public void WriteHtml(StringBuilder stringBuilder)
        {
            var tag = TagTable.TagToString[Tag];

            stringBuilder.Append($"<{tag}{StyleAttribute.Value()}>");

            if (Tag == Tag.Br)
            {
                return;
            }

            foreach (var child in Children)
            {
                child.WriteHtml(stringBuilder);
            }

            stringBuilder.Append($"</{tag}>");
        }
Example #4
0
 private IFont FillFont(StyleAttribute attr)
 {
     if (attr == null)
     {
         return(null);
     }
     if (attr.FontWeight > 0 ||
         !string.IsNullOrEmpty(attr.FontFamily) ||
         attr.FontSize > 0 ||
         attr.IsItalic ||
         !string.IsNullOrEmpty(attr.TextColor))
     {
         var font = _workbook.CreateFont();
         if (attr.FontWeight > 0)
         {
             font.Boldweight = attr.FontWeight;
         }
         if (!string.IsNullOrEmpty(attr.FontFamily))
         {
             font.FontName = attr.FontFamily;
         }
         if (attr.FontSize > 0)
         {
             font.FontHeightInPoints = attr.FontSize;
         }
         if (!string.IsNullOrEmpty(attr.TextColor))
         {
             var color = attr.TextColor.ToColor();
             if (color.HasValue)
             {
                 font.Color = GetColor(color.Value);
             }
         }
         if (attr.IsItalic)
         {
             font.IsItalic = true;
         }
         return(font);
     }
     return(null);
 }
Example #5
0
        private ICellStyle FillStyle(StyleAttribute attr)
        {
            if (attr == null)
            {
                return(null);
            }
            var style = _workbook.CreateCellStyle();

            style.Alignment         = attr.TextAlign;
            style.VerticalAlignment = attr.VerticalAlign;
            if (!string.IsNullOrEmpty(attr.BackgroundColor))
            {
                var color = attr.BackgroundColor.ToColor();
                if (color.HasValue)
                {
                    style.FillForegroundColor = GetColor(color.Value);
                    style.FillPattern         = FillPattern.SolidForeground;
                }
            }
            return(style);
        }
Example #6
0
        /// <summary>
        /// Creates style property from StyleAttribute
        /// </summary>
        /// <param name="attribute"></param>
        /// <returns></returns>
        public static StyleProperty FromAttribute(StyleAttribute attribute)
        {
            var value = attribute.GetDefault();

            /**
             * 1. If the value is a skin class, we should switch to string type
             * because we cannot serialize the type
             * Hopwever, both type and string are valid for skin class
             * */
            if (value is Type)
            {
                var type = (Type)value;
                if (typeof(Skin).IsAssignableFrom(type))
                {
                    /*if (null != value)
                     * attribute.Type = value.GetType(); // default*/

                    attribute.Type = typeof(string); // we cannot serialize type, so switching to string
                    value          = type.FullName;  // using string instead (full name as default value)
                }
            }

            var prop = CreateProperty <StyleProperty>(attribute.Name, attribute.Type);

            //prop.Name = attribute.Name;

            /**
             * We cannot serialize GUIStyle generated from code as object reference
             * */
            if (null != value && !NonSerializableStyleTypes.Contains(attribute.Type))
            {
                prop.Value = value;
            }

            return((StyleProperty)prop);
        }
Example #7
0
        private static void GetStyle(StyleAttribute attribute, out Style style, out StyleFlag styleFlag)
        {
            style = new Style()
            {
                IsTextWrapped = attribute.IsTextWrapped
            };
            styleFlag = new StyleFlag {
                WrapText = true
            };

            if (!string.IsNullOrEmpty(attribute.HorizontalAlign))
            {
                styleFlag.HorizontalAlignment = true;
                style.HorizontalAlignment     = (TextAlignmentType)Enum.Parse(typeof(TextAlignmentType), attribute.HorizontalAlign);
            }
            if (!string.IsNullOrEmpty(attribute.Pattern))
            {
                styleFlag.CellShading = true;
                style.Pattern         = (BackgroundType)Enum.Parse(typeof(BackgroundType), attribute.Pattern);
            }
            if (!string.IsNullOrEmpty(attribute.BackgroundColor))
            {
                styleFlag.CellShading = true;
                style.BackgroundColor = ColorTranslator.FromHtml(attribute.BackgroundColor);
            }
            if (!string.IsNullOrEmpty(attribute.ForegroundColor))
            {
                styleFlag.CellShading = true;
                style.ForegroundColor = ColorTranslator.FromHtml(attribute.ForegroundColor);
            }
            if (!string.IsNullOrEmpty(attribute.Custom))
            {
                styleFlag.NumberFormat = true;
                style.Custom           = attribute.Custom;
            }
            if (attribute.NumberFormat)
            {
                styleFlag.NumberFormat = attribute.NumberFormat;
            }
            if (attribute.FontBold)
            {
                style.Font.IsBold  = true;
                styleFlag.FontBold = true;
            }
            if (attribute.FontItalic)
            {
                style.Font.IsItalic  = true;
                styleFlag.FontItalic = true;
            }
            if (!string.IsNullOrEmpty(attribute.FontUnderline))
            {
                style.Font.Underline    = (FontUnderlineType)Enum.Parse(typeof(FontUnderlineType), attribute.FontUnderline);
                styleFlag.FontUnderline = true;
            }
            if (!string.IsNullOrEmpty(attribute.FontColor))
            {
                styleFlag.FontColor = true;
                style.Font.Color    = ColorTranslator.FromHtml(attribute.FontColor);
            }
            if (!string.IsNullOrEmpty(attribute.TopBorderLineStyle))
            {
                styleFlag.TopBorder = true;
                style.Borders[BorderType.TopBorder].LineStyle = (CellBorderType)Enum.Parse(typeof(CellBorderType), attribute.TopBorderLineStyle);
            }
            if (!string.IsNullOrEmpty(attribute.TopBorderColor))
            {
                styleFlag.TopBorder = true;
                style.Borders[BorderType.TopBorder].Color = ColorTranslator.FromHtml(attribute.TopBorderColor);
            }
            if (!string.IsNullOrEmpty(attribute.BottomBorderLineStyle))
            {
                styleFlag.BottomBorder = true;
                style.Borders[BorderType.BottomBorder].LineStyle = (CellBorderType)Enum.Parse(typeof(CellBorderType), attribute.BottomBorderLineStyle);
            }
            if (!string.IsNullOrEmpty(attribute.BottomBorderColor))
            {
                styleFlag.BottomBorder = true;
                style.Borders[BorderType.BottomBorder].Color = ColorTranslator.FromHtml(attribute.BottomBorderColor);
            }
            if (!string.IsNullOrEmpty(attribute.LeftBorderLineStyle))
            {
                styleFlag.LeftBorder = true;
                style.Borders[BorderType.LeftBorder].LineStyle = (CellBorderType)Enum.Parse(typeof(CellBorderType), attribute.LeftBorderLineStyle);
            }
            if (!string.IsNullOrEmpty(attribute.LeftBorderColor))
            {
                styleFlag.LeftBorder = true;
                style.Borders[BorderType.LeftBorder].Color = ColorTranslator.FromHtml(attribute.LeftBorderColor);
            }
            if (!string.IsNullOrEmpty(attribute.RightBorderLineStyle))
            {
                styleFlag.RightBorder = true;
                style.Borders[BorderType.RightBorder].LineStyle = (CellBorderType)Enum.Parse(typeof(CellBorderType), attribute.RightBorderLineStyle);
            }
            if (!string.IsNullOrEmpty(attribute.RightBorderColor))
            {
                styleFlag.RightBorder = true;
                style.Borders[BorderType.RightBorder].Color = ColorTranslator.FromHtml(attribute.RightBorderColor);
            }
        }
        public static IAttrSet Style(this IAttrSet attrSet, Style value)
        {
            StyleAttribute a = new StyleAttribute(value);

            return(attrSet.Add(a));
        }
Example #9
0
 protected void SetUp()
 {
     target = new StyleAttribute();
 }
Example #10
0
 private static int StyleSort(StyleAttribute x, StyleAttribute y)
 {
     return(String.Compare(x.Name, y.Name, StringComparison.OrdinalIgnoreCase));
 }