File tree 3 files changed +11
-12
lines changed
3 files changed +11
-12
lines changed Original file line number Diff line number Diff line change 121
121
122
122
fontname (ft:: FTFont ) = " $(family_name (ft)) $(style_name (ft)) "
123
123
124
- const FONT_CACHE = Dict {String, Tuple{String, FTFont} } ()
124
+ const FONT_CACHE = Dict {String, FTFont} ()
125
125
126
126
function findfont (
127
127
searchstring:: String ;
@@ -138,7 +138,6 @@ function findfont(
138
138
searchparts = unique (split (lowercase (searchstring), r" \W +" , keepempty= false ))
139
139
140
140
best_score_so_far = (0 , 0 , false , typemin (Int))
141
- best_font_path = " "
142
141
best_font = nothing
143
142
144
143
for folder in font_folders
@@ -162,14 +161,13 @@ function findfont(
162
161
isnothing (best_font) || finalize (best_font)
163
162
164
163
# new candidate
165
- best_font_path = fpath
166
164
best_font = face
167
165
best_score_so_far = score
168
166
else
169
167
finalize (face)
170
168
end
171
169
end
172
170
end
173
- best_font === nothing || (FONT_CACHE[searchstring] = (best_font_path, best_font) )
174
- return (best_font_path, best_font)
171
+ best_font === nothing || (FONT_CACHE[searchstring] = best_font)
172
+ return best_font
175
173
end
Original file line number Diff line number Diff line change @@ -124,12 +124,13 @@ function boundingbox(extent::FontExtent{T}) where T
124
124
end
125
125
126
126
mutable struct FTFont
127
+ ft_path:: String
127
128
ft_ptr:: FreeType.FT_Face
128
129
use_cache:: Bool
129
130
extent_cache:: Dict{UInt64, FontExtent{Float32}}
130
- function FTFont (ft_ptr:: FreeType.FT_Face , use_cache:: Bool = true )
131
+ function FTFont (ft_path :: String , ft_ptr:: FreeType.FT_Face , use_cache:: Bool = true )
131
132
extent_cache = Dict {UInt64, FontExtent{Float32}} ()
132
- face = new (ft_ptr, use_cache, extent_cache)
133
+ face = new (ft_path, ft_ptr, use_cache, extent_cache)
133
134
finalizer (safe_free, face)
134
135
return face
135
136
end
138
139
use_cache (face:: FTFont ) = getfield (face, :use_cache )
139
140
get_cache (face:: FTFont ) = getfield (face, :extent_cache )
140
141
141
- FTFont (path:: String ) = FTFont (newface (path))
142
+ FTFont (path:: String ) = FTFont (path, newface (path))
142
143
143
144
# C interop
144
145
Base. cconvert (:: Type{FreeType.FT_Face} , font:: FTFont ) = font
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ using Test
13
13
@test FA. ft_init ()
14
14
end
15
15
16
- face = FA. findfont (" hack" )[ 2 ]
16
+ face = FA. findfont (" hack" )
17
17
18
18
@testset " basics" begin
19
19
@test :size in propertynames (face)
@@ -261,12 +261,12 @@ end
261
261
append! (FA. valid_fontpaths, valid_fontpaths)
262
262
for font in fonts
263
263
@testset " finding $font " begin
264
- @test findfont (font)[ 2 ] != = nothing
264
+ @test findfont (font) != = nothing
265
265
end
266
266
end
267
267
@testset " find in additional dir" begin
268
- @test findfont (" Hack" )[ 2 ] === nothing
269
- @test findfont (" Hack" , additional_fonts = @__DIR__ )[ 2 ] != = nothing
268
+ @test findfont (" Hack" ) === nothing
269
+ @test findfont (" Hack" , additional_fonts = @__DIR__ ) != = nothing
270
270
end
271
271
end
272
272
You can’t perform that action at this time.
0 commit comments