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

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