-
Notifications
You must be signed in to change notification settings - Fork 620
/
Copy pathOutline.cs
114 lines (97 loc) · 2.84 KB
/
Outline.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
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
109
110
111
112
113
114
using System;
using System.Collections.Generic;
using System.Text;
using FastReport.Utils;
namespace FastReport.Preview
{
internal class Outline
{
private XmlItem rootItem;
private XmlItem curItem;
private int firstPassPosition;
public XmlItem Xml
{
get { return rootItem; }
set
{
rootItem = value;
curItem = rootItem;
value.Parent = null;
}
}
internal bool IsEmpty
{
get { return rootItem.Count == 0; }
}
internal XmlItem CurPosition
{
get { return curItem.Count == 0 ? null : curItem[curItem.Count - 1]; }
}
private void EnumItems(XmlItem item, float shift)
{
int pageNo = int.Parse(item.GetProp("Page"));
float offset = Converter.StringToFloat(item.GetProp("Offset"));
item.SetProp("Page", Converter.ToString(pageNo + 1));
item.SetProp("Offset", Converter.ToString(offset + shift));
for (int i = 0; i < item.Count; i++)
{
EnumItems(item[i], shift);
}
}
internal void Shift(XmlItem from, float newY)
{
if (from == null || from.Parent == null)
return;
int i = from.Parent.IndexOf(from);
if (i + 1 >= from.Parent.Count)
return;
from = from.Parent[i + 1];
float topY = Converter.StringToFloat(from.GetProp("Offset"));
EnumItems(from, newY - topY);
}
public void Add(string text, int pageNo, float offsetY)
{
curItem = curItem.Add();
curItem.Name = "item";
curItem.SetProp("Text", text);
curItem.SetProp("Page", pageNo.ToString());
curItem.SetProp("Offset", Converter.ToString(offsetY));
}
public void LevelRoot()
{
curItem = rootItem;
}
public void LevelUp()
{
if (curItem != rootItem)
curItem = curItem.Parent;
}
public void Clear()
{
Clear(-1);
}
private void Clear(int position)
{
if (position == -1)
rootItem.Clear();
else if (position < rootItem.Count)
rootItem.Items[position].Dispose();
LevelRoot();
}
public void PrepareToFirstPass()
{
firstPassPosition = rootItem.Count == 0 ? -1 : rootItem.Count;
LevelRoot();
}
public void ClearFirstPass()
{
Clear(firstPassPosition);
}
public Outline()
{
rootItem = new XmlItem();
rootItem.Name = "outline";
LevelRoot();
}
}
}