Changeset 419 for trunk/Jgraph/draw.c


Ignore:
Timestamp:
02/27/08 07:09:03 (16 years ago)
Author:
Nicholas Riley
Message:

Jgraph: Debian changes by pzn@…

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Jgraph/draw.c

    r418 r419  
    99#include <stdio.h>
    1010#include <math.h>
     11#include <stdlib.h> //by pzn@debian.org
     12#include <string.h> //by pzn@debian.org
    1113
    1214static char real_eof = EOF;
     
    315317              }
    316318              for (i = 0; i < 4; i++) {
    317                 if (fscanf(f, "%d", &(bb[i])) != 1) {
     319                if (fscanf(f, "%d", &(bb[i])) == NULL) {
    318320                  fprintf(stderr, "Error: Eps file '%s': eof in %s\n",
    319321                          c->eps, "bounding box");
     
    642644  Graphs gs_p;
    643645  Graph g;
     646  int page_counter=0;
    644647
    645648  for (gs_p = first(gs); gs_p != nil(gs); gs_p = next(gs_p)) {
     649    page_counter++;
    646650    draw_header(gs_p, pp, landscape);
    647651    for (g = first(gs_p->g); g != nil(gs_p->g); g = next(g)) {
     
    649653    }
    650654    draw_footer(gs_p, pp);
     655  }
     656  if (pp) {
     657      printf("\n%%%%Trailer\n");
     658      printf("%%%%Pages: %i\n",page_counter);
     659      printf("%%%%EOF\n");
    651660  }
    652661}
     
    660669  char c;
    661670
    662   if (gs->page == 1) printf("%%!PS-Adobe-2.0 EPSF-1.2\n");
    663   printf("%%%%Page: %d %d\n", gs->page, gs->page);
    664   if (landscape) {
    665     printf("%%%%BoundingBox: %d %d %d %d\n", gs->bb[1], gs->bb[0],
    666             gs->bb[3], gs->bb[2]);
     671  if (gs->page == 1) {
     672      if (pp) {
     673          printf("%%!PS-Adobe-3.0\n");
     674          printf("%%%%Pages: (atend)\n");
     675          printf("%%%%Creator: jgraph\n");
     676          printf("%%%%EndComments\n\n");
     677          printf("%%%%BeginProlog\n");
     678          printf("%%%%EndProlog\n");
     679          printf("%%%%BeginSetup\n");
     680          printf("%%%%EndSetup\n");
     681      } else {
     682          printf("%%!PS-Adobe-2.0 EPSF-1.2\n");
     683          printf("%%%%Creator: jgraph\n");
     684      }
     685  }
     686
     687  if (pp) {
     688      printf("\n%%%%Page: %d %d\n", gs->page, gs->page);
     689      printf("%%%%BeginPageSetup\n");
     690      printf("%%%%EndPageSetup\n\n");
     691  }
     692
     693  if ( (gs->page>1) && !pp ) {
     694      /* tring EPS with more than one page */
     695      fprintf(stderr, "Error: 'newpage' token is not allowed"
     696              " without '-P' command line option.\n");
     697      exit(1);
     698  }
     699
     700  /* if (landscape) {
     701      printf("%%%%BoundingBox: %d %d %d %d\n", gs->bb[1], gs->bb[0],
     702             gs->bb[3], gs->bb[2]);
    667703  } else {
    668     printf("%%%%BoundingBox: %d %d %d %d\n", gs->bb[0], gs->bb[1],
    669             gs->bb[2], gs->bb[3]);
    670   }
    671 
    672   printf("%%%%EndComments\n");
     704      printf("%%%%BoundingBox: %d %d %d %d\n", gs->bb[0], gs->bb[1],
     705             gs->bb[2], gs->bb[3]);
     706  }
     707  printf("%%%%EndComments\n"); */
     708
     709  //BEGIN added by pzn@debian.org
     710  { // expands the bounding box to fit characters with tilde, acute,...
     711    // if user has set JGRAPH_BORDER enviroment variable
     712    int expandborder=0;
     713    char *s;                          \
     714    s=(char *)getenv("JGRAPH_BORDER");
     715    if (s!=NULL) {
     716        expandborder=atoi(s);
     717    }
     718   if (!pp) {
     719    if (landscape) {
     720      printf("%%%%BoundingBox: %d %d %d %d\n", gs->bb[1]-expandborder,
     721             gs->bb[0]-expandborder, gs->bb[3]+expandborder,
     722             gs->bb[2]+expandborder);
     723    } else {
     724      printf("%%%%BoundingBox: %d %d %d %d\n", gs->bb[0]-expandborder,
     725             gs->bb[1]-expandborder, gs->bb[2]+expandborder,
     726             gs->bb[3]+expandborder);
     727    }
     728    printf("%%%%EndComments\n\n");
     729   }
     730  }
     731
     732  if (gs->page==1)
     733  //reencode fonts to ISOLatin1 or other
     734  {   //NOTE: this is a preliminary version. It will only work with
     735      //      the default fonts, that are Times-Roman and Times-Bold
     736      // "export JGRAPH_ENCODING=ISOLatin1Encoding" will work in sh
     737      char *s;                          \
     738      s=(char *)getenv("JGRAPH_ENCODING");
     739      if ((s!=NULL) && (strlen(s)>0)) {
     740          comment("Setting font encoding by pzn@debian.org");
     741          printf("/Times-Bold findfont\n");
     742          printf("dup length dict begin\n");
     743          printf(" {1 index /FID ne {def} {pop pop} ifelse} forall\n");
     744          printf(" /Encoding %s def\n",s);
     745          printf(" currentdict\n");
     746          printf("end\n");
     747          printf("/Times-Bold exch definefont pop\n");
     748          printf("/Times-Roman findfont\n");
     749          printf("dup length dict begin\n");
     750          printf(" {1 index /FID ne {def} {pop pop} ifelse} forall\n");
     751          printf(" /Encoding %s def\n",s);
     752          printf(" currentdict\n");
     753          printf("end\n");
     754          printf("/Times-Roman exch definefont pop\n");
     755          comment("End of font encoding");
     756          printf("\n");
     757      }
     758  }
     759  //END added by pzn
     760
    673761  if (landscape) {
    674762    printf("-90 rotate\n");
     
    771859  grestore();
    772860  if (pp) printf("showpage\n"); else printf("\n");
    773 }
    774 
     861
     862  if (pp) {
     863      printf("%%%%PageTrailer\n");
     864  }
     865
     866}
     867
Note: See TracChangeset for help on using the changeset viewer.