-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcap.js
65 lines (58 loc) · 1.66 KB
/
cap.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
56
57
58
59
60
61
62
63
64
65
const createCAPobj=(obj,newvalues)=>{
const def={bk:'', //book name
bkseq:-1,
_:-1 , //paranum group, most book has only one.
p:-1 , //paranum -1=not resolved
g:0 , //page unit grouping
x:0, //line offset from paranum, paranum==0 from beginning of book
//line==1 , point to end of first line, begin of next line
y:0, //syllabus from begining of line
z:0, //syllable count ,if==-1, point to a complete word
x0:0, //absolute linecount
bk0:-1, //line count from this book
_w:0, //total line of this paging unit
// x0-x+px ==> first line of next p
// x0-x ==> first line of this p
w:0 // 0 system to decide how many lines
// 1 only fetch this line
// 2 fetch one more line (even div 2 )
// 3 fetch upper one line and lower one line
// 4 fetch two more lines (total 3)
};
const out=Object.assign(def,obj);
for (var i in newvalues) {
if (out.hasOwnProperty(i)) {
out[i]=newvalues[i];
}
}
return out;
}
const stringify=function(){
const cap=this;
let bk=cap.bk;
let o=bk+"_";
if (cap._) o+=cap._;
//if (cap.p) o+='p'+cap.p;
if (cap.g) o+='g'+cap.g;
if (cap.w) o+='w'+cap.w;
if (cap.x||cap._==0) o+='x'+cap.x;
if (cap.y) o+='y'+cap.y;
if (cap.z==-1) o+='z';
else if (cap.z>0) o+='z'+cap.z;
return o;
}
const floor=function(){ //這一頁的開頭的絕對行數
const cap=this;
if (cap.x) {
cap.x0-=cap.x;
cap.bk0-=cap.x;
cap.x=0;
}
return cap.x0;
}
const getline=function(seq){
const cap=this;
seq=seq||cap.x0;
return cap.db().getline(seq);
}
module.exports={createCAPobj,stringify,floor,getline}