home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / FTREE0.3.LHA / ftree / src / RCS / print.c,v < prev    next >
Encoding:
Text File  |  1994-04-29  |  60.9 KB  |  2,805 lines

  1. head    1.11;
  2. access;
  3. symbols
  4.     stage1:1.8;
  5. locks; strict;
  6. comment    @ * @;
  7.  
  8.  
  9. 1.11
  10. date    94.04.30.00.12.07;    author peteric;    state Exp;
  11. branches;
  12. next    1.10;
  13.  
  14. 1.10
  15. date    94.04.27.11.37.54;    author peteric;    state Exp;
  16. branches;
  17. next    1.9;
  18.  
  19. 1.9
  20. date    94.03.26.11.28.03;    author peteric;    state Exp;
  21. branches;
  22. next    1.8;
  23.  
  24. 1.8
  25. date    94.03.10.21.28.26;    author peteric;    state Exp;
  26. branches;
  27. next    1.7;
  28.  
  29. 1.7
  30. date    94.03.07.12.44.14;    author peteric;    state Exp;
  31. branches;
  32. next    1.6;
  33.  
  34. 1.6
  35. date    94.03.01.23.19.50;    author peteric;    state Exp;
  36. branches;
  37. next    1.5;
  38.  
  39. 1.5
  40. date    94.02.27.19.37.21;    author peteric;    state Exp;
  41. branches;
  42. next    1.4;
  43.  
  44. 1.4
  45. date    94.02.13.16.44.05;    author peteric;    state Exp;
  46. branches;
  47. next    1.3;
  48.  
  49. 1.3
  50. date    94.02.12.20.33.26;    author peteric;    state Exp;
  51. branches;
  52. next    1.2;
  53.  
  54. 1.2
  55. date    94.02.12.20.00.23;    author peteric;    state Exp;
  56. branches;
  57. next    1.1;
  58.  
  59. 1.1
  60. date    94.02.12.19.52.00;    author peteric;    state Exp;
  61. branches;
  62. next    ;
  63.  
  64.  
  65. desc
  66. @print routine for ftree family tree formatter.
  67. @
  68.  
  69.  
  70. 1.11
  71. log
  72. @Fixed a problem with the inter-marriage lines not being printed
  73. correctly - now uses the 'datewidth' member to join points approx
  74. next to the date of each marriage linked; also includes a 'stroke'
  75. command which was missing.
  76. Also moved the initial placement of the title up a bit so it doesn't
  77. overlap the first marriage(s) on the tree.
  78. @
  79. text
  80. @/*************************************************************************
  81.  *
  82.  *     $RCSfile: print.c,v $
  83.  *
  84.  *    $Author: peteric $
  85.  *
  86.  *    $Date: 1994/04/27 11:37:54 $
  87.  *
  88.  *    $State: Exp $
  89.  *
  90.  *    $Revision: 1.10 $
  91.  *
  92.  *    Purpose:    Print routines for ftree.
  93.  *            
  94.  *    $Log: print.c,v $
  95.  * Revision 1.10  1994/04/27  11:37:54  peteric
  96.  * Moved widthof code here from layout.c; added new routines
  97.  * setpersonwidths and setmarriagewidths to run through the person
  98.  * and marriage lists & set up the widths.
  99.  * Adjusted the structure member 'width' to be h.width in accordance with
  100.  * the structure changes.
  101.  * Fixed (a) bug in the 'printtitle' code. Removed the quoting aroung
  102.  * the brackets in PS strings - we know they will match properly.
  103.  *
  104.  * Revision 1.9  1994/03/26  11:28:03  peteric
  105.  * Included multiple-marriage print routines.
  106.  * [Not working correctly yet!] and modified title print
  107.  * code with PS support.
  108.  *
  109.  * Revision 1.8  1994/03/10  21:28:26  peteric
  110.  * Multiple pages working!
  111.  *
  112.  * Revision 1.7  1994/03/07  12:44:14  peteric
  113.  * Passed on as first Version.
  114.  *
  115.  * Revision 1.6  1994/03/01  23:19:50  peteric
  116.  * fixed handling of tickmarks & postitioning of
  117.  * printed lines. Improved compliance of DSC comments. Final?
  118.  * mods to the landscape code
  119.  *
  120.  * Revision 1.5  1994/02/27  19:37:21  peteric
  121.  * improved comments; new prolog stuff, fixed landscape mode
  122.  * code, moved some functions to layout.c
  123.  *
  124.  *
  125.  *************************************************************************/
  126.  
  127. #include <stdio.h>
  128. #include <stdlib.h>
  129. #include <string.h>
  130. #include <sys/time.h>
  131. #include <math.h>
  132. #include <assert.h>
  133.  
  134. #include "ftree.h"
  135.  
  136. #define MAX_CHART_PEOPLE    15
  137. #define EOS        '\0'
  138.  
  139. int numpeople = 0;
  140. int numchartprocs = 1;
  141.  
  142. /*(
  143.  ************************************************************* 
  144.  *
  145.  *    Function:    print_tree
  146.  *
  147.  *
  148.  *    Inputs:
  149.  *        outf - the output file to write PostScript to.
  150.  *        opts - current option set
  151.  *        id - the ID of the person to start at, who should be
  152.  *            married.
  153.  *
  154.  *    Outputs:
  155.  *        (file)
  156.  *
  157.  *    Error Handling:
  158.  *        None.
  159.  *
  160.  *    Description:
  161.  *        
  162.  *        
  163.  *
  164.  ************************************************************* 
  165. )*/
  166.  
  167. void print_tree(FILE *outf, options_t *opts, marriage_t *marriage)
  168. {
  169.     person_t *child;
  170.     
  171.     while(marriage)
  172.     {
  173.         dbprintf(( "\nprint_tree: marriage at: %d,%d\n", marriage->h.xpos, marriage->h.ypos));
  174.  
  175.         /*
  176.          * print this marriage.
  177.          */
  178.         printmarriage(outf, opts, marriage, marriage->h.xpos, marriage->h.ypos);
  179.         
  180.         if (marriage->children > 0)
  181.         {
  182.             int gap;
  183.             int x1, x2;
  184.             int y;
  185.  
  186.             dbprintf(( "print_tree: writing %d children ...\n", marriage->children));
  187.  
  188.             fprintf(outf, "1 setlinewidth\n");
  189.  
  190.             /*
  191.              * gap allowed for the parents info.
  192.              */
  193.             gap = (opts->personfont.linespc * opts->marrlines);
  194.  
  195.             /*
  196.              * draw a line 'connecting' the parents
  197.              * to the children's line.
  198.              */
  199.             y = marriage->firstchild->h.ypos;
  200.             fprintf(outf, "%d %d moveto %d %d lineto\n",
  201.                 XOF(opts, marriage->h.xpos), YOF(opts, marriage->h.ypos + gap),
  202.                 XOF(opts, marriage->h.xpos), YOF(opts, y - opts->ticklen));
  203.  
  204.             /*
  205.              * draw the horizontal line connecting 
  206.              * the children together.
  207.              */
  208.             if (marriage->firstchild->married)
  209.                 x1 = marriage->firstchild->firstmarriage->h.xpos;
  210.             else
  211.                 x1 = marriage->firstchild->h.xpos;
  212.  
  213.             if (marriage->lastchild->married)
  214.                 x2 = marriage->lastchild->firstmarriage->h.xpos;
  215.             else
  216.                 x2 = marriage->lastchild->h.xpos;
  217.  
  218.             fprintf(outf, "%d %d %d xrln    %% draw connecting bar for family\n",
  219.                 DXOF(opts, x2 - x1), XOF(opts, x1), YOF(opts, y - opts->ticklen));
  220.  
  221.             /*
  222.              * draw the tickmarks for each child
  223.              */
  224.             child = marriage->firstchild;
  225.             while(child != NULL)
  226.             {
  227.                 if (child->married)
  228.                 {
  229.                     fprintf(outf, "%d %d %d yrln    %% draw tick for %s %s\n",
  230.                         DYOF(opts, -opts->ticklen),
  231.                         XOF(opts, child->firstmarriage->h.xpos), YOF(opts, child->firstmarriage->h.ypos),
  232.                         child->firstname, child->family);
  233.                 }
  234.                 else
  235.                 {
  236.                     fprintf(outf, "%d %d %d yrln    %% draw tick for %s %s\n",
  237.                         DYOF(opts, -opts->ticklen), XOF(opts, child->h.xpos), YOF(opts, child->h.ypos),
  238.                         child->firstname, child->family);
  239.                 }
  240.                 child = child->nextchild;
  241.             }
  242.             fprintf(outf, "stroke\n");
  243.             
  244.             /*
  245.              * draw each child
  246.              */
  247.             child = marriage->firstchild;
  248.             while(child != NULL)
  249.             {
  250.                 if (child->married)
  251.                     print_tree(outf, opts, child->firstmarriage);
  252.                 else
  253.                     printperson(outf, opts, child, child->h.xpos, child->h.ypos);
  254.                 child = child->nextchild;
  255.             }
  256.         }
  257.         marriage = marriage->next;
  258.     } 
  259.     
  260.     dbprintf(( "print_tree: finished writing marriage.\n"));
  261. }
  262.  
  263. /*(
  264.  ************************************************************* 
  265.  *
  266.  *    Function:    printperson
  267.  *
  268.  *
  269.  *    Inputs:
  270.  *        outf - output file to write PostScript to.
  271.  *        opts - global options
  272.  *        person - person to write
  273.  *        x, y - PostScript coordinates to write person at.
  274.  *
  275.  *    Outputs:
  276.  *        none.
  277.  *
  278.  *    Description:
  279.  *        
  280.  *        Print an unmarried person centred at the position
  281.  * (x,y). The y coordinate is at the top of the area used for
  282.  * printing. Notice is taken of the 'fullname' variable.
  283.  *
  284.  ************************************************************* 
  285. )*/
  286.  
  287. void printperson(FILE *outf, options_t *opts, person_t *person, int x, int y)
  288. {
  289.     char dbuf[64], nbuf[128];
  290.     int linepos, lines[3];
  291.  
  292.     if (opts->multipage && (++numpeople > MAX_CHART_PEOPLE))
  293.     {
  294.         numpeople = 0;
  295.         numchartprocs++;
  296.         fprintf(outf, "} def\n\n/chartproc%02d {\n", numchartprocs);
  297.     }
  298.     
  299.     linepos = y;
  300.  
  301.     /*
  302.      * print out id, if wanted.
  303.      */
  304.     if (opts->printids)
  305.     {
  306.         linepos += opts->identfont.linespc;
  307.         lines[0] = YOF(opts, linepos);
  308.     }
  309.     else
  310.         linepos += opts->personfont.linespc;
  311.  
  312.     /*
  313.      * print out name.
  314.      */
  315.     lines[1] = YOF(opts, linepos);
  316.     if (person->fullname)
  317.     {
  318.         strcpy(nbuf, person->firstname);
  319.         strcat(nbuf, " ");
  320.         strcat(nbuf, person->family);
  321.     }
  322.     else
  323.         strcpy(nbuf, person->firstname);
  324.  
  325.     /*
  326.      * print out the date of birth & death
  327.      * SORT OUT: d.o.baptism
  328.      */
  329.     linepos += opts->datefont.linespc;
  330.     lines[2] = YOF(opts, linepos);
  331.     datefmt(dbuf, &person->born, &person->died);
  332.  
  333.     if (opts->printids)
  334.         fprintf(outf, "(%s) %d (%s) %d (ID: %lX) %d %d printperson\n",
  335.             dbuf, lines[2], nbuf, lines[1], person->id, lines[0],
  336.             XOF(opts, x));
  337.     else
  338.         fprintf(outf, "(%s) %d (%s) %d %d printperson\n",
  339.             dbuf, lines[2], nbuf, lines[1], XOF(opts, x));
  340. }
  341.  
  342. /*(
  343.  ************************************************************* 
  344.  *
  345.  *    Function:    printmarriage
  346.  *
  347.  *
  348.  *    Inputs:
  349.  *        
  350.  *
  351.  *    Outputs:
  352.  *        (file)
  353.  *
  354.  *    Error Handling:
  355.  *        none.
  356.  *
  357.  *    Description:
  358.  *        
  359.  *        print two married people centred at the position
  360.  * (x,y)
  361.  *
  362.  ************************************************************* 
  363. )*/
  364.  
  365. void printmarriage(FILE *outf, options_t *opts, marriage_t *marriage,
  366.                     int x, int y)
  367. {
  368.     int linepos, lines[7];
  369.     person_t *husb, *wife;
  370.     char hdtbuf[64], wdtbuf[64], hidbuf[12], widbuf[12];
  371.  
  372.     if (marriage == NULL)
  373.     {
  374.         dbprintf(("printmarriage: no marriage!!.\n"));
  375.         return;
  376.     }
  377.  
  378.     if (opts->multipage && (++numpeople > MAX_CHART_PEOPLE))
  379.     {
  380.         numpeople = 0;
  381.         numchartprocs++;
  382.         fprintf(outf, "} def\n\n/chartproc%02d {\n", numchartprocs);
  383.     }
  384.     
  385.     husb = marriage->husband;
  386.     wife = marriage->wife;
  387.     
  388.     if (marriage->backlink != NULL)
  389.     {
  390.         person_t *p;
  391.         
  392.         /*
  393.          * First find out which parent is the child of the marriage given.
  394.          */
  395.         p = marriage->backlink->firstchild;
  396.         while(p != NULL && p != marriage->husband && p != marriage->wife)
  397.         {
  398.             p = p->nextchild;
  399.         }
  400.         if (p != husb)
  401.         {
  402.             husb = marriage->wife;
  403.             wife = marriage->husband;
  404.         }
  405.     }
  406.     else
  407.         dbprintf(("printmarriage: no backlink.\n"));
  408.     
  409.     linepos = y;
  410.     
  411.     /*
  412.      * calculate the details for the first person.
  413.      */
  414.     linepos += opts->personfont.linespc;
  415.     lines[0] = YOF(opts,linepos);
  416.  
  417.     if (opts->printids)
  418.     {
  419.         linepos += opts->identfont.linespc;
  420.         lines[1] = YOF(opts,linepos);
  421.         sprintf(hidbuf, "(ID: %lX) true\n", husb->id);
  422.     }
  423.     else
  424.         hidbuf[0] = EOS;
  425.  
  426.     datefmt(hdtbuf, &husb->born, &husb->died);
  427.     linepos += opts->datefont.linespc;
  428.     lines[2] = YOF(opts,linepos);
  429.  
  430.     /*
  431.      * line for 'x' between the people
  432.      */
  433.     linepos += opts->symfont.linespc;
  434.     lines[3] = YOF(opts,linepos);
  435.  
  436.     /*
  437.      * calculate the details for the second person.
  438.      */
  439.     linepos += opts->personfont.linespc;
  440.     lines[4] = YOF(opts,linepos);
  441.  
  442.     if (opts->printids)
  443.     {
  444.         linepos += opts->identfont.linespc;
  445.         lines[5] = YOF(opts, linepos);
  446.         sprintf(widbuf, "(ID: %lX)", wife->id);
  447.     }
  448.  
  449.     datefmt(wdtbuf, &wife->born, &wife->died);
  450.     linepos += opts->datefont.linespc;
  451.     lines[6] = YOF(opts,linepos);
  452.     
  453.     if (marriage->when.known)
  454.         fprintf(outf, "(%s) %d (%s %s) %d ( %s) true %d (%s) %d (%s %s) %d %d printmarriage\n",
  455.                 wdtbuf, lines[6], wife->firstname, wife->family, lines[4],
  456.                 date2string(&marriage->when), lines[3],
  457.                 hdtbuf, lines[2], husb->firstname, husb->family, lines[0],
  458.                 XOF(opts, x));
  459.     else
  460.         fprintf(outf, "(%s) %d (%s %s) %d false %d (%s) %d (%s %s) %d %d printmarriage\n",
  461.                 wdtbuf, lines[6], wife->firstname, wife->family, lines[4], lines[3],
  462.                 hdtbuf, lines[2], husb->firstname, husb->family, lines[0],
  463.                 XOF(opts, x));
  464.  
  465.     if (marriage->children == 0)
  466.     {
  467.         linepos += opts->personfont.linespc;
  468.         fprintf(outf, "personfont setfont %d %d moveto ([no issue]) showcentred\n", XOF(opts, x), YOF(opts, linepos));
  469.     }
  470.     
  471.     if (marriage->prev)
  472.     {
  473.         int axs, axe, ay;
  474.         
  475.         ay = lines[3] + (opts->symfont.linespc / 3);
  476.         axs = marriage->prev->h.xpos + (marriage->prev->datewidth / 2) + 2;
  477.         axe = marriage->h.xpos - 2 - (marriage->datewidth / 2);
  478.         dbprintf(("printmarriage: inter-marriage line: %d %d to %d %d\n", axs, ay, axe, ay));
  479.         axs = XOF(opts, axs);
  480.         axe = XOF(opts, axe);
  481.         fprintf(outf, "%d %d %d xrln stroke\n", (axe - axs) + 1, axs, ay);
  482.     }
  483. }
  484.  
  485. /*(
  486.  ************************************************************* 
  487.  *
  488.  *    Function:    do_title
  489.  *
  490.  *
  491.  *    Inputs:
  492.  *        outf - file to write PostScript to
  493.  *        opts - option settings, including the title etc.
  494.  *
  495.  *    Outputs:
  496.  *        (file)
  497.  *
  498.  *    Error Handling:
  499.  *        none.
  500.  *
  501.  *    Description:
  502.  *        
  503.  *        To print the title string of the tree. Optionally, to
  504.  * place it in a grey box.
  505.  *
  506.  ************************************************************* 
  507. )*/
  508.  
  509. void do_title(FILE *outf, options_t *opts, marriage_t *marriage)
  510. {
  511.     fprintf(outf, "%%\n%% Draw the page title\n%%\n");
  512.     if (opts->multipage)
  513.     {
  514.         fprintf(outf, "titlefont setfont\n");
  515.         fprintf(outf, "%d %d moveto %.3f %d (%s) printtitle\n",
  516.                 XOF(opts, marriage->h.xpos), YOF(opts, opts->titlefont.linespc) + 2,
  517.                 opts->titlegreylevel, opts->titlefont.linespc, opts->titlestr);
  518.     }
  519.     else
  520.     {
  521.         fprintf(outf, "titlefont setfont\n");
  522.         fprintf(outf, "%d %d moveto %.3f %d (%s) printtitle\n",
  523.                 XOF(opts, opts->pagewidth/2), YOF(opts, opts->titlefont.linespc) + 2,
  524.                 opts->titlegreylevel, opts->titlefont.linespc, opts->titlestr);
  525.     }
  526. }
  527.  
  528. /*(
  529.  ************************************************************* 
  530.  *
  531.  *    Function:    do_prolog
  532.  *
  533.  *
  534.  *    Inputs:
  535.  *        outf - the file to write to
  536.  *        opts - the current options set
  537.  *
  538.  *    Outputs:
  539.  *        None.
  540.  *
  541.  *    Error Handling:
  542.  *        None.
  543.  *
  544.  *    Description:
  545.  *        
  546.  *        To output the appropriate DSC comments for the output
  547.  * file and generate definitions of private procedures.
  548.  *
  549.  ************************************************************* 
  550. )*/
  551.  
  552. static char default_procs[] =
  553. {
  554.     "/showcentred {            % str =>\n"
  555.     "    dup stringwidth pop 2 div neg 0 rmoveto show\n"
  556.     "} def\n"
  557.     "/show2centred {            % fdict str1 fdict str2 =>\n"
  558.     "    4 dict begin /s2 exch def /f2 exch def /s1 exch def /f1 exch def\n"
  559.     "    f1 setfont s1 stringwidth pop\n"
  560.     "    f2 setfont s2 stringwidth pop\n"
  561.     "    add 2 div neg 0 rmoveto\n"
  562.     "    f1 setfont s1 show f2 setfont s2 show\n"
  563.     "end } def\n"
  564.     "/showright {                % str => \n"
  565.     "    dup stringwidth pop neg 0 rmoveto show\n"
  566.     "} def\n"
  567.     "/yrln {                % dy x y =>\n"
  568.     "    moveto 0 exch rlineto\n"
  569.     "} bind def\n"
  570.     "/xrln {                % dx x y =>\n"
  571.     "    moveto 0 rlineto\n"
  572.     "} bind def\n"
  573.     "/fsf {                    % name size font-id =>\n"
  574.     "    findfont exch scalefont def\n"
  575.     "} bind def\n"
  576.     "/printtitle {            % grlev ptsiz ttl =>\n"
  577.     "    /ttl exch def /yd exch 10 add def /grlev exch def\n"
  578.     "    0 5 rmoveto currentpoint\n"
  579.     "    /xd ttl stringwidth pop 2 div 10 add def\n"
  580.     "    xd neg 0 rlineto 0 yd neg rlineto xd 2 mul 0 rlineto 0 yd rlineto\n"
  581.     "    closepath gsave grlev setgray fill grestore stroke\n"
  582.     "    moveto 0 yd 10 sub neg rmoveto ttl showcentred\n"
  583.     "} def\n"
  584.     "/printmarriage    {    % wdt wdt-y wife wf-y { mdt } show2? mdt-y bool hdt hdt-y husb-nm husb-y xpos =>\n"
  585.     "    /xpos exch def\n"
  586.     "    personfont setfont\n"
  587.     "    xpos exch moveto showcentred\n"
  588.     "    datefont setfont\n"
  589.     "    xpos exch moveto showcentred\n"
  590.     "    xpos exch moveto\n"
  591.     "    { symfont (x) datefont 4 -1 roll show2centred }\n"
  592.     "    { symfont setfont (x) showcentred } ifelse\n"
  593.     "    personfont setfont\n"
  594.     "    xpos exch moveto showcentred\n"
  595.     "    datefont setfont\n"
  596.     "    xpos exch moveto showcentred\n"
  597.     "} def\n"
  598.     "/printperson {        % dt-str dt-y nm-str nm-y { id-str id-y } pr-id xpos =>\n"
  599.     "    /xpos exch def\n"
  600.     "    printids { identfont setfont\n"
  601.     "        xpos exch moveto showcentred\n"
  602.     "    } if\n"
  603.     "    personfont setfont\n"
  604.     "    xpos exch moveto showcentred\n"
  605.     "    datefont setfont\n"
  606.     "    xpos exch moveto showcentred\n"
  607.     "} def\n"
  608.     "/cross {            % dxby2 dyby2 =>\n"
  609.     "    /dby2 exch def\n"
  610.     "    dby2 0 rmoveto dby2 neg 2 mul 0 rlineto\n"
  611.     "    dby2 dy rmoveto 0 dby2 2 mul rlineto\n"
  612.     "    0 dby2 neg rmoveto \n"
  613.     "} def\n"
  614.     "/cross {            % dby2 =>\n"
  615.     "    /dby2 exch def\n"
  616.     "    dby2 0 rmoveto dby2 -2 mul 0 rlineto\n"
  617.     "    dby2 dby2 rmoveto 0 dby2 -2 mul rlineto\n"
  618.     "    0 dby2 rmoveto \n"
  619.     "} def\n"
  620.     "/pmargins {\n"
  621.     "    0 setlinewidth\n"
  622.     "    newpath\n"
  623.     "    0 0 moveto 5 cross\n"
  624.     "    0 pageheight rmoveto 5 cross\n"
  625.     "    pagewidth 0 rmoveto 5 cross\n"
  626.     "    0 pageheight neg rmoveto 5 cross\n"
  627.     "    stroke\n"
  628.     "} def\n"
  629.     "/printmultiple {    % x-pages y-pages =>\n"
  630.     "    /rows exch def\n"
  631.     "    /cols exch def\n"
  632.     "    /pictproc exch def\n"
  633.     "    newpath\n"
  634.     "    leftmargin botmargin moveto\n"
  635.     "    0 pageheight rlineto\n"
  636.     "    pagewidth 0 rlineto\n"
  637.     "    0 pageheight neg rlineto\n"
  638.     "    closepath clip\n"
  639.     "    newpath % clip doesn't do this\n"
  640.     "    leftmargin botmargin translate\n"
  641.     "    0 1 rows 1 sub {\n"
  642.     "        /rowcount exch def\n"
  643.     "        0 1 cols 1 sub {\n"
  644.     "            /colcount exch def\n"
  645.     "            gsave initclip pmargins grestore\n"
  646.     "            gsave\n"
  647.     "            pagewidth colcount mul neg\n"
  648.     "            pageheight rowcount mul neg\n"
  649.     "            translate\n"
  650.     "            pictproc\n"
  651.     "            gsave showpage grestore\n"
  652.     "            grestore\n"
  653.     "        } for\n"
  654.     "    } for\n"
  655.     "} def\n"
  656. };
  657.  
  658.  
  659. void do_prolog(FILE *outf, options_t *opts)
  660. {
  661.     time_t now;
  662.     FILE *fp;
  663.     int pagew, pageh;
  664.  
  665.     /*
  666.      * the page size in terms of drawable area.
  667.      */
  668.     pagew = opts->pagewidth - (opts->lmargin + opts->rmargin);
  669.     pageh = opts->pageheight - (opts->tmargin + opts->bmargin);
  670.     
  671.     time(&now);
  672.     fprintf(outf, "%%!PS-Adobe-3.0\n");
  673.     fprintf(outf, "%%%%BoundingBox: (atend)\n");
  674.     fprintf(outf, "%%%%Title: (%s)\n", opts->titlestr);
  675.     fprintf(outf, "%%%%Creator: Ftree version " VERSION " (" __DATE__ ")\n");
  676.     fprintf(outf, "%%%%Copyright: Copyright (c) 1994 P. Ivimey-Cook\n");
  677.     fprintf(outf, "%%%%CreationDate: %s", ctime(&now));
  678.     fprintf(outf, "%%%%DocumentMedia: Plain %d %d 0 white ()\n", opts->pagewidth, opts->pageheight);
  679.     fprintf(outf, "%%%%DocumentNeededResources: font %s\n", opts->titlefont.font);
  680.     if (opts->printids)
  681.         fprintf(outf, "%%+ font %s\n", opts->identfont.font);
  682.     fprintf(outf, "%%%%+ font %s\n", opts->symfont.font);
  683.     fprintf(outf, "%%%%+ font %s\n", opts->datefont.font);
  684.     fprintf(outf, "%%%%+ font %s\n", opts->personfont.font);
  685.     fprintf(outf, "%%%%DocumentSuppliedResources: file %s\n", PROCSET_FILENAME);
  686.     if (opts->multipage)
  687.     {
  688.         int xp, yp;
  689.         xp = (opts->bbux + (pagew - 1)) / pagew;
  690.         yp = (opts->bbly + (pageh - 1)) / pageh;
  691.         fprintf(outf, "%%%%Pages: %d\n", xp * yp);
  692.     }
  693.     else
  694.         fprintf(outf, "%%%%Pages: 1\n");
  695.     fprintf(outf, "%%%%EndComments\n");
  696.     fprintf(outf, "%%%%BeginProlog\n");
  697.     fprintf(outf, "%%%%EndProlog\n");
  698.     fprintf(outf, "\n");
  699.     fprintf(outf, "%%%%Page: 1 1\n");
  700.     fprintf(outf, "%%%%BeginPageSetup\n");
  701.     if (!streq(opts->papertype, "special"))
  702.     {
  703.         fprintf(outf, "%%%%BeginFeature: *PageSize %s\n", opts->papertype);
  704.         fprintf(outf, "systemdict /%s known { %s } if\n", opts->papertype, opts->papertype);
  705.         fprintf(outf, "%%%%EndFeature\n");
  706.     }
  707.     fprintf(outf, "50 dict begin\n");
  708.     fprintf(outf, "%%%%BeginResource: file %s\n", PROCSET_FILENAME);
  709.  
  710.     fp = fopen(PROCSET_FILENAME, "r");
  711.     if (fp == NULL)
  712.     {
  713.         fputs(default_procs, outf);
  714.         dbprintf(("do_prolog: default procset loaded\n"));
  715.     }
  716.     else
  717.     {
  718.         static char buf[1024];
  719.         unsigned int l;
  720.         dbprintf(("do_prolog: procset %s loaded\n", PROCSET_FILENAME));
  721.         while((l = fread(buf, 1, sizeof(buf), fp)) > 0)
  722.             fwrite(buf, 1, l, outf);
  723.         fclose(fp);
  724.     }
  725.     fprintf(outf, "%%%%EndResource: file %s\n", PROCSET_FILENAME);
  726.  
  727.     fprintf(outf, "/personfont %.1f /%s fsf\n", opts->personfont.size, opts->personfont.font);
  728.     fprintf(outf, "/titlefont %.1f /%s fsf\n", opts->titlefont.size, opts->titlefont.font);
  729.     fprintf(outf, "/datefont %.1f /%s fsf\n", opts->datefont.size, opts->datefont.font);
  730.     fprintf(outf, "/symfont %.1f /%s fsf\n", opts->symfont.size, opts->symfont.font);
  731.     if (opts->printids)
  732.     {
  733.         fprintf(outf, "/identfont %.1f /%s fsf\n", opts->identfont.size, opts->identfont.font);
  734.         fprintf(outf, "/printids true def\n");
  735.     }
  736.     else
  737.         fprintf(outf, "/printids false def\n");
  738.     if (opts->landscape)
  739.     {
  740.         fprintf(outf, "%%%%PageOrientation: Landscape\n");
  741.         fprintf(outf, "clippath pathbbox exch pop exch pop exch pop \n");
  742.         fprintf(outf, "0 0 moveto -90 rotate neg dup == 0 translate\n");
  743.     }
  744.     else
  745.         fprintf(outf, "%%%%PageOrientation: Portrait\n");
  746.     
  747.     if (opts->multipage)
  748.     {
  749.         fprintf(outf, "/pagewidth %d def\n", pagew);
  750.         fprintf(outf, "/pageheight %d def\n", pageh);
  751.         fprintf(outf, "/leftmargin %d def\n", opts->lmargin);
  752.         fprintf(outf, "/botmargin %d def\n", opts->bmargin);
  753.         fprintf(outf, "%%%%EndPageSetup\n");
  754.         fprintf(outf, "\n/chartproc01 {\n");
  755.         numchartprocs = 1;
  756.     }
  757.     else
  758.         fprintf(outf, "%%%%EndPageSetup\n");
  759.     
  760. }
  761.  
  762. /*(
  763.  ************************************************************* 
  764.  *
  765.  *    Function:    do_epilog
  766.  *
  767.  *
  768.  *    Inputs:
  769.  *        outf - the file to write to
  770.  *        opts - the current options set
  771.  *
  772.  *    Outputs:
  773.  *        none.
  774.  *
  775.  *    Error Handling:
  776.  *        none.
  777.  *
  778.  *    Description:
  779.  *        
  780.  *        To close off the postscript program with showpage and
  781.  * appropriate DSC comments.
  782.  *
  783.  ************************************************************* 
  784. )*/
  785.  
  786. void do_epilog(FILE *outf, options_t *opts)
  787. {
  788.     int i;
  789.     if (opts->multipage)
  790.     {
  791.         fprintf(outf, "} def\n");
  792.         fprintf(outf, "{ ");
  793.         for (i = 1; i <= numchartprocs; i++)
  794.             fprintf(outf, "chartproc%02d ", i);
  795.         fprintf(outf, "}\n");
  796.         fprintf(outf, "%d pagewidth 1 sub add pagewidth idiv\n", opts->bbux);
  797.         fprintf(outf, "%d pageheight 1 sub add pageheight idiv\n", opts->bbly);
  798.         fprintf(outf, "printmultiple\n");
  799.     }
  800.     else
  801.         fprintf(outf, "showpage\n");
  802.     fprintf(outf, "end         %% of dict begin\n");
  803.     fprintf(outf, "%%%%PageTrailer\n");
  804.     fprintf(outf, "%%%%Trailer\n");
  805.     fprintf(outf, "%%%%BoundingBox: %d %d %d %d\n",
  806.                 opts->bblx, opts->bbly, opts->bbux, opts->bbuy);
  807.     fprintf(outf, "%%%%EOF\n");
  808. }
  809.  
  810. /*(
  811.  ************************************************************* 
  812.  *
  813.  *    Function:    date2string
  814.  *
  815.  *
  816.  *    Inputs:
  817.  *        d - pointer to a struct date
  818.  *
  819.  *    Outputs:
  820.  *        char * - pointer to a statically allocated buffer
  821.  *
  822.  *    Error Handling:
  823.  *        Copes with various forms of unknown date by placing
  824.  * '?' characters in the returned string. Copes with 'd'
  825.  * being NULL by returning "".
  826.  *
  827.  *    Description:
  828.  *        
  829.  *        Formats a date into a string, accounting for the
  830.  * values of some of the fields being unknown. The date format
  831.  * is predefined and unchangeable.
  832.  *
  833.  ************************************************************* 
  834. )*/
  835.  
  836. static char *months[] =
  837. {
  838.     "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  839.     "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
  840. };
  841.  
  842. char *date2string(struct date *d)
  843. {
  844.     static char buf[32];
  845.     char tbuf[12];
  846.  
  847.     buf[0] = EOS;
  848.     if (d == NULL || d->known == 0)
  849.         return buf;
  850.     
  851.     if (d->dvalid)
  852.         sprintf(buf, "%d-", d->day);
  853.  
  854.     if (d->mvalid && d->month >= 1 && d->month <= 12)
  855.     {
  856.         sprintf(tbuf, "%s-", months[d->month-1]);
  857.         strcat(buf, tbuf);
  858.     }
  859.     else if (buf[0] != EOS)
  860.         strcat(buf, "?-");
  861.  
  862.     if (d->yvalid)
  863.     {
  864.         sprintf(tbuf, "%d", d->year);
  865.         strcat(buf, tbuf);
  866.     }
  867.     else
  868.         strcat(buf, "?");
  869.  
  870.     dbprintf(( "date2string: buf : %s\n", buf));
  871.     return buf;
  872. }
  873.  
  874. /*(
  875.  ***********************************************************************
  876.  *
  877.  *    Function:    datefmt
  878.  *
  879.  *
  880.  *    Inputs:
  881.  *        born & died - dates which to be written
  882.  *
  883.  *    Outputs:
  884.  *        buf contains formatted date
  885.  *
  886.  *    Description:
  887.  *        
  888.  *        Formats a date for inclusion in a chart - the standard format is:
  889.  *            (<born> - <died>)
  890.  * where <born> and <died> are the dates formatted by date2string above.
  891.  *
  892.  ***********************************************************************
  893. )*/
  894.  
  895. void datefmt(char *buf, struct date *born, struct date *died)
  896. {
  897.     strcpy(buf, "(");
  898.     strcat(buf, date2string(born));
  899.     strcat(buf, " - ");
  900.     strcat(buf, date2string(died));
  901.     strcat(buf, ")");
  902.     
  903.     return;
  904. }
  905.  
  906. void setmarriagewidths(options_t *opts, marriage_t *mroot)
  907. {
  908.     register marriage_t *m = mroot;
  909.     while(m)
  910.     {
  911.         m->h.width = widthofmarriage(opts, m);
  912.         m = m->nextmarriage;
  913.     }
  914. }
  915.  
  916. void setpersonwidths(options_t *opts, person_t *proot)
  917. {
  918.     register person_t *p = proot;
  919.     while(p)
  920.     {
  921.         p->h.width = widthof(opts, p);
  922.         p = p->nextperson;
  923.     }
  924. }
  925.  
  926. /*(
  927.  ********************************************************************************** 
  928.  *
  929.  *    Function:    widthof
  930.  *
  931.  *
  932.  *    Inputs:
  933.  *        opts - global options
  934.  *        pers - pointer to a person record.
  935.  *
  936.  *    Outputs:
  937.  *        int - width in PS units (points) of the printed
  938.  *            version of the person.
  939.  *
  940.  *    Description:
  941.  *        
  942.  *        return the width required to print 'person'
  943.  *
  944.  ********************************************************************************** 
  945. )*/
  946.  
  947. int widthof(options_t *opts, person_t *pers)
  948. {
  949.     int w, namew, datew;
  950.     char bufn[128], bufd[128];
  951.  
  952.     if (pers->fullname)
  953.     {
  954.         strcpy(bufn, pers->firstname);
  955.         strcat(bufn, " ");
  956.         strcat(bufn, pers->family);
  957.     }
  958.     else
  959.         strcpy(bufn, pers->firstname);
  960.     
  961.     namew = ceil(stringwidth(&opts->personfont, opts->afmconst, bufn));
  962.  
  963.     datefmt(bufd, &pers->born, &pers->died);
  964.     datew = ceil(stringwidth(&opts->datefont, opts->afmconst, bufd));
  965.  
  966.     if (namew > datew)
  967.         w = namew + opts->tree_gap;
  968.     else    
  969.         w = datew + opts->tree_gap;
  970.  
  971.     dbprintf(("widthof: person %s / %s returns %d / %d  --> result %d\n",
  972.             bufn, bufd, namew, datew, w));
  973.     return w;
  974. }
  975.  
  976. /*(
  977.  ********************************************************************************** 
  978.  *
  979.  *    Function:    widthofmarriage
  980.  *
  981.  *
  982.  *    Inputs:
  983.  *        opts - global options.
  984.  *        marriage - the marriage defintion record.
  985.  *
  986.  *    Outputs:
  987.  *        int - the required width
  988.  *
  989.  *    Description:
  990.  *        
  991.  * Determines the width required to print a marriage in the standard form. The
  992.  * person widths are used for the name lengths, and the additional dates etc are
  993.  * then added into the calculations.
  994.  *
  995.  *********************************************************************************
  996. )*/
  997.  
  998. int widthofmarriage(options_t *opts, marriage_t *marriage)
  999. {
  1000.     int w1, w2, w3;
  1001.     
  1002.     assert(marriage->husband->married);
  1003.     assert(marriage->wife->married);
  1004.  
  1005.     w1 = marriage->husband->h.width;
  1006.     w2 = marriage->wife->h.width;
  1007.     
  1008.     w3 = ceil(stringwidth(&opts->symfont, opts->afmconst, "x"));
  1009.     if (marriage->when.known)
  1010.     {
  1011.         char *buf = date2string(&marriage->when);
  1012.         w3 += ceil(stringwidth(&opts->datefont, opts->afmconst, buf));
  1013.     }
  1014.     marriage->datewidth = w3;
  1015.     
  1016.     if (w1 < w2)
  1017.         w1 = w2;
  1018.     if (w1 < w3)
  1019.         w1 = w3;
  1020.     
  1021.     dbprintf(("widthofmarriage: return %d for marriage width\n", w1));
  1022.     
  1023.     return w1;
  1024. }
  1025.  
  1026. @
  1027.  
  1028.  
  1029. 1.10
  1030. log
  1031. @Moved widthof code here from layout.c; added new routines
  1032. setpersonwidths and setmarriagewidths to run through the person
  1033. and marriage lists & set up the widths.
  1034. Adjusted the structure member 'width' to be h.width in accordance with
  1035. the structure changes.
  1036. Fixed (a) bug in the 'printtitle' code. Removed the quoting aroung
  1037. the brackets in PS strings - we know they will match properly.
  1038. @
  1039. text
  1040. @d7 1
  1041. a7 1
  1042.  *    $Date: 1994/03/26 11:28:03 $
  1043. d11 1
  1044. a11 1
  1045.  *    $Revision: 1.9 $
  1046. d16 9
  1047. d396 3
  1048. a398 3
  1049.         ay = lines[3];
  1050.         axs = marriage->prev->h.xpos + (marriage->prev->h.width / 2) - 1;
  1051.         axe = marriage->h.xpos - (marriage->h.width / 2) + 1;
  1052. d402 1
  1053. a402 1
  1054.         fprintf(outf, "2 setlinewidth %d %d %d xrln\n", axe - axs, axs, ay);
  1055. d437 1
  1056. a437 1
  1057.                 XOF(opts, marriage->h.xpos), YOF(opts, opts->titlefont.linespc),
  1058. d444 1
  1059. a444 1
  1060.                 XOF(opts, opts->pagewidth/2), YOF(opts, opts->titlefont.linespc),
  1061. d935 1
  1062. @
  1063.  
  1064.  
  1065. 1.9
  1066. log
  1067. @Included multiple-marriage print routines.
  1068. [Not working correctly yet!] and modified title print
  1069. code with PS support.
  1070. @
  1071. text
  1072. @d7 1
  1073. a7 1
  1074.  *    $Date: 1994/03/10 21:28:26 $
  1075. d11 1
  1076. a11 1
  1077.  *    $Revision: 1.8 $
  1078. d16 5
  1079. d43 2
  1080. d85 1
  1081. a85 1
  1082.         dbprintf(( "\nprint_tree: marriage at: %d,%d\n", marriage->xpos, marriage->ypos));
  1083. d90 1
  1084. a90 1
  1085.         printmarriage(outf, opts, marriage, marriage->xpos, marriage->ypos);
  1086. d111 1
  1087. a111 1
  1088.             y = marriage->firstchild->ypos;
  1089. d113 2
  1090. a114 2
  1091.                 XOF(opts, marriage->xpos), YOF(opts, marriage->ypos + gap),
  1092.                 XOF(opts, marriage->xpos), YOF(opts, y - opts->ticklen));
  1093. d121 1
  1094. a121 1
  1095.                 x1 = marriage->firstchild->firstmarriage->xpos;
  1096. d123 1
  1097. a123 1
  1098.                 x1 = marriage->firstchild->xpos;
  1099. d126 1
  1100. a126 1
  1101.                 x2 = marriage->lastchild->firstmarriage->xpos;
  1102. d128 1
  1103. a128 1
  1104.                 x2 = marriage->lastchild->xpos;
  1105. d143 1
  1106. a143 1
  1107.                         XOF(opts, child->firstmarriage->xpos), YOF(opts, child->firstmarriage->ypos),
  1108. d149 1
  1109. a149 1
  1110.                         DYOF(opts, -opts->ticklen), XOF(opts, child->xpos), YOF(opts, child->ypos),
  1111. d165 1
  1112. a165 1
  1113.                     printperson(outf, opts, child, child->xpos, child->ypos);
  1114. d361 1
  1115. a361 1
  1116.     datefmt(hdtbuf, &wife->born, &wife->died);
  1117. d388 2
  1118. a389 2
  1119.         axs = marriage->prev->xpos + (marriage->prev->width / 2) - 1;
  1120.         axe = marriage->xpos - (marriage->width / 2) + 1;
  1121. d428 1
  1122. a428 1
  1123.                 XOF(opts, marriage->xpos), YOF(opts, opts->titlefont.linespc),
  1124. d489 3
  1125. a491 3
  1126.     "    /ttl exch def /yd exch 1.2 mul def /grlev exch def\n"
  1127.     "    currentpoint\n"
  1128.     "    /xd ttl stringwidth pop 2 div 1.2 mul def\n"
  1129. d494 1
  1130. a494 1
  1131.     "    moveto yd 1.1 div 0 rmoveto ttl showcentred\n"
  1132. d584 1
  1133. a584 1
  1134.     fprintf(outf, "%%%%!PS-Adobe-3.0\n");
  1135. d653 2
  1136. a654 3
  1137.         fprintf(outf, "-90 rotate -%d %d translate\n",
  1138.                 opts->pageheight - opts->tmargin,
  1139.                 - ((opts->pageheight - opts->pagewidth) - opts->rmargin));
  1140. d809 1
  1141. a809 1
  1142.     strcpy(buf, "\\(");
  1143. d813 1
  1144. a813 1
  1145.     strcat(buf, "\\)");
  1146. d816 121
  1147. a936 1
  1148. }@
  1149.  
  1150.  
  1151. 1.8
  1152. log
  1153. @Multiple pages working!
  1154. @
  1155. text
  1156. @d7 1
  1157. a7 1
  1158.  *    $Date: 1994/03/07 12:44:14 $
  1159. d11 1
  1160. a11 1
  1161.  *    $Revision: 1.7 $
  1162. d16 3
  1163. d42 1
  1164. d72 1
  1165. a72 1
  1166. void print_tree(FILE *outf, options_t *opts, id_t id)
  1167. a74 1
  1168.     marriage_t *marriage;
  1169. a75 1
  1170.     marriage = findmarriage1(id);
  1171. d156 1
  1172. a156 1
  1173.                     print_tree(outf, opts, child->id);
  1174. d162 1
  1175. a162 1
  1176.         marriage = nextmarriage(marriage, id);
  1177. d175 4
  1178. a178 1
  1179.  *        
  1180. d181 1
  1181. a181 4
  1182.  *        
  1183.  *
  1184.  *    Error Handling:
  1185.  *        
  1186. d185 3
  1187. a187 2
  1188.  *        print an unmarried person centred at the position
  1189.  * (x,y)
  1190. d197 1
  1191. a197 1
  1192.     if (++numpeople > MAX_CHART_PEOPLE)
  1193. d236 1
  1194. a236 5
  1195.     strcpy(dbuf, "(");
  1196.     strcat(dbuf, date2string(&person->born));
  1197.     strcat(dbuf, " - ");
  1198.     strcat(dbuf, date2string(&person->died));
  1199.     strcat(dbuf, ")");
  1200. d283 1
  1201. a283 1
  1202.     if (++numpeople > MAX_CHART_PEOPLE)
  1203. d316 3
  1204. d329 1
  1205. a329 1
  1206.         hidbuf[0] = '\0';
  1207. d331 1
  1208. a331 5
  1209.     strcpy(hdtbuf, "(");
  1210.     strcat(hdtbuf, date2string(&husb->born));
  1211.     strcat(hdtbuf, " - ");
  1212.     strcat(hdtbuf, date2string(&husb->died));
  1213.     strcat(hdtbuf, ")");
  1214. d342 1
  1215. a342 1
  1216.      * deal with the wife.
  1217. d354 1
  1218. a354 5
  1219.     strcpy(wdtbuf, "(");
  1220.     strcat(wdtbuf, date2string(&wife->born));
  1221.     strcat(wdtbuf, " - ");
  1222.     strcat(wdtbuf, date2string(&wife->died));
  1223.     strcat(wdtbuf, ")");
  1224. d375 13
  1225. d414 1
  1226. a414 1
  1227. void do_title(FILE *outf, options_t *opts)
  1228. a415 2
  1229.     int lx, ty, rx, by;
  1230.  
  1231. d417 8
  1232. a424 1
  1233.     if (opts->titlegreylevel < 1.0)
  1234. d426 5
  1235. a430 14
  1236.         fprintf(outf, "%.3f setgray\n", opts->titlegreylevel);
  1237.         lx = 0;
  1238.         ty = 0;
  1239.         rx = opts->pagewidth - opts->rmargin;
  1240.         by = opts->titlefont.size * 1.7;
  1241.         fprintf(outf, "%d %d moveto %d %d lineto %d %d lineto %d %d lineto\n",
  1242.                 XOF(opts, lx),    YOF(opts, ty),    XOF(opts, rx),    YOF(opts, ty),
  1243.                 XOF(opts, rx),    YOF(opts, by),    XOF(opts, lx),    YOF(opts, by));
  1244.         fprintf(outf, "closepath gsave fill grestore 0 setgray stroke\n");
  1245.     }
  1246.     fprintf(outf, "titlefont setfont\n");
  1247.     fprintf(outf, "%d %d moveto (%s) showcentred\n",
  1248.             XOF(opts, opts->pagewidth/2), YOF(opts, opts->titlefont.linespc),
  1249.             opts->titlestr);
  1250. d481 8
  1251. d568 1
  1252. d570 6
  1253. d591 9
  1254. a599 1
  1255.     fprintf(outf, "%%%%Pages: 1\n");
  1256. d606 6
  1257. a611 3
  1258.     fprintf(outf, "%%%%BeginFeature: *PageSize %s\n", opts->papertype);
  1259.     fprintf(outf, "systemdict /%s known { %s } if\n", opts->papertype, opts->papertype);
  1260.     fprintf(outf, "%%%%EndFeature\n");
  1261. d652 1
  1262. d655 2
  1263. a656 2
  1264.         fprintf(outf, "/pagewidth %d def\n", opts->pagewidth - (opts->lmargin + opts->rmargin));
  1265.         fprintf(outf, "/pageheight %d def\n", opts->pageheight - (opts->tmargin + opts->bmargin));
  1266. d659 3
  1267. d665 1
  1268. a665 2
  1269.     fprintf(outf, "/chartproc01 {\n");
  1270.     numchartprocs = 1;
  1271. d753 1
  1272. a753 1
  1273.     buf[0] = '\0';
  1274. a758 2
  1275.     else
  1276.         strcpy(buf, "?-");
  1277. d765 1
  1278. a765 1
  1279.     else
  1280. d780 20
  1281. d801 10
  1282. @
  1283.  
  1284.  
  1285. 1.7
  1286. log
  1287. @Passed on as first Version.
  1288. @
  1289. text
  1290. @d7 1
  1291. a7 1
  1292.  *    $Date: 1994/03/01 23:19:50 $
  1293. d11 1
  1294. a11 1
  1295.  *    $Revision: 1.6 $
  1296. d16 3
  1297. d38 5
  1298. d103 1
  1299. a103 1
  1300.             fprintf(outf, "%d %d moveto %d %d lineto stroke\n",
  1301. d121 2
  1302. a122 3
  1303.             fprintf(outf, "%% draw connecting bar for family\n");
  1304.             fprintf(outf, "%d %d moveto %d 0 rlineto stroke\n",
  1305.                 XOF(opts, x1), YOF(opts, y - opts->ticklen), DXOF(opts, x2 - x1));
  1306. d132 2
  1307. a133 2
  1308.                     fprintf(outf, "%% draw tick for %s %s\n", child->firstname, child->family);
  1309.                     fprintf(outf, "%d %d moveto 0 %d rlineto stroke\n",
  1310. d135 1
  1311. a135 3
  1312.                         DYOF(opts, -opts->ticklen));
  1313.                 
  1314.                     print_tree(outf, opts, child->id);
  1315. d139 17
  1316. a155 4
  1317.                     fprintf(outf, "%% draw tick for %s %s\n", child->firstname, child->family);
  1318.                     fprintf(outf, "%d %d moveto 0 %d rlineto stroke\n",
  1319.                         XOF(opts, child->xpos), YOF(opts, child->ypos), DYOF(opts, -opts->ticklen));
  1320.                 
  1321. a156 1
  1322.                 }
  1323. d183 1
  1324. a183 1
  1325.  *        print an unmarried person centered at the position
  1326. d191 2
  1327. a192 2
  1328.     char buf[64];
  1329.     int linepos;
  1330. d194 7
  1331. d202 1
  1332. a202 1
  1333.     fprintf(outf, "%%\n%% print an unmarried person\n%%\n");
  1334. d209 1
  1335. a209 3
  1336.         fprintf(outf, "identfont setfont\n");
  1337.         fprintf(outf, "%d %d moveto (ID: %lX) show\n",
  1338.             XOF(opts, x), YOF(opts, linepos), person->id);
  1339. d217 1
  1340. a217 2
  1341.     fprintf(outf, "personfont setfont\n");
  1342.     fprintf(outf, "%d %d moveto\n", XOF(opts, x), YOF(opts, linepos));
  1343. d219 5
  1344. a223 1
  1345.         fprintf(outf, "(%s %s) showcentered\n", person->firstname, person->family);
  1346. d225 1
  1347. a225 1
  1348.         fprintf(outf, "(%s) showcentered\n", person->firstname);
  1349. d232 14
  1350. a245 8
  1351.     fprintf(outf, "datefont setfont\n");
  1352.     strcpy(buf, "(");
  1353.     strcat(buf, date2string(&person->born));
  1354.     strcat(buf, " - ");
  1355.     strcat(buf, date2string(&person->died));
  1356.     strcat(buf, ")");
  1357.     fprintf(outf, "%d %d moveto (%s) showcentered\n",
  1358.         XOF(opts, x), YOF(opts, linepos), buf);
  1359. d265 1
  1360. a265 1
  1361.  *        print two married people centered at the position
  1362. d274 1
  1363. a274 2
  1364.     char buf[64];
  1365.     int linepos;
  1366. d276 1
  1367. d283 8
  1368. d318 1
  1369. a318 4
  1370.     fprintf(outf, "%%\n%% print a marriage\n%%\n");
  1371.     fprintf(outf, "personfont setfont\n");
  1372.     fprintf(outf, "%d %d moveto\n", XOF(opts, x), YOF(opts, linepos));
  1373.     fprintf(outf, "(%s %s) showcentered\n", husb->firstname, husb->family);
  1374. d323 2
  1375. a324 3
  1376.         fprintf(outf, "identfont setfont\n");
  1377.         fprintf(outf, "%d %d moveto\n", XOF(opts, x), YOF(opts, linepos));
  1378.         fprintf(outf, "(ID: %lx) show\n", husb->id);
  1379. d326 2
  1380. d329 5
  1381. a333 6
  1382.     strcpy(buf, "(");
  1383.     strcat(buf, date2string(&husb->born));
  1384.     strcat(buf, " - ");
  1385.     strcat(buf, date2string(&husb->died));
  1386.     strcat(buf, ")");
  1387.     fprintf(outf, "datefont setfont\n");
  1388. d335 1
  1389. a335 2
  1390.     fprintf(outf, "%d %d moveto (%s) showcentered\n",
  1391.             XOF(opts, x), YOF(opts, linepos), buf);
  1392. d338 1
  1393. a338 1
  1394.      * put an 'x' between the people
  1395. d341 1
  1396. a341 13
  1397.     fprintf(outf, "symfont setfont %d %d moveto\n",
  1398.             XOF(opts, x), YOF(opts, linepos));
  1399. #ifdef GLYPH
  1400.     fprintf(outf, "/multiply glyphstring showcentered\n");
  1401. #else
  1402.     if (marriage->when.known)
  1403.     {
  1404.         fprintf(outf, "symfont (x) datefont ( %s) show2centered\n",
  1405.                 date2string(&marriage->when));
  1406.     }
  1407.     else
  1408.         fprintf(outf, "(x) showcentered\n");
  1409. #endif
  1410. a345 1
  1411.     fprintf(outf, "personfont setfont\n");
  1412. d347 1
  1413. a347 2
  1414.     fprintf(outf, "%d %d moveto\n", XOF(opts, x), YOF(opts, linepos));
  1415.     fprintf(outf, "(%s %s) showcentered\n", wife->firstname, wife->family);
  1416. d352 2
  1417. a353 3
  1418.         fprintf(outf, "identfont setfont\n");
  1419.         fprintf(outf, "%d %d moveto\n", XOF(opts, x), YOF(opts, linepos));
  1420.         fprintf(outf, "(ID: %lx) showcentered\n", wife->id);
  1421. d356 5
  1422. a360 6
  1423.     strcpy(buf, "(");
  1424.     strcat(buf, date2string(&wife->born));
  1425.     strcat(buf, " - ");
  1426.     strcat(buf, date2string(&wife->died));
  1427.     strcat(buf, ")");
  1428.     fprintf(outf, "datefont setfont\n");
  1429. d362 1
  1430. a362 1
  1431.     fprintf(outf, "%d %d moveto (%s) showcentered\n", XOF(opts, x), YOF(opts, linepos), buf);
  1432. d364 12
  1433. a377 1
  1434.         fprintf(outf, "personfont setfont\n");
  1435. d379 1
  1436. a379 1
  1437.         fprintf(outf, "%d %d moveto ([no issue]) showcentered\n", XOF(opts, x), YOF(opts, linepos));
  1438. d425 1
  1439. a425 1
  1440.     fprintf(outf, "%d %d moveto (%s) showcentered\n",
  1441. d454 99
  1442. d556 1
  1443. d559 1
  1444. a559 1
  1445.     fprintf(outf, "%%!PS-Adobe-3.0\n");
  1446. d568 5
  1447. a572 4
  1448.         fprintf(outf, "%%+ %s\n", opts->identfont.font);
  1449.     fprintf(outf, "%%%%+ %s\n", opts->symfont.font);
  1450.     fprintf(outf, "%%%%+ %s\n", opts->datefont.font);
  1451.     fprintf(outf, "%%%%+ %s\n", opts->personfont.font);
  1452. d583 20
  1453. a602 31
  1454.     fprintf(outf, "10 dict begin\n");
  1455.     fprintf(outf, "/showcentered {            %% str showcentered -- \n");
  1456.     fprintf(outf, "dup stringwidth pop 2 div neg 0 rmoveto show\n");
  1457.     fprintf(outf, "} def\n");
  1458.     fprintf(outf, "/show2centered {            %% fdict str1 fdict str2 showcentered -- \n");
  1459.     fprintf(outf, "4 dict begin /s2 exch def /f2 exch def /s1 exch def /f1 exch def\n");
  1460.     fprintf(outf, "f1 setfont s1 stringwidth pop\n");
  1461.     fprintf(outf, "f2 setfont s2 stringwidth pop\n");
  1462.     fprintf(outf, "add 2 div neg 0 rmoveto\n");
  1463.     fprintf(outf, "f1 setfont s1 show f2 setfont s2 show\n");
  1464.     fprintf(outf, "end } def\n");
  1465.     fprintf(outf, "/showright {            %% str showright -- \n");
  1466.     fprintf(outf, "dup stringwidth pop neg 0 rmoveto show\n");
  1467.     fprintf(outf, "} def\n");
  1468.     fprintf(outf, "/fsf {findfont exch scalefont def} bind def\n");
  1469. #ifdef GLYPH
  1470.     fprintf(outf, "/glyphstring            %% symname glyhstring string\n");
  1471.     fprintf(outf, "{ 4 dict begin\n");
  1472.     fprintf(outf, "  /glyph exch def        %% get parameter\n");
  1473.     fprintf(outf, "  /res 1 string def\n");
  1474.     fprintf(outf, "  /encoding currentfont /Encoding get def\n");
  1475.     fprintf(outf, "  0 1 encoding length 1 sub\n");
  1476.     fprintf(outf, "  { dup encoding exch get glyph eq\n");
  1477.     fprintf(outf, "    { res exch 0 exch put exit }\n");
  1478.     fprintf(outf, "    { pop } ifelse\n");
  1479.     fprintf(outf, "  } for\n");
  1480.     fprintf(outf, "  res end\n");
  1481.     fprintf(outf, "} def\n");
  1482. #endif
  1483.     if (opts->printids)
  1484.         fprintf(outf, "/identfont %.1f /%s fsf\n", opts->identfont.size, opts->identfont.font);
  1485. d607 7
  1486. d623 11
  1487. a633 1
  1488.     fprintf(outf, "%%%%EndPageSetup\n");
  1489. d662 14
  1490. a675 1
  1491.     fprintf(outf, "showpage\n");
  1492. @
  1493.  
  1494.  
  1495. 1.6
  1496. log
  1497. @fixed handling of tickmarks & postitioning of
  1498. printed lines. Improved compliance of DSC comments. Final?
  1499. mods to the landscape code
  1500. @
  1501. text
  1502. @d7 1
  1503. a7 1
  1504.  *    $Date: 1994/02/27 19:37:21 $
  1505. d11 1
  1506. a11 1
  1507.  *    $Revision: 1.5 $
  1508. d16 5
  1509. d209 1
  1510. a209 4
  1511.     if (person->born.known)
  1512.     {
  1513.         strcat(buf, date2string(&person->born));
  1514.     }
  1515. d211 1
  1516. a211 4
  1517.     if (person->died.known)
  1518.     {
  1519.         strcat(buf, date2string(&person->died));
  1520.     }
  1521. a242 1
  1522. #if 0
  1523. d245 1
  1524. d247 1
  1525. a247 3
  1526.     linepos = y;
  1527.     fprintf(outf, "%%\n%% print a marriage\n%%\n");
  1528.     if (opts->printids)
  1529. d249 2
  1530. a250 4
  1531.         linepos += opts->identfont.linespc;
  1532.         fprintf(outf, "identfont setfont\n");
  1533.         fprintf(outf, "%d %d moveto\n", XOF(opts, x), YOF(opts, linepos));
  1534.         fprintf(outf, "(ID: %lx) show\n", marriage->husband->id);
  1535. d252 4
  1536. a255 13
  1537.     else
  1538.         linepos += opts->personfont.linespc;
  1539.  
  1540.     fprintf(outf, "personfont setfont\n");
  1541.     fprintf(outf, "%d %d moveto\n", XOF(opts, x), YOF(opts, linepos));
  1542.     fprintf(outf, "( %s) show\n", marriage->husband->firstname);
  1543.     linepos += opts->personfont.linespc;
  1544.  
  1545.     fprintf(outf, "%d %d moveto\n", XOF(opts, x), YOF(opts, linepos));
  1546.     fprintf(outf, "( %s) show\n", marriage->husband->family);
  1547.     linepos += opts->personfont.linespc;
  1548.     strcpy(buf, "(");
  1549.     if (marriage->husband->born.known)
  1550. d257 15
  1551. a271 21
  1552.         strcat(buf, date2string(&marriage->husband->born));
  1553.     }
  1554.     strcat(buf, " - ");
  1555.     if (marriage->husband->died.known)
  1556.     {
  1557.         strcat(buf, date2string(&marriage->husband->died));
  1558.     }
  1559.     strcat(buf, ")");
  1560.     fprintf(outf, "datefont setfont\n");
  1561.     fprintf(outf, "%d %d moveto (%s) show\n", XOF(opts, x+1), YOF(opts, linepos), buf);
  1562.  
  1563.     /*
  1564.      * deal with the wife.
  1565.      */
  1566.     linepos = y;
  1567.     if (opts->printids)
  1568.     {
  1569.         linepos += opts->identfont.linespc;
  1570.         fprintf(outf, "identfont setfont\n");
  1571.         fprintf(outf, "%d %d moveto\n", XOF(opts, x), YOF(opts, linepos));
  1572.         fprintf(outf, "(ID: %lx) showright\n", marriage->wife->id);
  1573. d274 2
  1574. a275 26
  1575.         linepos += opts->personfont.linespc;
  1576.     fprintf(outf, "personfont setfont\n");
  1577.     fprintf(outf, "%d %d moveto\n", XOF(opts, x), YOF(opts, linepos));
  1578.     fprintf(outf, "(%s ) showright\n", marriage->wife->firstname);
  1579.     linepos += opts->personfont.linespc;
  1580.     fprintf(outf, "%d %d moveto\n", XOF(opts, x), YOF(opts, linepos));
  1581.     fprintf(outf, "(%s ) showright\n", marriage->wife->family);
  1582.     linepos += opts->personfont.linespc;
  1583.  
  1584.     strcpy(buf, "(");
  1585.     if (marriage->wife->born.known)
  1586.     {
  1587.         strcat(buf, date2string(&marriage->wife->born));
  1588.     }
  1589.     strcat(buf, " - ");
  1590.     if (marriage->wife->died.known)
  1591.     {
  1592.         strcat(buf, date2string(&marriage->wife->died));
  1593.     }
  1594.     strcat(buf, ")");
  1595.     fprintf(outf, "datefont setfont\n");
  1596.     fprintf(outf, "%d %d moveto (%s) showright\n", XOF(opts, x-1), YOF(opts, linepos), buf);
  1597. #else
  1598.     char buf[64];
  1599.     int linepos;
  1600.  
  1601. d277 1
  1602. d282 1
  1603. a282 1
  1604.     fprintf(outf, "(%s %s) showcentered\n", marriage->husband->firstname, marriage->husband->family);
  1605. d289 1
  1606. a289 1
  1607.         fprintf(outf, "(ID: %lx) show\n", marriage->husband->id);
  1608. d293 1
  1609. a293 4
  1610.     if (marriage->husband->born.known)
  1611.     {
  1612.         strcat(buf, date2string(&marriage->husband->born));
  1613.     }
  1614. d295 1
  1615. a295 4
  1616.     if (marriage->husband->died.known)
  1617.     {
  1618.         strcat(buf, date2string(&marriage->husband->died));
  1619.     }
  1620. d299 2
  1621. a300 1
  1622.     fprintf(outf, "%d %d moveto (%s) showcentered\n", XOF(opts, x), YOF(opts, linepos), buf);
  1623. d306 2
  1624. a307 1
  1625.     fprintf(outf, "symfont setfont %d %d moveto\n", XOF(opts, x), YOF(opts, linepos));
  1626. d313 2
  1627. a314 1
  1628.         fprintf(outf, "symfont (x) datefont ( %s) show2centered\n", date2string(&marriage->when));
  1629. d326 1
  1630. a326 1
  1631.     fprintf(outf, "(%s %s) showcentered\n", marriage->wife->firstname, marriage->wife->family);
  1632. d333 1
  1633. a333 1
  1634.         fprintf(outf, "(ID: %lx) showcentered\n", marriage->wife->id);
  1635. d337 1
  1636. a337 4
  1637.     if (marriage->wife->born.known)
  1638.     {
  1639.         strcat(buf, date2string(&marriage->wife->born));
  1640.     }
  1641. d339 1
  1642. a339 4
  1643.     if (marriage->wife->died.known)
  1644.     {
  1645.         strcat(buf, date2string(&marriage->wife->died));
  1646.     }
  1647. d344 7
  1648. a350 1
  1649. #endif
  1650. d560 6
  1651. d572 1
  1652. a572 1
  1653.     if (d == NULL)
  1654. d576 1
  1655. a576 1
  1656.         sprintf(buf, "%d/", d->day);
  1657. d578 1
  1658. a578 1
  1659.         strcpy(buf, "?/");
  1660. d580 1
  1661. a580 1
  1662.     if (d->mvalid)
  1663. d582 1
  1664. a582 1
  1665.         sprintf(tbuf, "%d/", d->month);
  1666. d586 1
  1667. a586 1
  1668.         strcat(buf, "?/");
  1669. @
  1670.  
  1671.  
  1672. 1.5
  1673. log
  1674. @improved comments; new prolog stuff, fixed landscape mode
  1675. code, moved some functions to layout.c
  1676. @
  1677. text
  1678. @d3 1
  1679. a3 1
  1680.  *     $RCSfile$
  1681. d5 1
  1682. a5 1
  1683.  *    $Author$
  1684. d7 1
  1685. a7 1
  1686.  *    $Date$
  1687. d9 1
  1688. a9 1
  1689.  *    $State$
  1690. d11 1
  1691. a11 1
  1692.  *    $Revision$
  1693. d15 4
  1694. a18 1
  1695.  *    $Log$
  1696. d20 1
  1697. d73 2
  1698. d83 1
  1699. a83 1
  1700.             gap = (opts->personfont.linespc * opts->marrlines) - (opts->ticklen);
  1701. d89 1
  1702. d92 1
  1703. a92 1
  1704.                 XOF(opts, marriage->xpos), YOF(opts, marriage->firstchild->ypos - opts->ticklen));
  1705. d98 11
  1706. d110 1
  1707. a110 2
  1708.                 XOF(opts, marriage->firstchild->xpos), YOF(opts, marriage->firstchild->ypos - opts->ticklen),
  1709.                 DXOF(opts, marriage->lastchild->xpos - marriage->firstchild->xpos));
  1710. d112 3
  1711. a117 3
  1712.                 fprintf(outf, "%d %d moveto 0 %d rlineto stroke\n",
  1713.                     XOF(opts, child->xpos), YOF(opts, child->ypos), DYOF(opts, -opts->ticklen));
  1714.                 
  1715. d120 5
  1716. d129 5
  1717. a133 1
  1718.                     printperson(outf, opts, child, child->xpos, child->ypos+opts->ticklen+1);
  1719. d174 3
  1720. a176 1
  1721.     fprintf(outf, "personfont setfont\n");
  1722. d180 2
  1723. a181 1
  1724.         fprintf(outf, "%d %d moveto (ID: %lx) show\n",
  1725. d184 7
  1726. d196 6
  1727. d215 1
  1728. a215 1
  1729.         XOF(opts, x), YOF(opts, y+opts->personfont.linespc), buf);
  1730. d252 1
  1731. a255 1
  1732.         linepos += opts->identfont.linespc;
  1733. d257 2
  1734. d288 1
  1735. a291 1
  1736.         linepos += opts->identfont.linespc;
  1737. d293 2
  1738. d321 1
  1739. a325 1
  1740.     linepos += opts->personfont.linespc;
  1741. d329 1
  1742. a332 1
  1743.         linepos += opts->identfont.linespc;
  1744. d347 1
  1745. a348 1
  1746.     linepos += opts->personfont.linespc;
  1747. d353 1
  1748. a364 1
  1749.     linepos += opts->symfont.linespc;
  1750. d370 1
  1751. a372 1
  1752.     linepos += opts->personfont.linespc;
  1753. d376 1
  1754. a379 1
  1755.         linepos += opts->identfont.linespc;
  1756. d394 1
  1757. d477 3
  1758. a479 1
  1759.     fprintf(outf, "%%%%CreatorTitle: Ftree version " VERSION " (" __DATE__ ")\n");
  1760. d481 1
  1761. d484 4
  1762. a487 4
  1763.     fprintf(outf, "%%+ %s\n", opts->identfont.font);
  1764.     fprintf(outf, "%%+ %s\n", opts->symfont.font);
  1765.     fprintf(outf, "%%+ %s\n", opts->datefont.font);
  1766.     fprintf(outf, "%%+ %s\n", opts->personfont.font);
  1767. d489 3
  1768. d495 3
  1769. a498 1
  1770.     fprintf(outf, "systemdict /%s known { %s } if\n", opts->papertype, opts->papertype);
  1771. d528 1
  1772. a528 1
  1773.     fprintf(outf, "/identfont %.1f /%s fsf\n", opts->identfont.size, opts->identfont.font);
  1774. d536 3
  1775. a538 2
  1776.         fprintf(outf, "-90 rotate -%d %d translate\n", opts->pageheight - opts->tmargin, opts->rmargin);
  1777.         fprintf(outf, "0.66 dup scale\n");
  1778. d573 2
  1779. a574 2
  1780.     fprintf(outf, "%%%%EndPage: 1 1\n");
  1781.     fprintf(outf, "%%%%Trailer:\n");
  1782. @
  1783.  
  1784.  
  1785. 1.4
  1786. log
  1787. @started to implement multiple marriages; they overprint at the
  1788. moment! Made the DSC comments treat the tree as a page & fixed
  1789. some minor errors. Added new code to print marriage people on
  1790. a line.
  1791. @
  1792. text
  1793. @d5 1
  1794. a5 1
  1795.  *    $Author: peteric $
  1796. d7 1
  1797. a7 1
  1798.  *    $Date: 1994/02/12 20:33:26 $
  1799. d11 1
  1800. a11 1
  1801.  *    $Revision: 1.3 $
  1802. d15 1
  1803. a15 3
  1804.  *    $Log: print.c,v $
  1805.  * Revision 1.3  1994/02/12  20:33:26  peteric
  1806.  * changed interface to marriages to allow multiple marriages per id
  1807. a16 5
  1808.  * Revision 1.2  94/02/12  20:00:23  20:00:23  peteric (Peter Ivimey-Cook)
  1809.  * added in comments etc.
  1810.  * 
  1811.  *    
  1812.  *
  1813. a18 1
  1814.  
  1815. d21 1
  1816. a25 2
  1817. #define TREE_GAP    12
  1818.  
  1819. d29 1
  1820. a29 1
  1821.  *    Function:    print
  1822. a32 318
  1823.  *        opts
  1824.  *
  1825.  *    Outputs:
  1826.  *        (file)
  1827.  *
  1828.  *    Error Handling:
  1829.  *        none.
  1830.  *
  1831.  *    Description:
  1832.  *        
  1833.  *        Calls the routines to format and output PostScript
  1834.  * statements which will draw the family tree described in the
  1835.  * opts array, using data from the mroot/proot lists.
  1836.  *
  1837.  *         The tree is assumed to be a true tree - i.e. one root
  1838.  * node branching out to n leaf nodes. 
  1839.  *
  1840.  *         If the named 'outputfile' is 'con' this is taken as
  1841.  * a signal to write output to the standard output stream
  1842.  * instead of opening a new file.
  1843.  *
  1844.  ************************************************************* 
  1845. )*/
  1846.  
  1847. void print(options_t *opts)
  1848. {
  1849.     FILE *outf;
  1850.     person_t *pers;
  1851.     marriage_t *marr;;
  1852.  
  1853.     if (strcmp(opts->outputfile, "con"))
  1854.     {
  1855.         outf = fopen(opts->outputfile, "w");
  1856.         if (outf == NULL)
  1857.         {
  1858.             fprintf(stderr, "ftree: cannot write file '%s'\n", opts->outputfile);
  1859.             exit(1);
  1860.         }
  1861.     }
  1862.     else
  1863.         outf = stdout;
  1864.  
  1865.     /*
  1866.      * print out the prolog stuff
  1867.      */
  1868.     do_prolog(outf, opts);
  1869.     
  1870.     /*
  1871.      * put a title on the page
  1872.      */
  1873.     do_title(outf, opts);
  1874.     
  1875.     /*
  1876.      * print our tree
  1877.      */
  1878.     do_simple_layout(opts, opts->startperson, (opts->pagewidth - opts->rmargin)/2, opts->title.linespc + 3*opts->person.linespc, 0);
  1879.     adjust_layout(opts, opts->startperson);
  1880.     print_tree(outf, opts, opts->startperson);
  1881.     
  1882.     /*
  1883.      * finish it off
  1884.      */
  1885.     do_epilog(outf, opts);
  1886.  
  1887.     /*
  1888.      * close the file.
  1889.      */
  1890.     if (outf != stdout)
  1891.         fclose(outf);
  1892. }
  1893.  
  1894. /*(
  1895.  ************************************************************* 
  1896.  *
  1897.  *    Function:    
  1898.  *
  1899.  *
  1900.  *    Inputs:
  1901.  *        
  1902.  *
  1903.  *    Outputs:
  1904.  *        
  1905.  *
  1906.  *    Error Handling:
  1907.  *        
  1908.  *
  1909.  *    Description:
  1910.  *        
  1911.  *        
  1912.  *
  1913.  ************************************************************* 
  1914. )*/
  1915.  
  1916. void do_simple_layout(options_t *opts, char *id, int x, int y, int level)
  1917. {
  1918.     int i, children;
  1919.     int ptwidth, startx, endx, childy;
  1920.     person_t *child;
  1921.     marriage_t *marriage, *m;
  1922.     
  1923.     dbprintf(( "\ndo_simple_layout: do layout for ID %s at: %d,%d\n", id, x,y));
  1924.  
  1925.     marriage = findmarriage(id);
  1926.     while(marriage)
  1927.     {
  1928.         dbprintf(( "do_simple_layout: found marriage.\n"));
  1929.         marriage->xpos = x;
  1930.         marriage->ypos = y;
  1931.  
  1932.         /*
  1933.          * work out how many children there are
  1934.          */
  1935.         children = 0;
  1936.         ptwidth = 0;
  1937.         child = marriage->firstchild;
  1938.         while(child != NULL)
  1939.         {
  1940.             children++;
  1941.             child->married = (findmarriage(child->id) != NULL);
  1942.             child->fullname = !streq(child->family, marriage->husband->family) || child->married;
  1943.             child->width = widthof(opts, child);
  1944.             ptwidth += child->width;
  1945.             dbprintf(( "do_simple_layout: adding width for child %d\n", children));
  1946.             child = child->nextchild;
  1947.         }
  1948.         marriage->children = children;
  1949.         marriage->level = level;
  1950.  
  1951.         /*
  1952.          * ptwidth is only the width of the connecting line ... it doesn't
  1953.          * include the space at each end.
  1954.          */
  1955.         if (marriage->children >= 1)
  1956.             ptwidth -= (marriage->firstchild->width + marriage->lastchild->width) / 2;
  1957.  
  1958.         dbprintf(( "do_simple_layout: ptwidth: %d children %d\n", ptwidth, marriage->children));
  1959.  
  1960.         if (marriage->children > 0)
  1961.         {
  1962.             childy = y + opts->vspace;
  1963.             startx = x - (ptwidth / 2);
  1964.             dbprintf(( "do_simple_layout: startx: %d (= %d - (%d/2)), children: %d\n", startx, x, ptwidth,marriage->children));
  1965.             /*
  1966.              * have a go at placing the children.
  1967.              */
  1968.             child = marriage->firstchild;
  1969.             while(child != NULL)
  1970.             {
  1971.                 child->xpos = startx;
  1972.                 child->ypos = childy;
  1973.                 dbprintf(( "do_simple_layout: child %s @@ %dx%d\n", child->firstname, startx, childy));
  1974.                 startx += (child->width + child->nextchild->width) / 2;
  1975.                 child = child->nextchild;
  1976.             }
  1977.  
  1978.             dbprintf(( "do_simple_layout: searching for marriages \n"));
  1979.  
  1980.             child = marriage->firstchild;
  1981.             while(child != NULL)
  1982.             {
  1983.                 if (child->married)
  1984.                 {
  1985.                     if (level <= opts->maxlevel)
  1986.                     {
  1987.                         do_simple_layout(opts, child->id, child->xpos, child->ypos + opts->ticklen+1, level+1);
  1988.                     }
  1989.                     else
  1990.                     {
  1991.                         dbprintf(("do_simple_layout: marriage of %s %s skipped - too many levels.\n", child->firstname, child->family));
  1992.                     }
  1993.                 }
  1994.                 child = child->nextchild;
  1995.             }
  1996.         }
  1997.         dbprintf(( "do_simple_layout: finished marriage.\n"));
  1998.         marriage = nextmarriage(marriage, id);
  1999.     }
  2000.  
  2001.     dbprintf(( "do_simple_layout: finished simple layout for ID %s.\n", id));
  2002. }
  2003.  
  2004. /*(
  2005.  ************************************************************* 
  2006.  *
  2007.  *    Function:    adjust_layout
  2008.  *
  2009.  *
  2010.  *    Inputs:
  2011.  *        opts - current option set
  2012.  *        id - the ID of the person to start at, who should be
  2013.  *            married.
  2014.  *
  2015.  *    Outputs:
  2016.  *        (file)
  2017.  *
  2018.  *    Error Handling:
  2019.  *        None.
  2020.  *
  2021.  *    Description:
  2022.  *        
  2023.  *        This routine takes the initial positions assigned by
  2024.  * the routine do_simple_layout and adjusts the positions
  2025.  * such that people do not overlap.
  2026.  *
  2027.  ************************************************************* 
  2028. )*/
  2029.  
  2030. void adjust_layout(options_t *opts, char *id)
  2031. {
  2032.     person_t *child, *lastchild = NULL;
  2033.     marriage_t *m, *marriage;
  2034.     int newpos, dx;
  2035.  
  2036.     dbprintf(( "adjust_layout: examining tree for ID %s....\n", id));
  2037.  
  2038.     marriage = findmarriage(id);
  2039.     while(marriage)
  2040.     {
  2041.         child = marriage->firstchild;
  2042.         while(child != NULL)
  2043.         {
  2044.             if (child->married)
  2045.             {
  2046.                 adjust_layout(opts, child->id);
  2047.                 m = findmarriage(child->id);
  2048.             }
  2049.             if (child->married && m->children > 0)
  2050.             {
  2051.                 if (lastchild)
  2052.                 {
  2053.                     newpos = m->firstchild->xpos;
  2054.                     dx = lastchild->xpos - newpos;
  2055.                     dbprintf(("adjust_layout: does child %s overlap %s (%d vs %d) ?",
  2056.                             m->firstchild->firstname, lastchild->firstname, newpos, lastchild->xpos));
  2057.                     if (dx > 0)
  2058.                     {
  2059.                         dbprintf((" ... yes\n"));
  2060.                         dx += ((lastchild->width + m->firstchild->width) / 2 );
  2061.                         dbprintf(("adjust_layout: dx += (%d + %d)/2 => %d\n", lastchild->width, m->firstchild->width, dx));
  2062.                         move_tree(m, dx);
  2063.                         child->xpos += dx;
  2064.                     }
  2065.                     else
  2066.                     {
  2067.                         dbprintf((" ... no\n"));
  2068.                     }
  2069.                 }
  2070.                 lastchild = m->lastchild;
  2071.             }
  2072.             child = child->nextchild;
  2073.         }
  2074.         marriage = nextmarriage(marriage, id);
  2075.     }
  2076.     
  2077.     dbprintf(( "adjust_layout: finished examining tree for ID %s...\n", id));
  2078. }
  2079.  
  2080. /*(
  2081.  ************************************************************* 
  2082.  *
  2083.  *    Function:    move_tree
  2084.  *
  2085.  *
  2086.  *    Inputs:
  2087.  *        marriage - the base of the tree to move
  2088.  *        dx - the ammount by which to move the tree
  2089.  *
  2090.  *    Outputs:
  2091.  *        none.
  2092.  *
  2093.  *    Error Handling:
  2094.  *        none.
  2095.  *
  2096.  *    Description:
  2097.  *        
  2098.  *        Moves the tree based at 'marriage' by an ammount 'dx'
  2099.  * in the X direction. No effect in the Y direction.
  2100.  *
  2101.  ************************************************************* 
  2102. )*/
  2103.  
  2104. void move_tree(marriage_t *marriage, int dx)
  2105. {
  2106.     person_t *child;
  2107.     marriage_t *m;
  2108.  
  2109.     dbprintf(( "move_tree: move marriage %s %s by %d\n",
  2110.             marriage->husband->firstname, marriage->wife->family, dx));
  2111.  
  2112.     marriage->xpos += dx;
  2113.  
  2114.     if (marriage->children > 0)
  2115.     {
  2116.         child = marriage->firstchild;
  2117.         while(child != NULL)
  2118.         {
  2119.             child->xpos += dx;
  2120.  
  2121.             dbprintf(( "move_tree: move child %s %s by %d\n",
  2122.                     child->firstname, child->family, dx));
  2123.  
  2124.             if (child->married)
  2125.             {
  2126.                 m = findmarriage(child->id);
  2127.                 move_tree(m, dx);
  2128.             }
  2129.             child = child->nextchild;
  2130.         }
  2131.     }
  2132. }
  2133.  
  2134. /*(
  2135.  ************************************************************* 
  2136.  *
  2137.  *    Function:    
  2138.  *
  2139.  *
  2140.  *    Inputs:
  2141. d51 1
  2142. a51 1
  2143. void print_tree(FILE *outf, options_t *opts, char *id)
  2144. d54 1
  2145. a54 1
  2146.     marriage_t *m, *marriage;
  2147. d56 1
  2148. a56 1
  2149.     marriage = findmarriage(id);
  2150. d77 1
  2151. a77 1
  2152.             gap = (opts->person.linespc * opts->marrlines) - (opts->ticklen);
  2153. a120 47
  2154.  *    Function:    widthof
  2155.  *
  2156.  *
  2157.  *    Inputs:
  2158.  *        
  2159.  *
  2160.  *    Outputs:
  2161.  *        
  2162.  *
  2163.  *    Error Handling:
  2164.  *        
  2165.  *
  2166.  *    Description:
  2167.  *        
  2168.  *        return the width required to print 'person'
  2169.  *
  2170.  ************************************************************* 
  2171. )*/
  2172.  
  2173. int widthof(options_t *opts, person_t *pers)
  2174. {
  2175.     int w;
  2176.     person_t *child;
  2177.     int l;
  2178.  
  2179.     if (pers->fullname)
  2180.     {
  2181.         l = strlen(pers->family);
  2182.         l += strlen(pers->firstname);
  2183.     }
  2184.     else
  2185.     {
  2186.         l = strlen(pers->firstname);
  2187.     }
  2188.  
  2189.     w = (opts->person.size * l) / 1.5;
  2190.     w = w + TREE_GAP;
  2191.  
  2192.     dbprintf(( "widthof: %s width of \"%s\" is \t%d (%dc).\n", 
  2193.         (pers->fullname)?"full":"short", pers->firstname, w, l));
  2194.     return w;
  2195. }
  2196.  
  2197.  
  2198. /*(
  2199.  ************************************************************* 
  2200.  *
  2201. d151 2
  2202. a152 2
  2203.         linepos += opts->ident.linespc;
  2204.         fprintf(outf, "%d %d moveto (ID: %s) show\n",
  2205. d173 1
  2206. a173 1
  2207.         XOF(opts, x), YOF(opts, y+opts->person.linespc), buf);
  2208. d212 2
  2209. a213 2
  2210.         fprintf(outf, "(ID: %s) show\n", marriage->husband->id);
  2211.         linepos += opts->ident.linespc;
  2212. d219 1
  2213. a219 1
  2214.     linepos += opts->person.linespc;
  2215. d223 1
  2216. a223 1
  2217.     linepos += opts->person.linespc;
  2218. d246 2
  2219. a247 2
  2220.         fprintf(outf, "(ID: %s) showright\n", marriage->wife->id);
  2221.         linepos += opts->ident.linespc;
  2222. d252 1
  2223. a252 1
  2224.     linepos += opts->person.linespc;
  2225. d255 1
  2226. a255 1
  2227.     linepos += opts->person.linespc;
  2228. d279 1
  2229. a279 1
  2230.     linepos += opts->person.linespc;
  2231. d285 2
  2232. a286 2
  2233.         fprintf(outf, "(ID: %s) show\n", marriage->husband->id);
  2234.         linepos += opts->ident.linespc;
  2235. d302 1
  2236. a302 1
  2237.     linepos += opts->person.linespc;
  2238. d305 1
  2239. a305 1
  2240.      * put an '=' between the people
  2241. d307 12
  2242. a318 3
  2243.     fprintf(outf, "%d %d moveto\n", XOF(opts, x), YOF(opts, linepos));
  2244.     fprintf(outf, "(=) showcentered\n");
  2245.     linepos += opts->person.linespc;
  2246. d326 1
  2247. a326 1
  2248.     linepos += opts->person.linespc;
  2249. d332 2
  2250. a333 2
  2251.         fprintf(outf, "(ID: %s) showcentered\n", marriage->wife->id);
  2252.         linepos += opts->ident.linespc;
  2253. a377 1
  2254.     int h;
  2255. a378 1
  2256.     float ptsz = opts->title.size;
  2257. d387 1
  2258. a387 1
  2259.         by = opts->title.size * 1.7;
  2260. d395 2
  2261. a396 1
  2262.             XOF(opts, opts->pagewidth/2), YOF(opts, opts->title.linespc), opts->titlestr);
  2263. d422 1
  2264. d432 6
  2265. a437 2
  2266.     fprintf(outf, "%%%%DocumentSuppliedResources: font %s %s %s\n",
  2267.                         opts->title.font, opts->ident.font, opts->person.font);
  2268. d444 1
  2269. a444 1
  2270.     fprintf(outf, "/showcentered {                %% str showc -- \n");
  2271. d447 8
  2272. a454 1
  2273.     fprintf(outf, "/showright {                   %% str showc -- \n");
  2274. d458 20
  2275. a477 4
  2276.     fprintf(outf, "/identfont %.1f /%s fsf\n", opts->ident.size, opts->ident.font);
  2277.     fprintf(outf, "/personfont %.1f /%s fsf\n", opts->person.size, opts->person.font);
  2278.     fprintf(outf, "/titlefont %.1f /%s fsf\n", opts->title.size, opts->title.font);
  2279.     fprintf(outf, "/datefont %.1f /%s fsf\n", opts->person.size-2, opts->person.font);
  2280. d481 2
  2281. a482 4
  2282.         fprintf(outf, "gsave clippath pathbbox grestore\n");
  2283.         fprintf(outf, "4 dict begin /ury exch def /urx exch def /lly exch def /llx exch def\n");
  2284.         fprintf(outf, "-90 rotate urx neg lly neg translate\n");
  2285.         fprintf(outf, "end\n");
  2286. d557 1
  2287. a557 1
  2288.         return;
  2289. @
  2290.  
  2291.  
  2292. 1.3
  2293. log
  2294. @changed interface to marriages to allow multiple marriages per id
  2295. @
  2296. text
  2297. @d3 1
  2298. a3 1
  2299.  *     $Name$
  2300. d7 1
  2301. a7 1
  2302.  *    $Date: 94/02/12 20:00:23 $
  2303. d9 1
  2304. a9 1
  2305.  *    $Revision: 1.2 $
  2306. d11 2
  2307. d15 4
  2308. a18 1
  2309.  *    $Log:    print.c,v $
  2310. d38 1
  2311. a38 1
  2312.  *    Function:    
  2313. d42 1
  2314. a42 1
  2315.  *        
  2316. d45 1
  2317. a45 1
  2318.  *        
  2319. d48 1
  2320. a48 1
  2321.  *        
  2322. d52 10
  2323. a61 1
  2324.  *        
  2325. d142 1
  2326. a142 1
  2327.     dbprintf(( "\ndo_simple_layout: marriage at: %d,%d\n", x,y));
  2328. d147 1
  2329. a180 2
  2330.             int gap;
  2331.  
  2332. d210 1
  2333. a210 1
  2334.                         dbprintf(("do_simple_layout: marriage skipped - too many levels.\n"));
  2335. d220 1
  2336. a220 1
  2337.     dbprintf(( "do_simple_layout: finished simple layout.\n"));
  2338. d226 1
  2339. a226 1
  2340.  *    Function:    
  2341. d230 3
  2342. a232 1
  2343.  *        
  2344. d235 1
  2345. a235 1
  2346.  *        
  2347. d238 1
  2348. a238 1
  2349.  *        
  2350. d242 3
  2351. a244 1
  2352.  *        
  2353. a252 1
  2354.     int lastpos = 0;
  2355. d255 1
  2356. a255 1
  2357.     dbprintf(( "adjust_layout: examining tree....\n"));
  2358. d263 6
  2359. a268 1
  2360.             if (child->married && (m = findmarriage(child->id)) && m->children > 0)
  2361. d273 1
  2362. a273 2
  2363.                     dx = (lastpos - newpos);
  2364.                     dbprintf(("adjust_layout: dx = (%d - %d) => %d\n", lastpos, newpos, dx));
  2365. d275 1
  2366. a275 1
  2367.                             m->firstchild->firstname, lastchild->firstname, newpos, lastpos));
  2368. a289 1
  2369.                 lastpos = lastchild->xpos;
  2370. d296 1
  2371. a296 1
  2372.     dbprintf(( "adjust_layout: finished examining tree...\n"));
  2373. d302 1
  2374. a302 1
  2375.  *    Function:    
  2376. d306 2
  2377. a307 1
  2378.  *        
  2379. d310 1
  2380. a310 1
  2381.  *        
  2382. d313 1
  2383. a313 1
  2384.  *        
  2385. d317 2
  2386. a318 1
  2387.  *        
  2388. d322 1
  2389. a322 3
  2390. /*
  2391.  * move a tree rooted at marriage by an ammount dx.
  2392.  */
  2393. d360 4
  2394. a363 1
  2395.  *        
  2396. d366 1
  2397. a366 1
  2398.  *        
  2399. d369 1
  2400. a369 1
  2401.  *        
  2402. d377 1
  2403. d404 1
  2404. a404 1
  2405.             gap = (opts->person.linespc * 5) - (opts->ticklen);
  2406. d448 1
  2407. a448 1
  2408.  *    Function:    
  2409. d462 1
  2410. a462 1
  2411.  *        
  2412. d466 1
  2413. a466 3
  2414. /*
  2415.  * return the width required to print 'person'
  2416.  */
  2417. d483 1
  2418. a483 1
  2419.     w = (opts->person.size * l) / 1.6;
  2420. d495 1
  2421. a495 1
  2422.  *    Function:    
  2423. d509 2
  2424. a510 1
  2425.  *        
  2426. d514 1
  2427. a514 3
  2428. /*
  2429.  * print an unmarried person centered at the position (x,y)
  2430.  */
  2431. d553 1
  2432. a553 1
  2433.  *    Function:    
  2434. d560 1
  2435. a560 1
  2436.  *        
  2437. d563 1
  2438. a563 1
  2439.  *        
  2440. d567 2
  2441. a568 1
  2442.  *        
  2443. d572 1
  2444. a572 3
  2445. /*
  2446.  * print two married people centered at the position (x,y)
  2447.  */
  2448. d720 1
  2449. a720 1
  2450.  *    Function:    
  2451. d724 2
  2452. a725 1
  2453.  *        
  2454. d728 1
  2455. a728 1
  2456.  *        
  2457. d731 1
  2458. a731 1
  2459.  *        
  2460. d735 2
  2461. a736 1
  2462.  *        
  2463. d740 1
  2464. a740 3
  2465. /*
  2466.  * print out our title string
  2467.  */
  2468. d748 13
  2469. a760 10
  2470.     fprintf(outf, "0.75 setgray\n");
  2471.     lx = 0;
  2472.     ty = 0;
  2473.     rx = opts->pagewidth - opts->rmargin;
  2474.     by = opts->title.size * 1.7;
  2475.     fprintf(outf, "%d %d moveto %d %d lineto %d %d lineto %d %d lineto ",
  2476.             XOF(opts, lx),    YOF(opts, ty),    XOF(opts, rx),    YOF(opts, ty),
  2477.             XOF(opts, rx),    YOF(opts, by),    XOF(opts, lx),    YOF(opts, by));
  2478.     fprintf(outf, " closepath fill\n");
  2479.     fprintf(outf, "titlefont setfont 0 setgray\n");
  2480. d768 1
  2481. a768 1
  2482.  *    Function:    
  2483. d772 2
  2484. a773 1
  2485.  *        
  2486. d776 1
  2487. a776 1
  2488.  *        
  2489. d779 1
  2490. a779 1
  2491.  *        
  2492. d783 2
  2493. a784 1
  2494.  *        
  2495. d795 1
  2496. a795 1
  2497.     fprintf(outf, "%%%%CreatorTitle: %s\n", opts->title);
  2498. d797 2
  2499. a798 1
  2500.     fprintf(outf, "%%%%DocumentFonts: %s\n", opts->title.font);
  2501. d800 4
  2502. a803 1
  2503.     fprintf(outf, "%%%%BeginProlog\n");
  2504. d817 10
  2505. a826 5
  2506.         fprintf(outf, "-90 rotate %d 0 translate\n", -opts->pagewidth);
  2507.     fprintf(outf, "%d %d translate\n", opts->lmargin, opts->bmargin);
  2508.     fprintf(outf, "%%%%EndProlog\n");
  2509.     fprintf(outf, "\n");
  2510.     fprintf(outf, "%%%%Page: 1 1\n");
  2511. d832 1
  2512. a832 1
  2513.  *    Function:    
  2514. d836 2
  2515. a837 1
  2516.  *        
  2517. d840 1
  2518. a840 1
  2519.  *        
  2520. d843 1
  2521. a843 1
  2522.  *        
  2523. d847 2
  2524. a848 1
  2525.  *        
  2526. d852 1
  2527. d856 1
  2528. d861 1
  2529. d867 1
  2530. a867 1
  2531.  *    Function:    
  2532. d871 1
  2533. a871 1
  2534.  *        
  2535. d874 1
  2536. a874 1
  2537.  *        
  2538. d877 3
  2539. a879 1
  2540.  *        
  2541. d883 3
  2542. a885 1
  2543.  *        
  2544. d889 1
  2545. d896 3
  2546. @
  2547.  
  2548.  
  2549. 1.2
  2550. log
  2551. @added in comments etc.
  2552. @
  2553. text
  2554. @d5 1
  2555. a5 1
  2556.  *    $Author$
  2557. d7 1
  2558. a7 1
  2559.  *    $Date$
  2560. d9 1
  2561. a9 1
  2562.  *    $Revision$
  2563. d13 4
  2564. a16 1
  2565.  *    $Log$
  2566. d30 22
  2567. a57 7
  2568.     marr = findmarriage(opts->startperson);
  2569.     if (marr == NULL)
  2570.     {
  2571.         fprintf(stderr, "ftree: start person %s not found in a marriage.\n", opts->startperson);
  2572.         exit(1);
  2573.     }
  2574.  
  2575. d83 3
  2576. a85 3
  2577.     do_simple_layout(opts, marr, (opts->pagewidth - opts->rmargin)/2, opts->title.linespc + 3*opts->person.linespc, 0);
  2578.     adjust_layout(opts, marr);
  2579.     print_tree(outf, opts, marr);
  2580. d99 23
  2581. a121 1
  2582. void do_simple_layout(options_t *opts, marriage_t *marriage, int x, int y, int level)
  2583. d126 1
  2584. a126 1
  2585.     marriage_t *m;
  2586. a128 3
  2587.     
  2588.     marriage->xpos = x;
  2589.     marriage->ypos = y;
  2590. d130 2
  2591. a131 7
  2592.     /*
  2593.      * work out how many children there are
  2594.      */
  2595.     children = 0;
  2596.     ptwidth = 0;
  2597.     child = marriage->firstchild;
  2598.     while(child != NULL)
  2599. d133 2
  2600. a134 10
  2601.         children++;
  2602.         child->married = (findmarriage(child->id) != NULL);
  2603.         child->fullname = !streq(child->family, marriage->husband->family) || child->married;
  2604.         child->width = widthof(opts, child);
  2605.         ptwidth += child->width;
  2606.         dbprintf(( "do_simple_layout: adding width for child %d\n", children));
  2607.         child = child->nextchild;
  2608.     }
  2609.     marriage->children = children;
  2610.     marriage->level = level;
  2611. a135 16
  2612.     /*
  2613.      * ptwidth is only the width of the connecting line ... it doesn't
  2614.      * include the space at each end.
  2615.      */
  2616.     if (marriage->children >= 1)
  2617.         ptwidth -= (marriage->firstchild->width + marriage->lastchild->width) / 2;
  2618.  
  2619.     dbprintf(( "do_simple_layout: ptwidth: %d children %d\n", ptwidth, marriage->children));
  2620.  
  2621.     if (marriage->children > 0)
  2622.     {
  2623.         int gap;
  2624.  
  2625.         childy = y + opts->vspace;
  2626.         startx = x - (ptwidth / 2);
  2627.         dbprintf(( "do_simple_layout: startx: %d (= %d - (%d/2)), children: %d\n", startx, x, ptwidth,marriage->children));
  2628. d137 1
  2629. a137 1
  2630.          * have a go at placing the children.
  2631. d139 2
  2632. d144 6
  2633. a149 4
  2634.             child->xpos = startx;
  2635.             child->ypos = childy;
  2636.             dbprintf(( "do_simple_layout: child %s @@ %dx%d\n", child->firstname, startx, childy));
  2637.             startx += (child->width + child->nextchild->width) / 2;
  2638. d152 2
  2639. d155 6
  2640. a160 1
  2641.         dbprintf(( "do_simple_layout: searching for marriages \n"));
  2642. d162 3
  2643. a164 2
  2644.         child = marriage->firstchild;
  2645.         while(child != NULL)
  2646. d166 10
  2647. a175 1
  2648.             if (child->married && (m = findmarriage(child->id)) != NULL && (level <= opts->maxlevel))
  2649. d177 5
  2650. a181 3
  2651.                 dbprintf(("do_simple_layout: calling do_simple_layout...\n"));
  2652.                 do_simple_layout(opts, m, child->xpos, child->ypos + opts->ticklen+1, level+1);
  2653.                 dbprintf(("do_simple_layout: returning from do_simple_layout...\n"));
  2654. d183 19
  2655. a201 1
  2656.             child = child->nextchild;
  2657. d203 2
  2658. d206 2
  2659. a207 1
  2660.     dbprintf(( "do_simple_layout: finished writing marriage.\n"));
  2661. d210 21
  2662. d232 1
  2663. a232 1
  2664. void adjust_layout(options_t *opts, marriage_t *marriage)
  2665. d235 1
  2666. a235 1
  2667.     marriage_t *m;
  2668. d241 2
  2669. a242 2
  2670.     child = marriage->firstchild;
  2671.     while(child != NULL)
  2672. d244 2
  2673. a245 1
  2674.         if (child->married && (m = findmarriage(child->id)) && m->children > 0)
  2675. d247 1
  2676. a247 1
  2677.             if (lastchild)
  2678. d249 1
  2679. a249 6
  2680.                 newpos = m->firstchild->xpos;
  2681.                 dx = (lastpos - newpos);
  2682.                 dbprintf(("adjust_layout: dx = (%d - %d) => %d\n", lastpos, newpos, dx));
  2683.                 dbprintf(("adjust_layout: does child %s overlap %s (%d vs %d) ?",
  2684.                         m->firstchild->firstname, lastchild->firstname, newpos, lastpos));
  2685.                 if (dx > 0)
  2686. d251 17
  2687. a267 5
  2688.                     dbprintf((" ... yes\n"));
  2689.                     dx += ((lastchild->width + m->firstchild->width) / 2 );
  2690.                     dbprintf(("adjust_layout: dx += (%d + %d)/2 => %d\n", lastchild->width, m->firstchild->width, dx));
  2691.                     move_tree(m, dx);
  2692.                     child->xpos += dx;
  2693. d269 2
  2694. a270 4
  2695.                 else
  2696.                 {
  2697.                     dbprintf((" ... no\n"));
  2698.                 }
  2699. d272 1
  2700. a272 2
  2701.             lastchild = m->lastchild;
  2702.             lastpos = lastchild->xpos;
  2703. d274 1
  2704. a274 1
  2705.         child = child->nextchild;
  2706. d280 21
  2707. d334 22
  2708. a355 1
  2709. void print_tree(FILE *outf, options_t *opts, marriage_t *marriage)
  2710. d358 1
  2711. a358 1
  2712.     marriage_t *m;
  2713. d360 2
  2714. a361 7
  2715.     dbprintf(( "\nprint_tree: marriage at: %d,%d\n", marriage->xpos, marriage->ypos));
  2716.     /*
  2717.      * print this marriage.
  2718.      */
  2719.     printmarriage(outf, opts, marriage, marriage->xpos, marriage->ypos);
  2720.     
  2721.     if (marriage->children > 0)
  2722. d363 1
  2723. a363 1
  2724.         int gap;
  2725. a364 4
  2726.         dbprintf(( "print_tree: writing %d children ...\n", marriage->children));
  2727.  
  2728.         fprintf(outf, "1 setlinewidth\n");
  2729.  
  2730. d366 1
  2731. a366 1
  2732.          * gap allowed for the parents info.
  2733. d368 5
  2734. a372 1
  2735.         gap = (opts->person.linespc * 5) - (opts->ticklen);
  2736. d374 1
  2737. a374 7
  2738.         /*
  2739.          * draw a line 'connecting' the parents
  2740.          * to the children's line.
  2741.          */
  2742.         fprintf(outf, "%d %d moveto %d %d lineto stroke\n",
  2743.             XOF(opts, marriage->xpos), YOF(opts, marriage->ypos + gap),
  2744.             XOF(opts, marriage->xpos), YOF(opts, marriage->firstchild->ypos - opts->ticklen));
  2745. d376 1
  2746. a376 7
  2747.         /*
  2748.          * draw the horizontal line connecting 
  2749.          * the children together.
  2750.          */
  2751.         fprintf(outf, "%d %d moveto %d 0 rlineto stroke\n",
  2752.             XOF(opts, marriage->firstchild->xpos), YOF(opts, marriage->firstchild->ypos - opts->ticklen),
  2753.             DXOF(opts, marriage->lastchild->xpos - marriage->firstchild->xpos));
  2754. d378 23
  2755. a400 7
  2756.         child = marriage->firstchild;
  2757.         while(child != NULL)
  2758.         {
  2759.             fprintf(outf, "%d %d moveto 0 %d rlineto stroke\n",
  2760.                 XOF(opts, child->xpos), YOF(opts, child->ypos), DYOF(opts, -opts->ticklen));
  2761.             
  2762.             if (child->married)
  2763. d402 12
  2764. a413 2
  2765.                 m = findmarriage(child->id);
  2766.                 print_tree(outf, opts, m);
  2767. a414 5
  2768.             else
  2769.             {
  2770.                 printperson(outf, opts, child, child->xpos, child->ypos+opts->ticklen+1);
  2771.             }
  2772.             child = child->nextchild;
  2773. d416 3
  2774. a418 1
  2775.     }
  2776. d422 21
  2777. d471 21
  2778. d530 21
  2779. a553 1
  2780. #if 0
  2781. d557 1
  2782. a624 1
  2783. }
  2784. a625 3
  2785. void printmarriage(FILE *outf, options_t *opts, marriage_t *marriage,
  2786.                     int x, int y)
  2787. {
  2788. d695 1
  2789. a696 1
  2790. #endif
  2791. d698 21
  2792. d743 21
  2793. d796 21
  2794. d826 21
  2795. @
  2796.  
  2797.  
  2798. 1.1
  2799. log
  2800. @Initial revision
  2801. @
  2802. text
  2803. @d1 17
  2804. @
  2805.