Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file gentex.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179(**************************************************************************)(* *)(* Copyright (C) Johannes Kanig, Stephane Lescuyer *)(* Jean-Christophe Filliatre, Romain Bardou and Francois Bobot *)(* *)(* This software is free software; you can redistribute it and/or *)(* modify it under the terms of the GNU Library General Public *)(* License version 2.1, with the special exception on linking *)(* described in file LICENSE. *)(* *)(* This software is distributed in the hope that it will be useful, *)(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *)(* *)(**************************************************************************)openPoint_libletjobname="gentex"letfilename=File.from_stringjobname(* FIXME different from Metapost.default_prelude? *)letlatex_cmdtmpdir=Printf.sprintf"latex -jobname=%s -ipc -halt-on-error -output-dir '%s'"jobname(File.Dir.to_stringtmpdir)(* Printf.sprintf "cat" *)typet={tex:Dviinterp.page;trans:Matrix.t;bb:float*float*float*float;}letset_verbosity_=()typeproc={outc:in_channel;inc:out_channel;errc:in_channel}typecomm={latex:proc;dvi:Dvi.Incremental.t;tmpdir:File.Dir.t}letends_withens=letl=String.lengthsinletk=String.lengtheninifk<=lthentryfori=0tok-1doifs.[l-i-1]<>en.[k-i-1]thenraiseExitdone;truewithExit->falseelsefalseletread_up_to_one=(* FIXME deal with EOF exception:
Actually that print on stdout and that throw the error.
Perhaps can we throw an exception with all in it.
But it is not very fun for user (only part of the string in an exception
is printed)
*)letend_="[1]"inletrecauxbufinc=lets=tryinput_lineincwithEnd_of_file->Buffer.output_bufferstdoutbuf;invalid_arg"One tex snippet contains an error"inBuffer.add_stringbufs;Buffer.add_charbuf'\n';ifends_withend_sthen()elseauxbufincinfuninc->letbuf=Buffer.create10inauxbufincletread_up_to_onep=read_up_to_onep.outcletmk_proc_latextmpdir=letoutc,inc,errc=Unix.open_process_full(latex_cmdtmpdir)(Unix.environment())in{outc;inc;errc}letwrite_to_procps=Printf.fprintfp.incsletpush_preludepprel=(* the shipout macro from metapost, that adds a vrule at the end of the tex
* to obtain easily the size of the dvi *)write_to_procp"%s\n\
\\begin{document}\n\
\\gdef\\mpxshipout{\\shipout\\hbox\\bgroup%%\n\
\ \\setbox0=\\hbox\\bgroup}%%\n\
\\gdef\\stopmpxshipout{\\egroup \\dimen0=\\ht0 \\advance\\dimen0\\dp0\n\
\ \\dimen1=\\ht0 \\dimen2=\\dp0\n\
\ \\setbox0=\\hbox\\bgroup\n\
\ \\box0\n\
\ \\ifnum\\dimen0>0 \\vrule width1sp height\\dimen1 depth\\dimen2\n\
\ \\else \\vrule width1sp height1sp depth0sp\\relax\n\
\ \\fi\\egroup\n\
\ \\ht0=0pt \\dp0=0pt \\box0 \\egroup}\n\
%!"prelletshipout_and_flushps=write_to_procp"\\mpxshipout %s\\stopmpxshipout\n%!"sletextractcl=(* the vrule added by the metapost shipout macro is exploited and removed *)matchclwith|Dviinterp.Fill_rect(_,x,y,_,h)::cl->letbb=(0.,-.(y+.h),x,-.y)in{tex=cl;trans=Matrix.identity;bb}|_->assertfalseletcomm=refNone(* TODO : do that only when clean is requested.
note if an error occured comm become None
*)let()=at_exit(fun()->match!commwithNone->()|Somep->File.Dir.rmp.tmpdir)letread_up_to_onep=tryread_up_to_onepwithe->comm:=None;raiseeletcreatetex=(* FIXME at some point we have to close the latex process *)match!commwith|None->lettmpdir=Metapost_tool.create_temp_dir"mlpost"""inletp=mk_proc_latextmpdirinpush_preludep(Defaults.get_prelude());shipout_and_flushptex;read_up_to_onep;letfilename=File.placetmpdir(File.set_extfilename"dvi")inletdvi_chan=File.open_infilenameinlett,pgs=Dvi.Incremental.mk_tdvi_chanincomm:=Some{latex=p;dvi=t;tmpdir};extract(Dviinterp.Incremental.load_paget(List.hdpgs))|Somep->shipout_and_flushp.latextex;read_up_to_onep.latex;letpgs=Dvi.Incremental.next_pagesp.dviinextract(Dviinterp.Incremental.load_pagep.dvi(List.hdpgs))letpoint_of_cmcm=0.3937*.72.*.cmletget_dimen_cmx=x.bb(** donne la dimension en centimètre *)letget_dimen_ptx=letx_min,y_min,x_max,y_max=get_dimen_cmxin(point_of_cmx_min,point_of_cmy_min,point_of_cmx_max,point_of_cmy_max)letget_bases_cm_=assertfalseletget_bases_pt_=assertfalseletbounding_boxx=letxmin,ymin,xmax,ymax=get_dimen_ptxinifDefaults.get_debug()thenFormat.printf"gentex bb : %f %f %f %f@."xminyminxmaxymax;({x=xmin;y=ymin},{x=xmax;y=ymax})letprintfmttex=letmin,max=bounding_boxtexinFormat.fprintffmt"[%a,%a]"printminprintmaxletdeb_printfmttex=Format.fprintffmt"{ tex: %a ; matrix: %a }"Dviinterp.Print.pagetex.texMatrix.printtex.trans