1if not modules then modules = { } end modules [ ' font-imp-properties ' ] = {
2 version = 1 . 001 ,
3 comment = " companion to font-ini.mkiv and hand-ini.mkiv " ,
4 author = " Hans Hagen, PRAGMA-ADE, Hasselt NL " ,
5 copyright = " PRAGMA ADE / ConTeXt Development Team " ,
6 license = " see context related readme files "
7}
8
9if not context then return end
10
11local next , type , tonumber , select = next , type , tonumber , select
12local byte , find , formatters = string . byte , string . find , string . formatters
13local utfchar = utf . char
14local sortedhash , sortedkeys , sort = table . sortedhash , table . sortedkeys , table . sort
15local insert = table . insert
16
17local context = context
18local fonts = fonts
19local utilities = utilities
20
21local helpers = fonts . helpers
22
23local handlers = fonts . handlers
24local hashes = fonts . hashes
25local otf = handlers . otf
26local afm = handlers . afm
27
28local registerotffeature = otf . features . register
29local registerafmfeature = afm . features . register
30
31local fontdata = hashes . identifiers
32local fontproperties = hashes . properties
33
34local constructors = fonts . constructors
35local getprivate = constructors . getprivate
36
37local allocate = utilities . storage . allocate
38
39local setmetatableindex = table . setmetatableindex
40
41local implement = interfaces . implement
42
43do
44
45 local P , lpegpatterns , lpegmatch = lpeg . P , lpeg . patterns , lpeg . match
46
47 local amount , stretch , shrink , extra
48
49 local factor = lpegpatterns . unsigned
50 local space = lpegpatterns . space
51 local pattern = (
52 ( factor / function ( n ) amount = tonumber ( n ) or amount end )
53 + ( P ( " + " ) + P ( " plus " ) ) * space ^ 0 * ( factor / function ( n ) stretch = tonumber ( n ) or stretch end )
54 + ( P ( " - " ) + P ( " minus " ) ) * space ^ 0 * ( factor / function ( n ) shrink = tonumber ( n ) or shrink end )
55 + ( P ( " extra " ) ) * space ^ 0 * ( factor / function ( n ) extra = tonumber ( n ) or extra end )
56 + space ^ 1
57 ) ^ 1
58
59 local function initialize ( tfmdata , key , value )
60 local characters = tfmdata . characters
61 local parameters = tfmdata . parameters
62 if type ( value ) = = " string " then
63 local emwidth = parameters . quad
64 amount , stretch , shrink , extra = 0 , 0 , 0 , false
65 lpegmatch ( pattern , value )
66 if not extra then
67 if shrink ~ = 0 then
68 extra = shrink
69 elseif stretch ~ = 0 then
70 extra = stretch
71 else
72 extra = amount
73 end
74 end
75 parameters . space = amount * emwidth
76 parameters . space_stretch = stretch * emwidth
77 parameters . space_shrink = shrink * emwidth
78 parameters . extra_space = extra * emwidth
79 end
80 end
81
82
83
84 registerotffeature {
85 name = " spacing " ,
86 description = " space settings " ,
87 manipulators = {
88 base = initialize ,
89 node = initialize ,
90 }
91 }
92
93end
94
95do
96
97 local function initialize ( tfmdata , value )
98 local properties = tfmdata . properties
99 if properties then
100 properties . identity = value = = " vertical " and " vertical " or " horizontal "
101 end
102 end
103
104 registerotffeature {
105 name = " identity " ,
106 description = " set font identity " ,
107 initializers = {
108 base = initialize ,
109 node = initialize ,
110 }
111 }
112
113 local function initialize ( tfmdata , value )
114 local properties = tfmdata . properties
115 if properties then
116 properties . writingmode = value = = " vertical " and " vertical " or " horizontal "
117 end
118 end
119
120 registerotffeature {
121 name = " writingmode " ,
122 description = " set font direction " ,
123 initializers = {
124 base = initialize ,
125 node = initialize ,
126 }
127 }
128
129end
130 |