defmodule GitGud.Badges.Native do
@moduledoc """
The `native/gitgud_badge` Rustler NIF: B612 Mono glyph outlines and
SVG-to-PNG rendering.
Badge lettering is drawn as paths instead of `<text>`. An SVG that
another site loads through `<img>` can't fetch a web font, so `<text>`
would render in whatever monospace the reader happens to have, and
the PNG renderer would need a font stack of its own. As outlines, the
SVG and the PNG are the same drawing everywhere. The font (SIL OFL
1.1) is compiled into the NIF; `resvg` is built without its text
features, so neither image needs fontconfig or any other system
library.
"""
use Rustler, otp_app: :git_gud, crate: "gitgud_badge"
@doc "One B612 Mono character's advance as a fraction of the font size."
@spec advance_em() :: float()
def advance_em, do: :erlang.nif_error(:nif_not_loaded)
@doc """
How wide `text` draws at `size` px. B612 Mono is monospaced, but the
emoji it falls back to for what it lacks aren't.
"""
@spec text_width(String.t(), boolean(), float()) :: float()
def text_width(_text, _bold, _size), do: :erlang.nif_error(:nif_not_loaded)
@doc """
`text` as an SVG path `d`, at `size` px, starting at `x` on `baseline`.
All three numbers must be floats.
"""
@spec text_path(String.t(), boolean(), float(), float(), float()) :: String.t()
def text_path(_text, _bold, _size, _x, _baseline), do: :erlang.nif_error(:nif_not_loaded)
@doc "PNG bytes for `svg`, rendered at `zoom` times its own size."
@spec rasterize(String.t(), float()) :: {:ok, binary()} | {:error, String.t()}
def rasterize(_svg, _zoom), do: :erlang.nif_error(:nif_not_loaded)
end
neiam
/gitgud
Git Gud
public · Issues · Pulls · Labels · Forks · Compare · Actions success · Badges · Packages
⭐
1
Log in to mark this repository.
1.6 KiB · text
History
b868907