[Dev-luatex] [PATCH] luaharfbuzz: Provide interface for variable fonts

Marcel Fabian Krüger tex at 2krueger.de
Tue Aug 3 13:43:57 CEST 2021


On Tue, Aug 03, 2021 at 11:51:16AM +0200, luigi scarso wrote:
> On Mon, Aug 2, 2021 at 8:40 PM Marcel Fabian Krüger <tex at 2krueger.de> wrote:
> 
> >
> > > 1) why 2 files ?
> >
> > Whenever I checkout the sources from git, svn or the web interface I get
> > files
> > with UNIX line ending, but some months ago you mentioned that a patch
> > couldn't be applied because it should have used Windows line endings
> > instead. Therefore I added a .win version with Windows line endings to
> > avoid issues but still included the other patch since that's the one I
> > actually tested locally.
> >
> >
> Do you remember the email ? All code should be with UNIX line ending

Hi Luigi,

Oops, looking back I realized that I remembered it incorrectly: The issue
was that the file couldn't get applied because the *patch* had Windows
lineendings. Not sure how that happened but anyway I stand corrected.

> 
> Sure, I added a zip of the individual patches.
> >
> 
> Patches applied, but I don't have variation.c, which is mentioned
> in luaharfbuzz.am.patch
> and  so variation.c.patch cannot be applied .

Actually variation.c.patch is supposed to create a new file, so it
should work even if the file doesn't exists yet. Not sure how standard
that format is though, it seems to be a git extension which got picked
up by GNU patch but not by many other tools.

I added the full file variation.c as an attachment. It belongs at
source/texk/web2c/luatexdir/luaharfbuzz/src/luaharfbuzz/variation.c

Best,
Marcel
-------------- next part --------------
// harfbuzz.Variation
#include "luaharfbuzz.h"

static int variation_new(lua_State *L) {
  Variation v;
  const char *variation = luaL_checkstring(L, 1);

  if (hb_variation_from_string(variation, -1, &v)) {
    Variation *vp = (Variation *)lua_newuserdata(L, sizeof(*vp));
    luaL_getmetatable(L, "harfbuzz.Variation");
    lua_setmetatable(L, -2);
    *vp = v;
  } else {
    lua_pushnil(L);
  }

  return 1;
}

static int variation_to_string(lua_State *L) {
  Variation* v = (Variation *)luaL_checkudata(L, 1, "harfbuzz.Variation");
  char variation[128];

  hb_variation_to_string(v, variation, 128);
  lua_pushstring(L, variation);
  return 1;
}

static const char *variation_tag_ptr;
static const char *variation_value_ptr;

static int variation_index(lua_State *L) {
  Variation* v = (Variation *)luaL_checkudata(L, 1, "harfbuzz.Variation");
  const char *key = lua_tostring(L, 2);

  if (key == variation_tag_ptr) {
    Tag *tag = (Tag *)lua_newuserdata(L, sizeof(*tag));
    luaL_getmetatable(L, "harfbuzz.Tag");
    lua_setmetatable(L, -2);
    *tag = v->tag;
  } else if (key == variation_value_ptr) {
    lua_pushnumber(L, v->value);
  } else {
    lua_pushnil(L);
  }
  return 1;
}

static int variation_newindex(lua_State *L) {
  Variation* v = (Variation *)luaL_checkudata(L, 1, "harfbuzz.Variation");
  const char *key = lua_tostring(L, 2);

  if (key == variation_tag_ptr) {
    v->tag = *(Tag *)luaL_checkudata(L, 3, "harfbuzz.Tag");
  } else if (key == variation_value_ptr) {
    v->value = luaL_checknumber(L, 3);
  }
  return 0;
}

static const struct luaL_Reg variation_methods[] = {
  { "__index", variation_index },
  { "__newindex", variation_newindex },
  { "__tostring", variation_to_string },
  { NULL, NULL },
};

static const struct luaL_Reg variation_functions[] = {
  { "new", variation_new },
  { NULL,  NULL }
};

int register_variation(lua_State *L) {
  lua_pushliteral(L, "tag");
  variation_tag_ptr = lua_tostring(L, -1);
  (void) luaL_ref (L, LUA_REGISTRYINDEX);
  lua_pushliteral(L, "value");
  variation_value_ptr = lua_tostring(L, -1);
  (void) luaL_ref (L, LUA_REGISTRYINDEX);

  return register_class(L, "harfbuzz.Variation", variation_methods, variation_functions, NULL);
}


More information about the dev-luatex mailing list