khaledhosny / luaotfload

Moved to https://github.com/latex3/luaotfload
23 stars 15 forks source link

Include font-pat.lua #20

Closed phst closed 13 years ago

phst commented 13 years ago

The file font-pat.lua contains patches for various font bugs, please include it in luaotfload.

khaledhosny commented 13 years ago

It can be tricky sense context modules usually depend on other modules (luaotfload is only possible because Hans deliberately cuts off the dependency of few modules to bare minimum so it can be used outside context).

phst commented 13 years ago

the patches are necessary and adding the ConTeXt file might be easiest, but of course that is not the only option. Relevant for me are only the lines that patch the DisplayOperatorMinHeight parameter (responsible for the tiny integral with Cambria Math), you could add these to the existing define_font callback in luaotfload.lua. Since define_font callbacks cannot be chained, you could also generalize the existing callback using a user-defined patch_font callback.

khaledhosny commented 13 years ago

Having such hooks are on my todo list, but I'm a bit busy now (and our stable branch lags behind ConTeXt significantly, so just borrowing another module is not feasible)

phst commented 13 years ago

ok, I'll see if I can provide a working patch that implements a simple hook system. The issue is that we have to fix font bugs directly after loading because if the font has already been selected it's too late.

phst commented 13 years ago

Here is a patch for luaotfload.dtx:

--- /data/Philipp.Stephani/opt/texlive/2010/texmf-dist/source/luatex/luaotfload/luaotfload.dtx  2010-11-18 01:35:21.000000000 +0100
+++ luaotfload.dtx  2010-11-24 18:10:05.000000000 +0100
@@ -587,6 +587,10 @@
 % to the \TeX\ end.
 %
 %    \begin{macrocode}
+local function default_callback(fontdata)
+    -- do nothing
+end
+luatexbase.create_callback("luaotfload.patch_font", "simple", default_callback)
 local function def_font(...)
     local fontdata = fonts.define.read(...)
     if type(fontdata) == "table" and fontdata.shared then
@@ -655,7 +659,7 @@
                 fontdata.parameters[11] = 50
             end
         end
-
+        luatexbase.call_callback("luaotfload.patch_font", fontdata)
     end
     return fontdata
 end
@@ -715,6 +719,10 @@
     luatexbase.remove_from_callback('find_vf_file',
                                      'luaotfload.find_vf_file')
 end
+
+function luaotfload.add_patch_callback(...)
+    luatexbase.add_to_callback("luaotfload.patch_font", ...)
+end
 %    \end{macrocode}
 %
 % \iffalse

Here is a possible application that fixes the integral size with Cambria Math:

\directlua {
  local~ function~ patch_font(fontdata)~
    if~ fontdata.MathConstants~ then~
      fontdata.MathConstants.DisplayOperatorMinHeight = \number \dimexpr 4ex \relax \c_space_tl~
    end~
  end~
  luaotfload.add_patch_callback(patch_font, "modernmath.patch_font")
}
khaledhosny commented 13 years ago

A slightly modified version of the patch (and a test file) are in git now.

phst commented 13 years ago

thanks, I'll test it tomorrow

phst commented 13 years ago

Seems to work fine. (I'm not closing this right now since although it can be used to solve the Cambria Math integral problem, the patches from font-pat.lua aren't implemented yet.)

khaledhosny commented 13 years ago

I think this now belongs to unicode-math or lualatex-math packages.