-- @titre Chiffres à chasse fixe -- @title Fixed-width figures -- @categorie espacer -- @resume Donne aux dix chiffres la même chasse dans chaque master (la plus large des dix) et centre chaque dessin, ancres comprises. Pour des chiffres tabulaires en plus des chiffres par défaut, préférez Automatisations › Chiffres tabulaires. -- @summary Gives the ten digits the same advance width in every master (the widest of the ten) and centres each drawing, anchors included. For tabular figures alongside the default ones, use Automations › Tabular figures instead. -- Fontista · bibliothèque de scripts · https://fontista.thinkspark.dev/scripts.html local DIGITS = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" } local en = lang == "en" local function xrange(contours) local a, b = nil, nil for _, c in ipairs(contours) do for _, nd in ipairs(c.nodes) do if not a or nd.x < a then a = nd.x end if not b or nd.x > b then b = nd.x end end end return a, b end for _, m in ipairs(font.masters) do local widest = 0 for _, g in ipairs(DIGITS) do local l = layer(g, m.id) if l and l.width > widest then widest = l.width end end local moved = 0 for _, g in ipairs(DIGITS) do local l = layer(g, m.id) if l and #l.contours > 0 and #components(g, m.id) == 0 then local a, b = xrange(l.contours) local dx = (widest - (b - a)) / 2 - a for _, c in ipairs(l.contours) do for _, nd in ipairs(c.nodes) do nd.x = nd.x + dx end end set_contours(g, m.id, l.contours) for name, p in pairs(anchors(g, m.id)) do set_anchor(g, m.id, name, p.x + dx, p.y) end set_width(g, m.id, widest) moved = moved + 1 elseif l then set_width(g, m.id, widest) end end print(string.format(en and "%s: %d figure(s) centred on %.0f units" or "%s : %d chiffre(s) centré(s) sur %.0f unités", m.name, moved, widest)) end