1if not modules then modules = { } end modules ['font-imp-italics'] = {
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
9local next, tonumber = next, tonumber
10
11local fonts = fonts
12local handlers = fonts.handlers
13local registerotffeature = handlers.otf.features.register
14local registerafmfeature = handlers.afm.features.register
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
43local function initialize(tfmdata,value)
44 if value then
45
46 local parameters = tfmdata.parameters
47 local italicangle = parameters.italicangle
48 if italicangle and italicangle ~= 0 then
49 local properties = tfmdata.properties
50 local factor = tonumber(value) or 1
51 properties.hasitalics = true
52 properties.autoitalicamount = factor * (parameters.uwidth or 40)/2
53 end
54 end
55end
56
57local specification = {
58 name = "itlc",
59 description = "italic correction",
60 initializers = {
61 base = initialize,
62 node = initialize,
63 }
64}
65
66registerotffeature(specification)
67registerafmfeature(specification)
68
69if context then
70
71 local function initialize(tfmdata,value)
72 tfmdata.properties.textitalics = toboolean(value)
73 end
74
75 local specification = {
76 name = "textitalics",
77 description = "use alternative text italic correction",
78 initializers = {
79 base = initialize,
80 node = initialize,
81 }
82 }
83
84 registerotffeature(specification)
85 registerafmfeature(specification)
86
87
88
89 local letter = characters.is_letter
90 local always = true
91
92 local function collapseitalics(tfmdata,key,value)
93 local threshold = value == true and 100 or tonumber(value)
94 if threshold and threshold > 0 then
95 if threshold > 100 then
96 threshold = 100
97 end
98 for unicode, data in next, tfmdata.characters do
99 if always or letter[unicode] or letter[data.unicode] then
100 local italic = data.italic
101 if italic and italic ~= 0 then
102 local width = data.width
103 if width and width ~= 0 then
104 local delta = threshold * italic / 100
105 data.width = width + delta
106 data.italic = italic - delta
107 end
108 end
109 end
110 end
111 end
112 end
113
114 local dimensions_specification = {
115 name = "collapseitalics",
116 description = "collapse italics",
117 manipulators = {
118 base = collapseitalics,
119 node = collapseitalics,
120 }
121 }
122
123 registerotffeature(dimensions_specification)
124 registerafmfeature(dimensions_specification)
125
126end
127 |