Luxor and Unicode

Is there a way to represent the unicode (\u21D0) etc in a Luxor plot? I guess I need to specifiy an adequate typeface, but is is annoying that the repl and jupyter show what I want for the Array A, but not Luxor, not even in png raster format. Any suggestion ?

using Luxor



function drawmatrix(A::Matrix;
        cellsize = (10, 10))
    table = Table(size(A)..., cellsize...)
    used = Set()
    for i in CartesianIndices(A)
        r, c = Tuple(i)
        @show A[r,c]
        text(A[r, c], table[r, c],
            halign=:center,
            valign=:middle)
        sethue("white")
        box(table, r, c, action = :stroke)
    end
end

A = Any["1" "2" "3" "4" "5" "6"; "1⇐" "6⇒" "1⇒" "4⇐" "3⇒" "2⇐"; "15⇑" "" "15⇓" "1⇑" "14⇓" "2⇑"]

@png begin
    fontface("Arial")
    background("black")
    fontsize(30)
    setline(0.5)
    sethue("white")
    drawmatrix(A, cellsize = 20 .* size(A))
end

I did it the hard way: looking into the fonts installed on my system and “cut/pasting”
into the preview option for each font until I found a font that was able to display the arrow (here “Lucida Sans Unicode”). Not nice but at least I have a solution

using Luxor





function drawmatrix(A::Matrix;
        cellsize = (10, 10))
    table = Table(size(A)..., cellsize...)
    used = Set()
    for i in CartesianIndices(A)
        r, c = Tuple(i)
        @show A[r,c]
        text(A[r, c], table[r, c],
            halign=:center,
            valign=:middle)
        sethue("white")
        box(table, r, c, action = :stroke)
    end
end

A = Any["1" "2" "3" "4" "5" "6"; "1⇐" "6⇒" "1⇒" "4⇐" "3⇒" "2⇐"; "15⇑" "" "15⇓" "1⇑" "14⇓" "2⇑"]

@png begin
    fontface("Lucida Sans Unicode")
    background("black")
    fontsize(30)
    setline(0.5)
    sethue("white")
    drawmatrix(A, cellsize = 20 .* size(A))
end

Font fallback is great in most environments, finding a font with the required glyph automatically fo you, but I don’t think Cairo does it. :worried:

You can check here how Makie does this, you can test programmatically if some font has a given glyph Makie.jl/src/utilities/texture_atlas.jl at 6dfb420445065c56f5af7944c87ecdfc22eff507 · MakieOrg/Makie.jl · GitHub

2 Likes