123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125(**************************************************************************)(* Lablgtk *)(* *)(* This program is free software; you can redistribute it *)(* and/or modify it under the terms of the GNU Library General *)(* Public License as published by the Free Software Foundation *)(* version 2, with the exception described in file COPYING which *)(* comes with the library. *)(* *)(* This program 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. See the *)(* GNU Library General Public License for more details. *)(* *)(* You should have received a copy of the GNU Library General *)(* Public License along with this program; if not, write to the *)(* Free Software Foundation, Inc., 59 Temple Place, Suite 330, *)(* Boston, MA 02111-1307 USA *)(* *)(* *)(**************************************************************************)(* $Id$ *)typesize_fun=int->int->int*intletroundf=int_of_float(iff<0.thenf-.0.5elsef+.0.5)letat_sizerwrhwh=(ifrw<0thenwelserw),(ifrh<0thenhelserh)letat_zoomzxzywh=ifw<0||h<0then(w,h)else(round(floatw*.zx)),(round(floath*.zy))letat_max_sizemwmhwh=ifw<0||h<0then(w,h)elseletzx=floatmw/.floatwinletzy=floatmh/.floathinletz=minzxzyin(round(floatw*.z)),(round(floath*.z))letat_zoom_with_maxzxzymwmhwh=ifw<0||h<0then(w,h)elseletrw=round(floatw*.zx)inletrh=round(floath*.zy)inifrw>mw||rh>mhthenletzx=floatmw/.floatwinletzy=floatmh/.floathinletz=minzxzyin(round(floatw*.z)),(round(floath*.z))else(rw,rh)typeerror=FailedexceptionErroroferror*stringexternal_init:unit->unit="ml_rsvg_init"let_=Callback.register_exception"ml_rsvg_exn"(Error(Failed,""));_init()typetexternalnew_handle:unit->t="ml_rsvg_handle_new"externalset_size_callback:t->size_fun->unit="ml_rsvg_handle_set_size_callback"externalfree_handle:t->unit="ml_rsvg_handle_free"externalclose:t->unit="ml_rsvg_handle_close"externalwrite:t->string->off:int->len:int->unit="ml_rsvg_handle_write"externalget_pixbuf:t->GdkPixbuf.pixbuf="ml_rsvg_handle_get_pixbuf"externalset_dpi:t->float->unit="ml_rsvg_handle_set_dpi"externalset_default_dpi:float->unit="ml_rsvg_set_default_dpi"typeinput=|Rsvg_SubStringofstring*int*int|Rsvg_Bufferofint*(bytes->int)letrender?dpi?size_cbinput=leth=new_handle()inGaux.may(set_size_callbackh)size_cb;Gaux.may(set_dpih)dpi;trybeginmatchinputwith|Rsvg_SubString(s,off,len)->writehs~off~len|Rsvg_Buffer(len,fill)->letbuff=Bytes.createleninletc=ref(fillbuff)inwhile!c>0dowriteh(Bytes.unsafe_to_stringbuff)0!c;c:=fillbuffdoneend;closeh;letpb=get_pixbufhinfree_handleh;pbwithexn->free_handleh;raiseexnletrender_from_string?dpi?size_cb?pos?lens=letoff=Gaux.default0~opt:posinletlen=Gaux.default(String.lengths-off)~opt:leninrender?dpi?size_cb(Rsvg_SubString(s,off,len))letrender_from_file?dpi?size_cbfname=letic=open_infnameinletpb=tryrender?dpi?size_cb(Rsvg_Buffer(4096,(funb->inputicb0(Bytes.lengthb))))withexn->close_inic;raiseexninclose_inic;pb