/
CustomLayoutVisitor.vb
108 lines (95 loc) · 3.12 KB
/
CustomLayoutVisitor.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
Imports DevExpress.XtraRichEdit.API.Layout
Imports DevExpress.XtraRichEdit.API.Native
Imports DevExpress.XtraRichEdit.Layout
Imports System
Imports System.Collections.Generic
Imports System.Drawing
Imports System.Linq
Imports System.Reflection
Imports System.Text
Namespace WindowsFormsApplication1
Public Class StaticsticsVisitor
Inherits DocumentVisitorBase
Private ReadOnly _buffer As StringBuilder
Public Sub New()
WordCount = 0
Me._buffer = New StringBuilder()
End Sub
Public Overrides Sub Visit(ByVal text As DocumentText)
_buffer.Append(text.Text)
End Sub
Public Overrides Sub Visit(ByVal paragraphEnd As DocumentParagraphEnd)
FinishParagraph()
End Sub
Private Sub FinishParagraph()
Dim text As String = _buffer.ToString()
Me.WordCount += text.Split(New Char() { " "c, "."c, "!"c, "?"c }, StringSplitOptions.RemoveEmptyEntries).Length
_buffer.Length = 0
End Sub
Private privateWordCount As Integer
Public Property WordCount() As Integer
Get
Return privateWordCount
End Get
Private Set(ByVal value As Integer)
privateWordCount = value
End Set
End Property
Protected ReadOnly Property Buffer() As StringBuilder
Get
Return _buffer
End Get
End Property
End Class
Public Class CustomLayoutVisitor
Inherits LayoutVisitor
Private document As Document
Public Sub New(ByVal doc As Document)
Me.document = doc
RowIndex = 0
ColIndex = 0
IsFound = False
End Sub
Protected Overrides Sub VisitRow(ByVal row As LayoutRow)
If Not IsFound Then
RowIndex += 1
If row.Range.Contains(document.CaretPosition.ToInt()) Then
IsFound = True
ColIndex = document.CaretPosition.ToInt() - row.Range.Start
End If
End If
MyBase.VisitRow(row)
End Sub
Public Sub Reset()
RowIndex = 0
ColIndex = 0
End Sub
Private privateColIndex As Integer
Public Property ColIndex() As Integer
Get
Return privateColIndex
End Get
Private Set(ByVal value As Integer)
privateColIndex = value
End Set
End Property
Private privateRowIndex As Integer
Public Property RowIndex() As Integer
Get
Return privateRowIndex
End Get
Private Set(ByVal value As Integer)
privateRowIndex = value
End Set
End Property
Private privateIsFound As Boolean
Public Property IsFound() As Boolean
Get
Return privateIsFound
End Get
Private Set(ByVal value As Boolean)
privateIsFound = value
End Set
End Property
End Class
End Namespace