Skip to content

Commit

Permalink
starting PrintCore Xcode15
Browse files Browse the repository at this point in the history
  • Loading branch information
tj_devel709 committed Oct 18, 2023
1 parent c661ef5 commit b753413
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/BindingHelpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#nullable enable

namespace BindingHelpers
{
internal static class BindingHelpers {
public static T? GetPtrToStruct<T> (IntPtr intPtr) where T : struct
{
if (intPtr == IntPtr.Zero)
return null;
return Marshal.PtrToStructure<T> (intPtr);
}

public static void SetPtrToStruct<T> (object? value, Action<IntPtr> setAction) where T : struct
{
if (value.HasValue) {
var size_of_scale_transform = Marshal.SizeOf<T> ();
IntPtr ptr = Marshal.AllocHGlobal (size_of_scale_transform);
try {
Marshal.StructureToPtr<T> (value.Value, ptr, false);
setAction (ptr);
} finally {
Marshal.FreeHGlobal (ptr);
}
} else {
setAction (IntPtr.Zero);
}
}
}
}
81 changes: 81 additions & 0 deletions src/PrintCore/PDEPlugInCallbackProtocol.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#nullable enable

#if MONOMAC

using System;
using System.Runtime.InteropServices;
using Foundation;
using ObjCRuntime;

namespace PrintCore {

public partial class PDEPlugInCallbackProtocol {

// public virtual MPSScaleTransform? ScaleTransform {
// get {
// var ptr = _GetScaleTransform ();
// if (ptr == IntPtr.Zero)
// return null;
// return Marshal.PtrToStructure<MPSScaleTransform> (ptr);
// }
// set {
// if (value.HasValue) {
// IntPtr ptr = Marshal.AllocHGlobal (size_of_scale_transform);
// try {
// Marshal.StructureToPtr<MPSScaleTransform> (value.Value, ptr, false);
// _SetScaleTransform (ptr);
// } finally {
// Marshal.FreeHGlobal (ptr);
// }
// } else {
// _SetScaleTransform (IntPtr.Zero);
// }
// }
// }

public PMPrintSession? PrintSession {
get => GetPtrToStruct<PMPrintSession> (_GetPrintSession ());
}

public PMPrintSession? PrintSession {
get => GetPtrToStruct<PMPrintSession> (_GetPrintSettings ());
}

public PMPageFormat? PageFormat {
get => GetPtrToStruct<PMPageFormat> (_GetPageFormat ());
}

public PMPrinter? PMPrinter {
get => GetPtrToStruct<PMPrinter> (_GetPMPrinter ());
}

public ppd_file_s? PpdFile {
get => GetPtrToStruct<ppd_file_s> (_GetPpdFile ());
}

internal T? GetPtrToStruct<T> (IntPtr intPtr) where T : struct
{
if (intPtr == IntPtr.Zero)
return null;
return Marshal.PtrToStructure<T> (intPtr);
}

internal void SetPtrToStruct<T> (object? value, Action<IntPtr> setAction) where T : struct
{
if (value.HasValue) {
var size_of_scale_transform = Marshal.SizeOf<T> ();
IntPtr ptr = Marshal.AllocHGlobal (size_of_scale_transform);
try {
Marshal.StructureToPtr<T> (value.Value, ptr, false);
setAction (ptr);
} finally {
Marshal.FreeHGlobal (ptr);
}
} else {
setAction (IntPtr.Zero);
}
}
}
}

#endif

0 comments on commit b753413

Please sign in to comment.