Getting the boundary of fonts as points

I want to plot letters/fonts as curves, hence access to a more point-like representation.

I’m looking for a way to get a point[all pixels] or curve[boundary] representation of fonts maybe normalised within a unit box, not sure if here sizes between different fonts will change a lot. Any packages out there that might help will be appreciated? Thanks.

Probably use FreeType directly although getting the actual glyph data might need a bit of twiddling around with the C api.

I think Harbuzz has an API for glyph outlines, and it has a prepackaged JLL binary for Julia: JuliaHub

But maybe FreeType is easier given https://github.com/JuliaGraphics/FreeType.jl … see also cairo - How to get a glyph outline of a true type character on a linux system - Stack Overflow

It looks like Luxor.jl may provide what you need with a nice high-level interface. For example, this gets a list of points outlining the letter “C” in the current font:

using Luxor
Drawing(500, 500)
newpath()
fontsize(60) # hide
textpath("C")
plist = reduce(vcat, pathtopoly())
1 Like

basic funtionality in Cairo.jl/Samples.md at master · JuliaGraphics/Cairo.jl · GitHub copy_path example.

And this doesn’t work on all fonts.

Ohh… I like this approach and it seems to work really well. Thanks!

Edit: Trying for Latex strings with this approach doesn’t work. Maybe @cormullion ? any hints for a similar function for textpath(L"\alpha") ?

This might be what you’re looking for:

using Luxor
using LaTeXStrings
using MathTeXEngine

@drawsvg begin
	background("black")
	fontsize(120)
	sethue("gold")
	text(L"e^{i\pi} + 1 = 0", Point(0, 0), halign=:center, paths=true)
	pts = pathtopoly()
	for pt in pts
		randomhue()
		poly(pt, :fill)
	end
end

Remember to pay attention to holes… :slight_smile:

3 Likes

This is great! now these can go into RPRMakie! for raytracing :smiley:

1 Like

It will be Beautiful, with you in charge!:joy: