summaryrefslogtreecommitdiff
path: root/tex/context/base/spec-xtx.tex
blob: ee71a60a2cf198301c1e626e47b9bb32863fbf98 (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
%D \module
%D   [       file=spec-xtx,
%D        version=2004.11.08,
%D          title=\CONTEXT\ Special Macros,
%D       subtitle=\XETEX\ support,
%D         author={Adam Lindsay \& Hans Hagen \& \unknown},
%D           date=\currentdate,
%D      copyright={Adam Lindsay \& Hans Hagen}]

\unprotect

\startspecials[xetex][reset,dpx]

%D Actually, there's an intermediate ``\type{xdv}''
%D output format, but by default, it's tranparently
%D converted to \PDF\ by \XETEX.

\setjobsuffix{pdf}

%D Rotation looks fine.

\definespecial\dostartrotation#1%
  {\special{x:gsave}\special{x:rotate #1}}

\definespecial\dostoprotation
  {\special{x:grestore}}

%D Scaling and mirroring are also fine.

\definespecial\dostartscaling#1#2%
  {\special{x:gsave}\special{x:scale #1 #2}}

\definespecial\dostopscaling
  {\special{x:grestore}}

\definespecial\dostartmirroring
  {\special{x:gsave}\special{x:scale -1 1}}

\definespecial\dostopmirroring
  {\special{x:grestore}}

%D Colors are done with the \DVIPDFMX\ color model, which are
%D inherited.

%D Although hex colors were accommodated by Hans, we'll try the
%D more familiar \DVIPDFMX\ ones. One good side-effect of the
%D previous approach was that it kept track of the color state
%D (transparency in XeTeX is accomplished setting the color to
%D an RGBA quadruple, rather than an RGB triple). So transparency
%D will need another plan.

% \macros
%   {dostarttransparency,dostoptransparency}
%
% \starttypen
% \dostarttransparency{fraction}{type}
% \dostoptransparency
% \stoptypen
%
% Although in \CONTEXT\ transparency is closely integrated
% in the color drivers, in the end it is an independent
% feature.

%\installspecial [\dostarttransparency] [or] [2]
%\installspecial [\dostoptransparency]  [or] [0]

%D \macros
%D   {doloadmapfile,doloadmapline,doresetmapfilelist}
%D
%D \XETEX\ 0.91 allows map file additions, via a special.

\definespecial\doresetmapfilelist{\special{x:fontmapfile original-empty.map}}
\definespecial\doloadmapfile #1#2{\special{x:fontmapfile #1#2}}
\definespecial\doloadmapline #1#2{\special{x:fontmapline #1#2}}

%D \XETEX\ supports \type{\doPDFdestination} and
%D \type{\doPDFbookmark} inherited straight from \DVIPDFMX.

\definespecial\doinsertfile#1#2#3#4#5#6#7#8#9%
  {\bgroup
   \dodoinsertfile{xtx}{#1}{#2}{#3}{#4}{#5}{#6}{#7}{#8}{#9}%
   \egroup}

\definefileinsertion{xtx}{jpg}{\xtxhandleotherimage}
\definefileinsertion{xtx}{png}{\xtxhandleotherimage}
\definefileinsertion{xtx}{gif}{\xtxhandleotherimage}
\definefileinsertion{xtx}{tif}{\xtxhandleotherimage}
\definefileinsertion{xtx}{pdf}{\xtxhandlepdfimage  }

\def\xtxhandleotherimage#1#2#3#4#5#6#7#8#9%
  {\bgroup % not needed, we load this under a normal catcode regime; \catcode`\"=11
   \XeTeXpicfile "#1" width #7 height #8\relax%
   \donetrue
   \egroup}

\def\xtxhandlepdfimage#1#2#3#4#5#6#7#8#9%
  {\bgroup % not needed, we load this under a normal catcode regime; \catcode`\"=11
   \checkpdfimagepagenumber{#9}
   \XeTeXpdffile "#1" \pdfimagepagenumber\space width #7 height #8  \relax%
   \donetrue
   \egroup}

\def\checkpdfimagepagenumber#1%
  {\let\pdfimagepagenumber\empty
   \getfromcommacommand[#1][1]%
   \doifnumberelse\commalistelement
     {\ifcase\commalistelement\else
        \edef\pdfimagepagenumber{page \commalistelement}%
        %\message{(pdf image \pdfimagepagenumber)}%
      \fi}
     {}}

% \type{\getfiguredimensionsA} calls this one.
% \type{\executedtrue} means it was able to get the desired
% dogetfiguresizeBLAH method for the image type.
% \type{\donetrue} means that the image was successfully
% measured to be more than zero points.

\def\dogetXTXfiguresize#1#2#3#4#5#6#7%
    {#4\zeropoint
     #5\zeropoint
     \setbox\foundexternalfigure\vbox{\XeTeXpicfile "#2"}%
     #6\wd\foundexternalfigure
     #7\ht\foundexternalfigure
     \ifdim\wd\foundexternalfigure=\zeropoint % \ifzeropt\wd\foundexternalfigure
       #1{#2}{#3}{#4}{#5}{#6}{#7}%
     \fi}

\def\dogetXTXpdfsize#1#2#3#4#5#6#7%
    {#4\zeropoint
     #5\zeropoint
     \checkpdfimagepagenumber{#3}
     \setbox\foundexternalfigure\vbox{\XeTeXpdffile "#2" \pdfimagepagenumber}% \relax not needed
     #6\wd\foundexternalfigure
     #7\ht\foundexternalfigure
     \ifdim\wd\foundexternalfigure=\zeropoint % \ifzeropt\wd\foundexternalfigure
       #1{#2}{#3}{#4}{#5}{#6}{#7}%
     \fi}

\let\normaldogetfiguresizepng=\dogetfiguresizepng
\let\normaldogetfiguresizetif=\dogetfiguresizetif
\let\normaldogetfiguresizejpg=\dogetfiguresizejpg
\let\normaldogetfiguresizegif=\dogetfiguresizegif
\let\normaldogetfiguresizepdf=\dogetfiguresizepdf

\def\dogetfiguresizepng{\dogetXTXfiguresize\normaldogetfiguresizepng}
\def\dogetfiguresizejpg{\dogetXTXfiguresize\normaldogetfiguresizejpg}
\def\dogetfiguresizegif{\dogetXTXfiguresize\normaldogetfiguresizegif}
\def\dogetfiguresizetif{\dogetXTXfiguresize\normaldogetfiguresizetif}
\def\dogetfiguresizepdf{\dogetXTXpdfsize\normaldogetfiguresizepdf}

\appendtoksonce
  \let\dogetfiguresizepng\normaldogetfiguresizepng
  \let\dogetfiguresizetif\normaldogetfiguresizetif
  \let\dogetfiguresizejpg\normaldogetfiguresizejpg
  \let\dogetfiguresizegif\normaldogetfiguresizegif
  \let\dogetfiguresizepdf\normaldogetfiguresizepdf
\to \everyresetspecials

%D The figure object system caused no end of headaches. They all
%D went away with this single line:

\setupexternalfigures[\c!object=\v!no]

\stopspecials

\protect \endinput