/// <summary> /// Perform the layout of the html in the control. /// </summary> protected override Size MeasureOverride(Size constraint) { if (_htmlContainer != null) { using (var ig = new GraphicsAdapter()) { var horizontal = Padding.Left + Padding.Right + BorderThickness.Left + BorderThickness.Right; var vertical = Padding.Top + Padding.Bottom + BorderThickness.Top + BorderThickness.Bottom; var size = new RSize(constraint.Width < Double.PositiveInfinity ? constraint.Width - horizontal : 0, constraint.Height < Double.PositiveInfinity ? constraint.Height - vertical : 0); var minSize = new RSize(MinWidth < Double.PositiveInfinity ? MinWidth - horizontal : 0, MinHeight < Double.PositiveInfinity ? MinHeight - vertical : 0); var maxSize = new RSize(MaxWidth < Double.PositiveInfinity ? MaxWidth - horizontal : 0, MaxHeight < Double.PositiveInfinity ? MaxHeight - vertical : 0); var newSize = HtmlRendererUtils.Layout(ig, _htmlContainer.HtmlContainerInt, size, minSize, maxSize, AutoSize, AutoSizeHeightOnly); constraint = new Size(newSize.Width + horizontal, newSize.Height + vertical); } } if (double.IsPositiveInfinity(constraint.Width) || double.IsPositiveInfinity(constraint.Height)) constraint = Size.Empty; return constraint; }
/// <summary> /// Render the html using the given device. /// </summary> /// <param name="g">the device to use to render</param> /// <param name="clip">the clip rectangle of the html container</param> public void PerformPaint(DrawingContext g, Rect clip) { ArgChecker.AssertArgNotNull(g, "g"); using (var ig = new GraphicsAdapter(g, Utils.Convert(clip))) { _htmlContainerInt.PerformPaint(ig); } }
/// <summary> /// Measures the bounds of box and children, recursively. /// </summary> public void PerformLayout() { using (var ig = new GraphicsAdapter()) { _htmlContainerInt.PerformLayout(ig); } }
public override void MeasureString(string str, RFont font, double maxWidth, out int charFit, out double charFitWidth) { using (var g = new GraphicsAdapter()) { g.MeasureString(str, font, maxWidth, out charFit, out charFitWidth); } }
/// <summary> /// Measure the size of the html by performing layout under the given restrictions. /// </summary> /// <param name="htmlContainer">the html to calculate the layout for</param> /// <param name="minSize">the minimal size of the rendered html (zero - not limit the width/height)</param> /// <param name="maxSize">the maximum size of the rendered html, if not zero and html cannot be layout within the limit it will be clipped (zero - not limit the width/height)</param> /// <returns>return: the size of the html to be rendered within the min/max limits</returns> private static Size MeasureHtmlByRestrictions(HtmlContainer htmlContainer, Size minSize, Size maxSize) { // use desktop created graphics to measure the HTML using (var mg = new GraphicsAdapter()) { var sizeInt = HtmlRendererUtils.MeasureHtmlByRestrictions(mg, htmlContainer.HtmlContainerInt, Utils.Convert(minSize), Utils.Convert(maxSize)); return Utils.ConvertRound(sizeInt); } }