mono / SkiaSharp

SkiaSharp is a cross-platform 2D graphics API for .NET platforms based on Google's Skia Graphics Library. It provides a comprehensive 2D API that can be used across mobile, server and desktop models to render images.
MIT License
4.38k stars 535 forks source link

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

Open AlexNosk opened 4 years ago

AlexNosk commented 4 years ago

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);
Gillibald commented 4 years ago

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?

AlexNosk commented 4 years ago

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

Gillibald commented 4 years ago

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.

mattleibow commented 4 years ago

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").

Gillibald commented 4 years ago

Might GDI work?

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

RamarajMarimuthu commented 4 years ago

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.

mattleibow commented 4 years ago

@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 commented 4 years ago

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

Gillibald commented 4 years ago

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

mattleibow commented 4 years ago

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...

Gillibald commented 4 years ago

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 😀

RamarajMarimuthu commented 4 years ago

Hi Guys,

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

Thanks in advance.

Thanks, Ramaraj Marimuthu.

Gillibald commented 4 years ago

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

mattleibow commented 4 years ago

@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 commented 4 years ago

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

AlexNosk commented 4 years ago

@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.

MadhanKumarasamy commented 4 years ago

@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.

mattleibow commented 4 years ago

@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?

milivojm commented 2 years ago

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.

Ramaraj-Marimuthu commented 1 year ago

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.

SevcikMichal commented 10 months ago

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.

AkashArul26 commented 9 months ago

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 commented 7 months ago

Hi @mattleibow & @Gillibald ,

Any update on this?

Regards, Akash.

mudderklirren commented 6 months ago

We also needs this, please get it fixed.

Gillibald commented 6 months ago

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