diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3734605f..dbe06a40 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,7 @@ jobs: fail-fast: false matrix: julia-version: - - "1.6" + - "1.9" - "1" - "nightly" os: diff --git a/Project.toml b/Project.toml index c36f49a4..db46a709 100644 --- a/Project.toml +++ b/Project.toml @@ -7,21 +7,23 @@ version = "3.9.0" Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" Cairo = "159f3aea-2a34-519c-b102-8c37f9878175" Colors = "5ae59095-9a9b-59fe-a467-6f913c188581" +DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" FFMPEG = "c87230d0-a227-11e9-1b43-d7ebe4e7570a" FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" Juno = "e5e0dc1b-0480-54bc-9374-aad01c23163d" +LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f" +MathTeXEngine = "0a4f8689-d25c-4efe-a92b-7142dfc1aa53" +PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Rsvg = "c4c386cf-5103-5370-be45-f3a111cca3b8" -PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a" -DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" [weakdeps] LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f" MathTeXEngine = "0a4f8689-d25c-4efe-a92b-7142dfc1aa53" [extensions] -LuxorExt = ["LaTeXStrings", "MathTeXEngine"] +LuxorExtLatex = ["LaTeXStrings", "MathTeXEngine"] [compat] Cairo = "0.7, 0.8, 1.0" @@ -31,15 +33,14 @@ FFMPEG = "0.4" FileIO = "1" Juno = "0.7, 0.8" LaTeXStrings = "1.1, 1.2, 1.3" -Rsvg = "1.0" PrecompileTools = "1" +Rsvg = "1.0" julia = "1.9" [extras] ImageIO = "82e4d734-157c-48bb-816b-45c225c6df19" LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f" MathTeXEngine = "0a4f8689-d25c-4efe-a92b-7142dfc1aa53" - Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] diff --git a/ext/LuxorExt.jl b/ext/LuxorExtLatex.jl similarity index 89% rename from ext/LuxorExt.jl rename to ext/LuxorExtLatex.jl index 97cd9b22..362b4949 100644 --- a/ext/LuxorExt.jl +++ b/ext/LuxorExtLatex.jl @@ -3,7 +3,7 @@ This extension is loaded and used by Luxor if both LaTeXStrings and MathTeXEngin The functions are accessed through Luxor as usual. """ -module LuxorExt +module LuxorExtLatex include("latex.jl") diff --git a/ext/latex.jl b/ext/latex.jl index 78db779f..12030208 100644 --- a/ext/latex.jl +++ b/ext/latex.jl @@ -3,10 +3,11 @@ import MathTeXEngine using MathTeXEngine: generate_tex_elements, inkwidth, inkheight, bottominkbound, TeXChar, HLine using LaTeXStrings -using Luxor -# Exports from LuxorExt to Luxor: -latextextsize, latexboundingbox, rawlatexboundingbox - +import Luxor +import Luxor: text, latextextsize, latexboundingbox, rawlatexboundingbox +using Luxor: Point, @layer, translate, rotate, move, + fontface, fontsize, get_fontsize, setfont, + setline, line, poly, closepath, newsubpath """ texalign(halign, valign, bottom_pt, top_pt, font_size) diff --git a/src/Luxor.jl b/src/Luxor.jl index 077b5649..4309667a 100644 --- a/src/Luxor.jl +++ b/src/Luxor.jl @@ -72,6 +72,7 @@ include("randompoints.jl") include("Path.jl") include("precompile.jl") include("placeeps.jl") +include("placeholders_for_extensions.jl") # include("play.jl") # will require MiniFB # include("shapefile.jl") # don't load unless you've loaded Shapefile.jl @@ -173,7 +174,7 @@ export Drawing, # experimental tidysvg, - # latex + # latex. These always throw errors if Base.get_extension(Luxor, :LuxorExtLatex) isa Nothing latextextsize, latexboundingbox, rawlatexboundingbox # basic unit conversion to Cairo/PostScript points diff --git a/src/placeholders_for_extensions.jl b/src/placeholders_for_extensions.jl new file mode 100644 index 00000000..5a18e334 --- /dev/null +++ b/src/placeholders_for_extensions.jl @@ -0,0 +1,25 @@ +# Extensions are modules that depend on Luxor and other modules. +# They are loaded when Luxor and these modules are loaded. +# Extensions (LuxorExt...) cannot however reliably introduce new symbols +# into Luxor. Hence, placeholder functions with catchall argument types: +function latextextsize(catch_all) + if Base.get_extension(Luxor, :LuxorExtLatex) isa Module + throw(MethodError(latextextsize, catch_all)) + else + throw(ErrorException("Modules LaTeXStrings and MathTeXEngine are not loaded.")) + end +end +function latexboundingbox(catch_all; kwargs...) + if Base.get_extension(Luxor, :LuxorExtLatex) isa Module + throw(MethodError(latexboundingbox, catch_all)) + else + throw(ErrorException("Modules LaTeXStrings and MathTeXEngine are not loaded.")) + end +end +function rawlatexboundingbox(catch_all) + if Base.get_extension(Luxor, :LuxorExtLatex) isa Module + throw(MethodError(rawlatexboundingbox, catch_all)) + else + throw(ErrorException("Modules LaTeXStrings and MathTeXEngine are not loaded.")) + end +end diff --git a/test/latex.jl b/test/latex.jl index 93a15f76..5cbba851 100644 --- a/test/latex.jl +++ b/test/latex.jl @@ -1,7 +1,31 @@ using Luxor using Test + +@testset "nolatexextension" begin + @test ! @isdefined LaTeXStrings + @test Base.get_extension(Luxor, :LuxorExtLatex) isa Nothing + @test length(methods(text)) == 3 + @test length(methods(latextextsize)) == 1 + @test length(methods(latexboundingbox)) == 1 + @test length(methods(rawlatexboundingbox)) == 1 + @test_throws ErrorException latextextsize(14.0) + @test_throws ErrorException latexboundingbox("14.0") + @test_throws ErrorException rawlatexboundingbox(:fourteen) +end + + using LaTeXStrings using MathTeXEngine +@testset "latexextension" begin + @test Base.get_extension(Luxor, :LuxorExtLatex) isa Module + @test length(methods(text)) == 4 + @test length(methods(latextextsize)) == 2 + @test length(methods(latexboundingbox)) == 3 + @test length(methods(rawlatexboundingbox)) == 2 + @test_throws MethodError latextextsize(14.0) + @test_throws MethodError latexboundingbox("14.0") + @test_throws MethodError rawlatexboundingbox(:fourteen) +end @testset "latex" begin d = Drawing(200, 200, :svg) @@ -14,28 +38,28 @@ using MathTeXEngine for halign in [:left, :right, :center], valign in [:baseline, :bottom, :top, :middle] text(t, O, halign=halign, valign=valign) - @test round.(Luxor.latextextsize(t); digits=2) == (36.99, 46.69) + @test round.(latextextsize(t); digits=2) == (36.99, 46.69) if halign === :left - @test round(Luxor.latexboundingbox(t, halign=halign, valign=valign)[1][1]; digits=2) == 0.0 - @test round(Luxor.latexboundingbox(t, halign=halign, valign=valign)[2][1]; digits=2) == 36.99 + @test round(latexboundingbox(t, halign=halign, valign=valign)[1][1]; digits=2) == 0.0 + @test round(latexboundingbox(t, halign=halign, valign=valign)[2][1]; digits=2) == 36.99 elseif halign === :right - @test round(Luxor.latexboundingbox(t, halign=halign, valign=valign)[1][1]; digits=2) == -36.99 - @test round(Luxor.latexboundingbox(t, halign=halign, valign=valign)[2][1]; digits=2) == 0.0 + @test round(latexboundingbox(t, halign=halign, valign=valign)[1][1]; digits=2) == -36.99 + @test round(latexboundingbox(t, halign=halign, valign=valign)[2][1]; digits=2) == 0.0 elseif halign === :center - @test round(Luxor.latexboundingbox(t, halign=halign, valign=valign)[1][1]; digits=2) == -36.98 / 2 - @test round(Luxor.latexboundingbox(t, halign=halign, valign=valign)[2][1]; digits=2) == 36.98 / 2 + @test round(latexboundingbox(t, halign=halign, valign=valign)[1][1]; digits=2) == -36.98 / 2 + @test round(latexboundingbox(t, halign=halign, valign=valign)[2][1]; digits=2) == 36.98 / 2 end if valign === :baseline || valign === :bottom - @test round(Luxor.latexboundingbox(t, halign=halign, valign=valign)[1][2]; digits=2) == 18.72 - @test round(Luxor.latexboundingbox(t, halign=halign, valign=valign)[2][2]; digits=2) == -27.97 + @test round(latexboundingbox(t, halign=halign, valign=valign)[1][2]; digits=2) == 18.72 + @test round(latexboundingbox(t, halign=halign, valign=valign)[2][2]; digits=2) == -27.97 elseif valign === :top - @test round(Luxor.latexboundingbox(t, halign=halign, valign=valign)[1][2]; digits=2) == 46.69 - @test round(Luxor.latexboundingbox(t, halign=halign, valign=valign)[2][2]; digits=2) == 0.0 + @test round(latexboundingbox(t, halign=halign, valign=valign)[1][2]; digits=2) == 46.69 + @test round(latexboundingbox(t, halign=halign, valign=valign)[2][2]; digits=2) == 0.0 elseif valign === :middle - @test round(Luxor.latexboundingbox(t, halign=halign, valign=valign)[1][2]; digits=2) == 46.70 / 2 - @test round(Luxor.latexboundingbox(t, halign=halign, valign=valign)[2][2]; digits=2) == -46.70 / 2 + @test round(latexboundingbox(t, halign=halign, valign=valign)[1][2]; digits=2) == 46.70 / 2 + @test round(latexboundingbox(t, halign=halign, valign=valign)[2][2]; digits=2) == -46.70 / 2 end end