diff options
author | Philipp Gesang <megas.kapaneus@gmail.com> | 2011-03-15 20:16:17 +0100 |
---|---|---|
committer | Philipp Gesang <megas.kapaneus@gmail.com> | 2011-03-15 20:16:17 +0100 |
commit | 4ad48ee19bbeeec83e637a27c7d770755a5fc22c (patch) | |
tree | 7cda46a658f03ca0e5c4f495e04a4b1607b7c74a | |
download | t-letterspace-4ad48ee19bbeeec83e637a27c7d770755a5fc22c.tar.gz |
initial
main commans sort of working but still extremely kludgey.
-rw-r--r-- | t-letterspace.mkiv | 130 |
1 files changed, 130 insertions, 0 deletions
diff --git a/t-letterspace.mkiv b/t-letterspace.mkiv new file mode 100644 index 0000000..1a9b862 --- /dev/null +++ b/t-letterspace.mkiv @@ -0,0 +1,130 @@ +%D \module [ +%D file=t-letterspace, +%D version=2011-03-15T12:59:48+0100 or later, +%D title=\CONTEXT\ User Module, +%D subtitle=Letterspacing commands, +%D author=Philipp Gesang, +%D date=\currentdate, +%D copyright=Philipp Gesang, +%D license=2-clause BSD, +%D ] + +\writestatus{loading}{ConTeXt User Module / Letterspace} + +\startmodule [letterspace] + +\startinterface all + \setinterfacevariable {letterspace} {letterspace} +\stopinterface + +\definenamespace [letterspace] [ + command=yes, + comment=Letterspacing module, + name=letterspace, + parent=letterspace, + setup=list, + style=no, + type=module, + version=hg, +] + +\unprotect + +%D \macros +%D {setupletterspace} +%D +%D Initial setup. +%D Setting the normal inline letterspacing factor +%D \type{textfactor} and a separate factor for capital spacing +%D \type{capfactor}. + +\setupletterspace [% + capfactor=.05, + capskip=.33em, + textfactor=.125, + textskip=.33em, + shortcommands=false, % “true” | “yes” | “yep” -- defaults to “false” +] + +%D Defining two letterspace settings. + +\definecharacterkerning [textspace] +\definecharacterkerning [capspace] + +\setupcharacterkerning [textspace] [factor=\letterspaceparameter{textfactor}] +\setupcharacterkerning [capspace] [factor=\letterspaceparameter{capfactor}] + +\unexpanded\def\letterspace_letterspace#1{% + \letterspace_do_letterspace{l}{#1}% +} + +\unexpanded\def\letterspace_capitalspace#1{% + \letterspace_do_letterspace{c}{#1}% +} + +\let \letterspace\letterspace_letterspace +\let\capitalspace\letterspace_capitalspace + +\def\letterspace_do_letterspace#1#2{% + \doif{#1}{l}{% + \let\currentletterspacecmd\letterspace_dodo_letterspace% + }% + \doif{#1}{c}{% + \let\currentletterspacecmd\letterspace_dodo_capitalspace% + }% + \ifhmode\ifnum\lastnodetype=\@@gluenode + \unskip{\currentletterspacecmd\ }% + \fi + \fi% + {\currentletterspacecmd#2}% + \doifnextspace{% + {\currentletterspacecmd\ }% + \gobblespacetokens% + }% +} + +\def\letterspace_dodo_letterspace{% + \dontleavehmode \setcharacterkerning[textspace]% + \advance \spaceskip \letterspaceparameter{textskip}% + \advance \xspaceskip \letterspaceparameter{textskip}% +}% + +\def\letterspace_dodo_capitalspace{% + \dontleavehmode \setcharacterkerning[capspace]% + \advance \spaceskip \letterspaceparameter{capskip}% + \advance \xspaceskip \letterspaceparameter{capskip}% +}% + +%D This is a partial ripoff of a couple of macros from +%D \type{syst-aux.mkiv}. +%D \useURL [flet] [http://www.tug.org/TUGboat/Articles/tb09-3/tb22bechtolsheim.pdf] [] [\type{futurelet}] +%D Very helpful for further understanding of what’s exactly going +%D on: Stephan von Bechtolsheim’s tutorial on \from[flet]. + +\def\doifnextspace#1{% + \def\!!string{#1}% + \futurelet\nexttoken\inspectnexttoken% +} + +\def\inspectnexttoken{% + \ifx\nexttoken\blankspace + \@EA\!!string + \fi% +} + +\def\letterspace_truestrings{true,yep,yes} + +\def\letterspace_define_shortcommands{% + \doifinset{\letterspaceparameter{shortcommands}}{\letterspace_truestrings}{% + \writestatus{letterspace}{enabling short commands}% + \global\let\CS\capitalspace% + \global\let\LS\letterspace% + }% +} + +\appendtoks \letterspace_define_shortcommands \to \everystarttext + +\protect \stopmodule \endinput + +% vim:ft=context:sw=2:ts=2 + |