%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