Evince
Evince is a document viewer capable of displaying multiple and single page document formats like PDF and Postscript.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
tiff2ps.h File Reference
#include <glib.h>
#include <stdio.h>
#include "tiffio.h"
+ Include dependency graph for tiff2ps.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef struct _TIFF2PSContext TIFF2PSContext
 

Functions

TIFF2PSContexttiff2ps_context_new (const gchar *filename)
 
void tiff2ps_process_page (TIFF2PSContext *ctx, TIFF *tif, double pagewidth, double pageheight, double leftmargin, double bottommargin, gboolean center)
 
void tiff2ps_context_finalize (TIFF2PSContext *ctx)
 

Typedef Documentation

Definition at line 23 of file tiff2ps.h.

Function Documentation

void tiff2ps_context_finalize ( TIFF2PSContext ctx)

Definition at line 188 of file tiff2ps.c.

188  {
189  PSTail(ctx);
190  fclose(ctx->fd);
191  g_free(ctx->filename);
192  g_free(ctx);
193 }

+ Here is the caller graph for this function:

TIFF2PSContext* tiff2ps_context_new ( const gchar *  filename)

Definition at line 172 of file tiff2ps.c.

172  {
173  TIFF2PSContext* ctx;
174 
175  ctx = g_new0(TIFF2PSContext, 1);
176  ctx->filename = g_strdup(filename);
177  ctx->fd = g_fopen(ctx->filename, "w");
178  if (ctx->fd == NULL) {
179  g_free (ctx->filename);
180  g_free (ctx);
181  return NULL;
182  }
183  ctx->interpolate = TRUE; /* interpolate level2 image */
184  ctx->PSavoiddeadzone = TRUE; /* enable avoiding printer deadzone */
185  return ctx;
186 }

+ Here is the caller graph for this function:

void tiff2ps_process_page ( TIFF2PSContext ctx,
TIFF *  tif,
double  pagewidth,
double  pageheight,
double  leftmargin,
double  bottommargin,
gboolean  center 
)

Definition at line 454 of file tiff2ps.c.

456 {
457  uint32 w, h;
458  float ox, oy;
459  double prw, prh;
460  double scale = 1.0;
461  double left_offset = lm * PS_UNIT_SIZE;
462  double bottom_offset = bm * PS_UNIT_SIZE;
463  uint16* sampleinfo;
464  int split;
465  /* buffers for locale-insitive number formatting */
466  gchar buf[2][G_ASCII_DTOSTR_BUF_SIZE];
467 
468  if (!TIFFGetField(tif, TIFFTAG_XPOSITION, &ox))
469  ox = 0;
470  if (!TIFFGetField(tif, TIFFTAG_YPOSITION, &oy))
471  oy = 0;
472  setupPageState(ctx, tif, &w, &h, &prw, &prh);
473 
474  ctx->tf_numberstrips = TIFFNumberOfStrips(tif);
475  TIFFGetFieldDefaulted(tif, TIFFTAG_ROWSPERSTRIP,
476  &ctx->tf_rowsperstrip);
477  setupPageState(ctx, tif, &w, &h, &prw, &prh);
478  if (!ctx->npages)
479  PSHead(ctx, tif, w, h, prw, prh, ox, oy);
480  TIFFGetFieldDefaulted(tif, TIFFTAG_BITSPERSAMPLE,
481  &ctx->bitspersample);
482  TIFFGetFieldDefaulted(tif, TIFFTAG_SAMPLESPERPIXEL,
483  &ctx->samplesperpixel);
484  TIFFGetFieldDefaulted(tif, TIFFTAG_PLANARCONFIG,
485  &ctx->planarconfiguration);
486  TIFFGetField(tif, TIFFTAG_COMPRESSION, &ctx->compression);
487  TIFFGetFieldDefaulted(tif, TIFFTAG_EXTRASAMPLES,
488  &ctx->extrasamples, &sampleinfo);
489  ctx->alpha = (ctx->extrasamples == 1 &&
490  sampleinfo[0] == EXTRASAMPLE_ASSOCALPHA);
491  if (!TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &ctx->photometric)) {
492  switch (ctx->samplesperpixel - ctx->extrasamples) {
493  case 1:
494  if (isCCITTCompression(tif))
495  ctx->photometric = PHOTOMETRIC_MINISWHITE;
496  else
497  ctx->photometric = PHOTOMETRIC_MINISBLACK;
498  break;
499  case 3:
500  ctx->photometric = PHOTOMETRIC_RGB;
501  break;
502  case 4:
503  ctx->photometric = PHOTOMETRIC_SEPARATED;
504  break;
505  }
506  }
507  if (checkImage(ctx, tif)) {
508  ctx->tf_bytesperrow = TIFFScanlineSize(tif);
509  ctx->npages++;
510  fprintf(ctx->fd, "%%%%Page: %d %d\n", ctx->npages,
511  ctx->npages);
512  if (!ctx->generateEPSF && ( ctx->level2 || ctx->level3 )) {
513  double psw = 0.0, psh = 0.0;
514  if (psw != 0.0) {
515  psw = pw * PS_UNIT_SIZE;
516  if (ctx->res_unit == RESUNIT_CENTIMETER)
517  psw *= 2.54F;
518  } else
519  psw=ctx->rotate ? prh:prw;
520  if (psh != 0.0) {
521  psh = ph * PS_UNIT_SIZE;
522  if (ctx->res_unit == RESUNIT_CENTIMETER)
523  psh *= 2.54F;
524  } else
525  psh=ctx->rotate ? prw:prh;
526  fprintf(ctx->fd,
527  "1 dict begin /PageSize [ %s %s ] def currentdict end setpagedevice\n",
528  g_ascii_dtostr(buf[0], sizeof(buf[0]), psw),
529  g_ascii_dtostr(buf[1], sizeof(buf[1]), psh));
530  fputs(
531  "<<\n /Policies <<\n /PageSize 3\n >>\n>> setpagedevice\n",
532  ctx->fd);
533  }
534  fprintf(ctx->fd, "gsave\n");
535  fprintf(ctx->fd, "100 dict begin\n");
536  if (pw != 0 || ph != 0) {
537  if (!pw)
538  pw = prw;
539  if (!ph)
540  ph = prh;
541  if (ctx->maxPageHeight) { /* used -H option */
542  split = PlaceImage(ctx,pw,ph,prw,prh,
543  0,lm,bm,cnt);
544  while( split ) {
545  PSpage(ctx, tif, w, h);
546  fprintf(ctx->fd, "end\n");
547  fprintf(ctx->fd, "grestore\n");
548  fprintf(ctx->fd, "showpage\n");
549  ctx->npages++;
550  fprintf(ctx->fd, "%%%%Page: %d %d\n",
551  ctx->npages, ctx->npages);
552  fprintf(ctx->fd, "gsave\n");
553  fprintf(ctx->fd, "100 dict begin\n");
554  split = PlaceImage(ctx,pw,ph,prw,prh,
555  split,lm,bm,cnt);
556  }
557  } else {
558  pw *= PS_UNIT_SIZE;
559  ph *= PS_UNIT_SIZE;
560 
561  /* NB: maintain image aspect ratio */
562  scale = pw/prw < ph/prh ?
563  pw/prw : ph/prh;
564  if (scale > 1.0)
565  scale = 1.0;
566  if (cnt) {
567  bottom_offset +=
568  (ph - prh * scale) / 2;
569  left_offset +=
570  (pw - prw * scale) / 2;
571  }
572  fprintf(ctx->fd, "%s %s translate\n",
573  g_ascii_dtostr(buf[0], sizeof(buf[0]), left_offset),
574  g_ascii_dtostr(buf[1], sizeof(buf[1]), bottom_offset));
575  fprintf(ctx->fd, "%s %s scale\n",
576  g_ascii_dtostr(buf[0], sizeof(buf[0]), prw * scale),
577  g_ascii_dtostr(buf[1], sizeof(buf[1]), prh * scale));
578  if (ctx->rotate)
579  fputs ("1 1 translate 180 ctx->rotate\n", ctx->fd);
580  }
581  } else {
582  fprintf(ctx->fd, "%s %s scale\n",
583  g_ascii_dtostr(buf[0], sizeof(buf[0]), prw),
584  g_ascii_dtostr(buf[1], sizeof(buf[1]), prh));
585  if (ctx->rotate)
586  fputs ("1 1 translate 180 ctx->rotate\n", ctx->fd);
587  }
588  PSpage(ctx, tif, w, h);
589  fprintf(ctx->fd, "end\n");
590  fprintf(ctx->fd, "grestore\n");
591  fprintf(ctx->fd, "showpage\n");
592  }
593 }

+ Here is the caller graph for this function: