Exemple #1
0
        protected override void CreateFragment()
        {
            string text = Text;
            string font = string.Format("font: {0}pt {1}", Font.Size, Font.FontFamily.Name);

            //Create fragment container
            _htmlContainer = new InitialContainer("<table border=0 cellspacing=5 cellpadding=0 style=\"" + font + "\"><tr><td>" + text + "</td></tr></table>");
            //_htmlContainer.SetBounds(new Rectangle(0, 0, 10, 10));
        }
Exemple #2
0
        /// <summary>
        /// Renders the specified HTML source on the specified area clipping if specified
        /// </summary>
        /// <param name="g">Device to draw</param>
        /// <param name="html">HTML source</param>
        /// <param name="area">Area where HTML should be drawn</param>
        /// <param name="clip">If true, it will only paint on the specified area</param>
        public static void Render(Graphics g, string html, RectangleF area, bool clip)
        {
            InitialContainer container = new InitialContainer(html);
            Region prevClip = g.Clip;

            if (clip) g.SetClip(area);

            container.SetBounds(area);
            container.MeasureBounds(g);
            container.Paint(g);

            if (clip) g.SetClip(prevClip, System.Drawing.Drawing2D.CombineMode.Replace);
        }
        /// <summary>
        /// Parses the document
        /// </summary>
        private void ParseDocument()
        {
            InitialContainer root   = this;
            MatchCollection  tags   = Parser.Match(Parser.HtmlTag, DocumentSource);
            CssBox           curBox = root;
            int lastEnd             = -1;

            foreach (Match tagmatch in tags)
            {
                string text = tagmatch.Index > 0 ? DocumentSource.Substring(lastEnd + 1, tagmatch.Index - lastEnd - 1) : string.Empty;

                if (!string.IsNullOrEmpty(text.Trim()))
                {
                    CssAnonymousBox abox = new CssAnonymousBox(curBox);
                    abox.Text = text;
                }
                else if (text != null && text.Length > 0)
                {
                    CssAnonymousSpaceBox sbox = new CssAnonymousSpaceBox(curBox);
                    sbox.Text = text;
                }

                HtmlTag tag = new HtmlTag(tagmatch.Value);

                if (tag.IsClosing)
                {
                    curBox = FindParent(tag.TagName, curBox);
                }
                else if (tag.IsSingle)
                {
                    CssBox foo = new CssBox(curBox, tag);
                }
                else
                {
                    curBox = new CssBox(curBox, tag);
                }



                lastEnd = tagmatch.Index + tagmatch.Length - 1;
            }

            string finaltext = DocumentSource.Substring((lastEnd > 0 ? lastEnd + 1 : 0), DocumentSource.Length - lastEnd - 1 + (lastEnd == 0 ? 1 : 0));

            if (!string.IsNullOrEmpty(finaltext))
            {
                CssAnonymousBox abox = new CssAnonymousBox(curBox);
                abox.Text = finaltext;
            }
        }
Exemple #4
0
        /// <summary>
        /// Creates a new HtmlPanel
        /// </summary>
        public HtmlPanel()
        {
            _htmlContainer = new InitialContainer();

            SetStyle(ControlStyles.ResizeRedraw, true);
            SetStyle(ControlStyles.Opaque, true);
            //SetStyle(ControlStyles.Selectable, true);

            DoubleBuffered = true;

            BackColor = SystemColors.Window;
            AutoScroll = true;

            HtmlRenderer.AddReference(Assembly.GetCallingAssembly());
        }
        /// <summary>
        /// Renders the specified HTML source on the specified area clipping if specified
        /// </summary>
        /// <param name="g">Device to draw</param>
        /// <param name="html">HTML source</param>
        /// <param name="area">Area where HTML should be drawn</param>
        /// <param name="clip">If true, it will only paint on the specified area</param>
        public static void Render(Graphics g, string html, RectangleF area, bool clip)
        {
            InitialContainer container = new InitialContainer(html);
            Region           prevClip  = g.Clip;

            if (clip)
            {
                g.SetClip(area);
            }

            container.SetBounds(area);
            container.MeasureBounds(g);
            container.Paint(g);

            if (clip)
            {
                g.SetClip(prevClip, System.Drawing.Drawing2D.CombineMode.Replace);
            }
        }
Exemple #6
0
        void HtmlToolTip_Popup(object sender, PopupEventArgs e)
        {
            string text = this.GetToolTip(e.AssociatedControl);
            string font = string.Format(NumberFormatInfo.InvariantInfo, "font: {0}pt {1}", e.AssociatedControl.Font.Size, e.AssociatedControl.Font.FontFamily.Name);

            //Create fragment container
            container = new InitialContainer("<table class=htmltooltipbackground cellspacing=5 cellpadding=0 style=\"" + font + "\"><tr><td style=border:0px>" + text + "</td></tr></table>");
            container.SetBounds(new Rectangle(0, 0, 10, 10));
            container.AvoidGeometryAntialias = true;

            //Measure bounds of the container
            using (Graphics g = e.AssociatedControl.CreateGraphics())
            {
                container.MeasureBounds(g);
            }

            //Set the size of the tooltip
            e.ToolTipSize = Size.Round(container.MaximumSize);
        }
        void HtmlToolTip_Popup(object sender, PopupEventArgs e)
        {
            string text = this.GetToolTip(e.AssociatedControl);
            string font = string.Format(NumberFormatInfo.InvariantInfo, "font: {0}pt {1}", e.AssociatedControl.Font.Size, e.AssociatedControl.Font.FontFamily.Name);

            //Create fragment container
            container = new InitialContainer("<table class=htmltooltipbackground cellspacing=5 cellpadding=0 style=\"" + font + "\"><tr><td style=border:0px>" + text + "</td></tr></table>");
            container.SetBounds(new Rectangle(0, 0, 10, 10));
            container.AvoidGeometryAntialias = true;

            //Measure bounds of the container
            using (Graphics g = e.AssociatedControl.CreateGraphics())
            {
                container.MeasureBounds(g);
            }

            //Set the size of the tooltip
            e.ToolTipSize = Size.Round(container.MaximumSize);
        }
 /// <summary>
 /// Sets the initial container of the box
 /// </summary>
 /// <param name="b"></param>
 private void SetInitialContainer(InitialContainer b)
 {
     _initialContainer = b;
 }
Exemple #9
0
 /// <summary>
 /// Creates the fragment of HTML that is rendered
 /// </summary>
 protected virtual void CreateFragment()
 {
     _htmlContainer = new InitialContainer(Text);
 }
Exemple #10
0
        private Bitmap GenerateBitmap()
        {
            try
            {
                Bitmap c = new Bitmap(this.Width, this.Height);

                Graphics g = Graphics.FromImage(c);
                g.FillRectangle(new SolidBrush(BackColor), new Rectangle(0, 0, Width, Height));
                int fontSize = (int)(((float)Block.Font.Size / 11) * 3);
                String html = "<font face=\"" + Block.Font.FontFamily.Name + "\" size=\"1\" color=\"" + ColorTranslator.ToHtml(Block.ForeColor) + "\">" + Text + "</font>";
                InitialContainer htmlContainer = new InitialContainer(html);
                htmlPanel.HtmlContainer.Text = html;
                HtmlRenderer.Render(g, html, new Point(0, 0), this.Width);
                //if (this.Shadow)
                 //   g.DrawString(Text, new Font("MS Sans Serif", 11), new SolidBrush(Block.TextShadowColor), new RectangleF(0f, -1f, (float)Width, (float)Height));
                //g.DrawString(Text, new Font("MS Sans Serif", 11), new SolidBrush(ForeColor), new RectangleF(0f, -0f, (float)Width, (float)Height));

                return c;
            }
            catch (Exception e)
            {
                return null;
            }
        }
		public static SizeF GetPreferredSize(Graphics g, string html, float width)
		{
			InitialContainer container = new InitialContainer(html);
			RectangleF area = new RectangleF(new PointF(0, 0), new SizeF(width, 0));

			container.SetBounds(area);
			container.MeasureBounds(g, true);
			return container.MaximumSize;
		}