WIP: feat/txt-01 #203
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feat/txt-01"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Add bitmap font support with a public text layout
Banjo can now load and use real font files.
This pull request adds bitmap font support, BMFont text and binary descriptors with BMP atlas pages, with a public text layout: a program can place, measure and draw glyphs itself.
It is the first delivery of the text plan.
The API is the product: it was written against the simplest font format, and later stories, TrueType, variable fonts and font fallback, plug into the same types without breaking them.
Pull request for the
feat/txt-01branch.It closes the bitmap font and layout work: the typeface and font couple, the inspectable layout, and the one glyph-drawing call every text drawing goes through.
Added
inc/banjo/font.hbj_typeface: the design read from a font file (glyphs, metrics, spacing); an index selects a face inside files that hold several.bj_load_typeface,bj_destroy_typeface: load and release, with the path passed as a borrowedbj_strview, valid UTF-8 by contract.bj_create_font,bj_destroy_font: derive one usable instance of a typeface at a pixel size; 0 asks for the size the file declares, and any other size fails on a bitmap font, which has the size it was exported at.bj_font_typeface: the typeface a font derives from, as a borrowed pointer for inspection.bj_load_font: the two calls composed, for a program that wants one file at one size; its documentation shows the equivalent code, which is its contract.inc/banjo/text.hbj_glyph_placement: one glyph of a laid-out text, carrying its glyph identifier, its pen position inbj_real, the byte offset of the character it came from, and the font it belongs to; a plain value a program can copy, keep and draw later.bj_text_style: how to compose a text, its font chain as a borrowed array in priority order, its wrap width and its alignments; one style lays out many texts, the text itself is a parameter of each call.bj_layout_text,bj_destroy_text_layout,bj_layout_glyph_count,bj_layout_glyph,bj_layout_bounds,bj_layout_line_count: lay a text out and read everything back, without drawing a pixel; measuring is reading the layout.bj_draw_glyph: the one glyph-drawing function of the library.bj_draw_text_layout: the convenience, lay out, draw every glyph, discard; a client of the layout, never a second engine, so a manual loop over the placements produces identical pixels.src/font.c,src/text.cassets/font/banjo-testfixtures, the descriptor in both encodings with defective variants, and their generator script.Other
test/spec_font.candtest/spec_text.c, one case per example row of the specifications.font-001-typeface-and-font.mdandtext-001-glyph-layout.md, a capability line in the README, and a CHANGELOG entry.Decisions
Per ADR 0009, the text API is a typeface and a font with a public layout.
The typeface is the design read from a font file, and the font is one instance of it at a size; a size is not always enough to describe a font, which is where variable fonts plug in.
A typeface counts its fonts: destroying a typeface handle only marks the typeface, its memory goes when its last font dies, and handles can be destroyed in any order.
Loading in one call is the two-call couple composed, never a second loader.
The layout refuses text that is not valid UTF-8, per ADR 0008.
One glyph-drawing function exists, and every text drawing, the convenience draw included, is that function or a loop over the same layout, so measure and draw cannot drift.
The style struct grows fields in later revisions, and its font chain is a borrowed array rather than a container object, so adding a public symbol waits for a real need.
Compatibility
The existing text engine,
bj_draw_text,bj_blit_text,bj_measure_textandbj_draw_textf, is unchanged and keeps its names until its removal in 2.0.The alignment values are the ones the old engine already uses, so both engines share the same enums while they coexist.
The built-in 8x8 font keeps working as before.
967aafa659a6e6db0209a6e6db0209389a20938a389a20938a9c33e051b62984a2bd59ee8d691ac0ee8d691ac0eda828195ceda828195c08b5aa3d6a08b5aa3d6a055b42008fView command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.