forked from iarna/rtf-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rtf-group.js
55 lines (51 loc) · 1.31 KB
/
rtf-group.js
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
"use strict";
const { cloneDeep, isEmpty } = require("lodash");
class RTFGroup {
constructor(parent) {
this.parent = parent;
this.content = [];
this.fonts = [];
this.colors = [];
this.style = {};
this.ignorable = null;
}
get(name) {
return this[name] != null ? this[name] : this.parent.get(name);
}
getFont(num) {
const output =
this.fonts[num] != null ? this.fonts[num] : this.parent.getFont(num);
return output;
}
getColor(num) {
return this.colors[num] != null
? this.colors[num]
: this.parent.getFont(num);
}
getStyle(name) {
if (!name) {
const noNameOutput = Object.assign(
{},
this.parent.getStyle(),
this.style
);
return noNameOutput;
}
const output =
this.style[name] != null ? this.style[name] : this.parent.getStyle(name);
return output;
}
resetStyle() {
this.style = {};
}
addContent(node) {
if (isEmpty(node.style) || (node.style.font && isEmpty(node.style.font))) {
node.style = cloneDeep(this.getStyle());
node.style.font = this.getFont(node.style.font);
node.style.foreground = this.getColor(node.style.foreground);
node.style.background = this.getColor(node.style.background);
}
this.content.push(node);
}
}
module.exports = RTFGroup;