Skip to content

Commit b380ba7

Browse files
committed
setfontcandidates!
1 parent 57ad173 commit b380ba7

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/artist.jl

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ end
3939
function fontsof(lang)
4040
union((listfonts(l) for l in expandlangcode(lang))...)
4141
end
42-
function getfonts(lang)
42+
function getfontcandidates(lang)
43+
lang = StopWords.normcode(String(lang))
4344
if haskey(FontCandidates, lang)
4445
return FontCandidates[lang]
4546
else
@@ -50,6 +51,15 @@ function getfonts(lang)
5051
end
5152
end
5253

54+
"""
55+
setfontcandidates!(lang::AbstractString, str_set)
56+
57+
Customize font candidates for language `lang`
58+
"""
59+
function setfontcandidates!(lang::AbstractString, str_list)
60+
FontCandidates[StopWords.normcode(String(lang))] = str_list
61+
end
62+
5363
Schemes_colorbrewer = filter(s -> occursin("colorbrewer", colorschemes[s].category), collect(keys(colorschemes)))
5464
Schemes_colorbrewer = filter(s -> (occursin("Accent", String(s))
5565
|| occursin("Dark", String(s))
@@ -343,10 +353,10 @@ end
343353
randomoutline() = rand((0, 0, 0, rand(2:10)))
344354
function randomfonts(lang="")
345355
if rand() < 0.8
346-
fonts = rand(getfonts(lang))
356+
fonts = rand(getfontcandidates(lang))
347357
fonts = fonts * rand(WeightCandidates)
348358
else
349-
fonts = rand(getfonts(lang), 2 + floor(Int, 2randexp()))
359+
fonts = rand(getfontcandidates(lang), 2 + floor(Int, 2randexp()))
350360
fonts = [f * rand(WeightCandidates) for f in fonts]
351361
rand() > 0.5 && (fonts = tuple(fonts...))
352362
end

test/runtests.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,10 @@ include("test_textprocessing.jl")
160160
wordcloud(["the"=>1.0, "to"=>0.51, "and"=>0.50,
161161
"of"=>0.47, "a"=>0.44, "in"=>0.33]) |> generate!
162162
wordcloud("It's easy to generate word clouds", maxnum=10) |> generate!
163+
164+
# font
165+
WordCloud.setfontcandidates!("zh", ["CJK"])
166+
@test WordCloud.getfontcandidates("zh") == WordCloud.getfontcandidates("zho") == ["CJK"]
167+
168+
@show keys(WordCloud.FontCandidates)
163169
end

0 commit comments

Comments
 (0)