gr: improve PNG output (resolution)
This commit is contained in:
parent
61be113714
commit
5be95be9ae
@ -543,7 +543,7 @@ function gr_set_gradient(c)
|
|||||||
end
|
end
|
||||||
|
|
||||||
# this is our new display func... set up the viewport_canvas, compute bounding boxes, and display each subplot
|
# this is our new display func... set up the viewport_canvas, compute bounding boxes, and display each subplot
|
||||||
function gr_display(plt::Plot)
|
function gr_display(plt::Plot, fmt="")
|
||||||
GR.clearws()
|
GR.clearws()
|
||||||
|
|
||||||
# collect some monitor/display sizes in meters and pixels
|
# collect some monitor/display sizes in meters and pixels
|
||||||
@ -554,17 +554,25 @@ function gr_display(plt::Plot)
|
|||||||
# compute the viewport_canvas, normalized to the larger dimension
|
# compute the viewport_canvas, normalized to the larger dimension
|
||||||
viewport_canvas = Float64[0,1,0,1]
|
viewport_canvas = Float64[0,1,0,1]
|
||||||
w, h = plt[:size]
|
w, h = plt[:size]
|
||||||
|
if !haskey(ENV, "PLOTS_TEST")
|
||||||
|
dpi_factor = plt[:dpi] / DPI
|
||||||
|
if fmt == "png"
|
||||||
|
dpi_factor *= 6
|
||||||
|
end
|
||||||
|
else
|
||||||
|
dpi_factor = 1
|
||||||
|
end
|
||||||
gr_plot_size[:] = [w, h]
|
gr_plot_size[:] = [w, h]
|
||||||
if w > h
|
if w > h
|
||||||
ratio = float(h) / w
|
ratio = float(h) / w
|
||||||
msize = display_width_ratio * w
|
msize = display_width_ratio * w * dpi_factor
|
||||||
GR.setwsviewport(0, msize, 0, msize * ratio)
|
GR.setwsviewport(0, msize, 0, msize * ratio)
|
||||||
GR.setwswindow(0, 1, 0, ratio)
|
GR.setwswindow(0, 1, 0, ratio)
|
||||||
viewport_canvas[3] *= ratio
|
viewport_canvas[3] *= ratio
|
||||||
viewport_canvas[4] *= ratio
|
viewport_canvas[4] *= ratio
|
||||||
else
|
else
|
||||||
ratio = float(w) / h
|
ratio = float(w) / h
|
||||||
msize = display_height_ratio * h
|
msize = display_height_ratio * h * dpi_factor
|
||||||
GR.setwsviewport(0, msize * ratio, 0, msize)
|
GR.setwsviewport(0, msize * ratio, 0, msize)
|
||||||
GR.setwswindow(0, ratio, 0, 1)
|
GR.setwswindow(0, ratio, 0, 1)
|
||||||
viewport_canvas[1] *= ratio
|
viewport_canvas[1] *= ratio
|
||||||
@ -1335,7 +1343,7 @@ for (mime, fmt) in _gr_mimeformats
|
|||||||
env = get(ENV, "GKSwstype", "0")
|
env = get(ENV, "GKSwstype", "0")
|
||||||
ENV["GKSwstype"] = $fmt
|
ENV["GKSwstype"] = $fmt
|
||||||
ENV["GKS_FILEPATH"] = filepath
|
ENV["GKS_FILEPATH"] = filepath
|
||||||
gr_display(plt)
|
gr_display(plt, $fmt)
|
||||||
GR.emergencyclosegks()
|
GR.emergencyclosegks()
|
||||||
write(io, readstring(filepath))
|
write(io, readstring(filepath))
|
||||||
rm(filepath)
|
rm(filepath)
|
||||||
|
|||||||
@ -8,6 +8,7 @@ default(show=false, reuse=true)
|
|||||||
img_eps = isinteractive() ? 1e-2 : 10e-2
|
img_eps = isinteractive() ? 1e-2 : 10e-2
|
||||||
|
|
||||||
@testset "GR" begin
|
@testset "GR" begin
|
||||||
|
ENV["PLOTS_TEST"] = "true"
|
||||||
ENV["GKSwstype"] = "100"
|
ENV["GKSwstype"] = "100"
|
||||||
@test gr() == Plots.GRBackend()
|
@test gr() == Plots.GRBackend()
|
||||||
@test backend() == Plots.GRBackend()
|
@test backend() == Plots.GRBackend()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user