SkiaSharp icon indicating copy to clipboard operation
SkiaSharp copied to clipboard

[BUG] SKTypeface cannot be created in a Windows Nano Server Docker container

Open AlexNosk opened this issue 5 years ago • 25 comments

Description

SkTypeface cannot be created in Windows Docker container. It simply returns null. I use SkiaSharp 1.68.1.1 version and SkiaSharp.NativeAssets.NanoServer 1.68.1.1 version. .csproj file is modified as required

I tried creating SkTypeface from file, stream, family name with the same result - SkTypeface is null. Also SkTypeface.CreateDefault() returns SkTypeface that is not null, but FamilyName is empty.

Code

        SKTypeface typeface = SKTypeface.FromFamilyName("Lucida Console", SKFontStyleWeight.Normal, SKFontStyleWidth.Normal, SKFontStyleSlant.Upright);
        Console.WriteLine("SkSKTypeface created from family name - {0}", typeface != null);

        const string fontFileName = @"C:\Windows\Fonts\lucon.ttf";
        typeface = SKTypeface.FromFile(fontFileName);
        Console.WriteLine("SkSKTypeface created from file name - {0}", typeface != null);

        using (FileStream fs = File.OpenRead(fontFileName))
        {
            typeface = SKTypeface.FromStream(fs);
            Console.WriteLine("SkSKTypeface created from stream - {0}", typeface != null);
        }

        typeface = SKTypeface.CreateDefault();
        Console.WriteLine(typeface.FamilyName);

AlexNosk avatar Jan 16 '20 12:01 AlexNosk

What yields https://docs.microsoft.com/en-us/dotnet/api/skiasharp.skfontmanager.fontfamilies?view=skiasharp-1.68.1#SkiaSharp_SKFontManager_FontFamilies for you? Does it contain any font family?

Gillibald avatar Jan 16 '20 12:01 Gillibald

@Gillibald
SKFontManager.Default.FontFamilyCount returns zero and SKFontManager.Default.FontFamilies is empty.

AlexNosk avatar Jan 16 '20 13:01 AlexNosk

I guess the nano server build has no font manager implementation https://github.com/google/skia/blob/master/src/core/SkFontMgr.cpp

https://github.com/google/skia/blob/master/src/core/SkFontMgr.cpp#L80 for example returns nullptr if not overridden.

Gillibald avatar Jan 16 '20 13:01 Gillibald

The facts. The Nano Server dll is actually working. It really is just the same as the Win32 dll, except that there is a single method that is a no-op for XPS type subsetting. That is the only difference. You can actually use the Nano Server dll on full Windows to test.

So, why is it not working? Well, guess what - the required dwrite.dll for DirectWrite is missing on Nano Server. This file C:\Windows\System32\DWrite.dll

I did not expect that. Not sure why that is not in the docker images. I see this list of APIs does not have it there either: https://docs.microsoft.com/en-us/previous-versions/windows/desktop/legacy/mt588480(v=vs.85)

I am not sure how we are supposed to draw text on Nano Server... I thought DirectWrite was the way forward. I will have to check to see what is going on.

This is the line that is failing: https://github.com/mono/skia/blob/xamarin-mobile-bindings/src/utils/win/SkDWrite.cpp#L31

GetProcAddress(LoadLibraryW(L"dwrite.dll"), "DWriteCreateFactory"));

It is because this returns null LoadLibraryW(L"dwrite.dll").

mattleibow avatar Jan 18 '20 23:01 mattleibow

Might GDI work?

This would involve a custom font manager implementation probably the directory font manager.

Gillibald avatar Jan 19 '20 00:01 Gillibald

Hi Guys,

We are also facing the same issue while creating a SkTypeface in Windows Nano Server with Docker. Could you please help me to resolve this.

FYI - “SKTypeface.Default” static property return a SkTypeface object with empty font name in Nano server, which is return "Segoe UI" font in windows.

Thanks in advance.

Thanks, Ramaraj Marimuthu.

RamarajMarimuthu avatar Jan 22 '20 05:01 RamarajMarimuthu

@Gillibald sooooooo. I tried the GDI font manager, and that works locally. But, not on Nano Server. The entire usp10.dll is missing... I feel fear!

mattleibow avatar Jan 22 '20 23:01 mattleibow

I will need to investigate this more as I have nothing at this point. What a bummer.

mattleibow avatar Jan 23 '20 00:01 mattleibow

Probably time to invite Freetype to the party. Not sure how hard that would be to build for Windows. Freetype + DirectoryFontManager

Gillibald avatar Jan 23 '20 04:01 Gillibald

Yeah. Same results on Twitter and here: https://groups.google.com/forum/#!topic/skia-discuss/cfgRsNWcm6Q

The code is there and is used on linux/android, so hopefully only a small bit of work...

mattleibow avatar Jan 23 '20 17:01 mattleibow

I am still dreaming about a customizable font rendering backend for SkiaSharp so users can supply managed implementations for the font manager etc. That way we could use Freetype bindings etc. But that is just some dream 😀

Gillibald avatar Jan 23 '20 18:01 Gillibald

Hi Guys,

Any update on this. We are eagerly waiting for the solution.

Thanks in advance.

Thanks, Ramaraj Marimuthu.

RamarajMarimuthu avatar Feb 12 '20 07:02 RamarajMarimuthu

We can't build Skia in combination with Freetype for the m68 release of Skia. The next major release of SkiaSharp will support this. We just need an extra build target for windows-externals-freetype or something. This will support rendering with Freetype but you have to use a dictionary font manager. @mattleibow https://github.com/google/skia/blob/master/BUILD.gn#L274

Gillibald avatar Feb 12 '20 07:02 Gillibald

@RamarajMarimuthu unfortunately no good feedback. But, if you are not using any windows specific features, you might try the Linux containers.

The plus side to Linux is that they are smaller and can run side by side with the windows containers.

Not the greatest answer, but we are still working on this.

mattleibow avatar Feb 12 '20 07:02 mattleibow

Just adding a note that Windows Server Core can still be used like this example

mattleibow avatar Feb 15 '20 11:02 mattleibow

@mattleibow Rechecked this with the latest stable SkiaSharp version and the problem is still there. By the way example you provided in the latest answer does not work. The created image does not contain text.

AlexNosk avatar Jul 28 '20 10:07 AlexNosk

@mattleibow If we can create the SKTypeface in Windows Docker Container and kindly mentioned the SkiaSharp version. So, that I can use the correct SkiaSharp version in my project.

MadhanKumarasamy avatar Aug 07 '20 07:08 MadhanKumarasamy

@AlexNosk @MadhanKumarasamy The issue here is that Windows Nano Server does not support the text drawing mechanisms required by SkiaSharp. I haven't yet gotten to trying out a build with FreeType, so for now the only option is to either use a Linux container or use Windows Server Core.

@Gillibald did you ever get to try out a build with FreeType?

mattleibow avatar Aug 07 '20 12:08 mattleibow

Hi,

SixLabor.Fonts with fonts packed in Docker container built on Nano Server works. We have to measure rendered text length for some internal purpose. Give it a try -> https://docs.sixlabors.com/articles/fonts/gettingstarted.html#expanded-example

We use aspnet:5.0.13-nanoserver-1809 as base image. Do not to forget to pack font(s) with the application to docker image.

milivojm avatar Jan 27 '22 14:01 milivojm

Hi @mattleibow & @Gillibald,

Any update in this? Still we are waiting to use SKTypeface (SkiaSharp) in Windows Nano Server and Docker Windows Container.

Do we have any plan to provide this support in SkiaSharp?

Thanks in advance.

Ramaraj-Marimuthu avatar Nov 21 '22 05:11 Ramaraj-Marimuthu

In case anyone stumble upon this..

It is possible to copy the DWrite.dll to the final build of windows nano server container and then even the text rendering is working.

I am not sure how robust/safe this solution is but at least for simple text rendering it works.

SevcikMichal avatar Nov 09 '23 16:11 SevcikMichal

Hi @mattleibow & @Gillibald ,

Any update on this? Still SKTypeFace (SkiaSharp) that we created using a stream is null and the default SKTypeFace is empty in Windows Container.

Any solution for this?

Regards, Akash.

AkashArul26 avatar Dec 08 '23 06:12 AkashArul26

Hi @mattleibow & @Gillibald ,

Any update on this?

Regards, Akash.

AkashArul26 avatar Jan 23 '24 06:01 AkashArul26

We also needs this, please get it fixed.

mudderklirren avatar Mar 01 '24 11:03 mudderklirren

There is nothing to fix here. Limitation of the platform.

Gillibald avatar Mar 01 '24 12:03 Gillibald