-- lx-bundle:true

-- This file is part of Lx and Qui, created by Liqube <www.liqube.com>
-- Copyright Liqube Audio. All rights reserved.
-- Lx Interim License. See LICENSE for details.

--- Describe fonts for the new UI without loading a pixel-sized renderer resource
-- @module qui.font

local font_api = assert(ui_font, "the UI font API is not loaded")
local Font = {}
local default_fallbacks = {
	FONTS_DIR .. "symbols.ttf",
	FONTS_DIR .. "coloremoji.ttf",
	FONTS_DIR .. "emoji.ttf",
	FONTS_DIR .. "symbols2.ttf",
}

--- Create one immutable font description measured in DIPs
-- @param options table primary path, fallback paths, size, and rendering preferences
-- @return userdata font checked C++ description handle
function Font.new(options)
	assert(type(options) == "table", "Font expects a table")

	return font_api.create(options)
end

--- Create one stock UI font size without repeating its face and fallback order
-- @param size number requested DIP size
-- @return userdata font checked C++ description handle
local function stock_font(size)
	return Font.new({
		path = FONTS_DIR .. "sans.ttf",
		fallbacks = default_fallbacks,
		size = size,
	})
end

-- Stock sizes share one face family while Controls choose the size suited to their role
Font.default = stock_font(14)
Font.compact = stock_font(13)

-- Callable module syntax keeps custom font declarations compact
setmetatable(Font, {
	__call = function(_, options)
		return Font.new(options)
	end,
})

return Font
