Rank: Newbie
Groups: Registered
Joined: 7/24/2018(UTC) Posts: 3 
|
I'm having an issue with highlighting text & scaling. Running my viewer in 100% is fine, but if I start it with Windows set to any other scale (125/150/175/200%) it seems that clientToPage is offset.
For example in 100% GetSelectedRects result = {702,85,154,17}
After performing clientToPage: upperLeft = {215.818634033203,782.601928710938} lowerRight = {337.562530517578,769.163330078125}
This is correct.
After re-starting my app in 125%: GetSelectedRects result = {623,115,209,22} Correct, as this is in client coordinates. Can see the Height & Width have grown by ~25% as expected
After performing clientToPage: upperLeft = {306.372741699219,765.552795410156} lowerRight = {458.467468261719,749.558288574219}
This is incorrect. I expected the same page coordinates (I'm highlighting the exact same text) but you can see the values are offset from the correct position. The larger the scaling the larger the offset.
What makes this even stranger is if I change the scaling without closing my app, clientToPage actually works correctly! The transform is perfect and there's no offset. It's only an issue if I start the viewer in anything but 100%.
|
|
|
|
|
|
Rank: Administration
Groups: Administrators
Joined: 1/5/2016(UTC) Posts: 1,138
Thanks: 10 times Was thanked: 133 time(s) in 130 post(s)
|
Fixed https://forum.patagames....released-on-Feb-27--2021Actually the GetClientRect method works fine. But... the point is that this method returns rectangles in pixels, while WPF operates with points. And the ClientToPage and PageToClient methods accept coordinates in WPF points as well. So, if your app is WPF app, then you must recalculate the coordinates from pixels to WPF points, as shown below. Code:
public static double PixelsToUnits(int pixels)
{
var flags = BindingFlags.NonPublic | BindingFlags.Static;
var dpiProperty = typeof(SystemParameters).GetProperty("Dpi", flags);
double Dpi = (double)(int)dpiProperty.GetValue(null, null);
double PixelSize = Dpi / 96;
return (double)pixels / PixelSize;
}
private void btnSetCurrentPage_Click(object sender, RoutedEventArgs e)
{
var rectInPixels = pdfViewer1.GetSelectedRects(0)[0];
var rectInWpfUnits = new Rect(
PixelsToUnits(rectInPixels.X),
PixelsToUnits(rectInPixels.Y),
PixelsToUnits(rectInPixels.Width),
PixelsToUnits(rectInPixels.Height));
var pagePt1 = pdfViewer1.ClientToPage(0, new Point(rectInWpfUnits.X, rectInWpfUnits.Y));
var pagePt2 = pdfViewer1.ClientToPage(0, new Point(rectInWpfUnits.X + rectInWpfUnits.Width, rectInWpfUnits.Y + rectInWpfUnits.Height));
var pageRect = new FS_RECTF(
Math.Min(pagePt1.X, pagePt2.X), //left
Math.Max(pagePt1.Y, pagePt2.Y), //top
Math.Max(pagePt1.X, pagePt2.X), //right
Math.Min(pagePt1.Y, pagePt2.Y) //bottom
);
var annot = new PdfSquareAnnotation(pdfViewer1.Document.Pages[0], pageRect, FS_COLOR.Green, FS_COLOR.Blue);
annot.GenerateAppearance(Patagames.Pdf.Enums.AppearanceStreamModes.Normal);
if (pdfViewer1.Document.Pages[0].Annots == null)
pdfViewer1.Document.Pages[0].CreateAnnotations();
pdfViewer1.Document.Pages[0].Annots.Add(annot);
pdfViewer1.Document.Pages[0].Dispose();
pdfViewer1.InvalidateVisual();
}
Edited by user Saturday, March 6, 2021 6:05:57 PM(UTC)
| Reason: Not specified
|
|
|
|
|
|
Rank: Newbie
Groups: Registered
Joined: 7/24/2018(UTC) Posts: 3 
|
Thank you :). Confirmed fixed on my end.
|
|
|
|
|
|
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.
Important Information:
The Patagames Software Support Forum uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close