Exemple #1
0
        /// <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);
        }
Exemple #2
0
 /// <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 g = Graphics.FromHwnd(IntPtr.Zero))
         using (var mg = new GraphicsAdapter(g, htmlContainer.UseGdiPlusTextRendering)) {
             var sizeInt = HtmlRendererUtils.MeasureHtmlByRestrictions(mg, htmlContainer.HtmlContainerInt, Utils.Convert(minSize), Utils.Convert(maxSize));
             return(Utils.ConvertRound(sizeInt));
         }
 }
 /// <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));
         if (maxSize.Width < 1 && sizeInt.Width > 4096)
         {
             sizeInt.Width = 4096;
         }
         return(Utils.ConvertRound(sizeInt));
     }
 }
Exemple #4
0
 /// <summary>
 /// Perform the layout of the html in the control.
 /// </summary>
 protected override void OnLayout(LayoutEventArgs levent)
 {
     if (_htmlContainer != null)
     {
         using (Graphics g = CreateGraphics())
             using (var ig = new GraphicsAdapter(g, _htmlContainer.UseGdiPlusTextRendering)) {
                 var newSize = HtmlRendererUtils.Layout(ig,
                                                        _htmlContainer.HtmlContainerInt,
                                                        new RSize(ClientSize.Width - Padding.Horizontal, ClientSize.Height - Padding.Vertical),
                                                        new RSize(MinimumSize.Width - Padding.Horizontal, MinimumSize.Height - Padding.Vertical),
                                                        new RSize(MaximumSize.Width - Padding.Horizontal, MaximumSize.Height - Padding.Vertical),
                                                        AutoSize,
                                                        AutoSizeHeightOnly);
                 ClientSize = Utils.ConvertRound(new RSize(newSize.Width + Padding.Horizontal, newSize.Height + Padding.Vertical));
             }
     }
     base.OnLayout(levent);
 }
Exemple #5
0
 private Size?GetPreferredSize()
 {
     if (_htmlContainer != null)
     {
         using (Graphics g = CreateGraphics()) {
             using (var ig = new GraphicsAdapter(g, _htmlContainer.UseGdiPlusTextRendering)) {
                 var newSize = HtmlRendererUtils.Layout(ig,
                                                        _htmlContainer.HtmlContainerInt,
                                                        new RSize(ClientSize.Width - InternalPadding.Horizontal - Padding.Horizontal, ClientSize.Height - InternalPadding.Vertical - Padding.Vertical),
                                                        new RSize(MinimumSize.Width - InternalPadding.Horizontal - Padding.Horizontal, MinimumSize.Height - InternalPadding.Vertical - Padding.Vertical),
                                                        new RSize(MaximumSize.Width - InternalPadding.Horizontal - Padding.Horizontal, MaximumSize.Height - InternalPadding.Vertical - Padding.Vertical),
                                                        AutoSize,
                                                        AutoSizeHeightOnly);
                 return(Utils.ConvertRound(new RSize(newSize.Width + InternalPadding.Horizontal + Padding.Horizontal, newSize.Height + InternalPadding.Vertical - Padding.Vertical)));
             }
         }
     }
     return(null);
 }
Exemple #6
0
 /// <summary>
 /// Perform the layout of the html in the control.
 /// </summary>
 protected void PerformLayout()
 {
     if (_htmlContainer != null)
     {
         using (var g = Utils.CreateGraphics())
         {
             using (var ig = new GraphicsAdapter(g))
             {
                 var newSize = HtmlRendererUtils.Layout(ig,
                                                        _htmlContainer.HtmlContainerInt,
                                                        new RSize(ClientSize.Width - Padding.Horizontal, ClientSize.Height - Padding.Vertical),
                                                        new RSize(MinimumSize.Width - Padding.Horizontal, MinimumSize.Height - Padding.Vertical),
                                                        new RSize(MaximumSize.Width - Padding.Horizontal, MaximumSize.Height - Padding.Vertical),
                                                        true,
                                                        false);
                 ClientSize = Utils.ConvertRound(new RSize(newSize.Width + Padding.Horizontal, newSize.Height + Padding.Vertical));
             }
         }
     }
 }