diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/card.lua | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/card.lua b/lib/card.lua index 474228d..4d94465 100644 --- a/lib/card.lua +++ b/lib/card.lua @@ -44,11 +44,26 @@ end -- values before the next call overwrites them. local extents = cairo_text_extents_t:create() +-- Ink size of a string: how much space the glyphs actually cover. +-- Use this to CENTRE or RIGHT-ALIGN text, never to advance a cursor. function M.measure(cr, s) cairo_text_extents(cr, s, extents) return extents.width, extents.height end +-- How far the cursor moves after drawing a string. Use this to lay out runs of +-- text left to right. +-- +-- Not measure(): that returns the INK width, which ignores leading and +-- trailing spaces because a space carries no ink. Stepping a cursor by the ink +-- width collapses the gaps, and " / " measures 6px of ink against a 14px +-- advance, so a date drawn in segments came out as "16 /SEP /2026" with each +-- slash jammed into the next glyph. +function M.advance(cr, s) + cairo_text_extents(cr, s, extents) + return extents.x_advance +end + -- Right-aligned text: x is the RIGHT edge. function M.text_right(cr, x, y, s) local w = M.measure(cr, s) |
