summaryrefslogtreecommitdiff
path: root/texmf-dist/tex/generic/harftex/harf-base.lua
blob: 37970b29df967fa63b71e0541e0021e94a043a42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
local hb = require("luaharfbuzz")

-- LuaTeX’s TFM structure indexes glyphs by character codes, so we fake it by
-- adding the maximum possible Unicode code point to the glyph id. This way
-- we have a simple mapping for all glyphs without interfering with any valid
-- Unicode code point.
--
-- LuaTeX use the first 256 characters above maximum Unicode character for
-- escaping raw bytes, so skip that as well.
hb.CH_GID_PREFIX = 0x110000 + 256


-- Legacy TeX Input Method Disguised as Font Ligatures hack.
--
-- Single replacements, keyed by character to replace. Handled separately
-- because TeX ligaturing mechanism does not support one-to-one replacements.
local trep = {
  [0x0022] = 0x201D, -- ["]
  [0x0027] = 0x2019, -- [']
  [0x0060] = 0x2018, -- [`]
}

-- Ligatures. The value is a character "ligature" table as described in the
-- manual.
local tlig ={
  [0x2013] = { [0x002D] = { char = 0x2014 } }, -- [---]
  [0x002D] = { [0x002D] = { char = 0x2013 } }, -- [--]
  [0x0060] = { [0x0060] = { char = 0x201C } }, -- [``]
  [0x0027] = { [0x0027] = { char = 0x201D } }, -- ['']
  [0x0021] = { [0x0060] = { char = 0x00A1 } }, -- [!`]
  [0x003F] = { [0x0060] = { char = 0x00BF } }, -- [?`]
  [0x002C] = { [0x002C] = { char = 0x201E } }, -- [,,]
  [0x003C] = { [0x003C] = { char = 0x00AB } }, -- [<<]
  [0x003E] = { [0x003E] = { char = 0x00BB } }, -- [>>]
}

hb.texrep = trep
hb.texlig = tlig

return hb