Beispiel #1
0
        public static StringBuilder ToStyleString(this IHasStyle hasStyle, StringBuilder sb)
        {
            if (hasStyle.BackColor != default(WebColor))
            {
                sb.Append($"background-color:{ColorTranslator.ToHtml(hasStyle.BackColor.ToColor()).Trim()};");
            }
            if (hasStyle.ForeColor != default(WebColor))
            {
                sb.Append($"color:{ColorTranslator.ToHtml(hasStyle.ForeColor.ToColor())};");
            }
            if (hasStyle.BorderStyle != BorderStyle.None && hasStyle.BorderStyle != BorderStyle.NotSet && hasStyle.BorderWidth.Value > 0 && hasStyle.BorderColor != default(WebColor))
            {
                sb.Append($"border:{hasStyle.BorderWidth.ToString()} {hasStyle.BorderStyle.ToString().ToLowerInvariant()} {ColorTranslator.ToHtml(hasStyle.BorderColor.ToColor())};");
            }

            if (hasStyle.Font_Bold)
            {
                sb.Append("font-weight:bold;");
            }
            if (hasStyle.Font_Italic)
            {
                sb.Append("font-style:italic;");
            }
            if (!string.IsNullOrEmpty(hasStyle.Font_Names))
            {
                sb.Append($"font-family:{hasStyle.Font_Names};");
            }
            if (hasStyle.Font_Size != FontUnit.Empty)
            {
                sb.Append($"font-size:{hasStyle.Font_Size.ToString()};");
            }
            if (hasStyle.Font_Underline || hasStyle.Font_Overline || hasStyle.Font_Strikeout)
            {
                sb.Append("text-decoration:");

                var td = new StringBuilder();
                if (hasStyle.Font_Underline)
                {
                    td.Append("underline ");
                }
                if (hasStyle.Font_Overline)
                {
                    td.Append("overline ");
                }
                if (hasStyle.Font_Strikeout)
                {
                    td.Append("line-through");
                }
                sb.Append(td.ToString().Trim());
                sb.Append(";");
            }

            return(sb);
        }
Beispiel #2
0
 public static void CopyTo(this IHasStyle source, IHasStyle destination)
 {
     destination.BackColor      = source.BackColor;
     destination.BorderColor    = source.BorderColor;
     destination.BorderStyle    = source.BorderStyle;
     destination.BorderWidth    = source.BorderWidth;
     destination.CssClass       = source.CssClass;
     destination.ForeColor      = source.ForeColor;
     destination.Height         = source.Height;
     destination.Width          = source.Width;
     destination.Font_Bold      = source.Font_Bold;
     destination.Font_Italic    = source.Font_Italic;
     destination.Font_Names     = source.Font_Names;
     destination.Font_Overline  = source.Font_Overline;
     destination.Font_Size      = source.Font_Size;
     destination.Font_Strikeout = source.Font_Strikeout;
     destination.Font_Underline = source.Font_Underline;
 }
Beispiel #3
0
        public static StyleBuilder ToStyle(this IHasStyle hasStyle) =>
        StyleBuilder.Empty().AddStyle("background-color", () => ColorTranslator.ToHtml(hasStyle.BackColor.ToColor()).Trim(),
                                      when: hasStyle.BackColor != default(WebColor))

        .AddStyle("color", () => ColorTranslator.ToHtml(hasStyle.ForeColor.ToColor()).Trim(),
                  when: hasStyle.ForeColor != default(WebColor))

        .AddStyle("border", v => v.AddValue(hasStyle.BorderWidth.ToString())
                  .AddValue(hasStyle.BorderStyle.ToString().ToLowerInvariant())
                  .AddValue(() => ColorTranslator.ToHtml(hasStyle.BorderColor.ToColor()), HasBorders(hasStyle)),
                  when: HasBorders(hasStyle))

        .AddStyle("font-weight", "bold", hasStyle.Font_Bold)
        .AddStyle("font-style", "italic", hasStyle.Font_Italic)
        .AddStyle("font-family", hasStyle.Font_Names, !string.IsNullOrEmpty(hasStyle.Font_Names))
        .AddStyle("font-size", hasStyle.Font_Size.ToString(), hasStyle.Font_Size != FontUnit.Empty)
        .AddStyle("text-decoration", v => v.AddValue("underline", hasStyle.Font_Underline)
                  .AddValue("overline", hasStyle.Font_Overline)
                  .AddValue("line-through", hasStyle.Font_Strikeout)
                  , HasTextDecorations(hasStyle));
Beispiel #4
0
 private static bool HasBorders(IHasStyle hasStyle) =>
 hasStyle.BorderStyle != BorderStyle.None &&
 hasStyle.BorderStyle != BorderStyle.NotSet &&
 hasStyle.BorderWidth.Value > 0 &&
 hasStyle.BorderColor != default(WebColor);
Beispiel #5
0
 private static bool HasTextDecorations(IHasStyle hasStyle) =>
 hasStyle.Font_Underline ||
 hasStyle.Font_Overline ||
 hasStyle.Font_Strikeout;
Beispiel #6
0
 public static string ToStyleString(this IHasStyle hasStyle)
 {
     return(ToStyleString(hasStyle, new StringBuilder()).ToString());
 }