Missing libskiasharp dependency when running in linux container

Hi,

I am experiencing problems when running aspoes words in a linux container on k8s. Here is a stack trace of such an exception (you can szbstitute REDACTED for any namespace, just didn’t want to share ours):

System.TypeInitializationException: The type initializer for 'Po' threw an exception.
 ---> System.TypeInitializationException: The type initializer for 'SkiaSharp.SKImageInfo' threw an exception.
 ---> System.DllNotFoundException: Unable to load shared library 'libSkiaSharp' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibSkiaSharp: cannot open shared object file: No such file or directory
   at SkiaSharp.SkiaApi.sk_colortype_get_default_8888()
   at SkiaSharp.SKImageInfo..cctor()
   --- End of inner exception stack trace ---
   at SkiaSharp.SKBitmap..ctor(Int32 width, Int32 height, Boolean isOpaque)
   at Po..cctor()
   --- End of inner exception stack trace ---
   at Po..ctor(Int32 a, Int32 b, Single c, Single d, lBb e)
   at kSa.a()
   at kSa.a(Stream a)
   at kSa.a(vt a, SizeF b, Stream c, ImageSaveOptions d, IWarningCallback e, Ci f)
   at o5a.a(Stream a, Ij b)
   at B5a.BtaVTAXa(Byte[] a, Document b, Aba c, Aba d, Ij e)
   at Gaa.a(Byte[] a, Aba b, Aba c, Ij d)
   at Aspose.Words.Drawing.ImageData.a(Byte[] a, Aba b, Aba c, Ij d)
   at Aspose.Words.DocumentBuilder.a(Byte[] a, RelativeHorizontalPosition b, Double c, RelativeVerticalPosition d, Double e, Double f, Double g, WrapType h, Boolean i)
   at *REDACTED*.ReportService.Services.ReplaceWithSvgImageEvaluator.Aspose.Words.Replacing.IReplacingCallback.Replacing(ReplacingArgs e) in /builds/development/*REDACTED*reportservice/src/*REDACTED*.ReportService/Services/ReplaceWithSvgImageEvaluator.cs:line 36
   at d8a.a(String a, Int32 b)
   at d8a.a(Node a)
   at d8a.a()
   at Aspose.Words.Range.Replace(String pattern, String replacement, FindReplaceOptions options)

Please help me with that.

Thanks
Florian

@fordi Aspose.Words for .NET Standard and .NET6 use SkiaSharp to deal with graphics, to make it work on Linux you have to add reference either to SkiaSharp.NativeAssets.Linux or to SkiaSharp.NativeAssets.Linux.NoDependencies

If you add reference to SkiaSharp.NativeAssets.Linux, you should also install libfontconfig1 in your system. SkiaSharp.NativeAssets.Linux depends on this library. You can use the following command to install it:

apt-get update && apt-get install -y libfontconfig1

If you do not have rights to install packages, or other reasons not to install libfontconfig1, you can simply use SkiaSharp.NativeAssets.Linux.NoDependencies, which does not require installation of libfontconfig1.

Hi Alexey,
thanks for your quick response. I was able to fix most of the problems I had by following your suggestion and also installing ttf-mscorefonts-installer. The resulting PDF rendered on Linux now almost matches the output generated on a Windows machine. The remaiining issue I am facing seems to be related to font substitution. If I insert a superscript negative sign (unicode character u+207b) in a Word document, it is always set to a font named Cambria Math. Converting to PDF works and the superscript negative sign is rendered correctly. However, when inserting a svg image that contains that character and has font-family set to Arial (which is the same as the rest of the document), the character is not rendered. I also cannot see any warning related to this character and a potential font substitution. Here is a sample svg that you can use to reproduce this. In warning callbacks, I see warnings on Segoe UI and Cambria Math not found and that those are substituted with DejaVu sans.

<svg xmlns="http://www.w3.org/2000/svg" width="150" height="100">
	<text x="0" y="10" style="font-family: 'Arial'">Arial ⁻</text>
	<text x="0" y="30" style="font-family: 'Segoe UI'">Segoe UI ⁻</text>
	<text x="0" y="50" style="font-family: 'Cambria Math'">Cambria Math ⁻</text>
</svg>

Is there anything I can do to render that superscript negative sign in svg correctly? Is there a fallback mechanism for non-printable characters in a given font? Is there a font that is similar to Arial, works on Linux and will render such mathematical characters correctly?

@fordi Arial font does not have the required glyph. In this case Aspose.Words performs font fallback, i.e. tries to find and use font that has the required glyphs.
On my side it use Cambria Math font: out.pdf (33.3 KB)

@alexey.noskov Thanks for your fast reply. Sorry for being unclear in my question, I can confirm that the fallback you describe works on Windows, but it does not seem to work on Linux, at least with my configuration (installed ttf-mscorefonts-installer and libertation-fonts). In essence, the fallback does not work in Linux in my case. Maybe I am missing some dependency on my linux image?
From the link you provided I understand that I would be able to provide my own fallback settings. So for such single characters not being found, would it be possible to setup a fallback setting that just then jumps in?

@fordi The fallback does not work on Linux because there are no required fonts. ttf-mscorefonts package does not include all MS fonts, it includes only basic fonts. You can try installing free Noto fonts and use Noto Fonts Fallback Settings. You can load them using FontFallbackSettings.LoadNotoFallbackSettings. Or you can customize the predefined fallback setting according to the fonts available in your environment.