Skip to content

Commit 89dbfd0

Browse files
authored
Merge pull request #60 from knuesel/refactor-f0-rect
Replace Vec2f0 with Vec2f, FRect2D with Rect2f, etc.
2 parents ae4a8f6 + b0fc2ce commit 89dbfd0

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
1313
ColorVectorSpace = "0.8, 0.9"
1414
Colors = "0.11, 0.12"
1515
FreeType = "4"
16-
GeometryBasics = "0.2, 0.3"
16+
GeometryBasics = "0.4.1"
1717
StaticArrays = "0.12, 1.0"
1818
julia = "1"
1919

src/layout.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ iter_or_array(x::StaticArray) = repeated(x)
66

77

88
function metrics_bb(char::Char, font::FTFont, pixel_size)
9-
extent = get_extent(font, char) .* Vec2f0(pixel_size)
9+
extent = get_extent(font, char) .* Vec2f(pixel_size)
1010
mini = bearing(extent)
11-
return Rect2D(mini, Vec2f0(extent.scale)), extent
11+
return Rect2(mini, Vec2f(extent.scale)), extent
1212
end
1313

1414
function boundingbox(char::Char, font::FTFont, pixel_size)
@@ -28,7 +28,7 @@ Newlines will be drawn like any other character.
2828
`fonts` can be a vector of fonts, or a single font.
2929
`scales` can be a single float or a Vec2, or a vector of any of those.
3030
31-
`f` will get called with `(char::Char, glyph_box::Rec2D, glyph_advance::Point2f0)`.
31+
`f` will get called with `(char::Char, glyph_box::Rec2D, glyph_advance::Point2f)`.
3232
3333
`char` is the currently iterated char.
3434
@@ -43,16 +43,16 @@ function iterate_extents(f, line::AbstractString, fonts, scales)
4343
lastpos = 0.0
4444
for (char, scale, font) in iterator
4545
glyph_box, extent = metrics_bb(char, font, scale)
46-
mini = minimum(glyph_box) .+ Vec2f0(lastpos, 0.0)
47-
glyph_box = Rect2D(mini, widths(glyph_box))
48-
glyph_advance = Point2f0(extent.advance)
46+
mini = minimum(glyph_box) .+ Vec2f(lastpos, 0.0)
47+
glyph_box = Rect2(mini, widths(glyph_box))
48+
glyph_advance = Point2f(extent.advance)
4949
lastpos += glyph_advance[1]
5050
f(char, glyph_box, glyph_advance)
5151
end
5252
end
5353

5454
function glyph_rects(line::AbstractString, fonts, scales)
55-
rects = Rect2D[]
55+
rects = Rect2[]
5656
iterate_extents(line, fonts, scales) do char, box, advance
5757
push!(rects, box)
5858
end
@@ -68,13 +68,13 @@ function inkboundingbox(ext::FontExtent)
6868
r = rightinkbound(ext)
6969
b = bottominkbound(ext)
7070
t = topinkbound(ext)
71-
return FRect2D((l, b), (r - l, t - b))
71+
return Rect2f((l, b), (r - l, t - b))
7272
end
7373

7474
function height_insensitive_boundingbox(ext::FontExtent, font::FTFont)
7575
l = leftinkbound(ext)
7676
r = rightinkbound(ext)
7777
b = descender(font)
7878
t = ascender(font)
79-
return FRect2D((l, b), (r - l, t - b))
79+
return Rect2f((l, b), (r - l, t - b))
8080
end

src/types.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function FontExtent(fontmetric::FreeType.FT_Glyph_Metrics, scale::Integer)
102102
end
103103

104104
function bearing(extent::FontExtent)
105-
return Vec2f0(extent.horizontal_bearing[1],
105+
return Vec2f(extent.horizontal_bearing[1],
106106
-(extent.scale[2] - extent.horizontal_bearing[2]))
107107
end
108108

@@ -115,7 +115,7 @@ end
115115

116116
function boundingbox(extent::FontExtent)
117117
mini = bearing(extent)
118-
return Rect2D(mini, Vec2f0(extent.scale))
118+
return Rect2(mini, Vec2f(extent.scale))
119119
end
120120

121121
mutable struct FTFont
@@ -176,10 +176,10 @@ function kerning(c1::Char, c2::Char, face::FTFont)
176176
kerning2d = Ref{FreeType.FT_Vector}()
177177
err = FT_Get_Kerning(face, i1, i2, FreeType.FT_KERNING_DEFAULT, kerning2d)
178178
# Can error if font has no kerning! Since that's somewhat expected, we just return 0
179-
err != 0 && return Vec2f0(0)
179+
err != 0 && return Vec2f(0)
180180
# 64 since metrics are in 1/64 units (units to 26.6 fractional pixels)
181181
divisor = 64
182-
return Vec2f0(kerning2d[].x / divisor, kerning2d[].y / divisor)
182+
return Vec2f(kerning2d[].x / divisor, kerning2d[].y / divisor)
183183
end
184184

185185
function get_extent(face::FTFont, char::Char)

0 commit comments

Comments
 (0)