Skip to content

Commit

Permalink
Add placeholders_for_extensions, CI on v1.9
Browse files Browse the repository at this point in the history
modified:   .github/workflows/ci.yml
modified:   Project.toml
renamed:    ext/LuxorExt.jl -> ext/LuxorExtLatex.jl
modified:   ext/latex.jl
modified:   src/Luxor.jl
new file:   src/placeholders_for_extensions.jl
modified:   test/latex.jl
  • Loading branch information
hustf committed Oct 11, 2023
1 parent 758a6cc commit ba5f199
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
fail-fast: false
matrix:
julia-version:
- "1.6"
- "1.9"
- "1"
- "nightly"
os:
Expand Down
11 changes: 6 additions & 5 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion ext/LuxorExt.jl → ext/LuxorExtLatex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
9 changes: 5 additions & 4 deletions ext/latex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/Luxor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions src/placeholders_for_extensions.jl
Original file line number Diff line number Diff line change
@@ -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
50 changes: 37 additions & 13 deletions test/latex.jl
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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

Expand Down

0 comments on commit ba5f199

Please sign in to comment.