-
-
Notifications
You must be signed in to change notification settings - Fork 291
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
Figure glitches CairoMakie backend #1843
Comments
With CairoMakie, could you try: save("fig_highres.png", your_figure; px_per_unit=5)
save("fig.pdf", your_figure; pt_per_unit=1) and upload them here? It looks like the lines are getting mitered instead of beveled, which should be a simple enough thing to fix (see https://www.cairographics.org/manual/cairo-cairo-t.html#cairo-set-miter-limit for reference). |
|
Dear @asinghvi17 , when I try to save the error occurs. |
Sorry, typo - it should be Click here to see code@eval CairoMakie begin
"""
CairoScreen(
scene::Scene, path::Union{String, IO}, mode::Symbol;
antialias = Cairo.ANTIALIAS_BEST
)
Creates a CairoScreen pointing to a given output path, with some rendering type defined by `mode`.
"""
function CairoScreen(scene::Scene, path::Union{String, IO}, mode::Symbol; device_scaling_factor = 1, antialias = Cairo.ANTIALIAS_BEST)
# the surface size is the scene size scaled by the device scaling factor
w, h = round.(Int, scene.camera.resolution[] .* device_scaling_factor)
if mode == :svg
surf = Cairo.CairoSVGSurface(path, w, h)
elseif mode == :pdf
surf = Cairo.CairoPDFSurface(path, w, h)
elseif mode == :eps
surf = Cairo.CairoEPSSurface(path, w, h)
elseif mode == :png
surf = Cairo.CairoARGBSurface(w, h)
else
error("No available Cairo surface for mode $mode")
end
# 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((:cairo_surface_set_device_scale, Cairo.libcairo), Cvoid, (Ptr{Nothing}, Cdouble, Cdouble),
surf.ptr, device_scaling_factor, device_scaling_factor)
ctx = Cairo.CairoContext(surf)
@ccall Cairo.libcairo.cairo_set_miter_limit(ctx.ptr::Ptr{Nothing}, 2.0::Cdouble)::Cvoid
#ccall((:cairo_set_miter_limit, Cairo.libcairo), Cvoid, (Ptr{Nothing}, Cdouble), (ctx.ptr, 2.0))
#Cairo.set_line_join(ctx, Cairo.CAIRO_LINE_JOIN_ROUND)
Cairo.set_antialias(ctx, antialias)
return CairoScreen(scene, surf, ctx, nothing)
end
"""
CairoScreen(scene::Scene; antialias = Cairo.ANTIALIAS_BEST)
Create a CairoScreen backed by an image surface.
"""
function CairoScreen(scene::Scene; device_scaling_factor = 1, antialias = Cairo.ANTIALIAS_BEST)
w, h = round.(Int, scene.camera.resolution[] .* device_scaling_factor)
surf = Cairo.CairoARGBSurface(w, h)
# 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((:cairo_surface_set_device_scale, Cairo.libcairo), Cvoid, (Ptr{Nothing}, Cdouble, Cdouble),
surf.ptr, device_scaling_factor, device_scaling_factor)
ctx = Cairo.CairoContext(surf)
Cairo.set_antialias(ctx, antialias)
# Set the miter limit (when miter transitions to bezel) to mimic GLMakie behaviour
@ccall Cairo.libcairo.cairo_set_miter_limit(ctx.ptr::Ptr{Nothing}, 2.0::Cdouble)::Cvoid
return CairoScreen(scene, surf, ctx, nothing)
end
end |
Thanks, it works now |
Glad to hear! Once #1844 is merged, this issue should close automatically. The fix will likely be out in the next release. |
* Set the Cairo miter limit to mimic GLMakie Fixes #1843 * Update NEWS.md * Switch back from macro ccall to function ccall Co-authored-by: Simon <sdanisch@protonmail.com>
As shown in figure, there are glitches when you try to thicken the line.
CairoMakie
linewidth = 1
linewidth = 2
linewidth = 5
These glitches can be resolved when you define large resolution.
fig=Figure(resolution=(4000,3000))
GLMakie
linewidth = 5
The text was updated successfully, but these errors were encountered: