empira / PDFsharp

PDFsharp and MigraDoc Foundation for .NET 6 and .NET Framework
https://docs.pdfsharp.net/
Other
492 stars 114 forks source link

NullReferenceException with unicode character #69

Closed julienrffr closed 3 months ago

julienrffr commented 9 months ago

In 6.1.0-preview-1 (and in 6.0.0 as well), When adding character '🦀' (https://www.compart.com/en/unicode/U+1F980) in a text string, I've got a NullReferenceException: image Because FontFace.cmap.cmap12 is null. While FontFace.cmap.cmap4 has a value.

This happens in method CharCodeToGlyphIndex(char highSurrogate, char lowSurrogate) of file OpenTypeDescriptor.cs https://github.com/empira/PDFsharp/blob/b28bc3265e0a15302c04b7b91da0d915a591e167/src/foundation/src/PDFsharp/src/PdfSharp/Fonts.OpenType/OpenTypeDescriptor.cs#L313

To reproduce, juste change this line (https://github.com/empira/PDFsharp/blob/b28bc3265e0a15302c04b7b91da0d915a591e167/src/samples/src/PDFsharp/src/HelloWorld/Program.cs#L58) in order to insert the character: gfx.DrawString("Hello, PDF🦀sharp!", font, XBrushes.Black, new XRect(0, 0, page.Width, page.Height), XStringFormats.Center);

I'm not sure if it is supposed to be supported, but I guess if this is not officialy supported, at least it should not throw an exception and just remove/not display the faulty character.

julienrffr commented 3 months ago

The null ref error has been fixed in 6.1.0. Now it does not fail anymore but it displays the emoji as an unknown char: image

Any idea if supporting those emoji are something feasible?

TH-Soft commented 3 months ago

Are you using a font that includes emoji, like e.g. "Segoe Emoji"? The char is not included in fonts like Arial or Segoe UI and the placeholder square is a feature, not a bug. Coloured emojis should come with 6.2.0, but they should already work in monochrome.

julienrffr commented 3 months ago

Indeed we are using an OpenSans font which doe snto include this emoji. Thanks for your feedback. Clsoing the issue as the null ref error has been fixed in 6.1.0.