%
%!PS
%% BeginResource: minidict.ps
%% Creator: byram@cappella.demon.co.uk
%% Version: Minidict 7.1 
%% For: Cappella Archive PostScript Markup
%% Date: 14.1.2007
%% EndComments

% Lines commented with a % must not linewrap

% This is the smaller Minidict version of the Tinydict without  
% the hyphenation dictionary for experimentation.
% Paste at the head of a text file and open with 'halfpage' or fullpage'.

% For the Cappella Archive PostScript Markup syntax see:
% http://www.cappella.demon.co.uk/tinyfiles/e-guide.pdf/

% The PostScript Markup and Dividing Dictionary patterns are
% Copyright: (C) 2004 David Byram-Wigfield. All Rights Reserved

% The PostScript word division procedures are
% Copyright (C) 2004 Olavi Sakari. All Rights Reserved

% The TeX or TinyDivi hyphenation patterns may be inserted 
% at the end of this dictionary. See:
% http://home.ricochet.com/osakari
% http://www.cappella.demon.co.uk/dividing/tinydivi.ps/

% The dimensions throughout are in points
% Only uncheck 'startjob' to download into Distiller, Ghostscript or
% PS printer memory. Do *not* uncheck if pasted at the head of a
% marked-up file: see the TinyGuide for printer instructions.
% true 0 startjob 

userdict begin

%%BeginProlog
% paper size default: a4: use 612 PW792 PH for letter
/PW { /pw exch def } def 597 PW 
/PH { /ph exch def } def 842 PH 
%%EndProlog

%%BeginSetup
% ISOLATORS 
/_Z { /defaults save def } def 
/ZZ { defaults restore } def 
% file closing command: 'grestore' closes last page 'gsave'
/cleanup { clear cleardictstack } def 
/close { showpage grestore cleanup ZZ } def 

% PAGE DEFAULTS:
% footer & inner margins: first page no.: columns
/FM { /fm exch def } def 72 FM
/IM { /im exch def } def 42 IM 
/PG { /pg exch def } def 1 PG
/NC {/nc exch def } def 2 NC

% TEXTBOX DEFAULTS: rm = textwidth
% top, bottom, left, right margins: inset and linespacing
/TM { /tm exch def } def 470 TM
/BM { /bm exch def } def 0 BM
/LM { /lm exch def } def 0 LM
/RM { /rm exch def } def 300 RM
/IN { /in exch def } def 0 IN 
/LG { /lg exch def } def 12 LG
/margins { 470 TM 300 RM 0 BM 0 LM 0 IN } def 

% PAGE FORMATS: see TinyGuide for multi page formats 
% Insert alternative fonts, style, and sizes in textbox and coltext

% Single pages for PDF viewing or re-imposition
/halfpage { _Z 420 PW 597 PH 300 RM 
<> setpagedevice
minidict begin 
/textbox { margins 12 LG 10 rom MT } def 
/coltext {10 rom 12 LG } def
/numbering { number folio } def p1 } def

% Single pages for letters or reports
/fullpage { _Z 597 PW 842 PH 480 RM 
<> setpagedevice
minidict begin 
/a4margins { margins 700 TM 480 RM } def
/textbox { a4margins 11 rom 13 LG MT } def 
/coltext { 11 rom 13 LG } def
/numbering { number folio } def p1 } def


% CLOSE THE USERDICT
end % this is IMPORTANT! % 
%%EndSetup

% THE MINIDICT
%% Open the smaller version of the TinyDict Dictionary
/minidict 100 dict def minidict begin

% SOME ABBREVIATIONS
/gs /gsave load def 
/gr /grestore load def
/s /show load def
/w /widthshow load def
/gray { gs setgray fill gr } bind def
/set { gs setlinewidth stroke gr } bind def 

% PAGE LAYOUT
/midpage { pw rm sub 2 div fm translate textbox numbering } bind def 

% PAGINATION: single pages
/p1 { gs midpage /jump { bm tm gt { showpage gr p1 } if } def } bind def 

% COLUMNS: "nocols" restores full textwidth: 
/colheight { ph fm 2 mul sub TM } def
/colwidth { rm nc div gutter sub RM } def
/gutter { lg 2 div } def
/nocols { tm end gr textbox TM H } def

/1st { gs colwidth coltext MT VS 
/coldict 10 dict def coldict begin 
 /jump { bm tm gt { 2 nc gt { nocols newpage 1st } 
{ 2nd } ifelse } if } def }  bind def 
/2nd { gr gs rm lg add 0 translate coltext vs TM MT 
 /jump { bm tm gt { nocols newpage 1st } if } def }  bind def 
 
% AUTO PAGE NUMBERING
/footerproc { cpp bm 20 neg add moveto s } def
/number { pg pg 1 add PG 4 string cvs } bind def
/numbering {number folio } def
/folio { gs pg pop 9 rom 50 string cvs centre footerproc gr } bind def

% HORIZONTAL MOVEMENT
/centre { dsp 2 div textwidth 2 div exch sub lm add tm moveto } bind def 
/emsize {lg 0.825 mul 0 rmoveto } def
/em { bm tm gt { jump emsize } { emsize } ifelse } def
/en { lg 0.42 mul 0 rmoveto } bind def
/right { dsp rm exch sub tm moveto } bind def 
/MT { 0.1 a } bind def

% VERTICAL MOVEMENT
% advance in points: e.g. 3 a
/a { tm exch sub TM lm tm moveto } bind def 
% reverse in points: e.g. 3 b
/b { tm add TM lm tm moveto } bind def 
% forwards half a line
/A { lg 2 div a } bind def 
% backwards half a line
/B { lg 2 div b } bind def 
% forwards one line 
/L { tm lg sub TM lm tm moveto } bind def 
% reverse one line 
/R { tm lg add TM lm tm moveto } bind def 
% vertical store
/VS { tm /vs exch def } def 
/newpage { 10 neg TM tm pop jump } bind def

% RULES: horizontal: use HR or specify width: eg. 1.5 rule
/HR { 0.2 rule } def
/rule { B gs lm tm moveto textwidth 3 sub 0 rlineto set gr L } bind def 

% DIGITAL ASSISTANTS
% where are we?
/cpp { currentpoint pop } def 
% how long is the chosen text?
/dsp { dup stringwidth pop } def 
% define a space
/space ( ) def 
% look for spaces
/ssp { space search pop } def 
% adjust space width for widthshow: e.g. 2 sw (text ) w
/sw { 0 32 } def 
 % textwidth usually equals 'rm' value 
/textwidth { rm lm sub } def
% count spaces % 
/dsc { dup spacecount } def 

% SPACECOUNTING AND LINEWRAPPING
/find { search { pop 3 -1 roll 1 add 3 1 roll } { pop exit } ifelse } bind def
/spacecount { 0 exch ( ) { find } loop } def
/rejoin { ssp exch glue } def
/toofar? { rejoin dsp cpp add rm gt } def
/pagejump { jump toofar? { L jump s } { s } ifelse }  bind def

% JUSTIFICATION PROCEDURES
/glue { 2 copy length exch length add string dup 4 2 roll 2 index 
0 3 index putinterval exch length exch putinterval } bind def
% TXT = text word store
/TXT { minidict /txt 3 -1 roll put } bind def () TXT 
/startpoint { rm currentpoint pop sub } bind def
/measure { dsp txt stringwidth pop add startpoint 2 add gt } bind def
/howlong? { rejoin measure } def
/join { txt exch glue TXT } bind def
/jproc { dsp startpoint exch sub exch dup spacecount } bind def
/popzero { dup 0 eq { pop }{ div } ifelse } def
/justify { jproc 1 sub 3 2 roll exch popzero sw 4 3 roll w L } bind def
/nextline { txt justify () TXT join } bind def

% PRINTING CODES: use 'S' or 'j' for inline font changes
/c { centre n } bind def 
/n { bm tm gt { jump s L } { s L } ifelse} bind def 
% ragged left: no line advance
/r { right n } bind def 
% ragged right: no line advance
/S { dsc { pagejump } repeat pop } bind def 
% ragged right: advance a line: no page jump
/p { dup spacecount { toofar? { L s } { s } ifelse } repeat pop L } bind def 
% rag paragraph right
/P {S L } def 

% tabs e.g. 100 T (text) s 150 T (last one) n 
/T { lm pop tm moveto } def 
% centre text and advance a line
/C { dsc { howlong? { jump txt c () TXT join }{ join } ifelse } repeat txt c () TXT pop } bind def

/hyphenson {/split {splitword } def } bind def
/hyphensoff {/split {} def } bind def
minidict /splitword known { hyphenson } { hyphensoff }   ifelse

% force justify
/fj { dsc { howlong? { split nextline }{ join } ifelse } repeat txt justify () TXT pop } bind def
% justify: no line advance: use to change font mid-line
/j { dsc { howlong? { split jump nextline }{ join } ifelse } repeat txt s () TXT pop } bind def
% justify and advance a line
/J { em dsc { howlong? { split jump nextline }{ join } ifelse } repeat txt n () TXT pop } bind def

% DEFAULT TYPEFACES: Adobe PostScript encoding
% For re-encoding: see the TinyGuide
% substitute fonts of choice using correct PS names
/F { exch selectfont } bind def 
% uncheck for level 1
%/F { findfont exch scalefont setfont } def
/rom { /Times-Roman F } def 
/bol { /Times-Bold F } def
/it { /Times-Italic F } def 
/bolit { /Times-BoldItalic F } def
/ss { /Helvetica F } def 
/sb { /Helvetica-Bold F } def
/si { /Helvetica-Oblique F } def 

% RESOURCES
% conversion from earlier versions
/H { A } def
/h { sw } def

%% INSERT HYPHENATION PROCS HERE
end % close the minidict
%%EndDictionary