diff options
-rw-r--r-- | platform/windows/gsprint.vcxproj | 164 | ||||
-rw-r--r-- | platform/windows/gsprint/dllmain.cpp | 19 | ||||
-rw-r--r-- | platform/windows/gsprint/gsprint.cpp | 73 | ||||
-rw-r--r-- | platform/windows/gsprint/gsprint.h | 12 | ||||
-rw-r--r-- | platform/windows/gsview/MainWindow.xaml.cs | 164 | ||||
-rw-r--r-- | platform/windows/gsview/PrintControl.xaml | 247 | ||||
-rw-r--r-- | platform/windows/gsview/PrintControl.xaml.cs | 697 | ||||
-rw-r--r-- | platform/windows/gsview/ghostsharp.cs | 17 | ||||
-rw-r--r-- | platform/windows/gsview/gsprint.cs | 315 | ||||
-rw-r--r-- | platform/windows/gsview/gsview.csproj | 7 | ||||
-rw-r--r-- | platform/windows/mupdf.sln | 65 |
11 files changed, 1739 insertions, 41 deletions
diff --git a/platform/windows/gsprint.vcxproj b/platform/windows/gsprint.vcxproj new file mode 100644 index 00000000..c191599d --- /dev/null +++ b/platform/windows/gsprint.vcxproj @@ -0,0 +1,164 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup Label="ProjectConfigurations"> + <ProjectConfiguration Include="Debug|Win32"> + <Configuration>Debug</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Debug|x64"> + <Configuration>Debug</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|Win32"> + <Configuration>Release</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|x64"> + <Configuration>Release</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + </ItemGroup> + <PropertyGroup Label="Globals"> + <ProjectGuid>{09FE8E75-9952-44E7-95F8-E8D74707FBA1}</ProjectGuid> + <Keyword>Win32Proj</Keyword> + <RootNamespace>gsprint</RootNamespace> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <PlatformToolset>v120</PlatformToolset> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <PlatformToolset>v120</PlatformToolset> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <PlatformToolset>v120</PlatformToolset> + <WholeProgramOptimization>true</WholeProgramOptimization> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <PlatformToolset>v120</PlatformToolset> + <WholeProgramOptimization>true</WholeProgramOptimization> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> + <ImportGroup Label="ExtensionSettings"> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <PropertyGroup Label="UserMacros" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <LinkIncremental>true</LinkIncremental> + <OutDir>$(SolutionDir)\gsview\bin\$(Configuration)\</OutDir> + <IntDir>$(Platform)\$(Configuration)\</IntDir> + <TargetName>$(ProjectName)32</TargetName> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <LinkIncremental>true</LinkIncremental> + <OutDir>$(SolutionDir)\gsview\bin\$(Configuration)\</OutDir> + <TargetName>$(ProjectName)64</TargetName> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <LinkIncremental>false</LinkIncremental> + <TargetName>$(ProjectName)32</TargetName> + <OutDir>$(SolutionDir)\gsview\bin\$(Configuration)\</OutDir> + <IntDir>$(Platform)\$(Configuration)\</IntDir> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <LinkIncremental>false</LinkIncremental> + <OutDir>$(SolutionDir)\gsview\bin\$(Configuration)\</OutDir> + <TargetName>$(ProjectName)64</TargetName> + </PropertyGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <ClCompile> + <PrecompiledHeader>NotUsing</PrecompiledHeader> + <WarningLevel>Level3</WarningLevel> + <Optimization>Disabled</Optimization> + <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;GSPRINT_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <SDLCheck>true</SDLCheck> + </ClCompile> + <Link> + <SubSystem>Windows</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <ClCompile> + <PrecompiledHeader>NotUsing</PrecompiledHeader> + <WarningLevel>Level3</WarningLevel> + <Optimization>Disabled</Optimization> + <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;GSPRINT_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <SDLCheck>true</SDLCheck> + </ClCompile> + <Link> + <SubSystem>Windows</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <PrecompiledHeader>NotUsing</PrecompiledHeader> + <Optimization>MaxSpeed</Optimization> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;GSPRINT_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <SDLCheck>true</SDLCheck> + </ClCompile> + <Link> + <SubSystem>Windows</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <PrecompiledHeader>NotUsing</PrecompiledHeader> + <Optimization>MaxSpeed</Optimization> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;GSPRINT_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <SDLCheck>true</SDLCheck> + </ClCompile> + <Link> + <SubSystem>Windows</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + </Link> + </ItemDefinitionGroup> + <ItemGroup> + <Text Include="ReadMe.txt" /> + </ItemGroup> + <ItemGroup> + <ClInclude Include="gsprint\gsprint.h" /> + </ItemGroup> + <ItemGroup> + <ClCompile Include="gsprint\dllmain.cpp" /> + <ClCompile Include="gsprint\gsprint.cpp" /> + </ItemGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> + <ImportGroup Label="ExtensionTargets"> + </ImportGroup> +</Project>
\ No newline at end of file diff --git a/platform/windows/gsprint/dllmain.cpp b/platform/windows/gsprint/dllmain.cpp new file mode 100644 index 00000000..bfaa6519 --- /dev/null +++ b/platform/windows/gsprint/dllmain.cpp @@ -0,0 +1,19 @@ +// dllmain.cpp : Defines the entry point for the DLL application. +#include <windows.h> + +BOOL APIENTRY DllMain( HMODULE hModule, + DWORD ul_reason_for_call, + LPVOID lpReserved + ) +{ + switch (ul_reason_for_call) + { + case DLL_PROCESS_ATTACH: + case DLL_THREAD_ATTACH: + case DLL_THREAD_DETACH: + case DLL_PROCESS_DETACH: + break; + } + return TRUE; +} + diff --git a/platform/windows/gsprint/gsprint.cpp b/platform/windows/gsprint/gsprint.cpp new file mode 100644 index 00000000..813364a8 --- /dev/null +++ b/platform/windows/gsprint/gsprint.cpp @@ -0,0 +1,73 @@ +// gsprint.cpp : Defines the exported functions for the DLL application. +// +#include "gsprint.h" +#include "stdlib.h" + +#define FAIL -1 + +/* Code to handle the special device properties window as well as make sure + * that the values are maintained when we leave */ +SYMBOL_DECLSPEC int __stdcall ShowPropertiesDialog(void *hptr, void *printername, bool show_win) +{ + HWND hWnd = (HWND)hptr; + HANDLE hPrinter = NULL; + LPDEVMODE pDevMode; + DWORD dwNeeded, dwRet; + wchar_t *output = NULL; + + int lenA = lstrlenA((char*)printername); + int lenW = ::MultiByteToWideChar(CP_ACP, 0, (char*)printername, lenA, NULL, 0); + if (lenW > 0) + { + output = new wchar_t[lenW + 1]; + if (output == NULL) + return -1; + ::MultiByteToWideChar(CP_ACP, 0, (char*)printername, lenA, output, lenW); + output[lenW] = 0; + } + else + return FAIL; + + if (!OpenPrinter(output, &hPrinter, NULL)) + { + free(output); + return FAIL; + } + + /* First get the size needed */ + dwNeeded = DocumentProperties(hWnd, hPrinter, output, NULL, NULL, 0); + pDevMode = (LPDEVMODE)malloc(dwNeeded); + if (pDevMode == NULL) + { + free(output); + ClosePrinter(hPrinter); + return FAIL; + } + + /* Now actually get the DEVMODE data. DM_IN_PROMPT brings up the window. + * DM_OUT_BUFFER ensures that we get the values that have been set */ + DWORD fMode = DM_OUT_BUFFER; + if (show_win) + fMode = fMode | DM_IN_PROMPT; + + dwRet = DocumentProperties(hWnd, hPrinter, output, pDevMode, NULL, fMode); + if (dwRet != IDOK) + { + free(output); + ClosePrinter(hPrinter); + free(pDevMode); + return FAIL; + } + + /* This is the secret to ensure that the DEVMODE settings are saved. Fun + * finding this bit of information in the MS literature */ + PRINTER_INFO_9 new_info; + new_info.pDevMode = pDevMode; + SetPrinter(hPrinter, 9, (LPBYTE)&new_info, 0); + + /* Clean up */ + free(pDevMode); + free(output); + ClosePrinter(hPrinter); + return 0; +} diff --git a/platform/windows/gsprint/gsprint.h b/platform/windows/gsprint/gsprint.h new file mode 100644 index 00000000..cfc2c7b3 --- /dev/null +++ b/platform/windows/gsprint/gsprint.h @@ -0,0 +1,12 @@ +#include <windows.h> +#include <winspool.h> + +#ifdef __cplusplus +#define EXTERNC extern "C" +#else +#define EXTERNC +#endif + +#define SYMBOL_DECLSPEC __declspec(dllexport) + +EXTERN_C SYMBOL_DECLSPEC int __stdcall ShowPropertiesDialog(void *ctx, void *printername, bool show_win); diff --git a/platform/windows/gsview/MainWindow.xaml.cs b/platform/windows/gsview/MainWindow.xaml.cs index 6e6ee855..fd26a50b 100644 --- a/platform/windows/gsview/MainWindow.xaml.cs +++ b/platform/windows/gsview/MainWindow.xaml.cs @@ -153,6 +153,7 @@ static class Constants public const int SCROLL_EDGE_BUFFER = 90; public const int VERT_SCROLL_STEP = 48; public const int PAGE_MARGIN = 1; + public const int MAX_PRINT_PREVIEW_LENGTH = 250; } public static class DocumentTypes @@ -205,6 +206,15 @@ namespace gsview public int num_rects; } + public struct printPreviewPage_t + { + public Byte[] bitmap; + public int width; + public int height; + public double width_inches; + public double height_inches; + } + public struct textSelectInfo_t { public int pagenum; @@ -282,6 +292,7 @@ namespace gsview List<DocPage> m_thumbnails; List<List<RectList>> m_page_link_list = null; IList<RectList> m_text_list; + DocPage m_PrintPreviewPage; public List<LinesText> m_lineptrs = null; public List<BlocksText> m_textptrs = null; List<Boolean> m_textset = null; @@ -308,12 +319,14 @@ namespace gsview Convert m_convertwin; PageExtractSave m_extractwin; Password m_password = null; + PrintControl m_printcontrol = null; String m_currpassword = null; BackgroundWorker m_thumbworker = null; BackgroundWorker m_textsearch = null; BackgroundWorker m_linksearch = null; BackgroundWorker m_openfile = null; BackgroundWorker m_initrender = null; + BackgroundWorker m_printerpreview = null; BackgroundWorker m_copytext = null; String m_document_type; Info m_infowindow; @@ -349,6 +362,7 @@ namespace gsview { m_docPages = new Pages(); m_thumbnails = new List<DocPage>(); + m_PrintPreviewPage = new DocPage(); m_lineptrs = new List<LinesText>(); m_textptrs = new List<BlocksText>(); m_textset = new List<Boolean>(); @@ -426,6 +440,8 @@ namespace gsview m_gsoutput.RealWindowClosing(); if (m_outputintents != null) m_outputintents.RealWindowClosing(); + if (m_printcontrol != null) + m_printcontrol.RealWindowClosing(); } else { @@ -433,6 +449,8 @@ namespace gsview m_gsoutput.Hide(); if (m_outputintents != null) m_outputintents.Hide(); + if (m_printcontrol != null) + m_printcontrol.Hide(); } } @@ -707,6 +725,12 @@ namespace gsview if (m_password != null && m_password.IsActive) m_password.Close(); + if (m_printcontrol != null && m_printcontrol.IsActive) + { + m_printcontrol.Close(); + m_printcontrol = null; + } + if (m_infowindow != null && m_infowindow.IsActive) m_infowindow.Close(); @@ -1743,47 +1767,40 @@ namespace gsview if (!m_file_open) return; - /* If file is already xps then gs need not do this */ - if (!m_isXPS) + if (m_printcontrol == null) { - xaml_DistillProgress.Value = 0; - 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; - } + m_printcontrol = new PrintControl(m_num_pages, m_currpage); + m_printcontrol.PrintDiagUpdatePreview += new PrintControl.PrintDiagCallBackPreview(PrintDiagUpdatePreview); + m_printcontrol.PrintDiagPrint += new PrintControl.PrintDiagCallBackPrint(PrintDiagPrint); + m_printcontrol.PrintDLLProblemMain += new PrintControl.PrintDLLProblem(gsDLL); + m_printcontrol.Activate(); + m_printcontrol.Show(); /* Makes it modal */ + PrintDiagEventArgs args = new PrintDiagEventArgs(0); + PrintDiagUpdatePreview(null, args); } else - PrintXPS(m_currfile); + m_printcontrol.Show(); + return; } private void PrintXPS(String file) { gsprint ghostprint = new gsprint(); - System.Windows.Controls.PrintDialog pDialog = ghostprint.GetPrintDialog(); - if (pDialog == null) - return; /* We have to create the XPS document on a different thread */ XpsDocument xpsDocument = new XpsDocument(file, FileAccess.Read); FixedDocumentSequence fixedDocSeq = xpsDocument.GetFixedDocumentSequence(); - PrintQueue printQueue = pDialog.PrintQueue; + System.Windows.Size temp = new Size(200, 200); + fixedDocSeq.DocumentPaginator.PageSize = temp; + + PrintQueue printq = m_printcontrol.m_selectedPrinter; m_ghostprint = ghostprint; xaml_PrintGrid.Visibility = System.Windows.Visibility.Visible; xaml_PrintProgress.Value = 0; - ghostprint.Print(printQueue, fixedDocSeq); + ghostprint.Print(printq, fixedDocSeq, m_printcontrol); } private void PrintProgress(object printHelper, gsPrintEventArgs Information) @@ -4902,5 +4919,106 @@ namespace gsview m_showannot = false; RenderRange(m_currpage, false, zoom_t.NO_ZOOM, 0); } + + /* Print preview rendering and control */ + private void RenderPrintPreview(object sender, DoWorkEventArgs e) + { + BackgroundWorker worker = sender as BackgroundWorker; + List<object> genericlist = e.Argument as List<object>; + int k = (int)genericlist[0]; + int desiredMax = Constants.MAX_PRINT_PREVIEW_LENGTH; + + Point ras_size; + double scale_factor = 1.0; + Byte[] bitmap; + BlocksText charlist; + status_t code; + Annotate_t annot; + + if (ComputePageSize(k, scale_factor, out ras_size) == status_t.S_ISOK) + { + /* Adjust the scale factor to ensure max length is set as desired */ + int maxSize = Math.Max((int)ras_size.X, (int)ras_size.Y); + scale_factor = (double)desiredMax / (double)maxSize; + ComputePageSize(k, scale_factor, out ras_size); + printPreviewPage_t result; + + try + { + bitmap = new byte[(int)ras_size.X * (int)ras_size.Y * 4]; + code = (status_t)mu_doc.RenderPage(k, bitmap, (int)ras_size.X, + (int)ras_size.Y, scale_factor, false, true, + false, out charlist, m_showannot, out annot); + result.width = (int)ras_size.X; + result.height = (int)ras_size.Y; + result.bitmap = bitmap; + ComputePageSize(k, 1.0, out ras_size); + result.height_inches = ras_size.Y / 72.0; + result.width_inches = ras_size.X / 72.0; + e.Result = result; + } + catch (OutOfMemoryException em) + { + Console.WriteLine("Memory allocation failed print preview page " + k + em.Message + "\n"); + } + } + } + + private void RenderPrintPreviewCompleted(object sender, RunWorkerCompletedEventArgs e) + { + BitmapSource BitMapSrc; + printPreviewPage_t Result = (printPreviewPage_t)e.Result; + + int stride = Result.width * 4; + BitMapSrc = BitmapSource.Create(Result.width, Result.height, + 72, 72, PixelFormats.Pbgra32, BitmapPalettes.Halftone256, Result.bitmap, stride); + + m_printcontrol.SetImage(BitMapSrc, Result.height_inches, Result.width_inches); + } + + private bool PrintDiagUpdatePreview(object PrintDiag, PrintDiagEventArgs args) + { + try + { + m_printerpreview = new BackgroundWorker(); + m_printerpreview.WorkerReportsProgress = false; + m_printerpreview.WorkerSupportsCancellation = false; + m_printerpreview.DoWork += new DoWorkEventHandler(RenderPrintPreview); + m_printerpreview.RunWorkerCompleted += new RunWorkerCompletedEventHandler(RenderPrintPreviewCompleted); + var arguments = new List<object>(); + arguments.Add(args.m_page); + m_printerpreview.RunWorkerAsync(arguments); + } + catch (OutOfMemoryException e) + { + Console.WriteLine("Memory allocation failed during printpreview render\n"); + ShowMessage(NotifyType_t.MESS_ERROR, "Out of memory: " + e.Message); + } + return true; + } + + private void PrintDiagPrint(object PrintDiag) + { + + /* If file is already xps then gs need not do this */ + if (!m_isXPS) + { + xaml_DistillProgress.Value = 0; + if (m_ghostscript.CreateXPS(m_currfile, Constants.DEFAULT_GS_RES, m_num_pages, m_printcontrol) == gsStatus.GS_BUSY) + { + ShowMessage(NotifyType_t.MESS_STATUS, "GS currently busy"); + return; + } + else + { + 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; + } + } + else + PrintXPS(m_currfile); + } } }
\ No newline at end of file diff --git a/platform/windows/gsview/PrintControl.xaml b/platform/windows/gsview/PrintControl.xaml new file mode 100644 index 00000000..8b9c30ae --- /dev/null +++ b/platform/windows/gsview/PrintControl.xaml @@ -0,0 +1,247 @@ +<Window x:Class="gsview.PrintControl" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + Title="gsview print" Height="650" Width="653" + SizeToContent="WidthAndHeight" ResizeMode="NoResize"> + + + <Window.Resources> + <Style x:Key="MySimpleScrollBar" TargetType="{x:Type ScrollBar}"> + <Setter Property="Stylus.IsFlicksEnabled" Value="false"/> + <Setter Property="Width" Value="Auto"/> + <Setter Property="MinHeight" Value="30"/> + <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/> + <Setter Property="Template"> + <Setter.Value> + <ControlTemplate TargetType="{x:Type ScrollBar}"> + <Border BorderThickness="1" BorderBrush="Gray"> + <Grid Margin="2"> + <Grid.ColumnDefinitions> + <ColumnDefinition/> + <ColumnDefinition /> + </Grid.ColumnDefinitions> + <TextBox VerticalAlignment="Center" FontSize="12" MinWidth="25" Text="{Binding Value, RelativeSource={RelativeSource TemplatedParent}}"/> + <Grid Grid.Column="1" x:Name="GridRoot" Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" Background="{TemplateBinding Background}"> + <Grid.RowDefinitions> + <RowDefinition MaxHeight="18"/> + <RowDefinition Height="0.00001*"/> + <RowDefinition MaxHeight="18"/> + </Grid.RowDefinitions> + <RepeatButton x:Name="DecreaseRepeat" Command="ScrollBar.LineDownCommand" Focusable="False"> + <Grid> + <Path x:Name="DecreaseArrow" Stroke="{TemplateBinding Foreground}" StrokeThickness="1" Data="M 0 4 L 8 4 L 4 0 Z"/> + </Grid> + </RepeatButton> + <RepeatButton Grid.Row="2" x:Name="IncreaseRepeat" Command="ScrollBar.LineUpCommand" Focusable="False"> + <Grid> + <Path x:Name="IncreaseArrow" Stroke="{TemplateBinding Foreground}" StrokeThickness="1" Data="M 0 0 L 4 4 L 8 0 Z"/> + </Grid> + </RepeatButton> + </Grid> + </Grid> + </Border> + </ControlTemplate> + </Setter.Value> + </Setter> + </Style> + </Window.Resources> + + <DockPanel Background="WhiteSmoke" LastChildFill="False" Margin="0,0,0,0"> + <GroupBox Header="Printer" Height="100" Width="500" DockPanel.Dock="Top" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="15,15,0,0"> + <Grid Background="WhiteSmoke" Visibility="Visible" > + <Grid.ColumnDefinitions> + <ColumnDefinition Width="Auto" /> + <ColumnDefinition Width="*" /> + <ColumnDefinition Width="Auto" /> + </Grid.ColumnDefinitions> + <Grid Grid.Column="0" Grid.Row="0" Background="WhiteSmoke"> + <Grid.RowDefinitions> + <RowDefinition Height="30" /> + <RowDefinition Height="30" /> + </Grid.RowDefinitions> + <TextBox Grid.Column="0" Grid.Row="0" Text="Name:" FontSize="12" FontFamily="Segoe UI" Background="WhiteSmoke" BorderThickness="0" VerticalAlignment="Center"/> + <TextBox Grid.Column="0" Grid.Row="1" Text="Status:" FontSize="12" FontFamily="Segoe UI" Background="WhiteSmoke" BorderThickness="0" VerticalAlignment="Center"/> + </Grid> + <Grid Grid.Column="1" Grid.Row="0" Background="WhiteSmoke"> + <Grid.RowDefinitions> + <RowDefinition Height="30" /> + <RowDefinition Height="30" /> + </Grid.RowDefinitions> + <ComboBox Grid.Column="0" Grid.Row="0" x:Name="xaml_selPrinter" SelectionChanged="selPrinterChanged" Width="225" HorizontalAlignment="Left" Margin="10,0,0,0" VerticalAlignment="Center" > + <ComboBox.ItemTemplate> + <DataTemplate> + <StackPanel Orientation="Horizontal"> + <TextBlock FontSize="11" FontFamily="Segoe UI" Text="{Binding Name}" /> + </StackPanel> + </DataTemplate> + </ComboBox.ItemTemplate> + </ComboBox> + <TextBox Grid.Column="0" Grid.Row="1" x:Name="xaml_Status" FontSize="12" FontFamily="Segoe UI" Text="" Margin="105,92,497,301" Background="WhiteSmoke" BorderThickness="0"/> + </Grid> + <Grid Grid.Column="2" Grid.Row="0" Background="WhiteSmoke"> + <Grid.RowDefinitions> + <RowDefinition Height="30" /> + </Grid.RowDefinitions> + <Button Grid.Column="0" Grid.Row="0" Content="Properties" FontSize="12" FontFamily="Segoe UI" HorizontalAlignment="Center" Margin="0, 0, 30, 0" VerticalAlignment="Center" Width="75" Click="ShowProperties"/> + </Grid> + </Grid> + </GroupBox> + <Grid DockPanel.Dock="Left" Background="WhiteSmoke" Visibility="Visible"> + <Grid.RowDefinitions> + <RowDefinition Height="Auto" /> + <RowDefinition Height="Auto" /> + <RowDefinition Height="Auto" /> + </Grid.RowDefinitions> + <GroupBox Grid.Column="0" Grid.Row="0" Header="Print Range" Height="150" Width="250" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="15,15,0,0"> + <Grid Background="WhiteSmoke" Visibility="Visible" > + <Grid.RowDefinitions> + <RowDefinition Height="30" /> + <RowDefinition Height="30" /> + <RowDefinition Height="30" /> + <RowDefinition Height="30" /> + </Grid.RowDefinitions> + <Grid.ColumnDefinitions> + <ColumnDefinition Width="90" /> + <ColumnDefinition Width="Auto" /> + </Grid.ColumnDefinitions> + <RadioButton Grid.Column="0" Grid.Row="0" Name="xaml_rbAll" VerticalAlignment="Center" GroupName="PageRange" Checked="AllPages">All</RadioButton> + <RadioButton Grid.Column="0" Grid.Row="1" Name="xaml_rbCurrent" VerticalAlignment="Center" GroupName="PageRange" Checked="CurrentPage">Current page</RadioButton> + <RadioButton Grid.Column="0" Grid.Row="2" Name="xaml_rbPages" VerticalAlignment="Center" GroupName="PageRange" Checked="PageRange">Pages</RadioButton> + + <TextBox x:Name="xaml_pagerange" Grid.Column="1" Grid.Row="2" Width="100" Height="20" VerticalScrollBarVisibility="Hidden" HorizontalAlignment="Left" + HorizontalScrollBarVisibility="Hidden" VerticalAlignment="Center" FontSize="12" FontFamily="Segoe UI" Margin="0,0,0,0" PreviewKeyDown="PageNumberEnter"/> + + <TextBox x:Name="xaml_invalid" Grid.Column="1" Grid.Row="1" Width="Auto" Height="Auto" VerticalScrollBarVisibility="Hidden" HorizontalAlignment="Center" Background="WhiteSmoke" Visibility="Collapsed" + HorizontalScrollBarVisibility="Hidden" VerticalAlignment="Center" Foreground="Red" Text="Invalid Range! (3-5, 7) e.g." FontSize="12" FontFamily="Segoe UI" Margin="0,0,0,0" PreviewKeyDown="PageNumberEnter"/> + + + <TextBox Grid.Column="0" Grid.Row="3" VerticalAlignment="Center" Text="Subset:" FontSize="12" FontFamily="Segoe UI" Background="WhiteSmoke" BorderThickness="0"/> + <ComboBox Grid.Column="1" Grid.Row="3" x:Name="xaml_Subset" SelectionChanged="Subset_SelectionChanged" Width="140" Height="Auto" VerticalAlignment="Center" HorizontalAlignment="Left"> + <ComboBoxItem Name="all" FontSize="11" FontFamily="Segoe UI">All pages in range</ComboBoxItem> + <ComboBoxItem Name="odd" FontSize="11" FontFamily="Segoe UI">Odd pages only</ComboBoxItem> + <ComboBoxItem Name="even" FontSize="11" FontFamily="Segoe UI">Even pages only</ComboBoxItem> + </ComboBox> + </Grid> + </GroupBox> + + <GroupBox Grid.Column="0" Grid.Row="1" Header="Page Handling" Height="90" Width="250" Margin="15,15,0,0" DockPanel.Dock="Left" HorizontalAlignment="Center" VerticalAlignment="Center" > + <Grid Background="WhiteSmoke" Visibility="Visible" Height="103" VerticalAlignment="Top"> + <Grid.RowDefinitions> + <RowDefinition Height="Auto" /> + <RowDefinition Height="Auto" /> + </Grid.RowDefinitions> + <Grid.ColumnDefinitions> + <ColumnDefinition Width="90" /> + <ColumnDefinition Width="Auto" /> + </Grid.ColumnDefinitions> + <TextBox Grid.Column="0" Grid.Row="0" VerticalAlignment="Center" Text="Copies:" FontSize="12" FontFamily="Segoe UI" Background="WhiteSmoke" BorderThickness="0" /> + <ScrollBar Grid.Column="1" Grid.Row="0" x:Name="xaml_Copies" HorizontalAlignment="Left" Style="{DynamicResource MySimpleScrollBar}" VerticalAlignment="Top" Value="1" Maximum="999" SmallChange="1" Height="15" ValueChanged="xaml_Copies_ValueChanged"/> + <CheckBox x:Name="xaml_autofit" Grid.Column="0" Grid.Row="2" Content="Auto-Fit" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Checked="AutoFit_Checked" Unchecked="AutoFit_Unchecked" Grid.ColumnSpan="2"/> + </Grid> + </GroupBox> + <Grid Background="WhiteSmoke" Grid.Column="0" Grid.Row="2" Visibility="Visible" Margin="0, 50, 0, 0" HorizontalAlignment="Center"> + <Grid.ColumnDefinitions> + <ColumnDefinition Width="Auto" /> + <ColumnDefinition Width="Auto" /> + </Grid.ColumnDefinitions> + <Button Grid.Column="0" Grid.Row="0" Content="OK" FontSize="12" FontFamily="Segoe UI" HorizontalAlignment="Center" VerticalAlignment="Center" Width="74" Click="ClickOK" Margin="20,0,0,0"/> + <Button Grid.Column="1" Grid.Row="0" Content="Cancel" FontSize="12" FontFamily="Segoe UI" HorizontalAlignment="Center" VerticalAlignment="Center" Width="74" Click="ClickCancel" Margin="40,0,0,0"/> + </Grid> + </Grid> + + + <GroupBox Header="Preview" Height="450" Width="350" DockPanel.Dock="Right" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,15,15,0"> + <Grid Background="WhiteSmoke" Visibility="Visible" > + <Grid.RowDefinitions> + <RowDefinition Height="Auto" /> + <RowDefinition Height="*" /> + <RowDefinition Height="40" /> + <RowDefinition Height="40" /> + <RowDefinition Height="40" /> + </Grid.RowDefinitions> + <Grid.ColumnDefinitions> + <ColumnDefinition Width="Auto" /> + <ColumnDefinition Width="*" /> + </Grid.ColumnDefinitions> + <Canvas x:Name="xaml_TopArrowCanvas" Grid.Row="0" Grid.Column="1" VerticalAlignment="Bottom" HorizontalAlignment="Left" Margin="0,0,0,25" Height="0" Width="0" Visibility="Collapsed"> + <Grid Background="WhiteSmoke" HorizontalAlignment="Center"> + <Grid.RowDefinitions> + <RowDefinition Height="*" /> + <RowDefinition Height="*" /> + </Grid.RowDefinitions> + <Line x:Name="xaml_topsize" Grid.Row="1" Y1="0" X1="0" X2="100" Y2="0" Stroke="Black" StrokeThickness="1"/> + <Line x:Name="xaml_topleftbottomarrow" Grid.Row="1" Y1="0" X1="0" X2="7" Y2="7" Stroke="Black" StrokeThickness="1" /> + <Line x:Name="xaml_toplefttoparrow" Grid.Row="1" Y1="0" X1="0" X2="7" Y2="-7" Stroke="Black" StrokeThickness="1" /> + <Line x:Name="xaml_toprighttoparrow" Grid.Row="1" Y1="-7" X1="93" X2="100" Y2="0" Stroke="Black" StrokeThickness="1" /> + <Line x:Name="xaml_toprightbottomarrow" Grid.Row="1" Y1="7" X1="93" X2="100" Y2="0" Stroke="Black" StrokeThickness="1" /> + <TextBlock x:Name="xaml_topsizevalue" Text="100" Grid.Row="0" HorizontalAlignment="Center"/> + </Grid> + </Canvas> + + <Canvas x:Name="xaml_LeftArrowCanvas" Grid.Row="1" Grid.Column="0" Height="Auto" Width="40" VerticalAlignment="Top" HorizontalAlignment="Center" Visibility="Collapsed"> + <Grid Background="WhiteSmoke" VerticalAlignment="Top" HorizontalAlignment="Center"> + <Grid.ColumnDefinitions> + <ColumnDefinition Width="*" /> + <ColumnDefinition Width="*" /> + </Grid.ColumnDefinitions> + <Line x:Name="xaml_leftsize" Grid.Column="1" Y1="0" X1="0" X2="0" Y2="100" Stroke="Black" StrokeThickness="1" /> + <Line x:Name="xaml_lefttopleft" Grid.Column="1" Y1="0" X1="0" X2="-7" Y2="7" Stroke="Black" StrokeThickness="1" /> + <Line x:Name="xaml_lefttopright" Grid.Column="1" Y1="0" X1="0" X2="7" Y2="7" Stroke="Black" StrokeThickness="1" /> + <Line x:Name="xaml_leftbottomleft" Grid.Column="1" Y1="93" X1="-7" X2="0" Y2="100" Stroke="Black" StrokeThickness="1" /> + <Line x:Name="xaml_leftbottomright" Grid.Column="1" Y1="93" X1="7" X2="0" Y2="100" Stroke="Black" StrokeThickness="1" /> + <TextBlock x:Name="xaml_leftsizevalue" Text="100" Grid.Column="0" VerticalAlignment="Center" Margin="0,0,10,0"/> + </Grid> + </Canvas> + + <!-- Draw the white paper full size white --> + <Rectangle x:Name="xaml_PreviewPaper" Visibility="Collapsed" Fill="White" Grid.Column="1" Grid.Row="1" Height="0" Width="0" VerticalAlignment="Top" HorizontalAlignment="Left"/> + + <!-- Draw the whole image --> + <Rectangle x:Name="xaml_PreviewImageRect" Visibility="Collapsed" Stroke="Red" Grid.Column="1" Grid.Row="1" Height="0" Width="0" VerticalAlignment="Top" HorizontalAlignment="Left"> + <Rectangle.Fill> + <ImageBrush x:Name="xaml_ImagePreview"> + </ImageBrush> + </Rectangle.Fill> + </Rectangle> + + <!-- Draw the gray shade over it --> + <Rectangle x:Name="xaml_PreviewGrayRect" Visibility="Collapsed" Stroke="Green" Fill="#7f7f7f7f" Grid.Column="1" Grid.Row="1" Height="0" Width="0" VerticalAlignment="Top" HorizontalAlignment="Left"/> + + <!-- Redraw with clipping --> + <Rectangle x:Name="xaml_PreviewImageRectClip" Visibility="Collapsed" Stroke="Blue" Grid.Column="1" Grid.Row="1" Height="0" Width="0" VerticalAlignment="Top" HorizontalAlignment="Left"> + <Rectangle.Fill> + <ImageBrush x:Name="xaml_ImagePreviewClip"> + </ImageBrush> + </Rectangle.Fill> + <Rectangle.Clip> + <RectangleGeometry x:Name="xaml_ImagePreviewClipGeom" Rect="0 0 50 100"/> + </Rectangle.Clip> + </Rectangle> + + <!-- Draw the final full black bounding rect for the paper--> + <Rectangle x:Name="xaml_PreviewPaperOuterRect" Stroke="Black" Fill="#00000000" Grid.Column="1" Grid.Row="1" Height="0" Width="0" VerticalAlignment="Top" HorizontalAlignment="Left"/> + + <Grid Grid.Column="1" Grid.Row="2" Height="Auto"> + <Grid.RowDefinitions> + <RowDefinition Height="Auto" /> + <RowDefinition Height="Auto" /> + </Grid.RowDefinitions> + <TextBox Visibility="Collapsed" x:Name="xaml_pagesize" Grid.Column="0" Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Left" FontSize="12" FontFamily="Segoe UI" Background="WhiteSmoke" BorderThickness="0" Height="16" Width="Auto" /> + <TextBox Visibility="Collapsed" x:Name="xaml_docsize" Grid.Column="0" Grid.Row="0" VerticalAlignment="Center" HorizontalAlignment="Left" FontSize="12" FontFamily="Segoe UI" Background="WhiteSmoke" BorderThickness="0" Height="16" Width="Auto" /> + </Grid> + + <TextBox x:Name="xaml_pagecount" Grid.Column="0" Grid.Row="3" VerticalAlignment="Center" HorizontalAlignment="Right" Text="1/1" FontSize="12" FontFamily="Segoe UI" Background="WhiteSmoke" BorderThickness="0" Height="16" Margin="0,12" Width="Auto" /> + <Slider x:Name="xaml_pageslider" IsSnapToTickEnabled="True" Grid.Column="1" Grid.Row="3" Maximum="100" VerticalAlignment="Center" Margin="15,11,36,11" Height="18" PreviewMouseUp="PageSelect_DragCompleted"/> + <TextBox Grid.Column="0" Grid.Row="4" VerticalAlignment="Center" HorizontalAlignment="Right" Text="Units:" FontSize="12" FontFamily="Segoe UI" Background="WhiteSmoke" BorderThickness="0" Height="16" Margin="0,12" Width="Auto" /> + <Grid Grid.Column="1" Grid.Row="4"> + <Grid.ColumnDefinitions> + <ColumnDefinition Width="Auto" /> + <ColumnDefinition Width="Auto" /> + </Grid.ColumnDefinitions> + <RadioButton Grid.Column="0" Grid.Row="0" Name="xaml_inches" VerticalAlignment="Center" GroupName="units" Checked="Inches" Margin="5,0,0,0">inches</RadioButton> + <RadioButton Grid.Column="1" Grid.Row="0" Name="xaml_cm" VerticalAlignment="Center" GroupName="units" Checked="Centimeters" Margin="5,0,0,0">cm</RadioButton> + </Grid> + </Grid> + </GroupBox> + </DockPanel> +</Window> diff --git a/platform/windows/gsview/PrintControl.xaml.cs b/platform/windows/gsview/PrintControl.xaml.cs new file mode 100644 index 00000000..c24fad17 --- /dev/null +++ b/platform/windows/gsview/PrintControl.xaml.cs @@ -0,0 +1,697 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; +using System.Printing; +using System.Drawing.Printing; +using System.Runtime.InteropServices; +using System.Windows.Interop; +using System.Text.RegularExpressions; + +namespace gsview +{ + /// <summary> + /// Interaction logic for PrintControl.xaml + /// </summary> + /// + + static class NATIVEWIN + { + public const int IDOK = 1; + public const int IDCANCEL = 2; + public const int DM_OUT_BUFFER = 2; + public const int DM_IN_BUFFER = 8; + public const int DM_IN_PROMPT = 4; + public const int DM_ORIENTATION = 1; + public const int DM_PAPERSIZE = 2; + public const int DM_PAPERLENGTH = 4; + public const int DM_WIDTH = 8; + public const int DMORIENT_PORTRAIT = 1; + public const int DMORIENT_LANDSCAPE = 2; + } + + public enum PrintPages_t + { + RANGE = 2, + CURRENT = 1, + ALL = 0 + } + + public enum PageSubset_t + { + ALL = 0, + ODD = 1, + EVEN = 2 + } + + public enum PageScale_t + { + NONE = 0, + FIT = 1, + } + + public enum Units_t + { + INCHES = 0, + CM = 1 + } + + public class PrintDiagEventArgs : EventArgs + { + public int m_page; + + public PrintDiagEventArgs(int page) + { + m_page = page; + } + } + + public class PrintRanges + { + public List<bool> ToPrint; + public bool HasEvens; + public bool HasOdds; + public int NumberPages; + + public PrintRanges(int number_pages) + { + ToPrint = new List<bool>(number_pages); + NumberPages = 0; + HasEvens = false; + HasOdds = false; + } + + public void InitRange(Match match) + { + NumberPages = 0; + HasEvens = false; + HasOdds = false; + + for (int k = 0; k < ToPrint.Count; k++) + { + if (CheckValue(match, k)) + { + NumberPages = NumberPages + 1; + ToPrint[k] = true; + if ((k+1) % 2 != 0) + HasOdds = true; + else + HasEvens = true; + } + else + ToPrint[k] = false; + } + } + + private bool CheckValue(Match match, int k) + { + return false; + } + } + + public partial class PrintControl : Window + { + private LocalPrintServer m_printServer; + public PrintQueue m_selectedPrinter = null; + String m_status; + PrintPages_t m_pages_setting; + PageSubset_t m_page_subset; + public double m_page_scale; + Units_t m_units; + int m_numpages; + int m_currpage; + PrintCapabilities m_printcap; + public PageSettings m_pagedetails; + TranslateTransform m_trans_pap; + TranslateTransform m_trans_doc; + double m_doc_height; + double m_doc_width; + public bool m_isrotated; + PrintRanges m_range_pages; + public int m_numcopies; + bool m_initdone; + bool m_is64bit; + + /* Callback to main to get preview images */ + internal delegate bool PrintDiagCallBackPreview(object gsObject, PrintDiagEventArgs info); + internal event PrintDiagCallBackPreview PrintDiagUpdatePreview; + /* Callback to perform printing */ + internal delegate void PrintDiagCallBackPrint(object gsObject); + internal event PrintDiagCallBackPrint PrintDiagPrint; + /* Callback to report problems */ + internal delegate void PrintDLLProblem(object gsObject, String mess); + internal event PrintDLLProblem PrintDLLProblemMain; + + /* Helper for displaying the custom printer dialog settings */ + #region DLLInterface + [DllImport("gsprint64.dll", EntryPoint = "ShowPropertiesDialog", CharSet = CharSet.Ansi, + CallingConvention = CallingConvention.StdCall)] + private static extern int ShowPropertiesDialog64(IntPtr hwnd, IntPtr printername, bool show_diag ); + [DllImport("gsprint32.dll", EntryPoint = "ShowPropertiesDialog", CharSet = CharSet.Ansi, + CallingConvention = CallingConvention.StdCall)] + private static extern int ShowPropertiesDialog32(IntPtr hwnd, IntPtr printername, bool show_diag); + + #endregion DLLInterface + + #region DLLErrorCatch + /* In case the DLL is not found we need to wrap the methods up with + * a try/catch. Also select 32 or 64 bit DLL at this time. This + * C# code is compiled as ANYCPU type */ + private int tc_ShowPropertiesDialog(IntPtr hwnd, IntPtr printername, bool show_prop) + { + int code; + + try + { + if (m_is64bit) + code = ShowPropertiesDialog64(hwnd, printername, show_prop); + else + code = ShowPropertiesDialog32(hwnd, printername, show_prop); + } + catch (DllNotFoundException) + { + /* DLL not found */ + String output = "DllNotFoundException: gsprint DLL not found"; + PrintDLLProblemMain(this, output); + return -1; + } + catch (BadImageFormatException) + { + /* Using 32 bit with 64 or vice versa */ + String output = "BadImageFormatException: Incorrect gsprint DLL"; + PrintDLLProblemMain(this, output); + return -1; + } + return code; + } + #endregion DLLErrorCatch + + /* Populate the printers */ + private void InitPrinterList() + { + PrintQueueCollection printQueuesOnLocalServer = + m_printServer.GetPrintQueues(new[] {EnumeratedPrintQueueTypes.Local, EnumeratedPrintQueueTypes.Connections}); + + this.xaml_selPrinter.ItemsSource = printQueuesOnLocalServer; + if (m_selectedPrinter != null) + { + foreach (PrintQueue pq in printQueuesOnLocalServer) + { + if (pq.FullName == m_selectedPrinter.FullName) + { + this.xaml_selPrinter.SelectedItem = pq; + break; + } + } + } + } + + /* Initialize */ + public PrintControl(int num_pages, int curr_page) + { + PrinterSettings ps = new PrinterSettings(); + + this.Closing += new System.ComponentModel.CancelEventHandler(FakeWindowClosing); + InitializeComponent(); + m_printServer = new LocalPrintServer(); + m_selectedPrinter = LocalPrintServer.GetDefaultPrintQueue(); + InitPrinterList(); + ps.PrinterName = m_selectedPrinter.FullName; + m_pagedetails = ps.DefaultPageSettings; + + + xaml_rbAll.IsChecked = true; + m_pages_setting = PrintPages_t.ALL; + m_page_subset = PageSubset_t.ALL; + xaml_Subset.SelectedIndex = (int) m_page_subset; + + xaml_autofit.IsChecked = false; + + xaml_inches.IsChecked = true; + m_units = Units_t.INCHES; + + m_currpage = curr_page; + m_numpages = num_pages; + xaml_pagecount.Text = "1/" + num_pages; + xaml_pageslider.Maximum = num_pages - 1; + + m_printcap = m_selectedPrinter.GetPrintCapabilities(); + + m_trans_pap = new TranslateTransform(0, 0); + m_trans_doc = new TranslateTransform(0, 0); + m_isrotated = false; + + /* Data range case */ + m_range_pages = new PrintRanges(m_numpages); + m_page_scale = 1.0; + + m_numcopies = 1; + m_initdone = false; + m_is64bit = Environment.Is64BitOperatingSystem && + Environment.Is64BitProcess; + } + + void FakeWindowClosing(object sender, System.ComponentModel.CancelEventArgs e) + { + e.Cancel = true; + this.Hide(); + } + + public void RealWindowClosing() + { + this.Closing -= new System.ComponentModel.CancelEventHandler(FakeWindowClosing); + this.Close(); + } + + /* Displays and updates the custom printer dialog settings. One can + * either do this with pinvoke of the various commands in winspool or + * go ahead and handle it in our own dll, which is what I decided to + * do. */ + private void ShowProperties(object sender, RoutedEventArgs e) + { + PrinterChanged(true); + } + + private void PrinterChanged(bool show_prop) + { + if (m_selectedPrinter != null) + { + var ptrNameGC = new GCHandle(); + var temp = System.Text.Encoding.UTF8.GetBytes(m_selectedPrinter.FullName.ToCharArray()); + ptrNameGC = GCHandle.Alloc(temp, GCHandleType.Pinned); + int res = tc_ShowPropertiesDialog(new WindowInteropHelper(this).Handle, ptrNameGC.AddrOfPinnedObject(), show_prop); + ptrNameGC.Free(); + if (res >= 0) + { + PrinterSettings ps = new PrinterSettings(); + ps.PrinterName = m_selectedPrinter.FullName; + m_pagedetails = ps.DefaultPageSettings; + UpdateView(); + } + } + } + + /* Printer selection changed */ + private void selPrinterChanged(object sender, SelectionChangedEventArgs e) + { + m_selectedPrinter = this.xaml_selPrinter.SelectedItem as PrintQueue; + GetPrinterStatus(); + if (m_initdone) + PrinterChanged(false); + } + + /* Printer Status */ + private void GetPrinterStatus() + { + if (m_selectedPrinter.IsBusy) + m_status = "Busy"; + else if (m_selectedPrinter.IsNotAvailable) + m_status = "Not Available"; + else if (m_selectedPrinter.IsOffline) + m_status = "Offline"; + else if (m_selectedPrinter.IsOutOfMemory) + m_status = "Out Of Memory"; + else if (m_selectedPrinter.IsOutOfPaper) + m_status = "Out Of Paper"; + else if (m_selectedPrinter.IsOutputBinFull) + m_status = "Output Bin Full"; + else if (m_selectedPrinter.IsPaperJammed) + m_status = "Paper Jam"; + else if (m_selectedPrinter.IsPaused) + m_status = "Paused"; + else if (m_selectedPrinter.IsPendingDeletion) + m_status = "Paused"; + else if (m_selectedPrinter.IsPrinting) + m_status = "Printing"; + else if (m_selectedPrinter.IsProcessing) + m_status = "Processing"; + else if (m_selectedPrinter.IsWaiting) + m_status = "Waiting"; + else if (m_selectedPrinter.IsWarmingUp) + m_status = "Warming Up"; + else + m_status = "Ready"; + xaml_Status.Text = m_status; + } + + private void Subset_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + /* On current page, only All is allowed */ + m_page_subset = (PageSubset_t) xaml_Subset.SelectedIndex; + if (m_pages_setting == PrintPages_t.CURRENT && + m_page_subset != PageSubset_t.ALL) + xaml_Subset.SelectedIndex = (int) PageSubset_t.ALL; + + /* Only one page, can't use even */ + if (m_pages_setting == PrintPages_t.ALL && + m_page_subset == PageSubset_t.EVEN && + m_numpages == 1) + xaml_Subset.SelectedIndex = (int)PageSubset_t.ALL; + } + + private void AllPages(object sender, RoutedEventArgs e) + { + xaml_invalid.Visibility = System.Windows.Visibility.Collapsed; + xaml_pageslider.Maximum = m_numpages - 1; + xaml_pageslider.Value = m_currpage; + xaml_pagecount.Text = (m_currpage + 1) + "/" + m_numpages; + m_pages_setting = PrintPages_t.ALL; + } + + private void CurrentPage(object sender, RoutedEventArgs e) + { + xaml_invalid.Visibility = System.Windows.Visibility.Collapsed; + m_pages_setting = PrintPages_t.CURRENT; + xaml_pagecount.Text = "1/1"; + xaml_pageslider.Maximum = 0; + xaml_pageslider.Value = 0; + PrintDiagEventArgs info = new PrintDiagEventArgs(m_currpage); + PrintDiagUpdatePreview(this, info); + } + + private void PageRange(object sender, RoutedEventArgs e) + { + xaml_invalid.Visibility = System.Windows.Visibility.Collapsed; + m_pages_setting = PrintPages_t.RANGE; + } + + private void UpdateScaleInfo() + { + /* + if (m_page_scale_type == PageScale_t.NONE) + { + double temp_width_doc = Math.Truncate(m_doc_width * 100.0) / 100.0; + double temp_height_doc = Math.Truncate(m_doc_height * 100.0) / 100.0; + double temp_width_page = m_pagedetails.Bounds.Width / 100; + double temp_height_page = m_pagedetails.Bounds.Height / 100; + + if (m_units == Units_t.CM) + { + temp_height_doc = (Math.Truncate(temp_height_doc * 2.54 * 100) / 100.0); + temp_width_doc = (Math.Truncate(temp_width_doc * 2.54 * 100) / 100.0); + temp_height_page = (Math.Truncate(temp_height_page * 2.54 * 100) / 100.0); + temp_width_page = (Math.Truncate(temp_width_page * 2.54 * 100) / 100.0); + } + xaml_pagesize.Text = "Paper:\t\t" + temp_width_page + " x " + temp_height_page; + xaml_docsize.Text = "Document:\t" + temp_width_doc + " x " + temp_height_doc; ; + xaml_pagesize.Visibility = System.Windows.Visibility.Visible; + xaml_docsize.Visibility = System.Windows.Visibility.Visible; + } + else + { + xaml_pagesize.Visibility = System.Windows.Visibility.Collapsed; + xaml_docsize.Visibility = System.Windows.Visibility.Collapsed; + } + * */ + } + + private void Inches(object sender, RoutedEventArgs e) + { + m_units = Units_t.INCHES; + UpdateUnits(); + UpdateScaleInfo(); + } + + private void Centimeters(object sender, RoutedEventArgs e) + { + m_units = Units_t.CM; + UpdateUnits(); + UpdateScaleInfo(); + } + + public void SetImage(BitmapSource image_in, double doc_height_in, + double doc_width_in) + { + xaml_PreviewImageRect.Visibility = System.Windows.Visibility.Collapsed; + xaml_PreviewGrayRect.Visibility = System.Windows.Visibility.Collapsed; + xaml_PreviewPaper.Visibility = System.Windows.Visibility.Collapsed; + + m_doc_width = doc_width_in; + m_doc_height = doc_height_in; + xaml_ImagePreview.ImageSource = image_in; + xaml_ImagePreviewClip.ImageSource = image_in; + + UpdateView(); + } + + private void UpdateView() + { + /* For our display we compute the page size as well as the paper size */ + /* The max length sets our scaling of each component */ + /* We then determine if any additional scaling is needed or translation + * based upon the settings of m_page_scale_type as well as the autofit + * and scale setting */ + double page_height = m_pagedetails.Bounds.Height; + double page_width = m_pagedetails.Bounds.Width; + double doc_height = m_doc_height * 100; + double doc_width = m_doc_width * 100; + bool autofit = (xaml_autofit.IsChecked == true); + bool center; + /* bool center = (xaml_center.IsChecked == true); */ + double scale_height; + double scale_width; + double max_scale; + double doc_offset_x = 0; + double doc_offset_y = 0; + double pap_offset_x = 0; + double pap_offset_y = 0; + Rect clip_rect; + + center = autofit; /* I may separate these later */ + m_page_scale = 1.0; + m_isrotated = false; + if (autofit && + ((m_pagedetails.Bounds.Height > m_pagedetails.Bounds.Width && doc_height < doc_width) || + (m_pagedetails.Bounds.Height < m_pagedetails.Bounds.Width && doc_height > doc_width))) + { + page_width = m_pagedetails.Bounds.Height; + page_height = m_pagedetails.Bounds.Width; + m_isrotated = true; + } + + /* Scale page data if needed. */ + + if (xaml_autofit.IsChecked == true) + { + scale_height = page_height / doc_height; + scale_width = page_width / doc_width; + max_scale = Math.Min(scale_height, scale_width); + + /* Adjust the doc size to fit in the page */ + doc_height = doc_height * max_scale; + doc_width = doc_width * max_scale; + m_page_scale = max_scale; + } + + /* Now figure out our preview scaling to ensure everything fits + * in the display window */ + double max_height = Math.Max(doc_height, page_height); + double max_width = Math.Max(doc_width, page_width); + double max_length = Math.Max(max_height, max_width); + double previewscale = (double)Constants.MAX_PRINT_PREVIEW_LENGTH / max_length; + + /* Adjust size of everything */ + doc_height = doc_height * previewscale; + doc_width = doc_width * previewscale; + page_height = page_height * previewscale; + page_width = page_width * previewscale; + + xaml_PreviewImageRect.Visibility = System.Windows.Visibility.Collapsed; + xaml_PreviewGrayRect.Visibility = System.Windows.Visibility.Collapsed; + xaml_PreviewPaper.Visibility = System.Windows.Visibility.Collapsed; + + /* Compute any offsets if needed due to centering */ + if (center) + { + if (doc_height > page_height) + pap_offset_y = (doc_height - page_height) / 2.0; + else + doc_offset_y = (page_height - doc_height) / 2.0; + if (doc_width > page_width) + pap_offset_x = (doc_width - page_width) / 2.0; + else + doc_offset_x = (page_width - doc_width) / 2.0; + } + + double offset_y = 0; + + if (!autofit) + offset_y = doc_height - page_height; + + /* See if the paper needs to translate */ + if (page_height < doc_height) + m_trans_pap = new TranslateTransform(pap_offset_x, pap_offset_y + offset_y); + else + m_trans_pap = new TranslateTransform(pap_offset_x, pap_offset_y); + + /* See if the doc needs to translate */ + if (page_height > doc_height) + m_trans_doc = new TranslateTransform(doc_offset_x, doc_offset_y - offset_y); + else + m_trans_doc = new TranslateTransform(doc_offset_x, doc_offset_y); + + /* Page black outer rect */ + xaml_PreviewPaperOuterRect.RenderTransform = m_trans_pap; + xaml_PreviewPaperOuterRect.Height = page_height; + xaml_PreviewPaperOuterRect.Width = page_width; + xaml_PreviewPaperOuterRect.Visibility = System.Windows.Visibility.Visible; + + /* Paper white fill */ + xaml_PreviewPaper.RenderTransform = m_trans_pap; + xaml_PreviewPaper.Height = page_height; + xaml_PreviewPaper.Width = page_width; + xaml_PreviewPaper.Visibility = System.Windows.Visibility.Visible; + + /* The image */ + xaml_PreviewImageRect.RenderTransform = m_trans_doc; + xaml_PreviewImageRect.Height = doc_height; + xaml_PreviewImageRect.Width = doc_width; + xaml_PreviewImageRect.Visibility = System.Windows.Visibility.Visible; + + /* The gray fill (not visible) */ + xaml_PreviewGrayRect.RenderTransform = m_trans_doc; + xaml_PreviewGrayRect.Height = doc_height; + xaml_PreviewGrayRect.Width = doc_width; + xaml_PreviewGrayRect.Visibility = System.Windows.Visibility.Visible; + + /* The visible portion */ + xaml_PreviewImageRectClip.RenderTransform = m_trans_doc; + xaml_PreviewImageRectClip.Height = doc_height; + xaml_PreviewImageRectClip.Width = doc_width; + clip_rect = new Rect(pap_offset_x, pap_offset_y + offset_y, page_width, page_height); + xaml_ImagePreviewClipGeom.Rect = clip_rect; + xaml_PreviewImageRectClip.Visibility = System.Windows.Visibility.Visible; + UpdateSizes(); + UpdateScaleInfo(); + m_initdone = true; + } + + private void PageSelect_DragCompleted(object sender, MouseButtonEventArgs e) + { + if (m_pages_setting == PrintPages_t.CURRENT) + return; + + /* Get the current page view */ + int page = (int) xaml_pageslider.Value; + PrintDiagEventArgs info = new PrintDiagEventArgs(page); + PrintDiagUpdatePreview(this, info); + page = page + 1; + xaml_pagecount.Text = page + "/" + m_numpages; + } + + private void AdjustPageSize() + { + m_printcap = m_selectedPrinter.GetPrintCapabilities(); + } + + private void UpdateSizes() + { + xaml_TopArrowCanvas.RenderTransform = new TranslateTransform(m_trans_pap.X, 0); + xaml_topsize.X2 = xaml_PreviewPaper.Width; + xaml_toprighttoparrow.X1 = xaml_PreviewPaper.Width - 7; + xaml_toprighttoparrow.X2 = xaml_PreviewPaper.Width; + xaml_toprightbottomarrow.X1 = xaml_PreviewPaper.Width - 7; + xaml_toprightbottomarrow.X2 = xaml_PreviewPaper.Width; + + xaml_LeftArrowCanvas.RenderTransform = new TranslateTransform(0, m_trans_pap.Y); + xaml_leftsize.Y2 = xaml_PreviewPaper.Height; + xaml_leftbottomleft.Y1 = xaml_PreviewPaper.Height - 7; + xaml_leftbottomleft.Y2 = xaml_PreviewPaper.Height; + xaml_leftbottomright.Y1 = xaml_PreviewPaper.Height - 7; + xaml_leftbottomright.Y2 = xaml_PreviewPaper.Height; + + xaml_LeftArrowCanvas.Visibility = System.Windows.Visibility.Visible; + xaml_TopArrowCanvas.Visibility = System.Windows.Visibility.Visible; + + UpdateUnits(); + } + + private void UpdateUnits() + { + + double valHeight = m_pagedetails.Bounds.Height; + double valWidth = m_pagedetails.Bounds.Width; + + if (m_units == Units_t.INCHES) + { + if (m_isrotated) + { + xaml_topsizevalue.Text = (Math.Truncate(valHeight) / 100.0).ToString(); + xaml_leftsizevalue.Text = (Math.Truncate(valWidth) / 100.0).ToString(); + } + else + { + xaml_leftsizevalue.Text = (Math.Truncate(valHeight) / 100.0).ToString(); + xaml_topsizevalue.Text = (Math.Truncate(valWidth) / 100.0).ToString(); + } + } + else + { + if (m_isrotated) + { + xaml_topsizevalue.Text = (Math.Truncate(valHeight * 2.54) / 100.0).ToString(); + xaml_leftsizevalue.Text = (Math.Truncate(valWidth * 2.54) / 100.0).ToString(); + } + else + { + xaml_leftsizevalue.Text = (Math.Truncate(valHeight * 2.54) / 100.0).ToString(); + xaml_topsizevalue.Text = (Math.Truncate(valWidth * 2.54) / 100.0).ToString(); + } + } + } + + private void PageNumberEnter(object sender, KeyEventArgs e) + { + if (e.Key == Key.Return) + { + e.Handled = true; + string desired_page = xaml_pagerange.Text; + + Regex rangePattern = new Regex(@"^\s*\d+\s*(\-\s*\d+\s*)?(\,\s*\d+\s*(\-\s*\d+\s*)?)*$"); + + Match m = rangePattern.Match(desired_page); + if (!m.Success) + xaml_invalid.Visibility = System.Windows.Visibility.Visible; + else + { + xaml_invalid.Visibility = System.Windows.Visibility.Collapsed; + } + } + } + + private void ClickOK(object sender, RoutedEventArgs e) + { + PrintDiagPrint(this); + this.Hide(); + } + + private void ClickCancel(object sender, RoutedEventArgs e) + { + this.Hide(); + } + + private void xaml_Copies_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) + { + m_numcopies = (int) e.NewValue; + } + + private void AutoFit_Checked(object sender, RoutedEventArgs e) + { + UpdateView(); + } + + private void AutoFit_Unchecked(object sender, RoutedEventArgs e) + { + UpdateView(); + } + } +} diff --git a/platform/windows/gsview/ghostsharp.cs b/platform/windows/gsview/ghostsharp.cs index 168ce476..099239e9 100644 --- a/platform/windows/gsview/ghostsharp.cs +++ b/platform/windows/gsview/ghostsharp.cs @@ -1047,10 +1047,10 @@ namespace gsview return RunGhostscript(gsparams); } - public gsStatus CreateXPS(String fileName, int resolution, int num_pages) + public gsStatus CreateXPS(String fileName, int resolution, int num_pages, + PrintControl printsettings) { gsParams_t gsparams = new gsParams_t(); - gsparams.init_file = null; gsparams.init_string = null; gsparams.device = gsDevice_t.xpswrite; @@ -1065,6 +1065,19 @@ namespace gsview gsparams.firstpage = -1; gsparams.lastpage = -1; gsparams.currpage = -1; + + if (printsettings != null) + { + double paperheight = printsettings.m_pagedetails.PaperSize.Height; + double paperwidth = printsettings.m_pagedetails.PaperSize.Width; + double width = paperwidth * 72.0 / 100.0; + double height = paperheight * 72.0 / 100.0; + String temp = " -dDEVICEWIDTHPOINTS=" + width + " -dDEVICEHEIGHTPOINTS=" + height + " -dFIXEDMEDIA"; + /* Scale and translate and rotate if needed */ + if (printsettings.xaml_autofit.IsChecked == true) + temp = temp + " -dFitPage"; + gsparams.options = gsparams.options + temp; + } return RunGhostscript(gsparams); } diff --git a/platform/windows/gsview/gsprint.cs b/platform/windows/gsview/gsprint.cs index 27976bc0..7d7c68fd 100644 --- a/platform/windows/gsview/gsprint.cs +++ b/platform/windows/gsview/gsprint.cs @@ -10,6 +10,7 @@ using System.Windows.Media; using System.Windows.Xps; using System.Windows.Xps.Packaging; using System.Windows.Xps.Serialization; +using System.Drawing.Printing; namespace gsview { @@ -74,8 +75,8 @@ namespace gsview PrintDialog dlg = new PrintDialog(); /* Current page and page ranges is going to require a little work */ dlg.PageRangeSelection = PageRangeSelection.AllPages; - //dlg.UserPageRangeEnabled = true; - //dlg.CurrentPageEnabled = true; + dlg.UserPageRangeEnabled = true; + dlg.CurrentPageEnabled = true; dlg.SelectedPagesEnabled = false; m_busy = false; if (dlg.ShowDialog() == true) @@ -84,30 +85,71 @@ namespace gsview } /* Main print entry point */ - public void Print(PrintQueue queu, FixedDocumentSequence fixdoc) + public void Print(PrintQueue queu, FixedDocumentSequence fixdoc, PrintControl printcontrol) { - XpsDocumentWriter docwrite = GetDocWriter(queu); - + XpsDocumentWriter docwrite; + PrintTicket Ticket = SetUpTicket(queu, printcontrol, fixdoc); + docwrite = GetDocWriter(queu); m_busy = true; +#if DISABLED_FOR_NOW docwrite.WritingPrintTicketRequired += - new WritingPrintTicketRequiredEventHandler(PrintTicket); - PrintPages(docwrite, fixdoc); + new WritingPrintTicketRequiredEventHandler(PrintTicket); +#endif + PrintPages(docwrite, fixdoc, Ticket); + } + + /* Set up the print ticket */ + private PrintTicket SetUpTicket(PrintQueue queue, PrintControl printcontrol, FixedDocumentSequence fixdoc) + { + PrintTicket Ticket = new PrintTicket(); + + PageMediaSizeName name = PaperKindToPageMediaSize(printcontrol.m_pagedetails.PaperSize.Kind); + PageMediaSize mediasize = new PageMediaSize(name, printcontrol.m_pagedetails.PaperSize.Width, printcontrol.m_pagedetails.PaperSize.Height); + + /* Media size */ + Ticket.PageMediaSize = mediasize; + /* Scale to fit */ + Ticket.PageScalingFactor = (int)Math.Round(printcontrol.m_page_scale * 100.0); + + System.Windows.Size page_size = new System.Windows.Size(mediasize.Width.Value, mediasize.Height.Value); + DocumentPaginator paginator = fixdoc.DocumentPaginator; + paginator.PageSize = page_size; + + /* Copy Count */ + Ticket.CopyCount = printcontrol.m_numcopies; + + /* Orientation */ + if (printcontrol.m_isrotated) + if (printcontrol.m_pagedetails.Landscape) + Ticket.PageOrientation = PageOrientation.Portrait; + else + Ticket.PageOrientation = PageOrientation.Landscape; + else + if (printcontrol.m_pagedetails.Landscape) + Ticket.PageOrientation = PageOrientation.Landscape; + else + Ticket.PageOrientation = PageOrientation.Portrait; + + System.Printing.ValidationResult result = queue.MergeAndValidatePrintTicket(queue.UserPrintTicket, Ticket); + queue.UserPrintTicket = result.ValidatedPrintTicket; + queue.Commit(); + return result.ValidatedPrintTicket; } /* Send it */ - private void PrintPages(XpsDocumentWriter xpsdw, FixedDocumentSequence fixdoc) + private void PrintPages(XpsDocumentWriter xpsdw, FixedDocumentSequence fixdoc, PrintTicket Ticket) { m_docWriter = xpsdw; xpsdw.WritingCompleted += new WritingCompletedEventHandler(AsyncCompleted); xpsdw.WritingProgressChanged += new WritingProgressChangedEventHandler(AsyncProgress); - xpsdw.WriteAsync(fixdoc); + xpsdw.WriteAsync(fixdoc, Ticket); } public void CancelAsync() { - /* ick. This does not work in windows 8. causes crash */ + /* ick. This does not work in windows 8. causes crash. */ /* https://connect.microsoft.com/VisualStudio/feedback/details/778145/xpsdocumentwriter-cancelasync-cause-crash-in-win8 */ m_docWriter.CancelAsync(); } @@ -142,26 +184,269 @@ namespace gsview PrintUpdate(this, info); } } - +#if DISABLED_FOR_NOW /* Print ticket handling. You can customize for PrintTicketLevel at - FixedDocumentSequencePrintTicket, FixedDocumentPrintTicket, - or FixedPagePrintTicket. We may want to play around with this some */ + FixedDocumentSequencePrintTicket, FixedDocumentPrintTicket, + or FixedPagePrintTicket. We may want to play around with this some */ private void PrintTicket(Object sender, WritingPrintTicketRequiredEventArgs e) { if (e.CurrentPrintTicketLevel == PrintTicketLevel.FixedDocumentSequencePrintTicket) { PrintTicket pts = new PrintTicket(); - pts.PageOrientation = PageOrientation.Portrait; e.CurrentPrintTicket = pts; } } - +#endif /* Create the document write */ private XpsDocumentWriter GetDocWriter(PrintQueue pq) { XpsDocumentWriter xpsdw = PrintQueue.CreateXpsDocumentWriter(pq); return xpsdw; } + + /* Two paths for designating printing = a pain in the ass.*/ + static PageMediaSizeName PaperKindToPageMediaSize(PaperKind paperKind) + { + switch (paperKind) + { + case PaperKind.Custom: + return PageMediaSizeName.Unknown; + case PaperKind.Letter: + return PageMediaSizeName.NorthAmericaLetter; + case PaperKind.Legal: + return PageMediaSizeName.NorthAmericaLegal; + case PaperKind.A4: + return PageMediaSizeName.ISOA4; + case PaperKind.CSheet: + return PageMediaSizeName.NorthAmericaCSheet; + case PaperKind.DSheet: + return PageMediaSizeName.NorthAmericaDSheet; + case PaperKind.ESheet: + return PageMediaSizeName.NorthAmericaESheet; + case PaperKind.LetterSmall: + return PageMediaSizeName.Unknown; + case PaperKind.Tabloid: + return PageMediaSizeName.NorthAmericaTabloid; + case PaperKind.Ledger: + return PageMediaSizeName.Unknown; + case PaperKind.Statement: + return PageMediaSizeName.NorthAmericaStatement; + case PaperKind.Executive: + return PageMediaSizeName.NorthAmericaExecutive; + case PaperKind.A3: + return PageMediaSizeName.ISOA3; + case PaperKind.A4Small: + return PageMediaSizeName.Unknown; + case PaperKind.A5: + return PageMediaSizeName.ISOA5; + case PaperKind.B4: + return PageMediaSizeName.ISOB4; + case PaperKind.B5: + return PageMediaSizeName.Unknown; + case PaperKind.Folio: + return PageMediaSizeName.OtherMetricFolio; + case PaperKind.Quarto: + return PageMediaSizeName.NorthAmericaQuarto; + case PaperKind.Standard10x14: + return PageMediaSizeName.Unknown; + case PaperKind.Standard11x17: + return PageMediaSizeName.Unknown; + case PaperKind.Note: + return PageMediaSizeName.NorthAmericaNote; + case PaperKind.Number9Envelope: + return PageMediaSizeName.NorthAmericaNumber9Envelope; + case PaperKind.Number10Envelope: + return PageMediaSizeName.NorthAmericaNumber10Envelope; + case PaperKind.Number11Envelope: + return PageMediaSizeName.NorthAmericaNumber11Envelope; + case PaperKind.Number12Envelope: + return PageMediaSizeName.NorthAmericaNumber12Envelope; + case PaperKind.Number14Envelope: + return PageMediaSizeName.NorthAmericaNumber14Envelope; + case PaperKind.DLEnvelope: + return PageMediaSizeName.ISODLEnvelope; + case PaperKind.C5Envelope: + return PageMediaSizeName.ISOC5Envelope; + case PaperKind.C3Envelope: + return PageMediaSizeName.ISOC3Envelope; + case PaperKind.C4Envelope: + return PageMediaSizeName.ISOC4Envelope; + case PaperKind.C6Envelope: + return PageMediaSizeName.ISOC6Envelope; + case PaperKind.C65Envelope: + return PageMediaSizeName.ISOC6C5Envelope; + case PaperKind.B4Envelope: + return PageMediaSizeName.ISOB4Envelope; + case PaperKind.B5Envelope: + return PageMediaSizeName.ISOB5Envelope; + case PaperKind.B6Envelope: + return PageMediaSizeName.Unknown; + case PaperKind.ItalyEnvelope: + return PageMediaSizeName.OtherMetricItalianEnvelope; + case PaperKind.MonarchEnvelope: + return PageMediaSizeName.NorthAmericaMonarchEnvelope; + case PaperKind.PersonalEnvelope: + return PageMediaSizeName.NorthAmericaPersonalEnvelope; + case PaperKind.USStandardFanfold: + return PageMediaSizeName.Unknown; + case PaperKind.GermanStandardFanfold: + return PageMediaSizeName.NorthAmericaGermanStandardFanfold; + case PaperKind.GermanLegalFanfold: + return PageMediaSizeName.NorthAmericaGermanLegalFanfold; + case PaperKind.IsoB4: + return PageMediaSizeName.ISOB4; + case PaperKind.JapanesePostcard: + return PageMediaSizeName.JapanHagakiPostcard; + case PaperKind.Standard9x11: + return PageMediaSizeName.Unknown; + case PaperKind.Standard10x11: + return PageMediaSizeName.Unknown; + case PaperKind.Standard15x11: + return PageMediaSizeName.Unknown; + case PaperKind.InviteEnvelope: + return PageMediaSizeName.OtherMetricInviteEnvelope; + case PaperKind.LetterExtra: + return PageMediaSizeName.NorthAmericaLetterExtra; + case PaperKind.LegalExtra: + return PageMediaSizeName.NorthAmericaLegalExtra; + case PaperKind.TabloidExtra: + return PageMediaSizeName.NorthAmericaTabloidExtra; + case PaperKind.A4Extra: + return PageMediaSizeName.ISOA4Extra; + case PaperKind.LetterTransverse: + return PageMediaSizeName.Unknown; + case PaperKind.A4Transverse: + return PageMediaSizeName.Unknown; + case PaperKind.LetterExtraTransverse: + return PageMediaSizeName.Unknown; + case PaperKind.APlus: + return PageMediaSizeName.Unknown; + case PaperKind.BPlus: + return PageMediaSizeName.Unknown; + case PaperKind.LetterPlus: + return PageMediaSizeName.NorthAmericaLetterPlus; + case PaperKind.A4Plus: + return PageMediaSizeName.OtherMetricA4Plus; + case PaperKind.A5Transverse: + return PageMediaSizeName.Unknown; + case PaperKind.B5Transverse: + return PageMediaSizeName.Unknown; + case PaperKind.A3Extra: + return PageMediaSizeName.ISOA3Extra; + case PaperKind.A5Extra: + return PageMediaSizeName.ISOA5Extra; + case PaperKind.B5Extra: + return PageMediaSizeName.ISOB5Extra; + case PaperKind.A2: + return PageMediaSizeName.ISOA2; + case PaperKind.A3Transverse: + return PageMediaSizeName.Unknown; + case PaperKind.A3ExtraTransverse: + return PageMediaSizeName.Unknown; + case PaperKind.JapaneseDoublePostcard: + return PageMediaSizeName.JapanDoubleHagakiPostcard; + case PaperKind.A6: + return PageMediaSizeName.ISOA6; + case PaperKind.JapaneseEnvelopeKakuNumber2: + return PageMediaSizeName.JapanKaku2Envelope; + case PaperKind.JapaneseEnvelopeKakuNumber3: + return PageMediaSizeName.JapanKaku3Envelope; + case PaperKind.JapaneseEnvelopeChouNumber3: + return PageMediaSizeName.JapanChou3Envelope; + case PaperKind.JapaneseEnvelopeChouNumber4: + return PageMediaSizeName.JapanChou4Envelope; + case PaperKind.LetterRotated: + return PageMediaSizeName.NorthAmericaLetterRotated; + case PaperKind.A3Rotated: + return PageMediaSizeName.ISOA3Rotated; + case PaperKind.A4Rotated: + return PageMediaSizeName.ISOA4Rotated; + case PaperKind.A5Rotated: + return PageMediaSizeName.ISOA5Rotated; + case PaperKind.B4JisRotated: + return PageMediaSizeName.JISB4Rotated; + case PaperKind.B5JisRotated: + return PageMediaSizeName.JISB5Rotated; + case PaperKind.JapanesePostcardRotated: + return PageMediaSizeName.JapanHagakiPostcardRotated; + case PaperKind.JapaneseDoublePostcardRotated: + return PageMediaSizeName.JapanHagakiPostcardRotated; + case PaperKind.A6Rotated: + return PageMediaSizeName.ISOA6Rotated; + case PaperKind.JapaneseEnvelopeKakuNumber2Rotated: + return PageMediaSizeName.JapanKaku2EnvelopeRotated; + case PaperKind.JapaneseEnvelopeKakuNumber3Rotated: + return PageMediaSizeName.JapanKaku3EnvelopeRotated; + case PaperKind.JapaneseEnvelopeChouNumber3Rotated: + return PageMediaSizeName.JapanChou3EnvelopeRotated; + case PaperKind.JapaneseEnvelopeChouNumber4Rotated: + return PageMediaSizeName.JapanChou4EnvelopeRotated; + case PaperKind.B6Jis: + return PageMediaSizeName.JISB6; + case PaperKind.B6JisRotated: + return PageMediaSizeName.JISB6Rotated; + case PaperKind.Standard12x11: + return PageMediaSizeName.Unknown; + case PaperKind.JapaneseEnvelopeYouNumber4: + return PageMediaSizeName.JapanYou4Envelope; + case PaperKind.JapaneseEnvelopeYouNumber4Rotated: + return PageMediaSizeName.JapanYou4EnvelopeRotated; + case PaperKind.Prc16K: + return PageMediaSizeName.PRC16K; + case PaperKind.Prc32K: + return PageMediaSizeName.PRC32K; + case PaperKind.Prc32KBig: + return PageMediaSizeName.PRC32KBig; + case PaperKind.PrcEnvelopeNumber1: + return PageMediaSizeName.PRC1Envelope; + case PaperKind.PrcEnvelopeNumber2: + return PageMediaSizeName.PRC2Envelope; + case PaperKind.PrcEnvelopeNumber3: + return PageMediaSizeName.PRC3Envelope; + case PaperKind.PrcEnvelopeNumber4: + return PageMediaSizeName.PRC4Envelope; + case PaperKind.PrcEnvelopeNumber5: + return PageMediaSizeName.PRC5Envelope; + case PaperKind.PrcEnvelopeNumber6: + return PageMediaSizeName.PRC6Envelope; + case PaperKind.PrcEnvelopeNumber7: + return PageMediaSizeName.PRC7Envelope; + case PaperKind.PrcEnvelopeNumber8: + return PageMediaSizeName.PRC8Envelope; + case PaperKind.PrcEnvelopeNumber9: + return PageMediaSizeName.PRC9Envelope; + case PaperKind.PrcEnvelopeNumber10: + return PageMediaSizeName.PRC10Envelope; + case PaperKind.Prc16KRotated: + return PageMediaSizeName.PRC16KRotated; + case PaperKind.Prc32KRotated: + return PageMediaSizeName.PRC32KRotated; + case PaperKind.Prc32KBigRotated: + return PageMediaSizeName.Unknown; + case PaperKind.PrcEnvelopeNumber1Rotated: + return PageMediaSizeName.PRC1EnvelopeRotated; + case PaperKind.PrcEnvelopeNumber2Rotated: + return PageMediaSizeName.PRC2EnvelopeRotated; + case PaperKind.PrcEnvelopeNumber3Rotated: + return PageMediaSizeName.PRC3EnvelopeRotated; + case PaperKind.PrcEnvelopeNumber4Rotated: + return PageMediaSizeName.PRC4EnvelopeRotated; + case PaperKind.PrcEnvelopeNumber5Rotated: + return PageMediaSizeName.PRC5EnvelopeRotated; + case PaperKind.PrcEnvelopeNumber6Rotated: + return PageMediaSizeName.PRC6EnvelopeRotated; + case PaperKind.PrcEnvelopeNumber7Rotated: + return PageMediaSizeName.PRC7EnvelopeRotated; + case PaperKind.PrcEnvelopeNumber8Rotated: + return PageMediaSizeName.PRC8EnvelopeRotated; + case PaperKind.PrcEnvelopeNumber9Rotated: + return PageMediaSizeName.PRC9EnvelopeRotated; + case PaperKind.PrcEnvelopeNumber10Rotated: + return PageMediaSizeName.PRC10EnvelopeRotated; + default: + throw new ArgumentOutOfRangeException("paperKind"); + } + } } } diff --git a/platform/windows/gsview/gsview.csproj b/platform/windows/gsview/gsview.csproj index 31f40f51..b57c86f0 100644 --- a/platform/windows/gsview/gsview.csproj +++ b/platform/windows/gsview/gsview.csproj @@ -111,6 +111,9 @@ <Compile Include="Password.xaml.cs"> <DependentUpon>Password.xaml</DependentUpon> </Compile> + <Compile Include="PrintControl.xaml.cs"> + <DependentUpon>PrintControl.xaml</DependentUpon> + </Compile> <Compile Include="RectList.cs" /> <Compile Include="Selection.xaml.cs"> <DependentUpon>Selection.xaml</DependentUpon> @@ -163,6 +166,10 @@ <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> + <Page Include="PrintControl.xaml"> + <SubType>Designer</SubType> + <Generator>MSBuild:Compile</Generator> + </Page> <Page Include="Selection.xaml"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> diff --git a/platform/windows/mupdf.sln b/platform/windows/mupdf.sln index 65818c0e..7fb74446 100644 --- a/platform/windows/mupdf.sln +++ b/platform/windows/mupdf.sln @@ -1,7 +1,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2013 -VisualStudioVersion = 12.0.21005.1 +VisualStudioVersion = 12.0.31101.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "generated", "generated.vcxproj", "{A5053AA7-02E5-4903-B596-04F17AEB1526}" EndProject @@ -25,6 +25,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mupdf_cpp", "mupdf_cpp\mupd EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "gsview", "gsview\gsview.csproj", "{5DA0ECC9-4026-4427-862F-E3226EFEFEB1}" ProjectSection(ProjectDependencies) = postProject + {09FE8E75-9952-44E7-95F8-E8D74707FBA1} = {09FE8E75-9952-44E7-95F8-E8D74707FBA1} {4468C2E0-6C90-4FA5-8A48-0A9629776167} = {4468C2E0-6C90-4FA5-8A48-0A9629776167} EndProjectSection EndProject @@ -53,6 +54,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libmupdf", "libmupdf\libmup EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libthirdparty", "libthirdparty\libthirdparty.vcxproj", "{DF87E242-8B2C-4F04-9A7E-61C578FD994C}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gsprint", "gsprint.vcxproj", "{09FE8E75-9952-44E7-95F8-E8D74707FBA1}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution CD_ROM|Any CPU = CD_ROM|Any CPU @@ -755,6 +758,66 @@ Global {DF87E242-8B2C-4F04-9A7E-61C578FD994C}.SingleImage|x64.Build.0 = Release|x64 {DF87E242-8B2C-4F04-9A7E-61C578FD994C}.SingleImage|x86.ActiveCfg = Release|Win32 {DF87E242-8B2C-4F04-9A7E-61C578FD994C}.SingleImage|x86.Build.0 = Release|Win32 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.CD_ROM|Any CPU.ActiveCfg = Release|Win32 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.CD_ROM|ARM.ActiveCfg = Release|Win32 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.CD_ROM|Mixed Platforms.ActiveCfg = Release|Win32 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.CD_ROM|Mixed Platforms.Build.0 = Release|Win32 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.CD_ROM|Win32.ActiveCfg = Release|Win32 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.CD_ROM|Win32.Build.0 = Release|Win32 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.CD_ROM|x64.ActiveCfg = Release|x64 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.CD_ROM|x64.Build.0 = Release|x64 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.CD_ROM|x86.ActiveCfg = Release|Win32 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.CD_ROM|x86.Build.0 = Release|Win32 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.Debug|Any CPU.ActiveCfg = Debug|Win32 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.Debug|ARM.ActiveCfg = Debug|Win32 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.Debug|Win32.ActiveCfg = Debug|Win32 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.Debug|Win32.Build.0 = Debug|Win32 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.Debug|x64.ActiveCfg = Debug|x64 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.Debug|x64.Build.0 = Debug|x64 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.Debug|x86.ActiveCfg = Debug|Win32 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.Debug|x86.Build.0 = Debug|Win32 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.DVD-5|Any CPU.ActiveCfg = Debug|Win32 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.DVD-5|ARM.ActiveCfg = Debug|Win32 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.DVD-5|Mixed Platforms.ActiveCfg = Debug|Win32 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.DVD-5|Mixed Platforms.Build.0 = Debug|Win32 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.DVD-5|Win32.ActiveCfg = Debug|Win32 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.DVD-5|Win32.Build.0 = Debug|Win32 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.DVD-5|x64.ActiveCfg = Debug|x64 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.DVD-5|x64.Build.0 = Debug|x64 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.DVD-5|x86.ActiveCfg = Debug|Win32 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.DVD-5|x86.Build.0 = Debug|Win32 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.Memento|Any CPU.ActiveCfg = Release|Win32 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.Memento|ARM.ActiveCfg = Release|Win32 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.Memento|Mixed Platforms.ActiveCfg = Release|Win32 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.Memento|Mixed Platforms.Build.0 = Release|Win32 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.Memento|Win32.ActiveCfg = Release|Win32 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.Memento|Win32.Build.0 = Release|Win32 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.Memento|x64.ActiveCfg = Release|x64 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.Memento|x64.Build.0 = Release|x64 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.Memento|x86.ActiveCfg = Release|Win32 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.Memento|x86.Build.0 = Release|Win32 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.Release|Any CPU.ActiveCfg = Release|Win32 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.Release|ARM.ActiveCfg = Release|Win32 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.Release|Mixed Platforms.Build.0 = Release|Win32 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.Release|Win32.ActiveCfg = Release|Win32 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.Release|Win32.Build.0 = Release|Win32 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.Release|x64.ActiveCfg = Release|x64 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.Release|x64.Build.0 = Release|x64 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.Release|x86.ActiveCfg = Release|Win32 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.Release|x86.Build.0 = Release|Win32 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.SingleImage|Any CPU.ActiveCfg = Release|Win32 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.SingleImage|ARM.ActiveCfg = Release|Win32 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.SingleImage|Mixed Platforms.ActiveCfg = Release|Win32 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.SingleImage|Mixed Platforms.Build.0 = Release|Win32 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.SingleImage|Win32.ActiveCfg = Release|Win32 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.SingleImage|Win32.Build.0 = Release|Win32 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.SingleImage|x64.ActiveCfg = Release|x64 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.SingleImage|x64.Build.0 = Release|x64 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.SingleImage|x86.ActiveCfg = Release|Win32 + {09FE8E75-9952-44E7-95F8-E8D74707FBA1}.SingleImage|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE |