/// <summary> /// Init. /// </summary> /// <param name="parent">the parent box of this box</param> /// <param name="tag">the html tag data of this box</param> public CssBoxFrame(CssBox parent, HtmlTag tag) : base(parent, tag) { _imageWord = new CssRectImage(this); Words.Add(_imageWord); Uri uri; if (Uri.TryCreate(GetAttribute("src"), UriKind.Absolute, out uri)) { if (uri.Host.IndexOf("youtube.com", StringComparison.InvariantCultureIgnoreCase) > -1) { _isVideo = true; LoadYoutubeDataAsync(uri); } else if (uri.Host.IndexOf("vimeo.com", StringComparison.InvariantCultureIgnoreCase) > -1) { _isVideo = true; LoadVimeoDataAsync(uri); } } if (!_isVideo) { SetErrorBorder(); } }
/// <summary> /// Init. /// </summary> /// <param name="parentBox">optional: the parent of this css box in html</param> /// <param name="tag">optional: the html tag associated with this css box</param> public CssBox(CssBox parentBox, HtmlTag tag) { if (parentBox != null) { _parentBox = parentBox; _parentBox.Boxes.Add(this); } _htmltag = tag; }
/// <summary> /// Create new css box for the given parent with the given optional html tag and insert it either /// at the end or before the given optional box.<br/> /// If no html tag is given the box will be anonymous.<br/> /// If no before box is given the new box will be added at the end of parent boxes collection.<br/> /// If before box doesn't exists in parent box exception is thrown.<br/> /// </summary> /// <remarks> /// To learn more about anonymous inline boxes visit: http://www.w3.org/TR/CSS21/visuren.html#anonymous /// </remarks> /// <param name="parent">the box to add the new box to it as child</param> /// <param name="tag">optional: the html tag to define the box</param> /// <param name="before">optional: to insert as specific location in parent box</param> /// <returns>the new box</returns> public static CssBox CreateBox(CssBox parent, HtmlTag tag = null, CssBox before = null) { ArgChecker.AssertArgNotNull(parent, "parent"); var newBox = new CssBox(parent, tag); newBox.InheritStyle(); if (before != null) { newBox.SetBeforeBox(before); } return newBox; }
/// <summary> /// Create new css box for the given parent with the given html tag.<br/> /// </summary> /// <param name="tag">the html tag to define the box</param> /// <param name="parent">the box to add the new box to it as child</param> /// <returns>the new box</returns> public static CssBox CreateBox(HtmlTag tag, CssBox parent = null) { ArgChecker.AssertArgNotNull(tag, "tag"); if (tag.Name == HtmlConstants.Img) { return new CssBoxImage(parent, tag); } else if (tag.Name == HtmlConstants.Iframe) { return new CssBoxFrame(parent, tag); } else if (tag.Name == HtmlConstants.Hr) { return new CssBoxHr(parent, tag); } else { return new CssBox(parent, tag); } }
/// <summary> /// Create new css block box for the given parent with the given optional html tag and insert it either /// at the end or before the given optional box.<br/> /// If no html tag is given the box will be anonymous.<br/> /// If no before box is given the new box will be added at the end of parent boxes collection.<br/> /// If before box doesn't exists in parent box exception is thrown.<br/> /// </summary> /// <remarks> /// To learn more about anonymous block boxes visit CSS spec: /// http://www.w3.org/TR/CSS21/visuren.html#anonymous-block-level /// </remarks> /// <param name="parent">the box to add the new block box to it as child</param> /// <param name="tag">optional: the html tag to define the box</param> /// <param name="before">optional: to insert as specific location in parent box</param> /// <returns>the new block box</returns> public static CssBox CreateBlock(CssBox parent, HtmlTag tag = null, CssBox before = null) { ArgChecker.AssertArgNotNull(parent, "parent"); var newBox = CreateBox(parent, tag, before); newBox.Display = CssConstants.Block; return newBox; }
/// <summary> /// Init. /// </summary> /// <param name="parent">the parent box of this box</param> /// <param name="tag">the html tag data of this box</param> public CssBoxImage(CssBox parent, HtmlTag tag) : base(parent, tag) { _imageWord = new CssRectImage(this); Words.Add(_imageWord); }
/// <summary> /// /// </summary> /// <param name="tag"></param> /// <param name="box"></param> private void TranslateAttributes(HtmlTag tag, CssBox box) { if (tag.HasAttributes()) { foreach (string att in tag.Attributes.Keys) { string value = tag.Attributes[att]; switch (att) { case HtmlConstants.Align: if (value == HtmlConstants.Left || value == HtmlConstants.Center || value == HtmlConstants.Right || value == HtmlConstants.Justify) box.TextAlign = value.ToLower(); else box.VerticalAlign = value.ToLower(); break; case HtmlConstants.Background: box.BackgroundImage = value.ToLower(); break; case HtmlConstants.Bgcolor: box.BackgroundColor = value.ToLower(); break; case HtmlConstants.Border: if (!string.IsNullOrEmpty(value) && value != "0") box.BorderLeftStyle = box.BorderTopStyle = box.BorderRightStyle = box.BorderBottomStyle = CssConstants.Solid; box.BorderLeftWidth = box.BorderTopWidth = box.BorderRightWidth = box.BorderBottomWidth = TranslateLength(value); if (tag.Name == HtmlConstants.Table) { if (value != "0") ApplyTableBorder(box, "1px"); } else { box.BorderTopStyle = box.BorderLeftStyle = box.BorderRightStyle = box.BorderBottomStyle = CssConstants.Solid; } break; case HtmlConstants.Bordercolor: box.BorderLeftColor = box.BorderTopColor = box.BorderRightColor = box.BorderBottomColor = value.ToLower(); break; case HtmlConstants.Cellspacing: box.BorderSpacing = TranslateLength(value); break; case HtmlConstants.Cellpadding: ApplyTablePadding(box, value); break; case HtmlConstants.Color: box.Color = value.ToLower(); break; case HtmlConstants.Dir: box.Direction = value.ToLower(); break; case HtmlConstants.Face: box.FontFamily = _cssParser.ParseFontFamily(value); break; case HtmlConstants.Height: box.Height = TranslateLength(value); break; case HtmlConstants.Hspace: box.MarginRight = box.MarginLeft = TranslateLength(value); break; case HtmlConstants.Nowrap: box.WhiteSpace = CssConstants.NoWrap; break; case HtmlConstants.Size: if (tag.Name.Equals(HtmlConstants.Hr, StringComparison.OrdinalIgnoreCase)) box.Height = TranslateLength(value); else if (tag.Name.Equals(HtmlConstants.Font, StringComparison.OrdinalIgnoreCase)) box.FontSize = value; break; case HtmlConstants.Valign: box.VerticalAlign = value.ToLower(); break; case HtmlConstants.Vspace: box.MarginTop = box.MarginBottom = TranslateLength(value); break; case HtmlConstants.Width: box.Width = TranslateLength(value); break; } } } }
/// <summary> /// Init. /// </summary> /// <param name="parent">the parent box of this box</param> /// <param name="tag">the html tag data of this box</param> public CssBoxHr(CssBox parent, HtmlTag tag) : base(parent, tag) { Display = CssConstants.Block; }
/// <summary> /// Parse the html part, the part from prev parsing index to the beginning of the next html tag.<br/> /// </summary> /// <param name="source">the html source to parse</param> /// <param name="tagIdx">the index of the next html tag</param> /// <param name="curBox">the current box in html tree parsing</param> /// <returns>the end of the parsed part, the new start index</returns> private static int ParseHtmlTag(string source, int tagIdx, ref CssBox curBox) { var endIdx = source.IndexOf('>', tagIdx + 1); if (endIdx > 0) { string tagName; Dictionary<string, string> tagAttributes; var length = endIdx - tagIdx + 1 - (source[endIdx - 1] == '/' ? 1 : 0); if (ParseHtmlTag(source, tagIdx, length, out tagName, out tagAttributes)) { if (!HtmlUtils.IsSingleTag(tagName) && curBox.ParentBox != null) { // need to find the parent tag to go one level up curBox = DomUtils.FindParent(curBox.ParentBox, tagName, curBox); } } else if (!string.IsNullOrEmpty(tagName)) { //new SubString(source, lastEnd + 1, tagmatch.Index - lastEnd - 1) var isSingle = HtmlUtils.IsSingleTag(tagName) || source[endIdx - 1] == '/'; var tag = new HtmlTag(tagName, isSingle, tagAttributes); if (isSingle) { // the current box is not changed CssBox.CreateBox(tag, curBox); } else { // go one level down, make the new box the current box curBox = CssBox.CreateBox(tag, curBox); } } else { endIdx = tagIdx + 1; } } return endIdx; }
/// <summary> /// Init. /// </summary> /// <param name="parent">the parent box of this box</param> /// <param name="tag">the html tag data of this box</param> public CssBoxImage(CssBox parent, HtmlTag tag) : base(parent, tag) { _imageWord = new CssRectImage(this); Words.Add(_imageWord); }
/// <summary> /// Init. /// </summary> /// <param name="parent">the parent box of this box</param> /// <param name="tag">the html tag data of this box</param> public CssBoxHr(CssBox parent, HtmlTag tag) : base(parent, tag) { Display = CssConstants.Block; }