-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathSpine.cs
49 lines (43 loc) · 1.28 KB
/
Spine.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
#region Related components
using System;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Collections.Generic;
#endregion
namespace net.vieapps.Components.Utility.Epub
{
class Spine
{
private struct ItemRef
{
public string ID;
public bool Linear;
};
private string _toc;
private List<ItemRef> _itemRefs;
internal Spine() => this._itemRefs = new List<ItemRef>();
internal void SetToc(string toc) => this._toc = toc;
internal void AddItemRef(string id, bool linear)
{
ItemRef itemRef;
itemRef.ID = id;
itemRef.Linear = linear;
this._itemRefs.Add(itemRef);
}
internal XElement ToElement()
{
var element = new XElement(Document.OpfNS + "spine");
if (!string.IsNullOrEmpty(this._toc))
element.Add(new XAttribute("toc", this._toc));
foreach (var itemRef in this._itemRefs)
{
var item = new XElement(Document.OpfNS + "itemref", new XAttribute("idref", itemRef.ID));
if (!itemRef.Linear)
item.SetAttributeValue("linear", "no");
element.Add(item);
}
return element;
}
}
}