1 (* Copyright (C) 2000-2005, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://cs.unibo.it/helm/.
26 (*************************************************************************)
30 (* Andrea Asperti <asperti@cs.unibo.it> *)
33 (*************************************************************************)
40 | H of attr * ('expr box) list
41 | V of attr * ('expr box) list
42 | HV of attr * ('expr box) list
43 | HOV of attr * ('expr box) list
44 | Object of attr * 'expr
45 | Action of attr * ('expr box) list
47 and attr = (string option * string * string) list
49 let smallskip = Space([None,"width","0.5em"]);;
50 let skip = Space([None,"width","1em"]);;
52 let indent t = H([],[skip;t]);;
57 let tag_of_box = function
64 let box2xml ~obj2xml box =
68 Text (attr,s) -> X.xml_nempty ~prefix "text" attr (X.xml_cdata s)
69 | Space attr -> X.xml_empty ~prefix "space" attr
70 | Ink attr -> X.xml_empty ~prefix "ink" attr
74 | HOV (attr,l) as box ->
75 X.xml_nempty ~prefix (tag_of_box box) attr
76 [< (List.fold_right (fun x i -> [< (aux x) ; i >]) l [<>])
79 X.xml_nempty ~prefix "obj" attr [< obj2xml m >]
81 X.xml_nempty ~prefix "action" attr
82 [< (List.fold_right (fun x i -> [< (aux x) ; i >]) l [<>]) >]
87 let rec map f = function
88 | (Text _) as box -> box
89 | (Space _) as box -> box
90 | (Ink _) as box -> box
91 | H (attr, l) -> H (attr, List.map (map f) l)
92 | V (attr, l) -> V (attr, List.map (map f) l)
93 | HV (attr, l) -> HV (attr, List.map (map f) l)
94 | HOV (attr, l) -> HOV (attr, List.map (map f) l)
95 | Action (attr, l) -> Action (attr, List.map (map f) l)
96 | Object (attr, obj) -> Object (attr, f obj)
100 let document_of_box ~obj2xml pres =
101 [< Xml.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
103 Xml.xml_nempty ~prefix "box"
104 [Some "xmlns","m","http://www.w3.org/1998/Math/MathML" ;
105 Some "xmlns","b","http://helm.cs.unibo.it/2003/BoxML" ;
106 Some "xmlns","helm","http://www.cs.unibo.it/helm" ;
107 Some "xmlns","xlink","http://www.w3.org/1999/xlink"
114 let b_hv a b = HV(a,b)
115 let b_hov a b = HOV(a,b)
116 let b_text a b = Text(a,b)
117 let b_object b = Object ([],b)
118 let b_indent = indent
119 let b_space = Space [None, "width", "0.5em"]
120 let b_kw = b_text (RenderingAttrs.object_keyword_attributes `BoxML)
124 Printf.sprintf "%s%s=%s" (match ns with None -> "" | Some s -> s ^ ":") n v
126 String.concat " " (List.map pp attr)
128 let get_attr = function
137 | Action (attr, _) ->
140 let set_attr attr = function
141 | Text (_, x) -> Text (attr, x)
142 | Space _ -> Space attr
144 | H (_, x) -> H (attr, x)
145 | V (_, x) -> V (attr, x)
146 | HV (_, x) -> HV (attr, x)
147 | HOV (_, x) -> HOV (attr, x)
148 | Object (_, x) -> Object (attr, x)
149 | Action (_, x) -> Action (attr, x)