Beispiel #1
0
        public void CanRenderLargeFont()
        {
            if (!TestEnvironment.IsWindows)
            {
                return;
            }

            using (var image = new Image <Rgba32>(300, 200))
            {
                string text = "TEST text foiw|\\";

                Fonts.Font font            = Fonts.SystemFonts.CreateFont("Arial", 40, Fonts.FontStyle.Regular);
                var        graphicsOptions = new GraphicsOptions {
                    Antialias = false
                };
                image.Mutate(
                    x => x.BackgroundColor(Color.White)
                    .DrawLines(
                        new DrawingOptions {
                    GraphicsOptions = graphicsOptions
                },
                        Color.Black,
                        1,
                        new PointF(0, 50),
                        new PointF(150, 50))
                    .DrawText(
                        new DrawingOptions {
                    GraphicsOptions = graphicsOptions
                },
                        text,
                        font,
                        Color.Black,
                        new PointF(50, 50)));
            }
        }
Beispiel #2
0
 public override bool OpenFileData(FileStream stream)
 {
     using (var reader = new StreamReader(stream))
     {
         MyFont = JsonConvert.DeserializeObject <Fonts.Font>(reader.ReadToEnd());
     }
     return(true);
 }
Beispiel #3
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);
            }
        }
Beispiel #4
0
        public void DrawTextCore()
        {
            using var image = new Image <Rgba32>(800, 800);
            Fonts.Font  font        = Fonts.SystemFonts.CreateFont("Arial", 12);
            TextOptions textOptions = new(font)
            {
                WrappingLength = 780,
                Origin         = new PointF(10, 10)
            };

            image.Mutate(x => x.DrawText(
                             textOptions,
                             this.TextToRender,
                             Processing.Pens.Solid(Color.HotPink, 10)));
        }
 public void DrawTextCore()
 {
     using (var image = new Image <Rgba32>(800, 800))
     {
         Fonts.Font font = Fonts.SystemFonts.CreateFont("Arial", 12);
         image.Mutate(x => x.DrawText(
                          new TextGraphicsOptions {
             Antialias = true, WrapTextWidth = 780
         },
                          this.TextToRender,
                          font,
                          Processing.Brushes.Solid(Color.HotPink),
                          new PointF(10, 10)));
     }
 }
Beispiel #6
0
        public void Setup()
        {
            this.image      = new Image <Rgba32>(Width, Height);
            this.sdBitmap   = new SDBitmap(Width, Height);
            this.sdGraphics = Graphics.FromImage(this.sdBitmap);
            this.sdGraphics.InterpolationMode = InterpolationMode.Default;
            this.sdGraphics.SmoothingMode     = SmoothingMode.AntiAlias;
            this.sdGraphics.InterpolationMode = InterpolationMode.Default;
            this.sdGraphics.SmoothingMode     = SmoothingMode.AntiAlias;
            this.skBitmap = new SKBitmap(Width, Height);
            this.skCanvas = new SKCanvas(this.skBitmap);

            this.sdFont     = new SDFont("Arial", 12, GraphicsUnit.Point);
            this.font       = Fonts.SystemFonts.CreateFont("Arial", 12);
            this.skTypeface = SKTypeface.FromFamilyName("Arial");
        }
 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,
                 null,
                 Processing.Pens.Solid(Color.HotPink, 10),
                 new PointF(10, 10)));
     }
Beispiel #8
0
        public void DrawTextCoreOld()
        {
            using (var image = new Image <Rgba32>(800, 800))
            {
                Fonts.Font  font        = Fonts.SystemFonts.CreateFont("Arial", 12);
                TextOptions textOptions = new(font)
                {
                    WrappingLength = 780,
                    Origin         = new PointF(10, 10)
                };

                image.Mutate(
                    x => DrawTextOldVersion(
                        x,
                        new DrawingOptions {
                    GraphicsOptions = { Antialias = true }
                },
                        textOptions,
                        this.TextToRender,
                        null,
                        Processing.Pens.Solid(Color.HotPink, 10)));
            }
            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);
            }