1 (* Copyright (C) 2004-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://helm.cs.unibo.it/
33 let matita_script_current = ref (fun _ -> (assert false : < advance: ?statement:string -> unit -> unit; grafite_status: GrafiteTypes.status; setGoal: int option -> unit >));;
34 let register_matita_script_current f = matita_script_current := f;;
35 let get_matita_script_current () = !matita_script_current ();;
37 type document_element = string
39 class type cicMathView =
43 method set_font_size: int -> unit
44 method update_font_size: unit
46 method load_root : root:document_element -> unit
47 method remove_selections: unit
48 method set_selection: document_element option -> unit
49 method get_selections: document_element list
51 (** @raise Failure "no selection" *)
52 method strings_of_selection: (MatitaGuiTypes.paste_kind * string) list
54 (** set hyperlink callback. None disable hyperlink handling *)
55 method set_href_callback: (string -> unit) option -> unit
57 (** load a sequent and render it into parent widget *)
59 #ApplyTransformation.status -> NCic.metasenv -> NCic.substitution -> int -> unit
61 method load_nobject: #ApplyTransformation.status -> NCic.obj -> unit
65 let xlink_ns = Gdome.domString "http://www.w3.org/1999/xlink"
66 let helm_ns = Gdome.domString "http://www.cs.unibo.it/helm"
67 let href_ds = Gdome.domString "href"
68 let xref_ds = Gdome.domString "xref"
71 (** Gdome.element of a MathML document whose rendering should be blank. Used
72 * by cicBrowser to render "about:blank" document *)
73 let empty_mathml = lazy ""
75 (** shown for goals closed by side effects *)
76 let closed_goal_mathml = lazy "chiuso per side effect..."
79 let rec has_maction (elt :Gdome.element) =
80 (* fix this comparison *)
81 if elt#get_tagName#to_string = "m:maction" ||
82 elt#get_tagName#to_string = "b:action" then
85 match elt#get_parentNode with
86 | Some node when node#get_nodeType = GdomeNodeTypeT.ELEMENT_NODE ->
87 has_maction (new Gdome.element_of_node node)
91 let hrefs_of_elt elt =
92 let localName = href_ds in
93 if elt#hasAttributeNS ~namespaceURI:xlink_ns ~localName then
95 (elt#getAttributeNS ~namespaceURI:xlink_ns ~localName)#to_string in
96 Some (HExtlib.split text)
100 let id_of_node (node: Gdome.element) =
102 node#getAttributeNS ~namespaceURI:helm_ns ~localName:xref_ds in
104 List.hd (HExtlib.split ~sep:' ' xref_attr#to_string)
105 with Failure _ -> assert false
108 | SelTerm of NCic.term * string option (* term, parent hypothesis (if any) *)
109 | SelHyp of string * NCic.context (* hypothesis, context *)
112 let near (x1, y1) (x2, y2) =
113 let distance = sqrt (((x2 -. x1) ** 2.) +. ((y2 -. y1) ** 2.)) in
117 let name_of_hypothesis = function
118 | Some (Cic.Name s, _) -> s
121 let domImpl = Gdome.domImplementation ()
123 (* ids_to_terms should not be passed here, is just for debugging *)
124 let find_root_id annobj id ids_to_father_ids ids_to_terms ids_to_inner_types =
125 assert false (* MATITA 1.0
126 let find_parent id ids =
128 (* (prerr_endline (sprintf "id %s = %s" id
130 CicPp.ppterm (Hashtbl.find ids_to_terms id)
131 with Not_found -> "NONE"))); *)
132 if List.mem id ids then Some id
135 (try Hashtbl.find ids_to_father_ids id with Not_found -> None)
138 | Some id' -> aux id')
142 let return_father id ids =
143 match find_parent id ids with
144 | None -> assert false
145 | Some parent_id -> parent_id
147 let mk_ids terms = List.map CicUtil.id_of_annterm terms in
151 match types.Cic2acic.annexpected with
152 None -> types.Cic2acic.annsynthesized :: acc
153 | Some ty -> ty :: types.Cic2acic.annsynthesized :: acc
154 ) ids_to_inner_types [] in
156 | Cic.AConstant (_, _, _, Some bo, ty, _, _)
157 | Cic.AVariable (_, _, Some bo, ty, _, _)
158 | Cic.ACurrentProof (_, _, _, _, bo, ty, _, _) ->
159 return_father id (mk_ids (ty :: bo :: inner_types))
160 | Cic.AConstant (_, _, _, None, ty, _, _)
161 | Cic.AVariable (_, _, None, ty, _, _) ->
162 return_father id (mk_ids (ty::inner_types))
163 | Cic.AInductiveDefinition _ ->
164 assert false (* TODO *)
167 (** @return string content of a dom node having a single text child node, e.g.
168 * <m:mi xlink:href="...">bool</m:mi> *)
169 let string_of_dom_node node =
170 match node#get_firstChild with
174 let text = new Gdome.text_of_node node in
175 text#get_data#to_string
176 with GdomeInit.DOMCastException _ -> "")
179 class clickableMathView obj =
180 let text_width = 80 in
182 inherit GSourceView2.source_view obj
184 method strings_of_selection = (assert false : (paste_kind * string) list)
185 method update_font_size =
186 self#misc#modify_font_by_name
187 (sprintf "%s %d" BuildTimeConf.script_font (MatitaMisc.get_current_font_size ()))
188 method set_href_callback = (function _ -> () : (string -> unit) option -> unit)
189 method private set_cic_info = (function _ -> () : unit (*(Cic.conjecture option * (Cic.id, Cic.term) Hashtbl.t *
190 (Cic.id, Cic.hypothesis) Hashtbl.t *
191 (Cic.id, Cic.id option) Hashtbl.t * ('a, 'b) Hashtbl.t * 'c option)*) option -> unit)
192 (* dal widget di Luca *)
193 method load_root ~root =
194 self#buffer#delete ~start:(self#buffer#get_iter `START)
195 ~stop:(self#buffer#get_iter `END);
196 self#buffer#insert root
197 method action_toggle = (fun _ -> assert false : document_element -> bool)
198 method remove_selections = (() : unit)
199 method set_selection = (fun _ -> () : document_element option -> unit)
200 method get_selections = (assert false : document_element list)
201 method set_font_size font_size =
202 self#misc#modify_font_by_name
203 (sprintf "%s %d" BuildTimeConf.script_font font_size)
206 self#set_font_size (MatitaMisc.get_current_font_size ());
207 self#source_buffer#set_language (Some MatitaGtkMisc.matita_lang);
208 self#source_buffer#set_highlight_syntax true;
209 self#set_editable false
212 inherit GMathViewAux.multi_selection_math_view obj
214 val mutable href_callback: (string -> unit) option = None
215 method set_href_callback f = href_callback <- f
217 val mutable _cic_info = None
218 method private set_cic_info info = _cic_info <- info
219 method private cic_info = _cic_info
221 val normal_cursor = Gdk.Cursor.create `LEFT_PTR
222 val href_cursor = Gdk.Cursor.create `HAND2
223 val maction_cursor = Gdk.Cursor.create `QUESTION_ARROW
226 self#set_font_size (MatitaMisc.get_current_font_size ());
227 ignore (self#connect#selection_changed self#choose_selection_cb);
228 ignore (self#event#connect#button_press self#button_press_cb);
229 ignore (self#event#connect#button_release self#button_release_cb);
230 ignore (self#event#connect#selection_clear self#selection_clear_cb);
231 ignore (self#connect#element_over self#element_over_cb);
232 ignore (self#coerce#misc#connect#selection_get self#selection_get_cb)
234 val mutable button_press_x = -1.
235 val mutable button_press_y = -1.
236 val mutable selection_changed = false
237 val mutable href_statusbar_msg:
238 (GMisc.statusbar_context * Gtk.statusbar_message) option = None
239 (* <statusbar ctxt, statusbar msg> *)
241 method private selection_get_cb ctxt ~info ~time =
243 match ctxt#target with
244 | "PATTERN" -> self#text_of_selection `Pattern
245 | "TERM" | _ -> self#text_of_selection `Term
249 | Some s -> ctxt#return s
251 method private text_of_selection fmt =
252 match self#get_selections with
254 | node :: _ -> Some (self#string_of_node ~paste_kind:fmt node)
256 method private selection_clear_cb sel_event =
257 self#remove_selections;
258 (GData.clipboard Gdk.Atom.clipboard)#clear ();
261 method private button_press_cb gdk_button =
262 let button = GdkEvent.Button.button gdk_button in
263 if button = MatitaMisc.left_button then begin
264 button_press_x <- GdkEvent.Button.x gdk_button;
265 button_press_y <- GdkEvent.Button.y gdk_button;
266 selection_changed <- false
267 end else if button = MatitaMisc.right_button then
268 self#popup_contextual_menu
270 (int_of_float (GdkEvent.Button.x gdk_button))
271 (int_of_float (GdkEvent.Button.y gdk_button)))
272 (GdkEvent.Button.time gdk_button);
275 method private element_over_cb (elt_opt, _, _, _) =
276 let win () = self#misc#window in
278 Gdk.Window.set_cursor (win ()) normal_cursor;
279 HExtlib.iter_option (fun (ctxt, msg) -> ctxt#remove msg)
284 if has_maction elt then
285 Gdk.Window.set_cursor (win ()) maction_cursor
287 (match hrefs_of_elt elt with
288 | Some ((_ :: _) as hrefs) ->
289 Gdk.Window.set_cursor (win ()) href_cursor;
290 let msg_text = (* now create statusbar msg and store it *)
292 | [ href ] -> sprintf "Hyperlink to %s" href
293 | _ -> sprintf "Hyperlinks to: %s" (String.concat ", " hrefs) in
294 let ctxt = (get_gui ())#main#statusBar#new_context ~name:"href" in
295 let msg = ctxt#push msg_text in
296 href_statusbar_msg <- Some (ctxt, msg)
297 | _ -> leave_href ())
298 | None -> leave_href ()
300 method private tactic_text_pattern_of_node node =
301 let id = id_of_node node in
302 let cic_info, unsh_sequent = self#get_cic_info id in
303 match self#get_term_by_id cic_info id with
304 | SelTerm (t, father_hyp) ->
305 let sequent = self#sequent_of_id ~paste_kind:`Pattern id in
306 let text = self#string_of_cic_sequent ~output_type:`Pattern sequent in
307 (match father_hyp with
308 | None -> None, [], Some text
309 | Some hyp_name -> None, [ hyp_name, text ], None)
310 | SelHyp (hyp_name, _ctxt) -> None, [ hyp_name, "%" ], None
312 method private tactic_text_of_node node =
313 let id = id_of_node node in
314 let cic_info, unsh_sequent = self#get_cic_info id in
315 match self#get_term_by_id cic_info id with
316 | SelTerm (t, father_hyp) ->
317 let sequent = self#sequent_of_id ~paste_kind:`Term id in
318 let text = self#string_of_cic_sequent ~output_type:`Term sequent in
320 | SelHyp (hyp_name, _ctxt) -> hyp_name
322 (** @return a pattern structure which contains pretty printed terms *)
323 method private tactic_text_pattern_of_selection =
324 match self#get_selections with
325 | [] -> assert false (* this method is invoked only if there's a sel. *)
326 | node :: _ -> self#tactic_text_pattern_of_node node
328 method private popup_contextual_menu element time =
329 let menu = GMenu.menu () in
330 let add_menu_item ?(menu = menu) ?stock ?label () =
331 GMenu.image_menu_item ?stock ?label ~packing:menu#append () in
332 let check = add_menu_item ~label:"Check" () in
333 let reductions_menu_item = GMenu.menu_item ~label:"βδιζ-reduce" () in
334 let tactics_menu_item = GMenu.menu_item ~label:"Apply tactic" () in
335 let hyperlinks_menu_item = GMenu.menu_item ~label:"Hyperlinks" () in
336 menu#append reductions_menu_item;
337 menu#append tactics_menu_item;
338 menu#append hyperlinks_menu_item;
339 let reductions = GMenu.menu () in
340 let tactics = GMenu.menu () in
341 let hyperlinks = GMenu.menu () in
342 reductions_menu_item#set_submenu reductions;
343 tactics_menu_item#set_submenu tactics;
344 hyperlinks_menu_item#set_submenu hyperlinks;
345 let normalize = add_menu_item ~menu:reductions ~label:"Normalize" () in
346 let simplify = add_menu_item ~menu:reductions ~label:"Simplify" () in
347 let whd = add_menu_item ~menu:reductions ~label:"Weak head" () in
349 | None -> hyperlinks_menu_item#misc#set_sensitive false
351 match hrefs_of_elt elt, href_callback with
355 let item = add_menu_item ~menu:hyperlinks ~label:h () in
356 connect_menu_item item (fun () -> f h)) l
357 | _ -> hyperlinks_menu_item#misc#set_sensitive false);
358 menu#append (GMenu.separator_item ());
359 let copy = add_menu_item ~stock:`COPY () in
360 let gui = get_gui () in
361 List.iter (fun item -> item#misc#set_sensitive gui#canCopy)
362 [ copy; check; normalize; simplify; whd ];
363 let reduction_action kind () =
364 let pat = self#tactic_text_pattern_of_selection in
366 let loc = HExtlib.dummy_floc in
368 GrafiteAstPp.pp_executable ~term_pp:(fun s -> s)
369 ~lazy_term_pp:(fun _ -> assert false) ~obj_pp:(fun _ -> assert false)
370 ~map_unicode_to_tex:(Helm_registry.get_bool
371 "matita.paste_unicode_as_tex")
372 (GrafiteAst.Tactic (loc,
373 Some (GrafiteAst.Reduce (loc, kind, pat)),
374 GrafiteAst.Semicolon loc)) in
375 (get_matita_script_current ())#advance ~statement () in
376 connect_menu_item copy gui#copy;
377 connect_menu_item normalize (reduction_action `Normalize);
378 connect_menu_item simplify (reduction_action `Simpl);
379 connect_menu_item whd (reduction_action `Whd);
380 menu#popup ~button:MatitaMisc.right_button ~time
382 method private button_release_cb gdk_button =
383 if GdkEvent.Button.button gdk_button = MatitaMisc.left_button then begin
384 let button_release_x = GdkEvent.Button.x gdk_button in
385 let button_release_y = GdkEvent.Button.y gdk_button in
386 if selection_changed then
388 else (* selection _not_ changed *)
389 if near (button_press_x, button_press_y)
390 (button_release_x, button_release_y)
392 let x = int_of_float button_press_x in
393 let y = int_of_float button_press_y in
394 (match self#get_element_at x y with
397 if has_maction elt then ignore(self#action_toggle elt) else
398 (match hrefs_of_elt elt with
399 | Some hrefs -> self#invoke_href_callback hrefs gdk_button
404 method private invoke_href_callback hrefs gdk_button =
405 let button = GdkEvent.Button.button gdk_button in
406 if button = MatitaMisc.left_button then
407 let time = GdkEvent.Button.time gdk_button in
408 match href_callback with
414 let menu = GMenu.menu () in
418 GMenu.menu_item ~label:uri ~packing:menu#append () in
419 connect_menu_item menu_item
420 (fun () -> try f uri with Not_found -> assert false))
422 menu#popup ~button ~time)
424 method private choose_selection_cb gdome_elt =
425 let set_selection elt =
426 let misc = self#coerce#misc in
427 self#set_selection (Some elt);
428 misc#add_selection_target ~target:"STRING" Gdk.Atom.primary;
429 ignore (misc#grab_selection Gdk.Atom.primary);
432 if (elt#getAttributeNS ~namespaceURI:helm_ns
433 ~localName:xref_ds)#to_string <> ""
438 (match elt#get_parentNode with
439 | None -> assert false
440 | Some p -> aux (new Gdome.element_of_node p))
441 with GdomeInit.DOMCastException _ -> ()
443 (match gdome_elt with
444 | Some elt when (elt#getAttributeNS ~namespaceURI:xlink_ns
445 ~localName:href_ds)#to_string <> "" ->
447 | Some elt -> aux elt
448 | None -> self#set_selection None);
449 selection_changed <- true
451 method update_font_size = self#set_font_size (MatitaMisc.get_current_font_size ())
453 (** find a term by id from stored CIC infos @return either `Hyp if the id
454 * correspond to an hypothesis or `Term (cic, hyp) if the id correspond to a
455 * term. In the latter case hyp is either None (if the term is a subterm of
456 * the sequent conclusion) or Some hyp_name if the term belongs to an
458 method private get_term_by_id cic_info id =
459 let unsh_item, ids_to_terms, ids_to_hypotheses, ids_to_father_ids, _, _ =
461 let rec find_father_hyp id =
462 if Hashtbl.mem ids_to_hypotheses id
463 then Some (name_of_hypothesis (Hashtbl.find ids_to_hypotheses id))
466 try Hashtbl.find ids_to_father_ids id
467 with Not_found -> assert false in
469 | Some id -> find_father_hyp id
473 let term = Hashtbl.find ids_to_terms id in
474 let father_hyp = find_father_hyp id in
475 SelTerm (term, father_hyp)
478 let hyp = Hashtbl.find ids_to_hypotheses id in
480 match unsh_item with Some seq -> seq | None -> assert false in
481 let context' = MatitaMisc.list_tl_at hyp context in
482 SelHyp (name_of_hypothesis hyp, context')
483 with Not_found -> assert false
485 method private find_obj_conclusion id =
486 match self#cic_info with
488 | Some (_, _, _, _, _, None) -> assert false
489 | Some (_, ids_to_terms, _, ids_to_father_ids, ids_to_inner_types, Some annobj) ->
491 find_root_id annobj id ids_to_father_ids ids_to_terms ids_to_inner_types
493 (try Hashtbl.find ids_to_terms id with Not_found -> assert false)
495 method private string_of_node ~(paste_kind:paste_kind) node =
496 if node#hasAttributeNS ~namespaceURI:helm_ns ~localName:xref_ds
498 match paste_kind with
500 let tactic_text_pattern = self#tactic_text_pattern_of_node node in
501 GrafiteAstPp.pp_tactic_pattern
502 ~term_pp:(fun s -> s) ~lazy_term_pp:(fun _ -> assert false)
503 ~map_unicode_to_tex:(Helm_registry.get_bool
504 "matita.paste_unicode_as_tex")
506 | `Term -> self#tactic_text_of_node node
507 else string_of_dom_node node
509 method private string_of_cic_sequent ~output_type cic_sequent =
510 let script = get_matita_script_current () in
512 if script#onGoingProof () then script#proofMetasenv else [] in
513 let map_unicode_to_tex =
514 Helm_registry.get_bool "matita.paste_unicode_as_tex" in
515 ApplyTransformation.txt_of_cic_sequent_conclusion ~map_unicode_to_tex
516 ~output_type text_width metasenv cic_sequent
518 method private pattern_of term father_hyp unsh_sequent =
519 let _, unsh_context, conclusion = unsh_sequent in
521 match father_hyp with
527 | Some (Cic.Name name', Cic.Decl ty)::_ when name' = name -> ty
528 | Some (Cic.Name name', Cic.Def (bo,_))::_ when name' = name-> bo
533 ProofEngineHelpers.pattern_of ~term:where [term]
535 method private get_cic_info id =
536 match self#cic_info with
537 | Some ((Some unsh_sequent, _, _, _, _, _) as info) -> info, unsh_sequent
538 | Some ((None, _, _, _, _, _) as info) ->
539 let t = self#find_obj_conclusion id in
540 info, (~-1, [], t) (* dummy sequent for obj *)
541 | None -> assert false
543 method private sequent_of_id ~(paste_kind:paste_kind) id =
544 let cic_info, unsh_sequent = self#get_cic_info id in
546 match self#get_term_by_id cic_info id with
547 | SelTerm (t, father_hyp) ->
549 IDIOTA: PRIMA SI FA LA LOCATE, POI LA PATTERN_OF. MEGLIO UN'UNICA pattern_of CHE PRENDA IN INPUT UN TERMINE E UN SEQUENTE. PER IL MOMENTO RISOLVO USANDO LA father_hyp PER RITROVARE L'IPOTESI PERDUTA
552 ProofEngineHelpers.locate_in_conjecture t unsh_sequent in
553 (match occurrences with
555 (match paste_kind with
556 | `Term -> ~-1, context, t
557 | `Pattern -> ~-1, [], self#pattern_of t father_hyp unsh_sequent)
559 HLog.error (sprintf "found %d occurrences while 1 was expected"
560 (List.length occurrences));
561 assert false) (* since it uses physical equality *)
562 | SelHyp (_name, context) -> ~-1, context, Cic.Rel 1 in
565 method private string_of_selection ~(paste_kind:paste_kind) =
566 match self#get_selections with
568 | node :: _ -> Some (self#string_of_node ~paste_kind node)
570 (** @return an associative list format -> string with all possible selection
571 * formats. Rationale: in order to convert the selection to TERM or PATTERN
572 * format we need the sequent, the metasenv, ... keeping all of them in a
573 * closure would be more expensive than keeping their already converted
575 method strings_of_selection =
577 let misc = self#coerce#misc in
579 (fun target -> misc#add_selection_target ~target Gdk.Atom.clipboard)
580 [ "TERM"; "PATTERN"; "STRING" ];
581 ignore (misc#grab_selection Gdk.Atom.clipboard);
584 paste_kind, HExtlib.unopt (self#string_of_selection ~paste_kind))
586 with Failure _ -> failwith "no selection"
590 class _cicMathView obj =
592 inherit clickableMathView obj
594 val mutable current_mathml = None
596 method nload_sequent:
597 'status. #ApplyTransformation.status as 'status -> NCic.metasenv ->
598 NCic.substitution -> int -> unit
599 = fun status metasenv subst metano ->
600 let sequent = List.assoc metano metasenv in
602 ApplyTransformation.ntxt_of_cic_sequent
603 ~map_unicode_to_tex:false 80 status metasenv subst (metano,sequent)
605 (* MATITA 1.0 if BuildTimeConf.debug then begin
607 "/tmp/sequent_viewer_" ^ string_of_int (Unix.getuid ()) ^ ".xml" in
608 HLog.debug ("load_sequent: dumping MathML to ./" ^ name);
609 ignore (domImpl#saveDocumentToFile ~name ~doc:mathml ())
611 self#load_root ~root:txt
613 method load_nobject :
614 'status. #ApplyTransformation.status as 'status -> NCic.obj -> unit
616 let txt = ApplyTransformation.ntxt_of_cic_object ~map_unicode_to_tex:false
620 (Some (None, ids_to_terms, ids_to_hypotheses, ids_to_father_ids, ids_to_inner_types, Some annobj));
621 (match current_mathml with
622 | Some current_mathml when use_diff ->
624 XmlDiff.update_dom ~from:current_mathml mathml;
628 (* MATITA1.0 if BuildTimeConf.debug then begin
630 "/tmp/cic_browser_" ^ string_of_int (Unix.getuid ()) ^ ".xml" in
631 HLog.debug ("cic_browser: dumping MathML to ./" ^ name);
632 ignore (domImpl#saveDocumentToFile ~name ~doc:mathml ())
634 self#load_root ~root:txt;
635 (*current_mathml <- Some mathml*)(*)*);
640 let cicMathView (*?auto_indent ?highlight_current_line ?indent_on_tab ?indent_width ?insert_spaces_instead_of_tabs ?right_margin_position ?show_line_marks ?show_line_numbers ?show_right_margin ?smart_home_end ?tab_width ?editable ?cursor_visible ?justification ?wrap_mode ?accepts_tab ?border_width*) ?width ?height ?packing ?show () =
641 ((*SourceView.make_params [] ~cont:(
642 GtkText.View.make_params ~cont:( *)
643 GContainer.pack_container ~create:(fun pl ->
644 let obj = SourceView.new_ () in
645 Gobject.set_params (Gobject.try_cast obj "GtkSourceView") pl;
646 new _cicMathView obj)(*)) ?auto_indent ?highlight_current_line ?indent_on_tab ?indent_width ?insert_spaces_instead_of_tabs ?right_margin_position ?show_line_marks ?show_line_numbers ?show_right_margin ?smart_home_end ?tab_width ?editable ?cursor_visible ?justification ?wrap_mode ?accepts_tab ?border_width*) [] ?width ?height ?packing ?show () :> cicMathView)
648 let screenshot status sequents metasenv subst (filename as ofn) =
650 let w = GWindow.window ~title:"screenshot" () in
653 let m = GMathView.math_view
654 ~font_size:(MatitaMisc.get_current_font_size ()) ~width ~height
661 (fun (mno,_ as sequent) i ->
663 ApplyTransformation.nmml_of_cic_sequent
664 status metasenv subst sequent
666 m#load_root ~root:mathml#get_documentElement;
667 let pixmap = m#get_buffer in
668 let pixbuf = GdkPixbuf.create ~width ~height () in
669 GdkPixbuf.get_from_drawable ~dest:pixbuf pixmap;
671 filename ^ "-raw" ^ string_of_int i ^ ".png"
673 GdkPixbuf.save ~filename ~typ:"png" pixbuf;
678 List.map (fun (x,mno) ->
682 " '(' -gravity west -bordercolor grey -border 1 label:%d ')' "^^
683 " '(' -trim -bordercolor white -border 5 "^^
684 " -bordercolor grey -border 1 %s ')' -append %s ")
687 (Filename.quote (x ^ ".label.png"))));
691 let rec div2 = function
694 | x::y::tl -> [x;y] :: div2 tl
696 let items = div2 items in
697 ignore(Sys.command (Printf.sprintf
698 "convert %s -append %s"
700 (List.map (fun items ->
701 Printf.sprintf " '(' %s +append ')' "
703 (" '(' -gravity center -size 10x10 xc: ')' ") items)) items))
704 (Filename.quote (ofn ^ ".png"))));
705 List.iter (fun x,_ -> Sys.remove x) filenames;
706 List.iter Sys.remove (List.flatten items);