Permalink
Browse files

winston: add .eps support

  • Loading branch information...
1 parent f6b9fbf commit 8136d14e747af20e02516fd2393287bb7e0b4c37 @nolta nolta committed Mar 18, 2012
Showing with 43 additions and 19 deletions.
  1. +22 −0 extras/cairo.jl
  2. +5 −7 extras/winston.ini
  3. +16 −12 extras/winston.jl
View
@@ -59,6 +59,17 @@ function CairoPDFSurface(filename::String, w_pts::Real, h_pts::Real)
surface
end
+function CairoEPSSurface(filename::String, w_pts::Real, h_pts::Real)
+ ptr = ccall(dlsym(_jl_libcairo,:cairo_ps_surface_create), Ptr{Void},
+ (Ptr{Uint8},Float64,Float64), cstring(filename), w_pts, h_pts)
+ ccall(dlsym(_jl_libcairo,:cairo_ps_surface_set_eps), Void,
+ (Ptr{Void},Int32), ptr, 1)
+ surface = CairoSurface(ptr, :eps)
+ surface.width = w_pts
+ surface.height = h_pts
+ surface
+end
+
function write_to_png(surface::CairoSurface, filename::String)
ccall(dlsym(_jl_libcairo,:cairo_surface_write_to_png), Void,
(Ptr{Uint8},Ptr{Uint8}), surface.ptr, cstring(filename))
@@ -351,6 +362,17 @@ function PDFRenderer(filename::String, w_pts::Float64, h_pts::Float64)
r
end
+EPSRenderer(filename::String, w_str::String, h_str::String) =
+ EPSRenderer(filename, _str_size_to_pts(w_str), _str_size_to_pts(h_str))
+
+function EPSRenderer(filename::String, w_pts::Float64, h_pts::Float64)
+ surface = CairoEPSSurface(filename, w_pts, h_pts)
+ r = CairoRenderer(surface)
+ r.upperright = (w_pts,h_pts)
+ r.on_close = () -> show_page(r.ctx)
+ r
+end
+
function open( self::CairoRenderer )
self.state = RendererState()
end
View
@@ -17,14 +17,12 @@ width = 512
height = 512
reuse = true
-[postscript]
-
-; paper size name; accepts ISO sizes ("a0",..,"a4"),
-; ANSI sizes ("a",..,"e"), "letter", "ledger", "tabloid",
-; and "b5".
-paper = letter
+[eps]
+; valid units are in,pt,cm,mm
+width = "7.5in"
+height = "7.5in"
-; size of output region on the page
+[pdf]
; valid units are in,pt,cm,mm
width = "7.5in"
height = "7.5in"
View
@@ -2472,15 +2472,13 @@ function x11( self::PlotContainer, args...)
page_compose( self, device )
end
-function write_pdf( self::PlotContainer, filename::String, args... )
- opt = HashTable()
- for (k,v) in config_options("postscript")
- opt[k] = v
- end
- for (k,v) in args2hashtable(args...)
- opt[k] = v
- end
- device = PDFRenderer( filename, opt["width"], opt["height"] )
+function write_eps( self::PlotContainer, filename::String, width, height )
+ device = EPSRenderer( filename, width, height )
+ page_compose( self, device )
+end
+
+function write_pdf( self::PlotContainer, filename::String, width, height )
+ device = PDFRenderer( filename, width, height )
page_compose( self, device )
end
@@ -2491,10 +2489,16 @@ end
function file( self::PlotContainer, filename::String, args... )
extn = filename[end-2:end]
- if extn == "pdf"
- write_pdf(self, filename, args...)
+ opts = args2hashtable(args...)
+ if extn == "eps"
+ width = has(opts,"width") ? opts["width"] : config_value("eps","width")
+ height = has(opts,"height") ? opts["height"] : config_value("eps","height")
+ write_eps(self, filename, width, height)
+ elseif extn == "pdf"
+ width = has(opts,"width") ? opts["width"] : config_value("pdf","width")
+ height = has(opts,"height") ? opts["height"] : config_value("pdf","height")
+ write_pdf(self, filename, width, height)
elseif extn == "png"
- opts = args2hashtable(args...)
width = has(opts,"width") ? opts["width"] : config_value("window","width")
height = has(opts,"height") ? opts["height"] : config_value("window","height")
write_png(self, filename, width, height)

0 comments on commit 8136d14

Please sign in to comment.