Skip to content

Commit 76c72d1

Browse files
committed
revert style changes
1 parent d279078 commit 76c72d1

File tree

4 files changed

+65
-49
lines changed

4 files changed

+65
-49
lines changed

src/findfonts.jl

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
if Sys.isapple()
2-
_font_paths() = [
3-
"/Library/Fonts", # Additional fonts that can be used by all users. This is generally where fonts go if they are to be used by other applications.
4-
joinpath(homedir(), "Library/Fonts"), # Fonts specific to each user.
5-
"/Network/Library/Fonts", # Fonts shared for users on a network
6-
"/System/Library/Fonts", # System specific fonts
7-
"/System/Library/Fonts/Supplemental", # new location since Catalina
8-
]
2+
function _font_paths()
3+
return [
4+
"/Library/Fonts", # Additional fonts that can be used by all users. This is generally where fonts go if they are to be used by other applications.
5+
joinpath(homedir(), "Library/Fonts"), # Fonts specific to each user.
6+
"/Network/Library/Fonts", # Fonts shared for users on a network
7+
"/System/Library/Fonts", # System specific fonts
8+
"/System/Library/Fonts/Supplemental", # new location since Catalina
9+
]
10+
end
911
elseif Sys.iswindows()
10-
_font_paths() = [
11-
joinpath(get(ENV, "SYSTEMROOT", "C:\\Windows"), "Fonts"),
12-
joinpath(homedir(), "AppData", "Local", "Microsoft", "Windows", "Fonts"),
13-
]
12+
function _font_paths()
13+
return [
14+
joinpath(get(ENV, "SYSTEMROOT", "C:\\Windows"), "Fonts"),
15+
joinpath(homedir(), "AppData", "Local", "Microsoft", "Windows", "Fonts"),
16+
]
17+
end
1418
else
1519
function add_recursive(result, path)
1620
for p in readdir(path)
@@ -29,7 +33,7 @@ else
2933
add_recursive(result, p)
3034
end
3135
end
32-
result
36+
return result
3337
end
3438
end
3539

@@ -99,7 +103,7 @@ function match_font(face::FTFont, searchparts)::Tuple{Int, Int, Bool, Int}
99103

100104
style_score = sum(length(part) for part in remaining_parts if occursin(part, sname))
101105

102-
(family_score, style_score, is_regular_style, fontlength_penalty)
106+
return (family_score, style_score, is_regular_style, fontlength_penalty)
103107
end
104108

105109
function try_load(fpath)
@@ -160,5 +164,5 @@ function findfont(
160164
end
161165
end
162166

163-
best_font
167+
return best_font
164168
end

src/layout.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ function glyph_rects(line::AbstractString, fonts, scales)
5858
return rects
5959
end
6060

61-
boundingbox(line::AbstractString, fonts, scales) = reduce(union, glyph_rects(line, fonts, scales))
61+
function boundingbox(line::AbstractString, fonts, scales)
62+
return reduce(union, glyph_rects(line, fonts, scales))
63+
end
6264

6365
function inkboundingbox(ext::FontExtent)
6466
l = leftinkbound(ext)

src/rendering.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,17 @@ function loadglyph(face::FTFont, c::Char, pixelsize::Integer)
99
loadchar(face, c)
1010
glyph = unsafe_load(face.glyph)
1111
@assert glyph.format == FreeType.FT_GLYPH_FORMAT_BITMAP
12-
glyph
12+
return glyph
1313
end
1414

1515
function renderface(face::FTFont, c::Char, pixelsize::Integer)
1616
glyph = loadglyph(face, c, pixelsize)
17-
glyphbitmap(glyph.bitmap), FontExtent(glyph.metrics)
17+
return glyphbitmap(glyph.bitmap), FontExtent(glyph.metrics)
1818
end
1919

20-
extents(face::FTFont, c::Char, pixelsize::Integer) =
21-
FontExtent(loadglyph(face, c, pixelsize).metrics)
20+
function extents(face::FTFont, c::Char, pixelsize::Integer)
21+
return FontExtent(loadglyph(face, c, pixelsize).metrics)
22+
end
2223

2324
function glyphbitmap(bitmap::FreeType.FT_Bitmap)
2425
@assert bitmap.pixel_mode == FreeType.FT_PIXEL_MODE_GRAY
@@ -32,7 +33,7 @@ function glyphbitmap(bitmap::FreeType.FT_Bitmap)
3233
bmp[:, r] = src
3334
row += bitmap.pitch
3435
end
35-
bmp
36+
return bmp
3637
end
3738

3839
one_or_typemax(::Type{T}) where {T<:Union{Real,Colorant}} = T<:Integer ? typemax(T) : oneunit(T)

src/types.jl

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -31,73 +31,81 @@ struct FontExtent{T}
3131
scale::Vec{2, T}
3232
end
3333

34-
@inline hadvance(ext::FontExtent) = ext.advance[1]
35-
@inline vadvance(ext::FontExtent) = ext.advance[2]
36-
@inline inkwidth(ext::FontExtent) = ext.scale[1]
37-
@inline inkheight(ext::FontExtent) = ext.scale[2]
38-
@inline hbearing_ori_to_left(ext::FontExtent) = ext.horizontal_bearing[1]
39-
@inline hbearing_ori_to_top(ext::FontExtent) = ext.horizontal_bearing[2]
40-
@inline leftinkbound(ext::FontExtent) = hbearing_ori_to_left(ext)
41-
@inline rightinkbound(ext::FontExtent) = leftinkbound(ext) + inkwidth(ext)
42-
@inline bottominkbound(ext::FontExtent) = hbearing_ori_to_top(ext) - inkheight(ext)
43-
@inline topinkbound(ext::FontExtent) = hbearing_ori_to_top(ext)
34+
hadvance(ext::FontExtent) = ext.advance[1]
35+
vadvance(ext::FontExtent) = ext.advance[2]
36+
inkwidth(ext::FontExtent) = ext.scale[1]
37+
inkheight(ext::FontExtent) = ext.scale[2]
38+
hbearing_ori_to_left(ext::FontExtent) = ext.horizontal_bearing[1]
39+
hbearing_ori_to_top(ext::FontExtent) = ext.horizontal_bearing[2]
40+
leftinkbound(ext::FontExtent) = hbearing_ori_to_left(ext)
41+
rightinkbound(ext::FontExtent) = leftinkbound(ext) + inkwidth(ext)
42+
bottominkbound(ext::FontExtent) = hbearing_ori_to_top(ext) - inkheight(ext)
43+
topinkbound(ext::FontExtent) = hbearing_ori_to_top(ext)
4444

4545
BroadcastStyle(::Type{<: FontExtent}) = Style{FontExtent}()
4646
BroadcastStyle(::Style{FontExtent}, x) = Style{FontExtent}()
4747
BroadcastStyle(x, ::Style{FontExtent}) = Style{FontExtent}()
4848

49-
broadcasted(op::Function, f::FontExtent, scaling::StaticVector) =
50-
FontExtent(
49+
function broadcasted(op::Function, f::FontExtent, scaling::StaticVector)
50+
return FontExtent(
5151
op.(f.vertical_bearing, scaling[1]),
5252
op.(f.horizontal_bearing, scaling[2]),
5353
op.(f.advance, scaling),
5454
op.(f.scale, scaling),
5555
)
56+
end
5657

57-
broadcasted(op::Function, f::FontExtent) =
58-
FontExtent(
58+
function broadcasted(op::Function, f::FontExtent)
59+
return FontExtent(
5960
op.(f.vertical_bearing),
6061
op.(f.horizontal_bearing),
6162
op.(f.advance),
6263
op.(f.scale),
6364
)
65+
end
6466

65-
broadcasted(op::Function, ::Type{T}, f::FontExtent) where T =
66-
FontExtent(
67+
function broadcasted(op::Function, ::Type{T}, f::FontExtent) where T
68+
return FontExtent(
6769
map(x-> op(T, x), f.vertical_bearing),
6870
map(x-> op(T, x), f.horizontal_bearing),
6971
map(x-> op(T, x), f.advance),
7072
map(x-> op(T, x), f.scale),
7173
)
74+
end
7275

73-
FontExtent(fontmetric::FreeType.FT_Glyph_Metrics, scale::T = 64.0) where T <: AbstractFloat =
74-
FontExtent(
76+
function FontExtent(fontmetric::FreeType.FT_Glyph_Metrics, scale::T = 64.0) where T <: AbstractFloat
77+
return FontExtent(
7578
Vec{2, T}(fontmetric.vertBearingX, fontmetric.vertBearingY) ./ scale,
7679
Vec{2, T}(fontmetric.horiBearingX, fontmetric.horiBearingY) ./ scale,
7780
Vec{2, T}(fontmetric.horiAdvance, fontmetric.vertAdvance) ./ scale,
7881
Vec{2, T}(fontmetric.width, fontmetric.height) ./ scale
7982
)
83+
end
8084

81-
==(x::FontExtent, y::FontExtent) = (
82-
x.vertical_bearing == y.vertical_bearing &&
83-
x.horizontal_bearing == y.horizontal_bearing &&
84-
x.advance == y.advance &&
85-
x.scale == y.scale
86-
)
85+
function ==(x::FontExtent, y::FontExtent)
86+
return (
87+
x.vertical_bearing == y.vertical_bearing &&
88+
x.horizontal_bearing == y.horizontal_bearing &&
89+
x.advance == y.advance &&
90+
x.scale == y.scale
91+
)
92+
end
8793

88-
FontExtent(fontmetric::FreeType.FT_Glyph_Metrics, scale::Integer) =
89-
FontExtent(
94+
function FontExtent(fontmetric::FreeType.FT_Glyph_Metrics, scale::Integer)
95+
return FontExtent(
9096
div.(Vec{2, Int}(fontmetric.vertBearingX, fontmetric.vertBearingY), scale),
9197
div.(Vec{2, Int}(fontmetric.horiBearingX, fontmetric.horiBearingY), scale),
9298
div.(Vec{2, Int}(fontmetric.horiAdvance, fontmetric.vertAdvance), scale),
9399
div.(Vec{2, Int}(fontmetric.width, fontmetric.height), scale)
94100
)
101+
end
95102

96-
bearing(extent::FontExtent{T}) where T =
97-
Vec2{T}(
103+
function bearing(extent::FontExtent{T}) where T
104+
return Vec2{T}(
98105
+extent.horizontal_bearing[1],
99106
-extent.horizontal_bearing[2],
100107
)
108+
end
101109

102110
function safe_free(face)
103111
ptr = getfield(face, :ft_ptr)
@@ -143,8 +151,9 @@ function Base.getproperty(font::FTFont, fieldname::Symbol)
143151
end
144152
end
145153

146-
Base.show(io::IO, font::FTFont) =
154+
function Base.show(io::IO, font::FTFont)
147155
print(io, "FTFont (family = $(font.family_name), style = $(font.style_name))")
156+
end
148157

149158
# Allow broadcasting over fonts
150159
Base.Broadcast.broadcastable(ft::FTFont) = Ref(ft)

0 commit comments

Comments
 (0)