Support for the FreeMonoTengwar font and ConScript encoding
[tengwarjs.git] / column.js
1
2 module.exports = makeColumn;
3 function makeColumn(font, tengwa, tengwaNote) {
4 return new Column(font, tengwa, tengwaNote);
5 };
6
7 var Column = function (font, tengwa, tengwaNote) {
8 this.font = font;
9 this.above = void 0;
10 this.tildeAbove = void 0;
11 this.tengwa = tengwa;
12 this.tildeBelow = void 0;
13 this.below = void 0;
14 this.following = void 0;
15 this.error = void 0;
16
17 this.aboveNote = void 0;
18 this.tildeAboveNote = void 0;
19 this.tengwaNote = tengwaNote;
20 this.tildeBelowNote = void 0;
21 this.belowNote = void 0;
22 this.followingNote = void 0;
23
24 this.hasVariant = false;
25 };
26
27 Column.prototype.canAddAbove = function (tehta, reversed) {
28 return (
29 !this.above && !!this.font.tehtaForTengwa(this.tengwa, tehta)
30 ) || ( // flip it
31 !reversed && !this.below && this.reversed().canAddAbove(tehta, true)
32 );
33 };
34
35 Column.prototype.addAbove = function (above, aboveNote) {
36 if (!this.font.tehtaForTengwa(this.tengwa, above)) {
37 this.reverse();
38 }
39 this.above = above;
40 this.aboveNote = aboveNote;
41 return this;
42 };
43
44 Column.prototype.canAddBelow = function (tehta, reversed) {
45 return (
46 !this.below && !!this.font.tehtaForTengwa(this.tengwa, tehta)
47 ) || ( // flip it
48 !reversed && !this.above && this.reversed().canAddBelow(tehta, true)
49 );
50 };
51
52 Column.prototype.addBelow = function (below, belowNote) {
53 if (!this.font.tehtaForTengwa(this.tengwa, below)) {
54 this.reverse();
55 }
56 this.below = below;
57 this.belowNote = belowNote;
58 return this;
59 };
60
61 Column.prototype.addTildeAbove = function (tildeAboveNote) {
62 this.tildeAbove = true;
63 this.tildeAboveNote = tildeAboveNote;
64 return this;
65 };
66
67 Column.prototype.addTildeBelow = function (tildeBelowNote) {
68 this.tildeBelow = true;
69 this.tildeBelowNote = tildeBelowNote;
70 return this;
71 };
72
73 Column.prototype.canAddFollowing = function (following) {
74 return !this.following && !!this.font.tehtaForTengwa(this.tengwa, following);
75 };
76
77 Column.prototype.addFollowing = function (following, followingNote) {
78 this.following = following;
79 this.followingNote = followingNote;
80 return this;
81 };
82
83 Column.prototype.reversed = function () {
84 return this.clone().reverse();
85 };
86
87 Column.prototype.clone = function () {
88 var column = new Column(this.font, this.tengwa);
89 if (this.above) column.addAbove(this.above, this.aboveNote);
90 if (this.below) column.addBelow(this.below, this.belowNote);
91 if (this.following) column.addFollowing(this.following, this.followingNote);
92 if (this.tildeBelow) column.addTildeBelow(this.tildeBelowNote);
93 if (this.tildeAbove) column.addTildeAbove(this.tildeAboveNote);
94 return column;
95 };
96
97 var reversed = {
98 "silme": "silme-nuquerna",
99 "esse": "esse-nuquerna",
100 "silme-nuquerna": "silme",
101 "esse-nuquerna": "esse"
102 };
103
104 Column.prototype.reverse = function () {
105 this.tengwa = reversed[this.tengwa] || this.tengwa;
106 return this;
107 };
108
109 Column.prototype.addError = function (error) {
110 this.errors = this.errors || [];
111 this.errors.push(error);
112 return this;
113 };
114
115 Column.prototype.varies = function () {
116 this.hasVariant = true;
117 return this;
118 };
119