Skip to content

Commit 4b6aa5e

Browse files
committed
feat(fonts): Configure macOS to fallback from macfonts to fontconfig
1 parent d2fb48a commit 4b6aa5e

1 file changed

Lines changed: 26 additions & 10 deletions

File tree

core/fontmanager.lua

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,36 @@
11
local fontManager = {}
2+
23
fontManager.fontconfig = require("justenoughfontconfig")
3-
pcall(function ()
4-
fontManager.macfonts = require("macfonts")
5-
end)
4+
5+
local has_macfonts, macfonts = pcall(require, "macfonts")
6+
if has_macfonts and macfonts then
7+
fontManager.macfonts = macfonts
8+
end
9+
10+
local function create_macfonts_fallback (self)
11+
return function (...)
12+
SU.debug("fonts", "Checking via macfonts")
13+
local status, result = pcall(self.macfonts._face, ...)
14+
if status and result and result.filename then
15+
SU.debug("fonts", "Found, returning result")
16+
return result
17+
else
18+
SU.debug("fonts", "Not found, trying fontconfig instead")
19+
return self.fontconfig._face(...)
20+
end
21+
end
22+
end
623

724
fontManager.face = function (self, ...)
8-
local manager
25+
local face
926
if SILE.input.fontmanager then
10-
manager = self[SILE.input.fontmanager]
27+
face = self[SILE.input.fontmanager]._face
28+
elseif has_macfonts then
29+
face = create_macfonts_fallback(self)
1130
else
12-
manager = self.macfonts and self.macfonts or self.fontconfig
13-
end
14-
if not manager then
15-
SU.error("Failed to load any working font manager")
31+
face = self.fontconfig._face
1632
end
17-
return manager._face(...)
33+
return face(...)
1834
end
1935

2036
return fontManager

0 commit comments

Comments
 (0)