Back to index

tetex-bin  3.0
Classes | Defines | Typedefs | Functions
pdfobj.h File Reference
#include <stdio.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  pdf_obj
struct  pdf_boolean
struct  pdf_number
struct  pdf_string
struct  pdf_name
struct  pdf_array
struct  pdf_dict
struct  pdf_stream
struct  pdf_indirect

Defines

#define PDF_BOOLEAN   1u
#define PDF_NUMBER   2u
#define PDF_STRING   3u
#define PDF_NAME   4u
#define PDF_ARRAY   5u
#define PDF_DICT   6u
#define PDF_STREAM   7u
#define PDF_NULL   8u
#define PDF_INDIRECT   9u
#define pdf_obj_string_value(s)   ((void *)(((pdf_string *)((s)->data)) -> string))
#define pdf_obj_string_length(s)   (((pdf_string *)((s)->data)) -> length)
#define STREAM_COMPRESS   1

Typedefs

typedef unsigned char pdf_obj_type
typedef struct pdf_obj
typedef struct pdf_boolean
typedef struct pdf_number
typedef struct pdf_string
typedef struct pdf_name
typedef struct pdf_array
typedef struct pdf_dict
typedef struct pdf_stream
typedef struct pdf_indirect

Functions

void pdf_obj_set_verbose (void)
struct pdf_objpdf_new_obj (pdf_obj_type type)
void pdf_out_init (const char *filename)
void pdf_out_flush (void)
pdf_objpdf_link_obj (pdf_obj *object)
pdf_objpdf_new_null (void)
pdf_objpdf_new_boolean (char value)
void pdf_set_boolean (pdf_obj *object, char value)
void pdf_set_info (pdf_obj *object)
void pdf_set_root (pdf_obj *object)
pdf_objpdf_new_number (double value)
void pdf_set_number (pdf_obj *object, double value)
double pdf_number_value (pdf_obj *number)
char * pdf_name_value (pdf_obj *object)
pdf_objpdf_new_string (const void *string, unsigned length)
void pdf_set_string (pdf_obj *object, unsigned char *string, unsigned length)
voidpdf_string_value (pdf_obj *object)
unsigned int pdf_string_length (pdf_obj *object)
pdf_objpdf_new_name (const char *name)
int pdf_check_name (const char *name)
pdf_objpdf_new_array (void)
void pdf_add_array (pdf_obj *array, pdf_obj *object)
pdf_objpdf_get_array (pdf_obj *array, unsigned long index)
pdf_objpdf_new_dict (void)
void pdf_add_dict (pdf_obj *dict, pdf_obj *key, pdf_obj *value)
void pdf_merge_dict (pdf_obj *dict1, pdf_obj *dict2)
pdf_objpdf_lookup_dict (const pdf_obj *dict, const char *name)
char * pdf_get_dict (const pdf_obj *dict, int index)
pdf_objpdf_new_stream (int flags)
void pdf_obj_set_compression (int level)
void pdf_add_stream (pdf_obj *stream, char *stream_data, unsigned length)
pdf_objpdf_stream_dict (pdf_obj *stream)
void pdf_release_obj (pdf_obj *object)
pdf_objpdf_deref_obj (pdf_obj *object)
pdf_objpdf_ref_obj (pdf_obj *object)
pdf_objpdf_new_ref (unsigned long label, int generation)
pdf_objpdf_ref_file_obj (unsigned long obj_no)
void pdf_write_obj (FILE *file, const pdf_obj *object)
pdf_objpdf_open (FILE *file)
void pdf_close (void)
int pdfobj_escape_str (char *buffer, int size, unsigned char *s, int len, int remap)
int check_for_pdf (FILE *file)
void pdf_set_version (unsigned version)
pdf_objpdf_read_object (unsigned long obj_no)
void pdf_error_cleanup (void)

Class Documentation

struct pdf_obj

Definition at line 46 of file pdfobj.h.

Class Members
void * data
unsigned generation
unsigned long label
unsigned refcount
pdf_obj_type type
struct pdf_boolean

Definition at line 57 of file pdfobj.h.

Class Members
char value
struct pdf_number

Definition at line 64 of file pdfobj.h.

Class Members
double value
struct pdf_string

Definition at line 70 of file pdfobj.h.

Class Members
unsigned length
unsigned char * string
struct pdf_name

Definition at line 78 of file pdfobj.h.

Class Members
char * name
struct pdf_array

Definition at line 85 of file pdfobj.h.

Collaboration diagram for pdf_array:
Class Members
unsigned long max
unsigned long size
pdf_obj ** values
struct pdf_dict

Definition at line 92 of file pdfobj.h.

Collaboration diagram for pdf_dict:
Class Members
pdf_obj * key
struct pdf_dict * next
pdf_obj * value
struct pdf_stream

Definition at line 100 of file pdfobj.h.

Collaboration diagram for pdf_stream:
Class Members
unsigned char _flags
struct pdf_obj * dict
unsigned long max_length
char * stream
unsigned long stream_length
struct pdf_indirect

Definition at line 110 of file pdfobj.h.

Class Members
int dirty
FILE * dirty_file
unsigned generation
unsigned label

Define Documentation

#define PDF_ARRAY   5u

Definition at line 36 of file pdfobj.h.

#define PDF_BOOLEAN   1u

Definition at line 32 of file pdfobj.h.

#define PDF_DICT   6u

Definition at line 37 of file pdfobj.h.

#define PDF_INDIRECT   9u

Definition at line 40 of file pdfobj.h.

#define PDF_NAME   4u

Definition at line 35 of file pdfobj.h.

#define PDF_NULL   8u

Definition at line 39 of file pdfobj.h.

#define PDF_NUMBER   2u

Definition at line 33 of file pdfobj.h.

#define pdf_obj_string_length (   s)    (((pdf_string *)((s)->data)) -> length)

Definition at line 143 of file pdfobj.h.

#define pdf_obj_string_value (   s)    ((void *)(((pdf_string *)((s)->data)) -> string))

Definition at line 142 of file pdfobj.h.

#define PDF_STREAM   7u

Definition at line 38 of file pdfobj.h.

#define PDF_STRING   3u

Definition at line 34 of file pdfobj.h.

#define STREAM_COMPRESS   1

Definition at line 163 of file pdfobj.h.


Typedef Documentation

typedef struct pdf_array

Definition at line 90 of file pdfobj.h.

typedef struct pdf_boolean

Definition at line 61 of file pdfobj.h.

typedef struct pdf_dict

Definition at line 98 of file pdfobj.h.

typedef struct pdf_indirect

Definition at line 119 of file pdfobj.h.

typedef struct pdf_name

Definition at line 82 of file pdfobj.h.

typedef struct pdf_number

Definition at line 68 of file pdfobj.h.

typedef struct pdf_obj

Definition at line 55 of file pdfobj.h.

typedef unsigned char pdf_obj_type

Definition at line 42 of file pdfobj.h.

typedef struct pdf_stream

Definition at line 108 of file pdfobj.h.

typedef struct pdf_string

Definition at line 75 of file pdfobj.h.


Function Documentation

int check_for_pdf ( FILE file)

Definition at line 1724 of file pdfobj.c.

{
  int result = 0;
  rewind (file);
  if (fread (work_buffer, sizeof(char), strlen("%PDF-1.x"), file) ==
      strlen("%PDF-1.x") &&
      !strncmp(work_buffer, "%PDF-1.", strlen("%PDF-1."))) {
    if (work_buffer[7] >= '0' && work_buffer[7] <= '0'+pdf_version)
      result = 1;
    else {
      fprintf (stderr, "\nVersion of PDF file (1.%c) is newer than version limit specification.\n", work_buffer[7]);
    }
  }
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pdf_add_array ( pdf_obj array,
pdf_obj object 
)

Definition at line 785 of file pdfobj.c.

{
  pdf_array *data;
  if (array == NULL || array -> type != PDF_ARRAY) {
     ERROR ("pdf_add_array:  Passed non-array object");
  }
  data = array -> data;
  if (data -> size >= data -> max) {
    data->max += ARRAY_ALLOC_SIZE;
    data->values = RENEW (data->values, data->max, pdf_obj *);
  }
  (data->values)[data->size++] = object;
  return;
}

Here is the caller graph for this function:

void pdf_add_dict ( pdf_obj dict,
pdf_obj key,
pdf_obj value 
)

Definition at line 846 of file pdfobj.c.

{
  pdf_dict *data;
  pdf_dict *new_node;
  if (key == NULL || key -> type != PDF_NAME ) {
    ERROR ("pdf_add_dict: Passed invalid key");
  }
  if (value != NULL &&
      (value -> type == 0 || value -> type > PDF_INDIRECT )) {
    ERROR ("pdf_add_dict: Passed invalid value");
  }
  if (dict == NULL || dict -> type != PDF_DICT) {
    fprintf (stderr, "key:");
    pdf_write_obj (stderr, key);
    fprintf (stderr, "value:");
    pdf_write_obj (stderr, value);
    ERROR ("pdf_add_dict:  Passed non-dict object");
  }
  data = dict -> data;
  /* If this key already exists, simply replace the value */
  while (data -> key != NULL) {
    if (!strcmp (pdf_name_value(key), pdf_name_value(data->key))) {
      /* Release the old value */
      pdf_release_obj (data->value);
      /* Release the new key (we don't need it) */
      pdf_release_obj (key);
      data->value = value;
      break;
    }
    data = data -> next;
  }
  /* If we didn't find the key, build a new "end" node and add
     the new key just before the end */
  if (data -> key == NULL) {
    new_node = NEW (1, pdf_dict);
    new_node -> key = NULL;
    new_node -> value = NULL;
    new_node -> next = NULL;
    data -> next = new_node;
    data -> key = key;
    data -> value = value;
  }
  return;
}

Here is the call graph for this function:

void pdf_add_stream ( pdf_obj stream,
char *  stream_data,
unsigned  length 
)

Definition at line 1083 of file pdfobj.c.

{
  pdf_stream *data;
  if (stream == NULL || stream -> type != PDF_STREAM) {
     ERROR ("pdf_add_stream:  Passed non-stream object");
  }
  if (length == 0)
    return;
  data = stream -> data;
  if (data -> stream_length + length > data -> max_length) {
    data -> max_length += length + STREAM_ALLOC_SIZE;
    data -> stream = RENEW (data -> stream, data->max_length, char);
  }
  memcpy ((data->stream)+(data->stream_length), stream_data,
         length);
  data->stream_length += length;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int pdf_check_name ( const char *  name)

Definition at line 631 of file pdfobj.c.

{
  static char *valid_chars =
    "!\"$&'*+,-.0123456789:;=?@ABCDEFGHIJKLMNOPQRSTUVWXYZ\\^_`abcdefghijklmnopqrstuvwxyz|~";
  if (strspn (name, valid_chars) == strlen (name))
    return 1;
  else
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1685 of file pdfobj.c.

{
  /* Following loop must be iterated because each write could trigger
     an additional indirect reference of an object with a lower
     number! */
  unsigned long i;
  int done;
  if (debug) {
    fprintf (stderr, "\npdf_close:\n");
    fprintf (stderr, "pdf_input_file=%p\n", pdf_input_file);
  }
  do {
    done = 1;
    for (i=0; i<num_input_objects; i++) {
      if (xref_table[i].direct != NULL) {
       pdf_release_obj (xref_table[i].direct);
       xref_table[i].direct = NULL;
       done = 0;
      }
    }
  } while (!done);
  /* Now take care of the indirect objects
     They had to be left around until all the direct
     objects were flushed */
  for (i=0; i<num_input_objects; i++) {
    if (xref_table[i].indirect != NULL) {
      pdf_release_obj (xref_table[i].indirect);
    }
  }
  RELEASE (xref_table);
  xref_table = NULL;
  num_input_objects = 0;
  any_open = 0;
  pdf_input_file = NULL;
  if (debug) {
    fprintf (stderr, "\nexiting pdf_close:\n");
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

pdf_obj* pdf_deref_obj ( pdf_obj object)

Definition at line 1476 of file pdfobj.c.

{
  pdf_obj *result, *tmp;
  pdf_indirect *indirect;
  if (obj == NULL)
    return NULL;
  if (obj -> type != PDF_INDIRECT) {
    return pdf_link_obj (obj);
  }
  indirect = obj -> data;
  if (!(indirect -> dirty)) {
    ERROR ("Tried to deref a non-file object");
  }
  result = pdf_read_object (indirect -> label);

  if (debug){
    fprintf (stderr, "\npdf_deref_obj: read_object returned\n");
    pdf_write_obj (stderr, result);
  }
  
  while (result && result -> type == PDF_INDIRECT) {
    tmp = pdf_read_object (result -> label);
    pdf_release_obj (result);
    result = tmp;
  }
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 232 of file pdfobj.c.

{
  /* This routine is the cleanup required for an abnormal exit.
     For now, simply close the file. */
  if (pdf_output_file)
    MFCLOSE (pdf_output_file);
}

Here is the caller graph for this function:

pdf_obj* pdf_get_array ( pdf_obj array,
unsigned long  index 
)

Definition at line 757 of file pdfobj.c.

{
  pdf_array *data;
  pdf_obj *result = NULL;
  if (array == NULL) {
    ERROR ("pdf_get_array: passed NULL object");
  }
  if (array -> type != PDF_ARRAY) {
    ERROR ("pdf_get_array: passed non array object");
  }
  data = array -> data;
  if (index < data -> size) {
    result = (data->values)[index];
  }
  return result;
}

Here is the caller graph for this function:

char* pdf_get_dict ( const pdf_obj dict,
int  index 
)

Definition at line 952 of file pdfobj.c.

{
  pdf_dict *data;
  char *result;
  if (dict == NULL) {
    ERROR ("pdf_get_dict: passed NULL object");
  }
  if (dict -> type != PDF_DICT) {
    ERROR ("pdf_get_dict: passed non array object");
  }
  data = dict -> data;
  while (index-- > 0 && data -> next != NULL)
    data = data -> next;
  if (data -> next == NULL)
    return NULL;
  result = pdf_name_value (data -> key);
  return result;
}

Here is the call graph for this function:

pdf_obj* pdf_link_obj ( pdf_obj object)

Definition at line 330 of file pdfobj.c.

{
  if (object == NULL)
    ERROR ("pdf_link_obj passed null pointer");
  object -> refcount += 1;
  return object;
}

Here is the caller graph for this function:

pdf_obj* pdf_lookup_dict ( const pdf_obj dict,
const char *  name 
)

Definition at line 917 of file pdfobj.c.

{
  pdf_dict *data;
  if (dict == NULL || dict ->type != PDF_DICT) 
    ERROR ("pdf_lookup_dict:  Passed invalid dictionary");
  data = dict -> data;
  while (data -> key != NULL) {
    if (pdf_match_name (data -> key, name))
      return data -> value;
    data = data -> next;
  }
  return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pdf_merge_dict ( pdf_obj dict1,
pdf_obj dict2 
)

Definition at line 895 of file pdfobj.c.

{
  pdf_dict *data;
  if (dict1 == NULL || dict1 -> type != PDF_DICT) 
    ERROR ("pdf_merge_dict:  Passed invalid first dictionary");
  if (dict2 == NULL || dict2 -> type != PDF_DICT)
    ERROR ("pdf_merge_dict:  Passed invalid second dictionary");
  data = dict2 -> data;
  while (data -> key != NULL) {
    pdf_add_dict (dict1, pdf_link_obj(data -> key),
                pdf_link_obj (data -> value));
    data = data -> next;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* pdf_name_value ( pdf_obj object)

Definition at line 712 of file pdfobj.c.

{
  pdf_name *data;
  if (object == NULL || object -> type != PDF_NAME) {
     ERROR ("pdf_name_value:  Passed non-name object");
  }
  data = object -> data;
  if (data -> name == NULL)
    return NULL;
  return data -> name;
}

Here is the caller graph for this function:

Definition at line 725 of file pdfobj.c.

{
  pdf_obj *result;
  pdf_array *data;
  result = pdf_new_obj (PDF_ARRAY);
  data = NEW (1, pdf_array);
  data -> values = NULL;
  data -> max = 0;
  data -> size = 0;
  result -> data = data;
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

pdf_obj* pdf_new_boolean ( char  value)

Definition at line 433 of file pdfobj.c.

{
  pdf_obj *result;
  pdf_boolean *data;
  result = pdf_new_obj (PDF_BOOLEAN);
  data = NEW (1, pdf_boolean);
  result -> data = data;
  data -> value = value;
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 820 of file pdfobj.c.

{
  pdf_obj *result;
  pdf_dict *data;
  result = pdf_new_obj (PDF_DICT);
  data = NEW (1, pdf_dict);
  data -> key = NULL;
  data -> value = NULL;
  data -> next = NULL;
  result -> data = data;
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

pdf_obj* pdf_new_name ( const char *  name)

Definition at line 641 of file pdfobj.c.

{
  pdf_obj *result;
  unsigned length = strlen (name);
  pdf_name *data;
  if (!pdf_check_name (name)) {
    fprintf (stderr, "Invalid PDF name \"%s\"\n", name);
    ERROR ("pdf_new_name:  invalid PDF name");
  }
  result = pdf_new_obj (PDF_NAME);
  data = NEW (1, pdf_name);
  result -> data = data;
  if (length != 0) {
    data -> name = NEW (length+1, char);
    memcpy (data -> name, name, length);
    (data->name)[length] = 0;
  } else 
    data -> name = NULL;
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 415 of file pdfobj.c.

{
  pdf_obj *result;
  result = pdf_new_obj (PDF_NULL);
  result -> data = NULL;
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

pdf_obj* pdf_new_number ( double  value)

Definition at line 467 of file pdfobj.c.

{
  pdf_obj *result;
  pdf_number *data;
  result = pdf_new_obj (PDF_NUMBER);
  data = NEW (1, pdf_number);
  result -> data = data;
  data -> value = value;
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

struct pdf_obj* pdf_new_obj ( pdf_obj_type  type) [read]

Definition at line 297 of file pdfobj.c.

{
  pdf_obj *result;
  result = NEW (1, pdf_obj);
  result -> type = type;
  result -> data = NULL;
  result -> label = 0;
  result -> generation = 0;
  result -> refcount = 1;
  return result;
}

Here is the caller graph for this function:

pdf_obj* pdf_new_ref ( unsigned long  label,
int  generation 
)

Definition at line 1387 of file pdfobj.c.

{
  pdf_obj *result;
  pdf_indirect *indirect;
  if (label >= num_input_objects || label < 0) {
    fprintf (stderr, "pdf_new_ref: Object doesn't exist\n");
    return NULL;
  }
  result = pdf_new_obj (PDF_INDIRECT);
  indirect = NEW (1, pdf_indirect);
  result -> data = indirect;
  indirect -> label = label;
  indirect -> generation = generation;
  indirect -> dirty = 1;
  indirect -> dirty_file = pdf_input_file;
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

pdf_obj* pdf_new_stream ( int  flags)

Definition at line 971 of file pdfobj.c.

{
  pdf_obj *result;
#ifdef HAVE_ZLIB  
  pdf_obj *filters = NULL;
#endif /* HAVE_ZLIB */
  pdf_stream *data;
  result = pdf_new_obj (PDF_STREAM);
  data = NEW (1, pdf_stream);
  result -> data = data;
  data -> dict = pdf_new_dict ();  /* Although we are using an arbitrary
                                  pdf_object here, it must have
                                  type=PDF_DICT and cannot be an
                                  indirect reference.  This will
                                  be checked by the output routine 
                               */
  data -> _flags = flags;
#ifdef HAVE_ZLIB
  if ((flags & STREAM_COMPRESS) && compression_level > 0) {
    if (!filters) {
      filters = pdf_new_array();
      pdf_add_dict (data -> dict, pdf_new_name ("Filter"), filters);
    }
    pdf_add_array (filters, pdf_new_name ("FlateDecode"));
  }
#endif /* HAVE_ZLIB */  

  data -> stream_length = 0;
  data -> max_length = 0;
  data -> stream = NULL;
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

pdf_obj* pdf_new_string ( const void string,
unsigned  length 
)

Definition at line 508 of file pdfobj.c.

{
  pdf_obj *result;
  pdf_string *data;
  result = pdf_new_obj (PDF_STRING);
  data = NEW (1, pdf_string);
  result -> data = data;
  if (length != 0) {
    data -> length = length;
    data -> string = NEW (length+1, unsigned char);
    memcpy (data -> string, string, length);
    data -> string[length] = 0;
  } else {
    data -> length = 0;
    data -> string = NULL;
  }
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

double pdf_number_value ( pdf_obj number)

Definition at line 500 of file pdfobj.c.

{
  if (object == NULL || object -> type != PDF_NUMBER) {
    ERROR ("pdf_obj_number_value:  Passed non-number object");
  }
  return ((pdf_number *)(object -> data)) -> value;
}

Here is the caller graph for this function:

Definition at line 102 of file pdfobj.c.

{
  if (level >= 0 && level <= 9) 
    compression_level = level;
  else {
    ERROR("set_compression: compression level");
  }
#ifndef HAVE_ZLIB_COMPRESS2
  if (level != 0) 
    fprintf (stderr, "Unable to set compression level--your zlib doesn't have compress2()\n");
#endif
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 129 of file pdfobj.c.

{
  if (verbose < 255)
    verbose += 1;
}

Here is the caller graph for this function:

pdf_obj* pdf_open ( FILE file)

Definition at line 1655 of file pdfobj.c.

{
  pdf_obj *trailer;
#ifdef MEM_DEBUG
MEM_START
#endif
  if (any_open) {
    fprintf (stderr, "\nOnly one PDF file may be open at one time.\n");
    any_open = 1;
    exit(1);
  }
  pdf_input_file = file;
  if (!check_for_pdf (pdf_input_file)) {
    fprintf (stderr, "pdf_open: Not a PDF 1.[1-3] file\n");
    return NULL;
  }
  if ((trailer = read_xref()) == NULL) {
    fprintf (stderr, "No trailer.\n");
    pdf_close ();
    return NULL;
  }
  if (debug) {
    fprintf (stderr, "\nDone with xref:\n");
  }
#ifdef MEM_DEBUG
  MEM_END
#endif
  return trailer;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 213 of file pdfobj.c.

{
  if (pdf_output_file) {
    if (debug) fprintf (stderr, "pdf_obj_out_flush:  dumping xref\n");
    dump_xref();
    if (debug) fprintf (stderr, "pdf_obj_out_flush:  dumping trailer\n");
    dump_trailer();
    if (verbose) {
      if (compression_level>0) {
       fprintf (stderr, "\nCompression eliminated approximately %lu bytes",
               compression_saved);
      }
    }
    fprintf (stderr, "\n%lu bytes written",
            pdf_output_file_position);
    MFCLOSE (pdf_output_file);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pdf_out_init ( const char *  filename)

Definition at line 136 of file pdfobj.c.

{
  char v;
#ifdef MEM_DEBUG
MEM_START
#endif
  if (!(pdf_output_file = MFOPEN (filename, FOPEN_WBIN_MODE))) {
    if (strlen(filename) < 128) {
      sprintf (format_buffer, "Unable to open %s\n", filename);
    } else
      sprintf (format_buffer, "Unable to open file");
    ERROR (format_buffer);
  }
  pdf_out (pdf_output_file, "%PDF-1.", strlen("%PDF-1."));
  v = '0'+pdf_version;
  pdf_out (pdf_output_file, &v, 1);
  pdf_out (pdf_output_file, "\n", 1);
#ifdef MEM_DEBUG
MEM_END
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

pdf_obj* pdf_read_object ( unsigned long  obj_no)

Definition at line 1405 of file pdfobj.c.

{
  long start_pos, end_pos;
  char *buffer, *number, *parse_pointer, *end;
  pdf_obj *result;
#ifdef MEM_DEBUG
MEM_START
#endif
  if (debug) {
    fprintf (stderr, "\nread_object: obj=%lu\n", obj_no);
  }
  if (obj_no < 0 || obj_no >= num_input_objects) {
    fprintf (stderr, "\nTrying to read nonexistent object\n");
    return NULL;
  }
  if (!xref_table[obj_no].used) {
    fprintf (stderr, "\nTrying to read deleted object\n");
    return NULL;
  }
  if (debug) {
    fprintf (stderr, "\nobj@%lu\n", xref_table[obj_no].position);
  }
  seek_absolute (pdf_input_file, start_pos =
               xref_table[obj_no].position);
  end_pos = next_object (obj_no);
  if (debug) {
    fprintf (stderr, "\nendobj@%lu\n", end_pos);
  }
  buffer = NEW (end_pos - start_pos+1, char);
  fread (buffer, sizeof(char), end_pos-start_pos, pdf_input_file);
  buffer[end_pos-start_pos] = 0;
  if (debug) {
    fprintf (stderr, "\nobject:\n%s", buffer);
  }
  parse_pointer = buffer;
  end = buffer+(end_pos-start_pos);
  skip_white (&parse_pointer, end);
  number = parse_number (&parse_pointer, end);
  if ((int) atof(number) != obj_no) {
    fprintf (stderr, "Object number doesn't match\n");
    RELEASE (buffer);
    return NULL;
  }
  if (number != NULL)
    RELEASE(number);
  skip_white (&parse_pointer, end);
  number = parse_number (&parse_pointer, end);
  if (number != NULL)
    RELEASE(number);
  skip_white(&parse_pointer, end);
  if (strncmp(parse_pointer, "obj", strlen("obj"))) {
    fprintf (stderr, "Didn't find \"obj\"\n");
    RELEASE (buffer);
    return (NULL);
  }
  parse_pointer += strlen("obj");
  result = parse_pdf_object (&parse_pointer, end);
  skip_white (&parse_pointer, end);
  if (strncmp(parse_pointer, "endobj", strlen("endobj"))) {
    fprintf (stderr, "Didn't find \"endobj\"\n");
    if (result != NULL)
      pdf_release_obj (result);
    result = NULL;
  }
  RELEASE (buffer);
  return (result);
#ifdef MEM_DEBUG
MEM_END
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

pdf_obj* pdf_ref_file_obj ( unsigned long  obj_no)

Definition at line 1359 of file pdfobj.c.

{
  pdf_obj *direct, *indirect;
#ifdef MEM_DEBUG
MEM_START
#endif
  if (obj_no >= num_input_objects) {
    fprintf (stderr, "\n\npdf_ref_file_obj: nonexistent object\n");
    return NULL;
  }
  if (xref_table[obj_no].indirect != NULL) {
    return pdf_link_obj(xref_table[obj_no].indirect);
  }
  if ((direct = pdf_read_object (obj_no)) == NULL) {
    fprintf (stderr, "\npdf_ref_file_obj: Could not read object\n");
    return NULL;
  }
  indirect = pdf_ref_obj (direct);
  xref_table[obj_no].indirect = indirect;
  xref_table[obj_no].direct = direct;
  /* Make sure the caller can't doesn't free this object */
#ifdef MEM_DEBUG
MEM_END
#endif
  return pdf_link_obj(indirect);
}

Here is the call graph for this function:

Here is the caller graph for this function:

pdf_obj* pdf_ref_obj ( pdf_obj object)

Definition at line 339 of file pdfobj.c.

{
  pdf_obj *result;
  pdf_indirect *indirect;
  
  if (object == NULL)
    ERROR ("pdf_ref_obj passed null pointer");
  
  if (object -> refcount == 0) {
    fprintf (stderr, "\npdf_ref_obj:  Called with already released object");
    pdf_write_obj (stderr, object);
    ERROR ("Fatal Error\n");
  }
  result = pdf_new_obj (PDF_INDIRECT);
  indirect = NEW (1, pdf_indirect);
  result -> data = indirect;
  if (object -> type == PDF_INDIRECT) { /* If an object is already an indirect reference,
                                      reference the original
                                      object, not the indirect
                                      one */
    indirect -> label = ((pdf_indirect *) (object -> data)) -> label;
    indirect -> generation = ((pdf_indirect *) (object -> data)) -> generation;
    indirect -> dirty = ((pdf_indirect *) (object -> data)) -> dirty;
    indirect -> dirty_file = ((pdf_indirect *) (object -> data)) -> dirty_file;
  } else {
    if (object -> label == 0) {
      pdf_label_obj (object);
    }
    indirect -> label = object -> label;
    indirect -> generation = object -> generation;
    indirect -> dirty = 0;
    indirect -> dirty_file = NULL;
  }
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pdf_release_obj ( pdf_obj object)

Definition at line 1160 of file pdfobj.c.

{
  if (object == NULL)
    return;
  if (object -> type > PDF_INDIRECT ||
      object -> refcount <= 0) {
    fprintf (stderr, "pdf_release_obj: object = %p, type = %d\n", object, object ->
            type);
    pdf_write_obj (stderr, object);
    ERROR ("pdf_release_obj:  Called with invalid object");
  }
  object -> refcount -= 1;
    if (object -> refcount == 0) { /* Nothing is using this object so it's okay to
                                remove it */
    /* Nonzero "label" means object needs to be written before it's destroyed*/
    if (object -> label && pdf_output_file != NULL) { 
      pdf_flush_obj (pdf_output_file, object);
    }
    switch (object -> type) {
    case PDF_BOOLEAN:
      release_boolean (object -> data);
      break;
    case PDF_NULL:
      release_null (object -> data);
      break;
    case PDF_NUMBER:
      release_number (object -> data);
      break;
    case PDF_STRING:
      release_string (object -> data);
      break;
    case PDF_NAME:
      release_name (object -> data);
      break;
    case PDF_ARRAY:
      release_array (object -> data);
      break;
    case PDF_DICT:
      release_dict (object -> data);
      break;
    case PDF_STREAM:
      release_stream (object -> data);
      break;
    case PDF_INDIRECT:
      release_indirect (object -> data);
      break;
    }
  /* This might help detect freeing already freed objects */
    /*  object -> type = -1;*/
    RELEASE (object);
  }
}

Here is the call graph for this function:

void pdf_set_boolean ( pdf_obj object,
char  value 
)

Definition at line 459 of file pdfobj.c.

{
   if (object == NULL || object -> type != PDF_BOOLEAN) {
     ERROR ("pdf_set_boolean:  Passed non-boolean object");
   }
   ((pdf_boolean *) (object -> data)) -> value = value;
}
void pdf_set_info ( pdf_obj object)

Definition at line 252 of file pdfobj.c.

{
  if (pdf_info_obj != 0) {
    ERROR ("pdf_set_info:  info object already set");
  }
  if (object -> label == 0) {  /* Make sure this object has a label */
    pdf_label_obj (object);
  }
  pdf_info_obj = object -> label;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pdf_set_number ( pdf_obj object,
double  value 
)

Definition at line 492 of file pdfobj.c.

{
   if (object == NULL || object -> type != PDF_NUMBER) {
     ERROR ("pdf_set_number:  Passed non-number object");
   }
   ((pdf_number *) (object -> data)) -> value = value;
}

Here is the caller graph for this function:

void pdf_set_root ( pdf_obj object)

Definition at line 241 of file pdfobj.c.

{
  if (pdf_root_obj != 0) {
    ERROR ("pdf_set_root:  root object already set");
  }
  if (object -> label == 0) {  /* Make sure this object has a label */
    pdf_label_obj (object);
  }
  pdf_root_obj = object -> label;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pdf_set_string ( pdf_obj object,
unsigned char *  string,
unsigned  length 
)

Definition at line 609 of file pdfobj.c.

{
  pdf_string *data;
  if (object == NULL || object -> type != PDF_STRING) {
     ERROR ("pdf_set_string:  Passed non-string object");
  }
  data = object -> data;
  if (data -> length != 0) {
    RELEASE (data -> string);
  }
  if (length != 0) {
    data -> length = length;
    data -> string = NEW (length+1, unsigned char);
    memcpy (data -> string, string, length);
    (data->string)[length] = 0;
  } else {
    data -> length = 0;
    data -> string = NULL;
  }
  return;
}

Here is the call graph for this function:

void pdf_set_version ( unsigned  version)

Definition at line 117 of file pdfobj.c.

{
  if (version >= 2 && version <= 3) {
    pdf_version = version;
  }
}

Here is the caller graph for this function:

Definition at line 1073 of file pdfobj.c.

{
  pdf_stream *data;
  if (stream == NULL || stream -> type != PDF_STREAM) {
     ERROR ("pdf_stream_dict:  Passed non-stream object");
  }
  data = stream -> data;
  return data -> dict;
}

Here is the caller graph for this function:

unsigned int pdf_string_length ( pdf_obj object)

Definition at line 534 of file pdfobj.c.

{
  pdf_string *data;
  data = a_pdf_string -> data;
  return (data -> length);
}

Here is the caller graph for this function:

void* pdf_string_value ( pdf_obj object)

Definition at line 527 of file pdfobj.c.

{
  pdf_string *data;
  data = a_pdf_string -> data;
  return data -> string;
}

Here is the caller graph for this function:

void pdf_write_obj ( FILE file,
const pdf_obj object 
)

Definition at line 1101 of file pdfobj.c.

{
  if (object == NULL) {
    write_null(file);
    return;
  }
  if (object -> type > PDF_INDIRECT) {
    fprintf (stderr, "Object type = %d\n", object -> type);
    ERROR ("pdf_write_obj:  Called with invalid object");
  }
  if (file == stderr)
    fprintf (stderr, "{%d}", object -> refcount);
  switch (object -> type) {
  case PDF_BOOLEAN:
    write_boolean (file, object -> data);
    break;
  case PDF_NUMBER:
    write_number (file, object -> data);
    break;
  case PDF_STRING:
    write_string (file, object -> data);
    break;
  case PDF_NAME:
    write_name (file, object -> data);
    break;
  case PDF_ARRAY:
    write_array (file, object -> data);
    break;
  case PDF_DICT:
    write_dict (file, object -> data);
    break;
  case PDF_STREAM:
    write_stream (file, object -> data);
    break;
  case PDF_NULL:
    write_null (file);
    break;
  case PDF_INDIRECT:
    write_indirect (file, object -> data);
    break;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

int pdfobj_escape_str ( char *  buffer,
int  size,
unsigned char *  s,
int  len,
int  remap 
)

Definition at line 545 of file pdfobj.c.

{
  int result = 0, i;
  unsigned char ch;
  for (i=0; i<len; i++) {
    ch = remap? twiddle(s[i]): s[i];
    /* Exit as fast as possible for printable characters */
    if (result+4 > bufsize)
      ERROR ("pdfobj_escape_str: Buffer overflow");
    if (ch < 32 || ch > 126) {
      buffer[result++] = '\\';
      sprintf (buffer+result, "%03o", ch);
      result += strlen (buffer+result);
      continue;
    }
    switch (ch) {
    case '(':
      buffer[result++] = '\\';
      buffer[result++] = '(';
      break;
    case ')':
      buffer[result++] = '\\';
      buffer[result++] = ')';
      break;
    case '\\':
      buffer[result++] = '\\';
      buffer[result++] = '\\';
      break;
    default:
      buffer[result++] = ch;
      break;
    }
  }
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function: