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