Faster glyph baking (new font sizes): @native rasterizer/rect packer/pixel loops, glyph shape cache, reused rasterizer scratch (edges, points, active edges, scanlines); fix leaked global 'step'

This commit is contained in:
4DBug committed 2026-10-17 08:57:15 -05:00
1 parent 25a7387642
commit 3a4fc158fa
8 files changed
+452 -39

No files matched your search

+1 -1
View File
@@ -1 +1 @@
[[46, "imgui.lua"], [22664, "imgui_demo.lua"], [34521, "imgui_draw.lua"], [42858, "imgui_h.lua"], [45861, "roblox/raster.lua"], [46337, "roblox/textures.lua"], [46508, "roblox/layers.lua"], [46845, "roblox/overlays.lua"], [46926, "roblox/render.lua"], [47771, "roblox/parallel.lua"], [48170, "imgui_impl_roblox.lua"], [48671, "imgui_impl_roblox_fonts.lua"], [55074, "imgui_internal.lua"], [59040, "imgui_tables.lua"], [64132, "imgui_widgets.lua"], [76373, "imstb_rectpack.lua"], [77037, "imstb_textedit.lua"], [78579, "imstb_truetype.lua"], [81367, "imstd_minstdio.lua"]]
[[46, "imgui.lua"], [22664, "imgui_demo.lua"], [34521, "imgui_draw.lua"], [42861, "imgui_h.lua"], [45864, "roblox/raster.lua"], [46340, "roblox/textures.lua"], [46511, "roblox/layers.lua"], [46848, "roblox/overlays.lua"], [46929, "roblox/render.lua"], [47774, "roblox/parallel.lua"], [48173, "imgui_impl_roblox.lua"], [48674, "imgui_impl_roblox_fonts.lua"], [55077, "imgui_internal.lua"], [59045, "imgui_tables.lua"], [64137, "imgui_widgets.lua"], [76378, "imstb_rectpack.lua"], [77055, "imstb_textedit.lua"], [78597, "imstb_truetype.lua"], [81504, "imstd_minstdio.lua"]]
+150 -12
View File
@@ -34569,6 +34569,7 @@ end
--- @param buf char[] # 1-based
--- @param base int # 1-based start index
--- @param u32 ImU32
@native
local function write_u32(buf, base, u32)
buf[base + 0] = bit32.band(u32, 0xFF)
buf[base + 1] = bit32.band(bit32.rshift(u32, 8), 0xFF)
@@ -35298,6 +35299,7 @@ end
--- @param dst_pitch int
--- @param w int
--- @param h int
@native
function ImFontAtlasTextureBlockConvert(src_pixels, src_fmt, src_pitch, dst_pixels, dst_pixels_base, dst_fmt, dst_pitch, w, h)
assert(src_pixels ~= nil and dst_pixels ~= nil)
local src_pixels_base = 1
@@ -35315,7 +35317,8 @@ function ImFontAtlasTextureBlockConvert(src_pixels, src_fmt, src_pitch, dst_pixe
local alpha = src_pixels[src_pixels_base + 0]
src_pixels_base = src_pixels_base + 1
write_u32(dst_pixels, dst_pixels_base, IM_COL32(255, 255, 255, alpha))
-- [Luau] inline write_u32(dst_pixels, dst_pixels_base, IM_COL32(255, 255, 255, alpha))
dst_pixels[dst_pixels_base] = 255; dst_pixels[dst_pixels_base + 1] = 255; dst_pixels[dst_pixels_base + 2] = 255; dst_pixels[dst_pixels_base + 3] = alpha
dst_pixels_base = dst_pixels_base + 4
end
@@ -55392,13 +55395,15 @@ end
--- @param s table # 1-based
--- @param c any
--- @param n int
@native
function ImStd.memset(s, c, n)
for i = 1, n do s[i] = c end
end
do
local _memmove = function(dest, dest_start, src, src_start, count)
@native
local function _memmove(dest, dest_start, src, src_start, count)
if count <= 0 then return end
local c = (dest == src and dest_start >= src_start)
@@ -76477,6 +76482,7 @@ local STBRP__PREV_LINK_TYPE = {
--- @return stbrp_rect
--- @nodiscard
@native
local function stbrp_rect()
return {
-- reserved for your use:
@@ -76500,6 +76506,7 @@ end
--- @return stbrp_node
--- @nodiscard
@native
local function stbrp_node()
return {
x = 0,
@@ -76521,6 +76528,7 @@ end
--- @return stbrp_context
--- @nodiscard
@native
local function stbrp_context()
return {
width = 0,
@@ -76543,6 +76551,7 @@ end
--- @field prev_link_type? int
--- @return stbrp__findresult
@native
local function stbrp__findresult()
return {
x = 0,
@@ -76563,6 +76572,7 @@ end
-- If you call init again, this will be reset to the default.
--- @param context stbrp_context
--- @param heuristic int
@native
local function stbrp_setup_heuristic(context, heuristic)
if context.init_mode == STBRP__INIT_skyline then
STBRP_ASSERT(heuristic == STBRP_HEURISTIC_Skyline.BL_sortHeight or heuristic == STBRP_HEURISTIC_Skyline.BF_sortHeight)
@@ -76577,6 +76587,7 @@ end
-- If you call init again, this will be reset to the default (false).
--- @param context stbrp_context
--- @param allow_out_of_mem boolean
@native
local function stbrp_setup_allow_out_of_mem(context, allow_out_of_mem)
if allow_out_of_mem then
-- if it's ok to run out of memory, then don't bother aligning them;
@@ -76620,6 +76631,7 @@ end
--- @param height int
--- @param nodes stbrp_node[]
--- @param num_nodes int
@native
function stbrp_init_target(context, width, height, nodes, num_nodes)
for i = 1, num_nodes - 1 do
nodes[i].next = nodes[i + 1]
@@ -76650,6 +76662,7 @@ end
--- @param x0 int
--- @param width int
--- @return int, int
@native
local function stbrp__skyline_find_min_y(c, first, x0, width)
local node = first
local x1 = x0 + width
@@ -76697,6 +76710,7 @@ end
--- @param width int
--- @param height int
--- @return stbrp__findresult
@native
local function stbrp__skyline_find_best_pos(c, width, height)
local best_waste = bit32.lshift(1, 30)
local best_x = 0
@@ -76826,6 +76840,7 @@ end
--- @param width int
--- @param height int
--- @return stbrp__findresult
@native
local function stbrp__skyline_pack_rectangle(context, width, height)
-- find best position according to heuristic
local res = stbrp__skyline_find_best_pos(context, width, height)
@@ -76894,6 +76909,7 @@ end
--- @param b stbrp_rect
--- @return bool
--- @package
@native
local function rect_height_compare(a, b)
if a.h > b.h then
return true
@@ -76908,6 +76924,7 @@ end
--- @param b stbrp_rect
--- @return bool
--- @package
@native
local function rect_original_order(a, b)
return a.was_packed < b.was_packed
end
@@ -76939,6 +76956,7 @@ end
--- @param rects stbrp_rect[]
--- @param num_rects int
--- @return int
@native
local function stbrp_pack_rects(context, rects, num_rects)
local all_rects_packed = 1
@@ -78746,7 +78764,7 @@ local stbtt_MakeGlyphBitmapSubpixelPrefilter
local stbtt_GetFontVMetrics
local stbtt__GetGlyphInfoT2
local stbtt__GetGlyphShapeT2
local stbtt_GetGlyphShape
local stbtt_GetGlyphShape, stbtt_GetGlyphShapeUncached
local stbtt_GetGlyphBitmapBox
local stbtt_GetGlyphBitmapBoxSubpixel
local stbtt_GetGlyphHMetrics
@@ -78799,6 +78817,7 @@ local trunc = function(x)
end
end
@native
local function STBTT__NOTUSED(_) return end
--- @alias stbtt_int32 int
@@ -78821,6 +78840,7 @@ local unsigned_char = stbtt_uint8
--- @param initial_offset? int
--- @return stbtt__buf
--- @nodiscard
@native
local function stbtt__buf(initial_offset)
return {
data = nil,
@@ -78855,6 +78875,7 @@ end
--- @field fdselect stbtt__buf # map from glyph to fontdict
--- @return stbtt_fontinfo
@native
function stbtt_fontinfo()
return {
data = nil,
@@ -78895,6 +78916,7 @@ end
--- @return stbtt_vertex
--- @nodiscard
@native
local function stbtt_vertex()
return {
x = nil,
@@ -78924,6 +78946,7 @@ end
--- @return stbtt__csctx
--- @nodiscard
@native
local function stbtt__csctx()
return {
bounds = false,
@@ -78945,6 +78968,7 @@ end
--- @param bounds bool
--- @return stbtt__csctx
--- @nodiscard
@native
local function STBTT__CSCTX_INIT(bounds)
local this = stbtt__csctx()
@@ -78978,6 +79002,7 @@ end
--- @return stbtt__edge
--- @nodiscard
@native
local function stbtt__edge()
return {
x0 = nil,
@@ -78992,6 +79017,7 @@ end
--- @return stbtt__active_edge
--- @nodiscard
@native
local function stbtt__active_edge()
return {
next = nil,
@@ -79006,8 +79032,15 @@ end
--- @return stbtt__active_edge
--- @nodiscard
local active_pool, active_pool_n = {}, 0 -- [Luau] reused per stbtt__rasterize_sorted_edges() call (C: stbtt__hheap)
@native
local function stbtt__new_active(e, off_x, start_point)
local z = stbtt__active_edge()
active_pool_n = active_pool_n + 1
local z = active_pool[active_pool_n]
if z == nil then
z = stbtt__active_edge()
active_pool[active_pool_n] = z
end
local dxdy = (e.x1 - e.x0) / (e.y1 - e.y0)
z.fdx = dxdy
@@ -79031,6 +79064,7 @@ end
--- @return stbtt__bitmap
--- @nodiscard
@native
local function stbtt__bitmap()
return {
w = nil,
@@ -79046,6 +79080,7 @@ end
--- @return stbtt__point
--- @nodiscard
@native
local function stbtt__point() return { x = nil, y = nil } end
----------------------------------------------
@@ -79056,6 +79091,7 @@ local function stbtt__point() return { x = nil, y = nil } end
---
--- @param b stbtt__buf
@native
local function stbtt__buf_get8(b)
if b.cursor >= b.size then return 0 end
local result = b.data[b.offset + b.cursor + 1]
@@ -79064,6 +79100,7 @@ local function stbtt__buf_get8(b)
end
--- @param b stbtt__buf
@native
local function stbtt__buf_peek8(b)
if b.cursor >= b.size then return 0 end
return b.data[b.offset + b.cursor + 1]
@@ -79071,6 +79108,7 @@ end
--- @param b stbtt__buf
--- @param o int
@native
local function stbtt__buf_seek(b, o)
STBTT_assert(not (o > b.size or o < 0))
if o > b.size or o < 0 then
@@ -79082,10 +79120,12 @@ end
--- @param b stbtt__buf
--- @param o int
@native
local function stbtt__buf_skip(b, o)
stbtt__buf_seek(b, b.cursor + o)
end
@native
local function stbtt__buf_get(b, n)
local v = 0
STBTT_assert(n >= 1 and n <= 4)
@@ -79100,6 +79140,7 @@ end
--- @param offset? int
--- @return stbtt__buf
--- @nodiscard
@native
local function stbtt__new_buf(p, size, offset)
local r = stbtt__buf(offset)
STBTT_assert(size < 0x40000000)
@@ -79110,8 +79151,10 @@ local function stbtt__new_buf(p, size, offset)
end
--- @param b stbtt__buf
@native
local function stbtt__buf_get16(b) return stbtt__buf_get(b, 2) end
--- @param b stbtt__buf
@native
local function stbtt__buf_get32(b) return stbtt__buf_get(b, 4) end
--- @param b stbtt__buf
@@ -79119,6 +79162,7 @@ local function stbtt__buf_get32(b) return stbtt__buf_get(b, 4) end
--- @param s int
--- @return stbtt__buf
--- @nodiscard
@native
local function stbtt__buf_range(b, o, s)
local r = stbtt__new_buf(nil, 0)
if (o < 0 or s < 0 or o > b.size or s > (b.size - o)) then
@@ -79131,6 +79175,7 @@ local function stbtt__buf_range(b, o, s)
end
--- @param b stbtt__buf
@native
local function stbtt__cff_get_index(b)
local count, start, offsize
start = b.cursor
@@ -79145,6 +79190,7 @@ local function stbtt__cff_get_index(b)
end
--- @param b stbtt__buf
@native
local function stbtt__cff_int(b)
local b0 = stbtt__buf_get8(b)
if b0 >= 32 and b0 <= 246 then return b0 - 139
@@ -79158,6 +79204,7 @@ local function stbtt__cff_int(b)
end
--- @param b stbtt__buf
@native
local function stbtt__cff_skip_operand(b)
local v
local b0 = stbtt__buf_peek8(b)
@@ -79179,6 +79226,7 @@ end
--- @param key int
--- @return stbtt__buf
--- @nodiscard
@native
local function stbtt__dict_get(b, key)
stbtt__buf_seek(b, 0)
while b.cursor < b.size do
@@ -79200,6 +79248,7 @@ end
--- @param outcount int
--- @return int[]
--- @nodiscard
@native
local function stbtt__dict_get_ints(b, key, outcount)
local operands = stbtt__dict_get(b, key)
local out = {}
@@ -79211,6 +79260,7 @@ local function stbtt__dict_get_ints(b, key, outcount)
end
--- @param b stbtt__buf
@native
local function stbtt__cff_index_count(b)
stbtt__buf_seek(b, 0)
return stbtt__buf_get16(b)
@@ -79220,6 +79270,7 @@ end
--- @param i int
--- @return stbtt__buf
--- @nodiscard
@native
local function stbtt__cff_index_get(b, i)
local count, offsize, start, _end
stbtt__buf_seek(b, 0)
@@ -79263,17 +79314,26 @@ end
--- stbtt_GetNumberOfFonts_internal
--- stbtt__get_svg
@native
local function ttUSHORT(p, offset) return stbtt_uint16(p[offset + 1] * 256 + p[offset + 2]) end
@native
local function ttSHORT(p, offset) return stbtt_int16(p[offset + 1] * 256 + p[offset + 2]) end
@native
local function ttULONG(p, offset) return stbtt_uint32(bit32.lshift(p[offset + 1], 24) + bit32.lshift(p[offset + 2], 16) + bit32.lshift(p[offset + 3], 8) + p[offset + 4]) end
@native
local function ttLONG(p, offset) return stbtt_int32(bit32.lshift(p[offset + 1], 24) + bit32.lshift(p[offset + 2], 16) + bit32.lshift(p[offset + 3], 8) + p[offset + 4]) end
@native
local function ttBYTE(p, offset) return stbtt_uint8(p[offset + 1]) end
@native
local function ttCHAR(p, offset) return stbtt_int8(p[offset + 1]) end
@native
local function stbtt_tag4(p, c0, c1, c2, c3, offset) offset = offset or 0; return p[offset + 1] == c0 and p[offset + 2] == c1 and p[offset + 3] == c2 and p[offset + 4] == c3 end
@native
local function stbtt_tag(p, str, offset) local c0, c1, c2, c3 = string.byte(str, 1, 4); return stbtt_tag4(p, c0, c1, c2, c3, offset) end
@native
local function stbtt__isfont(font)
-- check the version number
if stbtt_tag4(font, 49, 0, 0, 0) then return true end -- TrueType 1
@@ -79285,6 +79345,7 @@ local function stbtt__isfont(font)
end
-- @OPTIMIZE: binary search
@native
local function stbtt__find_table(data, font_start, tag)
local num_tables = ttUSHORT(data, font_start + 4)
local tabledir = font_start + 12
@@ -79297,6 +79358,7 @@ local function stbtt__find_table(data, font_start, tag)
return 0
end
@native
local function stbtt_GetFontOffsetForIndex_internal(font_collection, index)
-- if it's just a font, there's only one valid index
if stbtt__isfont(font_collection) then
@@ -79320,6 +79382,7 @@ end
--- @param cff stbtt__buf
--- @param fontdict stbtt__buf
@native
local function stbtt__get_subrs(cff, fontdict)
local private_loc = stbtt__dict_get_ints(fontdict, 18, 2)
if (private_loc[2] == 0 or private_loc[1] == 0) then
@@ -79335,6 +79398,7 @@ local function stbtt__get_subrs(cff, fontdict)
end
--- @return bool
@native
local function stbtt_InitFont_internal(info, data, fontstart)
local cmap
local numTables
@@ -79462,6 +79526,7 @@ end
-- Returns 0 if the character codepoint is not defined in the font.
--- @param info stbtt_fontinfo
--- @param unicode_codepoint int
@native
function stbtt_FindGlyphIndex(info, unicode_codepoint)
local data = info.data
local index_map = info.index_map
@@ -79567,6 +79632,7 @@ end
--- @param y stbtt_int32
--- @param cx stbtt_int32
--- @param cy stbtt_int32
@native
local function stbtt_setvertex(v, vtx_type, x, y, cx, cy)
v.type = vtx_type
v.x = (stbtt_int16)(x)
@@ -79575,6 +79641,7 @@ local function stbtt_setvertex(v, vtx_type, x, y, cx, cy)
v.cy = (stbtt_int16)(cy)
end
@native
local function stbtt__GetGlyfOffset(info, glyph_index)
STBTT_assert(info.cff.size == 0)
@@ -79595,6 +79662,7 @@ end
-- Gets the bounding box of the visible part of the glyph, in unscaled coordinates
--- @return integer, integer?, integer?, integer?, integer?
@native
local function stbtt_GetGlyphBox(info, glyph_index)
local n, x0, y0, x1, y1
@@ -79623,6 +79691,7 @@ end
--- @param scy stbtt_int32
--- @param cx stbtt_int32
--- @param cy stbtt_int32
@native
local function stbtt__close_shape(vertices, num_vertices, was_off, start_off, sx, sy, scx, scy, cx, cy)
if start_off then
if was_off then
@@ -79647,6 +79716,7 @@ end
--- @param glyph_index int
--- @return int num_vertices
--- @return stbtt_vertex[]? vertices
@native
local function stbtt__GetGlyphShapeTT(info, glyph_index)
local data = info.data
local num_vertices
@@ -79866,7 +79936,7 @@ local function stbtt__GetGlyphShapeTT(info, glyph_index)
n = STBTT_sqrt(mtx[3] * mtx[3] + mtx[4] * mtx[4])
-- Get indexed glyph.
comp_num_vertices, comp_verts = stbtt_GetGlyphShape(info, gidx)
comp_num_vertices, comp_verts = stbtt_GetGlyphShapeUncached(info, gidx) -- [Luau] transformed in place below: must be a fresh copy
if comp_num_vertices > 0 then
-- Transform vertices.
for i = 1, comp_num_vertices do
@@ -79904,6 +79974,7 @@ end
--- @param c stbtt__csctx
--- @param x stbtt_int32
--- @param y stbtt_int32
@native
local function stbtt__track_vertex(c, x, y)
if x > c.max_x or not c.started then c.max_x = x end
if y > c.max_y or not c.started then c.max_y = y end
@@ -79920,6 +79991,7 @@ end
--- @param cy stbtt_int32
--- @param cx1 stbtt_int32
--- @param cy1 stbtt_int32
@native
local function stbtt__csctx_v(c, vtx_type, x, y, cx, cy, cx1, cy1)
if c.bounds then
stbtt__track_vertex(c, x, y)
@@ -79935,6 +80007,7 @@ local function stbtt__csctx_v(c, vtx_type, x, y, cx, cy, cx1, cy1)
end
--- @param ctx stbtt__csctx
@native
local function stbtt__csctx_close_shape(ctx)
if ctx.first_x ~= ctx.x or ctx.first_y ~= ctx.y then
stbtt__csctx_v(ctx, STBTT_VTX.LINE, trunc(ctx.first_x), trunc(ctx.first_y), 0, 0, 0, 0)
@@ -79944,6 +80017,7 @@ end
--- @param ctx stbtt__csctx
--- @param dx float
--- @param dy float
@native
local function stbtt__csctx_rmove_to(ctx, dx, dy)
stbtt__csctx_close_shape(ctx)
ctx.x = ctx.x + dx
@@ -79956,6 +80030,7 @@ end
--- @param ctx stbtt__csctx
--- @param dx float
--- @param dy float
@native
local function stbtt__csctx_rline_to(ctx, dx, dy)
ctx.x = ctx.x + dx
ctx.y = ctx.y + dy
@@ -79969,6 +80044,7 @@ end
--- @param dy2 float
--- @param dx3 float
--- @param dy3 float
@native
local function stbtt__csctx_rccurve_to(ctx, dx1, dy1, dx2, dy2, dx3, dy3)
local cx1 = ctx.x + dx1
local cy1 = ctx.y + dy1
@@ -79979,6 +80055,7 @@ local function stbtt__csctx_rccurve_to(ctx, dx1, dy1, dx2, dy2, dx3, dy3)
stbtt__csctx_v(ctx, STBTT_VTX.CUBIC, trunc(ctx.x), trunc(ctx.y), trunc(cx1), trunc(cy1), trunc(cx2), trunc(cy2))
end
@native
local function stbtt__get_subr(idx, n)
local count = stbtt__cff_index_count(idx)
local bias = 107
@@ -79994,6 +80071,7 @@ local function stbtt__get_subr(idx, n)
return stbtt__cff_index_get(idx, n)
end
@native
local function stbtt__cid_get_glyph_subrs(info, glyph_index)
local fdselect = info.fdselect
local fdselector = -1
@@ -80024,6 +80102,7 @@ end
--- @param info stbtt_fontinfo
--- @param glyph_index int
--- @param c stbtt__csctx
@native
local function stbtt__run_charstring(info, glyph_index, c)
local in_header = true
local maskbits = 0
@@ -80297,6 +80376,7 @@ end
--- @param glyph_index int
--- @return int num_vertices
--- @return stbtt_vertex[]? vertices
@native
function stbtt__GetGlyphShapeT2(info, glyph_index)
-- runs the charstring twice, once to count and once to output (to avoid realloc)
local vertices = nil
@@ -80322,6 +80402,7 @@ end
--- @return int y0
--- @return int x1
--- @return int y1
@native
function stbtt__GetGlyphInfoT2(info, glyph_index)
local c = STBTT__CSCTX_INIT(true)
local r = stbtt__run_charstring(info, glyph_index, c)
@@ -80343,7 +80424,8 @@ end
-- its x,y, using cx,cy as the bezier control point.
--- @param info stbtt_fontinfo
--- @param glyph_index int
function stbtt_GetGlyphShape(info, glyph_index)
@native
function stbtt_GetGlyphShapeUncached(info, glyph_index)
if info.cff.size == 0 then
return stbtt__GetGlyphShapeTT(info, glyph_index)
else
@@ -80351,11 +80433,32 @@ function stbtt_GetGlyphShape(info, glyph_index)
end
end
@native
function stbtt_GetGlyphShape(info, glyph_index)
-- [Luau] shapes don't depend on the size: cache them per font (baking a new size re-used to re-parse every glyph).
-- Callers only read the vertices (stbtt_FreeShape is a no-op).
local cache = info._ShapeCache
if cache == nil then cache = {}; info._ShapeCache = cache end
local e = cache[glyph_index]
if e == nil then
local n, v
if info.cff.size == 0 then
n, v = stbtt__GetGlyphShapeTT(info, glyph_index)
else
n, v = stbtt__GetGlyphShapeT2(info, glyph_index)
end
e = { n, v }
cache[glyph_index] = e
end
return e[1], e[2]
end
-- leftSideBearing is the offset from the current horizontal position to the left edge of the character
-- advanceWidth is the offset from the current horizontal position to the next horizontal position
-- these are expressed in unscaled coordinates
--- @param info stbtt_fontinfo
--- @param glyph_index int
@native
function stbtt_GetGlyphHMetrics(info, glyph_index)
local numOfLongHorMetrics = ttUSHORT(info.data, info.hhea + 34)
@@ -80378,6 +80481,7 @@ end
-- these are expressed in unscaled coordinates, so you must multiply by
-- the scale factor for a given size
--- @param info stbtt_fontinfo
@native
function stbtt_GetFontVMetrics(info)
local ascent = ttSHORT(info.data, info.hhea + 4)
local descent = ttSHORT(info.data, info.hhea + 6)
@@ -80394,6 +80498,7 @@ end
-- so if you prefer to measure height by the ascent only, use a similar calculation.
--- @param info stbtt_fontinfo
--- @param height float
@native
function stbtt_ScaleForPixelHeight(info, height)
local fheight = ttSHORT(info.data, info.hhea + 4) - ttSHORT(info.data, info.hhea + 6)
return height / fheight
@@ -80414,6 +80519,7 @@ end
--- @param scale_y float
--- @param shift_x float
--- @param shift_y float
@native
function stbtt_GetGlyphBitmapBoxSubpixel(font, glyph, scale_x, scale_y, shift_x, shift_y)
local n, x0, y0, x1, y1 = stbtt_GetGlyphBox(font, glyph)
@@ -80444,6 +80550,7 @@ end
--- @param glyph int
--- @param scale_x float
--- @param scale_y float
@native
function stbtt_GetGlyphBitmapBox(font, glyph, scale_x, scale_y)
return stbtt_GetGlyphBitmapBoxSubpixel(font, glyph, scale_x, scale_y, 0.0, 0.0)
end
@@ -80471,6 +80578,7 @@ end
--- @param y0 float
--- @param x1 float
--- @param y1 float
@native
local function stbtt__handle_clipped_edge(scanline, x, e, x0, y0, x1, y1)
if y0 == y1 then return end
STBTT_assert(y0 < y1)
@@ -80512,6 +80620,7 @@ end
--- @param height float
--- @param top_width float
--- @param bottom_width float
@native
local function stbtt__sized_trapezoid_area(height, top_width, bottom_width)
STBTT_assert(top_width >= 0)
STBTT_assert(bottom_width >= 0)
@@ -80523,12 +80632,14 @@ end
--- @param tx1 float
--- @param bx0 float
--- @param bx1 float
@native
local function stbtt__position_trapezoid_area(height, tx0, tx1, bx0, bx1)
return stbtt__sized_trapezoid_area(height, tx1 - tx0, bx1 - bx0)
end
--- @param height float
--- @param width float
@native
local function stbtt__sized_triangle_area(height, width)
return height * width / 2
end
@@ -80538,6 +80649,7 @@ end
--- @param len int
--- @param e stbtt__active_edge
--- @param y_top float
@native
local function stbtt__fill_active_edges_new(scanline, scanline_fill, len, e, y_top)
local y_bottom = y_top + 1
@@ -80760,11 +80872,14 @@ end
--- @param vsubsample int
--- @param off_x int
--- @param off_y int
local rasterize_scanline, rasterize_scanline2 = {}, {} -- [Luau] reused: fully cleared per scanline below
@native
local function stbtt__rasterize_sorted_edges(result, e, n, vsubsample, off_x, off_y)
local active = nil
local scanline = {} -- [Port] size = result.w, 0-based
local scanline2 = {} -- [Port] size = result.w + 1, 0-based
active_pool_n = 0 -- every active edge of the previous call is dead
local scanline = rasterize_scanline -- [Port] size = result.w, 0-based
local scanline2 = rasterize_scanline2 -- [Port] size = result.w + 1, 0-based
STBTT__NOTUSED(vsubsample)
@@ -80835,7 +80950,7 @@ local function stbtt__rasterize_sorted_edges(result, e, n, vsubsample, off_x, of
end
-- advance all the edges
step = active
local step = active
while step do
step.fx = step.fx + step.fdx -- advance to position for current scanline
step = step.next -- advance through list
@@ -80855,6 +80970,7 @@ local STBTT__COMPARE = function(a, b)
end
--- @param p stbtt__edge[]
@native
local function stbtt__sort_edges(p)
STBTT_sort(p, STBTT__COMPARE)
end
@@ -80870,6 +80986,8 @@ end
--- @param off_x int
--- @param off_y int
--- @param invert bool
local rasterize_edges = {}
@native
local function stbtt__rasterize(result, pts, wcount, windings, scale_x, scale_y, shift_x, shift_y, off_x, off_y, invert)
local y_scale_inv = (invert) and -scale_y or scale_y
local vsubsample = 1 -- STBTT_RASTERIZER_VERSION == 2
@@ -80881,7 +80999,13 @@ local function stbtt__rasterize(result, pts, wcount, windings, scale_x, scale_y,
n = n + wcount[i]
end
local e = {} for i = 1, n + 1 do e[i] = stbtt__edge() end -- add an extra one as a sentinel
-- [Luau] edges reused across calls; unused entries are sentinels (y0 = nil) like the unfilled ones upstream
local e = rasterize_edges
for i = 1, n + 1 do
local ed = e[i]
if ed == nil then e[i] = stbtt__edge() else ed.y0 = nil; ed.invert = false end
end
for i = n + 2, #e do e[i].y0 = nil end
n = 0
local m = 0
@@ -80935,6 +81059,7 @@ end
--- @param n int
--- @param x float
--- @param y float
@native
local function stbtt__add_point(points, n, x, y)
if points == nil then return end -- during first pass, it's unallocated
points[n + 1].x = x
@@ -80953,6 +81078,7 @@ end
--- @param objspace_flatness_squared float
--- @param n int
--- @return int num_points # updated num_points passed in
@native
local function stbtt__tesselate_curve(points, num_points, x0, y0, x1, y1, x2, y2, objspace_flatness_squared, n)
-- midpoint
local mx = (x0 + 2 * x1 + x2) / 4
@@ -80989,6 +81115,7 @@ end
--- @param objspace_flatness_squared float
--- @param n int
--- @return int num_points # updated num_points passed in
@native
local function stbtt__tesselate_cubic(points, num_points, x0, y0, x1, y1, x2, y2, x3, y3, objspace_flatness_squared, n)
-- @TODO this "flatness" calculation is just made-up nonsense that seems to work well enough
local dx0 = x1 - x0
@@ -81040,6 +81167,8 @@ end
--- @return stbtt__point[]? points
--- @return int? num_contours
--- @return int[]? contour_lengths
local flatten_points = {}
@native
local function stbtt_FlattenCurves(vertices, num_verts, objspace_flatness)
local points = nil
local num_points = 0
@@ -81064,8 +81193,8 @@ local function stbtt_FlattenCurves(vertices, num_verts, objspace_flatness)
for pass = 0, 1 do
local x, y = 0, 0
if pass == 1 then
points = {}
for i = 1, num_points do points[i] = stbtt__point() end
points = flatten_points -- [Luau] reused across calls (only [1..num_points] is read)
for i = #points + 1, num_points do points[i] = stbtt__point() end
end
num_points = 0
n = -1
@@ -81122,6 +81251,7 @@ end
--- @param x_off int
--- @param y_off int
--- @param invert bool
@native
local function stbtt_Rasterize(result, flatness_in_pixels, vertices, num_verts, scale_x, scale_y, shift_x, shift_y, x_off, y_off, invert)
local scale = (scale_x > scale_y) and scale_y or scale_x
@@ -81149,6 +81279,7 @@ end
--- @param shift_x float
--- @param shift_y float
--- @param glyph int
@native
local function stbtt_MakeGlyphBitmapSubpixel(info, output, out_w, out_h, out_stride, scale_x, scale_y, shift_x, shift_y, glyph)
local num_verts, vertices = stbtt_GetGlyphShape(info, glyph)
local gbm = stbtt__bitmap()
@@ -81202,6 +81333,7 @@ local STBTT__OVER_MASK = STBTT_MAX_OVERSAMPLE - 1
--- @param h int
--- @param stride_in_bytes int
--- @param kernel_width unsigned_int
@native
local function stbtt__h_prefilter(pixels, w, h, stride_in_bytes, kernel_width)
local buffer = {}
local safe_w = w - kernel_width
@@ -81231,6 +81363,7 @@ end
--- @param h int
--- @param stride_in_bytes int
--- @param kernel_width unsigned_int
@native
local function stbtt__v_prefilter(pixels, w, h, stride_in_bytes, kernel_width)
local buffer = {}
local safe_h = h - kernel_width
@@ -81257,6 +81390,7 @@ end
--- @param oversample int
--- @return float
@native
local function stbtt__oversample_shift(oversample)
if oversample == 0 then
return 0.0
@@ -81283,6 +81417,7 @@ end
--- @param prefilter_x int
--- @param prefilter_y int
--- @param glyph int
@native
function stbtt_MakeGlyphBitmapSubpixelPrefilter(info, output, out_w, out_h, out_stride, scale_x, scale_y, shift_x, shift_y, prefilter_x, prefilter_y, glyph)
stbtt_MakeGlyphBitmapSubpixel(info, output, out_w - (prefilter_x - 1), out_h - (prefilter_y - 1), out_stride, scale_x, scale_y, shift_x, shift_y, glyph)
@@ -81336,6 +81471,7 @@ end
-- return '0' for index 0, and -1 for all other indices.
--- @param data table
--- @param index int
@native
function stbtt_GetFontOffsetForIndex(data, index) return stbtt_GetFontOffsetForIndex_internal(data, index) end
-- Given an offset into the file that defines a font, this function builds
@@ -81346,6 +81482,7 @@ function stbtt_GetFontOffsetForIndex(data, index) return stbtt_GetFontOffsetForI
--- @param info stbtt_fontinfo
--- @param data table
--- @param offset int
@native
function stbtt_InitFont(info, data, offset) return stbtt_InitFont_internal(info, data, offset) end
return {
@@ -82244,6 +82381,7 @@ return {
stbtt_GetGlyphBitmapBoxSubpixel = stbtt_GetGlyphBitmapBoxSubpixel,
stbtt_GetGlyphHMetrics = stbtt_GetGlyphHMetrics,
stbtt_GetGlyphShape = stbtt_GetGlyphShape,
stbtt_GetGlyphShapeUncached = stbtt_GetGlyphShapeUncached,
stbtt_InitFont = stbtt_InitFont,
stbtt_MakeGlyphBitmapSubpixelPrefilter = stbtt_MakeGlyphBitmapSubpixelPrefilter,
stbtt_ScaleForPixelHeight = stbtt_ScaleForPixelHeight,
+1 -1
View File
@@ -1 +1 @@
[[183, "imgui.lua"], [22801, "imgui_demo.lua"], [34658, "imgui_draw.lua"], [42995, "imgui_h.lua"], [45996, "imgui_impl_love.lua"], [46540, "imgui_internal.lua"], [50506, "imgui_tables.lua"], [55598, "imgui_widgets.lua"], [67839, "imstb_rectpack.lua"], [68503, "imstb_textedit.lua"], [70045, "imstb_truetype.lua"], [72833, "imstd_minstdio.lua"]]
[[183, "imgui.lua"], [22801, "imgui_demo.lua"], [34658, "imgui_draw.lua"], [42998, "imgui_h.lua"], [45999, "imgui_impl_love.lua"], [46543, "imgui_internal.lua"], [50511, "imgui_tables.lua"], [55603, "imgui_widgets.lua"], [67844, "imstb_rectpack.lua"], [68521, "imstb_textedit.lua"], [70063, "imstb_truetype.lua"], [72970, "imstd_minstdio.lua"]]
+151 -13
View File
@@ -138,7 +138,7 @@ if not utf8 then
end
local ImGui, ImVec2, ImVec4, ImRect, ImVec2_Copy, HelpMarker, IMGUI_DEMO_MARKER, ImGuiTableFlags, ImStd, ImVector, ImGuiKey, ImDrawFlags, ImGuiInputFlags, ImRect_Copy, ImStb, ImGuiDataType, IM_TRUNC, ImGuiStyleVarInfo, ImVec2_CopyV, IM_ASSERT_USER_ERROR, ImGuiHoveredFlags, ImHashStr, IM_ASSERT_USER_ERROR_RET, ImIsPowerOfTwo, ImS32, ImGuiColorEditFlags, ImVec4_Copy, ImAbs, ExampleAppConsoleMT, IM_ROUND, ImFormatString, ImGuiTableColumnFlags, ImGuiTreeNodeFlags, PopStyleCompact, PushStyleCompact, IM_ASSERT_PARANOID, ImU16, ExampleNames, ImGuiWindowFlags, ImGuiItemFlags, stbte, ImColor, ImCos, ImGuiButtonFlags, ImGuiDebugLogFlags, ImGuiListClipper, ImGuiLocKey, ImU32, ExampleTreeFuncs, ImS16, _PathArcToFastExXY, ImGuiMultiSelectFlags, ImSin, ImGuiTabBarFlags, ImLengthSqr, ImUpperPowerOfTwo, IM_F32_TO_INT8_SAT, ImFontAtlasPackGetRect, ImGuiMouseCursor, ImS64, DockSettingsRenameNodeReferences, ExampleDualListBoxMT, IM_DRAWLIST_TEX_LINES_WIDTH_MAX, ImCeil, ImFabs, ImGuiCol, ImGuiSelectionBasicStorage, ImS8, ImU8, ExampleAppPropertyEditorMT, ImGuiChildFlags, ImGuiScrollFlags, ImGui_ImplLOVE_GetBackendData, ExampleSelectionWithDeletionMT, CustomConstraints, ExampleAppLogMT, IMGUI_DEBUG_LOG_FONT, ImFontAtlasBuildInit, ImFontAtlasFontDestroyOutput, ImGuiComboFlags, ImGuiPopupFlags, ImGuiSliderFlags, ImTextClassifierSetCharClass, MyDocument, ShowExampleMenuFile, CalcCornerArcStepAndCount, ImFontAtlasBakedAddFontGlyph, ImFontAtlasPackAddRect, ImFontBaked_BuildLoadGlyph, ImFontConfig, ImGuiInputTextFlags, ImGuiStyle_Copy, ExampleAsset_s_current_sort_specs, IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_CALC, ImFontAtlasBuildNotifySetFont, ImFontAtlasBuildRenderBitmapFromString, ImFontAtlasFontDestroySourceData, ImFontAtlasFontSourceAddToFont, ImGuiTableColumn, stb_textedit_key, stbtt_GetGlyphBitmapBoxSubpixel, IM_FREE, ImDrawListSplitter, stb_text_locate_coord, stb_text_makeundo_insert, stb_text_makeundo_replace, stb_textedit_find_charpos, stbtt_GetGlyphShape, ImGuiTableColumnSortSpecs, ImGuiTableInstanceData, ImGuiTableSettings, stb_text_makeundo_delete, stb_text_redo, stb_text_undo, stb_textedit_click, stb_textedit_drag, stbtt_FindGlyphIndex, stbtt_GetFontOffsetForIndex, stbtt_GetFontVMetrics, stbtt_GetGlyphBitmapBox, stbtt_GetGlyphHMetrics, stbtt_InitFont, stbtt_MakeGlyphBitmapSubpixelPrefilter, stbtt_ScaleForPixelHeight, stbtt__GetGlyphInfoT2, stbtt__GetGlyphShapeT2, stbtt_fontinfo, ImGuiOldColumnData, ImGuiOldColumns, ImGuiTable, ImGuiTableColumnSettings, ImGuiTableSortSpecs, ImGuiTableTempData, ImGui_ImplLOVE_CreateTexture, ImGui_ImplLOVE_DestroyTexture, ImGui_ImplLOVE_Init, ImGui_ImplLOVE_NewFrame, ImGui_ImplLOVE_RenderDrawData, ImGui_ImplLOVE_Shutdown, ImGui_ImplLOVE_UpdateTexture, stbrp_init_target, IMGUI_TABLE_MAX_COLUMNS, IMSTB_TEXTEDIT_UNDOSTATECOUNT, IM_COL32_DISABLE, ImGui_ImplLove, STB_TEXTEDIT_K_BACKSPACE, STB_TEXTEDIT_K_DELETE, STB_TEXTEDIT_K_DOWN, STB_TEXTEDIT_K_LEFT, STB_TEXTEDIT_K_LINEEND, STB_TEXTEDIT_K_LINESTART, STB_TEXTEDIT_K_PGDOWN, STB_TEXTEDIT_K_PGUP, STB_TEXTEDIT_K_REDO, STB_TEXTEDIT_K_RIGHT, STB_TEXTEDIT_K_SHIFT, STB_TEXTEDIT_K_TEXTEND, STB_TEXTEDIT_K_TEXTSTART, STB_TEXTEDIT_K_UNDO, STB_TEXTEDIT_K_UP
local ImGui, ImVec2, ImVec4, ImRect, ImVec2_Copy, HelpMarker, IMGUI_DEMO_MARKER, ImGuiTableFlags, ImStd, ImVector, ImGuiKey, ImDrawFlags, ImGuiInputFlags, ImRect_Copy, ImStb, ImGuiDataType, IM_TRUNC, ImGuiStyleVarInfo, ImVec2_CopyV, IM_ASSERT_USER_ERROR, ImGuiHoveredFlags, ImHashStr, IM_ASSERT_USER_ERROR_RET, ImIsPowerOfTwo, ImS32, ImGuiColorEditFlags, ImVec4_Copy, ImAbs, ExampleAppConsoleMT, IM_ROUND, ImFormatString, ImGuiTableColumnFlags, ImGuiTreeNodeFlags, PopStyleCompact, PushStyleCompact, IM_ASSERT_PARANOID, ImU16, ExampleNames, ImGuiWindowFlags, ImGuiItemFlags, stbte, ImColor, ImCos, ImGuiButtonFlags, ImGuiDebugLogFlags, ImGuiListClipper, ImGuiLocKey, ImU32, ExampleTreeFuncs, ImS16, _PathArcToFastExXY, ImGuiMultiSelectFlags, ImSin, ImGuiTabBarFlags, ImLengthSqr, ImUpperPowerOfTwo, IM_F32_TO_INT8_SAT, ImFontAtlasPackGetRect, ImGuiMouseCursor, ImS64, DockSettingsRenameNodeReferences, ExampleDualListBoxMT, IM_DRAWLIST_TEX_LINES_WIDTH_MAX, ImCeil, ImFabs, ImGuiCol, ImGuiSelectionBasicStorage, ImS8, ImU8, ExampleAppPropertyEditorMT, ImGuiChildFlags, ImGuiScrollFlags, ImGui_ImplLOVE_GetBackendData, ExampleSelectionWithDeletionMT, CustomConstraints, ExampleAppLogMT, IMGUI_DEBUG_LOG_FONT, ImFontAtlasBuildInit, ImFontAtlasFontDestroyOutput, ImGuiComboFlags, ImGuiPopupFlags, ImGuiSliderFlags, ImTextClassifierSetCharClass, MyDocument, ShowExampleMenuFile, CalcCornerArcStepAndCount, ImFontAtlasBakedAddFontGlyph, ImFontAtlasPackAddRect, ImFontBaked_BuildLoadGlyph, ImFontConfig, ImGuiInputTextFlags, ImGuiStyle_Copy, ExampleAsset_s_current_sort_specs, IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_CALC, ImFontAtlasBuildNotifySetFont, ImFontAtlasBuildRenderBitmapFromString, ImFontAtlasFontDestroySourceData, ImFontAtlasFontSourceAddToFont, ImGuiTableColumn, stb_textedit_key, stbtt_GetGlyphBitmapBoxSubpixel, IM_FREE, ImDrawListSplitter, stb_text_locate_coord, stb_text_makeundo_insert, stb_text_makeundo_replace, stb_textedit_find_charpos, stbtt__GetGlyphShapeT2, ImGuiTableColumnSortSpecs, ImGuiTableInstanceData, ImGuiTableSettings, stb_text_makeundo_delete, stb_text_redo, stb_text_undo, stb_textedit_click, stb_textedit_drag, stbtt_FindGlyphIndex, stbtt_GetFontOffsetForIndex, stbtt_GetFontVMetrics, stbtt_GetGlyphBitmapBox, stbtt_GetGlyphHMetrics, stbtt_GetGlyphShape, stbtt_GetGlyphShapeUncached, stbtt_InitFont, stbtt_MakeGlyphBitmapSubpixelPrefilter, stbtt_ScaleForPixelHeight, stbtt__GetGlyphInfoT2, stbtt_fontinfo, ImGuiOldColumnData, ImGuiOldColumns, ImGuiTable, ImGuiTableColumnSettings, ImGuiTableSortSpecs, ImGuiTableTempData, ImGui_ImplLOVE_CreateTexture, ImGui_ImplLOVE_DestroyTexture, ImGui_ImplLOVE_Init, ImGui_ImplLOVE_NewFrame, ImGui_ImplLOVE_RenderDrawData, ImGui_ImplLOVE_Shutdown, ImGui_ImplLOVE_UpdateTexture, stbrp_init_target, IMGUI_TABLE_MAX_COLUMNS, IMSTB_TEXTEDIT_UNDOSTATECOUNT, IM_COL32_DISABLE, ImGui_ImplLove, STB_TEXTEDIT_K_BACKSPACE, STB_TEXTEDIT_K_DELETE, STB_TEXTEDIT_K_DOWN, STB_TEXTEDIT_K_LEFT, STB_TEXTEDIT_K_LINEEND, STB_TEXTEDIT_K_LINESTART, STB_TEXTEDIT_K_PGDOWN, STB_TEXTEDIT_K_PGUP, STB_TEXTEDIT_K_REDO, STB_TEXTEDIT_K_RIGHT, STB_TEXTEDIT_K_SHIFT, STB_TEXTEDIT_K_TEXTEND, STB_TEXTEDIT_K_TEXTSTART, STB_TEXTEDIT_K_UNDO
local type, mathMin, mathMax, mathFloor, mathCeil, bitOr, bitLShift = type, math.min, math.max, math.floor, math.ceil, bit32.bor, bit32.lshift
local function IM_COL32(R, G, B, A) return (bitOr(bitLShift(A, 24 --[[IM_COL32_A_SHIFT]]), bitLShift(B, 16 --[[IM_COL32_B_SHIFT]]), bitLShift(G, 8 --[[IM_COL32_G_SHIFT]]), bitLShift(R, 0 --[[IM_COL32_R_SHIFT]]))) end
@@ -34706,6 +34706,7 @@ end
--- @param buf char[] # 1-based
--- @param base int # 1-based start index
--- @param u32 ImU32
local function write_u32(buf, base, u32)
buf[base + 0] = bit32.band(u32, 0xFF)
buf[base + 1] = bit32.band(bit32.rshift(u32, 8), 0xFF)
@@ -35435,6 +35436,7 @@ end
--- @param dst_pitch int
--- @param w int
--- @param h int
function ImFontAtlasTextureBlockConvert(src_pixels, src_fmt, src_pitch, dst_pixels, dst_pixels_base, dst_fmt, dst_pitch, w, h)
assert(src_pixels ~= nil and dst_pixels ~= nil)
local src_pixels_base = 1
@@ -35452,7 +35454,8 @@ function ImFontAtlasTextureBlockConvert(src_pixels, src_fmt, src_pitch, dst_pixe
local alpha = src_pixels[src_pixels_base + 0]
src_pixels_base = src_pixels_base + 1
write_u32(dst_pixels, dst_pixels_base, IM_COL32(255, 255, 255, alpha))
-- [Luau] inline write_u32(dst_pixels, dst_pixels_base, IM_COL32(255, 255, 255, alpha))
dst_pixels[dst_pixels_base] = 255; dst_pixels[dst_pixels_base + 1] = 255; dst_pixels[dst_pixels_base + 2] = 255; dst_pixels[dst_pixels_base + 3] = alpha
dst_pixels_base = dst_pixels_base + 4
end
@@ -46858,13 +46861,15 @@ end
--- @param s table # 1-based
--- @param c any
--- @param n int
function ImStd.memset(s, c, n)
for i = 1, n do s[i] = c end
end
do
local _memmove = function(dest, dest_start, src, src_start, count)
local function _memmove(dest, dest_start, src, src_start, count)
if count <= 0 then return end
local c = (dest == src and dest_start >= src_start)
@@ -67943,6 +67948,7 @@ local STBRP__PREV_LINK_TYPE = {
--- @return stbrp_rect
--- @nodiscard
local function stbrp_rect()
return {
-- reserved for your use:
@@ -67966,6 +67972,7 @@ end
--- @return stbrp_node
--- @nodiscard
local function stbrp_node()
return {
x = 0,
@@ -67987,6 +67994,7 @@ end
--- @return stbrp_context
--- @nodiscard
local function stbrp_context()
return {
width = 0,
@@ -68009,6 +68017,7 @@ end
--- @field prev_link_type? int
--- @return stbrp__findresult
local function stbrp__findresult()
return {
x = 0,
@@ -68029,6 +68038,7 @@ end
-- If you call init again, this will be reset to the default.
--- @param context stbrp_context
--- @param heuristic int
local function stbrp_setup_heuristic(context, heuristic)
if context.init_mode == STBRP__INIT_skyline then
STBRP_ASSERT(heuristic == STBRP_HEURISTIC_Skyline.BL_sortHeight or heuristic == STBRP_HEURISTIC_Skyline.BF_sortHeight)
@@ -68043,6 +68053,7 @@ end
-- If you call init again, this will be reset to the default (false).
--- @param context stbrp_context
--- @param allow_out_of_mem boolean
local function stbrp_setup_allow_out_of_mem(context, allow_out_of_mem)
if allow_out_of_mem then
-- if it's ok to run out of memory, then don't bother aligning them;
@@ -68086,6 +68097,7 @@ end
--- @param height int
--- @param nodes stbrp_node[]
--- @param num_nodes int
function stbrp_init_target(context, width, height, nodes, num_nodes)
for i = 1, num_nodes - 1 do
nodes[i].next = nodes[i + 1]
@@ -68116,6 +68128,7 @@ end
--- @param x0 int
--- @param width int
--- @return int, int
local function stbrp__skyline_find_min_y(c, first, x0, width)
local node = first
local x1 = x0 + width
@@ -68163,6 +68176,7 @@ end
--- @param width int
--- @param height int
--- @return stbrp__findresult
local function stbrp__skyline_find_best_pos(c, width, height)
local best_waste = bit32.lshift(1, 30)
local best_x = 0
@@ -68292,6 +68306,7 @@ end
--- @param width int
--- @param height int
--- @return stbrp__findresult
local function stbrp__skyline_pack_rectangle(context, width, height)
-- find best position according to heuristic
local res = stbrp__skyline_find_best_pos(context, width, height)
@@ -68360,6 +68375,7 @@ end
--- @param b stbrp_rect
--- @return bool
--- @package
local function rect_height_compare(a, b)
if a.h > b.h then
return true
@@ -68374,6 +68390,7 @@ end
--- @param b stbrp_rect
--- @return bool
--- @package
local function rect_original_order(a, b)
return a.was_packed < b.was_packed
end
@@ -68405,6 +68422,7 @@ end
--- @param rects stbrp_rect[]
--- @param num_rects int
--- @return int
local function stbrp_pack_rects(context, rects, num_rects)
local all_rects_packed = 1
@@ -70212,7 +70230,7 @@ local stbtt_MakeGlyphBitmapSubpixelPrefilter
local stbtt_GetFontVMetrics
local stbtt__GetGlyphInfoT2
local stbtt__GetGlyphShapeT2
local stbtt_GetGlyphShape
local stbtt_GetGlyphShape, stbtt_GetGlyphShapeUncached
local stbtt_GetGlyphBitmapBox
local stbtt_GetGlyphBitmapBoxSubpixel
local stbtt_GetGlyphHMetrics
@@ -70265,6 +70283,7 @@ local trunc = function(x)
end
end
local function STBTT__NOTUSED(_) return end
--- @alias stbtt_int32 int
@@ -70287,6 +70306,7 @@ local unsigned_char = stbtt_uint8
--- @param initial_offset? int
--- @return stbtt__buf
--- @nodiscard
local function stbtt__buf(initial_offset)
return {
data = nil,
@@ -70321,6 +70341,7 @@ end
--- @field fdselect stbtt__buf # map from glyph to fontdict
--- @return stbtt_fontinfo
function stbtt_fontinfo()
return {
data = nil,
@@ -70361,6 +70382,7 @@ end
--- @return stbtt_vertex
--- @nodiscard
local function stbtt_vertex()
return {
x = nil,
@@ -70390,6 +70412,7 @@ end
--- @return stbtt__csctx
--- @nodiscard
local function stbtt__csctx()
return {
bounds = false,
@@ -70411,6 +70434,7 @@ end
--- @param bounds bool
--- @return stbtt__csctx
--- @nodiscard
local function STBTT__CSCTX_INIT(bounds)
local this = stbtt__csctx()
@@ -70444,6 +70468,7 @@ end
--- @return stbtt__edge
--- @nodiscard
local function stbtt__edge()
return {
x0 = nil,
@@ -70458,6 +70483,7 @@ end
--- @return stbtt__active_edge
--- @nodiscard
local function stbtt__active_edge()
return {
next = nil,
@@ -70472,8 +70498,15 @@ end
--- @return stbtt__active_edge
--- @nodiscard
local active_pool, active_pool_n = {}, 0 -- [Luau] reused per stbtt__rasterize_sorted_edges() call (C: stbtt__hheap)
local function stbtt__new_active(e, off_x, start_point)
local z = stbtt__active_edge()
active_pool_n = active_pool_n + 1
local z = active_pool[active_pool_n]
if z == nil then
z = stbtt__active_edge()
active_pool[active_pool_n] = z
end
local dxdy = (e.x1 - e.x0) / (e.y1 - e.y0)
z.fdx = dxdy
@@ -70497,6 +70530,7 @@ end
--- @return stbtt__bitmap
--- @nodiscard
local function stbtt__bitmap()
return {
w = nil,
@@ -70512,6 +70546,7 @@ end
--- @return stbtt__point
--- @nodiscard
local function stbtt__point() return { x = nil, y = nil } end
----------------------------------------------
@@ -70522,6 +70557,7 @@ local function stbtt__point() return { x = nil, y = nil } end
---
--- @param b stbtt__buf
local function stbtt__buf_get8(b)
if b.cursor >= b.size then return 0 end
local result = b.data[b.offset + b.cursor + 1]
@@ -70530,6 +70566,7 @@ local function stbtt__buf_get8(b)
end
--- @param b stbtt__buf
local function stbtt__buf_peek8(b)
if b.cursor >= b.size then return 0 end
return b.data[b.offset + b.cursor + 1]
@@ -70537,6 +70574,7 @@ end
--- @param b stbtt__buf
--- @param o int
local function stbtt__buf_seek(b, o)
STBTT_assert(not (o > b.size or o < 0))
if o > b.size or o < 0 then
@@ -70548,10 +70586,12 @@ end
--- @param b stbtt__buf
--- @param o int
local function stbtt__buf_skip(b, o)
stbtt__buf_seek(b, b.cursor + o)
end
local function stbtt__buf_get(b, n)
local v = 0
STBTT_assert(n >= 1 and n <= 4)
@@ -70566,6 +70606,7 @@ end
--- @param offset? int
--- @return stbtt__buf
--- @nodiscard
local function stbtt__new_buf(p, size, offset)
local r = stbtt__buf(offset)
STBTT_assert(size < 0x40000000)
@@ -70576,8 +70617,10 @@ local function stbtt__new_buf(p, size, offset)
end
--- @param b stbtt__buf
local function stbtt__buf_get16(b) return stbtt__buf_get(b, 2) end
--- @param b stbtt__buf
local function stbtt__buf_get32(b) return stbtt__buf_get(b, 4) end
--- @param b stbtt__buf
@@ -70585,6 +70628,7 @@ local function stbtt__buf_get32(b) return stbtt__buf_get(b, 4) end
--- @param s int
--- @return stbtt__buf
--- @nodiscard
local function stbtt__buf_range(b, o, s)
local r = stbtt__new_buf(nil, 0)
if (o < 0 or s < 0 or o > b.size or s > (b.size - o)) then
@@ -70597,6 +70641,7 @@ local function stbtt__buf_range(b, o, s)
end
--- @param b stbtt__buf
local function stbtt__cff_get_index(b)
local count, start, offsize
start = b.cursor
@@ -70611,6 +70656,7 @@ local function stbtt__cff_get_index(b)
end
--- @param b stbtt__buf
local function stbtt__cff_int(b)
local b0 = stbtt__buf_get8(b)
if b0 >= 32 and b0 <= 246 then return b0 - 139
@@ -70624,6 +70670,7 @@ local function stbtt__cff_int(b)
end
--- @param b stbtt__buf
local function stbtt__cff_skip_operand(b)
local v
local b0 = stbtt__buf_peek8(b)
@@ -70645,6 +70692,7 @@ end
--- @param key int
--- @return stbtt__buf
--- @nodiscard
local function stbtt__dict_get(b, key)
stbtt__buf_seek(b, 0)
while b.cursor < b.size do
@@ -70666,6 +70714,7 @@ end
--- @param outcount int
--- @return int[]
--- @nodiscard
local function stbtt__dict_get_ints(b, key, outcount)
local operands = stbtt__dict_get(b, key)
local out = {}
@@ -70677,6 +70726,7 @@ local function stbtt__dict_get_ints(b, key, outcount)
end
--- @param b stbtt__buf
local function stbtt__cff_index_count(b)
stbtt__buf_seek(b, 0)
return stbtt__buf_get16(b)
@@ -70686,6 +70736,7 @@ end
--- @param i int
--- @return stbtt__buf
--- @nodiscard
local function stbtt__cff_index_get(b, i)
local count, offsize, start, _end
stbtt__buf_seek(b, 0)
@@ -70729,17 +70780,26 @@ end
--- stbtt_GetNumberOfFonts_internal
--- stbtt__get_svg
local function ttUSHORT(p, offset) return stbtt_uint16(p[offset + 1] * 256 + p[offset + 2]) end
local function ttSHORT(p, offset) return stbtt_int16(p[offset + 1] * 256 + p[offset + 2]) end
local function ttULONG(p, offset) return stbtt_uint32(bit32.lshift(p[offset + 1], 24) + bit32.lshift(p[offset + 2], 16) + bit32.lshift(p[offset + 3], 8) + p[offset + 4]) end
local function ttLONG(p, offset) return stbtt_int32(bit32.lshift(p[offset + 1], 24) + bit32.lshift(p[offset + 2], 16) + bit32.lshift(p[offset + 3], 8) + p[offset + 4]) end
local function ttBYTE(p, offset) return stbtt_uint8(p[offset + 1]) end
local function ttCHAR(p, offset) return stbtt_int8(p[offset + 1]) end
local function stbtt_tag4(p, c0, c1, c2, c3, offset) offset = offset or 0; return p[offset + 1] == c0 and p[offset + 2] == c1 and p[offset + 3] == c2 and p[offset + 4] == c3 end
local function stbtt_tag(p, str, offset) local c0, c1, c2, c3 = string.byte(str, 1, 4); return stbtt_tag4(p, c0, c1, c2, c3, offset) end
local function stbtt__isfont(font)
-- check the version number
if stbtt_tag4(font, 49, 0, 0, 0) then return true end -- TrueType 1
@@ -70751,6 +70811,7 @@ local function stbtt__isfont(font)
end
-- @OPTIMIZE: binary search
local function stbtt__find_table(data, font_start, tag)
local num_tables = ttUSHORT(data, font_start + 4)
local tabledir = font_start + 12
@@ -70763,6 +70824,7 @@ local function stbtt__find_table(data, font_start, tag)
return 0
end
local function stbtt_GetFontOffsetForIndex_internal(font_collection, index)
-- if it's just a font, there's only one valid index
if stbtt__isfont(font_collection) then
@@ -70786,6 +70848,7 @@ end
--- @param cff stbtt__buf
--- @param fontdict stbtt__buf
local function stbtt__get_subrs(cff, fontdict)
local private_loc = stbtt__dict_get_ints(fontdict, 18, 2)
if (private_loc[2] == 0 or private_loc[1] == 0) then
@@ -70801,6 +70864,7 @@ local function stbtt__get_subrs(cff, fontdict)
end
--- @return bool
local function stbtt_InitFont_internal(info, data, fontstart)
local cmap
local numTables
@@ -70928,6 +70992,7 @@ end
-- Returns 0 if the character codepoint is not defined in the font.
--- @param info stbtt_fontinfo
--- @param unicode_codepoint int
function stbtt_FindGlyphIndex(info, unicode_codepoint)
local data = info.data
local index_map = info.index_map
@@ -71033,6 +71098,7 @@ end
--- @param y stbtt_int32
--- @param cx stbtt_int32
--- @param cy stbtt_int32
local function stbtt_setvertex(v, vtx_type, x, y, cx, cy)
v.type = vtx_type
v.x = (stbtt_int16)(x)
@@ -71041,6 +71107,7 @@ local function stbtt_setvertex(v, vtx_type, x, y, cx, cy)
v.cy = (stbtt_int16)(cy)
end
local function stbtt__GetGlyfOffset(info, glyph_index)
STBTT_assert(info.cff.size == 0)
@@ -71061,6 +71128,7 @@ end
-- Gets the bounding box of the visible part of the glyph, in unscaled coordinates
--- @return integer, integer?, integer?, integer?, integer?
local function stbtt_GetGlyphBox(info, glyph_index)
local n, x0, y0, x1, y1
@@ -71089,6 +71157,7 @@ end
--- @param scy stbtt_int32
--- @param cx stbtt_int32
--- @param cy stbtt_int32
local function stbtt__close_shape(vertices, num_vertices, was_off, start_off, sx, sy, scx, scy, cx, cy)
if start_off then
if was_off then
@@ -71113,6 +71182,7 @@ end
--- @param glyph_index int
--- @return int num_vertices
--- @return stbtt_vertex[]? vertices
local function stbtt__GetGlyphShapeTT(info, glyph_index)
local data = info.data
local num_vertices
@@ -71332,7 +71402,7 @@ local function stbtt__GetGlyphShapeTT(info, glyph_index)
n = STBTT_sqrt(mtx[3] * mtx[3] + mtx[4] * mtx[4])
-- Get indexed glyph.
comp_num_vertices, comp_verts = stbtt_GetGlyphShape(info, gidx)
comp_num_vertices, comp_verts = stbtt_GetGlyphShapeUncached(info, gidx) -- [Luau] transformed in place below: must be a fresh copy
if comp_num_vertices > 0 then
-- Transform vertices.
for i = 1, comp_num_vertices do
@@ -71370,6 +71440,7 @@ end
--- @param c stbtt__csctx
--- @param x stbtt_int32
--- @param y stbtt_int32
local function stbtt__track_vertex(c, x, y)
if x > c.max_x or not c.started then c.max_x = x end
if y > c.max_y or not c.started then c.max_y = y end
@@ -71386,6 +71457,7 @@ end
--- @param cy stbtt_int32
--- @param cx1 stbtt_int32
--- @param cy1 stbtt_int32
local function stbtt__csctx_v(c, vtx_type, x, y, cx, cy, cx1, cy1)
if c.bounds then
stbtt__track_vertex(c, x, y)
@@ -71401,6 +71473,7 @@ local function stbtt__csctx_v(c, vtx_type, x, y, cx, cy, cx1, cy1)
end
--- @param ctx stbtt__csctx
local function stbtt__csctx_close_shape(ctx)
if ctx.first_x ~= ctx.x or ctx.first_y ~= ctx.y then
stbtt__csctx_v(ctx, STBTT_VTX.LINE, trunc(ctx.first_x), trunc(ctx.first_y), 0, 0, 0, 0)
@@ -71410,6 +71483,7 @@ end
--- @param ctx stbtt__csctx
--- @param dx float
--- @param dy float
local function stbtt__csctx_rmove_to(ctx, dx, dy)
stbtt__csctx_close_shape(ctx)
ctx.x = ctx.x + dx
@@ -71422,6 +71496,7 @@ end
--- @param ctx stbtt__csctx
--- @param dx float
--- @param dy float
local function stbtt__csctx_rline_to(ctx, dx, dy)
ctx.x = ctx.x + dx
ctx.y = ctx.y + dy
@@ -71435,6 +71510,7 @@ end
--- @param dy2 float
--- @param dx3 float
--- @param dy3 float
local function stbtt__csctx_rccurve_to(ctx, dx1, dy1, dx2, dy2, dx3, dy3)
local cx1 = ctx.x + dx1
local cy1 = ctx.y + dy1
@@ -71445,6 +71521,7 @@ local function stbtt__csctx_rccurve_to(ctx, dx1, dy1, dx2, dy2, dx3, dy3)
stbtt__csctx_v(ctx, STBTT_VTX.CUBIC, trunc(ctx.x), trunc(ctx.y), trunc(cx1), trunc(cy1), trunc(cx2), trunc(cy2))
end
local function stbtt__get_subr(idx, n)
local count = stbtt__cff_index_count(idx)
local bias = 107
@@ -71460,6 +71537,7 @@ local function stbtt__get_subr(idx, n)
return stbtt__cff_index_get(idx, n)
end
local function stbtt__cid_get_glyph_subrs(info, glyph_index)
local fdselect = info.fdselect
local fdselector = -1
@@ -71490,6 +71568,7 @@ end
--- @param info stbtt_fontinfo
--- @param glyph_index int
--- @param c stbtt__csctx
local function stbtt__run_charstring(info, glyph_index, c)
local in_header = true
local maskbits = 0
@@ -71763,6 +71842,7 @@ end
--- @param glyph_index int
--- @return int num_vertices
--- @return stbtt_vertex[]? vertices
function stbtt__GetGlyphShapeT2(info, glyph_index)
-- runs the charstring twice, once to count and once to output (to avoid realloc)
local vertices = nil
@@ -71788,6 +71868,7 @@ end
--- @return int y0
--- @return int x1
--- @return int y1
function stbtt__GetGlyphInfoT2(info, glyph_index)
local c = STBTT__CSCTX_INIT(true)
local r = stbtt__run_charstring(info, glyph_index, c)
@@ -71809,7 +71890,8 @@ end
-- its x,y, using cx,cy as the bezier control point.
--- @param info stbtt_fontinfo
--- @param glyph_index int
function stbtt_GetGlyphShape(info, glyph_index)
function stbtt_GetGlyphShapeUncached(info, glyph_index)
if info.cff.size == 0 then
return stbtt__GetGlyphShapeTT(info, glyph_index)
else
@@ -71817,11 +71899,32 @@ function stbtt_GetGlyphShape(info, glyph_index)
end
end
function stbtt_GetGlyphShape(info, glyph_index)
-- [Luau] shapes don't depend on the size: cache them per font (baking a new size re-used to re-parse every glyph).
-- Callers only read the vertices (stbtt_FreeShape is a no-op).
local cache = info._ShapeCache
if cache == nil then cache = {}; info._ShapeCache = cache end
local e = cache[glyph_index]
if e == nil then
local n, v
if info.cff.size == 0 then
n, v = stbtt__GetGlyphShapeTT(info, glyph_index)
else
n, v = stbtt__GetGlyphShapeT2(info, glyph_index)
end
e = { n, v }
cache[glyph_index] = e
end
return e[1], e[2]
end
-- leftSideBearing is the offset from the current horizontal position to the left edge of the character
-- advanceWidth is the offset from the current horizontal position to the next horizontal position
-- these are expressed in unscaled coordinates
--- @param info stbtt_fontinfo
--- @param glyph_index int
function stbtt_GetGlyphHMetrics(info, glyph_index)
local numOfLongHorMetrics = ttUSHORT(info.data, info.hhea + 34)
@@ -71844,6 +71947,7 @@ end
-- these are expressed in unscaled coordinates, so you must multiply by
-- the scale factor for a given size
--- @param info stbtt_fontinfo
function stbtt_GetFontVMetrics(info)
local ascent = ttSHORT(info.data, info.hhea + 4)
local descent = ttSHORT(info.data, info.hhea + 6)
@@ -71860,6 +71964,7 @@ end
-- so if you prefer to measure height by the ascent only, use a similar calculation.
--- @param info stbtt_fontinfo
--- @param height float
function stbtt_ScaleForPixelHeight(info, height)
local fheight = ttSHORT(info.data, info.hhea + 4) - ttSHORT(info.data, info.hhea + 6)
return height / fheight
@@ -71880,6 +71985,7 @@ end
--- @param scale_y float
--- @param shift_x float
--- @param shift_y float
function stbtt_GetGlyphBitmapBoxSubpixel(font, glyph, scale_x, scale_y, shift_x, shift_y)
local n, x0, y0, x1, y1 = stbtt_GetGlyphBox(font, glyph)
@@ -71910,6 +72016,7 @@ end
--- @param glyph int
--- @param scale_x float
--- @param scale_y float
function stbtt_GetGlyphBitmapBox(font, glyph, scale_x, scale_y)
return stbtt_GetGlyphBitmapBoxSubpixel(font, glyph, scale_x, scale_y, 0.0, 0.0)
end
@@ -71937,6 +72044,7 @@ end
--- @param y0 float
--- @param x1 float
--- @param y1 float
local function stbtt__handle_clipped_edge(scanline, x, e, x0, y0, x1, y1)
if y0 == y1 then return end
STBTT_assert(y0 < y1)
@@ -71978,6 +72086,7 @@ end
--- @param height float
--- @param top_width float
--- @param bottom_width float
local function stbtt__sized_trapezoid_area(height, top_width, bottom_width)
STBTT_assert(top_width >= 0)
STBTT_assert(bottom_width >= 0)
@@ -71989,12 +72098,14 @@ end
--- @param tx1 float
--- @param bx0 float
--- @param bx1 float
local function stbtt__position_trapezoid_area(height, tx0, tx1, bx0, bx1)
return stbtt__sized_trapezoid_area(height, tx1 - tx0, bx1 - bx0)
end
--- @param height float
--- @param width float
local function stbtt__sized_triangle_area(height, width)
return height * width / 2
end
@@ -72004,6 +72115,7 @@ end
--- @param len int
--- @param e stbtt__active_edge
--- @param y_top float
local function stbtt__fill_active_edges_new(scanline, scanline_fill, len, e, y_top)
local y_bottom = y_top + 1
@@ -72226,11 +72338,14 @@ end
--- @param vsubsample int
--- @param off_x int
--- @param off_y int
local rasterize_scanline, rasterize_scanline2 = {}, {} -- [Luau] reused: fully cleared per scanline below
local function stbtt__rasterize_sorted_edges(result, e, n, vsubsample, off_x, off_y)
local active = nil
local scanline = {} -- [Port] size = result.w, 0-based
local scanline2 = {} -- [Port] size = result.w + 1, 0-based
active_pool_n = 0 -- every active edge of the previous call is dead
local scanline = rasterize_scanline -- [Port] size = result.w, 0-based
local scanline2 = rasterize_scanline2 -- [Port] size = result.w + 1, 0-based
STBTT__NOTUSED(vsubsample)
@@ -72301,7 +72416,7 @@ local function stbtt__rasterize_sorted_edges(result, e, n, vsubsample, off_x, of
end
-- advance all the edges
step = active
local step = active
while step do
step.fx = step.fx + step.fdx -- advance to position for current scanline
step = step.next -- advance through list
@@ -72321,6 +72436,7 @@ local STBTT__COMPARE = function(a, b)
end
--- @param p stbtt__edge[]
local function stbtt__sort_edges(p)
STBTT_sort(p, STBTT__COMPARE)
end
@@ -72336,6 +72452,8 @@ end
--- @param off_x int
--- @param off_y int
--- @param invert bool
local rasterize_edges = {}
local function stbtt__rasterize(result, pts, wcount, windings, scale_x, scale_y, shift_x, shift_y, off_x, off_y, invert)
local y_scale_inv = (invert) and -scale_y or scale_y
local vsubsample = 1 -- STBTT_RASTERIZER_VERSION == 2
@@ -72347,7 +72465,13 @@ local function stbtt__rasterize(result, pts, wcount, windings, scale_x, scale_y,
n = n + wcount[i]
end
local e = {} for i = 1, n + 1 do e[i] = stbtt__edge() end -- add an extra one as a sentinel
-- [Luau] edges reused across calls; unused entries are sentinels (y0 = nil) like the unfilled ones upstream
local e = rasterize_edges
for i = 1, n + 1 do
local ed = e[i]
if ed == nil then e[i] = stbtt__edge() else ed.y0 = nil; ed.invert = false end
end
for i = n + 2, #e do e[i].y0 = nil end
n = 0
local m = 0
@@ -72401,6 +72525,7 @@ end
--- @param n int
--- @param x float
--- @param y float
local function stbtt__add_point(points, n, x, y)
if points == nil then return end -- during first pass, it's unallocated
points[n + 1].x = x
@@ -72419,6 +72544,7 @@ end
--- @param objspace_flatness_squared float
--- @param n int
--- @return int num_points # updated num_points passed in
local function stbtt__tesselate_curve(points, num_points, x0, y0, x1, y1, x2, y2, objspace_flatness_squared, n)
-- midpoint
local mx = (x0 + 2 * x1 + x2) / 4
@@ -72455,6 +72581,7 @@ end
--- @param objspace_flatness_squared float
--- @param n int
--- @return int num_points # updated num_points passed in
local function stbtt__tesselate_cubic(points, num_points, x0, y0, x1, y1, x2, y2, x3, y3, objspace_flatness_squared, n)
-- @TODO this "flatness" calculation is just made-up nonsense that seems to work well enough
local dx0 = x1 - x0
@@ -72506,6 +72633,8 @@ end
--- @return stbtt__point[]? points
--- @return int? num_contours
--- @return int[]? contour_lengths
local flatten_points = {}
local function stbtt_FlattenCurves(vertices, num_verts, objspace_flatness)
local points = nil
local num_points = 0
@@ -72530,8 +72659,8 @@ local function stbtt_FlattenCurves(vertices, num_verts, objspace_flatness)
for pass = 0, 1 do
local x, y = 0, 0
if pass == 1 then
points = {}
for i = 1, num_points do points[i] = stbtt__point() end
points = flatten_points -- [Luau] reused across calls (only [1..num_points] is read)
for i = #points + 1, num_points do points[i] = stbtt__point() end
end
num_points = 0
n = -1
@@ -72588,6 +72717,7 @@ end
--- @param x_off int
--- @param y_off int
--- @param invert bool
local function stbtt_Rasterize(result, flatness_in_pixels, vertices, num_verts, scale_x, scale_y, shift_x, shift_y, x_off, y_off, invert)
local scale = (scale_x > scale_y) and scale_y or scale_x
@@ -72615,6 +72745,7 @@ end
--- @param shift_x float
--- @param shift_y float
--- @param glyph int
local function stbtt_MakeGlyphBitmapSubpixel(info, output, out_w, out_h, out_stride, scale_x, scale_y, shift_x, shift_y, glyph)
local num_verts, vertices = stbtt_GetGlyphShape(info, glyph)
local gbm = stbtt__bitmap()
@@ -72668,6 +72799,7 @@ local STBTT__OVER_MASK = STBTT_MAX_OVERSAMPLE - 1
--- @param h int
--- @param stride_in_bytes int
--- @param kernel_width unsigned_int
local function stbtt__h_prefilter(pixels, w, h, stride_in_bytes, kernel_width)
local buffer = {}
local safe_w = w - kernel_width
@@ -72697,6 +72829,7 @@ end
--- @param h int
--- @param stride_in_bytes int
--- @param kernel_width unsigned_int
local function stbtt__v_prefilter(pixels, w, h, stride_in_bytes, kernel_width)
local buffer = {}
local safe_h = h - kernel_width
@@ -72723,6 +72856,7 @@ end
--- @param oversample int
--- @return float
local function stbtt__oversample_shift(oversample)
if oversample == 0 then
return 0.0
@@ -72749,6 +72883,7 @@ end
--- @param prefilter_x int
--- @param prefilter_y int
--- @param glyph int
function stbtt_MakeGlyphBitmapSubpixelPrefilter(info, output, out_w, out_h, out_stride, scale_x, scale_y, shift_x, shift_y, prefilter_x, prefilter_y, glyph)
stbtt_MakeGlyphBitmapSubpixel(info, output, out_w - (prefilter_x - 1), out_h - (prefilter_y - 1), out_stride, scale_x, scale_y, shift_x, shift_y, glyph)
@@ -72802,6 +72937,7 @@ end
-- return '0' for index 0, and -1 for all other indices.
--- @param data table
--- @param index int
function stbtt_GetFontOffsetForIndex(data, index) return stbtt_GetFontOffsetForIndex_internal(data, index) end
-- Given an offset into the file that defines a font, this function builds
@@ -72812,6 +72948,7 @@ function stbtt_GetFontOffsetForIndex(data, index) return stbtt_GetFontOffsetForI
--- @param info stbtt_fontinfo
--- @param data table
--- @param offset int
function stbtt_InitFont(info, data, offset) return stbtt_InitFont_internal(info, data, offset) end
return {
@@ -73698,6 +73835,7 @@ return {
stbtt_GetGlyphBitmapBoxSubpixel = stbtt_GetGlyphBitmapBoxSubpixel,
stbtt_GetGlyphHMetrics = stbtt_GetGlyphHMetrics,
stbtt_GetGlyphShape = stbtt_GetGlyphShape,
stbtt_GetGlyphShapeUncached = stbtt_GetGlyphShapeUncached,
stbtt_InitFont = stbtt_InitFont,
stbtt_MakeGlyphBitmapSubpixelPrefilter = stbtt_MakeGlyphBitmapSubpixelPrefilter,
stbtt_ScaleForPixelHeight = stbtt_ScaleForPixelHeight,
+4 -1
View File
@@ -49,6 +49,7 @@ end
--- @param buf char[] # 1-based
--- @param base int # 1-based start index
--- @param u32 ImU32
@native
local function write_u32(buf, base, u32)
buf[base + 0] = bit32.band(u32, 0xFF)
buf[base + 1] = bit32.band(bit32.rshift(u32, 8), 0xFF)
@@ -778,6 +779,7 @@ end
--- @param dst_pitch int
--- @param w int
--- @param h int
@native
function ImFontAtlasTextureBlockConvert(src_pixels, src_fmt, src_pitch, dst_pixels, dst_pixels_base, dst_fmt, dst_pitch, w, h)
IM_ASSERT(src_pixels ~= nil and dst_pixels ~= nil)
local src_pixels_base = 1
@@ -795,7 +797,8 @@ function ImFontAtlasTextureBlockConvert(src_pixels, src_fmt, src_pitch, dst_pixe
local alpha = src_pixels[src_pixels_base + 0]
src_pixels_base = src_pixels_base + 1
write_u32(dst_pixels, dst_pixels_base, IM_COL32(255, 255, 255, alpha))
-- [Luau] inline write_u32(dst_pixels, dst_pixels_base, IM_COL32(255, 255, 255, alpha))
dst_pixels[dst_pixels_base] = 255; dst_pixels[dst_pixels_base + 1] = 255; dst_pixels[dst_pixels_base + 2] = 255; dst_pixels[dst_pixels_base + 3] = alpha
dst_pixels_base = dst_pixels_base + 4
end
+3 -1
View File
@@ -319,13 +319,15 @@ end
--- @param s table # 1-based
--- @param c any
--- @param n int
@native
function ImStd.memset(s, c, n)
for i = 1, n do s[i] = c end
end
do
local _memmove = function(dest, dest_start, src, src_start, count)
@native
local function _memmove(dest, dest_start, src, src_start, count)
if count <= 0 then return end
local c = (dest == src and dest_start >= src_start)
+13
View File
@@ -105,6 +105,7 @@ local STBRP__PREV_LINK_TYPE = {
--- @return stbrp_rect
--- @nodiscard
@native
local function stbrp_rect()
return {
-- reserved for your use:
@@ -128,6 +129,7 @@ end
--- @return stbrp_node
--- @nodiscard
@native
local function stbrp_node()
return {
x = 0,
@@ -149,6 +151,7 @@ end
--- @return stbrp_context
--- @nodiscard
@native
local function stbrp_context()
return {
width = 0,
@@ -171,6 +174,7 @@ end
--- @field prev_link_type? int
--- @return stbrp__findresult
@native
local function stbrp__findresult()
return {
x = 0,
@@ -191,6 +195,7 @@ end
-- If you call init again, this will be reset to the default.
--- @param context stbrp_context
--- @param heuristic int
@native
local function stbrp_setup_heuristic(context, heuristic)
if context.init_mode == STBRP__INIT_skyline then
STBRP_ASSERT(heuristic == STBRP_HEURISTIC_Skyline.BL_sortHeight or heuristic == STBRP_HEURISTIC_Skyline.BF_sortHeight)
@@ -205,6 +210,7 @@ end
-- If you call init again, this will be reset to the default (false).
--- @param context stbrp_context
--- @param allow_out_of_mem boolean
@native
local function stbrp_setup_allow_out_of_mem(context, allow_out_of_mem)
if allow_out_of_mem then
-- if it's ok to run out of memory, then don't bother aligning them;
@@ -248,6 +254,7 @@ end
--- @param height int
--- @param nodes stbrp_node[]
--- @param num_nodes int
@native
function stbrp_init_target(context, width, height, nodes, num_nodes)
for i = 1, num_nodes - 1 do
nodes[i].next = nodes[i + 1]
@@ -278,6 +285,7 @@ end
--- @param x0 int
--- @param width int
--- @return int, int
@native
local function stbrp__skyline_find_min_y(c, first, x0, width)
local node = first
local x1 = x0 + width
@@ -325,6 +333,7 @@ end
--- @param width int
--- @param height int
--- @return stbrp__findresult
@native
local function stbrp__skyline_find_best_pos(c, width, height)
local best_waste = bit32.lshift(1, 30)
local best_x = 0
@@ -454,6 +463,7 @@ end
--- @param width int
--- @param height int
--- @return stbrp__findresult
@native
local function stbrp__skyline_pack_rectangle(context, width, height)
-- find best position according to heuristic
local res = stbrp__skyline_find_best_pos(context, width, height)
@@ -522,6 +532,7 @@ end
--- @param b stbrp_rect
--- @return bool
--- @package
@native
local function rect_height_compare(a, b)
if a.h > b.h then
return true
@@ -536,6 +547,7 @@ end
--- @param b stbrp_rect
--- @return bool
--- @package
@native
local function rect_original_order(a, b)
return a.was_packed < b.was_packed
end
@@ -567,6 +579,7 @@ end
--- @param rects stbrp_rect[]
--- @param num_rects int
--- @return int
@native
local function stbrp_pack_rects(context, rects, num_rects)
local all_rects_packed = 1
+129 -10
View File
@@ -168,7 +168,7 @@ local stbtt_MakeGlyphBitmapSubpixelPrefilter
local stbtt_GetFontVMetrics
local stbtt__GetGlyphInfoT2
local stbtt__GetGlyphShapeT2
local stbtt_GetGlyphShape
local stbtt_GetGlyphShape, stbtt_GetGlyphShapeUncached
local stbtt_GetGlyphBitmapBox
local stbtt_GetGlyphBitmapBoxSubpixel
local stbtt_GetGlyphHMetrics
@@ -221,6 +221,7 @@ local trunc = function(x)
end
end
@native
local function STBTT__NOTUSED(_) return end
--- @alias stbtt_int32 int
@@ -243,6 +244,7 @@ local unsigned_char = stbtt_uint8
--- @param initial_offset? int
--- @return stbtt__buf
--- @nodiscard
@native
local function stbtt__buf(initial_offset)
return {
data = nil,
@@ -277,6 +279,7 @@ end
--- @field fdselect stbtt__buf # map from glyph to fontdict
--- @return stbtt_fontinfo
@native
function stbtt_fontinfo()
return {
data = nil,
@@ -317,6 +320,7 @@ end
--- @return stbtt_vertex
--- @nodiscard
@native
local function stbtt_vertex()
return {
x = nil,
@@ -346,6 +350,7 @@ end
--- @return stbtt__csctx
--- @nodiscard
@native
local function stbtt__csctx()
return {
bounds = false,
@@ -367,6 +372,7 @@ end
--- @param bounds bool
--- @return stbtt__csctx
--- @nodiscard
@native
local function STBTT__CSCTX_INIT(bounds)
local this = stbtt__csctx()
@@ -400,6 +406,7 @@ end
--- @return stbtt__edge
--- @nodiscard
@native
local function stbtt__edge()
return {
x0 = nil,
@@ -414,6 +421,7 @@ end
--- @return stbtt__active_edge
--- @nodiscard
@native
local function stbtt__active_edge()
return {
next = nil,
@@ -428,8 +436,15 @@ end
--- @return stbtt__active_edge
--- @nodiscard
local active_pool, active_pool_n = {}, 0 -- [Luau] reused per stbtt__rasterize_sorted_edges() call (C: stbtt__hheap)
@native
local function stbtt__new_active(e, off_x, start_point)
local z = stbtt__active_edge()
active_pool_n = active_pool_n + 1
local z = active_pool[active_pool_n]
if z == nil then
z = stbtt__active_edge()
active_pool[active_pool_n] = z
end
local dxdy = (e.x1 - e.x0) / (e.y1 - e.y0)
z.fdx = dxdy
@@ -453,6 +468,7 @@ end
--- @return stbtt__bitmap
--- @nodiscard
@native
local function stbtt__bitmap()
return {
w = nil,
@@ -468,6 +484,7 @@ end
--- @return stbtt__point
--- @nodiscard
@native
local function stbtt__point() return { x = nil, y = nil } end
----------------------------------------------
@@ -478,6 +495,7 @@ local function stbtt__point() return { x = nil, y = nil } end
---
--- @param b stbtt__buf
@native
local function stbtt__buf_get8(b)
if b.cursor >= b.size then return 0 end
local result = b.data[b.offset + b.cursor + 1]
@@ -486,6 +504,7 @@ local function stbtt__buf_get8(b)
end
--- @param b stbtt__buf
@native
local function stbtt__buf_peek8(b)
if b.cursor >= b.size then return 0 end
return b.data[b.offset + b.cursor + 1]
@@ -493,6 +512,7 @@ end
--- @param b stbtt__buf
--- @param o int
@native
local function stbtt__buf_seek(b, o)
STBTT_assert(not (o > b.size or o < 0))
if o > b.size or o < 0 then
@@ -504,10 +524,12 @@ end
--- @param b stbtt__buf
--- @param o int
@native
local function stbtt__buf_skip(b, o)
stbtt__buf_seek(b, b.cursor + o)
end
@native
local function stbtt__buf_get(b, n)
local v = 0
STBTT_assert(n >= 1 and n <= 4)
@@ -522,6 +544,7 @@ end
--- @param offset? int
--- @return stbtt__buf
--- @nodiscard
@native
local function stbtt__new_buf(p, size, offset)
local r = stbtt__buf(offset)
STBTT_assert(size < 0x40000000)
@@ -532,8 +555,10 @@ local function stbtt__new_buf(p, size, offset)
end
--- @param b stbtt__buf
@native
local function stbtt__buf_get16(b) return stbtt__buf_get(b, 2) end
--- @param b stbtt__buf
@native
local function stbtt__buf_get32(b) return stbtt__buf_get(b, 4) end
--- @param b stbtt__buf
@@ -541,6 +566,7 @@ local function stbtt__buf_get32(b) return stbtt__buf_get(b, 4) end
--- @param s int
--- @return stbtt__buf
--- @nodiscard
@native
local function stbtt__buf_range(b, o, s)
local r = stbtt__new_buf(nil, 0)
if (o < 0 or s < 0 or o > b.size or s > (b.size - o)) then
@@ -553,6 +579,7 @@ local function stbtt__buf_range(b, o, s)
end
--- @param b stbtt__buf
@native
local function stbtt__cff_get_index(b)
local count, start, offsize
start = b.cursor
@@ -567,6 +594,7 @@ local function stbtt__cff_get_index(b)
end
--- @param b stbtt__buf
@native
local function stbtt__cff_int(b)
local b0 = stbtt__buf_get8(b)
if b0 >= 32 and b0 <= 246 then return b0 - 139
@@ -580,6 +608,7 @@ local function stbtt__cff_int(b)
end
--- @param b stbtt__buf
@native
local function stbtt__cff_skip_operand(b)
local v
local b0 = stbtt__buf_peek8(b)
@@ -601,6 +630,7 @@ end
--- @param key int
--- @return stbtt__buf
--- @nodiscard
@native
local function stbtt__dict_get(b, key)
stbtt__buf_seek(b, 0)
while b.cursor < b.size do
@@ -622,6 +652,7 @@ end
--- @param outcount int
--- @return int[]
--- @nodiscard
@native
local function stbtt__dict_get_ints(b, key, outcount)
local operands = stbtt__dict_get(b, key)
local out = {}
@@ -633,6 +664,7 @@ local function stbtt__dict_get_ints(b, key, outcount)
end
--- @param b stbtt__buf
@native
local function stbtt__cff_index_count(b)
stbtt__buf_seek(b, 0)
return stbtt__buf_get16(b)
@@ -642,6 +674,7 @@ end
--- @param i int
--- @return stbtt__buf
--- @nodiscard
@native
local function stbtt__cff_index_get(b, i)
local count, offsize, start, _end
stbtt__buf_seek(b, 0)
@@ -685,17 +718,26 @@ end
--- stbtt_GetNumberOfFonts_internal
--- stbtt__get_svg
@native
local function ttUSHORT(p, offset) return stbtt_uint16(p[offset + 1] * 256 + p[offset + 2]) end
@native
local function ttSHORT(p, offset) return stbtt_int16(p[offset + 1] * 256 + p[offset + 2]) end
@native
local function ttULONG(p, offset) return stbtt_uint32(bit32.lshift(p[offset + 1], 24) + bit32.lshift(p[offset + 2], 16) + bit32.lshift(p[offset + 3], 8) + p[offset + 4]) end
@native
local function ttLONG(p, offset) return stbtt_int32(bit32.lshift(p[offset + 1], 24) + bit32.lshift(p[offset + 2], 16) + bit32.lshift(p[offset + 3], 8) + p[offset + 4]) end
@native
local function ttBYTE(p, offset) return stbtt_uint8(p[offset + 1]) end
@native
local function ttCHAR(p, offset) return stbtt_int8(p[offset + 1]) end
@native
local function stbtt_tag4(p, c0, c1, c2, c3, offset) offset = offset or 0; return p[offset + 1] == c0 and p[offset + 2] == c1 and p[offset + 3] == c2 and p[offset + 4] == c3 end
@native
local function stbtt_tag(p, str, offset) local c0, c1, c2, c3 = string.byte(str, 1, 4); return stbtt_tag4(p, c0, c1, c2, c3, offset) end
@native
local function stbtt__isfont(font)
-- check the version number
if stbtt_tag4(font, 49, 0, 0, 0) then return true end -- TrueType 1
@@ -707,6 +749,7 @@ local function stbtt__isfont(font)
end
-- @OPTIMIZE: binary search
@native
local function stbtt__find_table(data, font_start, tag)
local num_tables = ttUSHORT(data, font_start + 4)
local tabledir = font_start + 12
@@ -719,6 +762,7 @@ local function stbtt__find_table(data, font_start, tag)
return 0
end
@native
local function stbtt_GetFontOffsetForIndex_internal(font_collection, index)
-- if it's just a font, there's only one valid index
if stbtt__isfont(font_collection) then
@@ -742,6 +786,7 @@ end
--- @param cff stbtt__buf
--- @param fontdict stbtt__buf
@native
local function stbtt__get_subrs(cff, fontdict)
local private_loc = stbtt__dict_get_ints(fontdict, 18, 2)
if (private_loc[2] == 0 or private_loc[1] == 0) then
@@ -757,6 +802,7 @@ local function stbtt__get_subrs(cff, fontdict)
end
--- @return bool
@native
local function stbtt_InitFont_internal(info, data, fontstart)
local cmap
local numTables
@@ -884,6 +930,7 @@ end
-- Returns 0 if the character codepoint is not defined in the font.
--- @param info stbtt_fontinfo
--- @param unicode_codepoint int
@native
function stbtt_FindGlyphIndex(info, unicode_codepoint)
local data = info.data
local index_map = info.index_map
@@ -989,6 +1036,7 @@ end
--- @param y stbtt_int32
--- @param cx stbtt_int32
--- @param cy stbtt_int32
@native
local function stbtt_setvertex(v, vtx_type, x, y, cx, cy)
v.type = vtx_type
v.x = (stbtt_int16)(x)
@@ -997,6 +1045,7 @@ local function stbtt_setvertex(v, vtx_type, x, y, cx, cy)
v.cy = (stbtt_int16)(cy)
end
@native
local function stbtt__GetGlyfOffset(info, glyph_index)
STBTT_assert(info.cff.size == 0)
@@ -1017,6 +1066,7 @@ end
-- Gets the bounding box of the visible part of the glyph, in unscaled coordinates
--- @return integer, integer?, integer?, integer?, integer?
@native
local function stbtt_GetGlyphBox(info, glyph_index)
local n, x0, y0, x1, y1
@@ -1045,6 +1095,7 @@ end
--- @param scy stbtt_int32
--- @param cx stbtt_int32
--- @param cy stbtt_int32
@native
local function stbtt__close_shape(vertices, num_vertices, was_off, start_off, sx, sy, scx, scy, cx, cy)
if start_off then
if was_off then
@@ -1069,6 +1120,7 @@ end
--- @param glyph_index int
--- @return int num_vertices
--- @return stbtt_vertex[]? vertices
@native
local function stbtt__GetGlyphShapeTT(info, glyph_index)
local data = info.data
local num_vertices
@@ -1288,7 +1340,7 @@ local function stbtt__GetGlyphShapeTT(info, glyph_index)
n = STBTT_sqrt(mtx[3] * mtx[3] + mtx[4] * mtx[4])
-- Get indexed glyph.
comp_num_vertices, comp_verts = stbtt_GetGlyphShape(info, gidx)
comp_num_vertices, comp_verts = stbtt_GetGlyphShapeUncached(info, gidx) -- [Luau] transformed in place below: must be a fresh copy
if comp_num_vertices > 0 then
-- Transform vertices.
for i = 1, comp_num_vertices do
@@ -1326,6 +1378,7 @@ end
--- @param c stbtt__csctx
--- @param x stbtt_int32
--- @param y stbtt_int32
@native
local function stbtt__track_vertex(c, x, y)
if x > c.max_x or not c.started then c.max_x = x end
if y > c.max_y or not c.started then c.max_y = y end
@@ -1342,6 +1395,7 @@ end
--- @param cy stbtt_int32
--- @param cx1 stbtt_int32
--- @param cy1 stbtt_int32
@native
local function stbtt__csctx_v(c, vtx_type, x, y, cx, cy, cx1, cy1)
if c.bounds then
stbtt__track_vertex(c, x, y)
@@ -1357,6 +1411,7 @@ local function stbtt__csctx_v(c, vtx_type, x, y, cx, cy, cx1, cy1)
end
--- @param ctx stbtt__csctx
@native
local function stbtt__csctx_close_shape(ctx)
if ctx.first_x ~= ctx.x or ctx.first_y ~= ctx.y then
stbtt__csctx_v(ctx, STBTT_VTX.LINE, trunc(ctx.first_x), trunc(ctx.first_y), 0, 0, 0, 0)
@@ -1366,6 +1421,7 @@ end
--- @param ctx stbtt__csctx
--- @param dx float
--- @param dy float
@native
local function stbtt__csctx_rmove_to(ctx, dx, dy)
stbtt__csctx_close_shape(ctx)
ctx.x = ctx.x + dx
@@ -1378,6 +1434,7 @@ end
--- @param ctx stbtt__csctx
--- @param dx float
--- @param dy float
@native
local function stbtt__csctx_rline_to(ctx, dx, dy)
ctx.x = ctx.x + dx
ctx.y = ctx.y + dy
@@ -1391,6 +1448,7 @@ end
--- @param dy2 float
--- @param dx3 float
--- @param dy3 float
@native
local function stbtt__csctx_rccurve_to(ctx, dx1, dy1, dx2, dy2, dx3, dy3)
local cx1 = ctx.x + dx1
local cy1 = ctx.y + dy1
@@ -1401,6 +1459,7 @@ local function stbtt__csctx_rccurve_to(ctx, dx1, dy1, dx2, dy2, dx3, dy3)
stbtt__csctx_v(ctx, STBTT_VTX.CUBIC, trunc(ctx.x), trunc(ctx.y), trunc(cx1), trunc(cy1), trunc(cx2), trunc(cy2))
end
@native
local function stbtt__get_subr(idx, n)
local count = stbtt__cff_index_count(idx)
local bias = 107
@@ -1416,6 +1475,7 @@ local function stbtt__get_subr(idx, n)
return stbtt__cff_index_get(idx, n)
end
@native
local function stbtt__cid_get_glyph_subrs(info, glyph_index)
local fdselect = info.fdselect
local fdselector = -1
@@ -1446,6 +1506,7 @@ end
--- @param info stbtt_fontinfo
--- @param glyph_index int
--- @param c stbtt__csctx
@native
local function stbtt__run_charstring(info, glyph_index, c)
local in_header = true
local maskbits = 0
@@ -1719,6 +1780,7 @@ end
--- @param glyph_index int
--- @return int num_vertices
--- @return stbtt_vertex[]? vertices
@native
function stbtt__GetGlyphShapeT2(info, glyph_index)
-- runs the charstring twice, once to count and once to output (to avoid realloc)
local vertices = nil
@@ -1744,6 +1806,7 @@ end
--- @return int y0
--- @return int x1
--- @return int y1
@native
function stbtt__GetGlyphInfoT2(info, glyph_index)
local c = STBTT__CSCTX_INIT(true)
local r = stbtt__run_charstring(info, glyph_index, c)
@@ -1765,7 +1828,8 @@ end
-- its x,y, using cx,cy as the bezier control point.
--- @param info stbtt_fontinfo
--- @param glyph_index int
function stbtt_GetGlyphShape(info, glyph_index)
@native
function stbtt_GetGlyphShapeUncached(info, glyph_index)
if info.cff.size == 0 then
return stbtt__GetGlyphShapeTT(info, glyph_index)
else
@@ -1773,11 +1837,32 @@ function stbtt_GetGlyphShape(info, glyph_index)
end
end
@native
function stbtt_GetGlyphShape(info, glyph_index)
-- [Luau] shapes don't depend on the size: cache them per font (baking a new size re-used to re-parse every glyph).
-- Callers only read the vertices (stbtt_FreeShape is a no-op).
local cache = info._ShapeCache
if cache == nil then cache = {}; info._ShapeCache = cache end
local e = cache[glyph_index]
if e == nil then
local n, v
if info.cff.size == 0 then
n, v = stbtt__GetGlyphShapeTT(info, glyph_index)
else
n, v = stbtt__GetGlyphShapeT2(info, glyph_index)
end
e = { n, v }
cache[glyph_index] = e
end
return e[1], e[2]
end
-- leftSideBearing is the offset from the current horizontal position to the left edge of the character
-- advanceWidth is the offset from the current horizontal position to the next horizontal position
-- these are expressed in unscaled coordinates
--- @param info stbtt_fontinfo
--- @param glyph_index int
@native
function stbtt_GetGlyphHMetrics(info, glyph_index)
local numOfLongHorMetrics = ttUSHORT(info.data, info.hhea + 34)
@@ -1800,6 +1885,7 @@ end
-- these are expressed in unscaled coordinates, so you must multiply by
-- the scale factor for a given size
--- @param info stbtt_fontinfo
@native
function stbtt_GetFontVMetrics(info)
local ascent = ttSHORT(info.data, info.hhea + 4)
local descent = ttSHORT(info.data, info.hhea + 6)
@@ -1816,6 +1902,7 @@ end
-- so if you prefer to measure height by the ascent only, use a similar calculation.
--- @param info stbtt_fontinfo
--- @param height float
@native
function stbtt_ScaleForPixelHeight(info, height)
local fheight = ttSHORT(info.data, info.hhea + 4) - ttSHORT(info.data, info.hhea + 6)
return height / fheight
@@ -1836,6 +1923,7 @@ end
--- @param scale_y float
--- @param shift_x float
--- @param shift_y float
@native
function stbtt_GetGlyphBitmapBoxSubpixel(font, glyph, scale_x, scale_y, shift_x, shift_y)
local n, x0, y0, x1, y1 = stbtt_GetGlyphBox(font, glyph)
@@ -1866,6 +1954,7 @@ end
--- @param glyph int
--- @param scale_x float
--- @param scale_y float
@native
function stbtt_GetGlyphBitmapBox(font, glyph, scale_x, scale_y)
return stbtt_GetGlyphBitmapBoxSubpixel(font, glyph, scale_x, scale_y, 0.0, 0.0)
end
@@ -1893,6 +1982,7 @@ end
--- @param y0 float
--- @param x1 float
--- @param y1 float
@native
local function stbtt__handle_clipped_edge(scanline, x, e, x0, y0, x1, y1)
if y0 == y1 then return end
STBTT_assert(y0 < y1)
@@ -1934,6 +2024,7 @@ end
--- @param height float
--- @param top_width float
--- @param bottom_width float
@native
local function stbtt__sized_trapezoid_area(height, top_width, bottom_width)
STBTT_assert(top_width >= 0)
STBTT_assert(bottom_width >= 0)
@@ -1945,12 +2036,14 @@ end
--- @param tx1 float
--- @param bx0 float
--- @param bx1 float
@native
local function stbtt__position_trapezoid_area(height, tx0, tx1, bx0, bx1)
return stbtt__sized_trapezoid_area(height, tx1 - tx0, bx1 - bx0)
end
--- @param height float
--- @param width float
@native
local function stbtt__sized_triangle_area(height, width)
return height * width / 2
end
@@ -1960,6 +2053,7 @@ end
--- @param len int
--- @param e stbtt__active_edge
--- @param y_top float
@native
local function stbtt__fill_active_edges_new(scanline, scanline_fill, len, e, y_top)
local y_bottom = y_top + 1
@@ -2182,11 +2276,14 @@ end
--- @param vsubsample int
--- @param off_x int
--- @param off_y int
local rasterize_scanline, rasterize_scanline2 = {}, {} -- [Luau] reused: fully cleared per scanline below
@native
local function stbtt__rasterize_sorted_edges(result, e, n, vsubsample, off_x, off_y)
local active = nil
local scanline = {} -- [Port] size = result.w, 0-based
local scanline2 = {} -- [Port] size = result.w + 1, 0-based
active_pool_n = 0 -- every active edge of the previous call is dead
local scanline = rasterize_scanline -- [Port] size = result.w, 0-based
local scanline2 = rasterize_scanline2 -- [Port] size = result.w + 1, 0-based
STBTT__NOTUSED(vsubsample)
@@ -2257,7 +2354,7 @@ local function stbtt__rasterize_sorted_edges(result, e, n, vsubsample, off_x, of
end
-- advance all the edges
step = active
local step = active
while step do
step.fx = step.fx + step.fdx -- advance to position for current scanline
step = step.next -- advance through list
@@ -2277,6 +2374,7 @@ local STBTT__COMPARE = function(a, b)
end
--- @param p stbtt__edge[]
@native
local function stbtt__sort_edges(p)
STBTT_sort(p, STBTT__COMPARE)
end
@@ -2292,6 +2390,8 @@ end
--- @param off_x int
--- @param off_y int
--- @param invert bool
local rasterize_edges = {}
@native
local function stbtt__rasterize(result, pts, wcount, windings, scale_x, scale_y, shift_x, shift_y, off_x, off_y, invert)
local y_scale_inv = (invert) and -scale_y or scale_y
local vsubsample = 1 -- STBTT_RASTERIZER_VERSION == 2
@@ -2303,7 +2403,13 @@ local function stbtt__rasterize(result, pts, wcount, windings, scale_x, scale_y,
n = n + wcount[i]
end
local e = {} for i = 1, n + 1 do e[i] = stbtt__edge() end -- add an extra one as a sentinel
-- [Luau] edges reused across calls; unused entries are sentinels (y0 = nil) like the unfilled ones upstream
local e = rasterize_edges
for i = 1, n + 1 do
local ed = e[i]
if ed == nil then e[i] = stbtt__edge() else ed.y0 = nil; ed.invert = false end
end
for i = n + 2, #e do e[i].y0 = nil end
n = 0
local m = 0
@@ -2357,6 +2463,7 @@ end
--- @param n int
--- @param x float
--- @param y float
@native
local function stbtt__add_point(points, n, x, y)
if points == nil then return end -- during first pass, it's unallocated
points[n + 1].x = x
@@ -2375,6 +2482,7 @@ end
--- @param objspace_flatness_squared float
--- @param n int
--- @return int num_points # updated num_points passed in
@native
local function stbtt__tesselate_curve(points, num_points, x0, y0, x1, y1, x2, y2, objspace_flatness_squared, n)
-- midpoint
local mx = (x0 + 2 * x1 + x2) / 4
@@ -2411,6 +2519,7 @@ end
--- @param objspace_flatness_squared float
--- @param n int
--- @return int num_points # updated num_points passed in
@native
local function stbtt__tesselate_cubic(points, num_points, x0, y0, x1, y1, x2, y2, x3, y3, objspace_flatness_squared, n)
-- @TODO this "flatness" calculation is just made-up nonsense that seems to work well enough
local dx0 = x1 - x0
@@ -2462,6 +2571,8 @@ end
--- @return stbtt__point[]? points
--- @return int? num_contours
--- @return int[]? contour_lengths
local flatten_points = {}
@native
local function stbtt_FlattenCurves(vertices, num_verts, objspace_flatness)
local points = nil
local num_points = 0
@@ -2486,8 +2597,8 @@ local function stbtt_FlattenCurves(vertices, num_verts, objspace_flatness)
for pass = 0, 1 do
local x, y = 0, 0
if pass == 1 then
points = {}
for i = 1, num_points do points[i] = stbtt__point() end
points = flatten_points -- [Luau] reused across calls (only [1..num_points] is read)
for i = #points + 1, num_points do points[i] = stbtt__point() end
end
num_points = 0
n = -1
@@ -2544,6 +2655,7 @@ end
--- @param x_off int
--- @param y_off int
--- @param invert bool
@native
local function stbtt_Rasterize(result, flatness_in_pixels, vertices, num_verts, scale_x, scale_y, shift_x, shift_y, x_off, y_off, invert)
local scale = (scale_x > scale_y) and scale_y or scale_x
@@ -2571,6 +2683,7 @@ end
--- @param shift_x float
--- @param shift_y float
--- @param glyph int
@native
local function stbtt_MakeGlyphBitmapSubpixel(info, output, out_w, out_h, out_stride, scale_x, scale_y, shift_x, shift_y, glyph)
local num_verts, vertices = stbtt_GetGlyphShape(info, glyph)
local gbm = stbtt__bitmap()
@@ -2624,6 +2737,7 @@ local STBTT__OVER_MASK = STBTT_MAX_OVERSAMPLE - 1
--- @param h int
--- @param stride_in_bytes int
--- @param kernel_width unsigned_int
@native
local function stbtt__h_prefilter(pixels, w, h, stride_in_bytes, kernel_width)
local buffer = {}
local safe_w = w - kernel_width
@@ -2653,6 +2767,7 @@ end
--- @param h int
--- @param stride_in_bytes int
--- @param kernel_width unsigned_int
@native
local function stbtt__v_prefilter(pixels, w, h, stride_in_bytes, kernel_width)
local buffer = {}
local safe_h = h - kernel_width
@@ -2679,6 +2794,7 @@ end
--- @param oversample int
--- @return float
@native
local function stbtt__oversample_shift(oversample)
if oversample == 0 then
return 0.0
@@ -2705,6 +2821,7 @@ end
--- @param prefilter_x int
--- @param prefilter_y int
--- @param glyph int
@native
function stbtt_MakeGlyphBitmapSubpixelPrefilter(info, output, out_w, out_h, out_stride, scale_x, scale_y, shift_x, shift_y, prefilter_x, prefilter_y, glyph)
stbtt_MakeGlyphBitmapSubpixel(info, output, out_w - (prefilter_x - 1), out_h - (prefilter_y - 1), out_stride, scale_x, scale_y, shift_x, shift_y, glyph)
@@ -2758,6 +2875,7 @@ end
-- return '0' for index 0, and -1 for all other indices.
--- @param data table
--- @param index int
@native
function stbtt_GetFontOffsetForIndex(data, index) return stbtt_GetFontOffsetForIndex_internal(data, index) end
-- Given an offset into the file that defines a font, this function builds
@@ -2768,6 +2886,7 @@ function stbtt_GetFontOffsetForIndex(data, index) return stbtt_GetFontOffsetForI
--- @param info stbtt_fontinfo
--- @param data table
--- @param offset int
@native
function stbtt_InitFont(info, data, offset) return stbtt_InitFont_internal(info, data, offset) end
return {