@@ -176,8 +176,8 @@ function findfont_nocache(searchstring::String, fontfolders::Vector{<:AbstractSt
176
176
# \W splits at all groups of non-word characters (like space, -, ., etc)
177
177
searchparts = unique (split (lowercase (searchstring), r" \W +" , keepempty= false ))
178
178
max_score1 = sum (length, searchparts) + sum (1 : length (searchparts))
179
- best_1i, best_file, best_score = 0 , nothing , (0 , 0 , 0 , typemin (Int), 0 )
180
- for (i , fontfile) in enumerate ( fontfiles_guess_sorted (searchparts, fontfolders) )
179
+ best_file, best_score = nothing , (0 , 0 , 0 , typemin (Int), 0 )
180
+ for folder in fontfolders , fontfile in readdir (folder, join = true )
181
181
# we can compare all five tuple elements of the score at once
182
182
# in order of importance:
183
183
# 1. number of family and style match characters (with priority factor)
@@ -186,44 +186,9 @@ function findfont_nocache(searchstring::String, fontfolders::Vector{<:AbstractSt
186
186
# 4. the negative length of the font name, the shorter the better
187
187
# 5. the font file extension priority
188
188
score = score_font (searchparts, fontfile)
189
- if first (score) > 0 && score >= best_score
190
- best_1i = i
191
- if score > best_score
192
- best_file, best_score = fontfile, score
193
- end
194
- elseif first (best_score) == max_score1 && first (score) < first (best_score) && i > 2 * best_1i
195
- return best_file
189
+ if first (score) > 0 && score > best_score
190
+ best_file, best_score = fontfile, score
196
191
end
197
192
end
198
193
best_file
199
194
end
200
-
201
- const FONTFILE_NAMES = Dict {String, String} ()
202
-
203
- """
204
- fontfiles_guess_sorted(searchparts::Vector{<:AbstractString}; additional_fonts::String="")
205
-
206
- Collect all font files under `fontpaths` (also including `additional_fonts` if
207
- non-empty), and then rank them by how closely we think the font information
208
- matches `searchparts`, guessing based on the font file name.
209
- """
210
- function fontfiles_guess_sorted (searchparts:: Vector{<:AbstractString} , fontfolders:: Vector{<:AbstractString} )
211
- function score_names (searchparts, fontfile)
212
- filename = get! (() -> splitext (basename (fontfile)) |> first |> lowercase,
213
- FONTFILE_NAMES, fontfile) # Caching produces a ~7x speedup
214
- # We sum the length of the search parts found in `filename` with a reverse part
215
- # index (`i`) to weight earlier matching parts higher. This is essentially
216
- # an approximation of the more sophisticated (and expensive) scoring performed
217
- # in `score_font`.
218
- sum ((i + length (part) for (i, part) in enumerate (Iterators. reverse (searchparts))
219
- if occursin (part, filename)),
220
- init= 0 ), - length (filename)
221
- end
222
- searchparts = copy (searchparts)
223
- push! (searchparts, String (map (first, searchparts)))
224
- allfonts = String[]
225
- for folder in fontfolders
226
- append! (allfonts, readdir (folder, join= true ))
227
- end
228
- sort (allfonts, by= Base. Fix1 (score_names, searchparts), rev= true )
229
- end
0 commit comments