forked from freesewing/tile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtile.c
executable file
·1292 lines (1168 loc) · 46.9 KB
/
tile.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
# tile - resize a postscript image to print on larger media and/or multiple sheets
#
# This program scales a PostScript page to a given size (a poster).
# The output can be tiled on multiple sheets, and output
# media size can be chosen independently.
# Each tile (sheet) of a will bear cropmarks and slightly overlapping
# image for easier poster assembly.
# In principle it requires the input file to adhere to 'eps'
# (encapsulated postscript) conventions but it will work for many
# 'normal' postscript files as well.
#
# Compile this program with:
# cc -O -o tile tile.c -lm
# or something alike.
#
# Maybe you want to change the `DefaultMedia' and `DefaultImage'
# settings in the few lines below, to reflect your local situation.
# Names can to be chosen from the `mediatable' further down.
#
# The `Gv_gs_orientbug 1' disables a feature of this program to
# ask for landscape previewing of rotated images.
# Our currently installed combination of ghostview 1.5 with ghostscript 3.33
# cannot properly do a landscape viewing of the `poster' output.
# The problem does not exist in combination with an older ghostscript 2.x,
# and has the attention of the ghostview authors.
# (The problem is in the evaluation of the `setpagedevice' call.)
# If you have a different previewing environment,
# you might want to set `Gv_gs_orientbug 0'
#
# Tile now adds a coverpage, and takes the t and h options.
# I (joost) have yet to make this optional, and update the man page.
#
# Tile has now support for language files
# (tile.<2 letter language code>.yml, "tile.en.yml")
#
# --------------------------------------------------------------
# Tile is a fork of 'poster' by Jos T.J. van Eijndhoven
#
# Forked by Joost De Cock for freesewing.org
# Language extention by Wouter van Wageningen
#
# Copyright (C) 1999 Jos T.J. van Eijndhoven
# Copyright (C) 2017 Joost De Cock
# --------------------------------------------------------------
*/
#define Gv_gs_orientbug 1
#define DefaultMedia "A4"
#define DefaultImage "A4"
#define DefaultCutMargin "5%"
#define DefaultWhiteMargin "0"
#define BUFSIZE 1024
#define DefaultLanguage "en"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include "tilelang.h"
extern char *optarg; /* silently set by getopt() */
extern int optind, opterr; /* silently set by getopt() */
static void usage();
static void dsc_head1();
static int dsc_infile( double ps_bb[4]);
static void dsc_head2( void);
static void printposter( void );
static void printprolog();
static void tile ( int row, int col, int nrows, int ncols);
static void cover ( int row, int col);
static void printfile( void);
static void postersize( char *scalespec, char *posterspec);
static void box_convert( char *boxspec, double psbox[4]);
static void boxerr( char *spec);
static void margin_convert( char *spec, double margin[2]);
static int mystrncasecmp( const char *s1, const char *s2, int n);
int verbose;
int alignment = 0;
char *myname;
char *infile;
int rotate, nrows, ncols;
int manualfeed = 0;
int tail_cntl_D = 0;
#define Xl 0
#define Yb 1
#define Xr 2
#define Yt 3
#define X 0
#define Y 1
double posterbb[4]; /* final image in ps units */
double imagebb[4]; /* original image in ps units */
double mediasize[4]; /* [34] = size of media to print on, [01] not used! */
double cutmargin[2];
double whitemargin[2];
double scale; /* linear scaling factor */
/* defaults: */
char *imagespec = NULL;
char *posterspec = NULL;
char *mediaspec = NULL;
char *cutmarginspec = NULL;
char *whitemarginspec = NULL;
char *scalespec = NULL;
char *filespec = NULL;
char *patterntitle = NULL;
char *patternhandle = NULL;
char *language = NULL;
/* media sizes in ps units (1/72 inch) */
static char *mediatable[][2] =
{ { "Letter", "612,792"},
{ "Legal", "612,1008"},
{ "Tabloid", "792,1224"},
{ "Ledger", "792,1224"},
{ "Executive","540,720"},
{ "Monarch", "279,540"},
{ "Statement","396,612"},
{ "Folio", "612,936"},
{ "Quarto", "610,780"},
{ "C5", "459,649"},
{ "B4", "729,1032"},
{ "B5", "516,729"},
{ "Dl", "312,624"},
{ "A0", "2380,3368"},
{ "A1", "1684,2380"},
{ "A2", "1190,1684"},
{ "A3", "842,1190"},
{ "A4", "595,842"},
{ "A5", "420,595"},
{ "A6", "297,421"},
/* as fall-back: linear units of measurement: */
{ "p", "1,1"},
{ "i", "72,72"},
{ "ft", "864,864"},
{ "mm", "2.83465,2.83465"},
{ "cm", "28.3465,28.3465"},
{ "m", "2834.65,2834.65"},
{ NULL, NULL}
};
int main( int argc, char *argv[])
{
int opt;
double ps_bb[4];
int got_bb;
myname = argv[0];
while ((opt = getopt( argc, argv, "vafi:c:l:w:m:p:s:o:t:h:")) != EOF)
{ switch( opt)
{ case 'v': verbose++; break;
case 'f': manualfeed = 1; break;
case 'a': alignment = 1; break;
case 'l': language = optarg; break;
case 'i': imagespec = optarg; break;
case 'c': cutmarginspec = optarg; break;
case 'w': whitemarginspec = optarg; break;
case 'm': mediaspec = optarg; break;
case 'p': posterspec = optarg; break;
case 's': scalespec = optarg; break;
case 'o': filespec = optarg; break;
case 't': patterntitle = optarg; break;
case 'h': patternhandle = optarg; break;
default: usage(); break;
}
}
/*** check command line arguments ***/
if (scalespec && posterspec)
{ fprintf( stderr, "Please don't specify both -s and -o, ignoring -s!\n");
scalespec = NULL;
}
if (optind < argc)
infile = argv[ optind];
else
{ fprintf( stderr, "Filename argument missing!\n");
usage();
}
/*** decide on media size ***/
if (!mediaspec)
{ mediaspec = DefaultMedia;
if (verbose)
fprintf( stderr,
"Using default media of %s\n",
mediaspec);
}
box_convert( mediaspec, mediasize);
if (mediasize[3] < mediasize[2])
{ fprintf( stderr, "Media should always be specified in portrait format!\n");
exit(1);
}
if (mediasize[2]-mediasize[0] <= 10.0 || mediasize[3]-mediasize[1] <= 10.0)
{ fprintf( stderr, "Media size is ridiculous!\n");
exit(1);
}
/*** defaulting poster size ? **/
if (!scalespec && !posterspec)
{ /* inherit postersize from given media size */
posterspec = mediaspec;
if (verbose)
fprintf( stderr,
"Defaulting poster size to media size of %s\n",
mediaspec);
}
/*** decide the cutmargin size, after knowing media size ***/
if (!cutmarginspec)
{ /* if (!strcmp( posterspec, mediaspec)) */
/* zero cutmargin if printing to 1 sheet */
/* marginspec = "0%";
else */ cutmarginspec = DefaultCutMargin;
if (verbose)
fprintf( stderr,
"Using default cutmargin of %s\n",
cutmarginspec);
}
margin_convert( cutmarginspec, cutmargin);
/*** decide the whitemargin size, after knowing media size ***/
if (!whitemarginspec)
{ whitemarginspec = DefaultWhiteMargin;
if (verbose)
fprintf( stderr,
"Using default whitemargin of %s\n",
whitemarginspec);
}
margin_convert( whitemarginspec, whitemargin);
/*** get the language code ***/
if (!language)
{ language = DefaultLanguage;
if (verbose)
fprintf( stderr,
"Using default language of %s\n",
language);
}
if( strlen( language ) != 2 )
{
fprintf( stderr,
"Invalid language code '%s''\n",
language);
}
else if( LangRead( language ) )
{
fprintf( stderr,
"Error reading language file for '%s'. Using default language of 'en'\n",
language);
}
/******************* now start doing things **************************/
/* open output file */
if (filespec)
{ if (!freopen( filespec, "w", stdout))
{ fprintf( stderr, "Cannot open '%s' for writing!\n",
filespec);
exit(1);
} else if (verbose)
fprintf( stderr, "Opened '%s' for writing\n",
filespec);
}
/******* I might need to read some input to find picture size ********/
/* start DSC header on output */
dsc_head1();
/* pass input DSC lines to output, get BoundingBox spec if there */
got_bb = dsc_infile( ps_bb);
/**** decide the input image bounding box ****/
if (!got_bb && !imagespec)
{ imagespec = DefaultImage;
if (verbose)
fprintf( stderr,
"Using default input image of %s\n",
imagespec);
}
if (imagespec)
box_convert( imagespec, imagebb);
else
{ int i;
for (i=0; i<4; i++)
imagebb[i] = ps_bb[i];
}
if (verbose > 1)
fprintf( stderr, " Input image is: [%g,%g,%g,%g]\n",
imagebb[0], imagebb[1], imagebb[2], imagebb[3]);
if (imagebb[2]-imagebb[0] <= 0.0 || imagebb[3]-imagebb[1] <= 0.0)
{ fprintf( stderr, "Input image should have positive size!\n");
exit(1);
}
/*** decide on the scale factor and poster size ***/
postersize( scalespec, posterspec);
if (verbose > 1)
fprintf( stderr, " Output image is: [%g,%g,%g,%g]\n",
posterbb[0], posterbb[1], posterbb[2], posterbb[3]);
dsc_head2();
printposter();
LangClose();
exit (0);
}
static void usage()
{
fprintf( stderr, "Usage: %s <options> infile\n\n", myname);
fprintf( stderr, "options are:\n");
fprintf( stderr, " -v: be verbose\n");
fprintf( stderr, " -a: add alignment marks\n");
fprintf( stderr, " -f: ask manual feed on plotting/printing device\n");
fprintf( stderr, " -l<lang>: specify language code (en, nl, fr)\n");
fprintf( stderr, " -i<box>: specify input image size\n");
fprintf( stderr, " -c<margin>: horizontal and vertical cutmargin\n");
fprintf( stderr, " -w<margin>: horizontal and vertical additional white margin\n");
fprintf( stderr, " -m<box>: media paper size\n");
fprintf( stderr, " -p<box>: output poster size\n");
fprintf( stderr, " -s<number>: linear scale factor for poster\n");
fprintf( stderr, " -o<file>: output redirection to named file\n\n");
fprintf( stderr, " At least one of -s -p -m is mandatory, and don't give both -s and -p\n");
fprintf( stderr, " <box> is like 'A4', '3x3letter', '10x25cm', '200x200+10,10p'\n");
fprintf( stderr, " <margin> is either a simple <box> or <number>%%\n\n");
fprintf( stderr, " Defaults are: '-m%s', '-c%s', '-i<box>' read from input file.\n",
DefaultMedia, DefaultCutMargin);
fprintf( stderr, " and output written to stdout.\n");
exit(1);
}
#define exch( x, y) {double h; h=x; x=y; y=h;}
static void postersize( char *scalespec, char *posterspec)
{ /* exactly one the arguments is NULL ! */
/* media and image sizes are fixed already */
int nx0, ny0, nx1, ny1;
double sizex, sizey; /* size of the scaled image in ps units */
double drawablex, drawabley; /* effective drawable size of media */
double mediax, mediay;
double tmpposter[4];
/* available drawing area per sheet: */
drawablex = mediasize[2] - 2.0*cutmargin[0];
drawabley = mediasize[3] - 2.0*cutmargin[1];
/*** decide on number of pages ***/
if (scalespec)
{ /* user specified scale factor */
scale = atof( scalespec);
if (scale < 0.01 || scale > 1.0e6)
{ fprintf( stderr, "Illegal scale value %s!\n", scalespec);
exit(1);
}
sizex = (imagebb[2] - imagebb[0]) * scale + 2*whitemargin[0];
sizey = (imagebb[3] - imagebb[1]) * scale + 2*whitemargin[1];
/* without rotation */
nx0 = ceil( sizex / drawablex);
ny0 = ceil( sizey / drawabley);
/* with rotation */
nx1 = ceil( sizex / drawabley);
ny1 = ceil( sizey / drawablex);
} else
{ /* user specified output size */
box_convert( posterspec, tmpposter);
if (tmpposter[0]!=0.0 || tmpposter[1]!=0.0)
{ fprintf( stderr, "Poster lower-left coordinates are assumed 0!\n");
tmpposter[0] = tmpposter[1] = 0.0;
}
if (tmpposter[2]-tmpposter[0] <= 0.0 || tmpposter[3]-tmpposter[1] <= 0.0)
{ fprintf( stderr, "Poster should have positive size!\n");
exit(1);
}
if ((tmpposter[3]-tmpposter[1]) < (tmpposter[2]-tmpposter[0]))
{ /* hmmm... landscape spec, change to portrait for now */
exch( tmpposter[0], tmpposter[1]);
exch( tmpposter[2], tmpposter[3]);
}
/* Should we tilt the poster to landscape style? */
if ((imagebb[3] - imagebb[1]) < (imagebb[2] - imagebb[0]))
{ /* image has landscape format ==> make landscape poster */
exch( tmpposter[0], tmpposter[1]);
exch( tmpposter[2], tmpposter[3]);
}
/* without rotation */ /* assuming tmpposter[0],[1] = 0,0 */
nx0 = ceil( 0.95 * tmpposter[2] / mediasize[2]);
ny0 = ceil( 0.95 * tmpposter[3] / mediasize[3]);
/* with rotation */
nx1 = ceil( 0.95 * tmpposter[2] / mediasize[3]);
ny1 = ceil( 0.95 * tmpposter[3] / mediasize[2]);
/* (rotation is considered as media versus image, which is totally */
/* independent of the portrait or landscape style of the final poster) */
}
/* decide for rotation to get the minimum page count */
rotate = nx0*ny0 > nx1*ny1;
ncols = rotate ? nx1 : nx0;
nrows = rotate ? ny1 : ny0;
if (verbose)
fprintf( stderr,
"Deciding for %d column%s and %d row%s of %s pages.\n",
ncols, (ncols==1)?"":"s", nrows, (nrows==1)?"":"s",
rotate?"landscape":"portrait");
if (nrows * ncols > 400)
{ fprintf( stderr, "However %dx%d pages seems ridiculous to me!\n",
ncols, nrows);
exit(1);
}
mediax = ncols * (rotate ? drawabley : drawablex);
mediay = nrows * (rotate ? drawablex : drawabley);
if (!scalespec) /* no scaling number given by user */
{ double scalex, scaley;
scalex = (mediax - 2*whitemargin[0]) / (imagebb[2] - imagebb[0]);
scaley = (mediay - 2*whitemargin[1]) / (imagebb[3] - imagebb[1]);
scale = (scalex < scaley) ? scalex : scaley;
if (verbose)
fprintf( stderr,
"Deciding for a scale factor of %g\n", scale);
sizex = scale * (imagebb[2] - imagebb[0]);
sizey = scale * (imagebb[3] - imagebb[1]);
}
/* set poster size as if it were a continuous surface without margins */
posterbb[0] = (mediax - sizex) / 2.0; /* center picture on paper */
posterbb[1] = (mediay - sizey) / 2.0; /* center picture on paper */
posterbb[2] = posterbb[0] + sizex;
posterbb[3] = posterbb[1] + sizey;
}
static void margin_convert( char *spec, double margin[2])
{ double x;
int i, n;
if (1==sscanf( spec, "%lf%n", &x, &n) && x==0.0 && n==strlen(spec))
{ /* margin spec of 0, dont bother about a otherwise mandatory unit */
margin[0] = margin[1] = 0.0;
} else if (spec[ strlen( spec) - 1] == '%')
{ /* margin relative to media size */
if (1 != sscanf( spec, "%lf%%", &x))
{ fprintf( stderr, "Illegal margin specification!\n");
exit( 1);
}
margin[0] = 0.01 * x * mediasize[2];
margin[1] = 0.01 * x * mediasize[3];
} else
{ /* absolute margin value */
double marg[4];
box_convert( spec, marg);
margin[0] = marg[2];
margin[1] = marg[3];
}
for (i=0; i<2; i++)
{ if (margin[i] < 0 || 2.0*margin[i] >= mediasize[i+2])
{ fprintf( stderr, "Margin value '%s' out of range!\n",
spec);
exit(1);
}
}
}
static void box_convert( char *boxspec, double psbox[4])
{ /* convert user textual box spec into numbers in ps units */
/* box = [fixed x fixed][+ fixed , fixed] unit */
/* fixed = digits [ . digits] */
/* unit = medianame | i | cm | mm | m | p */
double mx, my, ox, oy, ux, uy;
int n, r, i, l, inx;
char *spec;
mx = my = 1.0;
ox = oy = 0.0;
spec = boxspec;
/* read 'fixed x fixed' */
if (isdigit( spec[0]))
{ r = sscanf( spec, "%lfx%lf%n", &mx, &my, &n);
if (r != 2)
{ r = sscanf( spec, "%lf*%lf%n", &mx, &my, &n);
if (r != 2) boxerr( boxspec);
}
spec += n;
}
/* read '+ fixed , fixed' */
if (1 < (r = sscanf( spec, "+%lf,%lf%n", &ox, &oy, &n)))
{ if (r != 2) boxerr( boxspec);
spec += n;
}
/* read unit */
l = strlen( spec);
for (n=i=0; mediatable[i][0]; i++)
{ if (!mystrncasecmp( mediatable[i][0], spec, l))
{ /* found */
n++;
inx = i;
if (l == strlen( mediatable[i][0]))
{ /* match is exact */
n = 1;
break;
}
}
}
if (!n) boxerr( boxspec);
if (n>1)
{ fprintf( stderr, "Your box spec '%s' is not unique! (give more chars)\n",
spec);
exit(1);
}
sscanf( mediatable[inx][1], "%lf,%lf", &ux, &uy);
psbox[0] = ox * ux;
psbox[1] = oy * uy;
psbox[2] = mx * ux;
psbox[3] = my * uy;
if (verbose > 1)
fprintf( stderr, " Box_convert: '%s' into [%g,%g,%g,%g]\n",
boxspec, psbox[0], psbox[1], psbox[2], psbox[3]);
for (i=0; i<2; i++)
{ if (psbox[i] < 0.0 || psbox[i+2] < psbox[i])
{ fprintf( stderr, "Your specification `%s' leads to "
"negative values!\n", boxspec);
exit(1);
}
}
}
static void boxerr( char *spec)
{ int i;
fprintf( stderr, "I don't understand your box specification `%s'!\n",
spec);
fprintf( stderr, "The proper format is: ([text] meaning optional text)\n");
fprintf( stderr, " [multiplier][offset]unit\n");
fprintf( stderr, " with multiplier: numberxnumber\n");
fprintf( stderr, " with offset: +number,number\n");
fprintf( stderr, " with unit one of:");
for (i=0; mediatable[i][0]; i++)
fprintf( stderr, "%c%-10s", (i%7)?' ':'\n', mediatable[i][0]);
fprintf( stderr, "\nYou can use a shorthand for these unit names,\n"
"provided it resolves unique.\n");
exit( 1);
}
/*********************************************/
/* output first part of DSC header */
/*********************************************/
static void dsc_head1()
{
printf ("%%!PS-Adobe-3.0\n");
printf ("%%%%Creator: %s\n", myname);
}
/*********************************************/
/* pass some DSC info from the infile in the new DSC header */
/* such as document fonts and */
/* extract BoundingBox info from the PS file */
/*********************************************/
static int dsc_infile( double ps_bb[4])
{
char *c, buf[BUFSIZE];
int gotall, atend, level, dsc_cont, inbody, got_bb;
if (freopen (infile, "r", stdin) == NULL) {
fprintf (stderr, "%s: fail to open file '%s'!\n",
myname, infile);
exit (1);
}
got_bb = 0;
dsc_cont = inbody = gotall = level = atend = 0;
while (!gotall && (gets(buf) != NULL))
{
if (buf[0] != '%')
{ dsc_cont = 0;
if (!inbody) inbody = 1;
if (!atend) gotall = 1;
continue;
}
if (!strncmp( buf, "%%+",3) && dsc_cont)
{ puts( buf);
continue;
}
dsc_cont = 0;
if (!strncmp( buf, "%%EndComments", 13))
{ inbody = 1;
if (!atend) gotall = 1;
}
else if (!strncmp( buf, "%%BeginDocument", 15) ||
!strncmp( buf, "%%BeginData", 11)) level++;
else if (!strncmp( buf, "%%EndDocument", 13) ||
!strncmp( buf, "%%EndData", 9)) level--;
else if (!strncmp( buf, "%%Trailer", 9) && level == 0)
inbody = 2;
else if (!strncmp( buf, "%%BoundingBox:", 14) &&
inbody!=1 && !level)
{ for (c=buf+14; *c==' ' || *c=='\t'; c++);
if (!strncmp( c, "(atend)", 7)) atend = 1;
else
{ sscanf( c, "%lf %lf %lf %lf",
ps_bb, ps_bb+1, ps_bb+2, ps_bb+3);
got_bb = 1;
}
}
else if (!strncmp( buf, "%%Document", 10) &&
inbody!=1 && !level) /* several kinds of doc props */
{ for (c=buf+10; *c && *c!=' ' && *c!='\t'; c++);
for (; *c==' ' || *c=='\t'; c++);
if (!strncmp( c, "(atend)", 7)) atend = 1;
else
{ /* pass this DSC to output */
puts( buf);
dsc_cont = 1;
}
}
}
return got_bb;
}
/*********************************************/
/* output last part of DSC header */
/*********************************************/
static void dsc_head2()
{
printf ("%%%%Pages: %d\n", nrows*ncols);
#ifndef Gv_gs_orientbug
printf ("%%%%Orientation: %s\n", rotate?"Landscape":"Portrait");
#endif
printf ("%%%%DocumentMedia: %s %d %d 0 white ()\n",
mediaspec, (int)(mediasize[2]), (int)(mediasize[3]));
printf ("%%%%BoundingBox: 0 0 %d %d\n", (int)(mediasize[2]), (int)(mediasize[3]));
printf ("%%%%EndComments\n\n");
printf ("%% Print poster %s in %dx%d tiles with %.3g magnification\n",
infile, nrows, ncols, scale);
}
/*********************************************/
/* output the poster, create tiles if needed */
/*********************************************/
static void printposter()
{
int row, col;
printprolog();
cover(nrows,ncols);
for (row = 1; row <= nrows; row++)
for (col = 1; col <= ncols; col++)
tile( row, col, nrows, ncols);
printf ("%%%%EOF\n");
if (tail_cntl_D)
{ printf("%c", 0x4);
}
}
/*******************************************************/
/* output PS prolog of the scaling and tiling routines */
/*******************************************************/
static void printprolog()
{
char *extraCode, *test1, *test2;
printf( "%%%%BeginProlog\n");
printf( "/cutmark %% - cutmark -\n"
"{ %% draw cutline\n"
" 0.5 setlinewidth 0 setgray\n"
" clipmargin\n"
" dup 0 moveto\n"
" dup neg leftmargin add 0 rlineto stroke\n"
" %% draw sheet alignment mark\n"
" dup dup neg moveto\n"
" dup 0 rlineto\n"
" dup dup lineto\n"
" 0 rlineto\n"
" closepath fill\n"
"} bind def\n\n");
if( alignment )
{
printf ("/alignmark\n"
"{\n"
" gsave\n"
" 0 setgray 1 setlinewidth\n"
" 10 neg 10 neg rmoveto\n"
" 20 20 rlineto \n"
" 20 neg 0 rmoveto\n"
" 20 20 neg rlineto stroke\n"
" grestore\n"
"} bind def\n"
"\n"
"/alignmarkhor\n"
"{\n"
" 120 0 rmoveto\n"
" alignmark\n"
" pagewidth 0 rmoveto\n"
" 240 neg 0 rmoveto\n"
" alignmark\n"
"} bind def\n"
"\n"
"/alignmarkver\n"
"{\n"
" 0 120 rmoveto\n"
" alignmark\n"
" 0 pageheight rmoveto\n"
" 0 240 neg rmoveto\n"
" alignmark\n"
"} bind def\n");
}
printf( "%% usage: row col tileprolog ps-code tilepilog\n"
"%% these procedures output the tile specified by row & col\n"
"/tileprolog\n"
"{ %%def\n"
" gsave\n"
" leftmargin botmargin translate\n"
" do_turn {exch} if\n"
" /colcount exch def\n"
" /rowcount exch def\n"
" %% clip page contents\n"
" clipmargin neg dup moveto\n"
" pagewidth clipmargin 2 mul add 0 rlineto\n"
" 0 pageheight clipmargin 2 mul add rlineto\n"
" pagewidth clipmargin 2 mul add neg 0 rlineto\n"
" closepath clip\n"
" %% set page contents transformation\n"
" do_turn\n"
" { pagewidth 0 translate\n"
" 90 rotate\n"
" } if\n"
" pagewidth colcount 1 sub mul neg\n"
" pageheight rowcount 1 sub mul neg\n"
" do_turn {exch} if\n"
" translate\n"
" posterxl posteryb translate\n"
" sfactor dup scale\n"
" imagexl neg imageyb neg translate\n"
" tiledict begin\n"
" 0 setgray 0 setlinecap 1 setlinewidth\n"
" 0 setlinejoin 10 setmiterlimit [] 0 setdash newpath\n"
"} bind def\n\n");
printf( "/tileepilog\n"
"{ end %% of tiledict\n"
" grestore\n"
" %% print the bounding box\n"
" gsave\n"
" do_turn {\n"
" /totalrows exch def\n"
" /totalcols exch def\n"
" /pagenr { colcount 1 sub totalrows mul rowcount add } bind def\n"
" } {\n"
" /totalcols exch def\n"
" /totalrows exch def\n"
" /pagenr { rowcount 1 sub totalcols mul colcount add } bind def\n"
" } ifelse\n"
" 0 setgray 1 setlinewidth\n"
" leftmargin botmargin moveto\n"
" 0 pageheight rlineto\n"
" pagewidth 0 rlineto\n"
" 0 pageheight neg rlineto closepath stroke\n"
" grestore\n"
" %% print the page label\n"
" 0 setgray\n"
" leftmargin clipmargin 3 mul add clipmargin labelsize add neg botmargin add moveto\n" );
printf( " (%s ) show\n", LangPrompt( "Page" ) );
printf( " pagenr strg cvs show\n"
" (: %s ) show\n", LangPrompt( "row" ) );
printf( " rowcount strg cvs show\n"
" (, %s ) show\n", LangPrompt( "column" ) );
printf( " colcount strg cvs show\n"
" pagewidth 69 sub clipmargin labelsize add neg botmargin add moveto\n"
" (freesewing.org ) show\n" );
if( alignment )
{
if( rotate ) {
test1 = " colcount totalcols lt\n";
test2 = " colcount 1 gt\n";
} else {
test1 = " colcount 1 gt\n";
test2 = " colcount totalcols lt\n";
}
printf( " gsave\n"
"%s"
" {\n"
" leftmargin botmargin moveto\n"
" alignmarkver\n"
" } if\n"
" rowcount 1 gt\n"
" {\n"
" leftmargin botmargin moveto\n"
" alignmarkhor\n"
" } if\n"
"%s"
" {\n"
" leftmargin botmargin moveto\n"
" pagewidth 0 rmoveto\n"
" alignmarkver\n"
" } if\n"
" rowcount totalrows lt\n"
" {\n"
" leftmargin botmargin moveto\n"
" 0 pageheight rmoveto\n"
" alignmarkhor\n"
" } if\n"
" grestore\n", test1, test2 );
}
printf( " showpage\n"
"} bind def\n\n");
printf( "%% usage: row col coverprolog ps-code coverepilog\n"
"%% these procedures output the cover page\n"
"/coverprolog\n"
"{ %%def\n"
" gsave\n"
" leftmargin botmargin translate\n"
" do_turn {exch} if\n"
" /colcount exch def\n"
" /rowcount exch def\n"
" %% clip page contents\n"
" clipmargin neg dup moveto\n"
" pagewidth clipmargin 2 mul add 0 rlineto\n"
" 0 pageheight clipmargin 2 mul add rlineto\n"
" pagewidth clipmargin 2 mul add neg 0 rlineto\n"
" closepath clip\n"
" %% set page contents transformation\n"
" pagewidth colcount 1 sub mul neg\n"
" pageheight rowcount 1 sub mul neg\n"
" do_turn {\n"
" pagewidth 0 translate\n"
" 90 rotate\n"
" botmargin leftmargin translate\n"
" 0.78 rowcount div dup scale\n"
" imagexl neg posterxl add imageyb neg posteryb add translate\n"
" } {\n"
" 0.1 pagewidth mul botmargin translate\n"
" 0.8 colcount div dup scale\n"
" imagexl neg posterxl add imageyb neg posteryb add translate\n"
" } ifelse\n"
" tiledict begin\n"
" 0 setgray 0 setlinecap 1 setlinewidth\n"
" 0 setlinejoin 10 setmiterlimit [] 0 setdash newpath\n"
"} bind def\n\n");
printf( "/coverepilog\n"
"{ end %% of tiledict\n"
" grestore\n"
" %% print the page label\n"
" 0 setgray\n"
" leftmargin clipmargin 3 mul add clipmargin labelsize add neg botmargin add moveto\n" );
printf( " ( %s ) show\n", LangPrompt( "cover page" ));
printf( " leftmargin clipmargin 3 mul add pageheight 10 add moveto\n"
" /Helvetica findfont 24 scalefont setfont\n"
" (freesewing) show\n"
" leftmargin clipmargin 3 mul add pageheight 5 sub moveto\n"
" /Helvetica findfont 11 scalefont setfont\n" );
printf( " (%s ) show\n", LangPrompt( "an open source platform for made-to-measure sewing patterns" ));
printf( " leftmargin clipmargin 3 mul add pageheight 62 sub moveto\n"
" /Helvetica findfont 42 scalefont setfont\n"
" patterntitle show\n"
" leftmargin clipmargin 4 mul add pageheight 80 sub moveto\n"
" /Helvetica findfont 9 scalefont setfont\n"
" 0.5 setgray\n"
" (freesewing.org/drafts/) show\n"
" patternhandle show\n"
" 0 setgray\n"
" /Helvetica findfont labelsize scalefont setfont\n"
" pagewidth 69 sub clipmargin labelsize add neg botmargin add moveto\n"
" (freesewing.org ) show\n"
" leftmargin clipmargin 3 mul add pageheight 70 sub moveto\n"
" pagewidth clipmargin 2 mul add pageheight 70 sub lineto stroke\n"
" gsave\n"
" pagewidth 75 sub pageheight 60 sub translate\n"
" logo\n"
" grestore\n"
" showpage\n"
"} bind def\n\n");
printf( "/covergrid\n"
"{ %% print the page label\n"
" /curcol exch def\n"
" /currow exch def\n"
" gsave\n"
" 0.8 setgray 0.2 setlinewidth\n"
" do_turn\n"
" { \n"
" /pagenr { currow 1 sub rowcount mul curcol add } bind def\n"
" curcol 1 sub pageheight mul currow 1 sub pagewidth mul moveto\n"
" posterxl neg posteryb neg rmoveto\n"
" 0 pagewidth rlineto\n"
" pageheight 0 rlineto\n"
" 0 pagewidth neg rlineto closepath stroke\n"
" /Helvetica findfont 60 scalefont setfont\n"
" curcol 1 sub pageheight mul currow 1 sub pagewidth mul moveto\n"
" posterxl neg 20 add posteryb neg 20 add rmoveto\n"
" (row ) show\n"
" curcol strg cvs show\n"
" (, column ) show\n"
" currow strg cvs show\n"
" curcol 1 sub pageheight mul currow 1 sub pagewidth mul moveto\n"
" posterxl neg 150 add posteryb neg 150 add rmoveto\n"
" /Helvetica findfont 300 scalefont setfont\n"
" pagenr strg cvs true charpath\n"
" 0.3 setlinewidth 0.6 setgray stroke\n"
" }\n"
" {\n"
" /pagenr { currow 1 sub colcount mul curcol add } bind def\n"
" curcol 1 sub pagewidth mul currow 1 sub pageheight mul moveto\n"
" posterxl neg posteryb neg rmoveto\n"
" 0 pageheight rlineto\n"
" pagewidth 0 rlineto\n"
" 0 pageheight neg rlineto closepath stroke\n"
" /Helvetica findfont 60 scalefont setfont\n"
" curcol 1 sub pagewidth mul currow 1 sub pageheight mul moveto\n"
" posterxl neg 20 add posteryb neg 20 add rmoveto\n"
" (row ) show\n"
" currow strg cvs show\n"
" (, column ) show\n"
" curcol strg cvs show\n"
" curcol 1 sub pagewidth mul currow 1 sub pageheight mul moveto\n"
" posterxl neg 150 add posteryb neg 150 add rmoveto\n"
" /Helvetica findfont 300 scalefont setfont\n"
" pagenr strg cvs true charpath\n"
" 0.3 setlinewidth 0.6 setgray stroke\n"
" } ifelse\n"
" grestore\n"
"} bind def\n\n");
printf( "/logo\n"
"{ %% print the logo\n"
" /m { moveto } bind def\n"
" /c { curveto } bind def\n"
" /l { lineto } bind def\n"
" /h { closepath } bind def\n"
" /f { fill } bind def\n"
" gsave\n"
" 0 setgray\n"
" 36.75 52.931 m 35.656 52.158 35.715 52.255 34.832 51.966 c 32.812 51.306\n"
" 30.875 51.669 28.578 51.861 c 27.887 51.939 27.199 51.986 26.531 51.99\n"
" c 23.148 52.013 20.277 51.021 19.734 48.251 c 18.734 47.646 17.812 46.908\n"
" 16.898 46.173 c 14.949 44.634 13.48 42.755 12.48 40.49 c 11.113 37.142\n"
" 12.348 33.548 12.961 30.158 c 13.105 29.365 13.258 28.607 13.34 28.314 c\n"
" 13.453 27.904 13.66 27.509 13.879 27.158 c 13.934 27.15 14.207 27.572 14.27\n"
" 27.755 c 14.367 28.029 14.355 28.462 14.25 28.837 c 14.023 29.681 13.805\n"
" 30.369 13.785 30.712 c 13.754 31.357 13.879 31.955 14.113 32.248 c 14.199\n"
" 32.353 14.391 31.814 14.34 31.615 c 14.281 31.373 14.238 30.959 14.258\n"
" 30.767 c 14.309 30.123 14.402 29.431 14.52 28.826 c 14.672 28.044 14.738\n"
" 27.544 14.711 27.349 c 14.691 27.209 14.625 27.068 14.371 26.63 c 14.148\n"
" 26.248 14.035 25.939 14.016 25.666 c 14 25.4 14.078 24.732 14.152 24.568\n"
" c 14.262 24.314 14.59 24.044 14.879 23.978 c 15.152 23.873 15.289 23.658\n"
" 15.43 23.412 c 15.773 22.759 16.039 21.962 16.301 20.763 c 16.43 20.189\n"
" 16.535 19.677 16.57 19.408 c 14.453 19.404 11.742 19.404 9.273 19.404 c\n"
" 8.441 19.392 6.938 19.783 5.562 19.873 c 5.363 22.025 4.414 24.529 2.797\n"