logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

New Topic Post Reply
Options
Go to last post Go to first unread
gffranca  
#1 Posted : Wednesday, August 25, 2021 6:17:27 PM(UTC)
Quote
gffranca

Rank: Member

Groups: Registered
Joined: 11/1/2019(UTC)
Posts: 17
Brazil
Location: Rio de Janeiro

Thanks: 2 times
Is it possible to use the selection tool in area (column) mode?

This image illustrates how the tool works in Acrobat. While using Alt key, the selection is based on it's starting point.
This feature, sometimes, is included in code editors too.
I believe it works similar to Text.GetBoundedText(), but in this case it is for selection in the viewer.

Any ideas?

marquee.PNG

Paul Rayman  
#2 Posted : Wednesday, August 25, 2021 8:35:19 PM(UTC)
Quote
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,075

Thanks: 6 times
Was thanked: 124 time(s) in 121 post(s)
Here is an example of such functionality.

Code:

public class MyPdfViewer : PdfViewer
{
	PointF _startPt = new PointF(0, 0);
	PointF _curPt = new PointF(0, 0);
	int _shapshotPage = -1;
	bool _isSelectionStarted = false;

	protected override void OnMouseDown(MouseEventArgs e)
	{
		base.OnMouseDown(e);

		_shapshotPage = PointInPage(e.Location);
		if (_shapshotPage >= 0)
		{
			HighlightedTextInfo.Clear();
			_startPt = ClientToPage(_shapshotPage, e.Location);
			_curPt = _startPt;
			_isSelectionStarted = true;
		}

	}

	protected override void OnMouseUp(MouseEventArgs e)
	{
		base.OnMouseUp(e);
		_isSelectionStarted = false;

		if (_shapshotPage >= 0)
		{
			FS_POINTF leftTop, rightBottom;
			NormalizeSnapshotPoints(out leftTop, out rightBottom);

			var page = Document.Pages[_shapshotPage];
			var len = page.Text.CountChars;
			int lineLen = 0;
			for(int i=0; i< len; i++)
            {
				var chBox = page.Text.GetCharBox(i);
				if(IntersectsWith(chBox, new FS_RECTF(leftTop.X, leftTop.Y, rightBottom.X, rightBottom.Y)))
					lineLen++;
				else if(lineLen>0)
				{
					if (!HighlightedTextInfo.ContainsKey(_shapshotPage))
						HighlightedTextInfo.Add(_shapshotPage, new List<HighlightInfo>());
					var hInf = HighlightedTextInfo[_shapshotPage];
					hInf.Add(new HighlightInfo() { CharIndex = i - lineLen, CharsCount = lineLen, Color = Color.Red });
					lineLen = 0;
					Invalidate();
                }
            }
			_shapshotPage = -1;
		}
	}

	protected override void OnMouseMove(MouseEventArgs e)
	{
		base.OnMouseMove(e);
		if (_isSelectionStarted)
		{
			DeselectText();
			int pageIdx = PointInPage(e.Location);
			if (pageIdx != _shapshotPage)
				return;

			_curPt = ClientToPage(_shapshotPage, e.Location);
			Invalidate();
		}
	}

	protected override void OnPaint(PaintEventArgs e)
	{
		base.OnPaint(e);
		if (_shapshotPage >= 0)
		{
			var pt1 = PageToClient(_shapshotPage, _startPt);
			var pt2 = PageToClient(_shapshotPage, _curPt);
			int left = Math.Min(pt1.X, pt2.X);
			int top = Math.Min(pt1.Y, pt2.Y);
			int right = Math.Max(pt1.X, pt2.X);
			int bottom = Math.Max(pt1.Y, pt2.Y);
			e.Graphics.DrawRectangle(Pens.Red, left, top, right - left, bottom - top);
		}
	}

	private void NormalizeSnapshotPoints(out FS_POINTF leftTop, out FS_POINTF rightBotton)
	{
		leftTop = new FS_POINTF(
			Math.Min(_startPt.X, _curPt.X),
			Math.Max(_startPt.Y, _curPt.Y));
		rightBotton = new FS_POINTF(
			Math.Max(_startPt.X, _curPt.X),
			Math.Min(_startPt.Y, _curPt.Y));
	}

	public bool IntersectsWith(FS_RECTF rect1, FS_RECTF rect2)
	{
		return rect1.left < rect2.right && rect1.right > rect2.left && rect1.top > rect2.bottom && rect1.bottom < rect2.top;
	}
}
Quick Reply Show Quick Reply
Users browsing this topic
New Topic Post Reply
Forum Jump  
You can post new topics in this forum.
You can reply to topics in this forum.
You can delete your posts in this forum.
You can edit your posts in this forum.
You cannot create polls in this forum.
You can vote in polls in this forum.