Module:ItemBox: Difference between revisionsGive feedback
Jump to navigation
Jump to search
Halfass solution for somewhat scaling the text on ItemBox |
m added a min font size. |
||
| Line 53: | Line 53: | ||
fontSize = fullSize - (longestLine - 8) * 1 | fontSize = fullSize - (longestLine - 8) * 1 | ||
end | end | ||
fontSize = math.max(6, fontSize) | |||
return fontSize | return fontSize | ||
Revision as of 03:24, 19 May 2026
Documentation for this module may be created at Module:ItemBox/doc
local p = {}
function p.getFontSize(frame)
local name = frame.args[1] or ""
local words = {}
for word in name:gmatch("%S+") do
table.insert(words, word)
end
local function wordWidth(word)
word = word:lower()
local width = 0
for i = 1, #word do
local c = word:sub(i, i)
if c == "i" or c == "l" then
width = width + 0.5
elseif c == "m" or c == "w" then
width = width + 1.5
else
width = width + 1
end
end
return math.ceil(width)
end
local longestLine
if #words == 1 then
longestLine = wordWidth(words[1])
elseif #words == 2 then
longestLine = math.max(wordWidth(words[1]), wordWidth(words[2]))
elseif #words == 3 then
local first = wordWidth(words[1])
local mid = wordWidth(words[2])
local last = wordWidth(words[3])
local shorterOuter = math.min(first, last)
local longerOuter = math.max(first, last)
local combined = mid + 1 + shorterOuter
longestLine = math.max(combined, longerOuter)
end
local fullSize = 15
local fontSize
if longestLine <= 8 then
fontSize = fullSize
else
fontSize = fullSize - (longestLine - 8) * 1
end
fontSize = math.max(6, fontSize)
return fontSize
end
return p