JuliaGraphics / FreeTypeAbstraction.jl

A Julian abstraction layer over FreeType.jl
Other
25 stars 20 forks source link

Layout & FTFont #30

Closed SimonDanisch closed 4 years ago

SimonDanisch commented 4 years ago

Introduces cleaner text layouting and bounding boxes. Also, finally introduces a decent font type, instead of having Vector{Ptr{FT_FaceRec}} everywhere! Helps Makie with text rendering:

using Makie
scene = Scene()

for (text, offset) in zip(["m", "1", "0abc"], Point2f0[(100, 100), (200, 200), (300, 300)])
    glyphs = map(x-> collect(transpose(RGBf0.(Gray.(1 .- (x ./ 255))))), renderface.((face,), collect(text)))
    bbs = glyph_rects(text, face, 1.0)
    positions = map(x-> x.+offset, minimum.(bbs))
    msize = widths.(bbs)
    scatter!(positions, markersize=msize, marker_offset=Vec2f0(0), marker=glyphs, scale_plot=false)
    bbox = reduce(union, bbs)
    lines!(Rect(minimum(bbox) .+ offset, widths(bbox)));
end
scene

image

asinghvi17 commented 4 years ago

@SimonDanisch Artifacts are unusable on pre-1.3 versions. A build stage needs to be added to FreeType, which checks the version and uses BinaryProvider to download the FreeType binaries if not present.