From 8495aab44c9d5204702a2b5ada15ef5e43639832 Mon Sep 17 00:00:00 2001 From: ederag Date: Sat, 15 Jan 2022 10:52:50 +0100 Subject: [PATCH 1/4] allow FTFont in TextConfig(font=...) --- src/outputs/textconfig.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/outputs/textconfig.jl b/src/outputs/textconfig.jl index 8d59fefb..49731037 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`: `FreeTypeAbstraction.FTFont` (direct), or `String` (font name to look for). - `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 From ec8830f5e3de8040be0f8c6706ad8fc190661ea5 Mon Sep 17 00:00:00 2001 From: ederag Date: Tue, 18 Jan 2022 16:50:58 +0100 Subject: [PATCH 2/4] Update src/outputs/textconfig.jl Co-authored-by: Rafael Schouten --- src/outputs/textconfig.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/outputs/textconfig.jl b/src/outputs/textconfig.jl index 49731037..01441ca2 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`: `FreeTypeAbstraction.FTFont` (direct), or `String` (font name to look for). +- `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`. From 4a65be933f1072736b56bb5d86c1338a1456dff1 Mon Sep 17 00:00:00 2001 From: ederag Date: Thu, 27 Jan 2022 09:20:26 +0100 Subject: [PATCH 3/4] move TextConfig tests to their own file --- test/image.jl | 2 -- test/runtests.jl | 1 + test/textconfig.jl | 6 ++++++ 3 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 test/textconfig.jl diff --git a/test/image.jl b/test/image.jl index 12f45370..e09dc8ac 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 bec82b16..64dd24de 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 00000000..adaa3010 --- /dev/null +++ b/test/textconfig.jl @@ -0,0 +1,6 @@ +using DynamicGrids, Test + +@testset "Fonts" begin + @test_throws ArgumentError TextConfig(; font="not_a_font") + @test_throws ArgumentError TextConfig(; font=:not_a_string) +end From 7ca66bc1ca005dd6d235e68007d8e48a34bab8df Mon Sep 17 00:00:00 2001 From: ederag Date: Thu, 27 Jan 2022 14:07:10 +0100 Subject: [PATCH 4/4] test passing String or FTFont to TextConfig --- test/textconfig.jl | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/test/textconfig.jl b/test/textconfig.jl index adaa3010..fd5f2593 100644 --- a/test/textconfig.jl +++ b/test/textconfig.jl @@ -1,6 +1,19 @@ -using DynamicGrids, Test +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