-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRichEditDocumentLayoutAnalyzer.cs
More file actions
65 lines (52 loc) · 3.93 KB
/
RichEditDocumentLayoutAnalyzer.cs
File metadata and controls
65 lines (52 loc) · 3.93 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DevExpress.XtraRichEdit.API.Layout;
using DevExpress.XtraRichEdit.API.Native;
namespace WindowsFormsApplication1.DocumentLayoutHelper {
public static class RichEditDocumentLayoutAnalyzer {
public static string GetInformationAboutRichEditDocumentLayout(Document currentDocument, DocumentLayout currentDocumentLayout) {
SubDocument subDocument = currentDocument.CaretPosition.BeginUpdateDocument();
DocumentPosition docPosition = subDocument.CreatePosition(currentDocument.CaretPosition.ToInt() == 0 ? 0 : currentDocument.CaretPosition.ToInt() - 1);
ReadOnlyShapeCollection shapes = subDocument.Shapes.Get(subDocument.CreateRange(docPosition, 1));
ReadOnlyDocumentImageCollection images = subDocument.Images.Get(subDocument.CreateRange(docPosition, 1));
if(shapes.Count == 0 && images.Count == 0) docPosition = subDocument.CreatePosition(currentDocument.CaretPosition.ToInt());
string returnedInformation = "";
// get infromation about a current document element
returnedInformation += GetInformationAboutCurrentDocumentElement(currentDocument, currentDocumentLayout, subDocument, docPosition);
// collect information about CURRENT PAGE
RangedLayoutElement layoutPosition = currentDocumentLayout.GetElement<RangedLayoutElement>(docPosition);
if(layoutPosition != null) {
int currentPageIndex = currentDocumentLayout.GetPageIndex(layoutPosition);
returnedInformation += PageLayoutHelper.GetInformationAboutCurrentPage(currentDocumentLayout, currentDocumentLayout.GetPage(currentPageIndex), docPosition);
}
currentDocument.CaretPosition.EndUpdateDocument(subDocument);
return returnedInformation;
}
public static string GetInformationAboutCurrentDocumentElement(Document currentDocument, DocumentLayout currentDocumentLayout, SubDocument currentSubDocument, DocumentPosition docPosition) {
if(currentSubDocument.GetSubDocumentType() == SubDocumentType.TextBox) {
return TextBoxLayoutHelper.GetInformationAboutCurrentTextBox(currentSubDocument, currentDocumentLayout, docPosition);
}
if(currentSubDocument.GetSubDocumentType() == SubDocumentType.Main) {
RangedLayoutElement tableCell = currentDocumentLayout.GetElement(docPosition, LayoutType.TableCell);
if(tableCell != null)
// collect information about TABLE CELL
return DocumentElementLayoutHelper.GetInformationAboutCurrentTableCell(currentDocument, tableCell as LayoutTableCell);
RangedLayoutElement imageinline = currentDocumentLayout.GetElement(docPosition, LayoutType.InlinePictureBox);
if(imageinline != null)
// collect information about INLINE PICTURE
return DocumentElementLayoutHelper.GetInformationAboutCurrentInlinePicture(imageinline as InlinePictureBox);
RangedLayoutElement floatingObjectAnchor = currentDocumentLayout.GetElement(docPosition, LayoutType.FloatingObjectAnchorBox);
if(floatingObjectAnchor != null)
// collect information about FLOATING OBJECT
return DocumentElementLayoutHelper.GetInformationAboutCurrentFloatingObject(floatingObjectAnchor as FloatingObjectAnchorBox, currentDocumentLayout);
RangedLayoutElement regularTextBlock = currentDocumentLayout.GetElement(docPosition, LayoutType.PlainTextBox);
if(regularTextBlock != null)
// collect information about REGULAR TEXT BLOCK
return DocumentElementLayoutHelper.GetInformationAboutRegularTextBlock(regularTextBlock as PlainTextBox, currentDocument);
}
return "";
}
}
}