home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1608 / pcalinit.h < prev    next >
Text File  |  1990-12-28  |  6KB  |  240 lines

  1. /*
  2.  * pcalinit.h - provides the PostScript routines for pcal.c
  3.  */
  4.  
  5. /* modified by AWR to skip printing days of week on small calendars */
  6.  
  7. char *header_1[] = {
  8.   "/month_names [ (January) (February) (March) (April) (May) (June) (July)",
  9.   "\t\t(August) (September) (October) (November) (December) ] def",
  10.   "/prtnum { 3 string cvs show} def",
  11.   "/drawgrid {\t\t% draw calendar boxes",
  12.   "\tdayfont findfont 10 scalefont setfont",
  13.   "\t0 1 6 {",
  14.   "\t\t/i exch def",
  15.   "\t\tsubmonth 0 eq {",
  16.   "\t\t\ti 100 mul 40 moveto",
  17.   "\t\t\t[ (Sunday) (Monday) (Tuesday) (Wednesday) (Thursday) (Friday) (Saturday) ] i get",
  18.   "\t\t\t100 center",
  19.   "\t\t} if",
  20.   "\t\ti 100 mul 35 moveto",
  21.   "\t\t1.0 setlinewidth",
  22.   "\t\t0 1 5 {",
  23.   "\t\t\tgsave",
  24.   "\t\t\t100 0 rlineto ",
  25.   "\t\t\t0 -80 rlineto",
  26.   "\t\t\t-100 0 rlineto",
  27.   "\t\t\tclosepath stroke",
  28.   "\t\t\tgrestore",
  29.   "\t\t\t0 -80 rmoveto",
  30.   "\t\t pop } for",
  31.   "\t} for",
  32.   "} def",
  33.   "/drawnums {\t\t% place day numbers on calendar",
  34.   "\tdayfont findfont 30 scalefont setfont",
  35.   "\t/start startday def",
  36.   "\t/days ndays def",
  37.   "\t/n 0 def",
  38.   "\tstart 100 mul 5 add 10 rmoveto",
  39.   "\t1 1 days {",
  40.   "\t\t/day exch def",
  41.   "\t\tgsave",
  42.   "\t\tsubmonth 0 eq {",
  43.   (char *)0
  44.   };
  45.  
  46. /* modified by AWR to calculate leap years correctly, print holidays in gray,
  47.    and to center month and year together */
  48.  
  49. char *header_2[] = {
  50.   "\t\t\tday holidays n get eq {",
  51.   "\t\t\t\t.8 setgray",
  52.   "\t\t\t\t/n n 1 add def",
  53.   "\t\t\t} if",
  54.   "\t\t} if",
  55.   "\t\tday prtnum",
  56.   "\t\tgrestore",
  57.   "\t\tday start add 7 mod 0 eq",
  58.   "\t\t{",
  59.   "\t\t\tcurrentpoint exch pop 80 sub 5 exch moveto",
  60.   "\t\t}",
  61.   "\t\t{",
  62.   "\t\t\t100 0 rmoveto",
  63.   "\t\t} ifelse",
  64.   "\t} for",
  65.   "} def",
  66.   "/drawfill {\t\t% place fill squares on calendar",
  67.   "\t/start startday def",
  68.   "\t/days ndays def",
  69.   "\t0 35 rmoveto",
  70.   "\t1.0 setlinewidth",
  71.   "\t0 1 start 1 sub {",
  72.   "\t\tgsave",
  73.   "\t\t.9 setgray",
  74.   "\t\t100 0 rlineto ",
  75.   "\t\t0 -80 rlineto",
  76.   "\t\t-100 0 rlineto",
  77.   "\t\tclosepath fill",
  78.   "\t\tgrestore",
  79.   "\t\t100 0 rmoveto",
  80.   "\tpop } for",
  81.   "\tsubmonth 1 eq",
  82.   "\t{",
  83.   "\t\t/lastday 42 def",
  84.   "\t\t600 -365 moveto",
  85.   "\t}",
  86.   "\t{",
  87.   "\t\t/lastday 40 def",
  88.   "\t\t400 -365 moveto",
  89.   "\t} ifelse",
  90.   "\tlastday -1 ndays start 1 add add",
  91.   "\t{",
  92.   "\t\t/day exch def",
  93.   "\t\tgsave",
  94.   "\t\t.9 setgray",
  95.   "\t\t100 0 rlineto ",
  96.   "\t\t0 -80 rlineto",
  97.   "\t\t-100 0 rlineto",
  98.   "\t\tclosepath fill",
  99.   "\t\tgrestore",
  100.   "\t\tday 7 mod 1 eq",
  101.   "\t\t{",
  102.   "\t\t\t600 -365 80 add moveto",
  103.   "\t\t}",
  104.   "\t\t{",
  105.   "\t\t\t-100 0 rmoveto",
  106.   "\t\t} ifelse",
  107.   "\t} for",
  108.   "} def",
  109.   "/isleap {\t\t% is this a leap year?",
  110.   "\tyear 4 mod 0 eq\t\t% multiple of 4",
  111.   "\tyear 100 mod 0 ne \t% not century",
  112.   "\tyear 400 mod 0 eq or and\t% or divisible by 400",
  113.   "} def",
  114.   "/days_month [ 31 28 31 30 31 30 31 31 30 31 30 31 ] def",
  115.   "/ndays {\t\t% number of days in this month",
  116.   "\tdays_month month 1 sub get",
  117.   "\tmonth 2 eq\t% Feb",
  118.   "\tisleap and",
  119.   "\t{",
  120.   "\t\t1 add",
  121.   "\t} if",
  122.   "} def",
  123.   "/startday {\t\t% starting day-of-week for this month",
  124.   "\t/off year 2000 sub def\t% offset from start of epoch",
  125.   "\toff",
  126.   "\toff 4 idiv add\t\t% number of leap years",
  127.   "\toff 100 idiv sub\t% number of centuries",
  128.   "\toff 400 idiv add\t% number of years divisible by 400",
  129.   "\t6 add 7 mod 7 add \t% offset from Jan 1 2000",
  130.   "\t/off exch def",
  131.   "\t1 1 month 1 sub {",
  132.   "\t\t/idx exch def",
  133.   "\t\tdays_month idx 1 sub get",
  134.   "\t\tidx 2 eq",
  135.   "\t\tisleap and",
  136.   "\t\t{",
  137.   "\t\t\t1 add",
  138.   "\t\t} if",
  139.   "\t\t/off exch off add def",
  140.   "\t} for",
  141.   "\toff 7 mod\t\t% 0--Sunday, 1--monday, etc.",
  142.   "} def",
  143.   "/center {\t\t% center string in given width",
  144.   "\t/width exch def",
  145.   "\t/str exch def width str ",
  146.   "\tstringwidth pop sub 2 div 0 rmoveto str show",
  147.   "} def",
  148.   "/strcat {\t\t% concatenate two strings",
  149.   "\t2 copy",
  150.   "\tlength exch length",
  151.   "\tdup 3 -1 roll add",
  152.   "\tstring",
  153.   "\tdup 0 6 -1 roll putinterval",
  154.   "\tdup 3 -1 roll 4 -1 roll putinterval",
  155.   "} def",
  156.   "/calendar",
  157.   "{",
  158.   "\ttitlefont findfont 48 scalefont setfont",
  159.   "\t/month_name month_names month 1 sub get def",
  160.   "\t/yearstring year 10 string cvs def",
  161.   "\t0 60 moveto",
  162.   "\tmonth_name (  ) strcat yearstring strcat 700 center",
  163.   "\t0 0 moveto",
  164.   "\tdrawnums",
  165.   "\t0 0 moveto",
  166.   "\tdrawfill",
  167.   "\t0 0 moveto",
  168.   "\tdrawgrid",
  169.   "} def",
  170.   "/daytext {",
  171.   "\t/Helvetica-Narrow findfont 6 scalefont setfont",
  172.   "\t/mytext\texch def /myday exch def",
  173.   "\tstartday myday 1 sub add dup 7 mod 100 mul 5 add % gives column",
  174.   "\texch 7 idiv -80 mul % gives row",
  175.   "\tdup /ypos exch def moveto",
  176.   "\t/LM currentpoint pop def /RM LM 95 add def",
  177.   "        mytext { dup (.p) eq { crlf pop} {prstr ( ) show} ifelse } forall",
  178.   "} def",
  179.   "/crlf {",
  180.   "    ypos 8 sub /ypos exch def LM ypos moveto",
  181.   "} def",
  182.   "/prstr {",
  183.   "    dup stringwidth pop currentpoint pop",
  184.   "    add RM gt {crlf} if show",
  185.   "} def",
  186.   "/printmonth {",
  187.    (char *)0,
  188.  };
  189.  
  190.  char *header_3[] = {
  191.   "\t/submonth 0 def",
  192.   "\tcalendar",
  193.   "\tmonth 1 sub 0 eq",
  194.   "\t{",
  195.   "\t\t/lmonth 12 def",
  196.   "\t\t/lyear year 1 sub def",
  197.   "\t}",
  198.   "\t{",
  199.   "\t\t/lmonth month 1 sub def",
  200.   "\t\t/lyear year def",
  201.   "\t} ifelse",
  202.   "\tmonth 1 add 13 eq",
  203.   "\t{",
  204.   "\t\t/nmonth 1 def",
  205.   "\t\t/nyear year 1 add def",
  206.   "\t} ",
  207.   "\t{",
  208.   "\t\t/nmonth month 1 add def",
  209.   "\t\t/nyear year def",
  210.   "\t} ifelse",
  211.   "\t/savemonth month def",
  212.   "\t/saveyear year def",
  213.   "\t/submonth 1 def",
  214.   "\t/year lyear def",
  215.   "\t/month lmonth def",
  216.   "\tgsave",
  217.   "\t500 -365 translate",
  218.   "\tgsave",
  219.   "\t.138 .138 scale",
  220.   "\t10 -120 translate",
  221.   "\tcalendar",
  222.   "\tgrestore",
  223.   "\t/submonth 1 def",
  224.   "\t/year nyear def",
  225.   "\t/month nmonth def",
  226.   "\t100 0 translate",
  227.   "\tgsave",
  228.   "\t.138 .138 scale",
  229.   "\t10 -120 translate",
  230.   "\tcalendar",
  231.   "\tgrestore",
  232.   "\t/month savemonth def",
  233.   "\t/year saveyear def",
  234.   "\t/submonth 0 def",
  235.   "\tgrestore",
  236.   "} def",
  237.   (char *)0,
  238. };
  239.  
  240.