devel
| Line | |
|---|
| 1 | package require base64 |
|---|
| 2 | |
|---|
| 3 | namespace eval mimetex { |
|---|
| 4 | variable cache |
|---|
| 5 | variable bin "" |
|---|
| 6 | variable defaultBin |
|---|
| 7 | |
|---|
| 8 | array set cache {} |
|---|
| 9 | |
|---|
| 10 | array set defaultBin { |
|---|
| 11 | Linux,4 linux32/mimetex |
|---|
| 12 | Linux,8 linux32/mimetex |
|---|
| 13 | Windows\ NT,4 win32/mimetex.exe |
|---|
| 14 | Windows\ NT,8 win32/mimetex.exe |
|---|
| 15 | } |
|---|
| 16 | |
|---|
| 17 | proc SetBinPath { path } { |
|---|
| 18 | variable bin $path |
|---|
| 19 | } |
|---|
| 20 | |
|---|
| 21 | proc RenderImage { latex { name "" } } { |
|---|
| 22 | variable cache |
|---|
| 23 | variable bin |
|---|
| 24 | |
|---|
| 25 | puts "RenderImage $latex" |
|---|
| 26 | if { [ info exists cache($latex) ] } { |
|---|
| 27 | return $cache($latex) |
|---|
| 28 | } |
|---|
| 29 | if { [ file executable $bin ] } { |
|---|
| 30 | set p [open [list |$bin -d $latex] r] |
|---|
| 31 | fconfigure $p -translation binary -encoding binary |
|---|
| 32 | set rawData [base64::encode [read $p]] |
|---|
| 33 | close $p |
|---|
| 34 | if { $name eq "" } { |
|---|
| 35 | set cache($latex) [ image create photo -data $rawData ] |
|---|
| 36 | } else { |
|---|
| 37 | set cache($latex) [ image create photo $name -data $rawData ] |
|---|
| 38 | } |
|---|
| 39 | return $cache($latex) |
|---|
| 40 | } else { |
|---|
| 41 | error "could not execute mimetex, $bin is not executable" |
|---|
| 42 | } |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | set os $::tcl_platform(os) |
|---|
| 47 | set wordSize $::tcl_platform(wordSize) |
|---|
| 48 | if { [ info exists defaultBin($os,$wordSize) ] } { |
|---|
| 49 | set _cwd [ file normalize [ file dir [ info script ] ] ] |
|---|
| 50 | SetBinPath [ file join $_cwd $defaultBin($os,$wordSize) ] |
|---|
| 51 | } else { |
|---|
| 52 | puts "There is no default mimetex.cgi for os = $os and wordSize = $wordSize. You should set it up with SetBinPath" |
|---|
| 53 | } |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | package provide mimetex 1.0 |
|---|
Note: See
TracBrowser
for help on using the repository browser.