-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyPagePainter.cs
71 lines (63 loc) · 3 KB
/
MyPagePainter.cs
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
using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Layout;
using DevExpress.XtraRichEdit.API.Native;
using System.Drawing;
namespace LineNumberingExample {
#region #MyPagePainter
public class MyPagePainter : PagePainter {
RichEditControl richEditControl;
int previousColumnIndex = -1;
Font lineNumberFont;
public MyPagePainter(RichEditControl richEdit)
: base() {
richEditControl = richEdit;
}
public MyPagePainter(RichEditControl richEdit, Color backColor, CharacterStyle style)
: base() {
richEditControl = richEdit;
NumberingHighlightColor = backColor;
NumberingFontName = style.FontName;
NumberingFontSize = style.FontSize ?? 10F;
NumberingFontColor = style.ForeColor ?? Color.Black;
}
public string NumberingFontName { get; set; }
public float NumberingFontSize { get; set; }
public Color NumberingFontColor { get; set; }
public Color NumberingHighlightColor { get; set; }
public int LineNumberPadding { get; set; }
public override void DrawPage(LayoutPage page) {
lineNumberFont = new Font(NumberingFontName, NumberingFontSize, FontStyle.Regular);
base.DrawPage(page);
lineNumberFont.Dispose();
}
public override void DrawPageArea(LayoutPageArea pageArea) {
Rectangle lineNumberBounds = new Rectangle(new Point(-LineNumberPadding, 0), new Size(LineNumberPadding, pageArea.Bounds.Height));
Canvas.FillRectangle(new RichEditBrush(NumberingHighlightColor), lineNumberBounds);
base.DrawPageArea(pageArea);
previousColumnIndex = -1;
}
public override void DrawColumn(LayoutColumn column) {
LayoutPageArea pageArea = column.GetParentByType<LayoutPageArea>();
if (pageArea != null) {
int leftBoundary = 0;
if (previousColumnIndex >= 0) {
leftBoundary = pageArea.Columns[previousColumnIndex].Bounds.Right;
}
if (column.LineNumbers.Count > 0) {
HighlightLineNumberingArea(column, leftBoundary);
}
previousColumnIndex++;
}
base.DrawColumn(column);
}
public override void DrawLineNumberBox(LineNumberBox lineNumberBox) {
Canvas.DrawString(lineNumberBox.Text, lineNumberFont, new RichEditBrush(NumberingFontColor), lineNumberBox.Bounds, this.richEditControl.LayoutUnit);
}
void HighlightLineNumberingArea(LayoutColumn column, int leftBoundary) {
LayoutPage page = column.GetParentByType<LayoutPage>();
Rectangle marginBounds = new Rectangle(new Point(leftBoundary, 0), new Size(column.Bounds.X - leftBoundary, page.Bounds.Height));
Canvas.FillRectangle(new RichEditBrush(NumberingHighlightColor), marginBounds);
}
}
#endregion #MyPagePainter
}