| 1 |
%% simple metapost slide show |
| 2 |
%% |
| 3 |
%% Copyright 2001, Patrick TJ McPhee |
| 4 |
%% everyone is welcome to use this code for any purpose, to modify it, and |
| 5 |
%% to copy it in whole or in part for use in other macro sets, with the |
| 6 |
%% conditions that this copyright notice be preserved with any significant |
| 7 |
%% portion of the code, and that modifications to this file be clearly |
| 8 |
%% marked. |
| 9 |
%% |
| 10 |
%% see the file slideshow.txt for documentation |
| 11 |
%% $Header: /usr/home/ptjm/texmf/metapost/RCS/slideshow.mp 1.8 2001/08/06 18:48:17 pmcphee Exp $ |
| 12 |
|
| 13 |
newinternal slideshowversion; |
| 14 |
slideshowversion := 1.0; |
| 15 |
|
| 16 |
%% |
| 17 |
%% basic figure handling |
| 18 |
%% |
| 19 |
|
| 20 |
picture lastpicture, background; |
| 21 |
|
| 22 |
% set the aspect ratio of the picture to match a 640x480 screen |
| 23 |
if not known lawidth: |
| 24 |
lawidth := 6.4in; |
| 25 |
laheight := 4.8in; |
| 26 |
fi; |
| 27 |
|
| 28 |
% make a sophisticated gradient background -- note that this can be done |
| 29 |
% natively in pdf 1.3 if you know how.... |
| 30 |
def drawgradient(expr topcolour, botcolour) := |
| 31 |
save pw,l,r,t,b,shade,grad; |
| 32 |
|
| 33 |
numeric l,r,t,b,pw; |
| 34 |
color shade, grad; |
| 35 |
|
| 36 |
% we will draw 100 coloured stripes across the screen |
| 37 |
pw = laheight/100; |
| 38 |
pickup pensquare scaled pw; |
| 39 |
lft l = 0 = bot b; |
| 40 |
rt r = lawidth; |
| 41 |
t = laheight; % don't say `top t' because I want to over-extend |
| 42 |
|
| 43 |
% shade is the colour of the current stripe, while grad |
| 44 |
% is the amount to change on each stripe |
| 45 |
shade := botcolour; |
| 46 |
grad := (1/100)*(topcolour - botcolour); |
| 47 |
|
| 48 |
for ypos := b step pw until t: |
| 49 |
draw (l, ypos)--(r, ypos) withcolor shade; |
| 50 |
shade := shade + grad; |
| 51 |
endfor; |
| 52 |
enddef; |
| 53 |
|
| 54 |
% draw the background -- we'll make it blue, just like power point |
| 55 |
background := image(drawgradient((0,0,.3), (0,0,.5));); |
| 56 |
|
| 57 |
% `keep track' of figure numbers |
| 58 |
def nextfig := beginfig(charcode+1) enddef; |
| 59 |
|
| 60 |
% always save the current picture at the end of each figure, |
| 61 |
% so it can be used in the next one |
| 62 |
extra_endfig := extra_endfig & "lastpicture := currentpicture; currentpicture := background; if known lastpicture: draw lastpicture; fi;"; |
| 63 |
|
| 64 |
% continue overlays the current picture with the last picture shipped out |
| 65 |
% this allows slides to be built up |
| 66 |
newinternal continuations; |
| 67 |
continuations := 0; |
| 68 |
def docontinue = if known lastpicture and (continuations = 1): currentpicture := lastpicture; bpos := bpos.prev; else: bpos := 0; fi; enddef; |
| 69 |
extra_beginfig := extra_beginfig & "docontinue;"; |
| 70 |
|
| 71 |
% one might want to do that by default |
| 72 |
def continue = continuations := 1; enddef; |
| 73 |
% or not |
| 74 |
def endcontinue = continuations := 0; enddef; |
| 75 |
|
| 76 |
% break in continuation |
| 77 |
def discontinue = clearit; lastpicture := nullpicture; bpos := 0; bpos.prev := 0; enddef; |
| 78 |
|
| 79 |
|
| 80 |
%% |
| 81 |
%% drawing assists |
| 82 |
%% |
| 83 |
|
| 84 |
|
| 85 |
% we'll use two pens to draw figures |
| 86 |
pickup pencircle xscaled 5 pt yscaled 4 pt rotated 20; |
| 87 |
thick nib := savepen; |
| 88 |
|
| 89 |
pickup pencircle xscaled 2 pt yscaled 1 pt rotated 20; |
| 90 |
thin nib := savepen; |
| 91 |
|
| 92 |
%% |
| 93 |
%% text manipulation assists |
| 94 |
%% |
| 95 |
|
| 96 |
|
| 97 |
% and we'll make the text yellow, just like power-point |
| 98 |
color textcolour; |
| 99 |
textcolour := red+green; |
| 100 |
defaultfont := "phvr8r"; |
| 101 |
|
| 102 |
|
| 103 |
% this is the thing we use as a bullet |
| 104 |
picture bulletpic; |
| 105 |
bulletpic := image(draw char(226) infont "pzdr" withcolor textcolour;); |
| 106 |
|
| 107 |
pair headerpos, footerpos, boff, borigin, borigin.in, blimit; |
| 108 |
numeric baselineskip, parskip, parskip.in, bpos; |
| 109 |
|
| 110 |
% positions of the bottom left corner of the header, and the bottom right |
| 111 |
% corner of the footer |
| 112 |
headerpos = (1in, 4in); |
| 113 |
footerpos = (6in, .2in); |
| 114 |
|
| 115 |
% offset of text from the bullet |
| 116 |
boff = (20bp, 0); |
| 117 |
|
| 118 |
% upper-left start position for bulletted text |
| 119 |
borigin = (1.5in,3.4in); |
| 120 |
|
| 121 |
% upper-left start position for indented bulletted text |
| 122 |
borigin.in = borigin + boff; |
| 123 |
|
| 124 |
% lower-right limit of bulletted text |
| 125 |
blimit = (4.4in,1in); |
| 126 |
|
| 127 |
% distance between baselines in bulletted text |
| 128 |
baselineskip = 11bp; |
| 129 |
|
| 130 |
% distance between bullet points for normal bullets |
| 131 |
parskip = 5 pt; |
| 132 |
|
| 133 |
% distance between bullet points for indented bullets |
| 134 |
parskip.in = 1pt; |
| 135 |
|
| 136 |
% current bullet position |
| 137 |
bpos = 0; |
| 138 |
|
| 139 |
% internal use - bullet position at the end of the last slide |
| 140 |
bpos.prev = 0; |
| 141 |
|
| 142 |
vardef breaktowidth(expr s, w)(text sheight) = |
| 143 |
save p; |
| 144 |
picture p; |
| 145 |
|
| 146 |
p := s infont defaultfont scaled defaultscale; |
| 147 |
% if the string is too long to fit within bounds, we break it up on |
| 148 |
% word boundaries. |
| 149 |
if xpart(lrcorner p - llcorner p) > w: |
| 150 |
save q, offs, len, goodlen; picture q; numeric offs, len, goodlen; |
| 151 |
picture q; |
| 152 |
p := nullpicture; |
| 153 |
offs := 0; |
| 154 |
len := 1; |
| 155 |
goodlen := 0; |
| 156 |
forever: |
| 157 |
exitunless len < length(s); |
| 158 |
q := (substring(offs, len) of s) infont defaultfont scaled defaultscale; |
| 159 |
if xpart (lrcorner q - llcorner q) > w: |
| 160 |
sheight := sheight + baselineskip; |
| 161 |
p := image(draw p shifted (0, baselineskip); |
| 162 |
draw (substring(offs, goodlen) of s) infont defaultfont |
| 163 |
scaled defaultscale;); |
| 164 |
offs := goodlen + 1; |
| 165 |
len := offs + 1; |
| 166 |
fi; |
| 167 |
if substring(len, len+1) of s = " ": goodlen := len; fi; |
| 168 |
len := len + 1; |
| 169 |
endfor; |
| 170 |
|
| 171 |
p := image(draw p shifted (0, baselineskip); |
| 172 |
draw (substring(offs, length s) of s) infont defaultfont |
| 173 |
scaled defaultscale;); |
| 174 |
fi; |
| 175 |
p |
| 176 |
enddef; |
| 177 |
|
| 178 |
% bullet(text) or bullet(picture) writes bulletpic and text or picture |
| 179 |
% in the next bullet position on the screen |
| 180 |
% bullet.in(text) does the same thing, but indented. This can be |
| 181 |
% extended for arbitrary suffix tag by defining a pair called borigin.tag, |
| 182 |
% and a numeric called parskip.tag. Note that bpos is shared, so this really |
| 183 |
% only works for additional levels of indentation |
| 184 |
vardef bullet@#(expr s) = |
| 185 |
save p, sheight; |
| 186 |
numeric sheight; |
| 187 |
picture p; |
| 188 |
|
| 189 |
% add the parskip for this bullet type, unless we're at the top |
| 190 |
if bpos > 0: bpos := bpos + parskip@#; fi |
| 191 |
|
| 192 |
if picture s: |
| 193 |
p := s; |
| 194 |
sheight := ypart(ulcorner p - llcorner p) - baselineskip; |
| 195 |
else: |
| 196 |
sheight := 0; |
| 197 |
p := image(draw breaktowidth(s, xpart(blimit - borigin@#))(sheight) |
| 198 |
withcolor textcolour;); |
| 199 |
fi; |
| 200 |
|
| 201 |
% start a new slide if this bullet won't fit. If we're in continuation mode, |
| 202 |
% the previous slide already has the previous bullets, so just clear this |
| 203 |
% slide and put the bullet at the top. In discontinous mode, we need to end |
| 204 |
% the figure, but this causes some problems as it ends the group started by |
| 205 |
% vardef, so we lose p and sheight (which were saved). |
| 206 |
if ypart borigin@# - sheight - bpos < ypart blimit: |
| 207 |
if continuations = 1: discontinue; |
| 208 |
else: |
| 209 |
begingroup; |
| 210 |
endfig; |
| 211 |
bpos.prev := 0; |
| 212 |
nextfig; |
| 213 |
endgroup; |
| 214 |
fi; |
| 215 |
fi; |
| 216 |
draw bulletpic shifted (borigin@# - (0, bpos)); |
| 217 |
draw p shifted (borigin@# + boff - (0, bpos+sheight)); |
| 218 |
bpos := bpos + sheight + baselineskip; |
| 219 |
bpos.prev := bpos; |
| 220 |
enddef; |
| 221 |
|
| 222 |
% handy abbreviation for a common paradigm |
| 223 |
vardef bpoint@#(expr s) = nextfig; bullet@#(s); endfig; enddef; |
| 224 |
|
| 225 |
% the same as the plain metapost label, but using textcolour |
| 226 |
vardef blabel@#(expr s,z) = draw thelabel@#(s,z) withcolor textcolour; enddef; |
| 227 |
|
| 228 |
vardef dotblabel@#(expr s,z) = |
| 229 |
blabel@#(s,z); |
| 230 |
interim linecap:=rounded; |
| 231 |
draw z withpen pencircle scaled dotlabeldiam withcolor textcolour; |
| 232 |
enddef; |
| 233 |
|
| 234 |
% a label which is also a hyperlink |
| 235 |
def dolink(expr p, n) = |
| 236 |
special "[ /Rect [ " & decimal xpart llcorner p & " " & |
| 237 |
decimal ypart llcorner p & " " & |
| 238 |
decimal xpart urcorner p & " " & |
| 239 |
decimal ypart urcorner p & " ] /Dest /" & n & |
| 240 |
" /Border [ 0 0 0 ] /Subtype /Link /ANN pdfmark"; |
| 241 |
enddef; |
| 242 |
|
| 243 |
vardef hyperlabel@#(expr s,z, n) = |
| 244 |
save p; |
| 245 |
picture p; |
| 246 |
p := thelabel@#(s,z); |
| 247 |
dolink(p, n); |
| 248 |
draw p withcolor textcolour; |
| 249 |
enddef; |
| 250 |
|
| 251 |
vardef hyperbullet@#(expr s, n) = |
| 252 |
save p; |
| 253 |
picture p; |
| 254 |
p := image(bullet@#(s);); |
| 255 |
dolink(p, n); |
| 256 |
draw p; |
| 257 |
enddef; |
| 258 |
|
| 259 |
def hyperdest(expr n) = special "[ /Dest /" & n & " /View [ /Fit ] /DEST pdfmark"; enddef; |
| 260 |
|
| 261 |
|
| 262 |
picture headerpic, footerpic; |
| 263 |
|
| 264 |
% header saves a string or picture which will be displayed at headerpos |
| 265 |
% on each slide. The header is added after the slide is saved to lastpicture |
| 266 |
def header(expr s) = |
| 267 |
if picture s: headerpic := s; |
| 268 |
else: headerpic := image( |
| 269 |
draw s infont defaultfont scaled (defaultscale*magstep1) |
| 270 |
shifted headerpos |
| 271 |
withcolor textcolour;); |
| 272 |
fi; |
| 273 |
enddef; |
| 274 |
|
| 275 |
def drawheader = if known headerpic: draw headerpic; fi; enddef; |
| 276 |
|
| 277 |
% header saves a string or picture which will be displayed to the left of |
| 278 |
% footerpos on each slide. The footer is added after the slide is saved |
| 279 |
% to lastpicture |
| 280 |
def footer(expr s) = |
| 281 |
if picture s: footerpic := s; |
| 282 |
else: footerpic := s infont defaultfont scaled defaultscale; |
| 283 |
footerpic := image( |
| 284 |
draw footerpic |
| 285 |
shifted (footerpos - (lrcorner footerpic - llcorner footerpic)) |
| 286 |
withcolor textcolour;); |
| 287 |
fi; |
| 288 |
enddef; |
| 289 |
|
| 290 |
def drawfooter = if known footerpic: draw footerpic; fi; enddef; |
| 291 |
extra_endfig := extra_endfig & "drawheader; drawfooter;"; |
| 292 |
|
| 293 |
% current slide number |
| 294 |
def folio = decimal charcode enddef; |
| 295 |
|
| 296 |
%% |
| 297 |
%% font encoding -- currently, only to 8r (I just couldn't bear putting this in |
| 298 |
%% a source file) |
| 299 |
%% |
| 300 |
def encodefont(expr tfm, fn) = |
| 301 |
special "/" & tfm & " /" & fn & "8r def"; |
| 302 |
special "/" & fn & " findfont dup length dict copy dup /Encoding"; |
| 303 |
special "[ /.notdef /dotaccent /fi /fl /fraction /hungarumlaut /Lslash /lslash"; |
| 304 |
special "/ogonek /ring /.notdef /breve /minus /.notdef /Zcaron /zcaron /caron /dotlessi"; |
| 305 |
special "/dotlessj /ff /ffi /ffl /.notdef /.notdef /.notdef /.notdef"; |
| 306 |
special "/.notdef /.notdef /.notdef /.notdef /grave /quotesingle /space /exclam /quotedbl /numbersign"; |
| 307 |
special "/dollar /percent /ampersand /quoteright /parenleft /parenright /asterisk /plus /comma /hyphen /period /slash"; |
| 308 |
special "/zero /one /two /three /four /five /six /seven /eight /nine /colon /semicolon /less /equal /greater /question"; |
| 309 |
special "/at /A /B /C /D /E /F /G /H /I /J /K /L /M /N /O /P /Q /R /S /T /U /V /W /X /Y /Z"; |
| 310 |
special "/bracketleft /backslash /bracketright /asciicircum /underscore /quoteleft"; |
| 311 |
special "/a /b /c /d /e /f /g /h /i /j /k /l /m /n /o /p /q /r /s /t /u /v /w /x /y /z"; |
| 312 |
special "/braceleft /bar /braceright /asciitilde /.notdef /.notdef /.notdef /quotesinglbase /florin"; |
| 313 |
special "/quotedblbase /ellipsis /dagger /daggerdbl /circumflex /perthousand /Scaron /guilsinglleft"; |
| 314 |
special "/OE /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /quotedblleft /quotedblright /bullet /endash /emdash"; |
| 315 |
special "/tilde /trademark /scaron /guilsinglright /oe /.notdef /.notdef /Ydieresis /.notdef"; |
| 316 |
special "/exclamdown /cent /sterling /currency /yen /brokenbar /section /dieresis /copyright /ordfeminine /guillemotleft"; |
| 317 |
special "/logicalnot /hyphen /registered /macron /degree /plusminus /twosuperior /threesuperior"; |
| 318 |
special "/acute /mu /paragraph /periodcentered /cedilla /onesuperior /ordmasculine /guillemotright"; |
| 319 |
special "/onequarter /onehalf /threequarters /questiondown /Agrave /Aacute /Acircumflex /Atilde /Adieresis /Aring /AE /Ccedilla"; |
| 320 |
special "/Egrave /Eacute /Ecircumflex /Edieresis /Igrave /Iacute /Icircumflex /Idieresis"; |
| 321 |
special "/Eth /Ntilde /Ograve /Oacute /Ocircumflex /Otilde /Odieresis /multiply /Oslash /Ugrave /Uacute /Ucircumflex"; |
| 322 |
special "/Udieresis /Yacute /Thorn /germandbls /agrave /aacute /acircumflex /atilde /adieresis /aring /ae /ccedilla"; |
| 323 |
special "/egrave /eacute /ecircumflex /edieresis /igrave /iacute /icircumflex /idieresis"; |
| 324 |
special "/eth /ntilde /ograve /oacute /ocircumflex /otilde /odieresis /divide /oslash /ugrave /uacute /ucircumflex"; |
| 325 |
special "/udieresis /yacute /thorn /ydieresis ] put /" & fn & "8r exch definefont pop"; |
| 326 |
enddef; |
| 327 |
|
| 328 |
%% |
| 329 |
%% pdf macros and assists |
| 330 |
%% |
| 331 |
|
| 332 |
|
| 333 |
% maintain a ps file which loads all the slides in order |
| 334 |
% this is specific to gs |
| 335 |
string psfile; |
| 336 |
psfile := jobname & ".ps"; |
| 337 |
|
| 338 |
extra_endfig := extra_endfig & "write " & ditto & "(" & ditto & "& jobname &" |
| 339 |
& ditto & "." & ditto |
| 340 |
& "& folio &" & ditto & ") run" & ditto & " to psfile;"; |
| 341 |
|
| 342 |
% put the viewer into full screen mode by default, and define a document-default |
| 343 |
% page transition (I'm using the random transition with 1/2 second duration) |
| 344 |
% since there is no way to specify a document-default, the transition has to be |
| 345 |
% added to each page dictionary |
| 346 |
special "[ /PageMode /FullScreen /DOCVIEW pdfmark"; |
| 347 |
|
| 348 |
special "[ /_objdef {mytrans} /type /dict /OBJ pdfmark"; |
| 349 |
special "[ {mytrans} << /Type /Trans /D .5 /S /Random /Dm /H /M /O /Di 315 >> /PUT pdfmark "; |
| 350 |
|
| 351 |
extra_endfig := extra_endfig & "special " & ditto |
| 352 |
& "[ {ThisPage} << /Trans {mytrans} >> /PUT pdfmark" & ditto & ";"; |
| 353 |
|
| 354 |
special "[ /CropBox [ 0 0 " & decimal(lawidth) & " " & decimal(laheight) & " ] /PAGES pdfmark"; |
| 355 |
|
| 356 |
% allow the user to specify document info |
| 357 |
def author(expr s) := |
| 358 |
special "[ /Author (" & s & ") /DOCINFO pdfmark"; |
| 359 |
enddef; |
| 360 |
def title(expr s) := |
| 361 |
special "[ /Title (" & s & ") /DOCINFO pdfmark"; |
| 362 |
enddef; |
| 363 |
def subject(expr s) := |
| 364 |
special "[ /Subject (" & s & ") /DOCINFO pdfmark"; |
| 365 |
enddef; |
| 366 |
def keywords(expr s) := |
| 367 |
special "[ /Keywords (" & s & ") /DOCINFO pdfmark"; |
| 368 |
enddef; |
| 369 |
def copyright(expr s) := |
| 370 |
special "[ /Copyright (" & s & ") /DOCINFO pdfmark"; |
| 371 |
enddef; |
| 372 |
|
| 373 |
def moddate(expr s) := |
| 374 |
special "[ /ModificationDate (" & s & ") /DOCINFO pdfmark"; |
| 375 |
enddef; |
| 376 |
|
| 377 |
def createdate(expr s) := |
| 378 |
special "[ /CreationDate (" & s & ") /DOCINFO pdfmark"; |
| 379 |
enddef; |
| 380 |
|
| 381 |
% except for the document info we specify ourselves |
| 382 |
createdate("D:" & decimal year & decimal month & if day < 10: "0" fi & decimal(day) & decimal time); |
| 383 |
special "[ /Creator (Metapost " & base_name & " base, version " & base_version & ") /DOCINFO pdfmark"; |
| 384 |
|
| 385 |
% gs will need this |
| 386 |
prologues:=2; |
| 387 |
|