-
Notifications
You must be signed in to change notification settings - Fork 128
/
Copy pathpptx.d
93 lines (73 loc) · 1.97 KB
/
pptx.d
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
/++
Bare minimum support for reading Microsoft PowerPoint files.
History:
Added February 19, 2025
+/
module arsd.pptx;
// see ~/zip/ppt
import arsd.core;
import arsd.zip;
import arsd.dom;
import arsd.color;
/++
+/
class PptxFile {
private ZipFile zipFile;
private XmlDocument document;
/++
+/
this(FilePath file) {
this.zipFile = new ZipFile(file);
load();
}
/// ditto
this(immutable(ubyte)[] rawData) {
this.zipFile = new ZipFile(rawData);
load();
}
/// public for now but idk forever.
PptxSlide[] slides;
private string[string] contentTypes;
private struct Relationship {
string id;
string type;
string target;
}
private Relationship[string] relationships;
private void load() {
loadXml("[Content_Types].xml", (document) {
foreach(element; document.querySelectorAll("Override"))
contentTypes[element.attrs.PartName] = element.attrs.ContentType;
});
loadXml("ppt/_rels/presentation.xml.rels", (document) {
foreach(element; document.querySelectorAll("Relationship"))
relationships[element.attrs.Id] = Relationship(element.attrs.Id, element.attrs.Type, element.attrs.Target);
});
loadXml("ppt/presentation.xml", (document) {
this.document = document;
foreach(element; document.querySelectorAll("p\\:sldIdLst p\\:sldId"))
loadXml("ppt/" ~ relationships[element.getAttribute("r:id")].target, (document) {
slides ~= new PptxSlide(this, document);
});
});
// then there's slide masters and layouts and idk what that is yet
}
private void loadXml(string filename, scope void delegate(XmlDocument document) handler) {
auto document = new XmlDocument(cast(string) zipFile.getContent(filename));
handler(document);
}
}
class PptxSlide {
private PptxFile file;
private XmlDocument document;
private this(PptxFile file, XmlDocument document) {
this.file = file;
this.document = document;
}
/++
+/
string toPlainText() {
// FIXME: need to handle at least some of the layout
return document.root.innerText;
}
}