~ubuntu-branches/debian/sid/gnubg/sid

« back to all changes in this revision

Viewing changes to postscript.c

  • Committer: Bazaar Package Importer
  • Author(s): Russ Allbery
  • Date: 2006-12-28 10:45:05 UTC
  • mfrom: (2.1.5 feisty)
  • Revision ID: james.westby@ubuntu.com-20061228104505-4p6sxxdosrlvhgpr
Tags: 0.14.3+20060923-4
* Translation updates:
  - French, thanks Thomas Huriaux.  (Closes: #404254)
  - Spanish, thanks Javier Ruano.  (Closes: #404613)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * postscript.c
3
3
 *
4
 
 * by Gary Wong <gtw@gnu.org>, 2001
 
4
 * by Gary Wong <gtw@gnu.org>, 2001, 2002
5
5
 *
6
6
 * This program is free software; you can redistribute it and/or modify
7
7
 * it under the terms of version 2 of the GNU General Public License as
16
16
 * along with this program; if not, write to the Free Software
17
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
18
 *
19
 
 * $Id: postscript.c,v 1.8 2001/11/01 15:47:56 gtw Exp $
 
19
 * $Id: postscript.c,v 1.41 2006/06/17 17:58:27 oysteijo Exp $
20
20
 */
21
21
 
22
22
#include "config.h"
25
25
#include <ctype.h>
26
26
#include <dynarray.h>
27
27
#include <stdio.h>
 
28
#include <stdlib.h>
28
29
#include <string.h>
29
30
#include <time.h>
30
31
 
 
32
#include "analysis.h"
31
33
#include "backgammon.h"
32
34
#include "drawboard.h"
33
 
 
34
 
typedef enum _font { FONT_NONE, FONT_RM, FONT_SF, FONT_TT } font;
35
 
static char *aszFont[ FONT_TT + 1 ] = { NULL, "rm", "sf", "tt" };
 
35
#include "positionid.h"
 
36
#include <glib/gi18n.h>
 
37
#include "format.h"
 
38
#include "export.h"
 
39
#include "matchid.h"
 
40
 
 
41
typedef enum _font { 
 
42
  FONT_NONE, 
 
43
  /* Times-Roman */
 
44
  FONT_RM,               
 
45
  FONT_RM_BOLD,          
 
46
  FONT_RM_ITALIC,       
 
47
  FONT_RM_BOLD_ITALIC,  
 
48
  /* Helvetica (Sans serif) */
 
49
  FONT_SF,  
 
50
  FONT_SF_BOLD,  
 
51
  FONT_SF_OBLIQUE,  
 
52
  FONT_SF_BOLD_OBLIQUE,  
 
53
  /* Courier (type writer) */
 
54
  FONT_TT,  
 
55
  FONT_TT_BOLD,
 
56
  FONT_TT_OBLIQUE,
 
57
  FONT_TT_BOLD_OBLIQUE,
 
58
  NUM_FONTS,
 
59
} font;
 
60
static char *aszFont[ NUM_FONTS ] = { 
 
61
  NULL, 
 
62
  "rm", "rmb", "rmi", "rmbi",
 
63
  "sf", "sfb", "sfo", "sfbo",
 
64
  "tt", "ttb", "tto", "ttbo",
 
65
};
 
66
 
 
67
static char *aszFontName[ NUM_FONTS ] = {
 
68
  NULL,
 
69
  "Times-Roman",
 
70
  "Times-Bold",
 
71
  "Times-Italic",
 
72
  "Times-BoldItalic",
 
73
  "Helvetica",
 
74
  "Helvetica-Bold",
 
75
  "Helvetica-Oblique",
 
76
  "Helvetica-Bold-Oblique",
 
77
  "Courier",
 
78
  "Courier-Bold",
 
79
  "Courier-Oblique",
 
80
  "Courier-Bold-Oblique" 
 
81
};
36
82
 
37
83
/* Output settings.  FIXME there should be commands to modify these! */
38
84
static int cxPage = 595, cyPage = 842; /* A4 -- min (451,648) */
40
86
 
41
87
/* Current document state. */
42
88
static int iPage, y, nFont, fPDF, idPages, idResources, idLength,
43
 
    aidFont[ FONT_TT + 1 ];
 
89
    aidFont[ NUM_FONTS ];
44
90
static long lStreamStart;
45
91
static font fn;
46
92
static dynarray daXRef, daPages;
68
114
    fputs( "endobj\n", pf );
69
115
}
70
116
 
71
 
static void PostScriptEscape( FILE *pf, char *pch ) {
72
 
 
 
117
static void PostScriptEscape( FILE *pf, unsigned char *pchIn ) {
 
118
 
 
119
    unsigned char *pch, *sz;
 
120
 
 
121
    pch = sz = Convert( pchIn, "ISO-8859-1", GNUBG_CHARSET );
 
122
    
73
123
    while( *pch ) {
74
124
        switch( *pch ) {
75
125
        case '\\':
83
133
            break;
84
134
        default:
85
135
            if( (unsigned char) *pch >= 0x80 )
86
 
                fprintf( pf, "\\%030o", *pch );
 
136
                fprintf( pf, "\\%03o", *pch );
87
137
            else
88
138
                putc( *pch, pf );
89
139
            break;
90
140
        }
91
141
        pch++;
92
142
    }
 
143
 
 
144
    free( sz );
93
145
}
94
146
 
95
 
static void StartPage( FILE *pf ) {
 
147
static void PSStartPage( FILE *pf ) {
96
148
 
97
149
    iPage++;
98
150
    fn = FONT_NONE;
128
180
                 ( cxPage - 451 ) / 2, ( cyPage - 648 ) / 2 );
129
181
}
130
182
 
131
 
static void EndPage( FILE *pf ) {
 
183
static void PSEndPage( FILE *pf ) {
132
184
 
133
185
    if( fPDF ) {
134
186
        long cb;
176
228
    assert( cy <= 648 );
177
229
    
178
230
    if( y < cy ) {
179
 
        EndPage( pf );
180
 
        StartPage( pf );
 
231
        PSEndPage( pf );
 
232
        PSStartPage( pf );
181
233
    }
182
234
}
183
235
 
197
249
static void Skip( FILE *pf, int cy ) {
198
250
 
199
251
    if( y < cy ) {
200
 
        EndPage( pf );
201
 
        StartPage( pf );
 
252
        PSEndPage( pf );
 
253
        PSStartPage( pf );
202
254
    } else if( y != 648 )
203
255
        Consume( pf, cy );
204
256
}
205
257
 
206
 
static void PostScriptPrologue( FILE *pf ) {
 
258
static void PostScriptPrologue( FILE *pf, int fEPS, char *szTitle ) {
207
259
 
208
260
    /* FIXME change the font-setting procedures to use ISO 8859-1
209
261
       encoding */
 
262
   
 
263
    int i;
210
264
    
211
 
    static char szPrologue[] =
212
 
        "%%%%Creator: (GNU Backgammon " VERSION ")\n"
 
265
    static char *aszPrologue[] = {
 
266
        "%%%%Creator: (" VERSION_STRING ")\n"
213
267
        "%%%%DocumentData: Clean7Bit\n"
214
268
        "%%%%DocumentNeededResources: font Courier Helvetica Times-Roman\n"
215
269
        "%%%%DocumentSuppliedResources: procset GNU-Backgammon-Prolog 1.0 0\n"
219
273
        "%%%%PageOrder: Ascend\n"
220
274
        "%%%%EndComments\n"
221
275
        "%%%%BeginDefaults\n"
222
 
        "%%%%PageResources: font Courier Helvetica Times-Roman\n"
 
276
        "%%%%PageResources: font Courier Helvetica Times-Roman\n"
223
277
        "%%%%EndDefaults\n"
224
278
        "%%%%BeginProlog\n"
225
279
        "%%%%BeginResource: procset GNU-Backgammon-Prolog 1.0 0\n"
226
 
        "\n"
227
 
        "/rm { /Times-Roman findfont exch scalefont setfont } bind def\n"
228
 
        "/sf { /Helvetica findfont exch scalefont setfont } bind def\n"
229
 
        "/tt { /Courier findfont exch scalefont setfont } bind def\n"
 
280
        "\n",
230
281
        "\n"
231
282
        "/cshow { dup stringwidth pop 2 div neg 0 rmoveto show } bind def\n"
232
283
        "\n"
309
360
        "%%%%IncludeResource: font Courier\n"
310
361
        "%%%%IncludeResource: font Helvetica\n"
311
362
        "%%%%IncludeResource: font Times-Roman\n"
312
 
        "%%%%EndSetup\n";
 
363
        "%%%%EndSetup\n" };
313
364
    time_t t;
314
365
    char *sz, *pch;
315
366
 
332
383
                 idPages = AllocateObject() );
333
384
        EndObject( pf );
334
385
 
335
 
        StartObject( pf, aidFont[ FONT_RM ] = AllocateObject() );
336
 
        fputs( "<<\n"
337
 
               "/Type /Font\n"
338
 
               "/Subtype /Type1\n"
339
 
               "/Name /rm\n"
340
 
               "/BaseFont /Times-Roman\n"
341
 
               "/Encoding /WinAnsiEncoding\n"
342
 
               ">>\n", pf );
343
 
        EndObject( pf );
344
 
        
345
 
        StartObject( pf, aidFont[ FONT_SF ] = AllocateObject() );
346
 
        fputs( "<<\n"
347
 
               "/Type /Font\n"
348
 
               "/Subtype /Type1\n"
349
 
               "/Name /sf\n"
350
 
               "/BaseFont /Helvetica\n"
351
 
               "/Encoding /WinAnsiEncoding\n"
352
 
               ">>\n", pf );
353
 
        EndObject( pf );
354
 
        
355
 
        StartObject( pf, aidFont[ FONT_TT ] = AllocateObject() );
356
 
        fputs( "<<\n"
357
 
               "/Type /Font\n"
358
 
               "/Subtype /Type1\n"
359
 
               "/Name /tt\n"
360
 
               "/BaseFont /Courier\n"
361
 
               "/Encoding /WinAnsiEncoding\n"
362
 
               ">>\n", pf );
363
 
        EndObject( pf );
 
386
        /* fonts */
 
387
 
 
388
        for ( i = 1; i < NUM_FONTS; ++i ) {
 
389
 
 
390
          StartObject ( pf, aidFont[ i ] = AllocateObject() );
 
391
 
 
392
          fprintf ( pf,
 
393
                    "<<\n"
 
394
                    "/Type /Font\n"
 
395
                    "/Subtype /Type1\n"
 
396
                    "/Name /%s\n"
 
397
                    "/BaseFont /%s\n"
 
398
                    "/Encoding /WinAnsiEncoding\n"
 
399
                    ">>\n", aszFont[ i ], aszFontName[ i ] );
 
400
          EndObject( pf );
 
401
 
 
402
        }
364
403
        
365
404
        StartObject( pf, idResources = AllocateObject() );
366
405
        fprintf( pf, "<<\n"
367
406
                 "/ProcSet [/PDF /Text]\n"
368
 
                 "/Font << /rm %d 0 R /sf %d 0 R /tt %d 0 R >>\n"
369
 
                 ">>\n", aidFont[ FONT_RM ], aidFont[ FONT_SF ],
370
 
                 aidFont[ FONT_TT ] );
 
407
                 "/Font << " );
 
408
 
 
409
        for ( i = 1; i < NUM_FONTS; ++i ) 
 
410
          fprintf ( pf, "/%s %d 0 R ", aszFont[ i ], aidFont[ i ] );
 
411
 
 
412
        fprintf ( pf, ">>\n" ">>\n" );
 
413
 
371
414
        /* FIXME list xobject resources */
372
415
        EndObject( pf );
373
416
    } else {
374
417
        fputs( "%!PS-Adobe-3.0\n", pf );
375
418
 
376
 
        fprintf( pf, "%%%%BoundingBox: %d %d %d %d\n",
377
 
                 ( cxPage - 451 ) / 2, ( cyPage - 648 ) / 2,
378
 
                 ( cxPage + 451 ) / 2, ( cyPage + 648 ) / 2 );
 
419
        if( fEPS )
 
420
            fprintf( pf, "%%%%BoundingBox: %d %d %d %d\n",
 
421
                     ( cxPage - 451 ) / 2 + 225 - 200 * nMag / 100,
 
422
                     ( cyPage + 648 ) / 2 - 260 * nMag / 100,
 
423
                     ( cxPage - 451 ) / 2 + 225 + 200 * nMag / 100,
 
424
                     ( cyPage + 648 ) / 2 );
 
425
        else
 
426
            fprintf( pf, "%%%%BoundingBox: %d %d %d %d\n",
 
427
                     ( cxPage - 451 ) / 2, ( cyPage - 648 ) / 2,
 
428
                     ( cxPage + 451 ) / 2, ( cyPage + 648 ) / 2 );
379
429
        
380
430
        time( &t );
381
431
        sz = ctime( &t );
384
434
        fprintf( pf, "%%%%CreationDate: (%s)\n", sz );
385
435
        
386
436
        fputs( "%%Title: (", pf );
387
 
        PostScriptEscape( pf, ap[ 0 ].szName );
388
 
        fputs( " vs. ", pf );
389
 
        PostScriptEscape( pf, ap[ 1 ].szName );
 
437
        PostScriptEscape( pf, szTitle );
390
438
        fputs( ")\n", pf );
 
439
 
 
440
        /* Prologue */
 
441
 
 
442
        fputs ( aszPrologue[ 0 ], pf );
 
443
 
 
444
        /* fonts */
 
445
 
 
446
        for ( i = 1; i < NUM_FONTS; ++i ) 
 
447
          fprintf ( pf, "/%s { /%s findfont exch scalefont setfont } "
 
448
                    "bind def\n", aszFont[ i ], aszFontName[ i ] );
391
449
        
392
 
        fprintf( pf, szPrologue, fClockwise ? -20 : 20,
 
450
        fprintf( pf, aszPrologue[ 1 ], fClockwise ? -20 : 20,
393
451
                 fClockwise ? 320 : 80, fClockwise ? 365 : 35 );
394
452
    }
395
453
    
396
454
    iPage = 0;
397
455
    
398
 
    StartPage( pf );
 
456
    PSStartPage( pf );
399
457
}
400
458
 
401
459
static void DrawPostScriptPoint( FILE *pf, int i, int fPlayer, int c ) {
402
460
 
403
 
    int j, x, y;
 
461
    int j, x, y = 0;
404
462
 
405
463
    if( i < 6 )
406
464
        x = 320 - 20 * i;
454
512
    }
455
513
}
456
514
 
 
515
static void
 
516
PostScriptPositionID ( FILE *pf, matchstate *pms ) {
 
517
 
 
518
  int anBoard[ 2 ][ 25 ];
 
519
 
 
520
  memcpy ( anBoard, pms->anBoard, sizeof ( anBoard ) );
 
521
 
 
522
  if ( ! pms->fMove )
 
523
    SwapSides ( anBoard );
 
524
 
 
525
  RequestFont ( pf, FONT_RM, 10 );
 
526
  fprintf( pf, fPDF ? "1 0 0 1 %d %d Tm (" : "%d %d moveto (", 
 
527
           285 - 200 * nMag / 100, y );
 
528
  fputs ( _("Position ID:"), pf );
 
529
  fputc ( ' ', pf );
 
530
  fputs( fPDF ? ") Tj\n" : ") show\n", pf );
 
531
 
 
532
  RequestFont ( pf, FONT_TT, 10 );
 
533
  fprintf( pf, fPDF ? "1 0 0 1 %d %d Tm (" : "%d %d moveto (", 
 
534
           285 - 200 * nMag / 100 + 55, y );
 
535
  fputs ( PositionID ( anBoard ), pf );
 
536
  fputs( fPDF ? ") Tj\n" : ") show\n", pf );
 
537
 
 
538
  RequestFont ( pf, FONT_RM, 10 );
 
539
  fprintf( pf, fPDF ? "1 0 0 1 %d %d Tm (" : "%d %d moveto (", 
 
540
           285 - 200 * nMag / 100 + 160, y );
 
541
  fputs ( _("Match ID:"), pf );
 
542
  fputs( fPDF ? ") Tj\n" : ") show\n", pf );
 
543
 
 
544
  RequestFont ( pf, FONT_TT, 10 );
 
545
  fprintf( pf, fPDF ? "1 0 0 1 %d %d Tm (" : "%d %d moveto (", 
 
546
           285 - 200 * nMag / 100 + 205, y );
 
547
  fputs ( MatchIDFromMatchState ( pms ), pf );
 
548
  fputs( fPDF ? ") Tj\n" : ") show\n", pf );
 
549
 
 
550
}
 
551
 
 
552
static void
 
553
PostScriptPipCounts ( FILE *pf, int anBoard[ 2 ][ 25 ], int fMove ) {
 
554
 
 
555
  int an[ 2 ][ 25 ];
 
556
  int anPips[ 2 ];
 
557
 
 
558
  memcpy ( an, anBoard, sizeof ( an ) );
 
559
 
 
560
  if ( ! fMove )
 
561
    SwapSides ( an );
 
562
 
 
563
  PipCount ( an, anPips );
 
564
 
 
565
  Advance ( pf, 10 );
 
566
  RequestFont ( pf, FONT_RM, 10 );
 
567
  fprintf( pf, fPDF ? "1 0 0 1 %d %d Tm (" : "%d %d moveto (", 
 
568
           285 - 200 * nMag / 100, y );
 
569
  fprintf ( pf, _("Pip counts: %s %d, %s %d"), 
 
570
            ap[ 0 ].szName, anPips[ 0 ], ap[ 1 ].szName, anPips[ 1 ] );
 
571
  fputs( fPDF ? ") Tj\n" : ") show\n", pf );
 
572
 
 
573
}
 
574
 
457
575
static void PrintPostScriptBoard( FILE *pf, matchstate *pms, int fPlayer ) {
458
576
 
459
577
    int yCube, theta, cos, sin, anOff[ 2 ] = { 15, 15 }, i;
 
578
    gchar buf[ G_ASCII_DTOSTR_BUF_SIZE ];
460
579
 
461
580
    if( pms->fCubeOwner < 0 ) {
462
581
        yCube = 130;
474
593
        sin = 0;
475
594
        cos = -1;
476
595
    }
477
 
    
 
596
 
478
597
    Advance( pf, 260 * nMag / 100 );
479
598
    ReleaseFont( pf );
480
599
    
481
600
    if( fPDF ) {
482
601
        /* FIXME most of the following could be encapsulated into a PDF
483
602
           XObject to optimise the output file */
484
 
        fprintf( pf, "q 1 0 0 1 %d %d cm %.2f 0 0 %.2f 0 0 cm 0.5 g\n",
485
 
                 225 - 200 * nMag / 100, y, nMag / 100.0, nMag / 100.0 );
 
603
        fprintf( pf, "q 1 0 0 1 %d %d cm %s 0 0 %s 0 0 cm 0.5 g\n",
 
604
                 225 - 200 * nMag / 100, y, 
 
605
                   g_ascii_formatd(buf, G_ASCII_DTOSTR_BUF_SIZE, "%.2f", nMag / 100.0),
 
606
                   g_ascii_formatd(buf, G_ASCII_DTOSTR_BUF_SIZE, "%.2f", nMag / 100.0));
486
607
        fputs( "60 10 280 240 re S\n", pf );
487
608
        for( i = 0; i < 6; i++ ) {
488
609
            fprintf( pf, "%d %d m %d %d l %d %d l %c\n",
518
639
                 pms->nCube == 1 ? 64 : pms->nCube );
519
640
    } else
520
641
        fprintf( pf, "gsave\n"
521
 
                 "%d %d translate %.2f %.2f scale\n"
522
 
                 "0 0 moveto %s board\n"
523
 
                 "%d %d %d cube\n", 225 - 200 * nMag / 100, y,
524
 
                 nMag / 100.0, nMag / 100.0, fPlayer ? "true" : "false",
525
 
                 pms->nCube == 1 ? 64 : pms->nCube, yCube, theta );
 
642
                   "%d %d translate %s %s scale\n"
 
643
                   "0 0 moveto %s board\n"
 
644
                   "%d %d %d cube\n", 225 - 200 * nMag / 100, y,
 
645
                   g_ascii_formatd(buf, G_ASCII_DTOSTR_BUF_SIZE, "%.2f", nMag / 100.0),
 
646
                   g_ascii_formatd(buf, G_ASCII_DTOSTR_BUF_SIZE, "%.2f", nMag / 100.0),
 
647
                   fPlayer ? "true" : "false",
 
648
                   pms->nCube == 1 ? 64 : pms->nCube, yCube, theta );
526
649
 
527
650
    for( i = 0; i < 25; i++ ) {
528
651
        anOff[ 0 ] -= pms->anBoard[ 0 ][ i ];
539
662
        fputs( "Q\n", pf );
540
663
    else
541
664
        fputs( "grestore\n", pf );
 
665
 
 
666
    /* FIXME: write position ID, match ID, and pip counts */
 
667
 
 
668
    PostScriptPositionID ( pf, pms );
 
669
    PostScriptPipCounts ( pf, pms->anBoard, pms->fMove );
 
670
 
542
671
}
543
672
 
544
673
static short acxTimesRoman[ 256 ] = {
604
733
 
605
734
/* Typeset a line of text.  We're not TeX, so we don't do any kerning,
606
735
   hyphenation or justification.  Word wrapping will have to do. */
607
 
static void PrintPostScriptComment( FILE *pf, unsigned char *pch ) {
 
736
 
 
737
static void PrintPostScriptLineWithSkip( FILE *pf, unsigned char *pch, 
 
738
                                         const int nSkip,
 
739
                                         font fn, int nSize ) {
608
740
 
609
741
    int x;
610
 
    unsigned char *pchStart, *pchBreak;
 
742
    unsigned char *sz, *pchStart, *pchBreak;
611
743
    
612
744
    if( !pch || !*pch )
613
745
        return;
614
746
 
615
 
    Skip( pf, 6 );
 
747
    pch = sz = Convert( pch, "ISO-8859-1", GNUBG_CHARSET );
 
748
    
 
749
    if ( nSkip )
 
750
      Skip( pf, nSkip );
616
751
 
617
752
    while( *pch ) {
618
753
        Advance( pf, 10 );
620
755
        pchBreak = NULL;
621
756
        pchStart = pch;
622
757
        
623
 
        for( x = 0; x < 451 * 1000 / 10; x += acxTimesRoman[ *pch++ ] )
 
758
        for( x = 0; x < 451 * 1000 / nSize; x += acxTimesRoman[ *pch++ ] )
624
759
            if( !*pch ) {
625
760
                /* finished; break here */
626
761
                pchBreak = pch;
636
771
        if( !pchBreak )
637
772
            pchBreak = ( pch == pchStart ) ? pch : pch - 1;
638
773
 
639
 
        RequestFont( pf, FONT_RM, 10 );
 
774
        RequestFont( pf, fn, nSize );
640
775
 
641
776
        fprintf( pf, fPDF ? "1 0 0 1 0 %d Tm (" : "0 %d moveto (", y );
642
777
        
651
786
                putc( '\\', pf );
652
787
                /* fall through */
653
788
            default:
654
 
                putc( *pchStart, pf );
 
789
                if( (unsigned char) *pchStart >= 0x80 )
 
790
                    fprintf( pf, "\\%03o", *pchStart );
 
791
                else
 
792
                    putc( *pchStart, pf );
655
793
            }
656
794
        fputs( fPDF ? ") Tj\n" : ") show\n", pf );
657
795
 
660
798
        
661
799
        pch = pchBreak + 1;
662
800
    }
663
 
}
664
 
 
665
 
static void PrintPostScriptCubeAnalysis( FILE *pf, matchstate *pms,
666
 
                                         int fPlayer, float arDouble[ 4 ],
667
 
                                         evalsetup *pes ) { 
 
801
 
 
802
    free( sz );
 
803
}
 
804
 
 
805
static void
 
806
PrintPostScriptLine ( FILE *pf, unsigned char *pch ) {
 
807
 
 
808
  PrintPostScriptLineWithSkip ( pf, pch, 0, FONT_RM, 10 );
 
809
 
 
810
}
 
811
 
 
812
static void
 
813
PrintPostScriptLineFont ( FILE *pf, unsigned char *pch, 
 
814
                          font fn, int nSize ) {
 
815
 
 
816
  PrintPostScriptLineWithSkip ( pf, pch, 0, fn, nSize );
 
817
 
 
818
}
 
819
 
 
820
 
 
821
 
 
822
static void
 
823
PrintPostScriptComment ( FILE *pf, unsigned char *pch ) {
 
824
 
 
825
  PrintPostScriptLineWithSkip ( pf, pch, 6, FONT_RM, 10 );
 
826
 
 
827
}
 
828
 
 
829
 
 
830
 
 
831
static void 
 
832
PrintPostScriptCubeAnalysis( FILE *pf, const matchstate *pms,
 
833
                             int const fPlayer, 
 
834
                             const float aarOutput[2][ NUM_ROLLOUT_OUTPUTS ], 
 
835
                             const float aarStdDev[2][ NUM_ROLLOUT_OUTPUTS ], 
 
836
                             const evalsetup* pes ) { 
668
837
    cubeinfo ci;
669
 
    char sz[ 1024 ], *pch, *pchNext;
 
838
    char *sz, *pch, *pchNext;
670
839
 
671
840
    if( pes->et == EVAL_NONE )
672
841
        return;
673
842
    
674
843
    SetCubeInfo( &ci, pms->nCube, pms->fCubeOwner, fPlayer, pms->nMatchTo,
675
 
                 pms->anScore, pms->fCrawford, fJacoby, nBeavers );
676
 
    
677
 
    if( !GetDPEq( NULL, NULL, &ci ) )
678
 
        /* No cube action possible */
679
 
        return;
680
 
    
681
 
    GetCubeActionSz( arDouble, sz, &ci, fOutputMWC, FALSE );
 
844
                 pms->anScore, pms->fCrawford, pms->fJacoby, nBeavers,
 
845
                 pms->bgv );
 
846
    
 
847
    sz = OutputCubeAnalysis( aarOutput, aarStdDev, pes, &ci );
682
848
 
683
849
    Skip( pf, 4 );
684
850
    for( pch = sz; pch && *pch; pch = pchNext ) {
712
878
                 fPlayer ? "fill" : "stroke" );
713
879
}
714
880
 
 
881
 
 
882
static void
 
883
PostScriptMatchInfo ( FILE *pf, matchinfo *pmi ) {
 
884
 
 
885
  char sz[ 1000 ];
 
886
  char szx[ 1000 ];
 
887
  int i;
 
888
  struct tm tmx;
 
889
  
 
890
  Ensure ( pf, 100 );
 
891
  Advance ( pf, 14 );
 
892
  PrintPostScriptLineFont ( pf, _("Match Information" ), FONT_RM_BOLD, 14 );
 
893
  Advance ( pf, 6 );
 
894
 
 
895
  /* ratings */
 
896
 
 
897
  RequestFont ( pf, FONT_RM, 10 );
 
898
  for ( i = 0; i < 2; ++i ) {
 
899
    sprintf ( sz, _("%s's rating: %s"),
 
900
              ap[ i ].szName,
 
901
              pmi->pchRating[ i ] ? pmi->pchRating[ i ] : _("n/a") );
 
902
    PrintPostScriptLine ( pf, sz );
 
903
  }
 
904
 
 
905
  /* date */
 
906
 
 
907
  if ( pmi->nYear ) {
 
908
 
 
909
    tmx.tm_year = pmi->nYear - 1900;
 
910
    tmx.tm_mon = pmi->nMonth - 1;
 
911
    tmx.tm_mday = pmi->nDay;
 
912
    strftime ( szx, sizeof ( szx ), _("%B %d, %Y"), &tmx );
 
913
    sprintf ( sz, _("Date: %s"), szx ); 
 
914
    PrintPostScriptLine ( pf, sz );
 
915
  }
 
916
  else 
 
917
    PrintPostScriptLine ( pf, _("Date: n/a") );
 
918
 
 
919
  /* event, round, place and annotator */
 
920
 
 
921
  sprintf( sz, _("Event: %s"),
 
922
           pmi->pchEvent ? pmi->pchEvent : _("n/a") );
 
923
  PrintPostScriptLine ( pf, sz );
 
924
 
 
925
  sprintf( sz, _("Round: %s"),
 
926
           pmi->pchRound ? pmi->pchRound : _("n/a") );
 
927
  PrintPostScriptLine ( pf, sz );
 
928
 
 
929
  sprintf( sz, _("Place: %s"),
 
930
           pmi->pchPlace ? pmi->pchPlace : _("n/a") );
 
931
  PrintPostScriptLine ( pf, sz );
 
932
 
 
933
  sprintf( sz, _("Annotator: %s"),
 
934
           pmi->pchAnnotator ? pmi->pchAnnotator : _("n/a") );
 
935
  PrintPostScriptLine ( pf, sz );
 
936
 
 
937
  sprintf( sz, _("Comments: %s"),
 
938
           pmi->pchComment ? pmi->pchComment : _("n/a") );
 
939
  PrintPostScriptLine ( pf, sz );
 
940
    
 
941
  ReleaseFont ( pf );
 
942
 
 
943
}
 
944
 
 
945
static void
 
946
PostScriptBoardHeader ( FILE *pf, matchstate *pms, const int iMove ) {
 
947
 
 
948
  /* move number */
 
949
 
 
950
  Advance ( pf, 20 );
 
951
  RequestFont ( pf, FONT_RM_BOLD, 10 );
 
952
  fprintf( pf, fPDF ? "1 0 0 1 0 %d Tm (" : "0 %d moveto (", y );
 
953
  fprintf ( pf,_("Move number %d:"), iMove + 1 );
 
954
  fputs( fPDF ? ") Tj\n" : ") show\n", pf );
 
955
 
 
956
  RequestFont ( pf, FONT_RM, 10 );
 
957
  fprintf( pf, fPDF ? "1 0 0 1 100 %d Tm (" : "100 %d moveto (", y );
 
958
 
 
959
  if ( pms->fResigned ) 
 
960
    
 
961
    /* resignation */
 
962
 
 
963
    fprintf ( pf,
 
964
              _("%s resigns %d points"), 
 
965
              ap[ pms->fTurn ].szName,
 
966
              pms->fResigned * pms->nCube
 
967
            );
 
968
  
 
969
  else if ( pms->anDice[ 0 ] && pms->anDice[ 1 ] )
 
970
 
 
971
    /* chequer play decision */
 
972
 
 
973
    fprintf ( pf,
 
974
              _("%s to play %d%d"),
 
975
              ap[ pms->fTurn ].szName,
 
976
              pms->anDice[ 0 ], pms->anDice[ 1 ] 
 
977
            );
 
978
 
 
979
  else if ( pms->fDoubled )
 
980
 
 
981
    /* take decision */
 
982
 
 
983
    fprintf ( pf,
 
984
              _("%s doubles to %d"),
 
985
              ap[ pms->fMove ].szName,
 
986
              pms->nCube * 2
 
987
            );
 
988
 
 
989
  else
 
990
 
 
991
    /* cube decision */
 
992
 
 
993
    fprintf ( pf,
 
994
              _("%s on roll, cube decision?"),
 
995
              ap[ pms->fTurn ].szName
 
996
            );
 
997
 
 
998
  fputs( fPDF ? ") Tj\n" : ") show\n", pf );
 
999
  
 
1000
 
 
1001
}
 
1002
 
715
1003
static void ExportGamePostScript( FILE *pf, list *plGame ) {
716
1004
 
717
1005
    list *pl;
719
1007
    matchstate msExport;
720
1008
    int fTook = FALSE, i, cx;
721
1009
    char sz[ 1024 ], *pch;
 
1010
    int iMove = 0;
 
1011
 
 
1012
    updateStatisticsGame ( plGame );
722
1013
 
723
1014
    for( pl = plGame->plNext; pl != plGame; pl = pl->plNext ) {
724
1015
        pmr = pl->p;
 
1016
        FixMatchState ( &msExport, pmr );
725
1017
        switch( pmr->mt ) {
726
1018
        case MOVE_GAMEINFO:
727
 
            /* FIXME game introduction */
 
1019
 
 
1020
            ApplyMoveRecord ( &msExport, plGame, pmr );
 
1021
          
 
1022
            Ensure( pf, 26 );
 
1023
            Consume( pf, 14 );
 
1024
            RequestFont( pf, FONT_RM, 14 );
 
1025
            if( pmr->g.nMatch )
 
1026
                sprintf( sz, _("%d point match (game %d)"), pmr->g.nMatch,
 
1027
                         pmr->g.i + 1 );
 
1028
            else
 
1029
                sprintf( sz, _("Money session (game %d)"), pmr->g.i + 1 );
 
1030
            
 
1031
            fprintf( pf, fPDF ? "1 0 0 1 0 %d Tm (%s) Tj\n" :
 
1032
                     "0 %d moveto (%s) show\n", y, sz );
 
1033
 
 
1034
            Consume( pf, 12 );
 
1035
            PlayerSymbol( pf, 8, 0 );
 
1036
            RequestFont( pf, FONT_RM, 12 );
 
1037
            fprintf( pf, fPDF ? "1 0 0 1 16 %d Tm (" : "16 %d moveto (",
 
1038
                     y );
 
1039
            PostScriptEscape( pf, ap[ 0 ].szName );
 
1040
            fprintf( pf, _(" (%d points)"), pmr->g.anScore[ 0 ] );
 
1041
            fputs( fPDF ? ") Tj\n" : ") show\n", pf );
 
1042
            
 
1043
            PlayerSymbol( pf, 225, 1 );
 
1044
            RequestFont( pf, FONT_RM, 12 );
 
1045
            fprintf( pf, fPDF ? "1 0 0 1 233 %d Tm (" : "233 %d moveto (",
 
1046
                     y );
 
1047
            PostScriptEscape( pf, ap[ 1 ].szName );
 
1048
            fprintf( pf, _(" (%d points)"), pmr->g.anScore[ 1 ] );
 
1049
            fputs( fPDF ? ") Tj\n" : ") show\n", pf );
 
1050
 
 
1051
            /* match information */
 
1052
 
 
1053
            if ( exsExport.fIncludeMatchInfo )
 
1054
              PostScriptMatchInfo ( pf, &mi );
 
1055
            
728
1056
            break;
729
1057
            
730
1058
        case MOVE_NORMAL:
 
1059
 
 
1060
            msExport.fTurn = msExport.fMove = pmr->fPlayer;
 
1061
            msExport.anDice[ 0 ] = pmr->anDice[ 0 ];
 
1062
            msExport.anDice[ 1 ] = pmr->anDice[ 1 ];
 
1063
 
731
1064
            if( fTook )
732
1065
                /* no need to print board following a double/take */
733
1066
                fTook = FALSE;
734
1067
            else {
735
 
                Ensure( pf, 260 * nMag / 100 + 10 );
736
 
                PrintPostScriptBoard( pf, &msExport, pmr->n.fPlayer );
 
1068
                Ensure( pf, 260 * nMag / 100 + 30 );
 
1069
                PostScriptBoardHeader ( pf, &msExport, iMove );
 
1070
                PrintPostScriptBoard( pf, &msExport, pmr->fPlayer );
737
1071
            }
738
1072
            
739
 
            PrintPostScriptCubeAnalysis( pf, &msExport, pmr->n.fPlayer,
740
 
                                         pmr->n.arDouble, &pmr->n.esDouble );
 
1073
            PrintPostScriptCubeAnalysis( pf, &msExport, pmr->fPlayer,
 
1074
                                         GCCCONSTAHACK pmr->CubeDecPtr->aarOutput,
 
1075
                                         GCCCONSTAHACK pmr->CubeDecPtr->aarStdDev, 
 
1076
                                         &pmr->CubeDecPtr->esDouble );
741
1077
            
742
1078
            Advance( pf, 10 );
743
1079
            FormatMove( sz, msExport.anBoard, pmr->n.anMove );
744
1080
            RequestFont( pf, FONT_RM, 10 );
745
1081
            cx = 15 /* 2 digits + colon + space */ +
746
 
                StringWidth( aszLuckTypeAbbr[ pmr->n.lt ] ) +
747
 
                StringWidth( aszSkillTypeAbbr[ pmr->n.st ] ) +
 
1082
                StringWidth( aszLuckTypeAbbr[ pmr->lt ] ) +
 
1083
                StringWidth( aszSkillTypeAbbr[ pmr->n.stMove ] ) +
748
1084
                StringWidth( sz );
749
1085
            fprintf( pf, fPDF ? "1 0 0 1 %d %d Tm (%d%d%s: %s%s) Tj\n" :
750
1086
                     "%d %d moveto (%d%d%s: %s%s) show\n",
751
1087
                     225 - cx / 2 + 6, y,
752
 
                     pmr->n.anRoll[ 0 ], pmr->n.anRoll[ 1 ],
753
 
                     aszLuckTypeAbbr[ pmr->n.lt ], sz,
754
 
                     aszSkillTypeAbbr[ pmr->n.st ] );
755
 
            PlayerSymbol( pf, 225 - cx / 2 - 2, pmr->n.fPlayer );
 
1088
                     pmr->anDice[ 0 ], pmr->anDice[ 1 ],
 
1089
                     aszLuckTypeAbbr[ pmr->lt ], sz,
 
1090
                     aszSkillTypeAbbr[ pmr->n.stMove ] );
 
1091
            PlayerSymbol( pf, 225 - cx / 2 - 2, pmr->fPlayer );
 
1092
            /* FIXME: output cube skill as well */
756
1093
 
757
 
            if( pmr->n.ml.cMoves ) {
 
1094
            if( pmr->ml.cMoves ) {
758
1095
                Skip( pf, 4 );
759
 
                for( i = 0; i < pmr->n.ml.cMoves && i <= pmr->n.iMove; i++ ) {
 
1096
                for( i = 0; i < pmr->ml.cMoves && i <= pmr->n.iMove; i++ ) {
760
1097
                    if( i >= 5 /* FIXME allow user to choose limit */ &&
761
1098
                        i != pmr->n.iMove )
762
1099
                        continue;
767
1104
                    fprintf( pf, fPDF ? "1 0 0 1 46 %d Tm (" :
768
1105
                             "46 %d moveto (", y );
769
1106
                    putc( i == pmr->n.iMove ? '*' : ' ', pf );
770
 
                    FormatMoveHint( sz, msExport.anBoard, &pmr->n.ml, i,
 
1107
                    FormatMoveHint( sz, &msExport, &pmr->ml, i,
771
1108
                                    i != pmr->n.iMove ||
772
 
                                    i != pmr->n.ml.cMoves - 1 );
 
1109
                                    i != pmr->ml.cMoves - 1, TRUE, TRUE );
773
1110
                    pch = strchr( sz, '\n' );
774
1111
                    *pch++ = 0;
775
1112
                    fputs( sz, pf );
785
1122
                }
786
1123
            }
787
1124
 
788
 
            PrintPostScriptComment( pf, pmr->a.sz );
 
1125
            PrintPostScriptComment( pf, pmr->sz );
789
1126
 
790
1127
            Skip( pf, 6 );
 
1128
 
 
1129
            ++iMove;
791
1130
            
792
1131
            break;
793
1132
            
794
1133
        case MOVE_DOUBLE:           
795
1134
            Ensure( pf, 260 * nMag / 100 );
796
 
            PrintPostScriptBoard( pf, &msExport, pmr->d.fPlayer );
 
1135
            PrintPostScriptBoard( pf, &msExport, pmr->fPlayer );
797
1136
 
798
 
            PrintPostScriptCubeAnalysis( pf, &msExport, pmr->d.fPlayer,
799
 
                                         pmr->d.arDouble, &pmr->d.esDouble );
 
1137
            PrintPostScriptCubeAnalysis( pf, &msExport, pmr->fPlayer,
 
1138
                                         GCCCONSTAHACK pmr->CubeDecPtr->aarOutput, 
 
1139
                                         GCCCONSTAHACK pmr->CubeDecPtr->aarStdDev, 
 
1140
                                         &pmr->CubeDecPtr->esDouble );
800
1141
 
801
1142
            Advance( pf, 10 );
802
1143
            RequestFont( pf, FONT_RM, 10 );
803
1144
            /* (Double) stringwidth = 29.439 */
804
 
            cx = StringWidth( aszSkillTypeAbbr[ pmr->d.st ] ) + 29;
805
 
            fprintf( pf, fPDF ? "1 0 0 1 %d %d Tm (Double%s) Tj\n" :
806
 
                     "%d %d moveto (Double%s) show\n", 225 - cx / 2 + 6, y,
807
 
                     aszSkillTypeAbbr[ pmr->d.st ] );
 
1145
            cx = StringWidth( aszSkillTypeAbbr[ pmr->stCube ] ) + 29;
 
1146
            fprintf( pf, fPDF ? "1 0 0 1 %d %d Tm (%s%s) Tj\n" :
 
1147
                     "%d %d moveto (%s%s) show\n", 225 - cx / 2 + 6, y,
 
1148
                     _("Double"),
 
1149
                     aszSkillTypeAbbr[ pmr->stCube ] );
808
1150
            
809
 
            PlayerSymbol( pf, 225 - cx / 2 - 2, pmr->n.fPlayer );
 
1151
            PlayerSymbol( pf, 225 - cx / 2 - 2, pmr->fPlayer );
810
1152
 
811
 
            PrintPostScriptComment( pf, pmr->a.sz );
 
1153
            PrintPostScriptComment( pf, pmr->sz );
812
1154
 
813
1155
            Skip( pf, 6 );
 
1156
 
 
1157
            ++iMove;
814
1158
            
815
1159
            break;
816
1160
            
820
1164
            Advance( pf, 10 );
821
1165
            RequestFont( pf, FONT_RM, 10 );
822
1166
            /* (Take) stringwidth = 19.9892 */
823
 
            cx = StringWidth( aszSkillTypeAbbr[ pmr->d.st ] ) + 20;
824
 
            fprintf( pf, fPDF ? "1 0 0 1 %d %d Tm (Take%s) Tj\n" :
825
 
                     "%d %d moveto (Take%s) show\n", 225 - cx / 2 + 6, y,
826
 
                     aszSkillTypeAbbr[ pmr->d.st ] );
 
1167
            cx = StringWidth( aszSkillTypeAbbr[ pmr->stCube ] ) + 20;
 
1168
            fprintf( pf, fPDF ? "1 0 0 1 %d %d Tm (%s%s) Tj\n" :
 
1169
                     "%d %d moveto (%s%s) show\n", 225 - cx / 2 + 6, y,
 
1170
                     _("Take"),
 
1171
                     aszSkillTypeAbbr[ pmr->stCube ] );
827
1172
            
828
 
            PlayerSymbol( pf, 225 - cx / 2 - 2, pmr->n.fPlayer );
 
1173
            PlayerSymbol( pf, 225 - cx / 2 - 2, pmr->fPlayer );
829
1174
 
830
 
            PrintPostScriptComment( pf, pmr->a.sz );
 
1175
            PrintPostScriptComment( pf, pmr->sz );
831
1176
 
832
1177
            Skip( pf, 6 );
 
1178
 
 
1179
            ++iMove;
833
1180
            
834
1181
            break;
835
1182
            
837
1184
            Advance( pf, 10 );
838
1185
            RequestFont( pf, FONT_RM, 10 );
839
1186
            /* (Drop) stringwidth = 20.5494 */
840
 
            cx = StringWidth( aszSkillTypeAbbr[ pmr->d.st ] ) + 20;
841
 
            fprintf( pf, fPDF ? "1 0 0 1 %d %d Tm (Drop%s) Tj\n" :
842
 
                     "%d %d moveto (Drop%s) show\n", 225 - cx / 2 + 6, y,
843
 
                     aszSkillTypeAbbr[ pmr->d.st ] );
844
 
            
845
 
            PlayerSymbol( pf, 225 - cx / 2 - 2, pmr->n.fPlayer );
846
 
            
847
 
            PrintPostScriptComment( pf, pmr->a.sz );
 
1187
            cx = StringWidth( aszSkillTypeAbbr[ pmr->stCube ] ) + 20;
 
1188
            fprintf( pf, fPDF ? "1 0 0 1 %d %d Tm (%s%s) Tj\n" :
 
1189
                     "%d %d moveto (%s%s) show\n", 225 - cx / 2 + 6, y,
 
1190
                     _("Drop"),
 
1191
                     aszSkillTypeAbbr[ pmr->stCube ] );
 
1192
            
 
1193
            PlayerSymbol( pf, 225 - cx / 2 - 2, pmr->fPlayer );
 
1194
            
 
1195
            PrintPostScriptComment( pf, pmr->sz );
848
1196
 
849
1197
            Skip( pf, 6 );
850
1198
 
 
1199
            ++iMove;
 
1200
 
851
1201
            break;
852
1202
            
853
1203
        case MOVE_RESIGN:
854
1204
            Advance( pf, 10 );
855
1205
            RequestFont( pf, FONT_RM, 10 );
856
1206
            /* (Resigns ) stringwidth = 34.1685 */
857
 
            cx = StringWidth( aszGameResult[ pmr->r.nResigned - 1 ] ) + 34;
858
 
            fprintf( pf, fPDF ? "1 0 0 1 %d %d Tm (Resigns %s) Tj\n" :
859
 
                     "%d %d moveto (Resigns %s) show\n", 225 - cx / 2 + 6, y,
860
 
                     aszGameResult[ pmr->r.nResigned - 1 ] );
 
1207
            cx = StringWidth( gettext ( aszGameResult[ pmr->r.nResigned - 1 ]  ) ) + 34;
 
1208
            fprintf( pf, fPDF ? "1 0 0 1 %d %d Tm (%s %s) Tj\n" :
 
1209
                     "%d %d moveto (%s %s) show\n", 225 - cx / 2 + 6, y,
 
1210
                     _("Resigns"),
 
1211
                     gettext ( aszGameResult[ pmr->r.nResigned - 1 ] ) );
861
1212
            
862
 
            PlayerSymbol( pf, 225 - cx / 2 - 2, pmr->n.fPlayer );
 
1213
            PlayerSymbol( pf, 225 - cx / 2 - 2, pmr->fPlayer );
863
1214
            
864
1215
            /* FIXME print resignation analysis, if available */
865
1216
            
866
 
            PrintPostScriptComment( pf, pmr->a.sz );
 
1217
            PrintPostScriptComment( pf, pmr->sz );
867
1218
 
868
1219
            Skip( pf, 6 );
869
1220
 
 
1221
            ++iMove;
 
1222
 
870
1223
            break;
871
1224
                    
872
1225
        case MOVE_SETDICE:
873
1226
            /* ignore */
874
1227
            break;
875
1228
            
 
1229
        case MOVE_TIME:
 
1230
                /* ignore */
 
1231
                break;
 
1232
 
876
1233
        case MOVE_SETBOARD:
877
1234
        case MOVE_SETCUBEVAL:
878
1235
        case MOVE_SETCUBEPOS:
880
1237
            break;
881
1238
        }
882
1239
 
883
 
        ApplyMoveRecord( &msExport, pmr );
 
1240
        ApplyMoveRecord( &msExport, plGame, pmr );
884
1241
    }
885
1242
    
886
 
    if( ( GameStatus( msExport.anBoard ) ) )
887
 
        /* FIXME print game result */
 
1243
    if( ( GameStatus( msExport.anBoard, msExport.bgv ) ) )
 
1244
        /* FIXME print game result and statistics */
888
1245
        ;
889
1246
    
890
1247
}
894
1251
    int i;
895
1252
    long lXRef;
896
1253
    
897
 
    EndPage( pf );
 
1254
    PSEndPage( pf );
898
1255
 
899
1256
    if( fPDF ) {
900
1257
        StartObject( pf, idPages );
936
1293
static void ExportGameGeneral( int f, char *sz ) {
937
1294
 
938
1295
    FILE *pf;
 
1296
    char szTitle[ 128 ];
939
1297
 
940
1298
    sz = NextToken( &sz );
941
1299
    
942
1300
    if( !plGame ) {
943
 
        outputl( "No game in progress (type `new game' to start one)." );
 
1301
        outputl( _("No game in progress (type `new game' to start one).") );
944
1302
        return;
945
1303
    }
946
1304
    
947
1305
    if( !sz || !*sz ) {
948
 
        outputl( "You must specify a file to export to (see `help export"
949
 
                 "game postscript')." ); /* FIXME not necessarily PS */
 
1306
        outputf( _("You must specify a file to export to (see `help export "
 
1307
                 "game %s').\n"), f ? "pdf" : "postscript" );
950
1308
        return;
951
1309
    }
952
1310
 
 
1311
    if ( ! confirmOverwrite ( sz, fConfirmSave ) )
 
1312
      return;
 
1313
 
953
1314
    if( !strcmp( sz, "-" ) ) {
954
1315
        if( f ) {
955
 
            outputl( "PDF files may not be written to standard output ("
956
 
                     "see `help export game pdf')." );
 
1316
            outputl( _("PDF files may not be written to standard output ("
 
1317
                     "see `help export game pdf').") );
957
1318
            return;
958
1319
        }
959
1320
        
960
1321
        pf = stdout;
961
1322
    } else if( !( pf = fopen( sz, f ? "wb" : "w" ) ) ) {
962
 
        perror( sz );
 
1323
        outputerr( sz );
963
1324
        return;
964
1325
    }
965
1326
 
966
1327
    fPDF = f;
967
 
    PostScriptPrologue( pf );
 
1328
    sprintf( szTitle, "%s vs. %s", ap[ 0 ].szName, ap[ 1 ].szName );
 
1329
    PostScriptPrologue( pf, FALSE, szTitle );
968
1330
    
969
1331
    ExportGamePostScript( pf, plGame );
970
1332
 
972
1334
    
973
1335
    if( pf != stdout )
974
1336
        fclose( pf );
 
1337
 
 
1338
    setDefaultFileName ( sz, f ? PATH_PDF : PATH_POSTSCRIPT );
 
1339
 
975
1340
}
976
1341
 
977
1342
extern void CommandExportGamePDF( char *sz ) {
988
1353
    
989
1354
    FILE *pf;
990
1355
    list *pl;
991
 
 
 
1356
    char szTitle[ 128 ];
 
1357
    
992
1358
    sz = NextToken( &sz );
993
1359
    
994
1360
    if( !plGame ) {
997
1363
    }
998
1364
    
999
1365
    if( !sz || !*sz ) {
1000
 
        outputf( "You must specify a file to export to (see `help export "
1001
 
                 "match %s\n').", f ? "pdf" : "postscript" );
 
1366
        outputf( _("You must specify a file to export to (see `help export "
 
1367
                 "match %s').\n"), f ? "pdf" : "postscript" );
1002
1368
        return;
1003
1369
    }
1004
1370
 
 
1371
    if ( ! confirmOverwrite ( sz, fConfirmSave ) )
 
1372
      return;
 
1373
 
1005
1374
    if( !strcmp( sz, "-" ) ) {
1006
1375
        if( f ) {
1007
 
            outputl( "PDF files may not be written to standard output ("
1008
 
                     "see `help export match pdf')." );
 
1376
            outputl( _("PDF files may not be written to standard output ("
 
1377
                     "see `help export match pdf').") );
1009
1378
            return;
1010
1379
        }
1011
1380
        
1012
1381
        pf = stdout;
1013
1382
    } else if( !( pf = fopen( sz, f ? "wb" : "w" ) ) ) {
1014
 
        perror( sz );
 
1383
        outputerr( sz );
1015
1384
        return;
1016
1385
    }
1017
1386
 
1018
1387
    fPDF = f;
1019
 
    PostScriptPrologue( pf );
 
1388
    sprintf( szTitle, "%s vs. %s", ap[ 0 ].szName, ap[ 1 ].szName );
 
1389
    PostScriptPrologue( pf, FALSE, szTitle );
1020
1390
 
1021
1391
    /* FIXME write match introduction? */
1022
1392
    
1027
1397
    
1028
1398
    if( pf != stdout )
1029
1399
        fclose( pf );
 
1400
 
 
1401
    setDefaultFileName ( sz, f ? PATH_PDF : PATH_POSTSCRIPT );
 
1402
 
1030
1403
}
1031
1404
 
1032
1405
extern void CommandExportMatchPDF( char *sz ) {
1038
1411
 
1039
1412
    ExportMatchGeneral( FALSE, sz );
1040
1413
}
 
1414
 
 
1415
extern void CommandExportPositionEPS( char *sz ) {
 
1416
 
 
1417
    FILE *pf;
 
1418
    char szTitle[ 32 ];
 
1419
        
 
1420
    sz = NextToken( &sz );
 
1421
    
 
1422
    if( ms.gs == GAME_NONE ) {
 
1423
        outputl( _("No game in progress (type `new game' to start one).") );
 
1424
        return;
 
1425
    }
 
1426
    
 
1427
    if( !sz || !*sz ) {
 
1428
        outputl( _("You must specify a file to export to (see `help export "
 
1429
                 "position eps').") );
 
1430
        return;
 
1431
    }
 
1432
 
 
1433
    if ( ! confirmOverwrite ( sz, fConfirmSave ) )
 
1434
      return;
 
1435
 
 
1436
    if( !strcmp( sz, "-" ) )
 
1437
        pf = stdout;
 
1438
    else if( !( pf = fopen( sz, "w" ) ) ) {
 
1439
        outputerr( sz );
 
1440
        return;
 
1441
    }
 
1442
 
 
1443
    fPDF = FALSE;
 
1444
    sprintf( szTitle, _("Position %s"), PositionID( ms.anBoard ) );
 
1445
    PostScriptPrologue( pf, TRUE, szTitle );
 
1446
 
 
1447
    PrintPostScriptBoard( pf, &ms, ms.fTurn );
 
1448
    
 
1449
    PostScriptEpilogue( pf );
 
1450
 
 
1451
    if( pf != stdout )
 
1452
        fclose( pf );
 
1453
 
 
1454
    setDefaultFileName ( sz, PATH_EPS );
 
1455
 
 
1456
}