/* ----------------------------------------------------------------- */ /// /// FitToWidth /// /// <summary> /// ウィンドウ(描画領域)の幅に合わせて拡大/縮小を行う. /// </summary> /// /* ----------------------------------------------------------------- */ public static double FitToWidth(Canvas canvas) { if (canvas == null) { return(0.0); } var engine = canvas.Tag as CanvasEngine; if (engine == null) { return(0.0); } var core = engine.Core; if (core == null) { return(0.0); } core.FitToWidth(canvas.Parent.Handle); core.Zoom = core.Zoom - 1; // 暫定 #if CUBE_ASYNC CanvasPolicy.AsyncRender(canvas, true); #else CanvasPolicy.Render(canvas, true); #endif return(core.Zoom); }
/* ----------------------------------------------------------------- */ /// /// Zoom /// /// <summary> /// 指定した倍率で現在のページを再描画する. /// </summary> /// /* ----------------------------------------------------------------- */ public static double Zoom(Canvas canvas, double percent) { if (canvas == null) { return(0.0); } var engine = canvas.Tag as CanvasEngine; if (engine == null) { return(0.0); } var core = engine.Core; if (core == null) { return(0.0); } var prev = canvas.Size; if (percent < core.Zoom || core.Zoom < 400) { core.Zoom = Math.Min(percent, 400); #if CUBE_ASYNC CanvasPolicy.AsyncRender(canvas, true); #else CanvasPolicy.Render(canvas, true); #endif } return(core.Zoom); }
/* ----------------------------------------------------------------- */ /// /// ZoomOut /// /// <summary> /// 現在のページを縮小して再描画する.縮小率はライブラリ依存. /// </summary> /// /* ----------------------------------------------------------------- */ public static double ZoomOut(Canvas canvas) { if (canvas == null) { return(0.0); } var engine = canvas.Tag as CanvasEngine; if (engine == null) { return(0.0); } var core = engine.Core; if (core == null) { return(0.0); } var prev = canvas.Size; core.ZoomOut(); #if CUBE_ASYNC CanvasPolicy.AsyncRender(canvas, true); #else CanvasPolicy.Render(canvas, true); #endif return(core.Zoom); }
/* ----------------------------------------------------------------- */ /// /// Render (private) /// /// <summary> /// MEMO: ロックは暫定処理.Microsoft によると public にアクセス /// 可能なオブジェクトを用いた lock は想定していないらしい. /// http://msdn.microsoft.com/ja-jp/library/c5kehkcz%28VS.80%29.aspx /// </summary> /// /* ----------------------------------------------------------------- */ private static bool Render(Canvas canvas, bool adjust) { if (canvas == null) { return(false); } var engine = canvas.Tag as CanvasEngine; if (engine == null) { return(false); } var core = engine.Core; if (core == null) { return(false); } lock (core) { var status = core.RenderPage(IntPtr.Zero, false, false); if (status && adjust) { CanvasPolicy.Adjust(canvas); } canvas.Invalidate(); return(status); } }
/* ----------------------------------------------------------------- */ /// /// LastPage /// /// <summary> /// 最後のページを描画する. /// </summary> /// /* ----------------------------------------------------------------- */ public static int LastPage(Canvas canvas) { if (canvas == null) { return(0); } var engine = canvas.Tag as CanvasEngine; if (engine == null) { return(0); } var core = engine.Core; if (core == null) { return(0); } core.CurrentPage = core.PageCount; #if CUBE_ASYNC CanvasPolicy.AsyncRender(canvas, false); var control = (ScrollableControl)canvas.Parent; control.AutoScrollPosition = new Point(0, 0); #else if (CanvasPolicy.Render(canvas, false)) { engine.UpdateURL(); var control = (ScrollableControl)canvas.Parent; control.AutoScrollPosition = new Point(0, 0); } #endif return(core.CurrentPage); }
public static bool Search(Canvas canvas, SearchArgs args) { if (canvas == null) { return(false); } var engine = canvas.Tag as CanvasEngine; if (engine == null) { return(false); } var core = engine.Core; if (core == null) { return(false); } core.SearchCaseSensitive = !args.IgnoreCase; var order = args.WholeDocument ? PDFLibNet.PDFSearchOrder.PDFSearchFromdBegin : PDFLibNet.PDFSearchOrder.PDFSearchFromCurrent; int result = 0; if (args.FromBegin) { PreviousSearchResult_ = null; result = core.FindFirst(args.Text, order, false, args.WholeWord); } else if (args.FindNext) { result = core.FindNext(args.Text); } else { result = core.FindPrevious(args.Text); } //else result = core.FindText(args.Text, core.CurrentPage, order, !args.IgnoreCase, !args.FindNext, true, args.WholeWord); var prev = core.CurrentPage; if (result > 0 && (PreviousSearchResult_ == null || !Equals(PreviousSearchResult_, core.SearchResults[0]))) { core.CurrentPage = core.SearchResults[0].Page; PreviousSearchResult_ = core.SearchResults[0]; } CanvasPolicy.Render(canvas, false); if (core.CurrentPage != prev) { engine.UpdateURL(); } return(result > 0); }
/* ----------------------------------------------------------------- */ /// /// MouseMoveHandler /// /// <summary> /// マウス押下中は手のひらツールとして機能する. /// それ以外の場合は,URL に重なった時にツールチップを表示する. /// </summary> /// /* ----------------------------------------------------------------- */ private static void MouseMoveHandler(object sender, MouseEventArgs e) { var canvas = sender as Canvas; if (canvas == null) { return; } if (is_mouse_down_ && e.Button == MouseButtons.Left) { var control = (ScrollableControl)canvas.Parent; var current = canvas.PointToScreen(e.Location); int x = current.X - origin_.X; int y = current.Y - origin_.Y; control.AutoScrollPosition = new Point(-x, -y); var cursor = CanvasPolicy.GetHandCursor(); if (cursor != null) { canvas.Cursor = cursor; } } else { var engine = canvas.Tag as CanvasEngine; if (engine == null) { return; } var core = engine.Core; if (core == null) { return; } lock (core) { var pos = new Point((int)(e.Location.X * 72.0 / core.RenderDPI), (int)(e.Location.Y * 72.0 / core.RenderDPI)); var result = engine.GetURL(pos); if (result != null) { if (canvas.Cursor == Cursors.Default) { canvas.Cursor = Cursors.Hand; tooltip_.Show(result, canvas, 3000); } } else { canvas.Cursor = Cursors.Default; tooltip_.Hide(canvas); } } } }
/* ----------------------------------------------------------------- */ /// Adjust_WorkCompletedHandler /* ----------------------------------------------------------------- */ private static void Adjust_WorkCompletedHandler(object sender, RunWorkerCompletedEventArgs e) { var canvas = e.Result as Canvas; if (canvas == null) { return; } canvas.Cursor = Cursors.Default; CanvasPolicy.Adjust(canvas); canvas.Invalidate(); }
/* ----------------------------------------------------------------- */ /// Destroy /* ----------------------------------------------------------------- */ public static void Destroy(Canvas canvas) { if (canvas == null) { return; } var parent = (ScrollableControl)canvas.Parent; foreach (var child in parent.Controls.Find("Canvas", false)) { CanvasPolicy.Close((Canvas)child); parent.Controls.Remove(child); child.Dispose(); } }
/* ----------------------------------------------------------------- */ /// /// Open /// /// <summary> /// 指定された PDF ファイルを開いて,最初のページを描画する. /// MEMO: パスの記憶場所を検討中.現在は,Parent.Tag を利用 /// している. /// </summary> /// /* ----------------------------------------------------------------- */ public static void Open(Canvas canvas, string path, string password, FitCondition which) { if (canvas == null) { return; } var engine = canvas.Tag as CanvasEngine; if (engine != null) { CanvasPolicy.Close(canvas); } var core = new PDF(); engine = new CanvasEngine(core); canvas.Tag = engine; core.UseMuPDF = true; core.UserPassword = password; core.OwnerPassword = password; if (core.LoadPDF(path)) { core.CurrentPage = 1; if (which == FitCondition.Height) { core.FitToHeight(canvas.Parent.Handle); core.Zoom = core.Zoom - 1; // 暫定 } else if (which == FitCondition.Width) { core.FitToWidth(canvas.Parent.Handle); core.Zoom = core.Zoom - 1; // 暫定 } else { core.Zoom = 100; } canvas.Parent.Text = System.IO.Path.GetFileNameWithoutExtension(path); canvas.Parent.Tag = path; CanvasPolicy.AsyncRender(canvas, true); } }
/* ----------------------------------------------------------------- */ /// MouseClickHandler /* ----------------------------------------------------------------- */ private static void MouseClickHandler(object sender, MouseEventArgs e) { var canvas = sender as Canvas; if (canvas == null) { return; } if (canvas.Cursor == Cursors.Hand) { var engine = canvas.Tag as CanvasEngine; if (engine == null) { return; } var core = engine.Core; if (core == null) { return; } lock (core) { var pos = new Point((int)(e.Location.X * 72.0 / core.RenderDPI), (int)(e.Location.Y * 72.0 / core.RenderDPI)); var addr = engine.GetURL(pos); if (addr != null) { System.Diagnostics.Process.Start(addr); } } canvas.Cursor = Cursors.Default; } else { var cursor = CanvasPolicy.GetHandCursor(); if (cursor != null) { canvas.Cursor = cursor; } } }
/* ----------------------------------------------------------------- */ /// /// FitToPage /// /// <summary> /// ウィンドウ(描画領域)に合わせて拡大/縮小を行う. /// </summary> /// /* ----------------------------------------------------------------- */ public static double FitToPage(Canvas canvas) { if (canvas == null) { return(0.0); } var engine = canvas.Tag as CanvasEngine; if (engine == null) { return(0.0); } var core = engine.Core; if (core == null) { return(0.0); } // 横長ならばFitToWidthを、縦長ならばFitToHeightを呼ぶ if (GetOrientation(canvas) == Orientation.portratit) { core.FitToHeight(canvas.Parent.Handle); } else { core.FitToWidth(canvas.Parent.Handle); } core.Zoom = core.Zoom - 1; // 暫定 #if CUBE_ASYNC CanvasPolicy.AsyncRender(canvas, true); #else CanvasPolicy.Render(canvas, true); #endif return(core.Zoom); }
public static double ZoomIn(Canvas canvas) { if (canvas == null) { return(0.0); } var engine = canvas.Tag as CanvasEngine; if (engine == null) { return(0.0); } var core = engine.Core; if (core == null) { return(0.0); } var prev = canvas.Size; if (core.Zoom < 400) { core.ZoomIN(); if (core.Zoom > 400) { core.Zoom = 400; } #if CUBE_ASYNC CanvasPolicy.AsyncRender(canvas, true); #else CanvasPolicyA.Render(canvas, true); #endif } return(core.Zoom); }
/* ----------------------------------------------------------------- */ /// Open /* ----------------------------------------------------------------- */ public static void Open(Canvas canvas, string path) { CanvasPolicy.Open(canvas, path, "", FitCondition.None); }
/* ----------------------------------------------------------------- */ /// Open /* ----------------------------------------------------------------- */ public static void Open(Canvas canvas, string path, FitCondition which) { CanvasPolicy.Open(canvas, path, "", which); }