ws-cleanup-types: archive, audio, data, font, image, layered, music, playlist, subtitle, vector, video: annotations, casts, one value per re-assignment where the solver loses the type
This commit is contained in:
1 parent
dc98aec2ec
commit
f459b2dcdf
44 files changed
+172
-119
No files matched your search
@@ -107,13 +107,13 @@ function Parse.text(s: string): (Desc?, string?)
|
||||
local a: { [string]: string } = {}
|
||||
-- key=value, key="quoted value"
|
||||
local i = 1
|
||||
while i <= #rest do
|
||||
local k, q, e = string.match(rest, '^%s*([%w_]+)="([^"]*)"()', i)
|
||||
while i <= #(rest :: string) do
|
||||
local k, q, e = string.match(rest :: string, '^%s*([%w_]+)="([^"]*)"()', i)
|
||||
if k then
|
||||
a[k] = q
|
||||
i = e
|
||||
else
|
||||
local k2, v2, e2 = string.match(rest, "^%s*([%w_]+)=(%S*)()", i)
|
||||
local k2, v2, e2 = string.match(rest :: string, "^%s*([%w_]+)=(%S*)()", i)
|
||||
if not k2 then
|
||||
break
|
||||
end
|
||||
@@ -135,7 +135,7 @@ function Parse.text(s: string): (Desc?, string?)
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ XML
|
||||
local ENTITIES = { quot = '"', amp = "&", lt = "<", gt = ">", apos = "'" }
|
||||
local ENTITIES: { [string]: string } = { quot = '"', amp = "&", lt = "<", gt = ">", apos = "'" }
|
||||
local function unescape(s: string): string
|
||||
return (
|
||||
string.gsub(s, "&(#?x?%w+);", function(e: string): string?
|
||||
@@ -159,8 +159,8 @@ function Parse.xml(s: string): (Desc?, string?)
|
||||
seenFont = true
|
||||
end
|
||||
local a: { [string]: string } = {}
|
||||
for k, q, v in string.gmatch(attrs, "([%w_]+)%s*=%s*([\"'])(.-)%2") do
|
||||
a[k] = unescape(v)
|
||||
for k, q, v in string.gmatch(attrs :: string, "([%w_]+)%s*=%s*([\"'])(.-)%2") do
|
||||
a[k] = unescape(v :: string)
|
||||
local _ = q
|
||||
end
|
||||
local err = apply(d, tag, a)
|
||||
|
||||
@@ -287,26 +287,28 @@ function Bmfont.bake(font: any, opts: BakeOptions?): (any, Err.Err?)
|
||||
if type(font) ~= "table" or type(font.rasterize) ~= "function" or type(font.glyphIndex) ~= "function" then
|
||||
return nil, Err.new(Err.ARG, "bake: expected an outline Font")
|
||||
end
|
||||
local o = opts or {}
|
||||
local o: BakeOptions = opts or {}
|
||||
local px = if type(o.px) == "number" and o.px > 0 and o.px <= 1024 then o.px else 32
|
||||
local pad = if type(o.padding) == "number" and o.padding >= 0 then math.floor(o.padding) else 1
|
||||
local scale = px / font.unitsPerEm
|
||||
local glyphs = {}
|
||||
local glyphs: { { cp: number, g: number, img: Types.Image } } = {}
|
||||
local area = 0
|
||||
local seen = {}
|
||||
for _, cp in codepoints(o.chars) do
|
||||
local g = font:glyphIndex(cp)
|
||||
local g = (font :: any):glyphIndex(cp)
|
||||
if (g ~= 0 or cp == 0) and not seen[cp] then
|
||||
seen[cp] = true
|
||||
local img = font:rasterize(g, px)
|
||||
local img: Types.Image? = (font :: any):rasterize(g, px)
|
||||
if img then
|
||||
table.insert(glyphs, { cp = cp, g = g, img = img })
|
||||
area += (img.width + pad) * (img.height + pad)
|
||||
end
|
||||
end
|
||||
end
|
||||
local size = o.pageSize
|
||||
if type(size) ~= "number" then
|
||||
local size: number
|
||||
if type(o.pageSize) == "number" then
|
||||
size = o.pageSize
|
||||
else
|
||||
size = 64
|
||||
while size * size < area * 1.3 and size < 4096 do
|
||||
size *= 2
|
||||
|
||||
Reference in new issue
Block a user