SixLabors / Fonts

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

Fonts 1.0.0-beta16 with ImageSharp 2.1.3 crashes with NullReferenceException when measuring text #292

Closed myblindy closed 2 years ago

myblindy commented 2 years ago

Prerequisites

Description

As in the title, upgrading to ImageSharp 2.* (and Fonts to 1.0.0-beta16 to match) now crashes during measuring.

Steps to Reproduce

using SixLabors.Fonts;

var fontCollection = new FontCollection();
var regularFontFamily = fontCollection.Add(@"Font\OpenSans-Regular.ttf");
var font = regularFontFamily.CreateFont(25);

var fontRect = TextMeasurer.Measure("V", new(font));

Full exception:

System.NullReferenceException
  HResult=0x80004003
  Message=Object reference not set to an instance of an object.
  Source=SixLabors.Fonts
  StackTrace:
   at SixLabors.Fonts.Tables.AdvancedTypographic.GPosTable.GetFeatureLookups(Tag& stageFeature, ScriptClass script) in /_/src/SixLabors.Fonts/Tables/AdvancedTypographic/GPosTable.cs:line 210

image

Similar code works fine with ImageSharp 1.* and the corresponding Fonts (with a few method name changes, of course). You can get the full repository at https://github.com/myblindy/font_test.

System Configuration

myblindy commented 2 years ago

I just tried Fonts 1.0.0-beta17 with same results.

JimBobSquarePants commented 2 years ago

Please see #276 and #266. This is a duplicate. You’ll need the latest MyGet release: 1.0.0-beta17.8

myblindy commented 2 years ago

For what it's worth, it actually worked with the woff2 version of the font, so I'm using that for now.

JimBobSquarePants commented 2 years ago

Yep that's because the WOFF font will not include the redundant features. I've released 1.0.0-beta18 on NuGet now which contains the fix.