Example #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));
        }
Example #2
0
        /// <summary>
        /// Writes log events to an <see cref="IRichTextBox"/> control, used only for unit-testing purposes.
        /// </summary>
        /// <param name="sinkConfiguration">Logger sink configuration.</param>
        /// <param name="richTextBox">The RichTextBox control to write to.</param>
        /// <param name="restrictedToMinimumLevel">The minimum level for
        /// events passed through the sink. Ignored when <paramref name="levelSwitch"/> is specified.</param>
        /// <param name="outputTemplate">A message template describing the format used to write to the sink.
        /// The default is <code>"[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}"</code>.</param>
        /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
        /// <param name="levelSwitch">A switch allowing the pass-through minimum level
        /// to be changed at runtime.</param>
        /// <param name="theme">The theme to apply to the styled output. If not specified,
        /// uses <see cref="RichTextBoxConsoleTheme.Literate"/>.</param>
        /// <param name="dispatcherPriority">The priority at which messages will be sent to the UI thread when logging from a non-UI thread.</param>
        /// <param name="syncRoot">An object that will be used to `lock` (sync) access to the <see cref="IRichTextBox"/> instance. If you specify this, you
        /// will have the ability to lock on this object, and guarantee that the RichTextBox sink will not be about to output anything while
        /// the lock is held.</param>
        /// <returns>Configuration object allowing method chaining.</returns>
        /// <exception cref="ArgumentNullException">When <paramref name="sinkConfiguration"/> is <code>null</code></exception>
        /// <exception cref="ArgumentNullException">When <paramref name="outputTemplate"/> is <code>null</code></exception>
        internal static LoggerConfiguration RichTextBox(
            this LoggerSinkConfiguration sinkConfiguration,
            IRichTextBox richTextBox,
            LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
            string outputTemplate                 = _defaultRichTextBoxOutputTemplate,
            IFormatProvider formatProvider        = null,
            LoggingLevelSwitch levelSwitch        = null,
            RichTextBoxTheme theme                = null,
            DispatcherPriority dispatcherPriority = DispatcherPriority.Background,
            object syncRoot = null)
        {
            if (sinkConfiguration is null)
            {
                throw new ArgumentNullException(nameof(sinkConfiguration));
            }

            if (outputTemplate is null)
            {
                throw new ArgumentNullException(nameof(outputTemplate));
            }

            var appliedTheme = theme ?? RichTextBoxConsoleThemes.Literate;

            syncRoot ??= _defaultSyncRoot;

            var formatter = new XamlOutputTemplateRenderer(appliedTheme, outputTemplate, formatProvider);

            return(sinkConfiguration.Sink(new RichTextBoxSink(richTextBox, formatter, dispatcherPriority, syncRoot),
                                          restrictedToMinimumLevel, levelSwitch));
        }
Example #3
0
        /// <inheritdoc />
        public override void CreateContents(IGridPanel gridComposite)
        {
            gridComposite.GridColumns = 1;
            gridComposite.GridRows    = 1;
            IContentAssistTextBox richTextBox = WidgetFactory.CreateInstance <IContentAssistTextBox>(gridComposite);

            gridComposite.AddWidget(richTextBox);
            TextBox = richTextBox;

            DataBindingOperator.Apply(richTextBox, PRichTextBox.TextProperty, new DataBinding(this, nameof(EditorText)));
        }
        public RichTextBoxSink(IRichTextBox richTextBox, ITextFormatter formatter, DispatcherPriority dispatcherPriority, object syncRoot)
        {
            _richTextBox = richTextBox ?? throw new ArgumentNullException(nameof(richTextBox));
            _formatter   = formatter ?? throw new ArgumentNullException(nameof(formatter));

            if (!Enum.IsDefined(typeof(DispatcherPriority), dispatcherPriority))
            {
                throw new InvalidEnumArgumentException(nameof(dispatcherPriority), (int)dispatcherPriority,
                                                       typeof(DispatcherPriority));
            }

            _dispatcherPriority = dispatcherPriority;
            _syncRoot           = syncRoot ?? throw new ArgumentNullException(nameof(syncRoot));

            _renderAction = Render;

            _messageQueue = new ConcurrentQueue <LogEvent>();

            _consumerThread = new Thread(new ThreadStart(ProcessMessages))
            {
                IsBackground = true
            };
            _consumerThread.Start();
        }
Example #5
0
 public byte[] BuildImageRgba(IRichTextBox textBox)
 {
     throw new NotImplementedException();
 }