summaryrefslogtreecommitdiff
path: root/doc/context/sources/general/manuals/cld/cld-goodies.tex
blob: d5b4b5c9cfa00353d99ac318ce26523e7090e835 (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
% language=uk

\startcomponent cld-macros

% \usemodule[man-01]
% \setvariables[document][title=Font Goodies, author=Hans Hagen]
% \setups[titlepage]

\environment cld-environment

\startchapter[title=Font goodies]

\startsection[title=Introduction]

One of the interesting aspects of \TEX\ is that it provides control over fonts
and \LUATEX\ provides quite some. In \CONTEXT\ we support basic functionality,
like \OPENTYPE\ features, as well as some extra functionality. We also have a
mechanism for making virtual fonts which is mostly used for the transition from
\TYPEONE\ math fonts to \OPENTYPE\ math fonts. Instead of hard coding specific
details in the core \LUA\ code, we use so called \LUA\ Font Goodies to control
them. These goodies are collected in tables and live in files. When a font is
loaded, one or more such goodie files can be loaded alongside.

In the following typescript we load a goodies file that defines a virtual Lucida
math font. The goodie file is loaded immediately and some information in the
table is turned into a form that permits access later on: the virtual font id
\type {lucida-math} that is used as part of the font specification.

\starttyping
\starttypescript [math] [lucida]
    \loadfontgoodies[lucida-math]
    \definefontsynonym[MathRoman][lucidamath@lucida-math]
\stoptypescript
\stoptyping

Not all information is to be used directly. Some can be accessed when needed. In
the following case the file \type {dingbats.lfg} gets loaded (only once) when the
font is actually used. In that file, there is information that is used by the
\type {unicoding} feature.

\starttyping
\definefontfeature
  [dingbats]
  [mode=base,
   goodies=dingbats,
   unicoding=yes]

\definefont[dingbats][file:dingbats][features=dingbats]
\stoptyping

In the following sections some aspects of goodies are discussed. We don't go into
details of what these goodies are, but just stick to the \LUA\ side of the
specification.

\stopsection

\startsection[title=Virtual math fonts]

A virtual font is defined using the \type {virtuals} entry in the \type
{mathematics} subtable. As \TYPEONE\ fonts are used, an additional table \type
{mapfiles} is needed to specify the files that map filenames onto real files.

\startsmalltyping
return {
  name = "px-math",
  version = "1.00",
  comment = "Goodies that complement px math.",
  author = "Hans Hagen",
  copyright = "ConTeXt development team",
  mathematics = {
    mapfiles = {
        "mkiv-px.map",
    },
    virtuals = {
      ["px-math"] = {
        { name = "texgyrepagella-regular.otf", features = "virtualmath", main = true },
        { name = "rpxr.tfm", vector = "tex-mr" } ,
        { name = "rpxmi.tfm", vector = "tex-mi", skewchar=0x7F },
        { name = "rpxpplri.tfm", vector = "tex-it", skewchar=0x7F },
        { name = "pxsy.tfm", vector = "tex-sy", skewchar=0x30, parameters = true } ,
        { name = "pxex.tfm", vector = "tex-ex", extension = true } ,
        { name = "pxsya.tfm", vector = "tex-ma" },
        { name = "pxsyb.tfm", vector = "tex-mb" },
        { name = "texgyrepagella-bold.otf", vector = "tex-bf" } ,
        { name = "texgyrepagella-bolditalic.otf", vector = "tex-bi" } ,
        { name = "lmsans10-regular.otf", vector = "tex-ss", optional=true },
        { name = "lmmono10-regular.otf", vector = "tex-tt", optional=true },
      },
    }
  }
}
\stopsmalltyping

Here the \type {px-math} virtual font is defined. A series of fonts is loaded and
combined into one. The \type {vector} entry is used to tell the builder how to
map the glyphs onto \UNICODE. Additional vectors can be defined, for instance:

\starttyping
fonts.encodings.math["mine"] = {
    [0x1234] = 0x56,
}
\stoptyping

Eventually these specifications wil be replaced by real \OPENTYPE\ fonts, but
even then we will keep the virtual definitions around.

\startsection[title=Math alternates]

In addition to the official \type {ssty} feature for enforcing usage of script
and scriptscript glyphs, some stylistic alternates can be present.

\startsmalltyping
return {
  name = "xits-math",
  version = "1.00",
  comment = "Goodies that complement xits (by Khaled Hosny).",
  author = "Hans Hagen",
  copyright = "ConTeXt development team",
  mathematics = {
    alternates = {
      cal       = {
        feature = 'ss01',
        value   = 1,
        comment = "Mathematical Calligraphic Alphabet"
      },
      greekssup = {
        feature = 'ss02',
        value   = 1,
        comment = "Mathematical Greek Sans Serif Alphabet"
      },
      greekssit = {
        feature = 'ss03',
        value   = 1,
        comment = "Mathematical Italic Sans Serif Digits"
      },
      monobfnum = {
        feature = 'ss04',
        value   = 1,
        comment = "Mathematical Bold Monospace Digits"
      },
      mathbbbf  = {
        feature = 'ss05',
        value   = 1,
        comment = "Mathematical Bold Double-Struck Alphabet"
      },
      mathbbit  = {
        feature = 'ss06',
        value   = 1,
        comment = "Mathematical Italic Double-Struck Alphabet"
      },
      mathbbbi  = {
        feature = 'ss07',
        value   = 1,
        comment = "Mathematical Bold Italic Double-Struck Alphabet"
      },
      upint     = {
        feature = 'ss08',
        value   = 1,
        comment = "Upright Integrals"
      },
    }
  }
}
\stopsmalltyping

These can be activated (in math mode) with the \type {\mathalternate} command
like:

\starttyping
$\mathalternate{cal}Z$
\stoptyping

\stopsection

\startsection[title=Math parameters]

Another goodie related to math is the overload of some parameters (part of the
font itself) and variables (used in making virtual shapes).

\startsmalltyping
return {
  name = "lm-math",
  version = "1.00",
  comment = "Goodies that complement latin modern math.",
  author = "Hans Hagen",
  copyright = "ConTeXt development team",
  mathematics = {
    mapfiles = {
      "lm-math.map",
      "lm-rm.map",
      "mkiv-base.map",
    },
    virtuals = {
      ["lmroman5-math"]      = five,
      ["lmroman6-math"]      = six,
      ["lmroman7-math"]      = seven,
      ["lmroman8-math"]      = eight,
      ["lmroman9-math"]      = nine,
      ["lmroman10-math"]     = ten,
      ["lmroman10-boldmath"] = ten_bold,
      ["lmroman12-math"]     = twelve,
      ["lmroman17-math"]     = seventeen,
    },
    variables = {
      joinrelfactor = 3, -- default anyway
    },
    parameters = { -- test values
  --  FactorA = 123.456,
  --  FactorB = false,
  --  FactorC = function(value,target,original) return 7.89 * target.factor end,
  --  FactorD = "Hi There!",
    },
  }
}
\stopsmalltyping

In this example you see several virtuals defined which is due to the fact that
Latin Modern has design sizes. The values (like \type {twelve} are tables defined
before the return happens and are not shown here. The variables are rather
\CONTEXT\ specific, and the parameters are those that come with regular
\OPENTYPE\ math fonts (so the example names are invalid).

In the following example we show two wasy to change parameters. In this case we
have a regular \OPENTYPE\ math font. First we install a patch to the font itself.
That change will be cached. We could also have changed that parameter using the
goodies table. The first method is the oldest.

\startsmalltyping
local patches = fonts.handlers.otf.enhancers.patches

local function patch(data,filename,threshold)
  local m = data.metadata.math
  if m then
    local d = m.DisplayOperatorMinHeight or 0
    if d < threshold then
      patches.report("DisplayOperatorMinHeight(%s -> %s)",d,threshold)
      m.DisplayOperatorMinHeight = threshold
    end
  end
end

patches.register(
  "after",
  "check math parameters",
  "asana",
  function(data,filename)
    patch(data,filename,1350)
  end
)

local function less(value,target,original)
  return 0.25 * value
end

return {
  name = "asana-math",
  version = "1.00",
  comment = "Goodies that complement asana.",
  author = "Hans Hagen",
  copyright = "ConTeXt development team",
  mathematics = {
    parameters = {
      StackBottomDisplayStyleShiftDown = less,
      StackBottomShiftDown             = less,
      StackDisplayStyleGapMin          = less,
      StackGapMin                      = less,
      StackTopDisplayStyleShiftUp      = less,
      StackTopShiftUp                  = less,
      StretchStackBottomShiftDown      = less,
      StretchStackGapAboveMin          = less,
      StretchStackGapBelowMin          = less,
      StretchStackTopShiftUp           = less,
    }
  }
}
\stopsmalltyping

We use a function so that the scaling is taken into account as the values passed
are those resulting from the scaling of the font to the requested size.

\stopsection

\startsection[title=Unicoding]

We still have to deal with existing \TYPEONE\ fonts, and some of them have an
encoding that is hard to map onto \UNICODE\ without additional information. The
following goodie does that. The keys in the \type {unicodes} table are the glyph
names. Keep in mind that this only works with simple fonts. The \CONTEXT\ code
takes care of kerns but that's about it.

\startsmalltyping
return {
  name = "dingbats",
  version = "1.00",
  comment = "Goodies that complement dingbats (funny names).",
  author = "Hans Hagen",
  copyright = "ConTeXt development team",
  remapping = {
    tounicode = true,
    unicodes = {
      a1   = 0x2701,
      a10  = 0x2721,
      a100 = 0x275E,
      a101 = 0x2761,
      .............
      a98  = 0x275C,
      a99  = 0x275D,
    },
  },
}
\stopsmalltyping

The \type {tounicode} option makes sure that additional information ends ip in
the output so that cut|-|and|-|paste becomes more trustworthy.

\stopsection

\startsection[title=Typescripts]

Some font collections, like antykwa, come with so many variants that defining
them all in typescripts becomes somewhat of a nuisance. While a regular font has
a typescript of a few lines, antykwa needs way more lines. This is why we provide
a nother way as well, using goodies.

\startsmalltyping
return {
  name = "antykwapoltawskiego",
  version = "1.00",
  comment = "Goodies that complement Antykwa Poltawskiego",
  author = "Hans & Mojca",
  copyright = "ConTeXt development team",
  files = {
    name = "antykwapoltawskiego", -- shared
    list = {
      ["AntPoltLtCond-Regular.otf"] = {
     -- name   = "antykwapoltawskiego",
        weight = "light",
        style  = "regular",
        width  = "condensed",
      },
      ["AntPoltLtCond-Italic.otf"] = {
        weight = "light",
        style  = "italic",
        width  = "condensed",
      },
      ["AntPoltCond-Regular.otf"] = {
        weight = "normal",
        style  = "regular",
        width  = "condensed",
      },

      .......


      ["AntPoltExpd-BoldItalic.otf"] = {
        weight = "bold",
        style  = "italic",
        width  = "expanded",
      },
    },
  },
  typefaces = { -- for Mojca (experiment, names might change)
    ["antykwapoltawskiego-light"] = {
      shortcut     = "rm",
      shape        = "serif",
      fontname     = "antykwapoltawskiego",
      normalweight = "light",
      boldweight   = "medium",
      width        = "normal",
      size         = "default",
      features     = "default",
    },

    .......

  },
}
\stopsmalltyping

This is a typical example of when a goodies file is loaded directly:

\starttyping
\loadfontgoodies[antykwapoltawskiego]
\stoptyping

A bodyfont is now defined by choosing from the defined combinations:

\starttyping
\definetypeface
  [name=mojcasfavourite,
   preset=antykwapoltawskiego,
   normalweight=light,
   boldweight=bold,
   width=expanded]

\setupbodyfont
  [mojcasfavourite]
\stoptyping

This mechanism is a follow up on a discussion at a \CONTEXT\ conference, still
somewhat experimental, and a playground for Mojca.

\stopsection

\startsection[title=Font strategies]

This goodie is closely related to the Oriental \TEX\ project where a dedicated
paragraph optimizer can be used. A rather advanced font is used (husayni) and its
associated goodie file is rather extensive. It defines stylistic features,
implements a couple of feature sets, provides colorschemes and most of all,
defines some strategies for making paragraphs look better. Some of the goodie
file is shown here.

\startsmalltyping
local yes = "yes"

local basics = {
  analyze  = yes,
  mode     = "node",
  language = "dflt",
  script   = "arab",
}

local analysis = {
  ccmp = yes,
  init = yes, medi = yes, fina = yes,
}

local regular = {
  rlig = yes, calt = yes, salt = yes, anum = yes,
  ss01 = yes, ss03 = yes, ss07 = yes, ss10 = yes, ss12 = yes, ss15 = yes, ss16 = yes,
  ss19 = yes, ss24 = yes, ss25 = yes, ss26 = yes, ss27 = yes, ss31 = yes, ss34 = yes,
  ss35 = yes, ss36 = yes, ss37 = yes, ss38 = yes, ss41 = yes, ss42 = yes, ss43 = yes,
  js16 = yes,
}

local positioning = {
  kern = yes, curs = yes, mark = yes, mkmk = yes,
}

local minimal_stretching = {
  js11 = yes, js03 = yes,
}

local medium_stretching = {
  js12=yes, js05=yes,
}

local maximal_stretching= {
  js13 = yes, js05 = yes, js09 = yes,
}

local wide_all = {
  js11 = yes, js12 = yes, js13 = yes, js05 = yes, js09 = yes,
}

local shrink = {
  flts = yes, js17 = yes, ss05 = yes, ss11 = yes, ss06 = yes, ss09 = yes,
}

local default = {
  basics, analysis, regular, positioning, -- xxxx = yes, yyyy = 2,
}

return {
  name = "husayni",
  version = "1.00",
  comment = "Goodies that complement the Husayni font by Idris Samawi Hamid.",
  author = "Idris Samawi Hamid and Hans Hagen",
  featuresets = { -- here we don't have references to featuresets
    default = {
      default,
    },
    minimal_stretching = {
      default,
      js11 = yes, js03 = yes,
    },
    medium_stretching = {
      default,
      js12=yes, js05=yes,
    },
    maximal_stretching= {
      default,
      js13 = yes, js05 = yes, js09 = yes,
    },
    wide_all = {
      default,
      js11 = yes, js12 = yes, js13 = yes, js05 = yes, js09 = yes,
    },
    shrink = {
      default,
      flts = yes, js17 = yes, ss05 = yes, ss11 = yes, ss06 = yes, ss09 = yes,
    },
  },
  solutions = { -- here we have references to featuresets, so we use strings!
    experimental = {
      less = {
        "shrink"
      },
      more = {
        "minimal_stretching",
        "medium_stretching",
        "maximal_stretching",
        "wide_all"
      },
    },
  },
  stylistics = {
    ......
    ss03 = "level-1 stack over Jiim, initial entry only",
    ss04 = "level-1 stack over Jiim, initial/medial entry",
    ......
    ss54 = "chopped finals",
    ss55 = "idgham-tanwin",
    ......
    js11 = "level-1 stretching",
    js12 = "level-2 stretching",
    ......
    js21 = "Haa.final_alt2",
  },
  colorschemes = {
    default = {
      [1] = {
        "Onedotabove", "Onedotbelow", ...
      },
      [2] = {
        "Fathah", "Dammah", "Kasrah", ...
      },
      [3] = {
        "Ttaa.waqf", "SsLY.waqf", "QLY.waqf", ...
      },
      [4] = {
        "ZeroArabic.ayah", "OneArabic.ayah", "TwoArabic.ayah", ...
      },
      [5] = {
        "Ayah", "Ayah.alt1", "Ayah.alt2", ...
      }
    }
  }
}
\stopmalltyping

Discussion of these goodies is beyond this document and happens elsewhere.

\stopsection

\startsection[title=Composition]

The \type {compose} features extends a font with additional (virtual) shapes.
This is mostly used with \TYPEONE\ fonts that lack support for eastern european
languages. The type {compositions} subtable is used to control placement of
accents. This can be done per font.

\startmalltyping
local defaultunits = 193 - 30

-- local compose = {
--                DY = defaultunits,
--   [0x010C] = { DY = defaultunits }, -- Ccaron
--   [0x02C7] = { DY = defaultunits }, -- textcaron
-- }

-- fractions relative to delta(X_height - x_height)

local defaultfraction = 0.85

local compose = {
  DY = defaultfraction, -- uppercase compensation
}

return {
  name = "lucida-one",
  version = "1.00",
  comment = "Goodies that complement lucida.",
  author = "Hans and Mojca",
  copyright = "ConTeXt development team",
  compositions = {
    ["lbr"]  = compose,
    ["lbi"]  = compose,
    ["lbd"]  = compose,
    ["lbdi"] = compose,
  }
}
\stopsmalltyping

\stopsection

\startsection[title=Postprocessing]

You can hook postprocessors into the scaler. Future versions might provide more
control over where this happens.

\startsmalltyping
local function statistics(tfmdata)
    commands.showfontparameters(tfmdata)
end

local function squeeze(tfmdata)
  for k, v in next, tfmdata.characters do
    v.height = 0.75 * (v.height or 0)
    v.depth  = 0.75 * (v.depth  or 0)
  end
end

return {
  name = "demo",
  version = "1.00",
  comment = "An example of goodies.",
  author = "Hans Hagen",
  postprocessors = {
    statistics = statistics,
    squeeze    = squeeze,
  },
}
\stopsmalltyping

\stopsection

\stopchapter

\stopcomponent