Skip to content

Commit f93b5cd

Browse files
committed
fix tests
1 parent dfee5ff commit f93b5cd

File tree

4 files changed

+21
-49
lines changed

4 files changed

+21
-49
lines changed

src/layout.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ iter_or_array(x::StaticArray) = repeated(x)
88
function metrics_bb(char::Char, font::FTFont, pixel_size)
99
extent = get_extent(font, char) .* Vec2f0(pixel_size)
1010
mini = bearing(extent)
11-
return Rect2D(mini, Vec2f0(extent.pixel_size)), extent
11+
return Rect2D(mini, Vec2f0(extent.scale)), extent
12+
end
13+
14+
function boundingbox(char::Char, font::FTFont, pixel_size)
15+
bb, extent = metrics_bb(char, font, pixel_size)
16+
return bb
1217
end
1318

1419
function glyph_ink_size(char::Char, font::FTFont, pixel_size)

src/rendering.jl

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11

2+
function loadchar(face::FTFont, c::Char)
3+
err = FT_Load_Char(face, c, FT_LOAD_RENDER)
4+
check_error(err, "Could not load char to render.")
5+
end
6+
27
function renderface(face::FTFont, c::Char, pixelsize::Integer)
38
set_pixelsize(face, pixelsize)
49
loadchar(face, c)
510
glyph = face.glyph
611
@assert glyph.format == FreeType.FT_GLYPH_FORMAT_BITMAP
7-
return glyphbitmap(glyph.bitmap), get_extent(face, c)
12+
return glyphbitmap(glyph.bitmap), FontExtent(glyph.metrics)
813
end
914

1015
function glyphbitmap(bitmap::FreeType.FT_Bitmap)
@@ -45,17 +50,17 @@ function renderstring!(
4550

4651
if pixelsize isa Tuple
4752
@warn "using tuple for pixelsize is deprecated, please use one integer"
48-
set_pixelsize(face, pixelsize[1])
49-
else
50-
set_pixelsize(face, pixelsize)
53+
pixelsize = pixelsize[1]
5154
end
5255

56+
set_pixelsize(face, pixelsize)
57+
5358
bitmaps = Vector{Matrix{UInt8}}(undef, lastindex(str))
5459
metrics = Vector{FontExtent{Int}}(undef, lastindex(str))
5560
ymin = ymax = sumadvancex = 0
5661

5762
for (istr, char) = enumerate(str)
58-
bitmap, metric_float = renderface(face, char)
63+
bitmap, metric_float = renderface(face, char, pixelsize)
5964
metric = round.(Int, metric_float)
6065
bitmaps[istr] = bitmap
6166
metrics[istr] = metric

src/types.jl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,6 @@ function kerning(c1::Char, c2::Char, face::FTFont)
185185
return Vec2f0(kerning2d[].x / divisor, kerning2d[].y / divisor)
186186
end
187187

188-
function loadchar(face::FTFont, c::Char)
189-
err = FT_Load_Char(face, c, FT_LOAD_RENDER | FT_LOAD_NO_HINTING)
190-
check_error(err, "Could not load char to render.")
191-
end
192-
193188
function get_extent(face::FTFont, char::Char)
194189
if use_cache(face)
195190
get!(get_cache(face), char) do

test/runtests.jl

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,20 @@
11
using FreeTypeAbstraction, Colors, ColorVectorSpace, GeometryBasics
22
using Test
3-
using FreeTypeAbstraction: boundingbox, Vec, glyph_rects, get_extent, FTFont, kerning
3+
using FreeTypeAbstraction: boundingbox, Vec, glyph_rects, get_extent, FTFont, kerning, glyph_ink_size
44
using FreeType
55

66
face = FreeTypeAbstraction.findfont("hack"; additional_fonts=@__DIR__)
77

8-
FreeTypeAbstraction.get_pixelsize(face)
9-
FreeTypeAbstraction.set_pixelsize(face, 122)
10-
FreeTypeAbstraction.set_pixelsize(face, 64)
11-
err = FT_Load_Char(face, 'm', FT_LOAD_DEFAULT)
12-
metrics = face.glyph.metrics
13-
# 64 since metrics are in 1/64 units (units to 26.6 fractional pixels)
14-
FontExtent(metrics, 64.0)
15-
16-
17-
18-
19-
20-
21-
22-
23-
err = FT_Load_Char(face, 'm', FT_LOAD_NO_AUTOHINT)
24-
metrics = face.glyph.metrics
25-
# 64 since metrics are in 1/64 units (units to 26.6 fractional pixels)
26-
FontExtent(metrics, 1.0)
27-
28-
29-
30-
31-
32-
33-
34-
35-
36-
37-
38-
39-
bb = boundingbox("asdasd", face, 1.0)
40-
@test bb == Rect(4.0, -1.0, 224.0, 50.0)
8+
bb = boundingbox("asdasd", face, 64)
9+
@test round.(Int, minimum(bb)) == Vec(4, -1)
10+
@test round.(Int, widths(bb)) == Vec2(221, 50)
4111

4212
FA = FreeTypeAbstraction
4313

4414
FA.set_pixelsize(face, 64) # should be the default
45-
img, extent = renderface(face, 'C')
15+
img, extent = renderface(face, 'C', 64)
4616
@test size(img) == (30, 49)
4717
@test typeof(img) == Array{UInt8,2}
48-
@test extent == FontExtent{Float32}(Float32[-15.0, 6.0], Float32[4.0, 48.0], Float32[39.0, 62.0], Float32[30.0, 49.0])
49-
img, extent = renderface(face, 'C', 200)
50-
@test round.(Int, widths(FA.boundingbox(extent))) == Vec(size(img))
5118

5219
a = renderstring!(zeros(UInt8, 20, 100), "helgo", face, 10, 10, 10)
5320

0 commit comments

Comments
 (0)