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

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