Editing Module:ItemBoxGive feedback
Jump to navigation
Jump to search
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 1: | Line 1: | ||
local p = {} | 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 | |||
local | width = width + 0.5 | ||
local | elseif c == "m" or c == "w" then | ||
local | 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 | end | ||
return fontSize | |||
return | |||
end | end | ||
return p | return p | ||