summaryrefslogtreecommitdiff
path: root/fonts/yfonts-otf/tex/oldgerm-otf.sty
blob: e58caaeb909093e0426644f7bd4b62e150192018 (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
\NeedsTeXFormat{LaTeX2e}[2019-01-01]
\def\fileversion{0.30}
\def\filedate{2022-07-18}
\ProvidesPackage{oldgerm-otf}[\filedate\space\fileversion]
\RequirePackage{iftex}[2019-10-24]
\newif\ifOGotf@oldumlaut
\newif\ifOGotf@gothlongs
\DeclareOption{oldumlaut}{\OGotf@oldumlauttrue}
\DeclareOption{gothvarlongs}{\OGotf@gothlongstrue}
\ProcessOptions
\iftutex
  \RequirePackage{fontspec}
  \ifOGotf@gothlongs
    \newfontfamily\gothfamily{ygoth.otf}%
      [Alternate=1, RawFeature=+hist;+rlig;+liga;+dlig;+hlig;+alig;+calt]
  \else
    \newfontfamily\gothfamily{ygoth.otf}%
      [RawFeature=+hist;+rlig;+liga;+dlig;+hlig;+alig;+calt]
  \fi
  \ifOGotf@oldumlaut
    \newfontfamily\swabfamily{yswab.otf}%
      [Alternate=0, RawFeature=+hist;+rlig;+liga;+dlig;+hlig;+calt]
    \newfontfamily\frakfamily{yfrak.otf}%
      [Alternate=0, RawFeature=+hist;+rlig;+liga;+dlig;+hlig;+calt]
  \else
    \newfontfamily\swabfamily{yswab.otf}%
      [RawFeature=+hist;+rlig;+liga;+dlig;+hlig;+calt]
    \newfontfamily\frakfamily{yfrak.otf}%
      [RawFeature=+hist;+rlig;+liga;+dlig;+hlig;+calt]
  \fi
  \DeclareTextFontCommand{\textgoth}{\gothfamily}
  \DeclareTextFontCommand{\textswab}{\swabfamily}
  \DeclareTextFontCommand{\textfrak}{\frakfamily}
  \DeclareTextCommand{\Jvar}{TU}{\textfrak{\char"E960}}
  \DeclareTextCommand{\etc}{TU}{\textfrak{\char"E961}}
  \ifluatex
    % This function adds character U+200B (zero width space) when an "s"
    % is followed by a TeX space (glue or penalty or a disc)
    % so that it is not turned into a long "s" by the "calt" feature.
    \directlua{%
      function add_eow_char (head)
        local eow = 0x200B
        local GLUE = node.id("glue")
        local GLYPH = node.id("glyph")
        local PENALTY = node.id("penalty")
        local DISC = node.id("disc")
        local Longs =
          {[string.byte("s")] = true}
        local new_node  = node.new
        local copy_node = node.copy
        local insert_node_after = node.insert_after
        % Perserve TeX's kerning
        head = node.kerning(head)
        % wordbd is the zero width node to add
        local wordbd = new_node(GLYPH)
        for item in node.traverse_id(GLYPH, head) do
            if Longs[item.char] then
               local fid = item.font
               % Check if char U+200B is available in the current font:
               % code borrowed from file "luaotfload-auxiliary.lua".
               local fontdata = fonts.hashes.identifiers[fid]
               if fontdata and fontdata.characters[eow] then
                  local nxt = item.next
                  if not nxt or nxt.id == GLUE or nxt.id == PENALTY
                             or nxt.id == DISC then
                     wordbd.font = fid
                     wordbd.char = eow
                     wordbd.attr = item.attr
                     insert_node_after(head,item,copy_node(wordbd))
                  end
               end
            end
        end
      end
      }
      % Register in callback "kerning".
      \AtBeginDocument{%
        \directlua{
          luatexbase.add_to_callback("kerning", add_eow_char,
                                     "add_end_of_word_boundary");
        }%
      }
  \fi
\else
  \PackageWarning{oldgerm-otf}%
     {This package requires LuaTeX or XeTeX engines.
      With other engines, consider using `oldgerm.sty', reported}
\fi
\endinput