libgdiplus icon indicating copy to clipboard operation
libgdiplus copied to clipboard

Drawing (Images, Font) issues with mono 6.8.105 and libgdiplus 6.0.4

Open g0ldi opened this issue 5 years ago • 14 comments

Steps to Reproduce

  1. Mono version 6.8.105 is installed (pkg: mono-complete)
  2. Compile this sample app source with msbuild mono_6.8_drawingissue.csproj
  3. libgdiplus version 6.0.4 is installed (pkg: libgdiplus=6.0.4-0xamarin1+debian9b1)
  4. Start the application mono_drawingissue.exe (see attached screenshots)
  5. Downgrade libgdiplus to version 5.6 (pkg: libgdiplus=5.6-0xamarin5+debian9b1)
  6. Start again the application mono_drawingissue.exe (see attached screenshots)
  7. Notice the difference between the application even it's the same appliacation.

Current Behavior

Note: Issue can be observed/reproduced with mono version 6.8.96 and 6.8.105.

Mono 6.8.105 with libgdiplus 6.0.4-0xamarin1+debian9b1

With the packages specified in the header the

  • image specified for the picturebox is drawn but not visible
  • text "Log On" is drawn but not visible
  • text of buttons (LBtn, MLBtn, MRBtn, RBtn) are not drawn using the specified font Arial, bold.
  • image and text "Log On" are redrawn and are visible when another window is moved over the form.
Screenshots
  • Application drawn when started (notice the button font): image

  • Application drawn when moving partially another screen over it: image

Mono 6.8.105 with libgdiplus 5.6-0xamarin5+debian9b1

  • image specified for the picturebox is drawn and is visible
  • text "Log On" is drawn and is visible
  • text of buttons (LBtn, MLBtn, MRBtn, RBtn) are drawn using the specified font Arial, bold.
Screenshots
  • Application drawn when started (notice the button font): image

Expected Behavior

The application draws the controls when it is loaded with mono 6.8.105 using the latest available libgdiplus (=6.0.4-0xamarin1+debian9b1) version. The application (from drawing perspective) should be identical, like with the older libgdiplus (=5.6-0xamarin5+debian9b1) version.

On which platforms did you notice this

[ ] macOS [x] Linux: Issue is observed on debian stretch 9.6 & 9.11 (arch: amd64 and armhf) [ ] Windows

Version Used:

Mono JIT compiler version 6.8.0.105 (tarball Tue Feb 4 21:19:49 UTC 2020) Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com TLS: __thread SIGSEGV: altstack Notifications: epoll Architecture: amd64 Disabled: none Misc: softdebug Interpreter: yes LLVM: yes(610) Suspend: hybrid GC: sgen (concurrent by default)

Package: libgdiplus Version: 6.0.4-0xamarin1+debian9b1 Priority: optional Section: libs Maintainer: Debian Mono Group [email protected] Installed-Size: 535 kB Depends: libc6 (>= 2.14), libcairo2 (>= 1.10.0), libexif12 (>= 0.6.21-1~), libfontconfig1 (>= 2.11), libfreetype6 (>= 2.2.1), libgif7 (>= 5.1), libglib2.0-0 (>= 2.31.8), libjpeg62-turbo (>= 1.3.1), libpng16-16 (>= 1.6.2-1), libtiff5 (>= 4.0.3), libx11-6 Homepage: http://www.mono-project.com/Libgdiplus Download-Size: 161 kB APT-Manual-Installed: yes APT-Sources: https://download.mono-project.com/repo/debian stable-stretch/main amd64 Packages Description: interface library for System.Drawing of Mono This package contains a GDI+ API compatible implementation needed by the System.Drawing library of Mono.

g0ldi avatar Feb 10 '20 13:02 g0ldi

This looks like a regression.

@filipnavara @akoeplinger any clues which change could cause that?

marek-safar avatar Feb 13 '20 17:02 marek-safar

Hi everyone, I played around with the sample and it starts breaking with version 6.0.3. 6.0.2 renders fine, but then 6.0.3 is broken.

abossard avatar Feb 19 '20 12:02 abossard

After going through commit by commit, this is the commit that introduces the broken rendering of the example: https://github.com/mono/libgdiplus/commit/398ad6de93a9b4140a209d9eae8ded9292ffc740

abossard avatar Feb 19 '20 12:02 abossard

@abossard Thanks for doing the analysis. I suspected it would be that one. However, it also fixes quite a lot of issues. The hard part is actually narrowing down the problem to specific thing that is broken.

filipnavara avatar Feb 19 '20 12:02 filipnavara

I suspect it is the same issue as https://github.com/mono/mono/issues/17493 which may be a bit easier to track down to specific code.

The libgdiplus library uses Cairo as the rendering backend. Unfortunately, the capabilities of the two libraries are different in terms of supported pixel formats for images. Historically this was handled incorrectly on many places where a conversion from PARGB format (R,G,B are premultiplied by the A value) to RGB (and/or back) was missing. This resulted in incorrect values being returned and some image transformations screwing up the output heavily when alpha value was used on pixels.

The patch introduced in https://github.com/mono/libgdiplus/commit/398ad6de93a9b4140a209d9eae8ded9292ffc740 tries to unify the approach a bit. If Cairo can handle the pixel format of an Image natively then they share the same pixel data in memory. If Cairo cannot handle it, however, then Cairo gets a converted copy of the image data and there are two parallel copies of the image data. Only the one handled in Cairo is considered valid at that point and it is the one with up-to-date data. Bugs like this one usually happen because either a) some drawing operations are not flushed correctly to the Cairo surface b) the stale non-converted copy of the image is used instead of the Cairo surface, or c) the Cairo surface is destroyed and the updated contents are not converted back into the original buffer in original pixel format.

If someone manages to reproduce the issue with pure System.Drawing or libgdiplus code I will be more than happy to try debugging it. Unfortunately stripping all the WinForms layers of code from the repro code proved to be quite time consuming.

filipnavara avatar Feb 19 '20 13:02 filipnavara

Thanks for the insights, @filipnavara. I don't really know System.Drawing or libgdiplus myself, but I'll try to dig deeper into it in the next days.

I noticed that if I reduce the image height by e.g. 20px, it starts working: Screenshot from 2020-02-19 17-20-46

abossard avatar Feb 19 '20 16:02 abossard

I started to investigate the font style issue, it appears that when using WinForms on Linux, the font style is not applied properly due to this commit https://github.com/mono/libgdiplus/commit/2f45a7d6382bce9e1cee11a7c06772e6727d99ae

If I revert this commit e.g. on master, it render the font correctly with bold. But it makes the tests fail on some platforms

abossard avatar Feb 27 '20 15:02 abossard

@abossard IIRC the reason to copy the FC font pattern was to preserve FC_FILE (and possibly FC_INDEX) from the original font.

filipnavara avatar Feb 27 '20 15:02 filipnavara

I tried to reproduce the issue on Ubunutu 18.04 running on WSL w/ VcXsrv as the X server and it rendered just fine:

image

Mono version:

filipnavara@DESKTOP-LFCAJ64:~/mo$ mono --version
Mono JIT compiler version 6.8.0.105 (tarball Tue Feb  4 21:20:20 UTC 2020)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
        TLS:           __thread
        SIGSEGV:       altstack
        Notifications: epoll
        Architecture:  amd64
        Disabled:      none
        Misc:          softdebug
        Interpreter:   yes
        LLVM:          yes(610)
        Suspend:       hybrid
        GC:            sgen (concurrent by default)

libgdiplus version:

libgdiplus=6.0.4-0xamarin1+ubuntu1804b1

filipnavara avatar Mar 31 '20 01:03 filipnavara

Should be fixed by https://github.com/mono/mono/pull/19460.

filipnavara avatar Apr 07 '20 10:04 filipnavara

Theses issues still exist on Debian (stretch) with LightDm:

Mono: 6.12 libgdiplus: 6.0.5

  1. Image Missing: Reproducible when the Image is larger than the canvas. I reproduced the error; on all mono versions.

  2. Font issue: the font Arial Bold is not displayed

engrch avatar Mar 04 '21 16:03 engrch

Mono 6.12 was branched as 2020-02 and doesn't contain the fix linked above.

filipnavara avatar Mar 04 '21 16:03 filipnavara

@filipnavara Thanks for pointing that out.

I built the latest mono from master and I can confirm that:

  1. Image Missing: Resolved
  2. Font issue: this is not resolved

Debian with LightDM Mono: Built from master libgdiplus: 6.0.5-0xamarin1+debian9b1

engrch avatar Mar 05 '21 09:03 engrch

Is there any update on resolving this issue? I’m still having it with mono 6.12 and libgdiplus 6.1. But only in Linux Mint 22. It worked fine on my previous Linux Mint 21.3 and I have no issues on my Raspberry Pi.

kd2var avatar Aug 28 '24 03:08 kd2var