summaryrefslogtreecommitdiff
path: root/demos/csharp
diff options
context:
space:
mode:
authorMichael Vrhel <michael.vrhel@artifex.com>2020-07-09 22:08:08 -0700
committerMichael Vrhel <michael.vrhel@artifex.com>2020-07-09 22:10:58 -0700
commit279f4835e1ab58653665e9024aaf58032c0591d7 (patch)
tree515684e6e98aa2d086a60840ae2525db5516511d /demos/csharp
parent2260ba90c0e70f38f2fef96baf8b1b972eef2940 (diff)
downloadghostpdl-279f4835e1ab58653665e9024aaf58032c0591d7.tar.gz
Linux Demo Viewer: Pages now rendering.
AA working. Need to add zoom, page navigation, track down a few crashing issues.
Diffstat (limited to 'demos/csharp')
-rw-r--r--demos/csharp/api/ghostnet.cs93
-rw-r--r--demos/csharp/linux/gtk_viewer/gtk-gui/gtk_viewer.src.gsOutput.cs10
-rw-r--r--demos/csharp/linux/gtk_viewer/gtk_viewer.csproj1
-rw-r--r--demos/csharp/linux/gtk_viewer/src/DocPage.cs17
-rw-r--r--demos/csharp/linux/gtk_viewer/src/MainRender.cs115
-rw-r--r--demos/csharp/linux/gtk_viewer/src/MainThumbRendering.cs74
-rw-r--r--demos/csharp/linux/gtk_viewer/src/MainWindow.cs159
-rw-r--r--demos/csharp/linux/gtk_viewer/src/gsOutput.cs14
8 files changed, 277 insertions, 206 deletions
diff --git a/demos/csharp/api/ghostnet.cs b/demos/csharp/api/ghostnet.cs
index 22c996e7a..e6707b9aa 100644
--- a/demos/csharp/api/ghostnet.cs
+++ b/demos/csharp/api/ghostnet.cs
@@ -155,7 +155,7 @@ public class gsEventArgs : EventArgs
private int display_page(IntPtr handle, IntPtr device, int copies, int flush)
{
m_params.currpage += 1;
- gsPageRenderedMain(this, m_pagewidth, m_pageheight, m_pageraster, m_pageptr, m_params);
+ gsPageRenderedMain(m_pagewidth, m_pageheight, m_pageraster, m_pageptr, m_params);
return 0;
}
@@ -212,10 +212,28 @@ public class gsEventArgs : EventArgs
private int stdout_callback(IntPtr handle, IntPtr pointer, int count)
{
- String output = Marshal.PtrToStringAnsi(pointer);
- gsIOUpdateMain(this, output, count);
-
- switch (m_params.task)
+ String output = null;
+ try
+ {
+ output = Marshal.PtrToStringAnsi(pointer);
+ }
+ catch (Exception except)
+ {
+ var mess = except.Message;
+ }
+
+ try
+ {
+ gsIOUpdateMain(output, count);
+ }
+ catch (Exception excep2)
+ {
+ var mess = excep2.Message;
+ }
+
+ return count;
+#if false
+ switch (m_params.task)
{
case GS_Task_t.CREATE_XPS:
if (count >= 7 && output.Substring(0, 4) == "Page")
@@ -276,12 +294,13 @@ public class gsEventArgs : EventArgs
break;
}
return count;
+#endif
}
private int stderr_callback(IntPtr handle, IntPtr pointer, int count)
{
String output = Marshal.PtrToStringAnsi(pointer);
- gsIOUpdateMain(this, output, count);
+ gsIOUpdateMain(output, count);
return count;
}
@@ -298,16 +317,16 @@ public class gsEventArgs : EventArgs
IntPtr ptr_display_struct;
/* Callbacks to Main */
- internal delegate void gsDLLProblem(object gsObject, String mess);
+ internal delegate void gsDLLProblem(String mess);
internal event gsDLLProblem gsDLLProblemMain;
- internal delegate void gsIOCallBackMain(object gsObject, String mess, int len);
+ internal delegate void gsIOCallBackMain(String mess, int len);
internal event gsIOCallBackMain gsIOUpdateMain;
- internal delegate void gsCallBackMain(object gsObject, gsEventArgs info);
+ internal delegate void gsCallBackMain(gsEventArgs info);
internal event gsCallBackMain gsUpdateMain;
- internal delegate void gsCallBackPageRenderedMain(object gsObject, int width, int height, int raster,
+ internal delegate void gsCallBackPageRenderedMain(int width, int height, int raster,
IntPtr data, gsParamState_t state);
internal event gsCallBackPageRenderedMain gsPageRenderedMain;
@@ -405,7 +424,7 @@ public class gsEventArgs : EventArgs
gsIOUpdateMain(this, bound, bound.Length);
gsIOUpdateMain(this, stack, stack.Length); */
String output = "Ghostscript DLL Invalid Access.";
- gsDLLProblemMain(this, output);
+ gsDLLProblemMain(output);
return;
}
switch (Params.task)
@@ -435,7 +454,7 @@ public class gsEventArgs : EventArgs
Value = (gsParamState_t)e.Result;
info = new gsEventArgs(true, 100, Value);
}
- gsUpdateMain(this, info);
+ gsUpdateMain(info);
}
/* Callback as worker progresses */
@@ -444,7 +463,7 @@ public class gsEventArgs : EventArgs
/* Callback with progress */
gsParamState_t Value = new gsParamState_t();
gsEventArgs info = new gsEventArgs(false, e.ProgressPercentage, Value);
- gsUpdateMain(this, info);
+ gsUpdateMain(info);
}
private gsParamState_t gsFileSync(gsParamState_t in_params)
{
@@ -489,7 +508,7 @@ public class gsEventArgs : EventArgs
argPtrsStable = GCHandle.Alloc(argPtrs, GCHandleType.Pinned);
fullcommand = "Command Line: " + fullcommand + "\n";
- gsIOUpdateMain(this, fullcommand, fullcommand.Length);
+ gsIOUpdateMain(fullcommand, fullcommand.Length);
code = ghostapi.gsapi_init_with_args(gsInstance, num_params, argPtrsStable.AddrOfPinnedObject());
if (code < 0 && code != gsConstants.E_QUIT)
{
@@ -498,23 +517,23 @@ public class gsEventArgs : EventArgs
}
catch (DllNotFoundException except)
{
- gsDLLProblemMain(this, "Exception: " + except.Message);
+ gsDLLProblemMain("Exception: " + except.Message);
in_params.result = GS_Result_t.gsFAILED;
cleanup = false;
}
catch (BadImageFormatException except)
{
- gsDLLProblemMain(this, "Exception: " + except.Message);
+ gsDLLProblemMain("Exception: " + except.Message);
in_params.result = GS_Result_t.gsFAILED;
cleanup = false;
}
catch (GhostscriptException except)
{
- gsDLLProblemMain(this, "Exception: " + except.Message);
+ gsDLLProblemMain("Exception: " + except.Message);
}
catch (Exception except)
{
- gsDLLProblemMain(this, "Exception: " + except.Message);
+ gsDLLProblemMain("Exception: " + except.Message);
}
finally
{
@@ -593,7 +612,7 @@ public class gsEventArgs : EventArgs
argPtrsStable = GCHandle.Alloc(argPtrs, GCHandleType.Pinned);
fullcommand = "Command Line: " + fullcommand + "\n";
- gsIOUpdateMain(this, fullcommand, fullcommand.Length);
+ gsIOUpdateMain(fullcommand, fullcommand.Length);
code = ghostapi.gsapi_init_with_args(gsInstance, num_params, argPtrsStable.AddrOfPinnedObject());
if (code < 0)
{
@@ -602,25 +621,25 @@ public class gsEventArgs : EventArgs
}
catch (DllNotFoundException except)
{
- gsDLLProblemMain(this, "Exception: " + except.Message);
+ gsDLLProblemMain("Exception: " + except.Message);
Params.result = GS_Result_t.gsFAILED;
cleanup = false;
e.Result = Params;
}
catch (BadImageFormatException except)
{
- gsDLLProblemMain(this, "Exception: " + except.Message);
+ gsDLLProblemMain("Exception: " + except.Message);
Params.result = GS_Result_t.gsFAILED;
cleanup = false;
e.Result = Params;
}
catch (GhostscriptException except)
{
- gsDLLProblemMain(this, "Exception: " + except.Message);
+ gsDLLProblemMain("Exception: " + except.Message);
}
catch (Exception except)
{
- gsDLLProblemMain(this, "Exception: " + except.Message);
+ gsDLLProblemMain("Exception: " + except.Message);
}
finally
{
@@ -712,7 +731,7 @@ public class gsEventArgs : EventArgs
argPtrsStable = GCHandle.Alloc(argPtrs, GCHandleType.Pinned);
fullcommand = "Command Line: " + fullcommand + "\n";
- gsIOUpdateMain(this, fullcommand, fullcommand.Length);
+ gsIOUpdateMain(fullcommand, fullcommand.Length);
code = ghostapi.gsapi_init_with_args(gsInstance, num_params, argPtrsStable.AddrOfPinnedObject());
if (code < 0)
{
@@ -767,26 +786,26 @@ public class gsEventArgs : EventArgs
}
catch (DllNotFoundException except)
{
- gsDLLProblemMain(this, "Exception: " + except.Message);
+ gsDLLProblemMain("Exception: " + except.Message);
Params.result = GS_Result_t.gsFAILED;
cleanup = false;
e.Result = Params;
}
catch (BadImageFormatException except)
{
- gsDLLProblemMain(this, "Exception: " + except.Message);
+ gsDLLProblemMain("Exception: " + except.Message);
Params.result = GS_Result_t.gsFAILED;
cleanup = false;
e.Result = Params;
}
catch (GhostscriptException except)
{
- gsDLLProblemMain(this, "Exception: " + except.Message);
+ gsDLLProblemMain("Exception: " + except.Message);
}
catch (Exception except)
{
/* Could be a file io issue */
- gsDLLProblemMain(this, "Exception: " + except.Message);
+ gsDLLProblemMain("Exception: " + except.Message);
Params.result = GS_Result_t.gsFAILED;
cleanup = false;
e.Result = Params;
@@ -881,7 +900,7 @@ public class gsEventArgs : EventArgs
argPtrsStable = GCHandle.Alloc(argPtrs, GCHandleType.Pinned);
fullcommand = "Command Line: " + fullcommand + "\n";
- gsIOUpdateMain(this, fullcommand, fullcommand.Length);
+ gsIOUpdateMain(fullcommand, fullcommand.Length);
code = ghostapi.gsapi_init_with_args(dispInstance, num_params, argPtrsStable.AddrOfPinnedObject());
if (code < 0)
{
@@ -891,21 +910,21 @@ public class gsEventArgs : EventArgs
catch (DllNotFoundException except)
{
- gsDLLProblemMain(this, "Exception: " + except.Message);
+ gsDLLProblemMain("Exception: " + except.Message);
gsparams.result = GS_Result_t.gsFAILED;
cleanup = false;
e.Result = gsparams;
}
catch (BadImageFormatException except)
{
- gsDLLProblemMain(this, "Exception: " + except.Message);
+ gsDLLProblemMain("Exception: " + except.Message);
gsparams.result = GS_Result_t.gsFAILED;
cleanup = false;
e.Result = gsparams;
}
catch (GhostscriptException except)
{
- gsDLLProblemMain(this, "Exception: " + except.Message);
+ gsDLLProblemMain("Exception: " + except.Message);
gsparams.result = GS_Result_t.gsFAILED;
if (dispInstance != IntPtr.Zero)
ghostapi.gsapi_delete_instance(dispInstance);
@@ -913,7 +932,7 @@ public class gsEventArgs : EventArgs
}
catch (Exception except)
{
- gsDLLProblemMain(this, "Exception: " + except.Message);
+ gsDLLProblemMain("Exception: " + except.Message);
gsparams.result = GS_Result_t.gsFAILED;
if (dispInstance != IntPtr.Zero)
ghostapi.gsapi_delete_instance(dispInstance);
@@ -993,7 +1012,7 @@ public class gsEventArgs : EventArgs
}
}
- #region public_methods
+#region public_methods
/* Direct call on gsapi to get the version of the DLL we are using */
public String GetVersion()
@@ -1022,7 +1041,7 @@ public class gsEventArgs : EventArgs
}
catch (Exception except)
{
- gsDLLProblemMain(this, "Exception: " + except.Message);
+ gsDLLProblemMain("Exception: " + except.Message);
}
return null;
}
@@ -1216,7 +1235,7 @@ public class gsEventArgs : EventArgs
}
catch (Exception except)
{
- gsDLLProblemMain(this, "Exception: " + except.Message);
+ gsDLLProblemMain("Exception: " + except.Message);
out_params.result = GS_Result_t.gsFAILED;
}
@@ -1237,6 +1256,6 @@ public class gsEventArgs : EventArgs
{
m_worker.CancelAsync();
}
- #endregion
+#endregion
}
}
diff --git a/demos/csharp/linux/gtk_viewer/gtk-gui/gtk_viewer.src.gsOutput.cs b/demos/csharp/linux/gtk_viewer/gtk-gui/gtk_viewer.src.gsOutput.cs
new file mode 100644
index 000000000..0eab65c63
--- /dev/null
+++ b/demos/csharp/linux/gtk_viewer/gtk-gui/gtk_viewer.src.gsOutput.cs
@@ -0,0 +1,10 @@
+
+namespace gtk_viewer.src
+{
+ public partial class gsOutput
+ {
+ private void Build()
+ {
+ }
+ }
+}
diff --git a/demos/csharp/linux/gtk_viewer/gtk_viewer.csproj b/demos/csharp/linux/gtk_viewer/gtk_viewer.csproj
index 948376edb..5b25dbebb 100644
--- a/demos/csharp/linux/gtk_viewer/gtk_viewer.csproj
+++ b/demos/csharp/linux/gtk_viewer/gtk_viewer.csproj
@@ -65,6 +65,7 @@
<Link>src\ghostnet.cs</Link>
</Compile>
<Compile Include="src\gsOutput.cs" />
+ <Compile Include="gtk-gui\gtk_viewer.src.gsOutput.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="packages\GtkSharp.3.22.25.98\build\GtkSharp.targets" Condition="Exists('packages\GtkSharp.3.22.25.98\build\GtkSharp.targets')" />
diff --git a/demos/csharp/linux/gtk_viewer/src/DocPage.cs b/demos/csharp/linux/gtk_viewer/src/DocPage.cs
index 01c9826f2..e2252af82 100644
--- a/demos/csharp/linux/gtk_viewer/src/DocPage.cs
+++ b/demos/csharp/linux/gtk_viewer/src/DocPage.cs
@@ -1,6 +1,5 @@
using System;
using System.ComponentModel;
-using System.Drawing;
using System.Collections.ObjectModel;
namespace gs_mono_example
@@ -10,7 +9,7 @@ namespace gs_mono_example
private int height;
private int width;
private double zoom;
- private Bitmap bitmap;
+ private Gdk.Pixbuf pixbuf;
private String pagename;
private int pagenum;
private Page_Content_t content;
@@ -41,13 +40,13 @@ namespace gs_mono_example
set { zoom = value; }
}
- public Bitmap BitMap
+ public Gdk.Pixbuf PixBuf
{
- get { return bitmap; }
+ get { return pixbuf; }
set
{
- bitmap = value;
- OnPropertyChanged("BitMap");
+ pixbuf = value;
+ OnPropertyChanged("PixBuf");
}
}
@@ -85,17 +84,17 @@ namespace gs_mono_example
this.height = 0;
this.width = 0;
this.zoom = 0;
- this.bitmap = null;
+ this.pixbuf = null;
this.pagenum = -1;
this.pagename = "";
}
- public DocPage(int Height, int Width, double Zoom, Bitmap BitMap, int PageNum)
+ public DocPage(int Height, int Width, double Zoom, Gdk.Pixbuf PixBuf, int PageNum)
{
this.height = Height;
this.width = Width;
this.zoom = Zoom;
- this.bitmap = BitMap;
+ this.pixbuf = PixBuf;
this.pagename = ("Page " + (pagenum + 1));
}
};
diff --git a/demos/csharp/linux/gtk_viewer/src/MainRender.cs b/demos/csharp/linux/gtk_viewer/src/MainRender.cs
index 9b659f6c3..316da5e99 100644
--- a/demos/csharp/linux/gtk_viewer/src/MainRender.cs
+++ b/demos/csharp/linux/gtk_viewer/src/MainRender.cs
@@ -8,7 +8,6 @@ namespace gs_mono_example
{
public partial class MainWindow
{
- bool m_busy_rendering;
int m_firstpage;
int m_lastpage;
@@ -27,59 +26,52 @@ namespace gs_mono_example
if (!render_pages)
return;
- m_busy_rendering = true;
+ m_busy_render = true;
m_firstpage = first_page;
m_lastpage = last_page;
//m_ghostscript.gsDisplayDeviceRender(m_currfile, first_page + 1, last_page + 1, 1.0);
}
- /* Callback from ghostscript with the rendered image. */
- private void MainPageCallback(object gsObject, int width, int height, int raster, double zoom_in,
- int page_num, IntPtr data)
- {
-
- Byte[] bitmap = new byte[raster * height];
-
- Marshal.Copy(data, bitmap, 0, raster * height);
-
- DocPage doc_page = m_docPages[page_num];
-
- if (doc_page.Content != Page_Content_t.FULL_RESOLUTION ||
- m_aa_change)
+ /* Callback from ghostscript with the rendered image. */
+ private void MainPageCallback(int width, int height, int raster, double zoom_in,
+ int page_num, IntPtr data)
+ {
+ try
{
- doc_page.Width = width;
- doc_page.Height = height;
- doc_page.Content = Page_Content_t.FULL_RESOLUTION;
-
- doc_page.Zoom = m_doczoom;
-
- GCHandle pinned = GCHandle.Alloc(bitmap, GCHandleType.Pinned);
- IntPtr address = pinned.AddrOfPinnedObject();
- doc_page.BitMap = new Bitmap(doc_page.Width, doc_page.Height, raster,
- System.Drawing.Imaging.PixelFormat.Format24bppRgb, address);
- pinned.Free();
+ Byte[] bitmap = new byte[raster * height];
+
+ Marshal.Copy(data, bitmap, 0, raster * height);
+ DocPage doc_page = m_docPages[page_num - 1];
+
+ if (doc_page.Content != Page_Content_t.FULL_RESOLUTION ||
+ m_aa_change)
+ {
+ doc_page.Width = width;
+ doc_page.Height = height;
+ doc_page.Content = Page_Content_t.FULL_RESOLUTION;
+ doc_page.Zoom = m_doczoom;
+ doc_page.PixBuf = new Gdk.Pixbuf(bitmap, Gdk.Colorspace.Rgb, false, 8, width, height, raster);
+ }
+
+ /* Get the 1.0 page scalings */
+ if (m_firstime)
+ {
+ pagesizes_t page_size = new pagesizes_t();
+ page_size.width = width;
+ page_size.height = height;
+ m_page_sizes.Add(page_size);
+ }
+ }
+ catch (Exception except)
+ {
+ var t = except.Message;
}
- //m_toppage_pos.Add(offset + Constants.PAGE_VERT_MARGIN);
- //offset += doc_page.Height + Constants.PAGE_VERT_MARGIN;
-
- /* Get the 1.0 page scalings */
- if (m_firstime)
- {
- pagesizes_t page_size = new pagesizes_t();
- page_size.width = width;
- page_size.height = height;
- m_page_sizes.Add(page_size);
- }
- /* Dispatch progress bar update on UI thread */
- /*
- System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
- {
- m_page_progress_count += 1;
- xaml_RenderProgress.Value = ((double)m_page_progress_count / (double) m_numpages) * 100.0;
- }));
- */
- }
+ /* Dispatch progress bar update on UI thread */
+ Gtk.Application.Invoke(delegate {
+ m_GtkProgressBar.Fraction = ((double)page_num / ((double)m_numpages));
+ });
+ }
/* Done rendering. Update the pages with the new raster information if needed */
private void RenderingDone()
@@ -87,17 +79,25 @@ namespace gs_mono_example
int page_index = m_firstpage - 1;
m_toppage_pos = new List<int>(m_images_rendered.Count + 1);
int offset = 0;
+ Gtk.TreeIter tree_iter;
+
+ m_GtkimageStoreMain.GetIterFirst(out tree_iter);
+ for (int k = 0; k < m_numpages; k++)
+ {
+ m_GtkimageStoreMain.SetValue(tree_iter, 0, m_docPages[k].PixBuf);
+ m_GtkimageStoreMain.IterNext(ref tree_iter);
+ }
- //xaml_ProgressGrid.Visibility = System.Windows.Visibility.Collapsed;
- //xaml_RenderProgress.Value = 0;
- m_aa_change = false;
+ m_GtkaaCheck.Sensitive = true;
+ m_aa_change = false;
m_firstime = false;
m_toppage_pos.Add(offset);
- m_busy_rendering = false;
+ m_busy_render = false;
m_images_rendered.Clear();
m_file_open = true;
m_busy_render = false;
- //m_ghostscript.gsPageRenderedMain -= new ghostsharp.gsCallBackPageRenderedMain(gsPageRendered);
+
+ m_ghostscript.gsPageRenderedMain -= new ghostsharp.gsCallBackPageRenderedMain(gsPageRendered);
}
/* Render all pages full resolution */
@@ -105,16 +105,8 @@ namespace gs_mono_example
{
m_firstpage = 1;
m_busy_render = true;
- //xaml_RenderProgress.Value = 0;
- //xaml_ProgressGrid.Visibility = System.Windows.Visibility.Visible;
m_page_progress_count = 0;
- //xaml_RenderProgressText.Text = "Rendering";
- if (m_firstime)
- {
- //xaml_Zoomsize.Text = "100";
- }
-
- //m_ghostscript.gsPageRenderedMain += new ghostsharp.gsCallBackPageRenderedMain(gsPageRendered);
+ m_ghostscript.gsPageRenderedMain += new ghostsharp.gsCallBackPageRenderedMain(gsPageRendered);
m_ghostscript.gsDisplayDeviceRenderAll(m_currfile, m_doczoom, m_aa, GS_Task_t.DISPLAY_DEV_NON_PDF);
}
@@ -123,7 +115,8 @@ namespace gs_mono_example
{
if (m_busy_render || !m_init_done)
return;
- RenderMainFirst();
+ m_GtkaaCheck.Sensitive = false;
+ RenderMainFirst();
}
}
}
diff --git a/demos/csharp/linux/gtk_viewer/src/MainThumbRendering.cs b/demos/csharp/linux/gtk_viewer/src/MainThumbRendering.cs
index e2461e38b..d6dff5f08 100644
--- a/demos/csharp/linux/gtk_viewer/src/MainThumbRendering.cs
+++ b/demos/csharp/linux/gtk_viewer/src/MainThumbRendering.cs
@@ -16,9 +16,9 @@ namespace gs_mono_example
DocPage doc_page = new DocPage();
doc_page.Content = Page_Content_t.THUMBNAIL;
doc_page.Zoom = zoom_in;
- doc_page.BitMap = m_thumbnails[page_num - 1].BitMap;
- doc_page.Width = (int)(width / (Constants.SCALE_THUMB));
- doc_page.Height = (int)(height / (Constants.SCALE_THUMB));
+ doc_page.Width = (int)(width / (Constants.SCALE_THUMB));
+ doc_page.Height = (int)(height / (Constants.SCALE_THUMB));
+ doc_page.PixBuf = m_thumbnails[page_num - 1].PixBuf.ScaleSimple(doc_page.Width, doc_page.Height, Gdk.InterpType.Nearest);
doc_page.PageNum = page_num;
m_docPages.Add(doc_page);
//m_toppage_pos.Add(offset + Constants.PAGE_VERT_MARGIN);
@@ -28,37 +28,42 @@ namespace gs_mono_example
/* Rendered all the thumbnail pages. Stick them in the appropriate lists */
private void ThumbsDone()
{
- //m_toppage_pos.Add(offset);
- //xaml_ProgressGrid.Visibility = System.Windows.Visibility.Collapsed;
- //xaml_RenderProgress.Value = 0;
- //xaml_PageList.ItemsSource = m_docPages;
- //xaml_ThumbList.ItemsSource = m_thumbnails;
- //xaml_ThumbList.Items.Refresh();
-
- //m_ghostscript.gsPageRenderedMain -= new ghostsharp.gsCallBackPageRenderedMain(gsThumbRendered);
-
- m_numpages = m_thumbnails.Count;
+ //m_GtkvBoxMain.Remove(m_GtkProgressBox);
+ m_ghostscript.gsPageRenderedMain -= new ghostsharp.gsCallBackPageRenderedMain(gsThumbRendered);
+ m_numpages = m_thumbnails.Count;
if (m_numpages < 1)
{
- //ShowMessage(NotifyType_t.MESS_STATUS, "File failed to open properly");
+ ShowMessage(NotifyType_t.MESS_STATUS, "File failed to open properly");
//CleanUp();
}
else
{
m_init_done = true;
- //xaml_TotalPages.Text = "/" + m_numpages;
- //xaml_currPage.Text = m_currpage.ToString();
+ m_GtkpageEntry.Text = "1";
+ m_GtkpageTotal.Text = "/" + m_numpages;
+ m_GtkzoomEntry.Text = "100";
+ for (int k = 0; k < m_numpages; k++)
+ {
+ m_GtkimageStoreThumb.AppendValues(m_thumbnails[k].PixBuf);
+ m_GtkimageStoreMain.AppendValues(m_docPages[k].PixBuf);
+ }
- /* If non-pdf, kick off full page rendering */
- //RenderMainFirst();
- }
- }
+ // var colmn = m_GtkTreeThumb.Columns;
+ // var mycol = (Gtk.TreeViewColumn)colmn.GetValue(0);
- /* Callback from ghostscript with the rendered thumbnail. Also update progress */
- private void ThumbPageCallback(object gsObject, int width, int height, int raster, double zoom_in,
- int page_num, IntPtr data)
- {
- Byte[] bitmap = new byte[raster * height];
+ //mycol.IsFloating = true;
+
+
+ /* If non-pdf, kick off full page rendering */
+ RenderMainFirst();
+ }
+ }
+
+ /* Callback from ghostscript with the rendered thumbnail. Also update progress */
+ private void ThumbPageCallback(int width, int height, int raster, double zoom_in,
+ int page_num, IntPtr data)
+ {
+ Byte[] bitmap = new byte[raster * height];
int offset = 0;
Marshal.Copy(data, bitmap, 0, raster * height);
@@ -71,28 +76,19 @@ namespace gs_mono_example
doc_page.Zoom = zoom_in;
doc_page.PageNum = page_num;
- GCHandle pinned = GCHandle.Alloc(bitmap, GCHandleType.Pinned);
- IntPtr address = pinned.AddrOfPinnedObject();
- doc_page.BitMap = new Bitmap(doc_page.Width, doc_page.Height, raster,
- System.Drawing.Imaging.PixelFormat.Format24bppRgb, address);
- pinned.Free();
-
+ doc_page.PixBuf = new Gdk.Pixbuf(bitmap, Gdk.Colorspace.Rgb, false, 8, width, height, raster);
ThumbAssignMain(page_num, width, height, 1.0, ref offset);
/* Dispatch progress bar update on UI thread */
-#if false
- System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
- {
- /* Logrithmic but it will show progress */
- //xaml_RenderProgress.Value = ((double) page_num / ((double) page_num + 1))* 100.0;
- }));
-#endif
+ Gtk.Application.Invoke(delegate {
+ m_GtkProgressBar.Fraction = ((double)page_num / ((double)page_num + 1));
+ });
}
/* Render the thumbnail images */
private void RenderThumbs()
{
- m_GtkvBoxMain.PackStart(m_GtkProgressBox, false, false, 0);
+ //m_GtkvBoxMain.PackStart(m_GtkProgressBox, false, false, 0);
m_GtkProgressLabel.Text = "Rendering Thumbs";
m_GtkProgressBar.Fraction = 0.0;
diff --git a/demos/csharp/linux/gtk_viewer/src/MainWindow.cs b/demos/csharp/linux/gtk_viewer/src/MainWindow.cs
index 7501dacee..7fde13dd2 100644
--- a/demos/csharp/linux/gtk_viewer/src/MainWindow.cs
+++ b/demos/csharp/linux/gtk_viewer/src/MainWindow.cs
@@ -101,32 +101,29 @@ namespace gs_mono_example
Gtk.ProgressBar m_GtkProgressBar;
Label m_GtkProgressLabel;
HBox m_GtkProgressBox;
- Gtk.TreeView m_GtkTree;
+ Gtk.TreeView m_GtkTreeThumb;
+ Gtk.TreeView m_GtkTreeMain;
Gtk.VBox m_GtkvBoxMain;
-
- void ShowMessage(Window parent, NotifyType_t type, string message)
+ Label m_GtkpageTotal;
+ Entry m_GtkpageEntry;
+ Gtk.ListStore m_GtkimageStoreThumb;
+ Gtk.ListStore m_GtkimageStoreMain;
+ Gtk.ScrolledWindow m_GtkthumbScroll;
+ Gtk.ScrolledWindow m_GtkmainScroll;
+ Gtk.Entry m_GtkzoomEntry;
+ Gtk.CheckButton m_GtkaaCheck;
+
+ void ShowMessage(NotifyType_t type, string message)
{
- Dialog dialog = null;
- String title = "Notice";
+ MessageDialog md = new MessageDialog(this,
+ DialogFlags.DestroyWithParent, MessageType.Error,
+ ButtonsType.Close, message);
if (type == NotifyType_t.MESS_ERROR)
- title = "Error";
-
- try
- {
- dialog = new Dialog(title, parent,
- DialogFlags.DestroyWithParent | DialogFlags.Modal,
- ResponseType.Ok);
- dialog.VBox.Add(new Label(message));
- dialog.ShowAll();
-
- dialog.Run();
- }
- finally
- {
- if (dialog != null)
- dialog.Destroy();
- }
+ md.Title = "Error";
+ else
+ md.Title = "Notice";
+ md.ShowAll();
}
public MainWindow() : base(Gtk.WindowType.Toplevel)
@@ -154,7 +151,6 @@ namespace gs_mono_example
m_validZoom = true;
m_firstime = true;
m_images_rendered = new List<idata_t>();
- m_busy_rendering = false;
m_aa = true;
m_aa_change = false;
Gtk.TextTagTable tag = new Gtk.TextTagTable(IntPtr.Zero);
@@ -210,43 +206,74 @@ namespace gs_mono_example
/* Add a hbox with the page information, zoom control, and aa to vbox */
HBox pageBox = new HBox(false, 0);
- Entry pageEntry = new Entry();
- pageEntry.WidthChars = 4;
- Label pageTotal = new Label("/0");
- pageBox.PackStart(pageEntry, false, false, 0);
- pageBox.PackStart(pageTotal, false, false, 0);
+ m_GtkpageEntry = new Entry();
+ m_GtkpageEntry.WidthChars = 4;
+ m_GtkpageTotal = new Label("/0");
+ pageBox.PackStart(m_GtkpageEntry, false, false, 0);
+ pageBox.PackStart(m_GtkpageTotal, false, false, 0);
HBox zoomBox = new HBox(false, 0);
Button zoomPlus = new Button();
zoomPlus.Label = "+";
Button zoomMinus = new Button();
zoomMinus.Label = "–";
- Entry zoomEntry = new Entry();
- zoomEntry.WidthChars = 3;
+ m_GtkzoomEntry = new Entry();
+ m_GtkzoomEntry.WidthChars = 3;
Label precentLabel = new Label("%");
zoomBox.PackStart(zoomPlus, false, false, 0);
zoomBox.PackStart(zoomMinus, false, false, 0);
- zoomBox.PackStart(zoomEntry, false, false, 0);
+ zoomBox.PackStart(m_GtkzoomEntry, false, false, 0);
zoomBox.PackStart(precentLabel, false, false, 0);
HBox hBoxControls = new HBox(false, 0);
- CheckButton aaCheck = new CheckButton("Enable Antialias:");
+ m_GtkaaCheck = new CheckButton("Enable Antialias:");
+ m_GtkaaCheck.Active = true;
+ m_GtkaaCheck.Clicked += AaCheck_Clicked;
hBoxControls.PackStart(pageBox, false, false, 0);
hBoxControls.PackStart(zoomBox, false, false, 20);
- hBoxControls.PackStart(aaCheck, false, false, 0);
+ hBoxControls.PackStart(m_GtkaaCheck, false, false, 0);
m_GtkvBoxMain.PackStart(hBoxControls, false, false, 0);
/* Tree view containing thumbnail and main images */
- m_GtkTree = new Gtk.TreeView();
- Gtk.TreeViewColumn thumbColumn = new Gtk.TreeViewColumn();
- Gtk.TreeViewColumn pageColumn = new Gtk.TreeViewColumn();
- m_GtkTree.AppendColumn(thumbColumn);
- m_GtkTree.AppendColumn(pageColumn);
- Gtk.ListStore imageStore = new Gtk.ListStore(typeof(Image), typeof(Image));
- m_GtkTree.Model = imageStore;
+ HBox hBoxPages = new HBox(false, 0);
+
+ /* Must be scrollable */
+ m_GtkthumbScroll = new ScrolledWindow();
+ m_GtkthumbScroll.BorderWidth = 5;
+ m_GtkthumbScroll.ShadowType = ShadowType.In;
+
+ m_GtkmainScroll = new ScrolledWindow();
+ m_GtkmainScroll.BorderWidth = 5;
+ m_GtkmainScroll.ShadowType = ShadowType.In;
+
+ m_GtkTreeThumb = new Gtk.TreeView();
+ m_GtkTreeThumb.HeadersVisible = false;
+ m_GtkimageStoreThumb = new Gtk.ListStore(typeof(Gdk.Pixbuf));
+ m_GtkTreeThumb.AppendColumn("Thumb", new Gtk.CellRendererPixbuf(), "pixbuf", 0);
+ m_GtkTreeThumb.Style.YThickness = 100;
+ m_GtkthumbScroll.Add(m_GtkTreeThumb);
+
+ /* var colmn = m_GtkTreeThumb.Columns;
+ var mycol = (Gtk.TreeViewColumn)colmn.GetValue(0);
+ mycol.Spacing = 40;
+ mycol.FixedWidth = 0;*/
+
+ m_GtkTreeMain = new Gtk.TreeView();
+ m_GtkTreeMain.HeadersVisible = false;
+ m_GtkimageStoreMain = new Gtk.ListStore(typeof(Gdk.Pixbuf));
+ m_GtkTreeMain.AppendColumn("Main", new Gtk.CellRendererPixbuf(), "pixbuf", 0);
+ m_GtkmainScroll.Add(m_GtkTreeMain);
- m_GtkvBoxMain.PackStart(m_GtkTree, true, true, 0);
+ hBoxPages.PackStart(m_GtkthumbScroll, false, false, 0);
+ hBoxPages.PackStart(m_GtkmainScroll, true, true, 0);
+
+ m_GtkTreeThumb.Model = m_GtkimageStoreThumb;
+ m_GtkTreeMain.Model = m_GtkimageStoreMain;
+
+
+
+ m_GtkvBoxMain.PackStart(hBoxPages, true, true, 0);
/* Progress bar */
m_GtkProgressBox = new HBox(false, 0);
@@ -256,10 +283,19 @@ namespace gs_mono_example
m_GtkProgressLabel = new Label("Render Thumbnails");
m_GtkProgressBox.PackStart(m_GtkProgressLabel, false, false, 0);
- // m_GtkvBoxMain.PackStart(m_GtkProgressBox, false, false, 0);
- // m_GtkvBoxMain.Remove(m_GtkProgressBox);
+ m_GtkvBoxMain.PackStart(m_GtkProgressBox, false, false, 0);
+ //m_GtkvBoxMain.Remove(m_GtkProgressBox);
+ }
+
+ void AaCheck_Clicked(object sender, EventArgs e)
+ {
+ m_aa = !m_aa;
+ m_aa_change = true;
+ if (m_init_done && !m_busy_render)
+ RenderMainAll();
}
+
private void OnQuit(object sender, EventArgs e)
{
Application.Quit();
@@ -275,31 +311,40 @@ namespace gs_mono_example
throw new NotImplementedException();
}
- private void gsIO(object gsObject, String mess, int len)
+ private void gsIO(String mess, int len)
{
Gtk.TextBuffer buffer = m_gsoutput.m_textView.Buffer;
Gtk.TextIter ti = buffer.EndIter;
- buffer.Insert(ref ti, mess.Substring(0, len));
+
+ try
+ {
+ var part = mess.Substring(0, len);
+ buffer.Insert(ref ti, part);
+ }
+ catch(Exception except)
+ {
+ var issue = except.Message;
+ }
}
- private void gsDLL(object gsObject, String mess)
+ private void gsDLL(String mess)
{
- ShowMessage(this, NotifyType_t.MESS_STATUS, mess);
+ ShowMessage(NotifyType_t.MESS_STATUS, mess);
}
- private void gsThumbRendered(object gsObject, int width, int height, int raster,
+ private void gsThumbRendered(int width, int height, int raster,
IntPtr data, gsParamState_t state)
{
- ThumbPageCallback(gsObject, width, height, raster, state.zoom, state.currpage, data);
+ ThumbPageCallback(width, height, raster, state.zoom, state.currpage, data);
}
- private void gsPageRendered(object gsObject, int width, int height, int raster,
+ private void gsPageRendered(int width, int height, int raster,
IntPtr data, gsParamState_t state)
{
- MainPageCallback(gsObject, width, height, raster, state.zoom, state.currpage, data);
+ MainPageCallback(width, height, raster, state.zoom, state.currpage, data);
}
- private void gsProgress(object gsObject, gsEventArgs asyncInformation)
+ private void gsProgress(gsEventArgs asyncInformation)
{
if (asyncInformation.Completed)
{
@@ -330,19 +375,19 @@ namespace gs_mono_example
switch (asyncInformation.Params.task)
{
case GS_Task_t.CREATE_XPS:
- ShowMessage(this, NotifyType_t.MESS_STATUS, "Ghostscript failed to create XPS");
+ ShowMessage(NotifyType_t.MESS_STATUS, "Ghostscript failed to create XPS");
break;
case GS_Task_t.PS_DISTILL:
- ShowMessage(this, NotifyType_t.MESS_STATUS, "Ghostscript failed to distill PS");
+ ShowMessage(NotifyType_t.MESS_STATUS, "Ghostscript failed to distill PS");
break;
case GS_Task_t.SAVE_RESULT:
- ShowMessage(this, NotifyType_t.MESS_STATUS, "Ghostscript failed to convert document");
+ ShowMessage(NotifyType_t.MESS_STATUS, "Ghostscript failed to convert document");
break;
default:
- ShowMessage(this, NotifyType_t.MESS_STATUS, "Ghostscript failed.");
+ ShowMessage(NotifyType_t.MESS_STATUS, "Ghostscript failed.");
break;
}
@@ -444,7 +489,7 @@ namespace gs_mono_example
case GS_Task_t.SAVE_RESULT:
/* Don't delete file in this case as this was our output! */
- ShowMessage(this, NotifyType_t.MESS_STATUS, "GS Completed Conversion");
+ ShowMessage(NotifyType_t.MESS_STATUS, "GS Completed Conversion");
break;
}
}
diff --git a/demos/csharp/linux/gtk_viewer/src/gsOutput.cs b/demos/csharp/linux/gtk_viewer/src/gsOutput.cs
index aa30e3a79..9c8c75f13 100644
--- a/demos/csharp/linux/gtk_viewer/src/gsOutput.cs
+++ b/demos/csharp/linux/gtk_viewer/src/gsOutput.cs
@@ -11,13 +11,21 @@ namespace gs_mono_example
{
this.SetDefaultSize(500, 500);
this.Title = "GhostPDL Standard Output";
- VBox vBox = new VBox(true, 0);
- this.Add(vBox);
+
+ //VBox vBox = new VBox(true, 0);
+ //this.Add(vBox);
+
+ ScrolledWindow scrolledWindow = new ScrolledWindow();
+ scrolledWindow.BorderWidth = 5;
+ scrolledWindow.ShadowType = ShadowType.In;
this.DeleteEvent += Handle_DeleteEvent;
m_textView = new Gtk.TextView();
- vBox.PackStart(m_textView, true, true, 0);
+ scrolledWindow.Add(m_textView);
+
+ //vBox.PackStart(scrolledWindow, true, true, 0);
+ this.Add(scrolledWindow);
this.ShowAll();
this.Hide();
}