summaryrefslogtreecommitdiff
path: root/demos
diff options
context:
space:
mode:
authorMichael Vrhel <michael.vrhel@artifex.com>2021-06-28 13:26:18 -0700
committerMichael Vrhel <michael.vrhel@artifex.com>2021-06-28 13:33:47 -0700
commitf41ac3c55c85ff550a78de2a2891499ad86f115c (patch)
tree3641094b8a1d408b33e16333edb0a8635448c7db /demos
parent70d34e6e254ad9698f65b8d1ce59363f46c91dd0 (diff)
downloadghostpdl-f41ac3c55c85ff550a78de2a2891499ad86f115c.tar.gz
Add DisplayDeviceOpen to C# mono demo
Diffstat (limited to 'demos')
-rw-r--r--demos/csharp/api/ghostmono.cs74
1 files changed, 70 insertions, 4 deletions
diff --git a/demos/csharp/api/ghostmono.cs b/demos/csharp/api/ghostmono.cs
index 4247c8894..80723e0cc 100644
--- a/demos/csharp/api/ghostmono.cs
+++ b/demos/csharp/api/ghostmono.cs
@@ -280,15 +280,15 @@ namespace GhostMono
IntPtr data, gsParamState_t state);
internal event PageRendered PageRenderedCallBack;
- /* From my understanding you cannot pin delegates. These need to be declared
+ /* From my understanding you cannot pin delegates. These need to be declared
* as members to keep a reference to the delegates and avoid their possible GC.
* since the C# GC has no idea that GS has a reference to these items. For some
* reason the Mono compiler throws a CS0414 warning about these not being assigned
* even though they are */
#pragma warning disable 0414
- readonly gs_stdio_handler raise_stdin;
- readonly gs_stdio_handler raise_stdout;
- readonly gs_stdio_handler raise_stderr;
+ GSAPI.gs_stdio_handler raise_stdin;
+ GSAPI.gs_stdio_handler raise_stdout;
+ GSAPI.gs_stdio_handler raise_stderr;
#pragma warning restore 0414
/* Ghostscript display callback struct */
@@ -1094,6 +1094,72 @@ namespace GhostMono
return RunGhostscriptAsync(gsparams);
}
+ /* Set up the display device ahead of time */
+ public gsParamState_t DisplayDeviceOpen()
+ {
+ int code;
+ gsParamState_t gsparams = new gsParamState_t();
+ gsparams.result = GS_Result_t.gsOK;
+
+ if (dispInstance != IntPtr.Zero)
+ return gsparams;
+
+ try
+ {
+ code = GSAPI.gsapi_new_instance(out dispInstance, IntPtr.Zero);
+ if (code < 0)
+ {
+ throw new GhostscriptException("DisplayDeviceOpen: gsapi_new_instance error");
+ }
+
+ code = GSAPI.gsapi_set_stdio(dispInstance, raise_stdin, raise_stdout, raise_stderr);
+ if (code < 0)
+ {
+ throw new GhostscriptException("DisplayDeviceOpen: gsapi_set_stdio error");
+ }
+
+ code = GSAPI.gsapi_set_arg_encoding(dispInstance, (int)gsEncoding.GS_ARG_ENCODING_UTF8);
+ if (code < 0)
+ {
+ throw new GhostscriptException("DisplayDeviceOpen: gsapi_set_arg_encoding error");
+ }
+
+ code = GSAPI.gsapi_set_display_callback(dispInstance, ptr_display_struct);
+ if (code < 0)
+ {
+ throw new GhostscriptException("DisplayDeviceOpen: gsapi_set_display_callback error");
+ }
+ }
+
+ catch (DllNotFoundException except)
+ {
+ DLLProblemCallBack("Exception: " + except.Message);
+ gsparams.result = GS_Result_t.gsFAILED;
+ }
+ catch (BadImageFormatException except)
+ {
+ DLLProblemCallBack("Exception: " + except.Message);
+ gsparams.result = GS_Result_t.gsFAILED;
+ }
+ catch (GhostscriptException except)
+ {
+ DLLProblemCallBack("Exception: " + except.Message);
+ gsparams.result = GS_Result_t.gsFAILED;
+ if (dispInstance != IntPtr.Zero)
+ GSAPI.gsapi_delete_instance(dispInstance);
+ dispInstance = IntPtr.Zero;
+ }
+ catch (Exception except)
+ {
+ DLLProblemCallBack("Exception: " + except.Message);
+ gsparams.result = GS_Result_t.gsFAILED;
+ if (dispInstance != IntPtr.Zero)
+ GSAPI.gsapi_delete_instance(dispInstance);
+ dispInstance = IntPtr.Zero;
+ }
+ return gsparams;
+ }
+
/* Close the display device and delete the instance */
public gsParamState_t DisplayDeviceClose()
{