Paste: Sprint stuff

Author: Nah
Mode: postscript
Date: Mon, 25 Jun 2012 00:09:12
Plain Text |
%!PS-Adobe-3.0
%%Title:      Sprint User Manual
%%Creator:    Jonas Westerlund
%%Version:    0.1-lambda
%%EndComments

% This tells the PostScript interpreter where to look for files.
% IMPORTANT: Paths must end with a path separator.
<<
/GenericResourceDir (./Resource/)
% You might also want to add paths to fonts and other stuff.
>> setsystemparams

% Define all exported names as local ones, out of laziness.
/sprint /ProcSet findresource { def } forall

% This initializes stuff that must be stored in local VM.
% Slightly annoying, looking for a better solution.
sprint!

% Set some fonts.
% When you use `/h1 /corbelb.ttf 15 pfont', a procedure is generated,
% named `font:h1'. Calling this procedure sets the font face and size.
/h1   /corbelb.ttf 15 pfont
/h2   /corbelb.ttf 13 pfont
/p    /constan.ttf 11 pfont
/code /consola.ttf 11 pfont

% Define some custom headings, using the `font:h2' procedure generated above.
/h2 { font:h2 justify newline } bind def

% Set up a simple page. This is the default, single-box page.
[ << /width 26 /height 38 /left 7 /bottom 7 >> ] setlayout!

% This procedure switches to a more elaborate layout.
% It also draws a bunch of stuff and is quite long, please disregard.
% We use the event system to switch at the moment a new page is created.
/layout2 {
  [ << /width 16 /height 16 /left 03 /bottom 31 >> % Top left column.
    << /width 16 /height 16 /left 21 /bottom 31 >> % Top right column.
    << /width 16 /height 16 /left 03 /bottom 05 >> % Bottom left column.
    << /width 16 /height 16 /left 21 /bottom 05 >> % Bottom right column.
  ] setlayout!
  % Remove self after one run.
  /layout2 load /page:pre off
} bind def

% Draw some grids and stuff on layout example page.
/drawstuff {
  /drawstuff load /page off
  gsave

  % Grids under boxes.
  << /w 16 /h 16 /x 03 /y 31 >> gridshow
  << /w 16 /h 16 /x 21 /y 31 >> gridshow
  << /w 16 /h 16 /x 03 /y 05 >> gridshow
  << /w 16 /h 16 /x 21 /y 05 >> gridshow

  % Numbers above boxes.
  0.50 0.10 0 0 setcmykcolor font:h2
  { cvroman dup stringwidth pop 2 div neg 0 rmoveto show }
  165 720 moveto 1 1 index exec
  435 720 moveto 2 1 index exec
  165 330 moveto 3 1 index exec
  435 330 moveto 4 1 index exec pop % THX U SERVD GRATE

  -6 grid /y get 24.5 mul
  translate % BECOME WIDER THAN IMPOSSIBLE

  % Draw some big-ass CMYK lines because I can't design?
  15 setlinewidth

  0 1 3 {
    0 0 0 1 4 index 4
    exch roll setcmykcolor
    0 1 index 15 mul
    moveto 612 0 rlineto
    stroke pop
  } for

  grestore
} bind def

doc:

(Sprint, a PostScript Typesetting Library)
h1

(PostScript is probably best known as a device-independent page description language, or maybe for its use in computer font files, such as OpenType fonts. It's also a general purpose programming language; a deceptively simple one.)
p+
 
(It provides various drawing commands, facilitating creation of sophisticated graphics. However, it has no built-in typesetting tools. That's where Sprint comes in, by providing basic typesetting capabilities, including:)
p+

list:
  (Full justification, automatic line breaking, as well as page breaking.)
  item
  (Customizable grid layout, allowing any number of rows and columns.)
  item
  (Some formatting tools: unordered lists, numbered lists (either Hindu- Arabic or Roman numerals), tables and more.)
  item
  (An event system for running custom procedures when something inte- resting happens, like a page break.)
  item
.

br  % LOL BR WHERE'S HR

(Design Rationale and Roadmap)
h1

(Sprint trades the mostly automagic behavior of LaTeX for more control and a full-fledged programming language. However, I do want to get closer to the automation sweet spot. Some features that are under development:)
p+

list:
  (Automatic sectioning and numbering.)
  item
  (Direct input of text, by reading plain text from the current file, possibly with some embedded code.)
  item
  (Automatic generation of table of contents, likely as a separate step.)
  item
  (Tools that simplify typesetting mathematical formulae.)
  item
.

% In anticipation of a new page.
/layout2   load /page:pre on  % Change layout before creating next page.
/drawstuff load /page     on  % Draw grids and stuff when on the next page.

(Of course, you can use any PostScript code at any point, when you need something more. More more more more more more more more more more mor.)
p

(The Sprint Layout System)
h2

(Sprint comes with a basic layout system, where a page consists of one or more boxes. For a standard single-column layout, use a single, centered box. For a double-column layout, simply place two boxes side by side.)
p+

(This page uses a layout consisting of four boxes, with numbers and grids printed to help visualize what's going on. When this box gets full, the text continues in the next one.)
p+

(Urgh dunno what to type type type type. My justification looks like ass in these narrow columns, how to de-ass? Automatic hyphenation would probably help. More text so that it goes into the next box boxy boxy box, but then I shall have to resort to lorem ipsum.)
p+

(Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.)
p+

(Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.)
p

(In third box now? Another one to go? Oh well, you get the idea, it goes to the last one eventually. Test some crap.)
p+

% Nesting counting testing.
list: /arabic style
  (One up here.)
  item
  (Two is next.)
  item

  list:
    (Then one in here because nest.)
    item
    (Two too.)
    item
  .
  (Then back to three and order.)
  item
.


. % doc

New Annotation

Summary:
Author:
Mode:
Body: