<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.luatex.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Khaled</id>
	<title>LuaTeXWiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.luatex.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Khaled"/>
	<link rel="alternate" type="text/html" href="https://wiki.luatex.org/index.php/Special:Contributions/Khaled"/>
	<updated>2026-05-26T12:06:29Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.31.1</generator>
	<entry>
		<id>https://wiki.luatex.org/index.php?title=Use_a_TrueType_font&amp;diff=152</id>
		<title>Use a TrueType font</title>
		<link rel="alternate" type="text/html" href="https://wiki.luatex.org/index.php?title=Use_a_TrueType_font&amp;diff=152"/>
		<updated>2011-10-02T22:23:37Z</updated>

		<summary type="html">&lt;p&gt;Khaled: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A TrueType (or Openype) font can be used without going through a TFM or an OFM file, like in XeTeX.&lt;br /&gt;
&lt;br /&gt;
For plain/LaTeX you are better using the package luaotfload, on the CTAN, and developped here: http://github.com/khaledhosny/luaotfload/, ConTeXt have this functionality built-in.&lt;br /&gt;
&lt;br /&gt;
The code shows how we can use the table of a TrueType font to produce an internal TeX font table:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
\pdfoutput1&lt;br /&gt;
\directlua{&lt;br /&gt;
callback.register(&amp;quot;define_font&amp;quot;,&lt;br /&gt;
  function(name, size)&lt;br /&gt;
    local fonttype, f&lt;br /&gt;
    local fonttype = string.match(string.lower(name), &amp;quot;otf$&amp;quot;) and &amp;quot;opentype&amp;quot;&lt;br /&gt;
                  or string.match(string.lower(name), &amp;quot;ttf$&amp;quot;) and &amp;quot;truetype&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    if fonttype then&lt;br /&gt;
      filename = kpse.find_file(name, &amp;quot;opentype fonts&amp;quot;) or kpse.find_file(name, &amp;quot;truetype fonts&amp;quot;)&lt;br /&gt;
      if size &amp;lt; 0 then&lt;br /&gt;
        size = (- 655.36) * size&lt;br /&gt;
      end&lt;br /&gt;
      ttffont = fontloader.to_table(fontloader.open(filename))&lt;br /&gt;
      if ttffont then&lt;br /&gt;
        f = { }&lt;br /&gt;
        f.name = ttffont.fontname&lt;br /&gt;
        f.fullname = ttffont.names[1].names.fullname&lt;br /&gt;
        f.parameters = { }&lt;br /&gt;
        f.designsize = size&lt;br /&gt;
        f.size = size&lt;br /&gt;
        f.direction = 0&lt;br /&gt;
        f.parameters.slant = 0&lt;br /&gt;
        f.parameters.space = size * 0.25&lt;br /&gt;
        f.parameters.space_stretch = 0.3 * size&lt;br /&gt;
        f.parameters.space_shrink = 0.1 * size&lt;br /&gt;
        f.parameters.x_height = 0.4 * size&lt;br /&gt;
        f.parameters.quad = 1.0 * size&lt;br /&gt;
        f.parameters.extra_space = 0&lt;br /&gt;
        f.characters = { }&lt;br /&gt;
        local mag = size / ttffont.units_per_em&lt;br /&gt;
&lt;br /&gt;
        local names_of_char = { }&lt;br /&gt;
        for char, glyph in pairs(ttffont.map.map) do&lt;br /&gt;
          names_of_char[ttffont.glyphs[glyph].name] = ttffont.map.backmap[glyph]&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        for char, glyph in pairs(ttffont.map.map) do&lt;br /&gt;
          local glyph_table = ttffont.glyphs[glyph]&lt;br /&gt;
&lt;br /&gt;
          f.characters[char] = {&lt;br /&gt;
            index = glyph,&lt;br /&gt;
            width = glyph_table.width * mag,&lt;br /&gt;
            name = glyph_table.name }&lt;br /&gt;
          if glyph_table.boundingbox[4] then&lt;br /&gt;
            f.characters[char].height = glyph_table.boundingbox[4] * mag&lt;br /&gt;
          end&lt;br /&gt;
          if glyph_table.boundingbox[2] then&lt;br /&gt;
            f.characters[char].depth = -glyph_table.boundingbox[2] * mag&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          if glyph_table.kerns then&lt;br /&gt;
            local kerns = { }&lt;br /&gt;
            for _, kern in pairs(glyph_table.kerns) do&lt;br /&gt;
              kerns[names_of_char[kern.char]] = kern.off * mag&lt;br /&gt;
            end&lt;br /&gt;
            f.characters[char].kerns = kerns&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        &lt;br /&gt;
        f.filename = filename&lt;br /&gt;
        f.type = &amp;quot;real&amp;quot;&lt;br /&gt;
        f.format = fonttype&lt;br /&gt;
        f.embedding = &amp;quot;subset&amp;quot;&lt;br /&gt;
        f.cidinfo = {&lt;br /&gt;
          registry = &amp;quot;Adobe&amp;quot;,&lt;br /&gt;
          ordering = &amp;quot;Identity&amp;quot;,&lt;br /&gt;
          supplement = 0,&lt;br /&gt;
          version = 1 }&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      f = font.read_tfm(name, size)&lt;br /&gt;
    end&lt;br /&gt;
  return f&lt;br /&gt;
  end)&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The index of the &amp;lt;tt&amp;gt;f.characters&amp;lt;/tt&amp;gt; table is the Unicode value, among the properties of each entry of that table we have &amp;lt;tt&amp;gt;index&amp;lt;/tt&amp;gt; which is the glyph index. Using this property we get the mapping between Unicode characters and glyphs. Kerning is handled via TeX font LKP.&lt;br /&gt;
&lt;br /&gt;
What is missing in the code above is better calculation of standard TeX font parameters and OpenType features.&lt;/div&gt;</summary>
		<author><name>Khaled</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.luatex.org/index.php?title=Use_a_TrueType_font&amp;diff=151</id>
		<title>Use a TrueType font</title>
		<link rel="alternate" type="text/html" href="https://wiki.luatex.org/index.php?title=Use_a_TrueType_font&amp;diff=151"/>
		<updated>2011-10-02T22:22:57Z</updated>

		<summary type="html">&lt;p&gt;Khaled: correct link and stuff&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A TrueType (or Openype) font can be used without going through a TFM or an OFM file, like in XeTeX.&lt;br /&gt;
&lt;br /&gt;
For plain/LaTeX you are better using the package luaotfload, on the CTAN, and developped here: http://github.com/khaledhosn/luaotfload/, ConTeXt have this functionality built-in.&lt;br /&gt;
&lt;br /&gt;
The code shows how we can use the table of a TrueType font to produce an internal TeX font table:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
\pdfoutput1&lt;br /&gt;
\directlua{&lt;br /&gt;
callback.register(&amp;quot;define_font&amp;quot;,&lt;br /&gt;
  function(name, size)&lt;br /&gt;
    local fonttype, f&lt;br /&gt;
    local fonttype = string.match(string.lower(name), &amp;quot;otf$&amp;quot;) and &amp;quot;opentype&amp;quot;&lt;br /&gt;
                  or string.match(string.lower(name), &amp;quot;ttf$&amp;quot;) and &amp;quot;truetype&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    if fonttype then&lt;br /&gt;
      filename = kpse.find_file(name, &amp;quot;opentype fonts&amp;quot;) or kpse.find_file(name, &amp;quot;truetype fonts&amp;quot;)&lt;br /&gt;
      if size &amp;lt; 0 then&lt;br /&gt;
        size = (- 655.36) * size&lt;br /&gt;
      end&lt;br /&gt;
      ttffont = fontloader.to_table(fontloader.open(filename))&lt;br /&gt;
      if ttffont then&lt;br /&gt;
        f = { }&lt;br /&gt;
        f.name = ttffont.fontname&lt;br /&gt;
        f.fullname = ttffont.names[1].names.fullname&lt;br /&gt;
        f.parameters = { }&lt;br /&gt;
        f.designsize = size&lt;br /&gt;
        f.size = size&lt;br /&gt;
        f.direction = 0&lt;br /&gt;
        f.parameters.slant = 0&lt;br /&gt;
        f.parameters.space = size * 0.25&lt;br /&gt;
        f.parameters.space_stretch = 0.3 * size&lt;br /&gt;
        f.parameters.space_shrink = 0.1 * size&lt;br /&gt;
        f.parameters.x_height = 0.4 * size&lt;br /&gt;
        f.parameters.quad = 1.0 * size&lt;br /&gt;
        f.parameters.extra_space = 0&lt;br /&gt;
        f.characters = { }&lt;br /&gt;
        local mag = size / ttffont.units_per_em&lt;br /&gt;
&lt;br /&gt;
        local names_of_char = { }&lt;br /&gt;
        for char, glyph in pairs(ttffont.map.map) do&lt;br /&gt;
          names_of_char[ttffont.glyphs[glyph].name] = ttffont.map.backmap[glyph]&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        for char, glyph in pairs(ttffont.map.map) do&lt;br /&gt;
          local glyph_table = ttffont.glyphs[glyph]&lt;br /&gt;
&lt;br /&gt;
          f.characters[char] = {&lt;br /&gt;
            index = glyph,&lt;br /&gt;
            width = glyph_table.width * mag,&lt;br /&gt;
            name = glyph_table.name }&lt;br /&gt;
          if glyph_table.boundingbox[4] then&lt;br /&gt;
            f.characters[char].height = glyph_table.boundingbox[4] * mag&lt;br /&gt;
          end&lt;br /&gt;
          if glyph_table.boundingbox[2] then&lt;br /&gt;
            f.characters[char].depth = -glyph_table.boundingbox[2] * mag&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          if glyph_table.kerns then&lt;br /&gt;
            local kerns = { }&lt;br /&gt;
            for _, kern in pairs(glyph_table.kerns) do&lt;br /&gt;
              kerns[names_of_char[kern.char]] = kern.off * mag&lt;br /&gt;
            end&lt;br /&gt;
            f.characters[char].kerns = kerns&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        &lt;br /&gt;
        f.filename = filename&lt;br /&gt;
        f.type = &amp;quot;real&amp;quot;&lt;br /&gt;
        f.format = fonttype&lt;br /&gt;
        f.embedding = &amp;quot;subset&amp;quot;&lt;br /&gt;
        f.cidinfo = {&lt;br /&gt;
          registry = &amp;quot;Adobe&amp;quot;,&lt;br /&gt;
          ordering = &amp;quot;Identity&amp;quot;,&lt;br /&gt;
          supplement = 0,&lt;br /&gt;
          version = 1 }&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      f = font.read_tfm(name, size)&lt;br /&gt;
    end&lt;br /&gt;
  return f&lt;br /&gt;
  end)&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The index of the &amp;lt;tt&amp;gt;f.characters&amp;lt;/tt&amp;gt; table is the Unicode value, among the properties of each entry of that table we have &amp;lt;tt&amp;gt;index&amp;lt;/tt&amp;gt; which is the glyph index. Using this property we get the mapping between Unicode characters and glyphs. Kerning is handled via TeX font LKP.&lt;br /&gt;
&lt;br /&gt;
What is missing in the code above is better calculation of standard TeX font parameters and OpenType features.&lt;/div&gt;</summary>
		<author><name>Khaled</name></author>
		
	</entry>
</feed>