Skip to content

Commit

Permalink
Merge pull request #32 from JuliaPlots/as/fixes
Browse files Browse the repository at this point in the history
General fixes, version 0.2.1
  • Loading branch information
asinghvi17 authored May 23, 2022
2 parents f3c4ef6 + f519459 commit 3fada62
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MakieTeX"
uuid = "6d554a22-29e7-47bd-aee5-0c5f06619414"
authors = ["Anshul Singhvi"]
version = "0.2.0"
version = "0.2.1"

[deps]
Cairo = "159f3aea-2a34-519c-b102-8c37f9878175"
Expand Down
19 changes: 10 additions & 9 deletions src/recipe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ function offset_from_align(align::Tuple{Symbol, Symbol}, wh)::Vec2f
y = -h / 2

if halign == :left
x -= w/2
x += w/2
elseif halign == :center
x -= 0
elseif halign == :right
x += w/2
x -= w/2
end

if valign == :top
Expand Down Expand Up @@ -114,12 +114,13 @@ function draw_tex(scene::Scene, screen::CairoMakie.CairoScreen, cachedtex::Cache

# First, find the desired position of the marker with respect to the alignment
halign, valign = align
pos = position
pos = if halign == :left
position .- (scale[1], 0)
pos # (scale[1], 0)
elseif halign == :center
position .- (scale[1] / 2, 0)
pos .- (scale[1] / 2, 0)
elseif halign == :right
position
pos .- (scale[1], 0)
end

pos = if valign == :top
Expand Down Expand Up @@ -155,9 +156,9 @@ function draw_tex(scene::Scene, screen::CairoMakie.CairoScreen, cachedtex::Cache
scale[1] / w,
scale[2] / h
)
# the rendereing pipeline
# first is the "unsafe" Poppler pipeline, with better results in PDF
# but worse in PNG, especially when rotated.
# 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)
Expand All @@ -175,7 +176,7 @@ function draw_tex(scene::Scene, screen::CairoMakie.CairoScreen, cachedtex::Cache
(Ptr{Cvoid}, Ptr{Cvoid}),
page, ctx.ptr
)
else # "safer" Cairo pipeline, also somewhat faster.
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)
Expand Down
25 changes: 22 additions & 3 deletions src/text_override.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,25 @@
# and spreads them out!
function to_plottable_cachedtex(lstr, font, textsize, lineheight, color)
# $(usemain && raw"\usepackage{fontspec}")
packages = [
# math stuff
"amsmath", "amssymb", "amsfonts", "esint",
# color management
"xcolor",
]
# smart detect tikz to decrease load time
if occursin("tikz", lstr)
push!(packages, "tikz")
end

package_load_str = raw"\usepackage{" * join(packages, ", ") * raw"}"


preamble = """
\\usepackage{lmodern}
\\usepackage[T1]{fontenc}
\\usepackage{amsmath, amssymb, amsfonts, xcolor, tikz}
$(package_load_str)
\\definecolor{maincolor}{HTML}{$(Makie.Colors.hex(RGBf(color)))}
\\DeclareMathSizes{$(textsize)}{$(textsize + .5)}{$(textsize*7/12)}{$(textsize*7/12)}
"""
Expand Down Expand Up @@ -46,7 +60,7 @@ end


function Makie.plot!(t::Makie.Text{<: Tuple{<:AbstractVector{<:CachedTeX}}})
teximgcollection!(
teximg!(
t, t[1];
space = t.space, position=t.position, align = t.align,
rotations = lift(to_array, t.rotation), visible = t.visible,
Expand Down Expand Up @@ -120,7 +134,7 @@ function Makie.plot!(t::Makie.Text{<: Tuple{<: AbstractVector{<: LaTeXString}}})
end



# Define bounding box methods for all extended plot types

function Makie.boundingbox(x::Makie.Text{<:Tuple{<:CachedTeX}})
Makie.boundingbox(
Expand Down Expand Up @@ -161,3 +175,8 @@ function Makie.boundingbox(x::Makie.Text{<:Tuple{<:AbstractArray{<:Union{LaTeXSt
x.align[]
)
end

# Re-direct and allow our methods to pick these up
function Makie.boundingbox(x::Makie.Text{<:Tuple{<:AbstractArray{<: Tuple{<:T, <:Point}}}}) where T <: AbstractString
return Makie.boundingbox(x.plots[1])
end

2 comments on commit 3fada62

@asinghvi17
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/60820

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.1 -m "<description of version>" 3fada62a4e0bed8e0caac9fe8e3f40dcc09e27fe
git push origin v0.2.1

Please sign in to comment.