0
require Webby.libpath(*%w[webby stelan mktemp])
0
@@ -36,8 +35,6 @@ module TexImgHelper
0
# TeX color spec, or #aabbcc) [default is black]
0
# :resolution : the desired resolution in dpi (HxV)
0
- # :antialias : if false, disables anti-aliasing in the resulting image
0
# the following options are passed as-is to the generated <img /> tag
0
# :style : CSS styles to apply to the <img />
0
@@ -60,21 +57,15 @@ module TexImgHelper
0
- # create a temporary file for holding any error messages
0
- # from the graphviz program
0
- err = Tempfile.new('graphviz_err')
0
+ path = opts.getopt(:path)
0
+ type = opts.getopt(:type, 'png')
0
+ bg = opts.getopt(:bg, 'white')
0
+ fg = opts.getopt(:fg, 'black')
0
+ res = opts.getopt(:resolution, '150x150')
0
- path = opts.getopt(:path)
0
- type = opts.getopt(:type, 'png')
0
- bg = opts.getopt(:bg, 'white')
0
- fg = opts.getopt(:fg, 'black')
0
- res = opts.getopt(:resolution, '150x150')
0
- aa = opts.getopt(:antialias, true)
0
- # fix the color escaping
0
- fg = TexImgHelper.tex_color(fg)
0
- bg = TexImgHelper.tex_color(bg)
0
+ fg = fg =~ %r/^[a-zA-Z]+$/ ? fg : "\"#{fg}\""
0
+ bg = bg =~ %r/^[a-zA-Z]+$/ ? bg : "\"#{bg}\""
0
# generate the image filename based on the path, graph name, and type
0
@@ -88,15 +79,21 @@ module TexImgHelper
0
FileUtils.mkpath(::File.join(out_dir, path)) unless path.nil?
0
- \\documentclass[12pt]{article}
0
- \\usepackage[usenames,dvipsnames]{color}
0
- \\usepackage[dvips]{graphicx}
0
+ \\documentclass{article}
0
+ \\usepackage[T1]{fontenc}
0
+ \\usepackage{amsmath,amsfonts,amssymb,wasysym,latexsym,marvosym,txfonts}
0
+ \\usepackage[pdftex]{color}
0
tex.gsub!(%r/\n\s+/, "\n").strip!
0
@@ -109,9 +106,14 @@ module TexImgHelper
0
File.open('out.tex', 'w') {|fd| fd.puts tex}
0
dev_null = test(?e, "/dev/null") ? "/dev/null" : "NUL:"
0
- %x[latex -interaction=batchmode out.tex &> #{dev_null}]
0
- %x[dvips -o out.eps -E out.dvi &> #{dev_null}]
0
- %x[convert +adjoin #{aa ? '-antialias' : '+antialias'} -density #{res} out.eps #{out_file} &> #{dev_null}]
0
+ %x[pdflatex -interaction=batchmode out.tex &> #{dev_null}]
0
+ convert = "\\( -density #{res} out.pdf -trim +repage \\) "
0
+ convert << "\\( +clone -fuzz 100% -fill #{fg} -opaque black \\) "
0
+ convert << "+swap -compose copy-opacity -composite "
0
+ convert << "\\( +clone -fuzz 100% -fill #{bg} -opaque white +matte \\) "
0
+ convert << "+swap -compose over -composite #{out_file}"
0
+ %x[convert #{convert} &> #{dev_null}]
0
FileUtils.rm_rf(tmpdir) if test(?e, tmpdir)
0
@@ -133,42 +135,10 @@ module TexImgHelper
0
- # TexImgHelper.tex_color( string ) => string
0
- # Taken the given color _string_ and convert it to a TeX color spec. The
0
- # input string can be either a RGB Hex value, a TeX color spec, or a color
0
- # tex_color( '#666666' ) #=> [rgb]{0.4,0.4,0.4}
0
- # tex_color( 'Tan' ) #=> {Tan}
0
- # tex_color( '[rgb]{1,0,0}' ) #=> [rgb]{1,0,0}
0
- # This is an example of an invalid Hex RGB color -- they must contain six
0
- # hexidecimal characters to be valid.
0
- # tex_color( '#333' ) #=> {#333}
0
- def self.tex_color( color )
0
- when %r/^#([A-Fa-f0-9]{6})/o
0
- hex.scan(%r/../) {|n| rgb << Float(n.to_i(16))/255.0}
0
- "[rgb]{#{rgb.join(',')}}"
0
end # module TexImgHelper
0
-%x[
latex --version 2>&1]
0
+%x[
pdflatex --version 2>&1]
0
%x[convert --version 2>&1]
Comments
No one has commented yet.