diff options
author | Michael Vrhel <michael.vrhel@artifex.com> | 2014-02-19 17:07:08 -0800 |
---|---|---|
committer | Michael Vrhel <michael.vrhel@artifex.com> | 2014-09-09 16:39:32 -0700 |
commit | 973ce4bf471a1b98a351d02bfa41bde75ead4f90 (patch) | |
tree | 6df4dacea9628b7e6add1ce27275401363f1b8d7 /platform/winrt | |
parent | 16c749eac751d6b87c8bc209234fb3ad2c9f0943 (diff) | |
download | mupdf-973ce4bf471a1b98a351d02bfa41bde75ead4f90.tar.xz |
Fix a few issues related to printing and the UI control.
Diffstat (limited to 'platform/winrt')
-rw-r--r-- | platform/winrt/gsview/MainWindow.xaml | 7 | ||||
-rw-r--r-- | platform/winrt/gsview/MainWindow.xaml.cs | 26 | ||||
-rw-r--r-- | platform/winrt/gsview/ghostsharp.cs | 52 | ||||
-rw-r--r-- | platform/winrt/gsview/gsprint.cs | 17 |
4 files changed, 88 insertions, 14 deletions
diff --git a/platform/winrt/gsview/MainWindow.xaml b/platform/winrt/gsview/MainWindow.xaml index aa2da142..7cd80618 100644 --- a/platform/winrt/gsview/MainWindow.xaml +++ b/platform/winrt/gsview/MainWindow.xaml @@ -342,7 +342,8 @@ <ProgressBar x:Name="xaml_PrintProgress" Grid.Row="0" Grid.Column="0" Margin="3" Minimum="0" Maximum="100" Height="20" HorizontalAlignment="Stretch" /> <TextBlock Grid.Row="0" Grid.Column="1" VerticalAlignment="Center" Margin="5, 0, 5, 0"><Bold>Printing</Bold></TextBlock> - <Button Grid.Row="0" Grid.Column="2" Width="50" Height="20" Name="xaml_CancelPrint" Click="CancelPrintClick" Background="Transparent" BorderBrush="Transparent" Margin="5,0,5,0"> + <!-- Asyc Cancel crashes in windows 8 for this xps creation --> + <!-- <Button Grid.Row="0" Grid.Column="2" Width="50" Height="20" Name="xaml_CancelPrint" Click="CancelPrintClick" Background="Transparent" BorderBrush="Transparent" Margin="5,0,5,0"> <Button.Template> <ControlTemplate TargetType="{x:Type Button}"> <Grid> @@ -356,7 +357,7 @@ </ControlTemplate> </Button.Template> <TextBlock><Bold>Cancel</Bold></TextBlock> - </Button> + </Button> --> </Grid> <!-- The progress bar that runs during distilling --> @@ -368,7 +369,7 @@ </Grid.ColumnDefinitions> <ProgressBar x:Name="xaml_DistillProgress" Grid.Row="0" Grid.Column="0" Margin="3" Minimum="0" Maximum="100" Height="20" HorizontalAlignment="Stretch"/> - <TextBlock Grid.Row="0" Grid.Column="1" VerticalAlignment="Center" Margin="5, 0, 5, 0"><Bold>Distilling</Bold></TextBlock> + <TextBlock x:Name="xaml_DistillName" Grid.Row="0" Grid.Column="1" VerticalAlignment="Center" Margin="5, 0, 5, 0"><Bold>Distilling</Bold></TextBlock> <Button Grid.Row="0" Grid.Column="2" Width="50" Height="20" Name="xaml_CancelDistill" Click="CancelDistillClick" Background="Transparent" BorderBrush="Transparent" Margin="5,0,5,0"> <Button.Template> <ControlTemplate TargetType="{x:Type Button}"> diff --git a/platform/winrt/gsview/MainWindow.xaml.cs b/platform/winrt/gsview/MainWindow.xaml.cs index 472d031c..4c960396 100644 --- a/platform/winrt/gsview/MainWindow.xaml.cs +++ b/platform/winrt/gsview/MainWindow.xaml.cs @@ -93,6 +93,7 @@ static class Constants public const int SEARCH_FORWARD = 1; public const int SEARCH_BACKWARD = -1; public const int TEXT_NOT_FOUND = -1; + public const int DEFAULT_GS_RES = 300; } namespace gsview @@ -410,6 +411,13 @@ namespace gsview ShowMessage(NotifyType_t.MESS_STATUS, "GS busy. Cancel to open new file."); return; } + + if (m_ghostprint != null && m_ghostprint.IsBusy()) + { + ShowMessage(NotifyType_t.MESS_STATUS, "Let printing complete"); + return; + } + OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter = "Document Files(*.ps;*.eps;*.pdf;*.xps;*.cbz)|*.ps;*.eps;*.pdf;*.xps;*.cbz|All files (*.*)|*.*"; dlg.FilterIndex = 1; @@ -426,11 +434,14 @@ namespace gsview if (extension.ToUpper() == ".PS" || extension.ToUpper() == ".EPS") { xaml_DistillProgress.Value = 0; - if (m_ghostscript.DistillPS(dlg.FileName) == gsStatus.GS_BUSY) + if (m_ghostscript.DistillPS(dlg.FileName, Constants.DEFAULT_GS_RES) == gsStatus.GS_BUSY) { ShowMessage(NotifyType_t.MESS_STATUS, "GS currently busy"); return; } + xaml_DistillName.Text = "Distilling"; + xaml_CancelDistill.Visibility = System.Windows.Visibility.Visible; + xaml_DistillName.FontWeight = FontWeights.Bold; xaml_DistillGrid.Visibility = System.Windows.Visibility.Visible; return; } @@ -859,18 +870,23 @@ namespace gsview if (!m_isXPS) { xaml_DistillProgress.Value = 0; - if (m_ghostscript.CreateXPS(m_currfile) == gsStatus.GS_BUSY) + if (m_ghostscript.CreateXPS(m_currfile, Constants.DEFAULT_GS_RES, m_num_pages) == gsStatus.GS_BUSY) { ShowMessage(NotifyType_t.MESS_STATUS, "GS currently busy"); return; } else { + /* Right now this is not possible to cancel due to the way + * that gs is run for xpswrite from pdf */ + xaml_CancelDistill.Visibility = System.Windows.Visibility.Collapsed; + xaml_DistillName.Text = "Convert to XPS"; + xaml_DistillName.FontWeight = FontWeights.Bold; xaml_DistillGrid.Visibility = System.Windows.Visibility.Visible; } - - } - PrintXPS(m_currfile); + } + else + PrintXPS(m_currfile); } private void PrintXPS(String file) diff --git a/platform/winrt/gsview/ghostsharp.cs b/platform/winrt/gsview/ghostsharp.cs index f945ee1f..c9882a7b 100644 --- a/platform/winrt/gsview/ghostsharp.cs +++ b/platform/winrt/gsview/ghostsharp.cs @@ -77,6 +77,7 @@ namespace gsview public String inputfile; public GS_Task_t task; public GS_Result_t result; + public int num_pages; }; public class gsEventArgs : EventArgs @@ -202,6 +203,31 @@ namespace gsview { String output = Marshal.PtrToStringAnsi(pointer); gsIOUpdateMain(this, output, count); + if (m_params.task == GS_Task_t.CREATE_XPS) + { + /* See if we have a page number */ + if (count >= 7 && output.Substring(0, 4) == "Page") + { + String page = output.Substring(5, count - 6); + int numVal; + try + { + numVal = System.Convert.ToInt32(page); + + double perc = 100.0 * (double)numVal / (double)m_params.num_pages; + m_worker.ReportProgress((int)perc); + } + catch (FormatException e) + { + Console.WriteLine("XPSPrint Error: Input string is not a sequence of digits."); + } + catch (OverflowException e) + { + Console.WriteLine("XPSPrint Error: The number cannot fit in an Int32."); + } + + } + } return count; } @@ -214,6 +240,7 @@ namespace gsview IntPtr gsInstance; BackgroundWorker m_worker; + gsParams_t m_params; /* Callbacks to Main */ internal delegate void gsIOCallBackMain(object gsObject, String mess, int len); internal event gsIOCallBackMain gsIOUpdateMain; @@ -458,6 +485,12 @@ namespace gsview { gsParams_t Value; gsEventArgs info; + gsParams_t Params = (gsParams_t) e.Result; + + if (Params.task == GS_Task_t.PS_DISTILL) + m_worker.DoWork -= new DoWorkEventHandler(gsWork2); + else + m_worker.DoWork -= new DoWorkEventHandler(gsWork1); if (e.Cancelled) { @@ -481,27 +514,31 @@ namespace gsview gsUpdateMain(this, info); } - public gsStatus DistillPS(String FileName) + public gsStatus DistillPS(String FileName, int resolution) { gsParams_t Params = new gsParams_t(); ; Params.device = gsDevice_t.pdfwrite; Params.outputfile = null; - Params.resolution = 300; + Params.resolution = resolution; Params.inputfile = FileName; Params.outputfile = null; + Params.num_pages = -1; + Params.task = GS_Task_t.PS_DISTILL; return RunGhostscript(Params); } - public gsStatus CreateXPS(String FileName) + public gsStatus CreateXPS(String FileName, int resolution, int num_pages) { gsParams_t Params = new gsParams_t(); ; Params.device = gsDevice_t.xpswrite; Params.outputfile = null; - Params.resolution = 300; + Params.resolution = resolution; Params.inputfile = FileName; Params.outputfile = null; + Params.task = GS_Task_t.CREATE_XPS; + Params.num_pages = num_pages; return RunGhostscript(Params); } @@ -531,10 +568,15 @@ namespace gsview m_worker = new BackgroundWorker(); m_worker.WorkerReportsProgress = true; m_worker.WorkerSupportsCancellation = true; - m_worker.DoWork += new DoWorkEventHandler(gsWork2); m_worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(gsCompleted); m_worker.ProgressChanged += new ProgressChangedEventHandler(gsProgressChanged); } + if (Params.task == GS_Task_t.PS_DISTILL) + m_worker.DoWork += new DoWorkEventHandler(gsWork2); + else + m_worker.DoWork += new DoWorkEventHandler(gsWork1); + + m_params = Params; m_worker.RunWorkerAsync(Params); return gsStatus.GS_READY; } diff --git a/platform/winrt/gsview/gsprint.cs b/platform/winrt/gsview/gsprint.cs index 8fb7ad81..51a6e135 100644 --- a/platform/winrt/gsview/gsprint.cs +++ b/platform/winrt/gsview/gsprint.cs @@ -48,6 +48,17 @@ namespace gsview private XpsDocumentWriter m_docWriter = null; internal delegate void AsyncPrintCallBack(object printObject, gsPrintEventArgs info); internal event AsyncPrintCallBack PrintUpdate; + private bool m_busy; + + public bool IsBusy() + { + return m_busy; + } + + public gsprint() + { + m_busy = false; + } /* Show std. print dialog */ public PrintDialog GetPrintDialog() @@ -58,6 +69,7 @@ namespace gsview //dlg.UserPageRangeEnabled = true; //dlg.CurrentPageEnabled = true; dlg.SelectedPagesEnabled = false; + m_busy = false; if (dlg.ShowDialog() == true) return dlg; return null; @@ -67,7 +79,8 @@ namespace gsview public void Print(PrintQueue queu, FixedDocumentSequence fixdoc) { XpsDocumentWriter docwrite = GetDocWriter(queu); - + + m_busy = true; docwrite.WritingPrintTicketRequired += new WritingPrintTicketRequiredEventHandler(PrintTicket); PrintPages(docwrite, fixdoc); @@ -95,6 +108,7 @@ namespace gsview private void AsyncCompleted(object sender, WritingCompletedEventArgs e) { string status = null; + if (e.Cancelled) status = "Print Canceled"; else if (e.Error != null) @@ -107,6 +121,7 @@ namespace gsview gsPrintEventArgs info = new gsPrintEventArgs(status, true, 0); PrintUpdate(this, info); } + m_busy = false; } /* Do this update with each fixed document (page) that is handled */ |