Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply Runic formatting #4568

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/Check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
name: Check
on:
push:
branches:
- 'master'
- 'release-'
tags:
- '*'
pull_request:
jobs:
runic:
name: Runic formatting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
with:
version: '1'
- uses: julia-actions/cache@v2
- uses: fredrikekre/runic-action@v1
with:
version: '1.2'
4 changes: 2 additions & 2 deletions CairoMakie/src/CairoMakie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ using Makie: numbers_to_colors
using Makie: Mat3f, Mat4f, Mat3d, Mat4d

# re-export Makie, including deprecated names
for name in names(Makie, all=true)
for name in names(Makie, all = true)
if Base.isexported(Makie, name)
@eval using Makie: $(name)
@eval export $(name)
Expand All @@ -31,7 +31,7 @@ include("primitives.jl")
include("overrides.jl")

function __init__()
activate!()
return activate!()
end

include("precompiles.jl")
Expand Down
39 changes: 23 additions & 16 deletions CairoMakie/src/cairo-extension.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# 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,7 +11,7 @@ function get_font_matrix(ctx)
end

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

function pattern_get_matrix(ctx)
Expand All @@ -21,15 +21,15 @@ function pattern_get_matrix(ctx)
end

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

function cairo_transform(ctx, cairo_matrix)
ccall(
return ccall(
(:cairo_transform, Cairo.libcairo),
Cvoid, (Ptr{Cvoid}, Ptr{Cvoid}),
ctx.ptr, Ref(cairo_matrix)
Expand Down Expand Up @@ -57,30 +57,35 @@ 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)
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)
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 @@ -96,6 +101,8 @@ end
function restrict_pdf_version!(surface::Cairo.CairoSurface, v::Integer)
@assert surface.ptr != C_NULL
0 v 3 || throw(ArgumentError("version must be 0, 1, 2, or 3 (received $v)"))
ccall((:cairo_pdf_surface_restrict_to_version, Cairo.libcairo), Nothing,
(Ptr{UInt8}, Int32), surface.ptr, v)
return ccall(
(:cairo_pdf_surface_restrict_to_version, Cairo.libcairo), Nothing,
(Ptr{UInt8}, Int32), surface.ptr, v
)
end
31 changes: 16 additions & 15 deletions CairoMakie/src/display.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#########################################
# Backend interface to Makie #
#########################################
Expand Down Expand Up @@ -28,17 +27,17 @@ function openurl(url::String)
tryrun(`python -mwebbrowser $(url)`) && return
# our last hope
tryrun(`python3 -mwebbrowser $(url)`) && return
@warn("Can't find a way to open a browser, open $(url) manually!")
return @warn("Can't find a way to open a browser, open $(url) manually!")
end

function Base.display(screen::Screen, scene::Scene; connect=false)
function Base.display(screen::Screen, scene::Scene; connect = false)
# Nothing to do, since drawing is done in the other functions
# TODO write to file and implement upenurl
return screen
end

function Base.display(screen::Screen{IMAGE}, scene::Scene; connect=false, screen_config...)
config = Makie.merge_screen_config(ScreenConfig, Dict{Symbol,Any}(screen_config))
function Base.display(screen::Screen{IMAGE}, scene::Scene; connect = false, screen_config...)
config = Makie.merge_screen_config(ScreenConfig, Dict{Symbol, Any}(screen_config))
screen = Makie.apply_screen_config!(screen, config, scene)
path = joinpath(mktempdir(), "display.png")
Makie.push_screen!(scene, screen)
Expand Down Expand Up @@ -75,7 +74,7 @@ function Makie.backend_show(screen::Screen{SVG}, io::IO, ::MIME"image/svg+xml",
# across svgs when embedding them on websites.
# the hash and therefore the salt will always be the same for the same file
# so the output is deterministic
salt = repr(CRC32c.crc32c(svg))[end-7:end]
salt = repr(CRC32c.crc32c(svg))[(end - 7):end]

# matches:
# id="someid"
Expand Down Expand Up @@ -111,15 +110,17 @@ end
# Disabling mimes and showable

const DISABLED_MIMES = Set{String}()
const SUPPORTED_MIMES = Set([
map(x->string(x()), Makie.WEB_MIMES)...,
"image/svg+xml",
"application/pdf",
"application/postscript",
"image/png"
])

function Makie.backend_showable(::Type{Screen}, ::MIME{SYM}) where SYM
const SUPPORTED_MIMES = Set(
[
map(x -> string(x()), Makie.WEB_MIMES)...,
"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 Down
10 changes: 5 additions & 5 deletions CairoMakie/src/infrastructure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function cairo_draw(screen::Screen, scene::Scene)
draw_background(screen, scene)

allplots = Makie.collect_atomic_plots(scene; is_atomic_plot = is_cairomakie_atomic_plot)
sort!(allplots; by=Makie.zvalue2d)
sort!(allplots; by = Makie.zvalue2d)
# If the backend is not a vector surface (i.e., PNG/ARGB),
# then there is no point in rasterizing twice.
should_rasterize = is_vector_backend(screen.surface)
Expand Down Expand Up @@ -116,7 +116,7 @@ function draw_background(screen::Screen, scene::Scene, root_h)
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 = viewport(scene)[]
# Makie has (0,0) at bottom left, Cairo at top left. Makie extends up,
# Cairo down. Negative height breaks other backgrounds
Expand All @@ -125,7 +125,7 @@ function draw_background(screen::Screen, scene::Scene, root_h)
fill(cr)
end
Cairo.restore(cr)
foreach(child_scene-> draw_background(screen, child_scene, root_h), scene.children)
return foreach(child_scene -> draw_background(screen, child_scene, root_h), scene.children)
end

function draw_plot(scene::Scene, screen::Screen, primitive::Plot)
Expand All @@ -149,7 +149,7 @@ 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{RT}, primitive::Plot, scale::Number = 1) where RT
function draw_plot_as_image(scene::Scene, screen::Screen{RT}, primitive::Plot, scale::Number = 1) where {RT}
# you can provide `p.rasterize = scale::Int` or `p.rasterize = true`, both of which are numbers

# Extract scene width in device independent units
Expand Down Expand Up @@ -183,5 +183,5 @@ function draw_plot_as_image(scene::Scene, screen::Screen{RT}, primitive::Plot, s
end

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