forked from bezzad/PdfiumViewer
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement bezzad issue #2: Search/Scroll not working
Limitations: - Highlighting the current match not always work - The order of matches is random within a page
- Loading branch information
1 parent
98e1f5a
commit 5080cbe
Showing
9 changed files
with
251 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,56 @@ | ||
using System; | ||
using System.Drawing; | ||
using System.Windows; | ||
using System.Windows.Media; | ||
using PdfiumViewer.Drawing; | ||
using Color = System.Windows.Media.Color; | ||
using Pen = System.Windows.Media.Pen; | ||
|
||
namespace PdfiumViewer.Core | ||
{ | ||
public class PdfMarker : IPdfMarker | ||
{ | ||
public int Page { get; } | ||
public RectangleF Bounds { get; } | ||
public Color Color { get; } | ||
public Color BorderColor { get; } | ||
public float BorderWidth { get; } | ||
|
||
public PdfMarker(int page, RectangleF bounds, Color color) | ||
: this(page, bounds, color, Colors.Transparent, 0) | ||
{ | ||
} | ||
|
||
public PdfMarker(int page, RectangleF bounds, Color color, Color borderColor, float borderWidth) | ||
{ | ||
Page = page; | ||
Bounds = bounds; | ||
Color = color; | ||
BorderColor = borderColor; | ||
BorderWidth = borderWidth; | ||
} | ||
|
||
public void Draw(PdfRenderer renderer, DrawingContext graphics) | ||
{ | ||
if (renderer == null) | ||
throw new ArgumentNullException(nameof(renderer)); | ||
if (graphics == null) | ||
throw new ArgumentNullException(nameof(graphics)); | ||
|
||
Rect bounds = renderer.BoundsFromPdf(new PdfRectangle(Page, Bounds)); | ||
var brush = new SolidColorBrush(Color) { Opacity = .8 }; | ||
var pen = new Pen(new SolidColorBrush(BorderColor) { Opacity = .8 }, BorderWidth); | ||
graphics.DrawRectangle(brush, null, bounds); | ||
|
||
if (BorderWidth > 0) | ||
{ | ||
graphics.DrawRectangle(null, pen, bounds); | ||
} | ||
} | ||
} | ||
} | ||
using System; | ||
using System.Diagnostics; | ||
using System.Drawing; | ||
using System.Windows; | ||
using System.Windows.Media; | ||
using PdfiumViewer.Drawing; | ||
using Color = System.Windows.Media.Color; | ||
using Pen = System.Windows.Media.Pen; | ||
|
||
namespace PdfiumViewer.Core | ||
{ | ||
public class PdfMarker : IPdfMarker | ||
{ | ||
public int Page { get; } | ||
public RectangleF Bounds { get; } | ||
public Color Color { get; } | ||
public Color BorderColor { get; } | ||
public float BorderWidth { get; } | ||
|
||
public PdfMarker(int page, RectangleF bounds, Color color) | ||
: this(page, bounds, color, Colors.Transparent, 0) | ||
{ | ||
} | ||
|
||
public PdfMarker(int page, RectangleF bounds, Color color, Color borderColor, float borderWidth) | ||
{ | ||
Page = page; | ||
Bounds = bounds; | ||
Color = color; | ||
BorderColor = borderColor; | ||
BorderWidth = borderWidth; | ||
} | ||
|
||
public void Draw(PdfRenderer renderer, DrawingContext graphics) | ||
{ | ||
if (renderer == null) | ||
throw new ArgumentNullException(nameof(renderer)); | ||
if (graphics == null) | ||
throw new ArgumentNullException(nameof(graphics)); | ||
|
||
Rect? bounds = renderer.BoundsFromPdf(new PdfRectangle(Page, Bounds)); | ||
if (bounds == null) return; | ||
|
||
Debug.WriteLine("DrawMarker[" + Page + "]: " + Color + ", bounds=" + bounds); | ||
|
||
var brush = new SolidColorBrush(Color) { Opacity = .8 }; | ||
graphics.DrawRectangle(brush, null, bounds.Value); | ||
|
||
if (BorderWidth > 0) | ||
{ | ||
var pen = new Pen(new SolidColorBrush(BorderColor) { Opacity = .8 }, BorderWidth); | ||
graphics.DrawRectangle(null, pen, bounds.Value); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System.Windows.Controls; | ||
using System.Windows.Media; | ||
|
||
namespace PdfiumViewer.Drawing | ||
{ | ||
public class PdfImage : Image | ||
{ | ||
public PdfRenderer Renderer { get; set; } | ||
public int PageNo {get; set; } | ||
|
||
protected override void OnRender(DrawingContext drawingContext) | ||
{ | ||
base.OnRender(drawingContext); | ||
if (Source != null) | ||
{ | ||
Renderer.EnsureMarkers(); | ||
Renderer.DrawMarkers(drawingContext, PageNo); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.