本文整理汇总了C#中TheArtOfDev.HtmlRenderer.Core.Dom.CssBox类的典型用法代码示例。如果您正苦于以下问题:C# CssBox类的具体用法?C# CssBox怎么用?C# CssBox使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CssBox类属于TheArtOfDev.HtmlRenderer.Core.Dom命名空间,在下文中一共展示了CssBox类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CssBoxFrame
/// <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();
}
}
示例2: GetTableSpacing
/// <summary>
/// Get the table cells spacing for all the cells in the table.<br/>
/// Used to calculate the spacing the table has in addition to regular padding and borders.
/// </summary>
/// <param name="tableBox">the table box to calculate the spacing for</param>
/// <returns>the calculated spacing</returns>
public static double GetTableSpacing(CssBox tableBox)
{
int count = 0;
int columns = 0;
foreach (var box in tableBox.Boxes)
{
if (box.Display == CssConstants.TableColumn)
{
columns += GetSpan(box);
}
else if (box.Display == CssConstants.TableRowGroup)
{
foreach (CssBox cr in tableBox.Boxes)
{
count++;
if (cr.Display == CssConstants.TableRow)
columns = Math.Max(columns, cr.Boxes.Count);
}
}
else if (box.Display == CssConstants.TableRow)
{
count++;
columns = Math.Max(columns, box.Boxes.Count);
}
// limit the amount of rows to process for performance
if (count > 30)
break;
}
// +1 columns because padding is between the cell and table borders
return (columns + 1) * GetHorizontalSpacing(tableBox);
}
示例3: ClipGraphicsByOverflow
/// <summary>
/// Clip the region the graphics will draw on by the overflow style of the containing block.<br/>
/// Recursively travel up the tree to find containing block that has overflow style set to hidden. if not
/// block found there will be no clipping and null will be returned.
/// </summary>
/// <param name="g">the graphics to clip</param>
/// <param name="box">the box that is rendered to get containing blocks</param>
/// <returns>true - was clipped, false - not clipped</returns>
public static bool ClipGraphicsByOverflow(RGraphics g, CssBox box)
{
var containingBlock = box.ContainingBlock;
while (true)
{
if (containingBlock.Overflow == CssConstants.Hidden)
{
var prevClip = g.GetClip();
var rect = box.ContainingBlock.ClientRectangle;
rect.X -= 2; // TODO:a find better way to fix it
rect.Width += 2;
if (!box.IsFixed)
rect.Offset(box.HtmlContainer.ScrollOffset);
rect.Intersect(prevClip);
g.PushClip(rect);
return true;
}
else
{
var cBlock = containingBlock.ContainingBlock;
if (cBlock == containingBlock)
return false;
containingBlock = cBlock;
}
}
}
示例4: CssLineBox
/// <summary>
/// Creates a new LineBox
/// </summary>
public CssLineBox(CssBox ownerBox)
{
_rects = new Dictionary<CssBox, RRect>();
_relatedBoxes = new List<CssBox>();
_words = new List<CssRect>();
_ownerBox = ownerBox;
_ownerBox.LineBoxes.Add(this);
}
示例5: CssSpacingBox
public CssSpacingBox(CssBox tableBox, ref CssBox extendedBox, int startRow)
: base(tableBox, new HtmlTag("none", false, new Dictionary<string, string> { { "colspan", "1" } }))
{
_extendedBox = extendedBox;
Display = CssConstants.None;
_startRow = startRow;
_endRow = startRow + Int32.Parse(extendedBox.GetAttribute("rowspan", "1")) - 1;
}
示例6: ContainsInlinesOnly
/// <summary>
/// Check if the given box contains only inline child boxes.
/// </summary>
/// <param name="box">the box to check</param>
/// <returns>true - only inline child boxes, false - otherwise</returns>
public static bool ContainsInlinesOnly(CssBox box)
{
foreach (CssBox b in box.Boxes)
{
if (!b.IsInline)
{
return false;
}
}
return true;
}
示例7: IsInBox
/// <summary>
/// Check if the given location is inside the given box deep.<br/>
/// Check inner boxes and all lines that the given box spans to.
/// </summary>
/// <param name="box">the box to check</param>
/// <param name="location">the location to check</param>
/// <returns>true - location inside the box, false - otherwise</returns>
public static bool IsInBox(CssBox box, RPoint location)
{
foreach (var line in box.Rectangles)
{
if (line.Value.Contains(location))
return true;
}
foreach (var childBox in box.Boxes)
{
if (IsInBox(childBox, location))
return true;
}
return false;
}
示例8: FindParent
/// <summary>
/// Recursively searches for the parent with the specified HTML Tag name
/// </summary>
/// <param name="root"></param>
/// <param name="tagName"></param>
/// <param name="box"></param>
public static CssBox FindParent(CssBox root, string tagName, CssBox box)
{
if (box == null)
{
return root;
}
else if (box.HtmlTag != null && box.HtmlTag.Name.Equals(tagName, StringComparison.CurrentCultureIgnoreCase))
{
return box.ParentBox ?? root;
}
else
{
return FindParent(root, tagName, box.ParentBox);
}
}
示例9: DrawBoxBorders
/// <summary>
/// Draws all the border of the box with respect to style, width, etc.
/// </summary>
/// <param name="g">the device to draw into</param>
/// <param name="box">the box to draw borders for</param>
/// <param name="rect">the bounding rectangle to draw in</param>
/// <param name="isFirst">is it the first rectangle of the element</param>
/// <param name="isLast">is it the last rectangle of the element</param>
public static void DrawBoxBorders(RGraphics g, CssBox box, RRect rect, bool isFirst, bool isLast)
{
if (rect.Width > 0 && rect.Height > 0)
{
if (!(string.IsNullOrEmpty(box.BorderTopStyle) || box.BorderTopStyle == CssConstants.None || box.BorderTopStyle == CssConstants.Hidden) && box.ActualBorderTopWidth > 0)
{
DrawBorder(Border.Top, box, g, rect, isFirst, isLast);
}
if (isFirst && !(string.IsNullOrEmpty(box.BorderLeftStyle) || box.BorderLeftStyle == CssConstants.None || box.BorderLeftStyle == CssConstants.Hidden) && box.ActualBorderLeftWidth > 0)
{
DrawBorder(Border.Left, box, g, rect, true, isLast);
}
if (!(string.IsNullOrEmpty(box.BorderBottomStyle) || box.BorderBottomStyle == CssConstants.None || box.BorderBottomStyle == CssConstants.Hidden) && box.ActualBorderBottomWidth > 0)
{
DrawBorder(Border.Bottom, box, g, rect, isFirst, isLast);
}
if (isLast && !(string.IsNullOrEmpty(box.BorderRightStyle) || box.BorderRightStyle == CssConstants.None || box.BorderRightStyle == CssConstants.Hidden) && box.ActualBorderRightWidth > 0)
{
DrawBorder(Border.Right, box, g, rect, isFirst, true);
}
}
}
示例10: DrawBackgroundImage
/// <summary>
/// Draw the background image of the given box in the given rectangle.<br/>
/// Handle background-repeat and background-position values.
/// </summary>
/// <param name="g">the device to draw into</param>
/// <param name="box">the box to draw its background image</param>
/// <param name="imageLoadHandler">the handler that loads image to draw</param>
/// <param name="rectangle">the rectangle to draw image in</param>
public static void DrawBackgroundImage(RGraphics g, CssBox box, ImageLoadHandler imageLoadHandler, RRect rectangle)
{
// image size depends if specific rectangle given in image loader
var imgSize = new RSize(imageLoadHandler.Rectangle == RRect.Empty ? imageLoadHandler.Image.Width : imageLoadHandler.Rectangle.Width,
imageLoadHandler.Rectangle == RRect.Empty ? imageLoadHandler.Image.Height : imageLoadHandler.Rectangle.Height);
// get the location by BackgroundPosition value
var location = GetLocation(box.BackgroundPosition, rectangle, imgSize);
var srcRect = imageLoadHandler.Rectangle == RRect.Empty
? new RRect(0, 0, imgSize.Width, imgSize.Height)
: new RRect(imageLoadHandler.Rectangle.Left, imageLoadHandler.Rectangle.Top, imgSize.Width, imgSize.Height);
// initial image destination rectangle
var destRect = new RRect(location, imgSize);
// need to clip so repeated image will be cut on rectangle
var lRectangle = rectangle;
lRectangle.Intersect(g.GetClip());
g.PushClip(lRectangle);
switch (box.BackgroundRepeat)
{
case "no-repeat":
g.DrawImage(imageLoadHandler.Image, destRect, srcRect);
break;
case "repeat-x":
DrawRepeatX(g, imageLoadHandler, rectangle, srcRect, destRect, imgSize);
break;
case "repeat-y":
DrawRepeatY(g, imageLoadHandler, rectangle, srcRect, destRect, imgSize);
break;
default:
DrawRepeat(g, imageLoadHandler, rectangle, srcRect, destRect, imgSize);
break;
}
g.PopClip();
}
示例11: GetMinMaxSumWords
/// <summary>
/// Get the <paramref name="min"/> and <paramref name="maxSum"/> of the box words content and <paramref name="paddingSum"/>.<br/>
/// </summary>
/// <param name="box">the box to calculate for</param>
/// <param name="min">the width that allows for each word to fit (width of the longest word)</param>
/// <param name="maxSum">the max width a single line of words can take without wrapping</param>
/// <param name="paddingSum">the total amount of padding the content has </param>
/// <param name="marginSum"></param>
/// <returns></returns>
private static void GetMinMaxSumWords(CssBox box, ref double min, ref double maxSum, ref double paddingSum, ref double marginSum)
{
double? oldSum = null;
// not inline (block) boxes start a new line so we need to reset the max sum
if (box.Display != CssConstants.Inline && box.Display != CssConstants.TableCell && box.WhiteSpace != CssConstants.NoWrap)
{
oldSum = maxSum;
maxSum = marginSum;
}
// add the padding
paddingSum += box.ActualBorderLeftWidth + box.ActualBorderRightWidth + box.ActualPaddingRight + box.ActualPaddingLeft;
// for tables the padding also contains the spacing between cells
if (box.Display == CssConstants.Table)
paddingSum += CssLayoutEngineTable.GetTableSpacing(box);
if (box.Words.Count > 0)
{
// calculate the min and max sum for all the words in the box
foreach (CssRect word in box.Words)
{
maxSum += word.FullWidth + (word.HasSpaceBefore ? word.OwnerBox.ActualWordSpacing : 0);
min = Math.Max(min, word.Width);
}
// remove the last word padding
if (box.Words.Count > 0 && !box.Words[box.Words.Count - 1].HasSpaceAfter)
maxSum -= box.Words[box.Words.Count - 1].ActualWordSpacing;
}
else
{
// recursively on all the child boxes
for (int i = 0; i < box.Boxes.Count; i++)
{
CssBox childBox = box.Boxes[i];
marginSum += childBox.ActualMarginLeft + childBox.ActualMarginRight;
//maxSum += childBox.ActualMarginLeft + childBox.ActualMarginRight;
GetMinMaxSumWords(childBox, ref min, ref maxSum, ref paddingSum, ref marginSum);
marginSum -= childBox.ActualMarginLeft + childBox.ActualMarginRight;
}
}
// max sum is max of all the lines in the box
if (oldSum.HasValue)
{
maxSum = Math.Max(maxSum, oldSum.Value);
}
}
示例12: GetMinimumWidth_LongestWord
/// <summary>
/// Gets the longest word (in width) inside the box, deeply.
/// </summary>
/// <param name="box"></param>
/// <param name="maxWidth"> </param>
/// <param name="maxWidthWord"> </param>
/// <returns></returns>
private static void GetMinimumWidth_LongestWord(CssBox box, ref double maxWidth, ref CssRect maxWidthWord)
{
if (box.Words.Count > 0)
{
foreach (CssRect cssRect in box.Words)
{
if (cssRect.Width > maxWidth)
{
maxWidth = cssRect.Width;
maxWidthWord = cssRect;
}
}
}
else
{
foreach (CssBox childBox in box.Boxes)
GetMinimumWidth_LongestWord(childBox, ref maxWidth, ref maxWidthWord);
}
}
示例13: InheritStyle
/// <summary>
/// Gets the rectangles where inline box will be drawn. See Remarks for more info.
/// </summary>
/// <returns>Rectangles where content should be placed</returns>
/// <remarks>
/// Inline boxes can be split across different LineBoxes, that's why this method
/// Delivers a rectangle for each LineBox related to this box, if inline.
/// </remarks>
/// <summary>
/// Inherits inheritable values from parent.
/// </summary>
internal new void InheritStyle(CssBox box = null, bool everything = false)
{
base.InheritStyle(box ?? ParentBox, everything);
}
示例14: FirstWordOccourence
/// <summary>
/// Searches for the first word occurrence inside the box, on the specified linebox
/// </summary>
/// <param name="b"></param>
/// <param name="line"> </param>
/// <returns></returns>
internal CssRect FirstWordOccourence(CssBox b, CssLineBox line)
{
if (b.Words.Count == 0 && b.Boxes.Count == 0)
{
return null;
}
if (b.Words.Count > 0)
{
foreach (CssRect word in b.Words)
{
if (line.Words.Contains(word))
{
return word;
}
}
return null;
}
else
{
foreach (CssBox bb in b.Boxes)
{
CssRect w = FirstWordOccourence(bb, line);
if (w != null)
{
return w;
}
}
return null;
}
}
示例15: SetAllBoxes
/// <summary>
/// Move all child boxes from <paramref name="fromBox"/> to this box.
/// </summary>
/// <param name="fromBox">the box to move all its child boxes from</param>
public void SetAllBoxes(CssBox fromBox)
{
foreach (var childBox in fromBox._boxes)
childBox._parentBox = this;
_boxes.AddRange(fromBox._boxes);
fromBox._boxes.Clear();
}