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
|
||||
|
||||
@@ -150,9 +150,11 @@ local function glyf(b: buffer, p: number, n: number, maxBytes: number): (any?, s
|
||||
fl = band(fl, 0x7F)
|
||||
local dx, dy
|
||||
if fl < 10 then
|
||||
dx, dy = 0, withSign(fl, band(fl, 14) * 128 + su8(glyphS))
|
||||
dx = 0
|
||||
dy = withSign(fl, band(fl, 14) * 128 + su8(glyphS))
|
||||
elseif fl < 20 then
|
||||
dx, dy = withSign(fl, band(fl - 10, 14) * 128 + su8(glyphS)), 0
|
||||
dx = withSign(fl, band(fl - 10, 14) * 128 + su8(glyphS))
|
||||
dy = 0
|
||||
elseif fl < 84 then
|
||||
local b0 = fl - 20
|
||||
local b1 = su8(glyphS)
|
||||
@@ -181,12 +183,17 @@ local function glyf(b: buffer, p: number, n: number, maxBytes: number): (any?, s
|
||||
end
|
||||
local x0, y0, x1, y1
|
||||
if hasBox(g) then
|
||||
x0, y0, x1, y1 = si16(bboxS), si16(bboxS), si16(bboxS), si16(bboxS)
|
||||
x0 = si16(bboxS)
|
||||
y0 = si16(bboxS)
|
||||
x1 = si16(bboxS)
|
||||
y1 = si16(bboxS)
|
||||
else
|
||||
x0, y0, x1, y1 = 32767, 32767, -32768, -32768
|
||||
for k = 1, total do
|
||||
x0, y0 = math.min(x0, xs[k]), math.min(y0, ys[k])
|
||||
x1, y1 = math.max(x1, xs[k]), math.max(y1, ys[k])
|
||||
x0 = math.min(x0, xs[k])
|
||||
y0 = math.min(y0, ys[k])
|
||||
x1 = math.max(x1, xs[k])
|
||||
y1 = math.max(y1, ys[k])
|
||||
end
|
||||
if total == 0 then
|
||||
x0, y0, x1, y1 = 0, 0, 0, 0
|
||||
|
||||
Reference in new issue
Block a user