Editing Module:ItemBox

Warning: You are not logged in. Once you make an edit, a temporary account will be created for you. Learn more. Log in or create an account to continue receiving notifications after this account expires, and to access other features.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision Your text
Line 10: Line 10:
--    .itembox-name      line-height: 1.2; font-size: 1.5em (overridden inline)
--    .itembox-name      line-height: 1.2; font-size: 1.5em (overridden inline)
--  so the name's content box is 8 - 2*0.4 = 7.2em wide and 4.5 - 2*0.5 = 3.5em
--  so the name's content box is 8 - 2*0.4 = 7.2em wide and 4.5 - 2*0.5 = 3.5em
--  tall. Only the ratio and the size limits are read from those figures: the
--  tall. Keep these in step with that stylesheet.
--  size is emitted in cqw against .itembox-name-area, so the browser supplies
--  Glyph widths live in [[Module:TextFit]].
--  the actual width. Glyph widths live in [[Module:TextFit]].
-- ============================================================================
-- ============================================================================
local NAME_W = 7.2
local NAME_W = 7.2
local NAME_H = 3.5
local NAME_H = 3.5
local LINE_H = 1.2
local LINE_H = 1.2
local MAX_EM = 1.5
local MAX_EM = 1.5
local MIN_EM = 0.8
local MIN_EM = 0.8
local SNAP_EM = 0.05  -- keep emitted sizes on a tidy grid


-- Returns the name font size as a cqw string, measured against
-- Returns the name font size as an em string (scales with the card).
-- .itembox-name-area, which [[Template:ItemBox]] makes a query container.
function p.getFontSize(frame)
function p.getFontSize(frame)
     local name = ustring.gsub(frame.args[1] or "", "^%s*(.-)%s*$", "%1")
     local name = ustring.gsub(frame.args[1] or "", "^%s*(.-)%s*$", "%1")
    local max = MAX_EM / NAME_W * 100          -- 20.83cqw
     if name == "" then return string.format("%.2f", MAX_EM) end
     if name == "" then return string.format("%.2fcqw", max) end


     return string.format("%.2fcqw", textfit.fit(name, {
     local pct = textfit.fit(name, {
         aspect    = NAME_H / NAME_W,
         aspect    = NAME_H / NAME_W,
         lineHeight = LINE_H,
         lineHeight = LINE_H,
         max        = max,
         max        = MAX_EM / NAME_W * 100,
         min        = MIN_EM / NAME_W * 100,   -- 11.11cqw
         min        = MIN_EM / NAME_W * 100,
     }))
        bold      = true,  -- .itembox-name is font-weight: bold
     })
 
    -- fit() returns a percentage of the usable width. Convert back to em and
    -- coarsen downward, so a snapped value still fits. The epsilon guards
    -- against binary representation: 1.45 / 0.05 is 28.999999999999996, which
    -- would otherwise floor a whole grid step too low.
    local em = math.floor(pct / 100 * NAME_W / SNAP_EM + 1e-9) * SNAP_EM
    return string.format("%.2f", math.max(em, MIN_EM))
end
end


Please note that all contributions to The Deadlock Wiki are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see Deadlock:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!
Cancel Editing help (opens in new window)
Preview page with this template

Page included on this page: