@@ -31,6 +31,28 @@ local function controlBox(world: tecs.ecs.World, label: string): tecs.ui.Layout
3131 return assert(world:get(control, tecs.ui.Layout))
3232end
3333
34+ local function checkSharedFonts(world: tecs.ecs.World, density: number): nil
35+ local fonts: {[number]: tecs.gfx.fonts.Font} = {}
36+ local texts = world:newQuery({include = {tecs.gfx.Text}})
37+ local checked = 0
38+ for candidate, count in texts:iter() do
39+ const column = assert(candidate:get(tecs.gfx.Text))
40+ for row = 1, count as integer do
41+ const text = column[row]
42+ const font = assert(text.font)
43+ nupp.test.equal(font.size, text.size * density)
44+ const shared = fonts[text.size]
45+ if shared then
46+ nupp.test.assert(font == shared, "demo labels overwrite the same image with different font atlases")
47+ checked = checked + 1
48+ else
49+ fonts[text.size] = font
50+ end
51+ end
52+ end
53+ nupp.test.assert(checked > 0, "demo must contain labels sharing a font size")
54+ end
55+
3456local function checkSceneGeometry(world: tecs.ecs.World, scene: string): nil
3557 if scene == "Flex" then
3658 const fixed = controlBox(world, "88px")
@@ -105,6 +127,7 @@ function suite.switchesEveryOriginalSceneThroughPointerInput(): nil
105127 end
106128 local heading = assert(world:get(textEntity(world, "Tecs UI"), tecs.gfx.Text))
107129 nupp.test.equal(assert(heading.font).size, 64)
130+ checkSharedFonts(world, 2)
108131 tecs.host.shutdown(session)
109132 tecs.files.reset()
110133end
@@ -125,6 +148,12 @@ function suite.keepsTheCenteredStandalonePanel(): nil
125148 nupp.test.equal(layout.width, 420)
126149 nupp.test.equal(layout.height, 540)
127150 nupp.test.assert(#tecs.gfx.text.glyphsOf(world, textEntity(world, "Rectangle instance")) > 0)
151+ checkSharedFonts(world, 1)
152+ for index, density in ipairs({2, 1, 2}) do
153+ tecs.host.pushResize(session, false, 960, 640, 960 * density, 640 * density, density, index, index)
154+ frame(session)
155+ checkSharedFonts(world, density)
156+ end
128157 tecs.host.shutdown(session)
129158 tecs.files.reset()
130159end
0 commit comments