Skip to content

Commit

Permalink
add compat save_image for Plots
Browse files Browse the repository at this point in the history
  • Loading branch information
t-bltg committed Feb 8, 2023
1 parent b12e041 commit e8c7928
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
7 changes: 6 additions & 1 deletion ext/FreeTypeExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,11 @@ function UnicodePlots.get_font_face(font = nothing, fallback = fallback_fonts())
face
end

UnicodePlots.save_image(args...; kw...) = FileIO.save(args...; kw...)
UnicodePlots.save_image(fn::AbstractString, args...; kw...) =
FileIO.save(fn, args...; kw...)

# compat for Plots
UnicodePlots.save_image(io::IO, args...; kw...) =
FileIO.save(FileIO.Stream{FileIO.format"PNG"}(io), args...; kw...)

end # module
10 changes: 10 additions & 0 deletions test/tst_io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ end

@test_throws ArgumentError savefig(p, tempname() * ".jpg")
end

# for Plots
if font_found
p = lineplot(1:2)
tmp = tempname() * ".png"
open(tmp, "w") do io
UnicodePlots.save_image(io, UnicodePlots.png_image(p))
end
@test filesize(tmp) > 1_000
end
end

@testset "stringify plot - performance regression" begin
Expand Down

0 comments on commit e8c7928

Please sign in to comment.