Ejemplo n.º 1
0
        public void DrawTextCoreOld()
        {
            using (var image = new Image <Rgba32>(800, 800))
            {
                Fonts.Font font = Fonts.SystemFonts.CreateFont("Arial", 12);
                image.Mutate(x => DrawTextOldVersion(
                                 x,
                                 new TextGraphicsOptions {
                    GraphicsOptions = { Antialias = true }, TextOptions = { WrapTextWidth = 780 }
                },
                                 this.TextToRender,
                                 font,
                                 Processing.Brushes.Solid(Color.HotPink),
                                 null,
                                 new PointF(10, 10)));
            }

            IImageProcessingContext DrawTextOldVersion(
                IImageProcessingContext source,
                TextGraphicsOptions options,
                string text,
                Fonts.Font font,
                IBrush brush,
                IPen pen,
                PointF location)
            {
                const float dpiX = 72;
                const float dpiY = 72;

                var style = new Fonts.RendererOptions(font, dpiX, dpiY, location)
                {
                    ApplyKerning        = options.TextOptions.ApplyKerning,
                    TabWidth            = options.TextOptions.TabWidth,
                    WrappingWidth       = options.TextOptions.WrapTextWidth,
                    HorizontalAlignment = options.TextOptions.HorizontalAlignment,
                    VerticalAlignment   = options.TextOptions.VerticalAlignment
                };

                IPathCollection glyphs = TextBuilder.GenerateGlyphs(text, style);

                var pathOptions = new ShapeGraphicsOptions()
                {
                    GraphicsOptions = options.GraphicsOptions
                };

                if (brush != null)
                {
                    source.Fill(pathOptions, brush, glyphs);
                }

                if (pen != null)
                {
                    source.Draw(pathOptions, pen, glyphs);
                }

                return(source);
            }
        }
            static IImageProcessingContext DrawTextOldVersion(
                IImageProcessingContext source,
                TextGraphicsOptions options,
                string text,
                Fonts.Font font,
                IBrush brush,
                IPen pen,
                PointF location)
            {
                var style = new Fonts.RendererOptions(font, options.TextOptions.DpiX, options.TextOptions.DpiY, location)
                {
                    ApplyKerning        = options.TextOptions.ApplyKerning,
                    TabWidth            = options.TextOptions.TabWidth,
                    WrappingWidth       = options.TextOptions.WrapTextWidth,
                    HorizontalAlignment = options.TextOptions.HorizontalAlignment,
                    VerticalAlignment   = options.TextOptions.VerticalAlignment
                };

                IPathCollection glyphs = TextBuilder.GenerateGlyphs(text, style);

                var pathOptions = new ShapeGraphicsOptions()
                {
                    GraphicsOptions = options.GraphicsOptions
                };

                if (brush != null)
                {
                    source.Fill(pathOptions, brush, glyphs);
                }

                if (pen != null)
                {
                    source.Draw(pathOptions, pen, glyphs);
                }

                return(source);
            }