Skip to content

Commit

Permalink
initial fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
t-bltg committed Dec 24, 2022
1 parent d3c5b18 commit fcf0d0d
Show file tree
Hide file tree
Showing 216 changed files with 11,899 additions and 9,889 deletions.
4 changes: 1 addition & 3 deletions CairoMakie/src/CairoMakie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ include("utils.jl")
include("primitives.jl")
include("overrides.jl")

function __init__()
activate!()
end
__init__() = activate!()

include("precompiles.jl")

Expand Down
57 changes: 37 additions & 20 deletions CairoMakie/src/cairo-extension.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
# TODO, move those to Cairo?

function set_font_matrix(ctx, matrix)
ccall((:cairo_set_font_matrix, Cairo.libcairo), Cvoid, (Ptr{Cvoid}, Ptr{Cvoid}), ctx.ptr, Ref(matrix))
return ccall(
(:cairo_set_font_matrix, Cairo.libcairo),
Cvoid,
(Ptr{Cvoid}, Ptr{Cvoid}),
ctx.ptr,
Ref(matrix),
)
end

function get_font_matrix(ctx)
Expand All @@ -11,19 +17,16 @@ function get_font_matrix(ctx)
end

function cairo_font_face_destroy(font_face)
ccall(
(:cairo_font_face_destroy, Cairo.libcairo),
Cvoid, (Ptr{Cvoid},),
font_face
)
return ccall((:cairo_font_face_destroy, Cairo.libcairo), Cvoid, (Ptr{Cvoid},), font_face)
end

function set_ft_font(ctx, font)

font_face = ccall(
(:cairo_ft_font_face_create_for_ft_face, Cairo.libcairo),
Ptr{Cvoid}, (Makie.FreeTypeAbstraction.FT_Face, Cint),
font, 0
Ptr{Cvoid},
(Makie.FreeTypeAbstraction.FT_Face, Cint),
font,
0,
)

ccall((:cairo_set_font_face, Cairo.libcairo), Cvoid, (Ptr{Cvoid}, Ptr{Cvoid}), ctx.ptr, font_face)
Expand All @@ -39,30 +42,44 @@ end

function show_glyph(ctx, glyph, x, y)
cg = Ref(CairoGlyph(glyph, x, y))
ccall((:cairo_show_glyphs, Cairo.libcairo),
Nothing, (Ptr{Nothing}, Ptr{CairoGlyph}, Cint),
ctx.ptr, cg, 1)
return ccall(
(:cairo_show_glyphs, Cairo.libcairo),
Nothing,
(Ptr{Nothing}, Ptr{CairoGlyph}, Cint),
ctx.ptr,
cg,
1,
)
end

function glyph_path(ctx, glyph, x, y)
cg = Ref(CairoGlyph(glyph, x, y))
ccall((:cairo_glyph_path, Cairo.libcairo),
Nothing, (Ptr{Nothing}, Ptr{CairoGlyph}, Cint),
ctx.ptr, cg, 1)
return ccall(
(:cairo_glyph_path, Cairo.libcairo),
Nothing,
(Ptr{Nothing}, Ptr{CairoGlyph}, Cint),
ctx.ptr,
cg,
1,
)
end

function surface_set_device_scale(surf, device_x_scale, device_y_scale=device_x_scale)
# this sets a scaling factor on the lowest level that is "hidden" so its even
# enabled when the drawing space is reset for strokes
# that means it can be used to increase or decrease the image resolution
ccall(
return ccall(
(:cairo_surface_set_device_scale, Cairo.libcairo),
Cvoid, (Ptr{Nothing}, Cdouble, Cdouble),
surf.ptr, device_x_scale, device_y_scale)
Cvoid,
(Ptr{Nothing}, Cdouble, Cdouble),
surf.ptr,
device_x_scale,
device_y_scale,
)
end

function set_miter_limit(ctx, limit)
ccall((:cairo_set_miter_limit, Cairo.libcairo), Cvoid, (Ptr{Nothing}, Cdouble), ctx.ptr, limit)
return ccall((:cairo_set_miter_limit, Cairo.libcairo), Cvoid, (Ptr{Nothing}, Cdouble), ctx.ptr, limit)
end

function get_render_type(surface::Cairo.CairoSurface)
Expand All @@ -71,5 +88,5 @@ function get_render_type(surface::Cairo.CairoSurface)
typ == Cairo.CAIRO_SURFACE_TYPE_PS && return EPS
typ == Cairo.CAIRO_SURFACE_TYPE_SVG && return SVG
typ == Cairo.CAIRO_SURFACE_TYPE_IMAGE && return IMAGE
error("Unsupported surface type: $(typ)")
return error("Unsupported surface type: $(typ)")
end
22 changes: 8 additions & 14 deletions CairoMakie/src/display.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
Try to run a command. Return `true` if `cmd` runs and is successful (exits with a code of `0`).
Return `false` otherwise.
"""
function tryrun(cmd::Cmd)
tryrun(cmd::Cmd) =
try
return success(cmd)
catch e
return false
end
end

function openurl(url::String)
if Sys.isapple()
Expand Down Expand Up @@ -63,7 +62,7 @@ function Makie.backend_show(screen::Screen{SVG}, io::IO, ::MIME"image/svg+xml",
screen2 = Screen(screen, io2, SVG)
cairo_draw(screen2, scene)
Cairo.flush(screen2.surface)
Cairo.finish(screen2.surface)
return Cairo.finish(screen2.surface)
end

# for some reason, in the svg, surfaceXXX ids keep counting up,
Expand Down Expand Up @@ -116,14 +115,9 @@ end
# Disabling mimes and showable

const DISABLED_MIMES = Set{String}()
const SUPPORTED_MIMES = Set([
"image/svg+xml",
"application/pdf",
"application/postscript",
"image/png"
])

function Makie.backend_showable(::Type{Screen}, ::MIME{SYM}) where SYM
const SUPPORTED_MIMES = Set(["image/svg+xml", "application/pdf", "application/postscript", "image/png"])

function Makie.backend_showable(::Type{Screen}, ::MIME{SYM}) where {SYM}
supported_mimes = Base.setdiff(SUPPORTED_MIMES, DISABLED_MIMES)
return string(SYM) in supported_mimes
end
Expand All @@ -133,7 +127,7 @@ end
Converts anything like `"png", :png, "image/png", MIME"image/png"()` to `"image/png"`.
"""
function to_mime_string(mime::Union{String, Symbol, MIME})
function to_mime_string(mime::Union{String,Symbol,MIME})
if mime isa MIME
mime_str = string(mime)
if !(mime_str in SUPPORTED_MIMES)
Expand All @@ -156,7 +150,7 @@ The default is automatic, which lets the display system figure out the best mime
If set to any other valid mime, will result in `showable(any_other_mime, figurelike)` to return false and only return true for `showable(preferred_mime, figurelike)`.
Depending on the display system used, this may result in nothing getting displayed.
"""
function disable_mime!(mimes::Union{String, Symbol, MIME}...)
function disable_mime!(mimes::Union{String,Symbol,MIME}...)
empty!(DISABLED_MIMES) # always start from 0
if isempty(mimes)
# Reset disabled mimes when called with no arguments
Expand All @@ -170,7 +164,7 @@ function disable_mime!(mimes::Union{String, Symbol, MIME}...)
return
end

function enable_only_mime!(mimes::Union{String, Symbol, MIME}...)
function enable_only_mime!(mimes::Union{String,Symbol,MIME}...)
empty!(DISABLED_MIMES) # always start from 0
if isempty(mimes)
# Reset disabled mimes when called with no arguments
Expand Down
16 changes: 7 additions & 9 deletions CairoMakie/src/infrastructure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ function cairo_draw(screen::Screen, scene::Scene)
return
end

function get_all_plots(scene, plots = AbstractPlot[])
function get_all_plots(scene, plots=AbstractPlot[])
append!(plots, scene.plots)
for c in scene.children
get_all_plots(c, plots)
end
plots
return plots
end

function prepare_for_scene(screen::Screen, scene::Scene)
Expand Down Expand Up @@ -90,13 +90,13 @@ function draw_background(screen::Screen, scene::Scene)
Cairo.save(cr)
if scene.clear[]
bg = scene.backgroundcolor[]
Cairo.set_source_rgba(cr, red(bg), green(bg), blue(bg), alpha(bg));
Cairo.set_source_rgba(cr, red(bg), green(bg), blue(bg), alpha(bg))
r = pixelarea(scene)[]
Cairo.rectangle(cr, origin(r)..., widths(r)...) # background
fill(cr)
end
Cairo.restore(cr)
foreach(child_scene-> draw_background(screen, child_scene), scene.children)
return foreach(child_scene -> draw_background(screen, child_scene), scene.children)
end

function draw_plot(scene::Scene, screen::Screen, primitive::Combined)
Expand All @@ -120,14 +120,14 @@ end
# instead of the whole Scene
# - Recognize when a screen is an image surface, and set scale to render the plot
# at the scale of the device pixel
function draw_plot_as_image(scene::Scene, screen::Screen, primitive::Combined, scale::Number = 1)
function draw_plot_as_image(scene::Scene, screen::Screen, primitive::Combined, scale::Number=1)
# you can provide `p.rasterize = scale::Int` or `p.rasterize = true`, both of which are numbers

# Extract scene width in pixels
w, h = Int.(scene.px_area[].widths)
# Create a new Screen which renders directly to an image surface,
# specifically for the plot's parent scene.
scr = Screen(scene; px_per_unit = scale)
scr = Screen(scene; px_per_unit=scale)
# Draw the plot to the screen, in the normal way
draw_plot(scene, scr, primitive)

Expand All @@ -150,6 +150,4 @@ function draw_plot_as_image(scene::Scene, screen::Screen, primitive::Combined, s
return
end

function draw_atomic(::Scene, ::Screen, x)
@warn "$(typeof(x)) is not supported by cairo right now"
end
draw_atomic(::Scene, ::Screen, x) = @warn "$(typeof(x)) is not supported by cairo right now"
Loading

0 comments on commit fcf0d0d

Please sign in to comment.