private void HandleMouseDownForTextSelection(MouseEventArgs e) { if (e.Button != MouseButtons.Left) { return; } var pdfLocation = PointToPdf(e.Location); if (!pdfLocation.IsValid) { return; } var characterIndex = Document.GetCharacterIndexAtPosition(pdfLocation, 4f, 4f); if (characterIndex >= 0) { _textSelectionState = new TextSelectionState() { StartPage = pdfLocation.Page, StartIndex = characterIndex, EndPage = -1, EndIndex = -1 }; _isSelectingText = true; Capture = true; } else { _isSelectingText = false; Capture = false; _textSelectionState = null; } }
public void Start(Point position, int pos, T content) { selectionStart = selectionEnd = pos; State = TextSelectionState.Clicked; selectionStartingPoint = position; Content = content; }
public void Set (int pos, Point position) { selectionEnd = pos; if (State == TextSelectionState.Clicked && Away (selectionStartingPoint, position, SelectionDistancePixel)) { State = TextSelectionState.Selecting; } }
public void SelectAll() { _textSelectionState = new TextSelectionState() { StartPage = 0, StartIndex = 0, EndPage = Document.PageCount - 1, EndIndex = Document.CountCharacters(Document.PageCount - 1) - 1 }; Invalidate(); }
public void SelectCurrentPage() { _textSelectionState = new TextSelectionState() { StartPage = Page, StartIndex = 0, EndPage = Page, EndIndex = Document.CountCharacters(Page) - 1 }; Invalidate(); }
private void DrawTextSelection(Graphics graphics, int page, TextSelectionState state) { if (state.EndPage < 0 || state.EndIndex < 0) { return; } if (page >= state.StartPage && page <= state.EndPage) { int start = 0, end = 0; if (page == state.StartPage) { start = state.StartIndex; } if (page == state.EndPage) { end = (state.EndIndex + 1); } else { end = Document.CountCharacters(page); } Region region = null; foreach (var rectangle in Document.GetTextRectangles(page, start, end - start)) { if (region == null) { region = new Region(BoundsFromPdf(rectangle)); } else { region.Union(BoundsFromPdf(rectangle)); } } if (region != null) { graphics.FillRegion(_textSelectionBrush, region); } } }
public void ReloadDocument() { _maxWidth = 0; _maxHeight = 0; _textSelectionState = null; foreach (var size in Document.PageSizes) { var translated = TranslateSize(size); _maxWidth = Math.Max((int)translated.Width, _maxWidth); _maxHeight = Math.Max((int)translated.Height, _maxHeight); } _documentScaleFactor = _maxHeight != 0 ? (double)_maxWidth / _maxHeight : 0D; _markers = null; UpdateScrollbars(); Invalidate(); }
private void HandleMouseDoubleClickForTextSelection(MouseEventArgs e) { var pdfLocation = PointToPdf(e.Location); if (!pdfLocation.IsValid) { return; } if (Document.GetWordAtPosition(pdfLocation, 4f, 4f, out var word)) { _textSelectionState = new TextSelectionState() { StartPage = pdfLocation.Page, EndPage = pdfLocation.Page, StartIndex = word.Offset, EndIndex = word.Offset + word.Length }; Invalidate(); } }
public void Stop() { State = TextSelectionState.Selected; }