Skip to content

Commit

Permalink
feat(shapers): Support named instances with FontConfig
Browse files Browse the repository at this point in the history
FontConfig will use the upper bits of the face index for named instance
index, and hb_font_create() handles this, but we were stripping these
bits prematurely. Strip them before sending the index to libtextpdf
instead.

With named instances supported, saying \font[name=Foo, weight=700] of a
variable font will set the correct variation coordinates for the named
instance, instead of always using the default instance.
  • Loading branch information
khaledhosny authored and alerque committed Jan 25, 2023
1 parent 8279a4e commit 29119b9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 0 additions & 4 deletions shapers/harfbuzz.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 81,6 @@ function shaper.getFace (opts)
SU.debug("fonts", "Resolved font family", opts.family, "->", face and face.filename)
if not face or not face.filename then SU.error("Couldn't find face '"..opts.family.."'") end
if SILE.makeDeps then SILE.makeDeps:add(face.filename) end
if bitshim.rshift(face.index, 16) ~= 0 then
SU.warn("GX feature in '"..opts.family.."' is not supported, fallback to regular font face.")
face.index = bitshim.band(face.index, 0xff)
end
face.variations = opts.variations or ""
face.pointsize = ("%g"):format(SILE.measurement(opts.size):tonumber())

Expand Down
4 changes: 4 additions & 0 deletions src/justenoughlibtexpdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 105,10 @@ int pdf_loadfont(lua_State *L) {
if (lua_isnumber(L, -1)) { index = lua_tointeger(L, -1); }
lua_pop(L,1);

/* FontConfig uses the upper bits of the face index for named instance index,
* but libtexpdf knows nothing about this. */
index &= 0xFFFFu;

lua_pushstring(L, "pointsize");
lua_gettable(L, -2);
if (lua_isnumber(L, -1)) { ptsize = lua_tonumber(L, -1); }
Expand Down

0 comments on commit 29119b9

Please sign in to comment.