]> matita.cs.unibo.it Git - helm.git/blob - helm/www/lambdadelta/bin/xhtbl/matrix.ml
update in basic_2
[helm.git] / helm / www / lambdadelta / bin / xhtbl / matrix.ml
1 module A = Array
2 module N = Filename
3
4 module T = Table
5
6 type cell = {
7    ck: T.text list; (* contents *)
8    cc: T.css;       (* css classes *)
9    cu: T.uri;       (* uri *)
10    cx: T.ext;       (* extension *)
11    cn: T.anchor;    (* named anchor *)   
12    cb: T.border;    (* border *)
13 }
14
15 type matrix = {
16    r: int;              (* rows *)
17    c: int;              (* columns *)
18    m: cell array array; (* matrix *)
19 }
20
21 let strand a b = if a = "" then b else a
22
23 let empty = {
24    ck = []; cc = []; cu = ""; cx = ""; cn = ""; cb = T.border false;
25 }
26
27 let make ts = {
28    r = ts.T.rf; c = ts.T.cf;
29    m = A.make_matrix ts.T.rf ts.T.cf empty;
30 }
31
32 let set_key m y x kl = 
33    m.m.(y).(x) <- {m.m.(y).(x) with ck = kl}
34
35 let set_attrs m y x c u e n = 
36    m.m.(y).(x) <- {m.m.(y).(x) with
37       cc = c @ m.m.(y).(x).cc;
38       cu = u ^ m.m.(y).(x).cu;
39       cx = m.m.(y).(x).cx ^ e;
40       cn = strand m.m.(y).(x).cn n;
41    }
42
43 let set_west m y x b =
44    let c = m.m.(y).(x) in
45    let cb = {c.cb with T.w = c.cb.T.w || b.T.w} in 
46    m.m.(y).(x) <- {c with cb = cb}
47
48 let set_north m y x b =
49    let c = m.m.(y).(x) in
50    let cb = {c.cb with T.n = c.cb.T.n || b.T.n} in 
51    m.m.(y).(x) <- {c with cb = cb}
52
53 let set_east m y x b =
54    if x < pred m.c then set_west m y (succ x) {b with T.w = b.T.e} else
55    let c = m.m.(y).(x) in
56    let cb = {c.cb with T.e = c.cb.T.e || b.T.e} in 
57    m.m.(y).(x) <- {c with cb = cb}
58
59 let set_south m y x b =
60    if y < pred m.r then set_north m (succ y) x {b with T.n = b.T.s} else
61    let c = m.m.(y).(x) in
62    let cb = {c.cb with T.s = c.cb.T.s || b.T.s} in 
63    m.m.(y).(x) <- {c with cb = cb}