Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial support for GDI+ #1679

Merged
merged 3 commits into from
Aug 15, 2023
Merged

Conversation

riverar
Copy link
Collaborator

@riverar riverar commented Aug 15, 2023

Fixes #1287

@riverar
Copy link
Collaborator Author

riverar commented Aug 15, 2023

Quick Rust sample

use windows::{
    core::w,
    Win32::Graphics::GdiPlus::{
        self, GdipCreateFontFamilyFromName, GdipNewInstalledFontCollection, GdiplusShutdown,
        GdiplusStartup, GdiplusStartupInput, GpFontCollection, GpFontFamily,
    },
};

fn main() -> windows::core::Result<()> {
    unsafe {
        let mut token = usize::default();
        let input = GdiplusStartupInput {
            GdiplusVersion: 1,
            ..Default::default()
        };

        assert_eq!(
            GdiplusStartup(&mut token, &input, std::ptr::null_mut()),
            GdiPlus::Ok
        );

        let mut collection: *mut GpFontCollection = std::ptr::null_mut();
        assert_eq!(
            GdipNewInstalledFontCollection(&mut collection as *mut *mut _),
            GdiPlus::Ok
        );

        let mut family: *mut GpFontFamily = std::ptr::null_mut();
        assert_eq!(
            GdipCreateFontFamilyFromName(w!("Segoe UI"), collection, &mut family as *mut *mut _),
            GdiPlus::Ok
        );
        assert_eq!(
            GdipCreateFontFamilyFromName(
                w!("Invalid Font Family"),
                collection,
                &mut family as *mut *mut _
            ),
            GdiPlus::FontFamilyNotFound
        );

        GdiplusShutdown(token);
    }

    Ok(())
}

@riverar
Copy link
Collaborator Author

riverar commented Aug 15, 2023

@elachlan Which Gdi+ APIs are you using? I'd like to make sure we have coverage here.

@elachlan
Copy link
Contributor

elachlan commented Aug 15, 2023

@JeremyKuhne will know better than myself. The only functions we are implementing ourselves at the moment are the ones from the linked issue.

They are implemented here:
https://github.com/dotnet/winforms/tree/c76063c493525c2b2f20f0dc67e6913e219db2d5/src/System.Windows.Forms.Primitives/src/Interop/GdiPlus

@riverar riverar marked this pull request as ready for review August 15, 2023 16:39
@mikebattista mikebattista merged commit 0c63f94 into microsoft:main Aug 15, 2023
1 check passed
@mikebattista
Copy link
Contributor

Awesome. Thanks!

@riverar
Copy link
Collaborator Author

riverar commented Aug 15, 2023

@mikebattista You okay with the separate Windows.Win32.Graphics.GdiPlus namespace? I figured folks that want to use a few standard GDI APIs didn't want to shoulder the burden of all the GDI+ goop.

@riverar riverar deleted the rafael/gdiplus branch August 15, 2023 16:48
@mikebattista
Copy link
Contributor

Yes that seemed reasonable.

@JeremyKuhne
Copy link
Member

Which Gdi+ APIs are you using? I'd like to make sure we have coverage here.

@riverar Most of them. WinForms owns System.Drawing which is mostly a wrap of GDI+. You can see some of them here:

https://github.com/dotnet/winforms/blob/main/src/System.Drawing.Common/src/System/Drawing/GdiplusNative.DllImport.cs

@riverar
Copy link
Collaborator Author

riverar commented Aug 15, 2023

Thanks @JeremyKuhne @elachlan will take a look. Think we got them all covered.

@mikebattista Looks like build validation didn't run in this PR and some tests failed that need fixes. Will clean that up today and submit another PR.

@mikebattista
Copy link
Contributor

@riverar could you implement the NativeTypedefs in autotypes.json? Or was there a reason you manually defined them?

I believe definitions like below should amount to the same result, and I'd prefer to keep all NativeTypedefs defined in autotypes.json if we can.

  {
    "Namespace": "Windows.Win32.Graphics.GdiPlus",
    "Name": "PathData",
    "ValueType": "IntPtr",
    "NativeTypedef": true
  }

@riverar
Copy link
Collaborator Author

riverar commented Aug 15, 2023

@mikebattista Can do!

@riverar
Copy link
Collaborator Author

riverar commented Aug 16, 2023

@mikebattista Given the following:

Duplicate types detected:
 POINTF(X,Y)
   Windows.Win32.Graphics.GdiPlus
   Windows.Win32.System.Ole
 POINT(X,Y)
   Windows.Win32.Foundation
   Windows.Win32.Graphics.GdiPlus
 DEBUGEVENTPROC(INVOKE)
   Windows.Win32.Graphics.GdiPlus
   Windows.Win32.System.VirtualDosMachines

I can move them to common areas but how do you then map to them via each partition? Or do we exclude them from both?

Information on suggestedRemappingsAllowList and any tips on resolving those would be great too.

@mikebattista
Copy link
Contributor

What do you mean by map to them via each partition?

@riverar
Copy link
Collaborator Author

riverar commented Aug 16, 2023

Ole and Gdiplus both need a PointF. Is the workflow: Create a common PointF, exclude PointF from each partition?

@mikebattista
Copy link
Contributor

Is just remapping in requiredNamespacesForNames not enough?

riverar added a commit to riverar/win32metadata that referenced this pull request Aug 18, 2023
mikebattista pushed a commit that referenced this pull request Aug 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Gdiplus missing some functions/enums GdipCreateSolidFill, GdipCloneBrush, GpStatus
4 participants