Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Push ttf patch #3

Open
wants to merge 3 commits into
base: hacking_ttf_font_loading
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions CorsixTH/Lua/dialogs/jukebox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ SOFTWARE. --]]
local ipairs
= ipairs

local TH = require("TH")

class "UIJukebox" (Window)

---@type UIJukebox
Expand All @@ -41,13 +43,14 @@ function UIJukebox:UIJukebox(app)
self.blue_font = app.gfx:loadFont("QData", "Font02V")

if TH.freetype_font then
-- Temporarily set the complete path to the font for debugging
local font_data = self.app.gfx:_loadFontData("/usr/share/fonts/truetype/material-design-icons-iconfont/MaterialIcons-Regular.ttf")

if not font_data then error("Can't load the Material Icons font!") end
-- Boldly copied from app.lua, lines 197..200, but it makes little sense to me.
local builtin_font = self.gfx:loadBuiltinFont()
self.materials = Graphics._constructTtfFont(font_data, builtin_font:getSheet())
local builtin_font = app.gfx:loadBuiltinFont()
self.materials = app.gfx:_constructTtfFont(font_data, builtin_font:getSheet())
else
print("no font available")
error("Can't load this UI, Freetype2 missing")
end

-- Dialog head (current track title & exit button)
Expand Down Expand Up @@ -168,6 +171,9 @@ function UIJukebox:draw(canvas, x, y)
end
Window.draw(self, canvas, x, y)
x, y = self.x + x, self.y + y
-- draw a material icon character in the top corner of the window
-- Currently using "Link" icon
self.materials:draw(canvas, "\u{e157}", x + 10, y + 10)

local playing = self.audio.background_music or ""
for i, info in ipairs(self.audio.background_playlist) do
Expand Down
14 changes: 10 additions & 4 deletions CorsixTH/Lua/graphics.lua
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ function Graphics:loadFontFile()
end

-- Adjust unicode font in the configuration if needed.
if self.ttf_font_data and self.app.config.unicode_font ~= loaded_font_file then
if self.ttf_font_data and self.app.config.unicode_font ~= loaded_font_path then
self.app.config.unicode_font = loaded_font_file
self.app:saveConfig()
end
Expand Down Expand Up @@ -429,7 +429,8 @@ function Graphics:loadLanguageFont(name, sprite_table, ...)
local cache = self.cache.language_fonts[name]
font = cache and cache[sprite_table]
if not font then
font = Graphics.lf:_constructTtfFont(self.ttf_font_data, sprite_table)

font = Graphics:_constructTtfFont(self.ttf_font_data, sprite_table)
self.reload_functions_last[font] = font_reloader

if not cache then
Expand All @@ -443,11 +444,16 @@ function Graphics:loadLanguageFont(name, sprite_table, ...)
return font
end

function Graphics._constructTtfFont(font_data, sprite_table)
-- Prepare a TTF font for use in the UI
-- font_data is the loaded font file
-- sprite_table gives the structural layout, but isn't actually used for TTF so we use
-- builtin_font instead
function Graphics:_constructTtfFont(font_data, sprite_table, direct_load)
local font = TH.freetype_font()
-- TODO: Choose face based on "name" rather than always using same face.
font:setFace(self.ttf_font_data)
font:setFace(font_data)
font:setSheet(sprite_table)
-- Not sure if self.load_info or something similar is needed for persistence
return font
end

Expand Down
Loading