Post Scriptum language

// Example 20

Encoding = array( 256 );
for ( i=0 to 255 )
        Encoding[ i ] = '.notdef';

str="a"; Encoding[ str[0] ] = 'smallbullet';        
str="b"; Encoding[ str[0] ] = 'mediumbullet';
str="c"; Encoding[ str[0] ] = 'largebullet';
str="d"; Encoding[ str[0] ] = 'openbox';

procedure notdef_fun() 
{
}

procedure smallbullet_fun()
{
        newpath();
        arc( 200, 350, 150, 0, 360 );
        closepath();
        fill();
}

procedure mediumbullet_fun()
{
        newpath();
        arc( 200, 350, 200, 0, 360 );
        closepath();
        fill();
}

procedure largebullet_fun()
{
        newpath();
        arc( 200, 350, 250, 0, 360 );
        closepath();
        fill();
}

procedure openbox_fun()
{
        newpath();
        moveto( 90, 30 );
        lineto( 90, 670 );
        lineto( 730, 670 );
        lineto( 730, 30 );
        closepath();
        setlinewidth( 60 );
        stroke();
}

procedure BuildChar_fun( fontdict, char ) 
{
        charname = fontdict.Encoding[ char ];
        bbox = fontdict.BBox[ charname ];
        setcachedevice( fontdict.Metrics[charname], 0, bbox[0],
                        bbox[1], bbox[2], bbox[3] );

        fontdict.CharacterDefs[ charname ]();
}

definefont( 'BoxesAndBullets',
[       FontType   : 3,
        FontMatrix : [.001, 0, 0, .001, 0, 0],
        FontBBox   : [ 50, 0, 760, 700],
        Encoding   : Encoding,
        Metrics    : [ ('.notdef') : 0,
                       smallbullet: 400,
                       mediumbullet: 520,
                       largebullet: 640,
                       openbox: 820 ],
        BBox       : [ ('.notdef') : [ 0, 0, 0, 0 ],
                       smallbullet : [50, 200, 350, 500],
                       mediumbullet: [50, 150, 450, 550],
                       largebullet : [50, 100, 550, 600],
                       openbox     : [60,   0, 760, 700] ],
        CharacterDefs: [ ('.notdef') : notdef_fun,
                         smallbullet : smallbullet_fun,
                         mediumbullet : mediumbullet_fun,
                         largebullet : largebullet_fun,
                         openbox : openbox_fun ],
        BuildChar: BuildChar_fun,
        UniqueID: 1

] );

bbfont   = scalefont( findfont( 'BoxesAndBullets' ), 16 );
textfont = scalefont( findfont( 'Times-Roman' ), 16 );

glo = [ yline: 650 ];

procedure ss( s ) {
        moveto( 72, glo.yline );
        show( s );
        glo.yline -=16;
}
        
procedure showbullettext( bulletchar )
{
        setfont( bbfont );
        ss( bulletchar );
        setfont( textfont );
        show( "Every bullet has its billet. \261William III" );
        setfont( bbfont );
        ss( bulletchar );
        setfont( textfont );
        show( "The bullet that will kill me is not yet cast." );
        show( "\261Napoleon I" );
        setfont( bbfont );
        ss( bulletchar );
        setfont( textfont );
        show( "The ballot is stronger than the bullet." );
        show( "\261Abraham Lincoln" );
}

glo.yline = 650;
showbullettext( "a" );
glo.yline = 550;
showbullettext( "b" );
glo.yline = 450;
showbullettext( "c" );

glo.yline = 300;

setfont( textfont );
ss( "Hieroglyphics are the root of letters. All" );
ss( "characters were orignally signs and all" );
ss( "signs were once images. Human society," );
ss( "the world, man in his entirety is in the" );
ss( "alphabet." );
setfont( bbfont );
show( "d" );

showpage();