Beispiel #1
0
        public byte[] BuildImageRgba(IRichTextBox textBox)
        {
            var text   = textBox.Text;
            var layout = textBox.Layout;

            var bitmap          = new Bitmap(textBox.Size.Width, textBox.Size.Height, PixelFormat.Format32bppRgba);
            var graphics        = new Graphics(bitmap);
            var backgroundColor = text.Style.BackgroundColor;

            graphics.Clear(new Color(backgroundColor.R, backgroundColor.G, backgroundColor.B, backgroundColor.A));

            foreach (var lspan in layout.LayoutSpans.Concat(layout.ExternalLayoutSpans))
            {
                if (lspan.EmbeddingImage != null)
                {
                    var etoImage = lspan.EmbeddingImage.ToEto();
                    graphics.DrawImage(etoImage, lspan.Bounds.MinX, lspan.Bounds.MinY);
                }
                else
                {
                    var style         = lspan.Style;
                    var rectText      = lspan.Text;
                    var etoFontFamily = fontFamilyCache.GetFontFamily(style.FontFamily);
                    var etoFont       = new Font(etoFontFamily, style.Size, ConvertFontStyle(style.FontDecoration), ConvertFontDecoration(style.FontDecoration));
                    var etoColor      = new Color(style.TextColor.R, style.TextColor.G, style.TextColor.B, style.TextColor.A);
                    graphics.DrawText(etoFont, etoColor, lspan.Bounds.MinX, lspan.Bounds.MinY, rectText);
                }
            }
            graphics.Flush();

            return(FromEtoImage.GetRawData(bitmap));
        }
Beispiel #2
0
        public Size2 MeasureString(string str, IRtSpanStyle style)
        {
            var etoFontFamily = fontFamilyCache.GetFontFamily(style.FontFamily);

            Converters.ToEto(style.FontDecoration, out var etoStyle, out var etoDecoration);
            var etoFont = new Font(etoFontFamily, style.Size, etoStyle, etoDecoration);

            return(Converters.ToClarity(graphics.MeasureString(etoFont, str)));
        }