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
|
%D \module
%D [ file=meta-imp-glyphs,
%D version=2022.10.26, % moved from test files by MS and HH
%D title=\METAPOST\ Graphics,
%D subtitle=Glyph Shape Manipulations,
%D author=Hans Hagen,
%D date=\currentdate,
%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
\startMPdefinitions
def LoadGlyph(expr tag, filename, unicode) =
glyphshape_start(filename,unicode) ;
expandafter picture scantokens(tag & "char");
expandafter path scantokens(tag & "bbox") ;
expandafter numeric scantokens(tag & "accent") ;
expandafter numeric scantokens(tag & "italic") ;
scantokens(tag & "char") := image (draw for i=1 upto glyphshape_n : glyphshape_path(i) && endfor cycle ;) ;
scantokens(tag & "bbox") := glyphshape_usedbox ;
scantokens(tag & "accent") := glyphshape_accent ;
scantokens(tag & "italic") := xpart urcorner glyphshape_usedbox - glyphshape_italic ;
glyphshape_stop ;
enddef ;
def ScaleGlyph(expr tag, s) =
scantokens(tag & "char") := scantokens(tag & "char") scaled s ;
scantokens(tag & "bbox") := scantokens(tag & "bbox") scaled s ;
scantokens(tag & "accent") := s * scantokens(tag & "accent") ;
scantokens(tag & "italic") := s * scantokens(tag & "italic") ;
enddef ;
def ShiftGlyph(expr tag, dx, dy) =
scantokens(tag & "char") := scantokens(tag & "char") shifted (dx, dy) ;
scantokens(tag & "bbox") := scantokens(tag & "bbox") shifted (dx, dy) ;
scantokens(tag & "accent") := scantokens(tag & "accent") + dx ;
scantokens(tag & "italic") := scantokens(tag & "italic") + dx ;
enddef ;
def DrawGlyph(expr tag) =
draw scantokens(tag & "char") withpen pencircle scaled 1 ;
draw scantokens(tag & "bbox") withcolor "darkyellow" ;
draw (scantokens(tag & "accent"), (ypart urcorner scantokens(tag & "bbox"))) withcolor "darkmagenta" withpen pencircle scaled 5 ;
draw (scantokens(tag & "italic"), .5(ypart urcorner scantokens(tag & "bbox"))) withcolor "orange" withpen pencircle scaled 5 ;
enddef ;
\stopMPdefinitions
\startMPdefinitions
def ShowShape(expr font, slot) =
glyphshape_start(font, slot) ;
draw for i=1 upto glyphshape_n : glyphshape_path(i) && endfor cycle ;
draw glyphshape_boundingbox withcolor red ;
draw glyphshape_usedline withcolor green ;
draw glyphshape_usedbox withcolor blue ;
draw (glyphshape_accent,glyphshape_depth) withcolor "orange" withpen pencircle scaled 5 ;
draw (glyphshape_italic,glyphshape_depth) withcolor "orange" withpen pencircle scaled 5 ;
glyphshape_stop ;
enddef;
\stopMPdefinitions
|