File: f_print.texi

package info (click to toggle)
libgeda 20050313-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 5,636 kB
  • ctags: 1,505
  • sloc: ansic: 19,449; sh: 8,627; makefile: 197; perl: 59
file content (714 lines) | stat: -rw-r--r-- 17,907 bytes parent folder | download
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
@c -*- mode: Noweb; noweb-doc-mode: texinfo-mode; noweb-code-mode: c-mode -*-

@node File f_print.c,,,Top
@chapter File @file{f_print.c}

@section File header

@format
@anchor{f_print.c - -root-}
@i{<<f_print.c : *>>=}@t{
@i{<<f_print.c : copyright and license -- @ref{f_print.c - copyright and license}>>}

/* DO NOT read or edit this file ! Use ../noweb/f_print.nw instead */

@i{<<f_print.c : include directives -- @ref{f_print.c - include directives}>>}
@i{<<f_print.c : structure header -- @ref{f_print.c - structure header}>>}
@i{<<f_print.c : f_print_set_line_width() -- @ref{f_print.c - f_print_set_line_width()}>>}
@i{<<f_print.c : f_print_set_color() -- @ref{f_print.c - f_print_set_color()}>>}
@i{<<f_print.c : f_print_header() -- @ref{f_print.c - f_print_header()}>>}
@i{<<f_print.c : f_print_footer() -- @ref{f_print.c - f_print_footer()}>>}
@i{<<f_print.c : f_print_objects() -- @ref{f_print.c - f_print_objects()}>>}
@i{<<f_print.c : f_print() -- @ref{f_print.c - f_print()}>>}
@i{<<f_print.c : f_print_set_type() -- @ref{f_print.c - f_print_set_type()}>>}


@display
@r{Uses :
@t{f_print},  -- @ref{f_print.c - f_print()}.
}
@end display
}
@end format




@format
@anchor{f_print.c - copyright and license}
@i{<<f_print.c : copyright and license>>=}@t{
/* gEDA - GPL Electronic Design Automation
 * libgeda - gEDA's library
 * Copyright (C) 1998-2000 Ales V. Hvezda
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
 */

}
@end format




@format
@anchor{f_print.c - include directives}
@i{<<f_print.c : include directives>>=}@t{
#include <config.h>

#include <stdio.h>
#include <math.h>

#include <gtk/gtk.h>
#include <libguile.h>

#include "defines.h"
#include "struct.h"
#include "globals.h"
#include "o_types.h"
#include "funcs.h"
#include "colors.h"

#include "../include/prototype.h"

#ifdef HAVE_LIBDMALLOC
#include <dmalloc.h>
#endif

}
@end format




@format
@anchor{f_print.c - structure header}
@i{<<f_print.c : structure header>>=}@t{
struct st_pslines @{
  char *line;
@};

struct st_pslines header[] = @{
#if 0
  @{ "%!\n"                      @},
  @{ "\n"                                @}, 

  @{ "/inch @{72 mul@} def\n"      @}, 
  @{ "\n"                                @}, 
  @{ "/setcoords\n"              @}, 
  @{ "@{\n"                       @}, 
  @{ "8.5 72 mul 0 translate\n"  @}, 
  @{ "90 rotate\n"               @}, 
  @{ ".46 .46 scale\n"           @}, /* was .46 .46 */
  @{ "@} def\n"                   @}, 


  @{ "\n"                                @},
  @{ "/mils\n"                   @},
  @{ "@{\n"                               @},
  @{ "1000 div inch\n"           @},
  @{ "@} def\n"                   @},
#endif


  /* box function */
  @{ "\n"                                @},
  @{ "/box @{\n"                  @},
  @{ "exch dup 0 rlineto\n"      @},
  @{ "exch 0 exch rlineto\n"     @},
  @{ "neg 0 rlineto\n"           @},
  @{ "closepath\n"                       @},
  @{ "stroke\n"                  @},
  @{ "@} def\n"                   @},     

  /* filled box function */
  @{ "/fbox @{\n"                 @},
  @{ "exch dup 0 rlineto\n"      @},
  @{ "exch 0 exch rlineto\n"     @},
  @{ "neg 0 rlineto\n"           @},
  @{ "closepath\n"                       @},
  @{ "fill\n"                    @},
  @{ "@} def\n"                   @},     

#if 0
  @{ "\n"                                @},
  @{ "/text\n"                   @},
  @{ "@{\n"                               @},
  @{ "gsave\n"                   @},
  @{ "moveto\n"                  @},
  @{ "2 -2 scale\n"              @},
  @{ "-90 rotate\n"              @},

  @{ "moveto\n"                  @},
  @{ "2 2 scale\n"                       @},
  @{ "show\n"                    @},
  @{ "grestore\n"                        @},
  @{ "@} def\n"                   @},    
  @{ "\n"                                @},
#endif

  /* set the coords to the wanted scale and rotation */
  @{ "\n\nsetcoords\n"                   @},
  @{ "\n"                                @},
  @{ NULL @}
@};

struct st_pslines footer[] = @{
  @{ "\n"                                @},
  @{ "showpage\n"                        @},
  @{ NULL @}
@};

@display
@r{Defines :
@t{header},
 -- @ref{f_print.c - f_print_header()}.
}
@end display
}
@end format



@section Function @code{f_print_set_line_width()}

@defun f_print_set_line_width fp width
@end defun

@format
@anchor{f_print.c - f_print_set_line_width()}
@i{<<f_print.c : f_print_set_line_width()>>=}@t{
/* width is in mils */
void
f_print_set_line_width(FILE *fp, int width)
@{
  if (width > 0) @{
    fprintf(fp, "%d mils setlinewidth\n", width);
  @}
@}

@display
@r{Defines :
.
}
@end display
}
@end format



@section Function @code{f_print_set_color()}

@defun f_print_set_color fp color
@end defun

@format
@anchor{f_print.c - f_print_set_color()}
@i{<<f_print.c : f_print_set_color()>>=}@t{
void
f_print_set_color(FILE *fp, int color) 
@{
  char *string;

  /* DO NOT free string... it's a reference to a malloced */
  /* string, there is *no* memory leak here */
  string = s_color_ps_string(color);

  if (string) @{
    fprintf(fp, "%s setrgbcolor\n", string);
  @} else @{
    fprintf(fp, "0 0 0 setrgbcolor\n");
  @}
@}

@display
@r{Defines :
@t{f_print_set_color},
 -- @ref{f_print.c - f_print_header()}.
}
@end display
}
@end format



@section Function @code{f_print_header()}

@defun f_print_header w_current fp paper_size_x paper_size_y world_right world_bottom
@end defun

@format
@anchor{f_print.c - f_print_header()}
@i{<<f_print.c : f_print_header()>>=}@t{
/* paper size is in inches and floats */
float
f_print_header(TOPLEVEL *w_current, FILE *fp, int paper_size_x, int paper_size_y, 
        int world_right, int world_bottom)
@{
  int i;
  struct st_pslines *ptr;
  float x, y;
  float final;

  /* define an inch */
  fprintf(fp, "%%!\n");
  fprintf(fp, "/inch @{72 mul@} def\n");

  /* define mils */
  fprintf(fp, "\n");
  fprintf(fp, "/mils\n");
  fprintf(fp, "@{\n");
  fprintf(fp, "1000 div inch\n");
  fprintf(fp, "@} def\n");

  fprintf(fp, "\n");

  if (w_current->setpagedevice_orientation) @{
    if (w_current->print_orientation == LANDSCAPE) @{
      fprintf(fp, "%c%c /Orientation 1 %c%c setpagedevice\n\n", '<', '<',
              '>', '>');
    @} else @{
      fprintf(fp, "%c%c /Orientation 0 %c%c setpagedevice\n\n", '<', '<',
              '>', '>');
    @}
  @}

  /* the height and width are in the right order here, since they were
   * specified in landscape order in the system-gschemrc file. */
  if (w_current->setpagedevice_pagesize) @{
    fprintf(fp, "%c%c /PageSize [%d %d] %c%c setpagedevice\n\n", '<', '<',
            (w_current->paper_height * 72) / MILS_PER_INCH,
            (w_current->paper_width * 72) / MILS_PER_INCH,
            '>', '>');
  @}

  /* coordinate setup function */
  fprintf(fp, "/setcoords\n@{\n");


  /* regular if it's portrait */
  if (w_current->print_orientation == LANDSCAPE) @{
    fprintf(fp, "%d mils 0 translate\n", paper_size_y);
    fprintf(fp, "90 rotate\n");
  @}

  x = (float) (paper_size_x) / world_right;
  y = (float) (paper_size_y) / world_bottom;

  final = min(x, y);

  if (w_current->print_output_type != EXTENTS_NOMARGINS) @{
     /* If Window or Extents with margins */
     /* make the finale scale factor a bit smaller */
     final = final - final / 10;
  @}

  fprintf(fp, "%f %f scale\n", final, final);

  fprintf(fp, "@} def\n");

  if (w_current->print_color) @{
    fprintf(fp, "\n");  
    f_print_set_color(fp, w_current->print_color_background);
    if (w_current->print_orientation == LANDSCAPE) @{
       fprintf(fp, "0 0 moveto\n%d 0 rlineto 0 %d rlineto -%d 0 rlineto\n",
               paper_size_y*72/1000, paper_size_x*72/1000, 
               paper_size_y*72/1000);
    @} else @{
       fprintf(fp, "0 0 moveto\n%d 0 rlineto 0 %d rlineto -%d 0 rlineto\n",
               paper_size_x*72/1000, paper_size_y*72/1000, 
               paper_size_x*72/1000);
   @}
    fprintf(fp, "closepath fill\n");
  @}


  /* print out rest of the header */
  i = 0;
  ptr = &header[0];
  while( ptr->line != NULL ) @{
    fprintf(fp, "%s", ptr->line);
    i++;
    ptr = &header[i];
  @}

  if (w_current->print_output_capstyle == BUTT_CAP) @{
    fprintf(fp, "0 setlinecap\n");
  @} else if (w_current->print_output_capstyle == SQUARE_CAP) @{
    fprintf(fp, "2 setlinecap\n");
  @} else if (w_current->print_output_capstyle == ROUND_CAP) @{
    fprintf(fp, "1 setlinecap\n");
  @}

  return(final);
@}

@display
@r{Defines :
@t{f_print_header},
 -- @ref{f_print.c - f_print()}.
}
@end display
@display
@r{Uses :
@t{f_print_set_color},  -- @ref{f_print.c - f_print_set_color()}.
@t{header},  -- @ref{f_print.c - structure header}.
}
@end display
}
@end format



@section Function @code{f_print_footer()}

@defun f_print_footer fp
@end defun

@format
@anchor{f_print.c - f_print_footer()}
@i{<<f_print.c : f_print_footer()>>=}@t{
void
f_print_footer(FILE *fp)
@{
  int i;
  struct st_pslines *ptr;
  i = 0;

  ptr = &footer[0];

  while( ptr->line != NULL ) @{
    fprintf(fp, "%s", ptr->line);
    i++;
    ptr = &footer[i];
  @}

@}

@display
@r{Defines :
@t{f_print_footer},
 -- @ref{f_print.c - f_print()}.
}
@end display
}
@end format



@section Function @code{f_print_objects()}

@defun f_print_objects w_current fp head start_x start_y scale
@end defun

@format
@anchor{f_print.c - f_print_objects()}
@i{<<f_print.c : f_print_objects()>>=}@t{
/* what happens if snap is off? */
/* hack deal with this !!!!!!!! */
void
f_print_objects(TOPLEVEL *w_current, FILE *fp, OBJECT *head, 
        int start_x, int start_y, float scale)
@{
  OBJECT *o_current=NULL;
  int origin_x, origin_y, bottom, right;
        
  if (start_x == -1 && start_y == -1) @{
    world_get_complex_bounds(w_current, head, &origin_x, &origin_y, 
                             &right, &bottom);


    /* right, bottom b-o r-o*/
    if (w_current->print_orientation == PORTRAIT) @{

      /*temp remove if (origin_x != 0 && origin_y != 0) @{ */
      origin_x = origin_x - (int)  ((w_current->paper_height - (float) (right-origin_x) * (float) scale)/2 / (float) scale);
      origin_y = origin_y - (int) ((w_current->paper_width - (float) (bottom-origin_y) * (float) scale)/2 / (float) scale);

      /*@}*/
    @} else @{ /* landscape */

      origin_x = origin_x - (int)  ((w_current->paper_width - (float) (right-origin_x) * (float) scale)/2 / (float) scale);
      origin_y = origin_y - (int) ((w_current->paper_height - (float) (bottom-origin_y) * (float) scale)/2 / (float) scale);

    @}
  @} else @{
    origin_x = start_x;
    origin_y = start_y;
  @}

  if (head == NULL) @{
    return;
  @}

  /* highly temp, might break everything */
  /* what a hack!!!!!!!!!! fix this... (by removing the dead code that */
  /* deals with the origin_x, and origin_y stuff */
  if (origin_x != 0 && origin_y != 0) @{
    fprintf(fp, "\n%% Translate origin to the right place...\n");

    if (origin_x < 0) @{
      fprintf(fp, "%d mils ", -origin_x);
    @} else @{
      fprintf(fp, "-%d mils ", origin_x);
    @}

    if (origin_y < 0) @{
      fprintf(fp, "%d mils ", -origin_y);
    @} else @{
      fprintf(fp, "-%d mils ", origin_y);
    @}

    fprintf(fp, "translate\n\n");
    /*fprintf(fp, "-%d mils -%d mils translate\n\n", origin_x, origin_y); */
  @} 


  /* no longer change the coords, the postscript translate takes care 
   * of this */
  origin_x = 0;
  origin_y = 0;

  o_current = head;

  while ( o_current != NULL ) @{

    if (o_current->type != OBJ_HEAD) @{

      switch (o_current->type) @{
        case(OBJ_LINE):
          o_line_print(w_current, fp, o_current,
                       origin_x, origin_y);
          break;
        
        case(OBJ_NET):
          o_net_print(w_current, fp, o_current,
                      origin_x, origin_y);
          break;

        case(OBJ_BUS):
          o_bus_print(w_current, fp, o_current,
                      origin_x, origin_y);
          break;
        
        case(OBJ_BOX):
          o_box_print(w_current, fp, o_current,
                      origin_x, origin_y);
          break;
                        
        case(OBJ_CIRCLE):
          o_circle_print(w_current, fp, o_current,
                         origin_x, origin_y);
          break;

        case(OBJ_COMPLEX):
        case(OBJ_PLACEHOLDER): /* new object -- 1.20.2005 SDB */
          fprintf(fp, "gsave\n");

          f_print_objects(w_current, fp, 
                          o_current->complex->prim_objs,
                          origin_x, origin_y, scale);
          fprintf(fp, "grestore\n");
          break;

        case(OBJ_TEXT):
          if (o_current->visibility == VISIBLE) @{
            fprintf(fp, "gsave\n");
                        
            if (w_current->text_output == VECTOR_FONTS || 
                o_text_num_lines(o_current->text->string) > 
                  w_current->print_vector_threshold) 
            @{   
              f_print_objects(w_current, 
                              fp, 
                              o_current->text->
                              prim_objs,
                              origin_x, origin_y, 
                              scale);
            @} else @{

              o_text_print(w_current, fp, 
                           o_current,
                           origin_x, origin_y);

            @}

            fprintf(fp, "grestore\n");
          @}
          break;


        case(OBJ_PIN):
          o_pin_print(w_current, fp, o_current,
                      origin_x, origin_y);
          break;
        
        case(OBJ_ARC):
          o_arc_print(w_current, fp, o_current,
                      origin_x, origin_y);
          break;

        case(OBJ_PICTURE):
            /* FIXME: Implement this */
          fprintf(stderr, "f_print_objects: o_picture_print not implemented yet\n");
          /* o_picture_print(); */
          break;

        default:
          fprintf(stderr, "Error type!\n");
          exit(-1);
          break;
      @}

      fprintf(fp, "\n");
    @} 
    o_current = o_current->next;
  @}

  s_cue_output_all(w_current, head, fp, POSTSCRIPT);
  return;
@}

@display
@r{Defines :
@t{f_print_objects},
 -- @ref{f_print.c - f_print()}.
}
@end display
}
@end format



@section Function @code{f_print()}

@defun f_print w_current filename
@end defun

@format
@anchor{f_print.c - f_print()}
@i{<<f_print.c : f_print()>>=}@t{
int
f_print(TOPLEVEL *w_current, const char *filename)
@{
  FILE *fp;
  int origin_x, origin_y, bottom, right;
  float scale;

  /* dots are breaking my filename selection hack hack !!!! */
  fp = fopen(filename, "w");

  /* check to see if it worked */ 
  if (fp == NULL) @{
    s_log_message("Could not open [%s] for printing\n", filename);
    return(-1);
  @}

  /*    printf("%d %d\n", w_current->paper_width, w_current->paper_height);*/

  world_get_complex_bounds(w_current, 
                           w_current->page_current->object_head, 
                           &origin_x, &origin_y, 
                           &right, &bottom);


  /* go inside if if output type is EXTENTS or EXTENTS_NOMARGINS */
  if (w_current->print_output_type != WINDOW) @{

    if (w_current->print_orientation == LANDSCAPE) @{
      scale = f_print_header(w_current, fp, 
                             w_current->paper_width, 
                             w_current->paper_height,  
                             right-origin_x, bottom-origin_y);  
    @} else @{
      scale = f_print_header(w_current, fp, 
                             w_current->paper_height,  
                             w_current->paper_width, 
                             right-origin_x, bottom-origin_y);  
    @}

#if DEBUG
    printf("scale: %f\n", scale);
#endif

    f_print_objects(w_current, fp, 
                    w_current->page_current->object_head,
                    -1, -1, scale);
  @} else @{
    scale = f_print_header(w_current, fp, 
                           w_current->paper_width, w_current->paper_height, 
                           w_current->page_current->right - 
                           w_current->page_current->left,  
                           w_current->page_current->bottom -
                           w_current->page_current->top);

#if DEBUG 
    printf("scale: %f\n", scale);
#endif  
    f_print_objects(w_current, fp, 
                    w_current->page_current->object_head,
                    w_current->page_current->left,
                    w_current->page_current->top, scale);
  @} 

  f_print_footer(fp);

  fclose(fp);
  return(0);
@}

@display
@r{Defines :
@t{f_print},
 -- @ref{f_print.c - -root-}.
}
@end display
@display
@r{Uses :
@t{f_print_footer},  -- @ref{f_print.c - f_print_footer()}.
@t{f_print_header},  -- @ref{f_print.c - f_print_header()}.
@t{f_print_objects},  -- @ref{f_print.c - f_print_objects()}.
}
@end display
}
@end format



@section Function @code{f_print_set_type()}

@defun f_print_set_type w_current type
@end defun

@format
@anchor{f_print.c - f_print_set_type()}
@i{<<f_print.c : f_print_set_type()>>=}@t{
void
f_print_set_type(TOPLEVEL *w_current, int type)
@{
  w_current->print_output_type = type;
@}

@display
@r{Defines :
.
}
@end display
}
@end format