summaryrefslogtreecommitdiff
path: root/platform/winrt
diff options
context:
space:
mode:
authorMichael Vrhel <michael.vrhel@artifex.com>2014-05-31 23:54:24 -0700
committerMichael Vrhel <michael.vrhel@artifex.com>2014-09-09 16:39:37 -0700
commit897bb7bae781933f966c528fbd5feda54055990c (patch)
tree84e10975ffe25c7a9ea263cca6f9f011132aaf70 /platform/winrt
parent80d82a6f9fadbb57a0ac0de945dfd9145a837b8b (diff)
downloadmupdf-897bb7bae781933f966c528fbd5feda54055990c.tar.xz
Fix crashes, add annotations, more AA control, Keyboard commands, select all plus more.
Includes xml, html, text save as, fix issues in window range that determines what pages are visible at a particular scaling. Fix very tricky to find problem in interface with gs. Managed code was freeing delegates that were allocated dynamically. It is not possible to pin these so they are now member variables.
Diffstat (limited to 'platform/winrt')
-rw-r--r--platform/winrt/gsview/DocPage.cs22
-rw-r--r--platform/winrt/gsview/Install64/Install64.vdproj10
-rw-r--r--platform/winrt/gsview/MainWindow.xaml73
-rw-r--r--platform/winrt/gsview/MainWindow.xaml.cs914
-rw-r--r--platform/winrt/gsview/TextBlock.cs2
-rw-r--r--platform/winrt/gsview/ghostsharp.cs136
-rw-r--r--platform/winrt/gsview/gsview.csproj1
-rw-r--r--platform/winrt/gsview/mudocument.cs174
-rw-r--r--platform/winrt/mupdfnet/mupdfnet.cpp28
-rw-r--r--platform/winrt/mupdfnet/mupdfnet.h6
-rw-r--r--platform/winrt/mupdfwinrt/muctx.cpp106
-rw-r--r--platform/winrt/mupdfwinrt/muctx.h11
12 files changed, 1201 insertions, 282 deletions
diff --git a/platform/winrt/gsview/DocPage.cs b/platform/winrt/gsview/DocPage.cs
index a4f01662..0114c045 100644
--- a/platform/winrt/gsview/DocPage.cs
+++ b/platform/winrt/gsview/DocPage.cs
@@ -10,6 +10,15 @@ using System.Windows.Media;
namespace gsview
{
+ public enum Annotate_t
+ {
+ UNKNOWN,
+ NO_ANNOTATE,
+ HAS_ANNOTATE,
+ ANNOTATE_VISIBLE,
+ ANNOTATE_HIDDEN
+ }
+
public class DocPage : INotifyPropertyChanged
{
private LinesText m_lines;
@@ -19,6 +28,7 @@ namespace gsview
private int nativeheight;
private int nativewidth;
private double zoom;
+ private Annotate_t annotate;
private BitmapSource bitmap;
private IList<RectList> textbox;
private List<RectList> linkbox;
@@ -127,6 +137,12 @@ namespace gsview
set { nativeheight = value; }
}
+ public Annotate_t Annotate
+ {
+ get { return annotate; }
+ set { annotate = value; }
+ }
+
public double Zoom
{
get { return zoom; }
@@ -201,7 +217,7 @@ namespace gsview
set { pagenum = value; }
}
- public bool AA
+ public AA_t AA
{
get;
set;
@@ -233,13 +249,13 @@ namespace gsview
this.PageNum = -1;
this.PageName = "";
this.TextBlocks = null;
- this.AA = true;
+ this.AA = AA_t.HIGH;
}
public DocPage(int Height, int Width, double Zoom, BitmapSource BitMap,
List<RectList> TextBox, List<RectList> LinkBox,
Page_Content_t Content, int PageNum, BlocksText TextBlocks,
- bool AA)
+ AA_t AA)
{
this.Height = Height;
this.Width = Width;
diff --git a/platform/winrt/gsview/Install64/Install64.vdproj b/platform/winrt/gsview/Install64/Install64.vdproj
index 25fceb9f..cebe46f8 100644
--- a/platform/winrt/gsview/Install64/Install64.vdproj
+++ b/platform/winrt/gsview/Install64/Install64.vdproj
@@ -62,6 +62,14 @@
"PrerequisitesLocation" = "2:1"
"Url" = "8:"
"ComponentsUrl" = "8:"
+ "Items"
+ {
+ "{EDC2488A-8267-493A-A98E-7D9C3B36CDF3}:.NETFramework,Version=v4.5"
+ {
+ "Name" = "8:Microsoft .NET Framework 4.5 (x86 and x64)"
+ "ProductCode" = "8:.NETFramework,Version=v4.5"
+ }
+ }
}
}
"Release"
@@ -286,7 +294,7 @@
"Name" = "8:Microsoft Visual Studio"
"ProductName" = "8:GSview 6.0"
"ProductCode" = "8:{A22596C0-BCF4-46F9-9CF2-1C66E8588C30}"
- "PackageCode" = "8:{2D4D7754-2AE5-45B4-B5CD-D3672BA861A7}"
+ "PackageCode" = "8:{472F1001-38CC-432D-9105-A519D7DD8F99}"
"UpgradeCode" = "8:{B494B7A2-738F-4F9D-87F4-31830A16FB76}"
"AspNetVersion" = "8:4.0.30319.0"
"RestartWWWService" = "11:FALSE"
diff --git a/platform/winrt/gsview/MainWindow.xaml b/platform/winrt/gsview/MainWindow.xaml
index 2b048ee5..d506afce 100644
--- a/platform/winrt/gsview/MainWindow.xaml
+++ b/platform/winrt/gsview/MainWindow.xaml
@@ -121,12 +121,30 @@
<!-- Customize listview to turn off selection -->
</Window.Resources>
+ <!-- The following is needed to set up all the keyboard short cuts -->
+ <Window.CommandBindings>
+ <CommandBinding Command="Open" Executed="OpenFileCommand"></CommandBinding>
+ <CommandBinding Command="SelectAll" Executed="SelectAllCommand"></CommandBinding>
+ <CommandBinding Command="Copy" Executed="CopyCommand"></CommandBinding>
+ <CommandBinding Command="Print" Executed="PrintCommand"></CommandBinding>
+ <CommandBinding Command="Help" Executed="HelpCommand"></CommandBinding>
+ <CommandBinding Command="Close" Executed="CloseCommand"></CommandBinding>
+ </Window.CommandBindings>
+ <Window.InputBindings>
+ <KeyBinding Key="O" Modifiers="Control" Command="Open"></KeyBinding>
+ <KeyBinding Key="A" Modifiers="Control" Command="SelectAll"></KeyBinding>
+ <KeyBinding Key="C" Modifiers="Control" Command="Copy"></KeyBinding>
+ <KeyBinding Key="P" Modifiers="Control" Command="Print"></KeyBinding>
+ <KeyBinding Key="W" Modifiers="Control" Command="Close"></KeyBinding>
+ <KeyBinding Key="F1" Command="Help"></KeyBinding>
+ </Window.InputBindings>
+
<!-- To do add in command short cuts and bindings -->
<DockPanel LastChildFill="True">
<!-- Menu item at top -->
<Menu IsMainMenu="True" DockPanel.Dock="Top">
<MenuItem Header="_File" x:Name="xaml_file">
- <MenuItem Header="_Open..." Click="OpenFile">
+ <MenuItem Header="_Open..." Command="Open" InputGestureText="Ctrl+O">
<MenuItem.Icon>
<Image Source="Resources/OpenFile.png" />
</MenuItem.Icon>
@@ -152,7 +170,7 @@
<MenuItem Header="HTML" Click="SaveHTML"/>
<MenuItem Header="XML" Click="SaveXML"/>
</MenuItem>
- <MenuItem Header="_Close" Click="CloseFile" x:Name="xaml_closefile">
+ <MenuItem Header="_Close" Command="Close" InputGestureText="Ctrl+W" x:Name="xaml_closefile">
<MenuItem.Icon>
<Image Source="Resources/Close.ico" />
</MenuItem.Icon>
@@ -170,12 +188,11 @@
<MenuItem Header="PDF" Click="ExtractPDF" x:Name="xaml_extractpdf"/>
<MenuItem Header="EPS" Click="ExtractEPS" x:Name="xaml_extracteps"/>
<MenuItem Header="PS" Click="ExtractPS" x:Name="xaml_extractps"/>
- <MenuItem Header="SVG" Click="ExtractSVG" x:Name="xaml_extractsvg"/>
</MenuItem>
<MenuItem Header="Page Conversions..." Click="ConvertClick" x:Name="xaml_conversions">
</MenuItem>
<Separator />
- <MenuItem Header="Print..." Click="Print" x:Name="xaml_print">
+ <MenuItem Header="Print..." Command="Print" InputGestureText="Ctrl+P" x:Name="xaml_print">
<MenuItem.Icon>
<Image Source="Resources/printer.ico" />
</MenuItem.Icon>
@@ -193,21 +210,24 @@
<Image Source="Resources/saveHS.png" />
</MenuItem.Icon>
</MenuItem>
+ <Separator />
<MenuItem Header="Copy Page" Click="CopyPage" x:Name="xaml_copypage">
<MenuItem.Icon>
<Image Source="Resources/copy.ico" />
</MenuItem.Icon>
</MenuItem>
- <Separator />
<MenuItem Header="Paste Page To" x:Name="xaml_pastpageto">
<MenuItem Header="BMP" Click="PastePage" Tag="BMP"/>
<MenuItem Header="GIF" Click="PastePage" Tag="GIF"/>
<MenuItem Header="JPEG" Click="PastePage" Tag="JPG"/>
<MenuItem Header="PNG" Click="PastePage" Tag="PNG"/>
<MenuItem Header="TIFF" Click="PastePage" Tag="TIF"/>
- <MenuItem Header="WDP" Click="PastePage" Tag="WDP"/>
+ <MenuItem Header="WDP (HD Photo)" Click="PastePage" Tag="WDP"/>
</MenuItem>
- <MenuItem Header="Copy Text" x:Name="xaml_copytext"/>
+ <Separator />
+ <MenuItem Header="Select Text All" Command="SelectAll" InputGestureText="Ctrl+A" x:Name="xaml_selectalltext" />
+ <MenuItem Header="Deselect Text" x:Name="xaml_deselecttext" />
+ <MenuItem Header="Copy Text" Command="Copy" InputGestureText="Ctrl+C" x:Name="xaml_copytext" />
</MenuItem>
<MenuItem Header="_View" x:Name="xaml_view">
<MenuItem Header="Next Page" Click="OnForwardPageClick"/>
@@ -217,11 +237,19 @@
<MenuItem Header="_Options">
<MenuItem Header="Output Intents" Click="OutputIntents" />
<MenuItem Header="Zoom Control" IsCheckable="true" Checked="ShowFooter" Unchecked="HideFooter"/>
- <MenuItem x:Name="xaml_AA" Header="Enable AntiAlias" IsCheckable="True" IsChecked="True" Checked="OnAAChecked" Unchecked="OnAAChecked"/>
+ <MenuItem Header="Show Annotations" IsCheckable="True" IsChecked ="True" Checked="AnnotationOn" Unchecked="AnnotationOff"/>
+ <MenuItem Header="AntiAlias" >
+ <MenuItem x:Name="xaml_AA_High" Header="High" IsCheckable="True" IsChecked="True" Checked="OnAAChecked" />
+ <MenuItem x:Name="xaml_AA_MedHigh" Header="Medium High" IsCheckable="True" IsChecked="False" Checked="OnAAChecked"/>
+ <MenuItem x:Name="xaml_AA_Med" Header="Medium" IsCheckable="True" IsChecked="False" Checked="OnAAChecked"/>
+ <MenuItem x:Name="xaml_AA_Low" Header="Low" IsCheckable="True" IsChecked="False" Checked="OnAAChecked" />
+ <MenuItem x:Name="xaml_AA_None" Header="None" IsCheckable="True" IsChecked="False" Checked="OnAAChecked" />
+ </MenuItem>
+
</MenuItem>
<MenuItem Header="_Help">
- <MenuItem Header="GSView Help" Click="OnHelpClick"/>
+ <MenuItem Header="GSView Help" Command="Help" InputGestureText="F1"/>
<MenuItem Header="About" Click="OnAboutClick"/>
</MenuItem>
</Menu>
@@ -584,6 +612,33 @@
</Button>
</Grid>
+ <!-- The progress bar that runs during copy all text to clipboard -->
+ <Grid x:Name="xaml_CopyTextGrid" DockPanel.Dock="Bottom" Visibility="Collapsed">
+ <Grid.ColumnDefinitions>
+ <ColumnDefinition Width="*" />
+ <ColumnDefinition Width="Auto" />
+ <ColumnDefinition Width="Auto" />
+ </Grid.ColumnDefinitions>
+ <ProgressBar x:Name="xaml_CopyTextProgress" 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_CancelCopyText" Click="CancelCopyText" Background="Transparent" BorderBrush="Transparent" Margin="5,0,5,0">
+ <Button.Template>
+ <ControlTemplate TargetType="{x:Type Button}">
+ <Grid>
+ <Rectangle Height="Auto" RadiusX="5" RadiusY="5">
+ <Rectangle.Fill >
+ <SolidColorBrush Color="LightSlateGray"></SolidColorBrush>
+ </Rectangle.Fill>
+ </Rectangle>
+ <ContentPresenter Content="{TemplateBinding Content}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
+ </Grid>
+ </ControlTemplate>
+ </Button.Template>
+ <TextBlock><Bold>Cancel</Bold></TextBlock>
+ </Button>
+ </Grid>
+
<!-- The progress bar that runs during printing -->
<Grid x:Name="xaml_PrintGrid" DockPanel.Dock="Bottom" Visibility="Collapsed">
<Grid.ColumnDefinitions>
diff --git a/platform/winrt/gsview/MainWindow.xaml.cs b/platform/winrt/gsview/MainWindow.xaml.cs
index cb98f25a..bd1d13d2 100644
--- a/platform/winrt/gsview/MainWindow.xaml.cs
+++ b/platform/winrt/gsview/MainWindow.xaml.cs
@@ -22,6 +22,15 @@ using System.Windows.Markup;
using System.Runtime.InteropServices;
using Microsoft.Win32; /* For registry */
+public enum AA_t
+{
+ HIGH = 8,
+ MEDHIGH = 6,
+ MED = 4,
+ LOW = 2,
+ NONE = 0
+}
+
enum PDFType_t
{
PDFX,
@@ -56,6 +65,20 @@ public enum status_t
E_NEEDPASSWORD
};
+public enum textout_t
+{
+ HTML = 0,
+ XML,
+ TEXT
+}
+
+enum zoom_t
+{
+ NO_ZOOM,
+ ZOOM_IN,
+ ZOOM_OUT
+}
+
enum view_t
{
VIEW_WEB,
@@ -78,6 +101,7 @@ public enum Page_Content_t
public enum Save_Type_t
{
PDF13,
+ LINEAR_PDF,
PDFA1_RGB,
PDFA1_CMYK,
PDFA2_RGB,
@@ -90,8 +114,7 @@ public enum Save_Type_t
SVG,
TEXT,
HTML,
- XML,
- LINEAR_PDF
+ XML
}
public enum Extract_Type_t
@@ -129,6 +152,7 @@ static class Constants
public const int SCROLL_STEP = 10;
public const int SCROLL_EDGE_BUFFER = 90;
public const int VERT_SCROLL_STEP = 48;
+ public const int PAGE_MARGIN = 1;
}
public static class DocumentTypes
@@ -156,6 +180,7 @@ namespace gsview
public BlocksText charlist;
public int pagenum;
public Point size;
+ public Annotate_t annot;
}
public struct ContextMenu_t
@@ -187,6 +212,68 @@ namespace gsview
public bool last_line_full;
}
+ public static class ScrollBarExtensions
+ {
+ public static double GetThumbCenter(this System.Windows.Controls.Primitives.ScrollBar s)
+ {
+ double thumbLength = GetThumbLength(s);
+ double trackLength = s.Maximum - s.Minimum;
+
+ return thumbLength / 2 + s.Minimum + (s.Value - s.Minimum) *
+ (trackLength - thumbLength) / trackLength;
+ }
+
+ public static void SetThumbCenter(this System.Windows.Controls.Primitives.ScrollBar s, double thumbCenter)
+ {
+ double thumbLength = GetThumbLength(s);
+ double trackLength = s.Maximum - s.Minimum;
+
+ if (thumbCenter >= s.Maximum - thumbLength / 2)
+ {
+ s.Value = s.Maximum;
+ }
+ else if (thumbCenter <= s.Minimum + thumbLength / 2)
+ {
+ s.Value = s.Minimum;
+ }
+ else if (thumbLength >= trackLength)
+ {
+ s.Value = s.Minimum;
+ }
+ else
+ {
+ s.Value = (int)(s.Minimum + trackLength *
+ ((thumbCenter - s.Minimum - thumbLength / 2)
+ / (trackLength - thumbLength)));
+ }
+ }
+
+ public static double GetThumbLength(this System.Windows.Controls.Primitives.ScrollBar s)
+ {
+ double trackLength = s.Maximum - s.Minimum;
+ return trackLength * s.ViewportSize /
+ (trackLength + s.ViewportSize);
+ }
+
+ public static void SetThumbLength(this System.Windows.Controls.Primitives.ScrollBar s, double thumbLength)
+ {
+ double trackLength = s.Maximum - s.Minimum;
+
+ if (thumbLength < 0)
+ {
+ s.ViewportSize = 0;
+ }
+ else if (thumbLength < trackLength)
+ {
+ s.ViewportSize = trackLength * thumbLength / (trackLength - thumbLength);
+ }
+ else
+ {
+ s.ViewportSize = double.MaxValue;
+ }
+ }
+ }
+
public partial class MainWindow : Window
{
mudocument mu_doc;
@@ -207,6 +294,7 @@ namespace gsview
String m_textsearchcolor = "#4072AC25";
String m_textselectcolor = "#402572AC";
String m_regionselect = "#00FFFFFF";
+ String m_blockcolor = "#00FFFFFF";
//String m_regionselect = "#FFFF0000"; /* Debug */
String m_linkcolor = "#40AC7225";
private bool m_have_thumbs;
@@ -226,6 +314,7 @@ namespace gsview
BackgroundWorker m_linksearch = null;
BackgroundWorker m_openfile = null;
BackgroundWorker m_initrender = null;
+ BackgroundWorker m_copytext = null;
String m_document_type;
Info m_infowindow;
OutputIntent m_outputintents;
@@ -240,9 +329,11 @@ namespace gsview
double m_maxY;
bool m_ignorescrollchange;
double m_totalpageheight;
- bool m_AA;
+ AA_t m_AA;
bool m_regstartup;
int m_initpage;
+ bool m_selectall;
+ bool m_showannot;
public MainWindow()
{
@@ -250,6 +341,7 @@ namespace gsview
this.Closing += new System.ComponentModel.CancelEventHandler(Window_Closing);
m_file_open = false;
m_regstartup = true;
+ m_showannot = true;
status_t result = CleanUp();
/* Allocations and set up */
@@ -478,9 +570,11 @@ namespace gsview
CloseExtraWindows(false);
ResetScroll();
m_totalpageheight = 0;
- m_AA = xaml_AA.IsChecked;
+ m_AA = GetAA();
m_origfile = null;
m_initpage = 0;
+ xaml_Zoomsize.Text = "100";
+ m_selectall = false;
return result;
}
@@ -492,12 +586,12 @@ namespace gsview
RegistryKey keygs = keyA.CreateSubKey("GSview 6.0");
String filepath = null;
Int32 page;
- bool aa_on = true;
+ AA_t aa = AA_t.HIGH;
try
{
filepath = (String)keygs.GetValue("File", null);
- aa_on = System.Convert.ToBoolean((Int32) keygs.GetValue("AA"));
+ aa = (AA_t)keygs.GetValue("AA");
page = (Int32)keygs.GetValue("Page");
}
catch
@@ -508,8 +602,8 @@ namespace gsview
keyA.Close();
key.Close();
- xaml_AA.IsChecked = aa_on;
- m_AA = aa_on;
+ SetAA(aa);
+ m_AA = aa;
if (filepath != null && File.Exists(filepath))
{
@@ -539,7 +633,8 @@ namespace gsview
keygs.SetValue("File", m_currfile, RegistryValueKind.String);
}
keygs.SetValue("Page", m_currpage, RegistryValueKind.DWord);
- keygs.SetValue("AA", System.Convert.ToInt32(xaml_AA.IsChecked), RegistryValueKind.DWord);
+ Int32 aa_int = (Int32)m_AA;
+ keygs.SetValue("AA", aa_int, RegistryValueKind.DWord);
keygs.Close();
keyA.Close();
key.Close();
@@ -564,6 +659,12 @@ namespace gsview
}
}
+ private void CloseCommand(object sender, ExecutedRoutedEventArgs e)
+ {
+ if (m_init_done)
+ CloseDoc();
+ }
+
private void CloseDoc()
{
CleanUp();
@@ -571,7 +672,7 @@ namespace gsview
/* Set the page with the new raster information */
private void UpdatePage(int page_num, Byte[] bitmap, Point ras_size,
- Page_Content_t content, double zoom_in, bool AA)
+ Page_Content_t content, double zoom_in, AA_t AA)
{
DocPage doc_page = this.m_docPages[page_num];
@@ -594,6 +695,11 @@ namespace gsview
}
}
+ private void OpenFileCommand(object sender, ExecutedRoutedEventArgs e)
+ {
+ OpenFile(sender, e);
+ }
+
private void OpenFile(object sender, RoutedEventArgs e)
{
if (m_password != null && m_password.IsActive)
@@ -618,7 +724,7 @@ namespace gsview
}
System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog();
- dlg.Filter = "Document Files(*.ps;*.eps;*.pdf;*.xps;*.cbz)|*.ps;*.eps;*.pdf;*.xps;*.cbz|All files (*.*)|*.*";
+ dlg.Filter = "Document Files(*.ps;*.eps;*.pdf;*.xps;*.oxps;*.cbz;*.png;*.jpg;*.jpeg)|*.ps;*.eps;*.pdf;*.xps;*.oxps;*.cbz;*.png;*.jpg;*.jpeg|All files (*.*)|*.*";
dlg.FilterIndex = 1;
if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
ProcessFile(dlg.FileName);
@@ -645,6 +751,7 @@ namespace gsview
m_document_type = DocumentTypes.EPS;
break;
case ".XPS":
+ case ".OXPS":
m_document_type = DocumentTypes.XPS;
break;
case ".PDF":
@@ -683,7 +790,7 @@ namespace gsview
return;
}
/* Set if this is already xps for printing */
- if (extension.ToUpper() == ".XPS")
+ if (extension.ToUpper() == ".XPS" || extension.ToUpper() == ".OXPS")
m_isXPS = true;
OpenFile2(FileName);
}
@@ -715,7 +822,10 @@ namespace gsview
{
/* Check if we need a password */
if (mu_doc.RequiresPassword())
+ {
+ xaml_OpenProgressGrid.Visibility = System.Windows.Visibility.Collapsed;
GetPassword();
+ }
else
StartViewer();
}
@@ -743,6 +853,32 @@ namespace gsview
}
}
+ private void SetPageAnnot(int page_num, Annotate_t render_result)
+ {
+ if (m_docPages[page_num].Annotate == Annotate_t.UNKNOWN)
+ {
+ if (render_result == Annotate_t.NO_ANNOTATE)
+ m_docPages[page_num].Annotate = Annotate_t.NO_ANNOTATE;
+ else
+ {
+ if (m_showannot)
+ m_docPages[page_num].Annotate = Annotate_t.ANNOTATE_VISIBLE;
+ else
+ m_docPages[page_num].Annotate = Annotate_t.ANNOTATE_HIDDEN;
+ }
+ }
+ else
+ {
+ if (m_docPages[page_num].Annotate != Annotate_t.NO_ANNOTATE)
+ {
+ if (m_showannot)
+ m_docPages[page_num].Annotate = Annotate_t.ANNOTATE_VISIBLE;
+ else
+ m_docPages[page_num].Annotate = Annotate_t.ANNOTATE_HIDDEN;
+ }
+ }
+ }
+
private void InitialRenderWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
@@ -758,6 +894,7 @@ namespace gsview
Byte[] bitmap;
BlocksText charlist;
status_t code;
+ Annotate_t annot;
if (ComputePageSize(k, scale_factor, out ras_size) == status_t.S_ISOK)
{
@@ -768,7 +905,7 @@ namespace gsview
/* Synchronous call on our background thread */
code = (status_t)mu_doc.RenderPage(k, bitmap, (int)ras_size.X,
(int)ras_size.Y, scale_factor, false, true,
- !(m_textset[k]), out charlist);
+ !(m_textset[k]), out charlist, m_showannot, out annot);
}
catch (OutOfMemoryException em)
{
@@ -784,6 +921,7 @@ namespace gsview
page_prog.charlist = charlist;
page_prog.pagenum = k;
page_prog.size = ras_size;
+ page_prog.annot = annot;
worker.ReportProgress(100, page_prog);
}
}
@@ -802,6 +940,7 @@ namespace gsview
UpdatePage(k, result.bitmap, result.size, Page_Content_t.FULL_RESOLUTION, 1.0, m_AA);
m_docPages[k].NativeHeight = (int) result.size.Y;
m_docPages[k].NativeWidth = (int)result.size.X;
+ SetPageAnnot(k, result.annot);
}
private void InitialRenderCompleted(object sender, RunWorkerCompletedEventArgs e)
@@ -850,7 +989,6 @@ namespace gsview
private void InitialRenderBG()
{
- m_num_pages = mu_doc.GetPageCount();
int look_ahead = Math.Min(Constants.INIT_LOOK_AHEAD, m_num_pages);
m_currpage = 0;
m_thumbnails.Capacity = m_num_pages;
@@ -892,9 +1030,20 @@ namespace gsview
}
private void StartViewer()
{
- xaml_openfilestatus.Text = "Initial Page Rendering";
- xaml_openfilestatus.UpdateLayout();
- InitialRenderBG();
+ m_num_pages = mu_doc.GetPageCount();
+
+ if (m_num_pages == 0)
+ {
+ xaml_OpenProgressGrid.Visibility = System.Windows.Visibility.Collapsed;
+ CleanUp();
+ ShowMessage(NotifyType_t.MESS_ERROR, m_currfile + " is corrupted");
+ }
+ else
+ {
+ xaml_openfilestatus.Text = "Initial Page Rendering";
+ xaml_openfilestatus.UpdateLayout();
+ InitialRenderBG();
+ }
}
private status_t ComputePageSize(int page_num, double scale_factor,
@@ -933,18 +1082,19 @@ namespace gsview
return doc_page;
}
+ #region Navigation
private void OnBackPageClick(object sender, RoutedEventArgs e)
{
if (m_currpage == 0 || !m_init_done) return;
m_ignorescrollchange = true;
- RenderRange(m_currpage - 1, true, false, 0);
+ RenderRange(m_currpage - 1, true, zoom_t.NO_ZOOM, 0);
}
private void OnForwardPageClick(object sender, RoutedEventArgs e)
{
if (m_currpage == m_num_pages - 1 || !m_init_done) return;
m_ignorescrollchange = true;
- RenderRange(m_currpage + 1, true, false, 0);
+ RenderRange(m_currpage + 1, true, zoom_t.NO_ZOOM, 0);
}
private void PageEnterClicked(object sender, System.Windows.Input.KeyEventArgs e)
@@ -959,7 +1109,7 @@ namespace gsview
if (page > 0 && page < (m_num_pages + 1))
{
m_ignorescrollchange = true;
- RenderRange(page - 1, true, false, 0);
+ RenderRange(page - 1, true, zoom_t.NO_ZOOM, 0);
}
}
catch (FormatException e1)
@@ -973,6 +1123,43 @@ namespace gsview
}
}
+ private void OnKeyDownHandler(object sender, System.Windows.Input.KeyEventArgs e)
+ {
+ switch (e.Key)
+ {
+ case Key.Left:
+ if (m_currpage == 0 || !m_init_done)
+ return;
+ m_ignorescrollchange = true;
+ RenderRange(m_currpage - 1, true, zoom_t.NO_ZOOM, 0);
+ e.Handled = true;
+ break;
+
+ case Key.Right:
+ if (m_currpage == m_num_pages - 1 || !m_init_done)
+ return;
+ m_ignorescrollchange = true;
+ RenderRange(m_currpage + 1, true, zoom_t.NO_ZOOM, 0);
+ e.Handled = true;
+ break;
+
+ case Key.Up:
+ if (!m_init_done)
+ return;
+ e.Handled = true;
+ OffsetScroll(-Constants.VERT_SCROLL_STEP * m_doczoom);
+ break;
+
+ case Key.Down:
+ if (!m_init_done)
+ return;
+ e.Handled = true;
+ OffsetScroll(Constants.VERT_SCROLL_STEP * m_doczoom);
+ break;
+ }
+ }
+ #endregion Navigation
+
private void CancelLoadClick(object sender, RoutedEventArgs e)
{
/* Cancel during thumbnail loading. Deactivate the button
@@ -1025,7 +1212,7 @@ namespace gsview
{
if (item.PageNum < 0)
return;
- RenderRange(item.PageNum, true, false, 0);
+ RenderRange(item.PageNum, true, zoom_t.NO_ZOOM, 0);
}
}
@@ -1036,7 +1223,7 @@ namespace gsview
{
int page = m_docPages[item.Page].PageNum;
if (page >= 0 && page < m_num_pages)
- RenderRange(page, true, false, 0);
+ RenderRange(page, true, zoom_t.NO_ZOOM, 0);
}
}
@@ -1116,7 +1303,9 @@ namespace gsview
/* Finish */
double perc = (double)second_item / (double)(m_num_pages - 1);
xaml_VerticalScroll.Value = perc * xaml_VerticalScroll.Maximum;
- RenderRange(second_item, false, false, 0);
+ if (second_item < 0)
+ second_item = 0;
+ RenderRange(second_item, false, zoom_t.NO_ZOOM, 0);
}
}
@@ -1153,14 +1342,30 @@ namespace gsview
if (viewer != null)
{
double curr_value = viewer.VerticalOffset;
+ AdjustScrollPercent(offset / viewer.ScrollableHeight);
+ viewer.ScrollToVerticalOffset(curr_value + offset);
+ }
+ }
+
+ /* Scroll to offset */
+ private void OffsetScrollPercent(double percent)
+ {
+ /* Get access to the scrollviewer */
+ ScrollViewer viewer = FindScrollViewer(xaml_PageList);
+ if (viewer != null)
+ {
+ double curr_value = viewer.VerticalOffset;
if (curr_value < 0 || curr_value > viewer.MaxHeight)
return;
- viewer.ScrollToVerticalOffset(curr_value + offset);
+ var extentheight = viewer.ExtentHeight;
+
+ var pos = extentheight * percent;
+ viewer.ScrollToVerticalOffset(pos);
}
}
/* Render +/- the look ahead from where we are if blank page is present */
- async private void RenderRange(int new_page, bool scrollto, bool newzoom, double zoom_offset)
+ async private void RenderRange(int new_page, bool scrollto, zoom_t newzoom, double zoom_offset)
{
/* Need to figure out what pages are going to be visible */
double bottom = this.ActualHeight;
@@ -1168,13 +1373,15 @@ namespace gsview
int final_page = new_page;
double count = -zoom_offset;
int offset = -1;
+ bool scrollbottom = false;
- if (newzoom)
+ if (newzoom != zoom_t.NO_ZOOM)
offset = 0;
if (m_thumbnails.Count < m_num_pages)
final_page = final_page + 1;
else
+ {
while (!done && final_page >= 0 && final_page < m_num_pages)
{
count = count + m_thumbnails[final_page].NativeHeight * m_doczoom;
@@ -1182,7 +1389,27 @@ namespace gsview
if (final_page == m_num_pages || count > bottom)
done = true;
}
-
+ /* We have zoomed out to a point where the offset will not stay
+ * in its current spot. Figure out where we need to be */
+ final_page = final_page - 1;
+ if (newzoom == zoom_t.ZOOM_OUT && count < bottom)
+ {
+ int curr_page = new_page - 1;
+ while (true)
+ {
+ if (curr_page < 0)
+ break;
+ count = count + m_thumbnails[curr_page].NativeHeight * m_doczoom;
+ if (count > bottom)
+ break;
+ curr_page = curr_page - 1;
+ }
+ new_page = curr_page;
+ if (new_page < 0)
+ new_page = 0;
+ scrollbottom = true;
+ }
+ }
for (int k = new_page + offset; k <= final_page + 1; k++)
{
@@ -1191,7 +1418,10 @@ namespace gsview
/* Check if page is already rendered */
var doc = m_docPages[k];
if (doc.Content != Page_Content_t.FULL_RESOLUTION ||
- doc.Zoom != m_doczoom || m_AA != doc.AA)
+ doc.Zoom != m_doczoom || m_AA != doc.AA ||
+ (doc.Annotate == Annotate_t.UNKNOWN && m_showannot) ||
+ (doc.Annotate == Annotate_t.ANNOTATE_VISIBLE && !m_showannot) ||
+ (doc.Annotate == Annotate_t.ANNOTATE_HIDDEN && m_showannot))
{
Point ras_size;
double scale_factor = m_doczoom;
@@ -1206,19 +1436,22 @@ namespace gsview
{
Byte[] bitmap = new byte[(int)ras_size.X * (int)ras_size.Y * 4];
BlocksText charlist = null;
+ Annotate_t annot = Annotate_t.UNKNOWN;
m_docPages[k].NativeWidth = (int)(ras_size.X / scale_factor);
m_docPages[k].NativeHeight = (int)(ras_size.Y / scale_factor);
Task<int> ren_task =
new Task<int>(() => mu_doc.RenderPage(k, bitmap,
(int)ras_size.X, (int)ras_size.Y, scale_factor,
- false, true, !(m_textset[k]), out charlist));
+ false, true, !(m_textset[k]), out charlist, m_showannot,
+ out annot));
ren_task.Start();
await ren_task.ContinueWith((antecedent) =>
{
status_t code = (status_t)ren_task.Result;
if (code == status_t.S_ISOK)
{
+ SetPageAnnot(k, annot);
if (m_docPages[k].TextBox != null)
ScaleTextBox(k);
if (m_links_on && m_page_link_list != null)
@@ -1238,6 +1471,14 @@ namespace gsview
ScaleTextBlocks(k, scale_factor);
m_docPages[k].TextBlocks = m_textptrs[k];
m_textset[k] = true;
+ if (m_selectall)
+ {
+ int num_blocks = m_docPages[k].TextBlocks.Count;
+ for (int jj = 0; jj < num_blocks; jj++)
+ {
+ m_docPages[k].TextBlocks[jj].Color = m_textselectcolor;
+ }
+ }
}
else
{
@@ -1255,12 +1496,13 @@ namespace gsview
}
/* This needs to be handled here to reduce
* flashing effects */
- if (newzoom && k == new_page)
+ if (newzoom != zoom_t.NO_ZOOM && k == new_page)
{
m_ignorescrollchange = true;
UpdatePageSizes();
xaml_VerticalScroll.Maximum = m_totalpageheight * m_doczoom + 4 * m_num_pages;
- ScrollPageToTop(new_page, zoom_offset, false);
+ if (!scrollbottom)
+ ScrollPageToTop(new_page, zoom_offset, false);
}
UpdatePage(k, bitmap, ras_size,
Page_Content_t.FULL_RESOLUTION, m_doczoom, m_AA);
@@ -1288,11 +1530,6 @@ namespace gsview
m_ignorescrollchange = true;
ScrollPageToTop(k, 0, false);
}
- /*
- if (k == new_page && m_docPages[k].TextBlocks == null)
- {
- m_docPages[k].TextBlocks = m_textptrs[k];
- } */
}
}
}
@@ -1478,6 +1715,11 @@ namespace gsview
}
}
+ private void PrintCommand(object sender, ExecutedRoutedEventArgs e)
+ {
+ Print(sender, e);
+ }
+
/* Printing is achieved using xpswrite device in ghostscript and
* pushing that file through the XPS print queue */
private void Print(object sender, RoutedEventArgs e)
@@ -1770,10 +2012,15 @@ namespace gsview
m_currpassword = m_password.xaml_Password.Password;
m_password.Close();
m_password = null;
+ xaml_OpenProgressGrid.Visibility = System.Windows.Visibility.Visible;
+ xaml_openfilestatus.Text = "Opening File";
StartViewer();
}
else
+ {
+ xaml_OpenProgressGrid.Visibility = System.Windows.Visibility.Collapsed;
ShowMessage(NotifyType_t.MESS_STATUS, "Password Incorrect");
+ }
}
private void ShowInfo(object sender, RoutedEventArgs e)
@@ -1806,43 +2053,80 @@ namespace gsview
#region Zoom Control
/* Find out where the current page is */
- private double ComputeOffset(double old_zoom)
+ private double ComputeOffsetZoomOut(double old_zoom)
+ {
+ double y = 0;
+ ScrollViewer viewer = FindScrollViewer(xaml_PageList);
+ if (viewer != null)
+ {
+ /* Look at the offset and where it falls relative to the top of our current page */
+ UIElement uiElement = (UIElement)xaml_PageList.ItemContainerGenerator.ContainerFromIndex(m_currpage);
+ y = viewer.TranslatePoint(new System.Windows.Point(0, 0), uiElement).Y;
+ }
+ return y * m_doczoom / old_zoom;
+ }
+
+ private double ComputeOffsetZoomIn(double old_zoom, out int new_page)
{
double y = 0;
ScrollViewer viewer = FindScrollViewer(xaml_PageList);
+ new_page = m_currpage;
if (viewer != null)
{
/* Look at the offset and where it falls relative to the top of our current page */
UIElement uiElement = (UIElement)xaml_PageList.ItemContainerGenerator.ContainerFromIndex(m_currpage);
y = viewer.TranslatePoint(new System.Windows.Point(0, 0), uiElement).Y;
+
+ /* If we are zoomed out, we can be on a page that is not on the top boundry. See if we can find one
+ * that is */
+ if (y < 0)
+ {
+ new_page = m_currpage - 1;
+ while (true)
+ {
+ if (new_page < 0)
+ {
+ new_page = 0;
+ return 0;
+ }
+ uiElement = (UIElement)xaml_PageList.ItemContainerGenerator.ContainerFromIndex(new_page);
+ y = viewer.TranslatePoint(new System.Windows.Point(0, 0), uiElement).Y;
+ if (y >= 0)
+ {
+ return y * m_doczoom / old_zoom;
+ }
+ new_page = new_page - 1;
+ }
+ }
}
return y * m_doczoom / old_zoom;
}
private void ZoomOut(object sender, RoutedEventArgs e)
{
- if (!m_init_done)
+ if (!m_init_done || m_doczoom <= Constants.ZOOM_MIN)
return;
double old_zoom = m_doczoom;
m_doczoom = m_doczoom - Constants.ZOOM_STEP;
if (m_doczoom < Constants.ZOOM_MIN)
m_doczoom = Constants.ZOOM_MIN;
xaml_ZoomSlider.Value = m_doczoom * 100.0;
- double offset = ComputeOffset(old_zoom);
- RenderRange(m_currpage, false, true, offset);
+ double offset = ComputeOffsetZoomOut(old_zoom);
+ RenderRange(m_currpage, false, zoom_t.ZOOM_OUT, offset);
}
private void ZoomIn(object sender, RoutedEventArgs e)
{
- if (!m_init_done)
+ if (!m_init_done || m_doczoom >= Constants.ZOOM_MAX)
return;
double old_zoom = m_doczoom;
m_doczoom = m_doczoom + Constants.ZOOM_STEP;
if (m_doczoom > Constants.ZOOM_MAX)
m_doczoom = Constants.ZOOM_MAX;
xaml_ZoomSlider.Value = m_doczoom * 100.0;
- double offset = ComputeOffset(old_zoom);
- RenderRange(m_currpage, false, true, offset);
+ int newpage;
+ double offset = ComputeOffsetZoomIn(old_zoom, out newpage);
+ RenderRange(newpage, false, zoom_t.ZOOM_IN, offset);
}
private void ActualSize(object sender, RoutedEventArgs e)
@@ -1852,8 +2136,17 @@ namespace gsview
double old_zoom = m_doczoom;
m_doczoom = 1.0;
xaml_ZoomSlider.Value = m_doczoom * 100.0;
- double offset = ComputeOffset(old_zoom);
- RenderRange(m_currpage, false, true, offset);
+ if (old_zoom < 1.0)
+ {
+ int new_page;
+ double offset = ComputeOffsetZoomIn(old_zoom, out new_page);
+ RenderRange(new_page, false, zoom_t.ZOOM_IN, offset);
+ }
+ else if (old_zoom > 1.0)
+ {
+ double offset = ComputeOffsetZoomOut(old_zoom);
+ RenderRange(m_currpage, false, zoom_t.ZOOM_OUT, offset);
+ }
}
private void ContScrollFill(object sender, RoutedEventArgs e)
@@ -1873,9 +2166,13 @@ namespace gsview
scale = Constants.ZOOM_MAX;
if (m_doczoom == scale)
return;
+ double old_zoom = m_doczoom;
m_doczoom = scale;
xaml_ZoomSlider.Value = m_doczoom * 100.0;
- RenderRange(m_currpage, true, false, 0);
+ if (old_zoom > m_doczoom)
+ RenderRange(m_currpage, true, zoom_t.ZOOM_OUT, 0);
+ else
+ RenderRange(m_currpage, true, zoom_t.ZOOM_IN, 0);
}
private void ExpandFill(object sender, RoutedEventArgs e)
@@ -1899,9 +2196,13 @@ namespace gsview
scale = Constants.ZOOM_MAX;
if (m_doczoom == scale)
return;
+ double old_zoom = m_doczoom;
m_doczoom = scale;
xaml_ZoomSlider.Value = m_doczoom * 100.0;
- RenderRange(m_currpage, true, false, 0);
+ if (old_zoom > m_doczoom)
+ RenderRange(m_currpage, true, zoom_t.ZOOM_OUT, 0);
+ else
+ RenderRange(m_currpage, true, zoom_t.ZOOM_IN, 0);
}
private void ShowFooter(object sender, RoutedEventArgs e)
@@ -1925,8 +2226,17 @@ namespace gsview
zoom = Constants.ZOOM_MIN;
double old_zoom = zoom;
m_doczoom = zoom;
- double offset = ComputeOffset(old_zoom);
- RenderRange(m_currpage, false, true, offset);
+ if (old_zoom > m_doczoom)
+ {
+ double offset = ComputeOffsetZoomOut(old_zoom);
+ RenderRange(m_currpage, false, zoom_t.ZOOM_OUT, offset);
+ }
+ else
+ {
+ int new_page;
+ double offset = ComputeOffsetZoomIn(old_zoom, out new_page);
+ RenderRange(new_page, false, zoom_t.ZOOM_IN, offset);
+ }
}
}
@@ -1942,8 +2252,17 @@ namespace gsview
var item = ((FrameworkElement)e.OriginalSource).DataContext as DocPage;
if (item != null)
{
- double offset = ComputeOffset(old_zoom);
- RenderRange(item.PageNum, true, true, offset);
+ if (old_zoom > m_doczoom)
+ {
+ double offset = ComputeOffsetZoomOut(old_zoom);
+ RenderRange(m_currpage, false, zoom_t.ZOOM_OUT, offset);
+ }
+ else
+ {
+ int new_page;
+ double offset = ComputeOffsetZoomIn(old_zoom, out new_page);
+ RenderRange(new_page, false, zoom_t.ZOOM_IN, offset);
+ }
}
}
}
@@ -1963,8 +2282,17 @@ namespace gsview
zoom = Constants.ZOOM_MIN;
double old_zoom = m_doczoom;
m_doczoom = zoom;
- double offset = ComputeOffset(old_zoom);
- RenderRange(m_currpage, false, true, offset);
+ if (old_zoom > m_doczoom)
+ {
+ double offset = ComputeOffsetZoomOut(old_zoom);
+ RenderRange(m_currpage, false, zoom_t.ZOOM_OUT, offset);
+ }
+ else
+ {
+ int new_page;
+ double offset = ComputeOffsetZoomIn(old_zoom, out new_page);
+ RenderRange(new_page, false, zoom_t.ZOOM_IN, offset);
+ }
}
catch (FormatException e1)
{
@@ -1980,6 +2308,7 @@ namespace gsview
/* Rescale the pages based upon the zoom value and the native size */
private void UpdatePageSizes()
{
+ SetThumbwidth();
for (int k = 0; k > m_num_pages; k++)
{
var thumbpage = m_thumbnails[k];
@@ -2062,11 +2391,11 @@ namespace gsview
{
bitmap = new byte[(int)ras_size.X * (int)ras_size.Y * 4];
BlocksText charlist;
-
+ Annotate_t annot;
/* Synchronous call on our background thread */
code = (status_t)mu_doc.RenderPage(k, bitmap, (int)ras_size.X,
(int)ras_size.Y, scale_factor, false, false, false,
- out charlist);
+ out charlist, false, out annot);
}
catch (OutOfMemoryException em)
{
@@ -2103,6 +2432,9 @@ namespace gsview
xaml_ThumbList.Items.Refresh();
xaml_VerticalScroll.Minimum = 0;
xaml_VerticalScroll.Maximum = m_totalpageheight + 4 * m_num_pages;
+ //thumbSize = (viewportSize/(maximum–minimum+viewportSize))×trackLength
+ SetThumbwidth();
+ //ScrollBarExtensions.SetThumbLength(xaml_VerticalScroll, 1);
}
private void ThumbsProgressChanged(object sender, ProgressChangedEventArgs e)
@@ -2278,6 +2610,11 @@ namespace gsview
System.IO.File.Copy(m_currfile, dlg.FileName, true);
use_gs = false;
break;
+ case Save_Type_t.LINEAR_PDF:
+ mu_doc.PDFExtract(m_currfile, dlg.FileName, m_currpassword,
+ m_currpassword != null, true, -1, null);
+ use_gs = false;
+ break;
case Save_Type_t.PDF13:
options = "-dCompatibilityLevel=1.3";
break;
@@ -2324,26 +2661,29 @@ namespace gsview
/* Non PDF output */
gsDevice_t Device = gsDevice_t.xpswrite;
bool use_mupdf = true;
+ String Message = "";
+ textout_t textout = textout_t.HTML;
switch (type)
{
- case Save_Type_t.LINEAR_PDF:
- dlg.Filter = "PDF (*.pdf)|*.pdf";
- if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- mu_doc.PDFExtract(m_currfile, dlg.FileName, m_currpassword,
- m_currpassword != null, true, -1, null);
- }
+ case Save_Type_t.HTML:
+ dlg.Filter = "HTML (*.html)|*.html";
+ Message = "HTML content written";
+ break;
+ case Save_Type_t.XML:
+ dlg.Filter = "XML (*.xml)|*.xml";
+ Message = "XML content written";
+ textout = textout_t.XML;
+ break;
+ case Save_Type_t.TEXT:
+ dlg.Filter = "Text (*.txt)|*.txt";
+ Message = "Text content written";
+ textout = textout_t.TEXT;
break;
case Save_Type_t.PCLXL:
use_mupdf = false;
dlg.Filter = "PCL-XL (*.bin)|*.bin";
Device = gsDevice_t.pxlcolor;
break;
- case Save_Type_t.TEXT:
- use_mupdf = false;
- dlg.Filter = "Text Files(*.txt)|*.txt";
- Device = gsDevice_t.txtwrite;
- break;
case Save_Type_t.XPS:
use_mupdf = false;
dlg.Filter = "XPS Files(*.xps)|*.xps";
@@ -2363,6 +2703,58 @@ namespace gsview
}
}
}
+ else
+ {
+ if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
+ {
+ /* Write out first non null page then append the rest */
+ int curr_page = 0;
+ bool done = false;
+
+ while (!done)
+ {
+ String output = null;
+ output = mu_doc.GetText(curr_page, textout);
+ if (output == null)
+ {
+ curr_page = curr_page + 1;
+ if (curr_page == m_num_pages)
+ {
+ ShowMessage(NotifyType_t.MESS_STATUS, "No text found in file");
+ return;
+ }
+ }
+ else
+ {
+ System.IO.File.WriteAllText(dlg.FileName, output);
+ done = true;
+ }
+ }
+ curr_page = curr_page + 1;
+
+ if (curr_page == m_num_pages)
+ {
+ ShowMessage(NotifyType_t.MESS_STATUS, Message);
+ return;
+ }
+ done = false;
+ while (!done)
+ {
+ String output = null;
+ output = mu_doc.GetText(curr_page, textout);
+ if (output != null)
+ {
+ System.IO.File.AppendAllText(dlg.FileName, output);
+ }
+ curr_page = curr_page + 1;
+ if (curr_page == m_num_pages)
+ {
+ ShowMessage(NotifyType_t.MESS_STATUS, Message);
+ return;
+ }
+ }
+ }
+ }
}
}
@@ -2381,6 +2773,11 @@ namespace gsview
SaveFile(Save_Type_t.TEXT);
}
+ private void SaveXML(object sender, RoutedEventArgs e)
+ {
+ SaveFile(Save_Type_t.XML);
+ }
+
private void SaveHTML(object sender, RoutedEventArgs e)
{
SaveFile(Save_Type_t.HTML);
@@ -2489,11 +2886,12 @@ namespace gsview
{
Byte[] bitmap = new byte[(int)ras_size.X * (int)ras_size.Y * 4];
BlocksText charlist;
+ Annotate_t annot;
Task<int> ren_task =
new Task<int>(() => mu_doc.RenderPage(page_num, bitmap,
(int)ras_size.X, (int)ras_size.Y, zoom, false, true,
- false, out charlist));
+ false, out charlist, true, out annot));
ren_task.Start();
await ren_task.ContinueWith((antecedent) =>
{
@@ -2608,10 +3006,6 @@ namespace gsview
{
Extract(Extract_Type_t.PS);
}
- private void ExtractSVG(object sender, RoutedEventArgs e)
- {
- Extract(Extract_Type_t.SVG);
- }
private void OutputIntents(object sender, RoutedEventArgs e)
{
m_outputintents.Show();
@@ -3078,7 +3472,7 @@ namespace gsview
{
if (m_currpage != link.PageNum && link.PageNum >= 0 &&
link.PageNum < m_num_pages)
- RenderRange(link.PageNum, true, false, 0);
+ RenderRange(link.PageNum, true, zoom_t.NO_ZOOM, 0);
}
else if (link.Type == Link_t.LINK_URI)
System.Diagnostics.Process.Start(link.Urilink.AbsoluteUri);
@@ -3109,6 +3503,8 @@ namespace gsview
}
m_textSelect.Clear();
m_textselected = false;
+ m_selectall = false;
+ SetSelectAll(m_blockcolor);
}
private void InitTextSelection(DocPage page)
@@ -3171,7 +3567,7 @@ namespace gsview
if (page.Content != Page_Content_t.FULL_RESOLUTION ||
page.Zoom != m_doczoom)
{
- RenderRange(page.PageNum, false, false, 0);
+ RenderRange(page.PageNum, false, zoom_t.NO_ZOOM, 0);
}
UpdateSelection(pos, page);
@@ -3283,7 +3679,8 @@ namespace gsview
for (int kk = 0; kk < lines.Count; kk++)
{
double scale = m_doczoom / lines[kk].Scale;
- var intersect_line = lines[kk].CheckIntersection(x * scale, y * scale, w * scale, h * scale);
+ //var intersect_line = lines[kk].CheckIntersection(x * scale, y * scale, w * scale, h * scale);
+ var intersect_line = lines[kk].CheckIntersection(x / scale , y / scale , w / scale , h / scale);
if (intersect_line == Intersection_t.FULL)
{
m_lineptrs[page.PageNum].Add(lines[kk]);
@@ -3670,6 +4067,12 @@ namespace gsview
private void CheckIfSelected()
{
m_textselected = false;
+
+ if (m_selectall)
+ {
+ SetSelectAll(m_blockcolor);
+ m_selectall = false;
+ }
/* Check if anything was selected */
for (int kk = 0; kk < m_lineptrs.Count; kk++)
{
@@ -3873,7 +4276,7 @@ namespace gsview
info.page_num = page.PageNum;
can.ContextMenu = contextmenu;
- if (m_textselected)
+ if (m_textselected || m_selectall)
{
var m1 = new System.Windows.Controls.MenuItem();
m1.Header = "Copy";
@@ -3939,14 +4342,75 @@ namespace gsview
m4.Tag = info;
contextmenu.Items.Add(m4);
- /*var m5 = new System.Windows.Controls.MenuItem();
+ var m5 = new System.Windows.Controls.MenuItem();
m5.Header = "Select All";
m5.Click += cntxMenuSelectAll;
- contextmenu.Items.Add(m5);*/
+ contextmenu.Items.Add(m5);
+ }
+
+ private void CopyTextDone(object sender, RunWorkerCompletedEventArgs e)
+ {
+ String result = (String) e.Result;
+ xaml_CopyTextProgress.Visibility = System.Windows.Visibility.Collapsed;
+ xaml_CopyTextProgress.Value = 0;
+
+ try
+ {
+ System.Windows.Clipboard.SetText(result);
+ }
+ catch
+ {
+ return;
+ }
+ }
+
+ private void CopyTextWork(object sender, DoWorkEventArgs e)
+ {
+ String output = null;
+ String fullstring = null;
+ BackgroundWorker worker = sender as BackgroundWorker;
+
+ for (int k = 0; k < m_num_pages; k++)
+ {
+ output = mu_doc.GetText(k, textout_t.TEXT);
+ if (output != null)
+ fullstring = fullstring + output;
+
+ double percent = 100 * (double)(k + 1) / (double)m_num_pages;
+ worker.ReportProgress((int)percent, output);
+
+ if (worker.CancellationPending == true)
+ {
+ e.Cancel = true;
+ break;
+ }
+ }
+ e.Result = fullstring;
+ }
+
+ private void CopyTextProgress(object sender, ProgressChangedEventArgs e)
+ {
+ String output = (String)(e.UserState);
+ xaml_CopyTextProgress.Value = e.ProgressPercentage;
}
private void cntxMenuCopy(object sender, RoutedEventArgs e)
{
+ if (m_selectall)
+ {
+ /* Start a thread to go through and copy the pages to the
+ * clipboard */
+ m_copytext = new BackgroundWorker();
+ m_copytext.WorkerReportsProgress = true;
+ m_copytext.WorkerSupportsCancellation = true;
+ m_copytext.DoWork += new DoWorkEventHandler(CopyTextWork);
+ m_copytext.RunWorkerCompleted += new RunWorkerCompletedEventHandler(CopyTextDone);
+ m_copytext.ProgressChanged += new ProgressChangedEventHandler(CopyTextProgress);
+ xaml_CopyTextProgress.Visibility = System.Windows.Visibility.Visible;
+ m_copytext.RunWorkerAsync();
+ return;
+ }
+
/* Go through and get each line of text */
String result = null;
@@ -4065,8 +4529,6 @@ namespace gsview
CheckIfSelected();
}
- /* We need to await on the render range TODO FIXME Disable for now */
- /*
private void cntxMenuSelectAll(object sender, RoutedEventArgs e)
{
var mi = sender as System.Windows.Controls.MenuItem;
@@ -4075,26 +4537,49 @@ namespace gsview
else
m_textSelect = new List<textSelectInfo_t>();
- SelectFullPage(0);
- for (int kk = 1; kk < m_num_pages; kk++)
+ m_selectall = true;
+ SetSelectAll(m_textselectcolor);
+ }
+
+ private void SetSelectAll(String color)
+ {
+ if (!m_init_done)
+ return;
+
+ for (int kk = 0; kk < m_num_pages; kk++)
{
- if (!m_textset[kk])
- RenderRange(kk, false, false, 0);
- var page = m_docPages[kk];
- Point pos = new Point();
- pos.X = page.Width;
- pos.Y = page.Height;
- UpdateSelection(pos, page);
+ if (m_docPages[kk] != null && m_docPages[kk].TextBlocks != null)
+ {
+ int num_blocks = m_docPages[kk].TextBlocks.Count;
+ for (int jj = 0; jj < num_blocks; jj++)
+ m_docPages[kk].TextBlocks[jj].Color = color;
+ }
}
- CheckIfSelected();
}
- */
private void cntxMenuDeselectAll(object sender, RoutedEventArgs e)
{
ClearSelections();
}
+ private void SelectAllCommand(object sender, ExecutedRoutedEventArgs e)
+ {
+ if (m_init_done)
+ cntxMenuSelectAll(sender, e);
+ }
+
+ private void CopyCommand(object sender, ExecutedRoutedEventArgs e)
+ {
+ if (m_init_done)
+ cntxMenuCopy(sender, e);
+ }
+
+ private void CancelCopyText(object sender, RoutedEventArgs e)
+ {
+ if (m_copytext != null && m_copytext.IsBusy)
+ m_copytext.CancelAsync();
+ }
+
/* To add with annotation support */
/*
private void cntxMenuHighlight(object sender, RoutedEventArgs e)
@@ -4152,12 +4637,12 @@ namespace gsview
about.ShowDialog();
}
- private void OnHelpClick(object sender, RoutedEventArgs e)
+ private void HelpCommand(object sender, ExecutedRoutedEventArgs e)
{
-
+ OnHelpClick(sender, e);
}
- private void SaveXML(object sender, RoutedEventArgs e)
+ private void OnHelpClick(object sender, RoutedEventArgs e)
{
}
@@ -4168,93 +4653,226 @@ namespace gsview
DimSelections();
}
- /* Due to the scroll viewer being wonky on its updating during zooming
- * we have to do this */
+ private double GetTotalHeightZoom()
+ {
+ return m_totalpageheight * m_doczoom + (m_num_pages - 1) * Constants.PAGE_MARGIN;
+ }
+
+ private double GetTotalHeightNoZoom()
+ {
+ return m_totalpageheight + (m_num_pages - 1) * Constants.PAGE_MARGIN;
+ }
+
+ private double GetViewPortSize()
+ {
+ ScrollViewer viewer = FindScrollViewer(xaml_PageList);
+ return viewer.ViewportHeight;
+ }
+
+ private void SetThumbwidth()
+ {
+ double percent = GetViewPortSize() / GetTotalHeightZoom();
+ double range = xaml_VerticalScroll.Maximum - xaml_VerticalScroll.Minimum;
+ xaml_VerticalScroll.SetThumbLength(percent * range);
+ }
+
+ private void AdjustScrollPercent(double percent)
+ {
+ double curr_value = xaml_VerticalScroll.Value;
+ double range = xaml_VerticalScroll.Maximum;
+ double step = range * percent;
+
+ xaml_VerticalScroll.Value = curr_value + step;
+ }
+
+ /* Due to the scroll bar on the scroll viewer being wonky on its updating during zooming
+ * we have to do this ourselves */
private void VerticalScroll(object sender, System.Windows.Controls.Primitives.ScrollEventArgs e)
{
var mi = sender as System.Windows.Controls.Primitives.ScrollBar;
ScrollViewer viewer = FindScrollViewer(xaml_PageList);
if (viewer == null || mi == null)
return;
-
- if (e.ScrollEventType == System.Windows.Controls.Primitives.ScrollEventType.EndScroll)
+
+ if (e.ScrollEventType == System.Windows.Controls.Primitives.ScrollEventType.ThumbTrack)
{
- /* figure out where we are percent wise */
- double perc = mi.Value / mi.Maximum;
- /* Get the page that we are in. This needs to be cleaned
- up to handle docs with variable page sizes and to account
- for being partially in page */
- double step = 100.0 / m_num_pages;
- int page_num = (int) Math.Floor(perc * 100.0 / step);
- if (page_num > m_num_pages - 1)
- page_num = m_num_pages - 1;
-
- m_ignorescrollchange = true;
- RenderRange(page_num, true, false, 0);
+ OffsetScrollPercent(mi.Value / mi.Maximum);
+ e.Handled = true;
+ }
+ else if (e.ScrollEventType == System.Windows.Controls.Primitives.ScrollEventType.First)
+ {
+ mi.Value = 0;
+ viewer.ScrollToTop();
+ }
+ else if (e.ScrollEventType == System.Windows.Controls.Primitives.ScrollEventType.Last)
+ {
+ mi.Value = mi.Maximum;
+ viewer.ScrollToBottom();
}
else if (e.ScrollEventType == System.Windows.Controls.Primitives.ScrollEventType.SmallDecrement)
{
- double curr_value = viewer.VerticalOffset;
- viewer.ScrollToVerticalOffset(curr_value - Constants.VERT_SCROLL_STEP);
+ OffsetScroll(-Constants.VERT_SCROLL_STEP * m_doczoom);
}
else if (e.ScrollEventType == System.Windows.Controls.Primitives.ScrollEventType.SmallIncrement)
{
- double curr_value = viewer.VerticalOffset;
- viewer.ScrollToVerticalOffset(curr_value + Constants.VERT_SCROLL_STEP);
+ OffsetScroll(Constants.VERT_SCROLL_STEP * m_doczoom);
}
else if (e.ScrollEventType == System.Windows.Controls.Primitives.ScrollEventType.LargeDecrement)
{
- OnBackPageClick(null, null);
+ if (m_currpage == 0)
+ {
+ mi.Value = 0;
+ viewer.ScrollToTop();
+ }
+ else
+ OnBackPageClick(null, null);
}
else if (e.ScrollEventType == System.Windows.Controls.Primitives.ScrollEventType.LargeIncrement)
{
- OnForwardPageClick(null, null);
+ if (m_currpage == m_num_pages - 1)
+ {
+ mi.Value = mi.Maximum;
+ viewer.ScrollToBottom();
+ }
+ else
+ OnForwardPageClick(null, null);
+ }
+ else if (e.ScrollEventType == System.Windows.Controls.Primitives.ScrollEventType.ThumbPosition)
+ {
+ OffsetScrollPercent(e.NewValue / mi.Maximum);
}
}
private void OnAAChecked(object sender, RoutedEventArgs e)
{
- m_AA = xaml_AA.IsChecked;
+ var control = sender as System.Windows.Controls.Control;
+ string Name = control.Name;
+
+ /* It would be nice to uncheck all and then recheck the one
+ * that we want to avoid the repeated code below, but that puts
+ * us in a infinite recursion with the call from the xaml Checked
+ * call */
+
+ switch (Name)
+ {
+ case "xaml_AA_High":
+ m_AA = AA_t.HIGH;
+ if (xaml_AA_MedHigh != null)
+ xaml_AA_MedHigh.IsChecked = false;
+ if (xaml_AA_Med != null)
+ xaml_AA_Med.IsChecked = false;
+ if (xaml_AA_Low != null)
+ xaml_AA_Low.IsChecked = false;
+ if (xaml_AA_None != null)
+ xaml_AA_None.IsChecked = false;
+ break;
+ case "xaml_AA_MedHigh":
+ m_AA = AA_t.MEDHIGH;
+ if (xaml_AA_High != null)
+ xaml_AA_High.IsChecked = false;
+ if (xaml_AA_Med != null)
+ xaml_AA_Med.IsChecked = false;
+ if (xaml_AA_Low != null)
+ xaml_AA_Low.IsChecked = false;
+ if (xaml_AA_None != null)
+ xaml_AA_None.IsChecked = false;
+ break;
+ case "xaml_AA_Med":
+ m_AA = AA_t.MED;
+ if (xaml_AA_High != null)
+ xaml_AA_High.IsChecked = false;
+ if (xaml_AA_MedHigh != null)
+ xaml_AA_MedHigh.IsChecked = false;
+ if (xaml_AA_Low != null)
+ xaml_AA_Low.IsChecked = false;
+ if (xaml_AA_None != null)
+ xaml_AA_None.IsChecked = false;
+ break;
+ case "xaml_AA_Low":
+ m_AA = AA_t.LOW;
+ if (xaml_AA_High != null)
+ xaml_AA_High.IsChecked = false;
+ if (xaml_AA_MedHigh != null)
+ xaml_AA_MedHigh.IsChecked = false;
+ if (xaml_AA_Med != null)
+ xaml_AA_Med.IsChecked = false;
+ if (xaml_AA_None != null)
+ xaml_AA_None.IsChecked = false;
+ break;
+ case "xaml_AA_None":
+ m_AA = AA_t.NONE;
+ if (xaml_AA_High != null)
+ xaml_AA_High.IsChecked = false;
+ if (xaml_AA_MedHigh != null)
+ xaml_AA_MedHigh.IsChecked = false;
+ if (xaml_AA_Med != null)
+ xaml_AA_Med.IsChecked = false;
+ if (xaml_AA_Low != null)
+ xaml_AA_Low.IsChecked = false;
+ break;
+ }
if (mu_doc != null)
mu_doc.SetAA(m_AA);
if (m_init_done)
- RenderRange(m_currpage, false, false, 0);
+ RenderRange(m_currpage, false, zoom_t.NO_ZOOM, 0);
}
- private void OnKeyDownHandler(object sender, System.Windows.Input.KeyEventArgs e)
+ private AA_t GetAA()
{
- switch (e.Key)
- {
- case Key.Left:
- if (m_currpage == 0 || !m_init_done)
- return;
- m_ignorescrollchange = true;
- RenderRange(m_currpage - 1, true, false, 0);
- e.Handled = true;
- break;
-
- case Key.Right:
- if (m_currpage == m_num_pages - 1 || !m_init_done)
- return;
- m_ignorescrollchange = true;
- RenderRange(m_currpage + 1, true, false, 0);
- e.Handled = true;
- break;
+ if (xaml_AA_High.IsChecked)
+ return AA_t.HIGH;
+ else if (xaml_AA_MedHigh.IsChecked)
+ return AA_t.MEDHIGH;
+ else if (xaml_AA_Med.IsChecked)
+ return AA_t.MED;
+ else if (xaml_AA_Low.IsChecked)
+ return AA_t.LOW;
+ else
+ return AA_t.NONE;
+ }
- case Key.Up:
- if (!m_init_done)
- return;
- e.Handled = true;
- OffsetScroll(-Constants.VERT_SCROLL_STEP * m_doczoom);
- break;
+ private void SetAA(AA_t aa)
+ {
+ xaml_AA_High.IsChecked = false;
+ xaml_AA_MedHigh.IsChecked = false;
+ xaml_AA_Med.IsChecked = false;
+ xaml_AA_Low.IsChecked = false;
+ xaml_AA_None.IsChecked = false;
- case Key.Down:
- if (!m_init_done)
- return;
- e.Handled = true;
- OffsetScroll(Constants.VERT_SCROLL_STEP * m_doczoom);
- break;
+ switch (aa)
+ {
+ case AA_t.HIGH:
+ xaml_AA_High.IsChecked = true;
+ break;
+ case AA_t.MEDHIGH:
+ xaml_AA_MedHigh.IsChecked = true;
+ break;
+ case AA_t.MED:
+ xaml_AA_High.IsChecked = true;
+ break;
+ case AA_t.LOW:
+ xaml_AA_High.IsChecked = true;
+ break;
+ case AA_t.NONE:
+ xaml_AA_High.IsChecked = true;
+ break;
}
}
+
+ private void AnnotationOn(object sender, RoutedEventArgs e)
+ {
+ if (!m_init_done)
+ return;
+ m_showannot = true;
+ RenderRange(m_currpage, false, zoom_t.NO_ZOOM, 0);
+ }
+
+ private void AnnotationOff(object sender, RoutedEventArgs e)
+ {
+ if (!m_init_done)
+ return;
+ m_showannot = false;
+ RenderRange(m_currpage, false, zoom_t.NO_ZOOM, 0);
+ }
}
} \ No newline at end of file
diff --git a/platform/winrt/gsview/TextBlock.cs b/platform/winrt/gsview/TextBlock.cs
index 25378831..55d3e744 100644
--- a/platform/winrt/gsview/TextBlock.cs
+++ b/platform/winrt/gsview/TextBlock.cs
@@ -89,7 +89,7 @@ namespace gsview
set
{
color = value;
- //OnPropertyChanged("Color");
+ OnPropertyChanged("Color");
}
}
diff --git a/platform/winrt/gsview/ghostsharp.cs b/platform/winrt/gsview/ghostsharp.cs
index f8b7c14c..b5451645 100644
--- a/platform/winrt/gsview/ghostsharp.cs
+++ b/platform/winrt/gsview/ghostsharp.cs
@@ -193,7 +193,7 @@ namespace gsview
[DllImport("gsdll64.dll", EntryPoint = "gsapi_set_stdio", CharSet = CharSet.Ansi,
CallingConvention = CallingConvention.StdCall)]
- private static extern int gsapi_set_stdio64(IntPtr instance,
+ private static extern int gsapi_set_stdio64(IntPtr instance,
gsStdIOHandler stdin, gsStdIOHandler stdout, gsStdIOHandler stderr);
[DllImport("gsdll64.dll", EntryPoint = "gsapi_run_string_begin", CharSet = CharSet.Ansi,
@@ -348,6 +348,7 @@ namespace gsview
private int tc_gsapi_init_with_args(IntPtr instance, int argc, IntPtr argv)
{
int code;
+
try
{
if (is64bit)
@@ -369,6 +370,13 @@ namespace gsview
gsDLLProblemMain(this, output);
return -1;
}
+ catch(System.Reflection.TargetInvocationException ee)
+ {
+ String output = "TargetInvocationException";
+ gsDLLProblemMain(this, output);
+ return -1;
+ }
+
return code;
}
@@ -612,13 +620,24 @@ namespace gsview
internal event gsIOCallBackMain gsIOUpdateMain;
internal delegate void gsCallBackMain(object gsObject, gsEventArgs info);
internal event gsCallBackMain gsUpdateMain;
+ /* These need to be declared as members, to keep a reference and avoid GC
+ * You do not pin delegates */
+ gsStdIOHandler RaiseStdInCallback;
+ gsStdIOHandler RaiseStdOutCallback;
+ gsStdIOHandler RaiseStdErrCallback;
public ghostsharp()
{
/* Determine now if we are 64 or 32 bit */
- is64bit = EnvironmentCheck.IS64Bit;
+ is64bit = Environment.Is64BitOperatingSystem &&
+ Environment.Is64BitProcess;
m_worker = null;
gsInstance = IntPtr.Zero;
+
+ /* Go ahead and do the assignment here */
+ RaiseStdInCallback = StdInCallback;
+ RaiseStdOutCallback = StdOutCallback;
+ RaiseStdErrCallback = StdErrCallback;
}
private List<String> GetOptions(String options)
@@ -678,17 +697,8 @@ namespace gsview
return;
}
- var RaiseStdInCallback = new gsStdIOHandler(StdInCallback);
- var RaiseStdOutCallback = new gsStdIOHandler(StdOutCallback);
- var RaiseStdErrCallback = new gsStdIOHandler(StdErrCallback);
-
- var stdInPtr = Marshal.GetFunctionPointerForDelegate(RaiseStdInCallback);
- var stdOutPtr = Marshal.GetFunctionPointerForDelegate(RaiseStdOutCallback);
- var stdErrPtr = Marshal.GetFunctionPointerForDelegate(RaiseStdErrCallback);
-
- // Setup stdio callback functions
- code = tc_gsapi_set_stdio(gsInstance, RaiseStdInCallback, RaiseStdOutCallback, RaiseStdErrCallback);
-
+ code = tc_gsapi_set_stdio(gsInstance, RaiseStdInCallback,
+ RaiseStdOutCallback, RaiseStdErrCallback);
code = tc_gsapi_set_arg_encoding(gsInstance, (int)gsEncoding.GS_ARG_ENCODING_UTF8);
if (code == 0)
@@ -780,7 +790,6 @@ namespace gsview
argPtrsStable = GCHandle.Alloc(argPtrs, GCHandleType.Pinned);
code = tc_gsapi_init_with_args(gsInstance, num_params, argPtrsStable.AddrOfPinnedObject());
-
/* All the pinned items need to be freed so the GC can do its job */
for (int k = 0; k < num_params; k++)
{
@@ -789,7 +798,7 @@ namespace gsview
argPtrsStable.Free();
/* Free the character array list in case we have multiple runs */
CharacterArray.Clear();
-
+
if (code < 0)
break;
}
@@ -799,10 +808,6 @@ namespace gsview
if ((code == 0) || (code == gsConstants.E_QUIT))
code = code1;
- RaiseStdInCallback = null;
- RaiseStdOutCallback = null;
- RaiseStdErrCallback = null;
-
tc_gsapi_delete_instance(gsInstance);
if ((code == 0) || (code == gsConstants.E_QUIT))
{
@@ -849,17 +854,8 @@ namespace gsview
return;
}
- var RaiseStdInCallback = new gsStdIOHandler(StdInCallback);
- var RaiseStdOutCallback = new gsStdIOHandler(StdOutCallback);
- var RaiseStdErrCallback = new gsStdIOHandler(StdErrCallback);
-
- var stdInPtr = Marshal.GetFunctionPointerForDelegate(RaiseStdInCallback);
- var stdOutPtr = Marshal.GetFunctionPointerForDelegate(RaiseStdOutCallback);
- var stdErrPtr = Marshal.GetFunctionPointerForDelegate(RaiseStdErrCallback);
-
- // Setup stdio callback functions
- code = tc_gsapi_set_stdio(gsInstance, RaiseStdInCallback, RaiseStdOutCallback, RaiseStdErrCallback);
-
+ code = tc_gsapi_set_stdio(gsInstance, RaiseStdInCallback,
+ RaiseStdOutCallback, RaiseStdErrCallback);
code = tc_gsapi_set_arg_encoding(gsInstance, (int)gsEncoding.GS_ARG_ENCODING_UTF8);
if (code == 0)
@@ -967,8 +963,40 @@ namespace gsview
{
gsParams_t Value;
gsEventArgs info;
- gsParams_t Params = (gsParams_t) e.Result;
+ gsParams_t Params;
+ try
+ {
+ Params = (gsParams_t)e.Result;
+ }
+ catch(System.Reflection.TargetInvocationException ee)
+ {
+ /* Something went VERY wrong with GS */
+ /* Following is to help debug these issues */
+ /* var inner = ee.InnerException;
+ var message = ee.Message;
+ var inner_message = inner.Message;
+ String bound = "\n************\n";
+ gsIOUpdateMain(this, bound, bound.Length);
+ gsIOUpdateMain(this, message, message.Length);
+ gsIOUpdateMain(this, bound, bound.Length);
+ gsIOUpdateMain(this, inner_message, inner_message.Length);
+ gsIOUpdateMain(this, bound, bound.Length);
+ var temp = inner.Source;
+ gsIOUpdateMain(this, bound, bound.Length);
+ gsIOUpdateMain(this, temp, temp.Length);
+ var method = inner.TargetSite;
+ gsIOUpdateMain(this, bound, bound.Length);
+ var method_name = method.Name;
+ gsIOUpdateMain(this, method_name, method_name.Length);
+ var stack = inner.StackTrace;
+ gsIOUpdateMain(this, bound, bound.Length);
+ gsIOUpdateMain(this, stack, stack.Length); */
+ String output = "Ghostscript DLL Invalid Access.";
+ gsDLLProblemMain(this, output);
+ return;
+ }
+
if (Params.task == GS_Task_t.PS_DISTILL)
m_worker.DoWork -= new DoWorkEventHandler(gsWork2);
else
@@ -1111,6 +1139,7 @@ namespace gsview
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
@@ -1132,49 +1161,4 @@ namespace gsview
m_worker.CancelAsync();
}
}
-
- /* We need to determine if we are a 64 bit or 32 bit process. In .NET 4+
- * there is a simple check, Environment.Is64BitProcess. I don't want to
- * rely upon having that new of version. Hence, the following */
- public static class EnvironmentCheck
- {
- [StructLayout(LayoutKind.Sequential)]
- internal struct SYSTEM_INFO
- {
- public ushort processorArchitecture;
- ushort reserved;
- public uint pageSize;
- public IntPtr minimumApplicationAddress;
- public IntPtr maximumApplicationAddress;
- public IntPtr activeProcessorMask;
- public uint numberOfProcessors;
- public uint processorType;
- public uint allocationGranularity;
- public ushort processorLevel;
- public ushort processorRevision;
- }
-
- [DllImport("kernel32.dll")]
- internal static extern void GetNativeSystemInfo(ref SYSTEM_INFO si);
- [DllImport("kernel32.dll")]
- internal static extern bool IsWow64Process(IntPtr handle, out bool result);
- [DllImport("kernel32.dll")]
- internal static extern IntPtr GetCurrentProcess();
-
- public static bool IS64Bit
- {
- get
- {
- SYSTEM_INFO si = new SYSTEM_INFO();
- GetNativeSystemInfo(ref si);
- if (si.processorArchitecture == 0) // zero means x86
- return false;
- bool result;
-
- if (!IsWow64Process(GetCurrentProcess(), out result))
- throw new InvalidOperationException();
- return !result;
- }
- }
- }
}
diff --git a/platform/winrt/gsview/gsview.csproj b/platform/winrt/gsview/gsview.csproj
index 25ac57c6..d2bcb190 100644
--- a/platform/winrt/gsview/gsview.csproj
+++ b/platform/winrt/gsview/gsview.csproj
@@ -76,7 +76,6 @@
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
- <Reference Include="WindowsFormsIntegration" />
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
diff --git a/platform/winrt/gsview/mudocument.cs b/platform/winrt/gsview/mudocument.cs
index e0c56ea6..47bd4d82 100644
--- a/platform/winrt/gsview/mudocument.cs
+++ b/platform/winrt/gsview/mudocument.cs
@@ -149,6 +149,10 @@ namespace gsview
private static extern IntPtr mCreateDisplayList64(IntPtr ctx, int page_num,
ref int page_width, ref int page_height);
+ [DllImport("mupdfnet64.dll", EntryPoint = "mCreateDisplayListAnnot",
+ CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
+ private static extern IntPtr mCreateDisplayListAnnot64(IntPtr ctx, int page_num);
+
[DllImport("mupdfnet64.dll", EntryPoint = "mCreateDisplayListText", CharSet = CharSet.Auto,
CallingConvention = CallingConvention.StdCall)]
private static extern IntPtr mCreateDisplayListText64(IntPtr ctx, int page_num,
@@ -157,8 +161,8 @@ namespace gsview
[DllImport("mupdfnet64.dll", EntryPoint = "mRenderPageMT", CharSet = CharSet.Auto,
CallingConvention = CallingConvention.StdCall)]
private static extern int mRenderPageMT64(IntPtr ctx, IntPtr dlist,
- int page_width, int page_height, Byte[] bmp_data, int bmp_width,
- int bmp_height, double scale, bool flipy);
+ IntPtr annot_dlist, int page_width, int page_height, Byte[] bmp_data,
+ int bmp_width, int bmp_height, double scale, bool flipy);
[DllImport("mupdfnet64.dll", EntryPoint = "mTextSearchPage", CharSet = CharSet.Auto,
CallingConvention = CallingConvention.StdCall)]
@@ -228,6 +232,12 @@ namespace gsview
[return: MarshalAs(UnmanagedType.LPStr)]
private static extern string mGetVers64();
+ /* The managed code Marshal actually releases the allocated string from C */
+ [DllImport("mupdfnet64.dll", EntryPoint = "mGetText", CharSet = CharSet.Ansi,
+ CallingConvention = CallingConvention.StdCall)]
+ [return: MarshalAs(UnmanagedType.LPStr)]
+ private static extern string mGetText64(IntPtr ctx, int pagenum, int type);
+
/* And the 32bit version */
[DllImport("mupdfnet32.dll", EntryPoint = "mInitialize", CharSet = CharSet.Auto,
CallingConvention = CallingConvention.StdCall)]
@@ -287,6 +297,11 @@ namespace gsview
private static extern IntPtr mCreateDisplayList32(IntPtr ctx, int page_num,
ref int page_width, ref int page_height);
+ [DllImport("mupdfnet32.dll", EntryPoint = "mCreateDisplayListAnnot",
+ CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
+ private static extern IntPtr mCreateDisplayListAnnot32(IntPtr ctx, int page_num);
+
+
[DllImport("mupdfnet32.dll", EntryPoint = "mCreateDisplayListText", CharSet = CharSet.Auto,
CallingConvention = CallingConvention.StdCall)]
private static extern IntPtr mCreateDisplayListText32(IntPtr ctx, int page_num,
@@ -295,8 +310,8 @@ namespace gsview
[DllImport("mupdfnet32.dll", EntryPoint = "mRenderPageMT", CharSet = CharSet.Auto,
CallingConvention = CallingConvention.StdCall)]
private static extern int mRenderPageMT32(IntPtr ctx, IntPtr dlist,
- int page_width, int page_height, Byte[] bmp_data, int bmp_width,
- int bmp_height, double scale, bool flipy);
+ IntPtr annot_dlist, int page_width, int page_height, Byte[] bmp_data,
+ int bmp_width, int bmp_height, double scale, bool flipy);
[DllImport("mupdfnet32.dll", EntryPoint = "mTextSearchPage", CharSet = CharSet.Auto,
CallingConvention = CallingConvention.StdCall)]
@@ -366,6 +381,12 @@ namespace gsview
[return: MarshalAs(UnmanagedType.LPStr)]
private static extern string mGetVers32();
+ /* The managed code Marshal actually releases the allocated string from C */
+ [DllImport("mupdfnet32.dll", EntryPoint = "mGetText", CharSet = CharSet.Ansi,
+ CallingConvention = CallingConvention.StdCall)]
+ [return: MarshalAs(UnmanagedType.LPStr)]
+ private static extern string mGetText32(IntPtr ctx, int pagenum, int type);
+
#endregion DLLInterface
#region DLLErrorTrap
@@ -670,6 +691,33 @@ namespace gsview
return output;
}
+ private IntPtr tc_mCreateDisplayListAnnot(IntPtr ctx, int page_num)
+ {
+ IntPtr output;
+ try
+ {
+ if (is64bit)
+ output = mCreateDisplayListAnnot64(ctx, page_num);
+ else
+ output = mCreateDisplayListAnnot32(ctx, page_num);
+ }
+ catch (DllNotFoundException)
+ {
+ /* DLL not found */
+ String err = "DllNotFoundException: MuPDF DLL not found";
+ mupdfDLLProblemMain(this, err);
+ return IntPtr.Zero;
+ }
+ catch (BadImageFormatException)
+ {
+ /* Using 32 bit with 64 or vice versa */
+ String err = "BadImageFormatException: Incorrect MuPDF DLL";
+ mupdfDLLProblemMain(this, err);
+ return IntPtr.Zero;
+ }
+ return output;
+ }
+
private IntPtr tc_mCreateDisplayList(IntPtr ctx, int page_num,
ref int page_width, ref int page_height)
{
@@ -756,19 +804,19 @@ namespace gsview
return output;
}
- private int tc_mRenderPageMT(IntPtr ctx, IntPtr dlist, int page_width,
- int page_height, Byte[] bmp_data, int bmp_width, int bmp_height,
- double scale, bool flipy)
+ private int tc_mRenderPageMT(IntPtr ctx, IntPtr dlist, IntPtr annot_dlist,
+ int page_width, int page_height, Byte[] bmp_data, int bmp_width,
+ int bmp_height, double scale, bool flipy)
{
int output;
try
{
if (is64bit)
- output = mRenderPageMT64(ctx, dlist, page_width, page_height,
- bmp_data, bmp_width, bmp_height, scale, flipy);
+ output = mRenderPageMT64(ctx, dlist, annot_dlist, page_width,
+ page_height, bmp_data, bmp_width, bmp_height, scale, flipy);
else
- output = mRenderPageMT32(ctx, dlist, page_width, page_height,
- bmp_data, bmp_width, bmp_height, scale, flipy);
+ output = mRenderPageMT32(ctx, dlist, annot_dlist, page_width,
+ page_height, bmp_data, bmp_width, bmp_height, scale, flipy);
}
catch (DllNotFoundException)
{
@@ -1130,6 +1178,35 @@ namespace gsview
return output;
}
+ private string tc_mGetText(IntPtr ctx, int pagenum, textout_t type)
+ {
+ String output;
+ try
+ {
+ if (is64bit)
+ output = mGetText64(ctx, pagenum, (int) type);
+ else
+ output = mGetText32(ctx, pagenum, (int) type);
+ }
+ catch (DllNotFoundException)
+ {
+ /* DLL not found */
+ String err = "DllNotFoundException: MuPDF DLL not found";
+ mupdfDLLProblemMain(this, err);
+ return null;
+ }
+ catch (BadImageFormatException)
+ {
+ /* Using 32 bit with 64 or vice versa */
+ String err = "BadImageFormatException: Incorrect MuPDF DLL";
+ mupdfDLLProblemMain(this, err);
+ return null;
+ }
+ return output;
+ }
+
+
+
private int tc_mSavePage(IntPtr ctx, String outfile, int page_num,
int res, int type, bool append)
{
@@ -1162,7 +1239,8 @@ namespace gsview
/* Now the actual code that does some work */
public status_t Initialize()
{
- is64bit = EnvironmentCheck.IS64Bit;
+ is64bit = is64bit = Environment.Is64BitOperatingSystem &&
+ Environment.Is64BitProcess;
mu_object = tc_mInitialize();
if (mu_object == null)
return status_t.E_FAILURE;
@@ -1179,6 +1257,11 @@ namespace gsview
}
}
+ public String GetText(int page_num, textout_t type)
+ {
+ return tc_mGetText(mu_object, page_num, type);
+ }
+
public void GetVersion(out String vers)
{
vers = tc_mGetVers();
@@ -1199,34 +1282,31 @@ namespace gsview
return tc_mApplyPassword(mu_object, password);
}
- public void SetAA(bool AAon)
+ public void SetAA(AA_t AAlevel)
{
- if (AAon)
- lock (m_lock)
- {
- tc_mSetAA(mu_object, 8);
- }
- else
- lock (m_lock)
- {
- tc_mSetAA(mu_object, 0);
- }
+ lock (m_lock)
+ {
+ tc_mSetAA(mu_object, (int)AAlevel);
+ }
}
public int RenderPage(int page_num, Byte[] bmp_data, int bmp_width,
int bmp_height, double scale, bool flipy, bool use_dlist, bool
- get_text, out BlocksText blocks)
+ get_text, out BlocksText blocks, bool annotation,
+ out Annotate_t annot_type)
{
int code;
blocks = null;
String blockcolor = "#00FFFFFF";
String linecolor = "#402572AC";
/* Debug */
- //blockcolor = "#4000FF00";
+ //blockcolor = "#20FFFF00";
+ annot_type = Annotate_t.UNKNOWN;
if (use_dlist)
{
IntPtr dlist = IntPtr.Zero;
+ IntPtr annot_dlist = IntPtr.Zero;
IntPtr text = IntPtr.Zero;
int num_blocks = 0;
@@ -1310,15 +1390,25 @@ namespace gsview
dlist = tc_mCreateDisplayList(mu_object, page_num,
ref page_width, ref page_height);
}
+ if (annotation)
+ {
+ lock (m_lock)
+ {
+ annot_dlist = tc_mCreateDisplayListAnnot(mu_object, page_num);
+ if (annot_dlist == IntPtr.Zero)
+ annot_type = Annotate_t.NO_ANNOTATE;
+ else
+ annot_type = Annotate_t.HAS_ANNOTATE;
+ }
+ }
/* Rendering of display list can occur with other threads so unlock */
if (dlist == null)
{
return (int) status_t.E_FAILURE;
}
- code = tc_mRenderPageMT(mu_object, dlist, page_width, page_height,
- bmp_data, bmp_width, bmp_height,
- scale, flipy);
+ code = tc_mRenderPageMT(mu_object, dlist, annot_dlist, page_width,
+ page_height, bmp_data, bmp_width, bmp_height, scale, flipy);
}
else
{
@@ -1453,6 +1543,34 @@ namespace gsview
tc_mReleaseText(mu_object, textpage);
}
+ public void HTMLSaveAs(String infile, String outfile, String password,
+ bool has_password, bool linearize, int num_pages, System.Collections.IList pages)
+ {
+ if (num_pages > 0)
+ {
+ /* We need to do an allocation for our array of page numbers and
+ * perform pinning to avoid GC while in the c++ code */
+ GCHandle pagesPtrStable;
+ int[] page_list;
+ page_list = new int[pages.Count];
+
+ for (int kk = 0; kk < pages.Count; kk++)
+ {
+ SelectPage currpage = (SelectPage)pages[kk];
+ page_list[kk] = currpage.Page;
+ }
+ pagesPtrStable = GCHandle.Alloc(page_list, GCHandleType.Pinned);
+ tc_mExtractPages(infile, outfile, password, has_password, linearize,
+ num_pages, pagesPtrStable.AddrOfPinnedObject());
+ pagesPtrStable.Free();
+ }
+ else
+ {
+ tc_mExtractPages(infile, outfile, password, has_password, linearize,
+ num_pages, IntPtr.Zero);
+ }
+ }
+
public void PDFExtract(String infile, String outfile, String password,
bool has_password, bool linearize, int num_pages, System.Collections.IList pages)
{
diff --git a/platform/winrt/mupdfnet/mupdfnet.cpp b/platform/winrt/mupdfnet/mupdfnet.cpp
index c52b5b1e..6a59aec9 100644
--- a/platform/winrt/mupdfnet/mupdfnet.cpp
+++ b/platform/winrt/mupdfnet/mupdfnet.cpp
@@ -148,6 +148,24 @@ SYMBOL_DECLSPEC char* __stdcall mGetContentsItem(int k, int *len, int *page)
return retstr;
}
+SYMBOL_DECLSPEC char * __stdcall mGetText(void *ctx, int pagenum, int type)
+{
+ char* retstr = NULL;
+ muctx *mu_ctx = static_cast<muctx*>(ctx);
+ std::string text_cstr;
+ int len;
+
+ text_cstr = mu_ctx->GetText(pagenum, type);
+ if (text_cstr.size() > 0)
+ {
+ auto text = text_cstr.c_str();
+ len = strlen(text);
+ retstr = (char*)::CoTaskMemAlloc(len + 1);
+ strcpy(retstr, text);
+ }
+ return retstr;
+}
+
SYMBOL_DECLSPEC int __stdcall mTextSearchPage(void *ctx, int page_num, PCWSTR needle)
{
muctx *mu_ctx = static_cast<muctx*>(ctx);
@@ -252,6 +270,12 @@ SYMBOL_DECLSPEC void* __stdcall mCreateDisplayList(void *ctx, int page_num,
return (void*)mu_ctx->CreateDisplayList(page_num, page_width, page_height);
}
+SYMBOL_DECLSPEC void* __stdcall mCreateDisplayListAnnot(void *ctx, int page_num)
+{
+ muctx *mu_ctx = static_cast<muctx*>(ctx);
+ return (void*)mu_ctx->CreateAnnotationList(page_num);
+}
+
SYMBOL_DECLSPEC void* __stdcall mCreateDisplayListText(void *ctx, int page_num,
int *page_width, int *page_height, void **text_out, int *length)
{
@@ -264,12 +288,12 @@ SYMBOL_DECLSPEC void* __stdcall mCreateDisplayListText(void *ctx, int page_num,
}
SYMBOL_DECLSPEC int __stdcall mRenderPageMT(void *ctx, void *dlist,
- int page_width, int page_height, byte *bmp_data, int bmp_width,
+ void *annot_dlist, int page_width, int page_height, byte *bmp_data, int bmp_width,
int bmp_height, double scale, bool flipy)
{
muctx *mu_ctx = static_cast<muctx*>(ctx);
- return (int) mu_ctx->RenderPageMT(dlist, page_width, page_height,
+ return (int) mu_ctx->RenderPageMT(dlist, annot_dlist, page_width, page_height,
&(bmp_data[0]), bmp_width, bmp_height,
scale, flipy, false, { 0, 0 }, { 0, 0 });
}
diff --git a/platform/winrt/mupdfnet/mupdfnet.h b/platform/winrt/mupdfnet/mupdfnet.h
index 0f2915a2..99d23062 100644
--- a/platform/winrt/mupdfnet/mupdfnet.h
+++ b/platform/winrt/mupdfnet/mupdfnet.h
@@ -37,7 +37,7 @@ EXTERN_C SYMBOL_DECLSPEC bool __stdcall mGetTextSearchItem(int k, double *top_x,
*top_y, double *height, double *width);
EXTERN_C SYMBOL_DECLSPEC void __stdcall mReleaseTextSearch();
EXTERN_C SYMBOL_DECLSPEC char* __stdcall mGetVers();
-
+EXTERN_C SYMBOL_DECLSPEC char * __stdcall mGetText(void *ctx, int pagenum, int type);
EXTERN_C SYMBOL_DECLSPEC int __stdcall mGetLinksPage(void *ctx, int page_num);
EXTERN_C SYMBOL_DECLSPEC char* __stdcall mGetLinkItem(int k, double *top_x, double
@@ -48,9 +48,11 @@ EXTERN_C SYMBOL_DECLSPEC void* __stdcall mCreateDisplayList(void *ctx, int page_
int *page_width, int *page_height);
EXTERN_C SYMBOL_DECLSPEC void* __stdcall mCreateDisplayListText(void *ctx, int page_num,
int *page_width, int *page_height, void **textptr, int *length);
+EXTERN_C SYMBOL_DECLSPEC void* __stdcall mCreateDisplayListAnnot(void *ctx,
+ int page_num);
EXTERN_C SYMBOL_DECLSPEC int __stdcall mRenderPageMT(void *ctx, void *dlist,
- int page_width, int page_height, byte *bmp_data, int bmp_width,
+ void *annot_dlist, int page_width, int page_height, byte *bmp_data, int bmp_width,
int bmp_height, double scale, bool flipy);
EXTERN_C SYMBOL_DECLSPEC int __stdcall mGetTextBlock(void *text, int block_num,
diff --git a/platform/winrt/mupdfwinrt/muctx.cpp b/platform/winrt/mupdfwinrt/muctx.cpp
index 4153c1db..d5c34c80 100644
--- a/platform/winrt/mupdfwinrt/muctx.cpp
+++ b/platform/winrt/mupdfwinrt/muctx.cpp
@@ -149,9 +149,12 @@ void muctx::CleanUp(void)
fz_free_outline(mu_ctx, mu_outline);
fz_close_document(mu_doc);
page_cache->Empty(mu_ctx);
+ annot_cache->Empty(mu_ctx);
fz_free_context(mu_ctx);
delete page_cache;
+ delete annot_cache;
+ annot_cache = NULL;
page_cache = NULL;
this->mu_ctx = NULL;
this->mu_doc = NULL;
@@ -195,6 +198,7 @@ muctx::muctx(void)
mu_doc = NULL;
mu_outline = NULL;
page_cache = new Cache();
+ annot_cache = new Cache();
}
/* Destructor */
@@ -203,6 +207,7 @@ muctx::~muctx(void)
fz_free_outline(mu_ctx, mu_outline);
fz_close_document(mu_doc);
page_cache->Empty(mu_ctx);
+ annot_cache->Empty(mu_ctx);
fz_free_context(mu_ctx);
mu_ctx = NULL;
@@ -210,6 +215,8 @@ muctx::~muctx(void)
mu_outline = NULL;
delete page_cache;
page_cache = NULL;
+ delete annot_cache;
+ annot_cache = NULL;
}
/* Return the documents page count */
@@ -436,6 +443,51 @@ unsigned int muctx::GetLinks(int page_num, sh_vector_link links_vec)
return num_links;
}
+fz_display_list * muctx::CreateAnnotationList(int page_num)
+{
+ fz_device *dev = NULL;
+ fz_page *page = NULL;
+ int width, height;
+
+ /* First see if we have this one in the cache */
+ fz_display_list *dlist = annot_cache->Use(page_num, &width, &height, mu_ctx);
+ if (dlist != NULL)
+ return dlist;
+
+ /* Apparently not, lets go ahead and create and add to cache */
+ fz_var(dev);
+ fz_var(page);
+ fz_var(dlist);
+
+ fz_try(mu_ctx)
+ {
+ fz_annot *annot;
+ page = fz_load_page(mu_doc, page_num);
+ annot = fz_first_annot(mu_doc, page);
+ if (annot != NULL)
+ {
+ /* Create display list */
+ dlist = fz_new_display_list(mu_ctx);
+ dev = fz_new_list_device(mu_ctx, dlist);
+
+ for (annot = fz_first_annot(mu_doc, page); annot; annot = fz_next_annot(mu_doc, annot))
+ fz_run_annot(mu_doc, page, annot, dev, &fz_identity, NULL);
+ annot_cache->Add(page_num, 0, 0, dlist, mu_ctx);
+ }
+ }
+ fz_always(mu_ctx)
+ {
+ fz_free_device(dev);
+ fz_free_page(mu_doc, page);
+ }
+ fz_catch(mu_ctx)
+ {
+ fz_drop_display_list(mu_ctx, dlist);
+ return NULL;
+ }
+ return dlist;
+}
+
fz_display_list * muctx::CreateDisplayList(int page_num, int *width, int *height)
{
fz_device *dev = NULL;
@@ -548,7 +600,7 @@ fz_display_list * muctx::CreateDisplayListText(int page_num, int *width, int *he
}
/* Render display list bmp_data buffer. No lock needed for this operation */
-status_t muctx::RenderPageMT(void *dlist, int page_width, int page_height,
+status_t muctx::RenderPageMT(void *dlist, void *a_dlist, int page_width, int page_height,
unsigned char *bmp_data, int bmp_width, int bmp_height,
float scale, bool flipy, bool tile, point_t top_left,
point_t bottom_right)
@@ -558,12 +610,14 @@ status_t muctx::RenderPageMT(void *dlist, int page_width, int page_height,
fz_matrix ctm, *pctm = &ctm;
fz_context *ctx_clone = NULL;
fz_display_list *display_list = (fz_display_list*) dlist;
+ fz_display_list *annot_displaylist = (fz_display_list*) a_dlist;
ctx_clone = fz_clone_context(mu_ctx);
fz_var(dev);
fz_var(pix);
fz_var(display_list);
+ fz_var(annot_displaylist);
fz_try(ctx_clone)
{
@@ -586,12 +640,16 @@ status_t muctx::RenderPageMT(void *dlist, int page_width, int page_height,
fz_clear_pixmap_with_value(ctx_clone, pix, 255);
dev = fz_new_draw_device(ctx_clone, pix);
fz_run_display_list(display_list, dev, pctm, NULL, NULL);
+ if (annot_displaylist != NULL)
+ fz_run_display_list(annot_displaylist, dev, pctm, NULL, NULL);
+
}
fz_always(ctx_clone)
{
fz_free_device(dev);
fz_drop_pixmap(ctx_clone, pix);
fz_drop_display_list(ctx_clone, display_list);
+ fz_drop_display_list(ctx_clone, annot_displaylist);
}
fz_catch(ctx_clone)
{
@@ -631,7 +689,11 @@ status_t muctx::RenderPage(int page_num, unsigned char *bmp_data, int bmp_width,
bmp_height, bmp_data);
fz_clear_pixmap_with_value(mu_ctx, pix, 255);
dev = fz_new_draw_device(mu_ctx, pix);
- fz_run_page(mu_doc, page, dev, pctm, NULL);
+ fz_run_page(mu_doc, page, dev, pctm, NULL);
+
+ fz_annot *annot;
+ for (annot = fz_first_annot(mu_doc, page); annot; annot = fz_next_annot(mu_doc, annot))
+ fz_run_annot(mu_doc, page, annot, dev, &fz_identity, NULL);
}
fz_always(mu_ctx)
{
@@ -656,7 +718,7 @@ bool muctx::ApplyPassword(char* password)
return fz_authenticate_password(mu_doc, password) != 0;
}
-std::string muctx::GetHTML(int page_num)
+std::string muctx::GetText(int page_num, int type)
{
fz_output *out = NULL;
fz_device *dev = NULL;
@@ -664,7 +726,7 @@ std::string muctx::GetHTML(int page_num)
fz_text_sheet *sheet = NULL;
fz_text_page *text = NULL;
fz_buffer *buf = NULL;
- std::string html;
+ std::string output;
fz_var(dev);
fz_var(page);
@@ -683,8 +745,19 @@ std::string muctx::GetHTML(int page_num)
fz_analyze_text(mu_ctx, sheet, text);
buf = fz_new_buffer(mu_ctx, 256);
out = fz_new_output_with_buffer(mu_ctx, buf);
- fz_print_text_page_html(mu_ctx, out, text);
- html = std::string(((char*) buf->data));
+ if (type == HTML)
+ {
+ fz_print_text_page_html(mu_ctx, out, text);
+ }
+ else if (type == XML)
+ {
+ fz_print_text_page_xml(mu_ctx, out, text);
+ }
+ else
+ {
+ fz_print_text_page(mu_ctx, out, text);
+ }
+ output = std::string(((char*)buf->data));
}
fz_always(mu_ctx)
{
@@ -698,7 +771,7 @@ std::string muctx::GetHTML(int page_num)
{
return nullptr;
}
- return html;
+ return output;
}
void muctx::ReleaseText(void *text)
@@ -719,6 +792,7 @@ status_t muctx::SavePage(char *filename, int page_num, int resolution, int type,
fz_device *dev = NULL;
int width, height;
fz_display_list *dlist = NULL;
+ fz_display_list *annot_dlist = NULL;
fz_page *page = NULL;
bool valid = true;
fz_pixmap *pix = NULL;
@@ -727,6 +801,7 @@ status_t muctx::SavePage(char *filename, int page_num, int resolution, int type,
fz_var(dev);
fz_var(page);
fz_var(dlist);
+ fz_var(annot_dlist);
fz_var(pix);
fz_try(mu_ctx)
@@ -741,6 +816,7 @@ status_t muctx::SavePage(char *filename, int page_num, int resolution, int type,
/* First see if we have this one in the cache */
dlist = page_cache->Use(page_num, &width, &height, mu_ctx);
+ annot_dlist = annot_cache->Use(page_num, &width, &height, mu_ctx);
if (type == SVG_OUT)
{
@@ -754,6 +830,14 @@ status_t muctx::SavePage(char *filename, int page_num, int resolution, int type,
fz_run_display_list(dlist, dev, &ctm, &tbounds, NULL);
else
fz_run_page(mu_doc, page, dev, &ctm, NULL);
+ if (annot_dlist != NULL)
+ fz_run_display_list(annot_dlist, dev, &ctm, &tbounds, NULL);
+ else
+ {
+ fz_annot *annot;
+ for (annot = fz_first_annot(mu_doc, page); annot; annot = fz_next_annot(mu_doc, annot))
+ fz_run_annot(mu_doc, page, annot, dev, &fz_identity, NULL);
+ }
}
else
{
@@ -765,6 +849,14 @@ status_t muctx::SavePage(char *filename, int page_num, int resolution, int type,
fz_run_display_list(dlist, dev, &ctm, &tbounds, NULL);
else
fz_run_page(mu_doc, page, dev, &ctm, NULL);
+ if (annot_dlist != NULL)
+ fz_run_display_list(annot_dlist, dev, &ctm, &tbounds, NULL);
+ else
+ {
+ fz_annot *annot;
+ for (annot = fz_first_annot(mu_doc, page); annot; annot = fz_next_annot(mu_doc, annot))
+ fz_run_annot(mu_doc, page, annot, dev, &fz_identity, NULL);
+ }
switch (type)
{
case PNM_OUT:
diff --git a/platform/winrt/mupdfwinrt/muctx.h b/platform/winrt/mupdfwinrt/muctx.h
index 2e95fc61..16c44cd1 100644
--- a/platform/winrt/mupdfwinrt/muctx.h
+++ b/platform/winrt/mupdfwinrt/muctx.h
@@ -15,6 +15,7 @@ extern "C" {
#define MAX_SEARCH 500
enum { SVG_OUT, PNM_OUT, PCL_OUT, PWG_OUT };
+enum { HTML = 0, XML, TEXT };
typedef struct point_s
{
@@ -82,6 +83,7 @@ private:
void FlattenOutline(fz_outline *outline, int level,
sh_vector_content contents_vec);
Cache *page_cache;
+ Cache *annot_cache;
public:
muctx(void);
@@ -91,20 +93,21 @@ public:
status_t InitializeContext();
status_t RenderPage(int page_num, unsigned char *bmp_data, int bmp_width,
int bmp_height, float scale, bool flipy);
- status_t RenderPageMT(void *dlist, int page_width, int page_height,
+ status_t RenderPageMT(void *dlist, void *a_dlist, int page_width, int page_height,
unsigned char *bmp_data, int bmp_width, int bmp_height,
float scale, bool flipy, bool tile, point_t top_left,
point_t bottom_right);
fz_display_list* CreateDisplayList(int page_num, int *width, int *height);
- fz_display_list * muctx::CreateDisplayListText(int page_num, int *width,
- int *height, fz_text_page **text, int *length);
+ fz_display_list * CreateDisplayListText(int page_num, int *width,
+ int *height, fz_text_page **text, int *length);
+ fz_display_list * CreateAnnotationList(int page_num);
int MeasurePage(int page_num, point_t *size);
point_t MeasurePage(fz_page *page);
unsigned int GetLinks(int page_num, sh_vector_link links_vec);
void SetAA(int level);
int GetTextSearch(int page_num, char* needle, sh_vector_text texts_vec);
int GetContents(sh_vector_content contents_vec);
- std::string GetHTML(int page_num);
+ std::string GetText(int page_num, int type);
void ReleaseText(void *text);
bool RequiresPassword(void);
bool ApplyPassword(char* password);