public static void FontStyleConverter(ref BaseStyle style, Declaration declaration) { string flag; try { flag = declaration.Expression.Terms.First().Value; } catch (InvalidOperationException exception) { throw new FormatException("Style 'font-style' has incorrect value. [font-style: normal | italic]", exception); } catch (ArgumentNullException exception) { throw new FormatException("Style 'font-style' has incorrect value. [font-style: normal | italic]", exception); } catch (NullReferenceException exception) { throw new FormatException("Style 'font-style' has incorrect value. [font-style: normal | italic]", exception); } switch (flag) { case "normal": style.IsItalic = false; break; case "italic": style.IsItalic = true; break; default: throw new FormatException("Style 'font-style' has incorrect value. [font-style: normal | italic]"); } }
private bool Equals(BaseStyle other) { return((Color == other.Color) && (Width == other.Width) && (Height == other.Height) && (BackgroundColor == other.BackgroundColor) && (BorderLeftColor == other.BorderLeftColor) && (BorderLeftWidth == other.BorderLeftWidth) && (BorderRightColor == other.BorderRightColor) && (BorderTopColor == other.BorderTopColor) && (BorderBottomColor == other.BorderBottomColor) && (BorderRightWidth == other.BorderRightWidth) && (BorderTopWidth == other.BorderTopWidth) && (BorderBottomWidth == other.BorderBottomWidth) && (Font == other.Font) && (FontSize == other.FontSize) && (HAlign == other.HAlign) && (VAlign == other.VAlign) && (IsLineThrough == other.IsLineThrough) && (IsOverline == other.IsOverline) && (IsUnderline == other.IsUnderline) && (IsItalic == other.IsItalic) && (IsBold == other.IsBold) && (BorderBottomStyle == other.BorderBottomStyle) && (BorderLeftStyle == other.BorderLeftStyle) && (BorderRightStyle == other.BorderRightStyle) && (BorderTopStyle == other.BorderTopStyle)); }
public static void FontFamilyConverter(ref BaseStyle style, Declaration declaration) { var family = declaration.Expression.Terms.First().Value; new Font(family, 10); style.Font = family; }
public static void BorderTopConverter(ref BaseStyle style, Declaration declaration) { var width = ushort.Parse(declaration.Expression.Terms.ElementAt(0).Value); var borderStyle = EnumUtils.ParseBorderStyle(declaration.Expression.Terms.ElementAt(1).Value); var color = declaration.Expression.Terms.ElementAt(2).ToColor(); style.BorderTopColor = color; style.BorderTopStyle = borderStyle; style.BorderTopWidth = width; }
private bool Equals(BaseStyle other) { return (Color == other.Color) && (Width == other.Width) && (Height == other.Height) && (BackgroundColor == other.BackgroundColor) && (BorderLeftColor == other.BorderLeftColor) && (BorderLeftWidth == other.BorderLeftWidth) && (BorderRightColor == other.BorderRightColor) && (BorderTopColor == other.BorderTopColor) && (BorderBottomColor == other.BorderBottomColor) && (BorderRightWidth == other.BorderRightWidth) && (BorderTopWidth == other.BorderTopWidth) && (BorderBottomWidth == other.BorderBottomWidth) && (Font == other.Font) && (FontSize == other.FontSize) && (HAlign == other.HAlign) && (VAlign == other.VAlign) && (IsLineThrough == other.IsLineThrough) && (IsOverline == other.IsOverline) && (IsUnderline == other.IsUnderline) && (IsItalic == other.IsItalic) && (IsBold == other.IsBold) && (BorderBottomStyle == other.BorderBottomStyle) && (BorderLeftStyle == other.BorderLeftStyle) && (BorderRightStyle == other.BorderRightStyle) && (BorderTopStyle == other.BorderTopStyle); }
public static void FontSizeConverter(ref BaseStyle style, Declaration declaration) { var value = declaration.Expression.Terms.First().Value; style.FontSize = ushort.Parse(value); }
public static void ColorConverter(ref BaseStyle style, Declaration declaration) { style.Color = declaration.Expression.Terms.First().ToColor(); }
public static void WidthConverter(ref BaseStyle style, Declaration declaration) { style.Width = ushort.Parse(declaration.Expression.Terms.First().Value); }
public static void VAlignConverter(ref BaseStyle style, Declaration declaration) { style.VAlign = EnumUtils.ParseVAlign(declaration.Expression.Terms.First().Value); }
public static void TextDecorationConverter(ref BaseStyle style, Declaration declaration) { style.IsLineThrough = false; style.IsOverline = false; style.IsUnderline = false; var flags = declaration.Expression.Terms.Select(flag => flag.Value).ToArray(); if (!flags.Any()) { throw new FormatException("Style 'text-decoration' has incorrect value. [text-decoration: [line-through | overline | underline] | none]"); } if (flags.Contains("none")) { return; } if (flags.Contains("line-through")) { style.IsLineThrough = true; } if (flags.Contains("overline")) { style.IsOverline = true; } if (flags.Contains("underline")) { style.IsUnderline = true; } }
public static void BackgroundColorConverter(ref BaseStyle style, Declaration declaration) { var backgroundColor = declaration.Expression.Terms.First().ToColor(); style.BackgroundColor = backgroundColor; }
private static BaseStyle MergeStyles(BaseStyle baseStyle, BaseStyle mutations) { var isNewId = false; if (mutations.Color.HasValue && baseStyle.Color != mutations.Color) { isNewId = true; baseStyle.Color = mutations.Color; } if (mutations.Width.HasValue && baseStyle.Width != mutations.Width) { isNewId = true; baseStyle.Width = mutations.Width; } if (mutations.Height.HasValue && baseStyle.Height != mutations.Height) { isNewId = true; baseStyle.Height = mutations.Height; } if (mutations.BackgroundColor.HasValue && baseStyle.BackgroundColor != mutations.BackgroundColor) { isNewId = true; baseStyle.BackgroundColor = mutations.BackgroundColor; } if (mutations.BorderLeftColor.HasValue && baseStyle.BorderLeftColor != mutations.BorderLeftColor) { isNewId = true; baseStyle.BorderLeftColor = mutations.BorderLeftColor; } if (mutations.BorderLeftWidth.HasValue && baseStyle.BorderLeftWidth != mutations.BorderLeftWidth) { isNewId = true; baseStyle.BorderLeftWidth = mutations.BorderLeftWidth; } if (mutations.BorderRightColor.HasValue && baseStyle.BorderRightColor != mutations.BorderRightColor) { isNewId = true; baseStyle.BorderRightColor = mutations.BorderRightColor; } if (mutations.BorderTopColor.HasValue && baseStyle.BorderTopColor != mutations.BorderTopColor) { isNewId = true; baseStyle.BorderTopColor = mutations.BorderTopColor; } if (mutations.BorderBottomColor.HasValue && baseStyle.BorderBottomColor != mutations.BorderBottomColor) { isNewId = true; baseStyle.BorderBottomColor = mutations.BorderBottomColor; } if (mutations.BorderRightWidth.HasValue && baseStyle.BorderRightWidth != mutations.BorderRightWidth) { isNewId = true; baseStyle.BorderRightWidth = mutations.BorderRightWidth; } if (mutations.BorderTopWidth.HasValue && baseStyle.BorderTopWidth != mutations.BorderTopWidth) { isNewId = true; baseStyle.BorderTopWidth = mutations.BorderTopWidth; } if (mutations.BorderBottomWidth.HasValue && baseStyle.BorderBottomWidth != mutations.BorderBottomWidth) { isNewId = true; baseStyle.BorderBottomWidth = mutations.BorderBottomWidth; } if (mutations.Font.HasValue && baseStyle.Font != mutations.Font) { isNewId = true; baseStyle.Font = mutations.Font; } if (mutations.FontSize.HasValue && baseStyle.FontSize != mutations.FontSize) { isNewId = true; baseStyle.FontSize = mutations.FontSize; } if (mutations.HAlign.HasValue && baseStyle.HAlign != mutations.HAlign) { isNewId = true; baseStyle.HAlign = mutations.HAlign; } if (mutations.VAlign.HasValue && baseStyle.VAlign != mutations.VAlign) { isNewId = true; baseStyle.VAlign = mutations.VAlign; } if (mutations.IsBold.HasValue && baseStyle.IsBold != mutations.IsBold) { isNewId = true; baseStyle.IsBold = mutations.IsBold; } if (mutations.IsItalic.HasValue && baseStyle.IsItalic != mutations.IsItalic) { isNewId = true; baseStyle.IsItalic = mutations.IsItalic; } if (mutations.IsLineThrough.HasValue && baseStyle.IsLineThrough != mutations.IsLineThrough) { isNewId = true; baseStyle.IsLineThrough = mutations.IsLineThrough; } if (mutations.IsOverline.HasValue && baseStyle.IsOverline != mutations.IsOverline) { isNewId = true; baseStyle.IsOverline = mutations.IsOverline; } if (mutations.IsUnderline.HasValue && baseStyle.IsUnderline != mutations.IsUnderline) { isNewId = true; baseStyle.IsUnderline = mutations.IsUnderline; } if (mutations.BorderBottomStyle.HasValue && baseStyle.BorderBottomStyle != mutations.BorderBottomStyle) { isNewId = true; baseStyle.BorderBottomStyle = mutations.BorderBottomStyle; } if (mutations.BorderLeftStyle.HasValue && baseStyle.BorderLeftStyle != mutations.BorderLeftStyle) { isNewId = true; baseStyle.BorderLeftStyle = mutations.BorderLeftStyle; } if (mutations.BorderRightStyle.HasValue && baseStyle.BorderRightStyle != mutations.BorderRightStyle) { isNewId = true; baseStyle.BorderRightStyle = mutations.BorderRightStyle; } if (mutations.BorderTopStyle.HasValue && baseStyle.BorderTopStyle != mutations.BorderTopStyle) { isNewId = true; baseStyle.BorderTopStyle = mutations.BorderTopStyle; } if (isNewId) { baseStyle.Id = Guid.NewGuid(); } return baseStyle; }
public static BaseStyle MergeStyles(BaseStyle style, IEnumerable<BaseStyle> children) { return children.Aggregate(style, MergeStyles); }