SixLabors / Fonts

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

Woff font loading broken in latest beta - Could not read compressed data! #296

Closed mj2015 closed 2 years ago

mj2015 commented 2 years ago

Prerequisites

Description

I have code that loads WOFF fonts from files on disk, then renders them to a bitmap. This worked fine in version 1. I updated to the latest Nuget betas, and now I get an error when calling TextMeasurer.Measure with a reference to the font. The error is Could not read compressed data! Expected bytes: 35776, bytes read: 14988 which implies to me that the font loading has failed. Full stack is:

at SixLabors.Fonts.Tables.Woff.WoffTableHeader.CreateReader(Stream stream) at SixLabors.Fonts.FontReader.GetReaderAtTablePosition(String tableName) at SixLabors.Fonts.Tables.TrueType.Glyphs.GlyphTable.Load(FontReader reader) at SixLabors.Fonts.Tables.TableLoader.Load[TTable](FontReader reader) at SixLabors.Fonts.FontReader.TryGetTable[TTableType]() at SixLabors.Fonts.FontReader.GetTable[TTableType]() at SixLabors.Fonts.StreamFontMetrics.LoadTrueTypeFont(FontReader reader) at SixLabors.Fonts.StreamFontMetrics.LoadFont(String path, Int64 offset) at System.Lazy1.ViaFactory(LazyThreadSafetyMode mode) at System.Lazy1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor) at System.Lazy1.CreateValue() at SixLabors.Fonts.FileFontMetrics.TryGetGlyphId(CodePoint codePoint, Nullable1 nextCodePoint, UInt16& glyphId, Boolean& skipNextCodePoint) at SixLabors.Fonts.TextLayout.DoFontRun(ReadOnlySpan1 text, Int32 start, IReadOnlyList1 textRuns, Int32& textRunIndex, Int32& codePointIndex, Int32& bidiRunIndex, Boolean isFallbackRun, Font font, BidiRun[] bidiRuns, Dictionary2 bidiMap, GlyphSubstitutionCollection substitutions, GlyphPositioningCollection positionings) at SixLabors.Fonts.TextLayout.ProcessText(ReadOnlySpan1 text, TextOptions options) at SixLabors.Fonts.TextMeasurer.Measure(String text, TextOptions options) at MultiRender.RenderGraphic.RenderSplits(List1 items, String outputFile) in C:\src\bvcs-obs-controller\RenderText\MultiRender\RenderGraphic.cs:line 105`

Steps to Reproduce

This probably depends on a specific woff font file, I can't upload for general access, but can supply to someone working on this. The code is quite simple so nothing special, but could supply that too if needed.

System Configuration

mj2015 commented 2 years ago

I've put together a simple sample - will remove once sorted. Open the VS project, Start it, and it will stop at a breakpoint where it is about to call TextMeasurer.Measure - everything looks fine to me. Then F10 and it will fail.

Download sample project

JimBobSquarePants commented 2 years ago

Thanks for the info and sample.

Do you happen to know what Fonts version you had that worked previously and were you running it with .NET 6? There were changes with stream reading in .NET 6 that might have affected our ability to read zlib streams so it would help to narrow things down.

mj2015 commented 2 years ago

I still have the old project, which was in .Net 5. SixLabors.Fonts 1.0.0-beta15 SixLabors.ImageSharp 1.0.3 SixLabors.ImageSHarp.Drawing 1.0.0-beta13

I should say though that the library with my code that was .Net5 is used in a .Net 6 container without issue.

brianpopow commented 2 years ago

That's very likely the same issue as #1707 we had with ImageSharp. It's strange though that it does not happen in the container. Are you sure the container version of .Net matches exactly the host version.

I would like to double check with the font file. ~@mj2015 can you send me the file to~ (edit: removed email)

mj2015 commented 2 years ago

@brianpopow The font is in the sample project - fully self contained as the code loads it from the assembly-relative directory.

The "old" version works fine built with .Net5 and then linked into the code which runs on Windows and Linux. The new one I've only tried on Windows as it doesn't work...

brianpopow commented 2 years ago

@mj2015 I see, thanks. I can reproduce it.

brianpopow commented 2 years ago

Ok there is now a PR to fix this #297.

@mj2015 I just wanted to double check: I cannot use the font file provided in a unit test, correct?

mj2015 commented 2 years ago

Sorry, the font is not mine to give out. There may be an internet version out there - not sure if this was one supplied by a client or from the internet!

brianpopow commented 2 years ago

Closing via #297