Skip to content

Commit

Permalink
Remove old CairoMakie code
Browse files Browse the repository at this point in the history
  • Loading branch information
asinghvi17 authored Jun 24, 2024
1 parent e3e046c commit f12a46f
Showing 1 changed file with 0 additions and 110 deletions.
110 changes: 0 additions & 110 deletions src/recipe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -144,116 +144,6 @@ function Makie.plot!(plot::TeXImg)
)
end

# CairoMakie direct drawing method
function draw_tex(scene::Scene, screen::CairoMakie.Screen, cachedtex::CachedTeX, position::VecTypes, scale::VecTypes, rotation::Real, align::Tuple{Symbol, Symbol})
# establish some initial values
x0, y0 = 0.0, 0.0
w, h = cachedtex.dims
ctx = screen.context
# First we center the position with respect to the center of the image,
# regardless of its alignment. This ensures that rotation takes place
# in the correct "axis" (2d).
position = position .+ (-scale[1]/2, scale[2]/2)


# Then, we find the appropriate "marker offset" w.r.t. alignment.
# This is separate because of Cairo's reversed y-axis.
halign, valign = align
pos = Point2f(0)
pos = if halign == :left
pos .- (-scale[1] / 2, 0)
elseif halign == :center
pos .- (0, 0)
elseif halign == :right
pos .- (scale[1] / 2, 0)
end

pos = if valign == :top
pos .+ (0, scale[2]/2)
elseif valign == :center
pos .+ (0, 0)
elseif valign == :bottom
pos .- (0, scale[2]/2)
end

# Calculate, with respect to the rotation, where the rotated center of the image
# should be.
# (Rotated center - Normal center)
cx = 0.5scale[1] * cos(rotation) - 0.5scale[2] * sin(rotation) - 0.5scale[1]
cy = 0.5scale[1] * sin(rotation) + 0.5scale[2] * cos(rotation) - 0.5scale[2]

# Begin the drawing and translation process
Cairo.save(ctx)
# translate to normal position
Cairo.translate(
ctx,
position[1],
position[2] - scale[2]
)
# rotate context by required rotation
Cairo.rotate(ctx, -rotation)
# cairo rotates around position as an axis,
#compensate for that with previously calculated values
Cairo.translate(ctx, cx, cy)
# apply "marker offset" to implement/simulate alignment
Cairo.translate(ctx, pos[1], pos[2])
# scale the marker appropriately
Cairo.scale(
ctx,
scale[1] / w,
scale[2] / h
)
# the rendering pipeline
# first is the "safe" Poppler pipeline, with better results in PDF
# and PNG, especially when rotated.
if !(RENDER_EXTRASAFE[])
# retrieve a new Poppler document pointer
document = update_pointer!(cachedtex)
# retrieve the first page
page = ccall(
(:poppler_document_get_page, Poppler_jll.libpoppler_glib),
Ptr{Cvoid},
(Ptr{Cvoid}, Cint),
document, 0 # page 0 is first page
)
# Render the page to the surface
ccall(
(:poppler_page_render, Poppler_jll.libpoppler_glib),
Cvoid,
(Ptr{Cvoid}, Ptr{Cvoid}),
page, ctx.ptr
)
else # "extra-safe" Cairo pipeline, also somewhat faster.
# render the cached CairoSurface to the screen.
# bad with PNG output though.
Cairo.set_source(ctx, cachedtex.surf, 0, 0)
Cairo.paint(ctx)
end
# restore context and end
Cairo.restore(ctx)
end

function CairoMakie.draw_plot(scene::Scene, screen::CairoMakie.Screen, img::T) where T <: MakieTeX.TeXImg

broadcast_foreach(img[1][], img.position[], img.scale[], CairoMakie.remove_billboard(img.rotations[]), img.align[]) do cachedtex, position, scale, rotation, align

w, h = cachedtex.dims

pos = CairoMakie.project_position(
scene, img.space[],
Makie.apply_transform(scene.transformation.transform_func[], position),
img.model[]
)

_w = scale * w; _h = scale * h
scale_factor = CairoMakie.project_scale(scene, img.space[], Vec2{Float32}(_w, _h), img.model[])

draw_tex(scene, screen, cachedtex, pos, scale_factor, rotation, align)

end

end

"""
tex_annotation!(axis::Axis, lstring, x, y; mainfont = nothing, mathfont = nothing, scale_factor=1)
Expand Down

0 comments on commit f12a46f

Please sign in to comment.