summaryrefslogtreecommitdiff
path: root/tex/context/base/typo-spa.mkiv
blob: c877fdf67cea9b99298aec1827a3c409c5aa03ae (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
%D \module
%D   [       file=typo-spa,
%D        version=2009.03.27, % code moved from cors-spa.mkiv
%D          title=\CONTEXT\ Typesetting Macros,
%D       subtitle=Spacing,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright=\PRAGMA]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\writestatus{loading}{ConTeXt Typesetting Macros / Spacing}

\unprotect

\registerctxluafile{typo-spa}{1.001}

\definesystemattribute[spacing] \chardef\spacingattribute \dogetattributeid{spacing}

% experimental spacing
%
% test: oeps {\setcharacterspacing[frenchpunctuation]x: xx \bfd x: xx} oeps: test

\newcount \maxcharacterspacingid

\unexpanded\def\definecharacterspacing[#1]%
  {\ifcsname\??ch#1\endcsname \else
     \global\advance\maxcharacterspacingid\plusone
     \setxvalue{\??ch:#1}{\the\maxcharacterspacingid}%
   \fi}

\unexpanded\def\setupcharacterspacing
  {\dotripleargument\dosetupcharacterspacing}

\def\dosetupcharacterspacing[#1][#2][#3]%
  {\ifcsname\??ch:#1\endcsname
     \begingroup % for the moment we use modes, in ordere to avoid interface translation
     \getparameters[\??ch][\c!left=0,\c!right=0,\c!alternative=0,#3]%
     \ctxlua{typesetting.spacings.setup(\getvalue{\??ch:#1},\number#2,\@@chleft,\@@chright,\@@chalternative)}%
     \endgroup
   \fi}

\unexpanded\def\setcharacterspacing[#1]%
  {\ctxlua{typesetting.spacings.set(\number\csname\??ch:#1\endcsname)}}

\unexpanded\def\resetcharacterspacing % fast one
  {\attribute\spacingattribute\attributeunsetvalue}

\letvalue{\??ch:\s!reset}\attributeunsetvalue

\appendtoks
    \resetcharacterspacing
\to \everyresettypesetting

% \setcharacterspacing[frenchpunctuation]
% «\type{bla}»\crlf « \type{bla}»\crlf
% «bla »\crlf « bla»\crlf « bla »\crlf
% bla: bla\crlf bla : bla

\definecharacterspacing [frenchpunctuation] % name may change / unit is em

\setupcharacterspacing [frenchpunctuation] ["003A] [\c!left =.25,\c!alternative=1] % : % strip preceding space(char)
\setupcharacterspacing [frenchpunctuation] ["003B] [\c!left =.25,\c!alternative=1] % ; % strip preceding space(char)
\setupcharacterspacing [frenchpunctuation] ["003F] [\c!left =.25,\c!alternative=1] % ? % strip preceding space(char)
\setupcharacterspacing [frenchpunctuation] ["0021] [\c!left =.25,\c!alternative=1] % ! % strip preceding space(char)
\setupcharacterspacing [frenchpunctuation] ["00AB] [\c!right=.25,\c!alternative=1] % guillemotleft/leftguillemot   % strip following space(char)
\setupcharacterspacing [frenchpunctuation] ["00BB] [\c!left =.25,\c!alternative=1] % guillemotright/rightguillemot % strip preceding space(char)

\protect \endinput