Skip to content

Commit 792df58

Browse files
committed
add ft_path field to FTFont
1 parent caa0f02 commit 792df58

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

src/findfonts.jl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ end
121121

122122
fontname(ft::FTFont) = "$(family_name(ft)) $(style_name(ft))"
123123

124-
const FONT_CACHE = Dict{String, Tuple{String,FTFont}}()
124+
const FONT_CACHE = Dict{String, FTFont}()
125125

126126
function findfont(
127127
searchstring::String;
@@ -138,7 +138,6 @@ function findfont(
138138
searchparts = unique(split(lowercase(searchstring), r"\W+", keepempty=false))
139139

140140
best_score_so_far = (0, 0, false, typemin(Int))
141-
best_font_path = ""
142141
best_font = nothing
143142

144143
for folder in font_folders
@@ -162,14 +161,13 @@ function findfont(
162161
isnothing(best_font) || finalize(best_font)
163162

164163
# new candidate
165-
best_font_path = fpath
166164
best_font = face
167165
best_score_so_far = score
168166
else
169167
finalize(face)
170168
end
171169
end
172170
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
175173
end

src/types.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,13 @@ function boundingbox(extent::FontExtent{T}) where T
124124
end
125125

126126
mutable struct FTFont
127+
ft_path::String
127128
ft_ptr::FreeType.FT_Face
128129
use_cache::Bool
129130
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)
131132
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)
133134
finalizer(safe_free, face)
134135
return face
135136
end
@@ -138,7 +139,7 @@ end
138139
use_cache(face::FTFont) = getfield(face, :use_cache)
139140
get_cache(face::FTFont) = getfield(face, :extent_cache)
140141

141-
FTFont(path::String) = FTFont(newface(path))
142+
FTFont(path::String) = FTFont(path, newface(path))
142143

143144
# C interop
144145
Base.cconvert(::Type{FreeType.FT_Face}, font::FTFont) = font

test/runtests.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ using Test
1313
@test FA.ft_init()
1414
end
1515

16-
face = FA.findfont("hack")[2]
16+
face = FA.findfont("hack")
1717

1818
@testset "basics" begin
1919
@test :size in propertynames(face)
@@ -261,12 +261,12 @@ end
261261
append!(FA.valid_fontpaths, valid_fontpaths)
262262
for font in fonts
263263
@testset "finding $font" begin
264-
@test findfont(font)[2] !== nothing
264+
@test findfont(font) !== nothing
265265
end
266266
end
267267
@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
270270
end
271271
end
272272

0 commit comments

Comments
 (0)