Example #1
0
        public Size Measure(string text, double fontSize, Typeface typeface, double maxWidth)
        {
            if (htmlElement == null)
            {
                htmlElement = Document.CreateElement("div");
                Bridge.Html5.Window.Body.AppendChild(htmlElement);
            }

            htmlElement.SetHtmlStyleProperty("position", "absolute");
            htmlElement.SetHtmlStyleProperty("visibility", "hidden");
            htmlElement.SetHtmlFontSize(fontSize, converter);
            htmlElement.SetHtmlFontFamily(typeface.FontFamily, converter);
            htmlElement.SetHtmlFontStretch(typeface.Stretch, converter);
            htmlElement.SetHtmlFontStyle(typeface.Style, converter);
            htmlElement.SetHtmlFontWeight(typeface.Weight, converter);

            if (maxWidth.IsNaN() || double.IsInfinity(maxWidth))
            {
                htmlElement.SetHtmlTextWrapping(TextWrapping.NoWrap, converter);
                htmlElement.ClearHtmlStyleProperty("max-width");
            }
            else
            {
                htmlElement.SetHtmlTextWrapping(TextWrapping.Wrap, converter);
                htmlElement.SetHtmlStyleProperty("max-width", converter.ToPixelString(maxWidth));
            }

            htmlElement.InnerHTML = converter.ToHtmlContentString(text.DefaultIfNullOrEmpty("A"));

            (int width, int height) = htmlElement.Dimensions;
            return(new Size(text.IsNullOrEmpty() ? 0 : width + 2, height));
        }
Example #2
0
 public static void SetHtmlBackgroundSize(this HtmlElement element, Size size, HtmlValueConverter converter)
 {
     if (Size.IsNullOrEmpty(size))
     {
         element.ClearHtmlStyleProperty("background-size");
     }
     else
     {
         element.SetHtmlStyleProperty("background-size", converter.ToPixelString(size));
     }
 }
Example #3
0
 public static void SetHtmlBackgroundLocation(this HtmlElement element, Point location, HtmlValueConverter converter)
 {
     if (Point.IsNullOrEmpty(location))
     {
         element.ClearHtmlStyleProperty("background-position");
     }
     else
     {
         element.SetHtmlStyleProperty("background-position", converter.ToPixelString(location));
     }
 }
Example #4
0
 public static void SetHtmlFontSize(this HtmlElement element, double fontSize, HtmlValueConverter converter)
 {
     if (fontSize.IsNaN())
     {
         element.ClearHtmlStyleProperty("font-size");
     }
     else
     {
         element.SetHtmlStyleProperty("font-size", converter.ToPixelString(fontSize));
     }
 }
Example #5
0
        public static void SetHtmlSize(this HtmlElement element, Size size, HtmlValueConverter converter)
        {
            if (size.Width.IsNaN())
            {
                element.ClearHtmlStyleProperty("width");
            }
            else
            {
                element.SetHtmlStyleProperty("width", converter.ToPixelString(size.Width));
            }

            if (size.Height.IsNaN())
            {
                element.ClearHtmlStyleProperty("height");
            }
            else
            {
                element.SetHtmlStyleProperty("height", converter.ToPixelString(size.Height));
            }
        }
Example #6
0
        public static void SetHtmlCornerRadius(this HtmlElement element, CornerRadius cornerRadius, HtmlValueConverter converter)
        {
            element.ClearHtmlStyleProperty("border-radius");
            element.ClearHtmlStyleProperty("border-top-left-radius");
            element.ClearHtmlStyleProperty("border-top-right-radius");
            element.ClearHtmlStyleProperty("border-bottom-left-radius");
            element.ClearHtmlStyleProperty("border-bottom-right-radius");

            if (cornerRadius != CornerRadius.Zero)
            {
                if (cornerRadius.IsUniform)
                {
                    element.SetHtmlStyleProperty("border-radius", converter.ToPixelString(cornerRadius.TopLeft));
                }
                else
                {
                    element.SetHtmlStyleProperty("border-top-left-radius", converter.ToPixelString(cornerRadius.TopLeft));
                    element.SetHtmlStyleProperty("border-top-right-radius", converter.ToPixelString(cornerRadius.TopRight));
                    element.SetHtmlStyleProperty("border-bottom-left-radius", converter.ToPixelString(cornerRadius.BottomLeft));
                    element.SetHtmlStyleProperty("border-bottom-right-radius", converter.ToPixelString(cornerRadius.BottomRight));
                }
            }
        }
Example #7
0
 public static void SetHtmlBorderThickness(this HtmlElement element, Thickness borderThickness, HtmlValueConverter converter)
 {
     if (borderThickness == Thickness.Zero)
     {
         element.ClearHtmlStyleProperty("border-style");
         element.ClearHtmlStyleProperty("border-width");
         element.ClearHtmlStyleProperty("border-image-slice");
     }
     else
     {
         element.SetHtmlStyleProperty("border-style", "solid");
         element.SetHtmlStyleProperty("border-width", converter.ToPixelString(borderThickness));
         element.SetHtmlStyleProperty("border-image-slice", converter.ToImplicitValueString(borderThickness));
     }
 }
Example #8
0
 public static void SetHtmlLocation(this HtmlElement element, Point location, HtmlValueConverter converter)
 {
     element.SetHtmlStyleProperty("position", "absolute");
     element.SetHtmlStyleProperty("left", converter.ToPixelString(location.X));
     element.SetHtmlStyleProperty("top", converter.ToPixelString(location.Y));
 }