-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPageLayoutHelper.vb
More file actions
70 lines (59 loc) · 3.92 KB
/
PageLayoutHelper.vb
File metadata and controls
70 lines (59 loc) · 3.92 KB
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
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports DevExpress.XtraRichEdit.API.Layout
Imports DevExpress.XtraRichEdit.API.Native
Namespace WindowsFormsApplication1.DocumentLayoutHelper
Public NotInheritable Class PageLayoutHelper
Private Sub New()
End Sub
Public Shared Function GetInformationAboutCurrentPage(ByVal currentDocumentLayout As DocumentLayout, ByVal currentPage As LayoutPage, ByVal currentPosition As DocumentPosition) As String
Dim returnedInformation As String = ""
Dim currentPageIndex As Integer = currentDocumentLayout.GetPageIndex(currentPage)
Dim totalPageCount As Integer = currentDocumentLayout.GetFormattedPageCount()
' get information about page content using a LayoutVisitor descendant
Dim visitor As New CustomDocumentLayoutVisitor()
visitor.Visit(currentPage)
' get information about page bounds using PageArea properties
Dim pageAreaProperties As PageAreaProperties = CaculatePageAreaProperties(currentPage.PageAreas(0), currentPosition)
returnedInformation &= String.Format(Constants.vbCrLf & "Page: {0} of {1}" & Constants.vbCrLf, currentPageIndex + 1, totalPageCount)
returnedInformation &= String.Format("Current page range: {0} - {1}" & Constants.vbCrLf, currentPage.MainContentRange.Start, currentPage.MainContentRange.Start + currentPage.MainContentRange.Length - 1)
returnedInformation &= String.Format("Images count: {0}" & Constants.vbCrLf, visitor.ImagesCount)
returnedInformation &= String.Format("Tables count: {0}" & Constants.vbCrLf, visitor.TablesCount)
returnedInformation &= String.Format("Text Boxes count: {0}" & Constants.vbCrLf, visitor.TextBoxesCount)
returnedInformation &= String.Format("Paragraphs count: {0}" & Constants.vbCrLf, visitor.ParagraphsCount)
returnedInformation &= String.Format("Text lines count: {0}" & Constants.vbCrLf, visitor.TextLinesCount)
returnedInformation &= String.Format("Words (text blocks) count: {0}" & Constants.vbCrLf, visitor.WordsCount)
returnedInformation &= String.Format(Constants.vbCrLf & "Column: {0} of {1}" & Constants.vbCrLf, pageAreaProperties.currentColumnIndex, pageAreaProperties.columnCount)
returnedInformation &= String.Format("Current COLUMN content bounds: {0}" & Constants.vbCrLf, pageAreaProperties.currentColumnBounds)
returnedInformation &= String.Format("Current PAGE content bounds: {0}" & Constants.vbCrLf, pageAreaProperties.currentPageBounds)
Return returnedInformation
End Function
Public Shared Function CaculatePageAreaProperties(ByVal pageArea As LayoutPageArea, ByVal pos As DocumentPosition) As PageAreaProperties
Dim pageAreaProperties As New PageAreaProperties()
pageAreaProperties.columnCount = pageArea.Columns.Count
pageAreaProperties.currentPageBounds.Location = pageArea.Columns(0).Bounds.Location
For i As Integer = 0 To pageArea.Columns.Count - 1
Dim currentColumnContentHeight As Integer = pageArea.Columns(i).Rows.Last.Bounds.Bottom - pageArea.Columns(i).Rows.First.Bounds.Top
If pageArea.Columns(i).Range.Contains(pos.ToInt()) Then
pageAreaProperties.currentColumnIndex = i
pageAreaProperties.currentColumnBounds.Location = pageArea.Columns(i).Bounds.Location
pageAreaProperties.currentColumnBounds.Width = pageArea.Columns(i).Bounds.Width
pageAreaProperties.currentColumnBounds.Height = currentColumnContentHeight
End If
pageAreaProperties.currentPageBounds.Width += pageArea.Columns(i).Bounds.Width
pageAreaProperties.currentPageBounds.Height = Math.Max(pageAreaProperties.currentPageBounds.Height, currentColumnContentHeight)
Next i
Return pageAreaProperties
End Function
End Class
Public Class PageAreaProperties
Public currentColumnIndex As Integer = 0
Public columnCount As Integer = 0
Public currentColumnBounds As Rectangle = Rectangle.Empty
Public currentPageBounds As Rectangle = Rectangle.Empty
End Class
End Namespace