SixLabors / Fonts

:black_nib: Font loading and layout library.
https://sixlabors.com/products/fonts
Other
308 stars 71 forks source link

Nuget package for SixLabors.Fonts 1.0.0 fails to Mutate the image. #350

Closed FlaviusHouk closed 1 year ago

FlaviusHouk commented 1 year ago

Prerequisites

Description

Using the most recent version (1.0.0) of the SixLabors.Fonts from NuGet.org with the current available version of SixLabors.ImageSharp.Drawing (1.0.0-beta15) fails to mutate the image and draw simple text (numbers only) with system font. It throws exception like this

Exception has occurred: CLR/System.TypeLoadException
An unhandled exception of type 'System.TypeLoadException' occurred in SixLabors.ImageSharp.dll: 'Method 'BeginGlyph' in type 'CachingGlyphRenderer' from assembly 'SixLabors.ImageSharp.Drawing, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d998eea7b14cab13' does not have an implementation.'
   at SixLabors.ImageSharp.Drawing.Processing.Processors.Text.DrawTextProcessor`1.BeforeImageApply()
   at SixLabors.ImageSharp.Processing.Processors.ImageProcessor`1.SixLabors.ImageSharp.Processing.Processors.IImageProcessor<TPixel>.Execute()
   at SixLabors.ImageSharp.Processing.DefaultImageProcessorContext`1.ApplyProcessor(IImageProcessor processor, Rectangle rectangle)
   at SixLabors.ImageSharp.Processing.DefaultImageProcessorContext`1.ApplyProcessor(IImageProcessor processor)
   at SixLabors.ImageSharp.Drawing.Processing.DrawTextExtensions.DrawText(IImageProcessingContext source, String text, Font font, Color color, PointF location)

Steps to Reproduce

  1. Create new .Net project.
  2. Add required packages (currently it installs SixLabors.Fonts 1.0.0 and SixLabors.ImageSharp.Drawing 1.0.0-beta15)
    dotnet add package SixLabors.Fonts
    dotnet add package SixLabors.ImageSharp.Drawing --prerelease
  3. Write a sample code like this
    FontCollection fonts = new();
    fonts.AddSystemFonts();
    if(!fonts.TryGet("Calibri", out FontFamily fontFamily))
    {
     throw new Exception("Font not found.");
    }
    Font f = fontFamily.CreateFont(12);
    using Image image = Image.Load(fileName); //tested with .png image
    image.Mutate(i => i.DrawText("1", f, Color.Grey, new PointF(10, 10))); //Exception raised here
    image.SaveAsPng(fileName);
  4. Run the application.

System Configuration

Windows 10 22H2 x64. .Net 6.0.300.

Additional information

Previous version of SixLabors.Fonts (1.0.0-beta19) works fine and above code does what it is supposed to do.

JimBobSquarePants commented 1 year ago

ImageSharp.Drawing v1 has been released