]> matita.cs.unibo.it Git - helm.git/blobdiff - matitaB/components/content_pres/boxPp.ml
Simplified rendering
[helm.git] / matitaB / components / content_pres / boxPp.ml
index 45c8b6c20b89f4c131848c92da3d93d39a263b06..7f71aa20bd81f8ffd0abbfb63a9c59a0cc19a851 100644 (file)
@@ -25,7 +25,6 @@
 
 (* $Id$ *)
 
-module Pres = Mpresentation
 
 (** {2 Pretty printing from BoxML to strings} *)
 
@@ -33,8 +32,8 @@ let utf8_string_length s = Utf8.compute_len s 0 (String.length s)
 
 let string_space = " "
 let string_space_len = utf8_string_length string_space
-let string_indent = (* string_space *) [],""
-let string_indent_len = utf8_string_length (snd string_indent)
+let string_indent = (* string_space *) ""
+let string_indent_len = utf8_string_length string_indent
 let string_ink = "---------------------------"
 let string_ink_len = utf8_string_length string_ink
 
@@ -46,24 +45,8 @@ let want_spacing = contains_attrs (RenderingAttrs.spacing_attributes `BoxML)
 
 let shift off = List.map (fun (start,stop,v) -> start+off,stop+off,v);;
 
-let (^^) (map1,s1) (map2,s2) = map1 @ (shift (utf8_string_length s1) map2), s1 ^ s2;;
+let indent_string s = string_indent ^ s
 
-(* CSC: inefficient (quadratic) implementation *)
-let mapped_string_concat sep =
- let sep_len = utf8_string_length sep in
- let rec aux off =
-  function
-     [] -> [],""
-   | [map,s] -> shift off map,s
-   | (map,s)::tl ->
-       let map = shift off map in
-       let map2,s2 = aux (off + utf8_string_length s + sep_len) tl in
-        map@map2, s ^ sep ^ s2
- in
-  aux 0
-;;
-
-let indent_string s = string_indent ^^ s
 let indent_children (size, children) =
   let children' = List.map indent_string children in
   size + string_space_len, children'
@@ -82,9 +65,9 @@ let merge_columns sep cols =
   let add_row ~continue row =
     match !res_rows with
     | last :: prev when continue ->
-        res_rows := (last ^^ ([],sep) ^^ row) :: prev;
-        indent := !indent + utf8_string_length (snd last) + sep_len
-    | _ -> res_rows := (([],String.make !indent ' ') ^^ row) :: !res_rows;
+        res_rows := (last ^ sep ^ row) :: prev;
+        indent := !indent + utf8_string_length last + sep_len
+    | _ -> res_rows := ((String.make !indent ' ') ^ row) :: !res_rows;
   in
   List.iter
     (fun rows ->
@@ -97,7 +80,7 @@ let merge_columns sep cols =
   List.rev !res_rows
     
 let max_len =
-  List.fold_left (fun max_size (_,s) -> max (utf8_string_length s) max_size) 0
+  List.fold_left (fun max_size s -> max (utf8_string_length s) max_size) 0
 
 let render_row available_space spacing children =
   let spacing_bonus = if spacing then string_space_len else 0 in
@@ -113,21 +96,20 @@ let render_row available_space spacing children =
   let rendering = merge_columns sep (List.rev !renderings) in
   max_len rendering, rendering
 
-let fixed_rendering href s =
+let fixed_rendering s = 
   let s_len = utf8_string_length s in
-  let map = match href with None -> [] | Some href -> [0,s_len-1,href] in
-  (fun _ -> s_len, [map,s])
+  fun _ -> s_len,[s]
 
 let render_to_strings ~map_unicode_to_tex choose_action size markup =
   let max_size = max_int in
   let rec aux_box =
     function
-    | Box.Text (_, t) -> fixed_rendering None t
-    | Box.Space _ -> fixed_rendering None string_space
-    | Box.Ink _ -> fixed_rendering None string_ink
+    | Box.Text (_, t) -> fixed_rendering t
+    | Box.Space _ -> fixed_rendering string_space
+    | Box.Ink _ -> fixed_rendering string_ink
     | Box.Action (_, []) -> assert false
     | Box.Action (_, l) -> aux_box (choose_action l)
-    | Box.Object (_, o) -> aux_mpres o
+    | Box.Object (_, o) -> fixed_rendering o
     | Box.H (attrs, children) ->
         let spacing = want_spacing attrs in
         let children' = List.map aux_box children in
@@ -150,7 +132,7 @@ let render_to_strings ~map_unicode_to_tex choose_action size markup =
         let hd_f = aux_box hd in
         let tl_fs = List.map aux_box tl in
         (fun size ->
-          let _, hd_rendering = hd_f size in
+          let hd_rendering = snd (hd_f size) in
           let children_size =
             max 0 (if indent then size - string_indent_len else size)
           in
@@ -207,74 +189,9 @@ let render_to_strings ~map_unicode_to_tex choose_action size markup =
             fs;
           if !renderings <> [] then end_cluster ();
           max_len !rows, List.rev !rows)
-  and aux_mpres =
-   let text s = Pres.Mtext ([], s) in
-   let mrow c = Pres.Mrow ([], c) in
-   let parentesize s = s in
-   function x ->
-    let attrs = Pres.get_attr x in
-    let href =
-     try
-      let _,_,href =
-       List.find (fun (ns,na,value) -> ns = Some "xlink" && na = "href") attrs
-      in
-       Some href
-     with Not_found -> None in
-    match x with
-    | Pres.Mi (_, s)
-    | Pres.Mn (_, s)
-    | Pres.Mtext (_, s)
-    | Pres.Ms (_, s)
-    | Pres.Mgliph (_, s) -> fixed_rendering href s
-    | Pres.Mo (_, s) ->
-        let s =
-          if map_unicode_to_tex then begin
-            if utf8_string_length s = 1 && Char.code s.[0] < 128 then
-              s
-            else
-              match Utf8Macro.tex_of_unicode s with
-              | s::_ -> s ^ " "
-              | [] -> " " ^ s ^ " "
-          end else
-            s
-        in
-        fixed_rendering href s
-    | Pres.Mspace _ -> fixed_rendering href string_space
-    | Pres.Mrow (attrs, children) ->
-        let children' = List.map aux_mpres children in
-        (fun size -> render_row size false children')
-    | Pres.Mfrac (_, m, n) ->
-       aux_mpres (mrow [ text " \\frac "; parentesize m ; text " "; parentesize n; text " " ])
-    | Pres.Msqrt (_, m) -> aux_mpres (mrow [ text " \\sqrt "; parentesize m; text " "])
-    | Pres.Mroot (_, r, i) ->
-        aux_mpres (mrow [
-          text " \\root "; parentesize i; text " \\of "; parentesize r; text " " ])
-    | Pres.Mstyle (_, m)
-    | Pres.Merror (_, m)
-    | Pres.Mpadded (_, m)
-    | Pres.Mphantom (_, m)
-    | Pres.Menclose (_, m) -> aux_mpres m
-    | Pres.Mfenced (_, children) -> aux_mpres (mrow children)
-    | Pres.Maction (_, []) -> assert false
-    | Pres.Msub (_, m, n) ->
-        aux_mpres (mrow [ text " "; parentesize m; text " \\sub "; parentesize n; text " " ])
-    | Pres.Msup (_, m, n) ->
-        aux_mpres (mrow [ text " "; parentesize m; text " \\sup "; parentesize n; text " " ])
-    | Pres.Munder (_, m, n) ->
-        aux_mpres (mrow [ text " "; parentesize m; text " \\below "; parentesize n; text " " ])
-    | Pres.Mover (_, m, n) ->
-        aux_mpres (mrow [ text " "; parentesize m; text " \\above "; parentesize n; text " " ])
-    | Pres.Msubsup _
-    | Pres.Munderover _
-    | Pres.Mtable _ ->
-        prerr_endline
-          "MathML presentation element not yet available in concrete syntax";
-        assert false
-    | Pres.Maction (_, hd :: _) -> aux_mpres hd
-    | Pres.Mobject (_, o) -> aux_box (o: CicNotationPres.boxml_markup)
   in
-  snd (aux_mpres markup size)
+  snd (aux_box markup size)
 
 let render_to_string ~map_unicode_to_tex choose_action size markup =
mapped_string_concat "\n"
String.concat "\n"
   (render_to_strings ~map_unicode_to_tex choose_action size markup)