diff --git a/src/outputs/textconfig.jl b/src/outputs/textconfig.jl index 8d59fef..01441ca 100644 --- a/src/outputs/textconfig.jl +++ b/src/outputs/textconfig.jl @@ -8,7 +8,7 @@ Text configuration for printing timestep and grid name on the image. # Arguments / Keywords -- `font`: `String` font name. +- `font`: A `FreeTypeAbstraction.FTFont`, or a `String` with the font name to look for. The `FTFont` may load more quickly. - `namepixels` and `timepixels`: the pixel size of the font. - `timepos` and `namepos`: tuples that set the label positions, in `Int` pixels. - `fcolor` and `bcolor`: the foreground and background colors, as `ARGB32`. @@ -28,7 +28,9 @@ function TextConfig(; timepos=(2timepixels, timepixels), fcolor=ARGB32(1.0), bcolor=ZEROCOL, ) - if font isa AbstractString + if font isa FreeTypeAbstraction.FTFont + face = font + elseif font isa AbstractString face = FreeTypeAbstraction.findfont(font) face isa Nothing && _fontnotfounderror(font) else diff --git a/test/image.jl b/test/image.jl index 12f4537..e09dc8a 100644 --- a/test/image.jl +++ b/test/image.jl @@ -300,8 +300,6 @@ end ) simdata = SimData(output, Ruleset(Life())) @test_throws ArgumentError render!(output, simdata) - @test_throws ArgumentError TextConfig(; font="not_a_font") - @test_throws ArgumentError TextConfig(; font=:not_a_string) end @testset "Layout is the default for NamedTuple of grids" begin output = NoDisplayImageOutput(multiinit; tspan=1:10) diff --git a/test/runtests.jl b/test/runtests.jl index bec82b1..64dd24d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -24,6 +24,7 @@ end @time @safetestset "objectgrids" begin include("objectgrids.jl") end @time @safetestset "parametersources" begin include("parametersources.jl") end @time @safetestset "show" begin include("show.jl") end +@time @safetestset "textconfig" begin include("textconfig.jl") end # ImageMagick breaks in windows travis for some reason if !Sys.iswindows() @time @safetestset "image" begin include("image.jl") end diff --git a/test/textconfig.jl b/test/textconfig.jl new file mode 100644 index 0000000..fd5f259 --- /dev/null +++ b/test/textconfig.jl @@ -0,0 +1,19 @@ +using DynamicGrids, FreeTypeAbstraction, Test + +@testset "Fonts" begin + @test DynamicGrids.autofont() isa String + name = DynamicGrids.autofont() + face = FreeTypeAbstraction.findfont(name) + @testset "TextConfig accepts font as String" begin + @test name isa String + textconfig = TextConfig(; font=name) + @test textconfig.face isa FreeTypeAbstraction.FTFont + end + @testset "TextConfig accepts font as FTFont" begin + @test face isa FreeTypeAbstraction.FTFont + textconfig = TextConfig(; font=face) + @test textconfig.face === face + end + @test_throws ArgumentError TextConfig(; font="not_a_font") + @test_throws ArgumentError TextConfig(; font=:not_a_string) +end