Back to index

texmacs  1.0.7.15
Defines | Typedefs | Functions
pdfobj.h File Reference
#include <stdio.h>

Go to the source code of this file.

Defines

#define PDF_BOOLEAN   1
#define PDF_NUMBER   2
#define PDF_STRING   3
#define PDF_NAME   4
#define PDF_ARRAY   5
#define PDF_DICT   6
#define PDF_STREAM   7
#define PDF_NULL   8
#define PDF_INDIRECT   9
#define PDF_UNDEFINED   10
#define PDF_OBJ_INVALID   0
#define STREAM_COMPRESS   (1 << 0)
#define PDF_OBJ_MAX_DEPTH   30
#define PDF_OBJ_NUMBERTYPE(o)   ((o) && pdf_obj_typeof((o)) == PDF_NUMBER)
#define PDF_OBJ_BOOLEANTYPE(o)   ((o) && pdf_obj_typeof((o)) == PDF_BOOLEAN)
#define PDF_OBJ_STRINGTYPE(o)   ((o) && pdf_obj_typeof((o)) == PDF_STRING)
#define PDF_OBJ_NAMETYPE(o)   ((o) && pdf_obj_typeof((o)) == PDF_NAME)
#define PDF_OBJ_ARRAYTYPE(o)   ((o) && pdf_obj_typeof((o)) == PDF_ARRAY)
#define PDF_OBJ_NULLTYPE(o)   ((o) && pdf_obj_typeof((o)) == PDF_NULL)
#define PDF_OBJ_DICTTYPE(o)   ((o) && pdf_obj_typeof((o)) == PDF_DICT)
#define PDF_OBJ_STREAMTYPE(o)   ((o) && pdf_obj_typeof((o)) == PDF_STREAM)
#define PDF_OBJ_INDIRECTTYPE(o)   ((o) && pdf_obj_typeof((o)) == PDF_INDIRECT)
#define PDF_OBJ_UNDEFINED(o)   ((o) && pdf_obj_typeof((o)) == PDF_UNDEFINED)
#define PDF_OBJ_TYPEOF(o)   pdf_obj_typeof((o))

Typedefs

typedef struct pdf_obj
typedef struct pdf_file

Functions

int pdf_obj_get_verbose (void)
void pdf_obj_set_verbose (void)
void pdf_error_cleanup (void)
void pdf_out_init (const char *filename, int do_encryption)
void pdf_out_flush (void)
void pdf_set_version (unsigned version)
unsigned pdf_get_version (void)
void pdf_release_obj (pdf_obj *object)
int pdf_obj_typeof (pdf_obj *object)
pdf_objpdf_ref_obj (pdf_obj *object)
pdf_objpdf_link_obj (pdf_obj *object)
void pdf_transfer_label (pdf_obj *dst, pdf_obj *src)
pdf_objpdf_new_undefined (void)
pdf_objpdf_new_null (void)
pdf_objpdf_new_boolean (char value)
char pdf_boolean_value (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)
pdf_objpdf_new_string (const void *str, unsigned length)
void pdf_set_string (pdf_obj *object, unsigned char *str, unsigned length)
void * pdf_string_value (pdf_obj *object)
unsigned pdf_string_length (pdf_obj *object)
pdf_objpdf_new_name (const char *name)
char * pdf_name_value (pdf_obj *object)
pdf_objpdf_new_array (void)
void pdf_add_array (pdf_obj *array, pdf_obj *object)
pdf_objpdf_get_array (pdf_obj *array, long idx)
unsigned pdf_array_length (pdf_obj *array)
void pdf_unshift_array (pdf_obj *array, pdf_obj *object)
pdf_objpdf_new_dict (void)
void pdf_remove_dict (pdf_obj *dict, const char *key)
void pdf_merge_dict (pdf_obj *dict1, pdf_obj *dict2)
pdf_objpdf_lookup_dict (pdf_obj *dict, const char *key)
pdf_objpdf_dict_keys (pdf_obj *dict)
int pdf_add_dict (pdf_obj *dict, pdf_obj *key, pdf_obj *value)
int pdf_foreach_dict (pdf_obj *dict, int(*proc)(pdf_obj *, pdf_obj *, void *), void *pdata)
pdf_objpdf_new_stream (int flags)
void pdf_add_stream (pdf_obj *stream, const void *stream_data_ptr, long stream_data_len)
int pdf_concat_stream (pdf_obj *dst, pdf_obj *src)
pdf_objpdf_stream_dict (pdf_obj *stream)
long pdf_stream_length (pdf_obj *stream)
const void * pdf_stream_dataptr (pdf_obj *stream)
int pdf_compare_reference (pdf_obj *ref1, pdf_obj *ref2)
void pdf_set_compression (int level)
void pdf_set_info (pdf_obj *obj)
void pdf_set_id (pdf_obj *id)
void pdf_set_root (pdf_obj *obj)
void pdf_set_encrypt (pdf_obj *encrypt)
void pdf_files_init (void)
void pdf_files_close (void)
int check_for_pdf (FILE *file)
pdf_filepdf_open (const char *ident, FILE *file)
void pdf_close (pdf_file *pf)
int pdf_file_get_version (pdf_file *pf)
pdf_objpdf_file_get_catalog (pdf_file *pf)
pdf_objpdf_deref_obj (pdf_obj *object)
pdf_objpdf_import_object (pdf_obj *object)
int pdfobj_escape_str (char *buffer, int size, const unsigned char *s, int len)
pdf_objpdf_new_indirect (pdf_file *pf, unsigned long label, unsigned short generation)

Define Documentation

#define PDF_ARRAY   5

Definition at line 36 of file pdfobj.h.

#define PDF_BOOLEAN   1

Definition at line 32 of file pdfobj.h.

#define PDF_DICT   6

Definition at line 37 of file pdfobj.h.

#define PDF_INDIRECT   9

Definition at line 40 of file pdfobj.h.

#define PDF_NAME   4

Definition at line 35 of file pdfobj.h.

#define PDF_NULL   8

Definition at line 39 of file pdfobj.h.

#define PDF_NUMBER   2

Definition at line 33 of file pdfobj.h.

#define PDF_OBJ_ARRAYTYPE (   o)    ((o) && pdf_obj_typeof((o)) == PDF_ARRAY)

Definition at line 71 of file pdfobj.h.

#define PDF_OBJ_BOOLEANTYPE (   o)    ((o) && pdf_obj_typeof((o)) == PDF_BOOLEAN)

Definition at line 68 of file pdfobj.h.

#define PDF_OBJ_DICTTYPE (   o)    ((o) && pdf_obj_typeof((o)) == PDF_DICT)

Definition at line 73 of file pdfobj.h.

#define PDF_OBJ_INDIRECTTYPE (   o)    ((o) && pdf_obj_typeof((o)) == PDF_INDIRECT)

Definition at line 75 of file pdfobj.h.

#define PDF_OBJ_INVALID   0

Definition at line 43 of file pdfobj.h.

#define PDF_OBJ_MAX_DEPTH   30

Definition at line 48 of file pdfobj.h.

#define PDF_OBJ_NAMETYPE (   o)    ((o) && pdf_obj_typeof((o)) == PDF_NAME)

Definition at line 70 of file pdfobj.h.

#define PDF_OBJ_NULLTYPE (   o)    ((o) && pdf_obj_typeof((o)) == PDF_NULL)

Definition at line 72 of file pdfobj.h.

#define PDF_OBJ_NUMBERTYPE (   o)    ((o) && pdf_obj_typeof((o)) == PDF_NUMBER)

Definition at line 67 of file pdfobj.h.

#define PDF_OBJ_STREAMTYPE (   o)    ((o) && pdf_obj_typeof((o)) == PDF_STREAM)

Definition at line 74 of file pdfobj.h.

#define PDF_OBJ_STRINGTYPE (   o)    ((o) && pdf_obj_typeof((o)) == PDF_STRING)

Definition at line 69 of file pdfobj.h.

#define PDF_OBJ_TYPEOF (   o)    pdf_obj_typeof((o))

Definition at line 78 of file pdfobj.h.

#define PDF_OBJ_UNDEFINED (   o)    ((o) && pdf_obj_typeof((o)) == PDF_UNDEFINED)

Definition at line 76 of file pdfobj.h.

#define PDF_STREAM   7

Definition at line 38 of file pdfobj.h.

#define PDF_STRING   3

Definition at line 34 of file pdfobj.h.

#define PDF_UNDEFINED   10

Definition at line 41 of file pdfobj.h.

#define STREAM_COMPRESS   (1 << 0)

Definition at line 45 of file pdfobj.h.


Typedef Documentation

typedef struct pdf_file

Definition at line 51 of file pdfobj.h.

typedef struct pdf_obj

Definition at line 50 of file pdfobj.h.


Function Documentation

int check_for_pdf ( FILE *  file)

Definition at line 3010 of file pdfobj.c.

{
  return (check_for_pdf_version(file) >= 0);
}

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 1234 of file pdfobj.c.

{
  pdf_array *data;

  TYPECHECK(array, PDF_ARRAY);

  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;
  data->size++;

  return;
}

Here is the caller graph for this function:

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

Definition at line 1406 of file pdfobj.c.

{
  pdf_dict *data, *new_node;

  TYPECHECK(dict, PDF_DICT);
  TYPECHECK(key,  PDF_NAME);

  /* It seems that NULL is sometimes used for null object... */
  if (value != NULL && INVALIDOBJ(value))
    ERROR("pdf_add_dict(): Passed invalid value");

  /* If this key already exists, simply replace the value */
  for (data = dict->data; data->key != NULL; data = data->next) {
    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;
      return 1;
    }
  }
  /*
   * We didn't find the key. We build a new "end" node and add
   * the new key just before the end
   */
  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 0;
}

Here is the call graph for this function:

void pdf_add_stream ( pdf_obj stream,
const void *  stream_data_ptr,
long  stream_data_len 
)

Definition at line 1792 of file pdfobj.c.

{
  pdf_stream *data;

  TYPECHECK(stream, PDF_STREAM);

  if (length < 1)
    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, unsigned char);
  }
  memcpy(data->stream + data->stream_length, stream_data, length);
  data->stream_length += length;
}

Here is the caller graph for this function:

unsigned pdf_array_length ( pdf_obj array)

Definition at line 1202 of file pdfobj.c.

{
  pdf_array *data;

  TYPECHECK(array, PDF_ARRAY);

  data = (pdf_array *) array->data;

  return (unsigned int) data->size;
}

Here is the caller graph for this function:

char pdf_boolean_value ( pdf_obj object)

Definition at line 789 of file pdfobj.c.

{
  pdf_boolean *data;

  TYPECHECK(object, PDF_BOOLEAN);

  data = object->data;

  return data->value;
}

Here is the caller graph for this function:

void pdf_close ( pdf_file pf)

Definition at line 2984 of file pdfobj.c.

{
  if (pf)
    pf->file = NULL;
}

Here is the caller graph for this function:

int pdf_compare_reference ( pdf_obj ref1,
pdf_obj ref2 
)

Definition at line 3148 of file pdfobj.c.

{
  pdf_indirect *data1, *data2;

  ASSERT(PDF_OBJ_INDIRECTTYPE(ref1) && PDF_OBJ_INDIRECTTYPE(ref2));

  data1 = (pdf_indirect *) ref1->data;
  data2 = (pdf_indirect *) ref2->data;

  return data1->pf != data2->pf || data1->label != data2->label
    || data1->generation != data2->generation;
}

Here is the caller graph for this function:

int pdf_concat_stream ( pdf_obj dst,
pdf_obj src 
)

Definition at line 1854 of file pdfobj.c.

{
  const char *stream_data;
  long        stream_length;
  pdf_obj    *stream_dict;
  pdf_obj    *filter;

  if (!PDF_OBJ_STREAMTYPE(dst) || !PDF_OBJ_STREAMTYPE(src))
    ERROR("Invalid type.");

  stream_data   = pdf_stream_dataptr(src);
  stream_length = pdf_stream_length (src);
  stream_dict   = pdf_stream_dict   (src);

  if (pdf_lookup_dict(stream_dict, "DecodeParms")) {
    WARN("Streams with DecodeParams not supported.");
    return -1;
  }

  filter = pdf_lookup_dict(stream_dict, "Filter");
  if (!filter) {
    pdf_add_stream(dst, stream_data, stream_length);
    return 0;
#if HAVE_ZLIB
  } else {
    char *filter_name;
    if (PDF_OBJ_NAMETYPE(filter)) {
      filter_name = pdf_name_value(filter);
      if (filter_name && !strcmp(filter_name, "FlateDecode"))
       return pdf_add_stream_flate(dst, stream_data, stream_length);
      else {
       WARN("DecodeFilter \"%s\" not supported.", filter_name);
       return -1;
      }
    } else if (PDF_OBJ_ARRAYTYPE(filter)) {
      if (pdf_array_length(filter) > 1) {
       WARN("Multiple DecodeFilter not supported.");
       return -1;
      } else {
       filter_name = pdf_name_value(pdf_get_array(filter, 0));
       if (filter_name && !strcmp(filter_name, "FlateDecode"))
         return pdf_add_stream_flate(dst, stream_data, stream_length);
       else {
         WARN("DecodeFilter \"%s\" not supported.", filter_name);
         return -1;
       }
      }
    } else
      ERROR("Broken PDF file?");
#endif /* HAVE_ZLIB */
  }

  return -1;
}

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 2510 of file pdfobj.c.

{
  int count = PDF_OBJ_MAX_DEPTH;

  if (obj)
    obj = pdf_link_obj(obj);

  while (PDF_OBJ_INDIRECTTYPE(obj) && --count) {
    pdf_file *pf = OBJ_FILE(obj);
    unsigned long  obj_num = OBJ_NUM(obj);
    unsigned short obj_gen = OBJ_GEN(obj);
    ASSERT(pf);
    pdf_release_obj(obj);
    obj = pdf_get_object(pf, obj_num, obj_gen);
  }

  if (!count)
    ERROR("Loop in object hierarchy detected. Broken PDF file?");

  if (PDF_OBJ_NULLTYPE(obj)) {
    pdf_release_obj(obj);
    return NULL;
  } else
    return obj;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1547 of file pdfobj.c.

{
  pdf_obj  *keys;
  pdf_dict *data;

  TYPECHECK(dict, PDF_DICT);

  keys = pdf_new_array();
  for (data = dict->data; (data &&
                        data->key != NULL); data = data->next) {
    /* We duplicate name object rather than linking keys.
     * If we forget to free keys, broken PDF is generated.
     */
    pdf_add_array(keys, pdf_new_name(pdf_name_value(data->key)));
  }

  return keys;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pdf_error_cleanup ( void  )

Definition at line 473 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:

Definition at line 2912 of file pdfobj.c.

{
  ASSERT(pf);
  return pf->catalog;
}

Here is the caller graph for this function:

Definition at line 2896 of file pdfobj.c.

{
  ASSERT(pf);
  return pf->version;
}

Here is the caller graph for this function:

void pdf_files_close ( void  )

Definition at line 2991 of file pdfobj.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void pdf_files_init ( void  )

Definition at line 2889 of file pdfobj.c.

{
  pdf_files = NEW(1, struct ht_table);
  ht_init_table(pdf_files, (void (*)(void *)) pdf_file_free);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int pdf_foreach_dict ( pdf_obj dict,
int(*)(pdf_obj *, pdf_obj *, void *)  proc,
void *  pdata 
)

Definition at line 1504 of file pdfobj.c.

{
  int       error = 0;
  pdf_dict *data;

  ASSERT(proc);

  TYPECHECK(dict, PDF_DICT);

  data = dict->data;
  while (!error &&
        data->key != NULL) {
    error = proc(data->key, data->value, pdata);
    data = data->next;
  }

  return error;
}

Here is the call graph for this function:

Here is the caller graph for this function:

pdf_obj* pdf_get_array ( pdf_obj array,
long  idx 
)

Definition at line 1184 of file pdfobj.c.

{
  pdf_obj   *result = NULL;
  pdf_array *data;

  TYPECHECK(array, PDF_ARRAY);

  data = array->data;
  if (idx < 0)
    result = data->values[idx + data->size];
  else if (idx < data->size) {
    result = data->values[idx];
  }

  return result;
}

Here is the caller graph for this function:

unsigned pdf_get_version ( void  )

Definition at line 258 of file pdfobj.c.

{
  return pdf_version;
}

Here is the caller graph for this function:

Definition at line 3081 of file pdfobj.c.

{
  pdf_obj  *imported;
  pdf_obj  *tmp;
  int       i;

  switch (pdf_obj_typeof(object)) {

  case PDF_INDIRECT:
    if (OBJ_FILE(object)) {
      imported = pdf_import_indirect(object);
    } else {
      imported = pdf_link_obj(object);
    }
    break;

  case PDF_STREAM:
    {
      pdf_obj *stream_dict;

      tmp = pdf_import_object(pdf_stream_dict(object));
      if (!tmp)
       return NULL;

      imported    = pdf_new_stream(0);
      stream_dict = pdf_stream_dict(imported);
      pdf_merge_dict(stream_dict, tmp);
      pdf_release_obj(tmp);
      pdf_add_stream(imported,
                   pdf_stream_dataptr(object),
                   pdf_stream_length(object));
    }
    break;

  case PDF_DICT:

    imported = pdf_new_dict();
    if (pdf_foreach_dict(object, import_dict, imported) < 0) {
      pdf_release_obj(imported);
      return NULL;
    }

    break;

  case PDF_ARRAY:

    imported = pdf_new_array();
    for (i = 0; i < pdf_array_length(object); i++) {
      tmp = pdf_import_object(pdf_get_array(object, i));
      if (!tmp) {
       pdf_release_obj(imported);
       return NULL;
      }
      pdf_add_array(imported, tmp);
    }
    break;

  default:
    imported = pdf_link_obj(object);
  }

  return imported;
}

Here is the call graph for this function:

Here is the caller graph for this function:

pdf_obj* pdf_link_obj ( pdf_obj object)

Definition at line 658 of file pdfobj.c.

{
  if (INVALIDOBJ(object))
    ERROR("pdf_link_obj(): passed invalid object.");

  object->refcount += 1;

  return object;
}

Here is the caller graph for this function:

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

Definition at line 1526 of file pdfobj.c.

{
  pdf_dict *data;

  ASSERT(name);

  TYPECHECK(dict, PDF_DICT);

  data = dict->data;
  while (data->key != NULL) {
    if (!strcmp(name, pdf_name_value(data->key))) {
      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 1489 of file pdfobj.c.

{
  pdf_dict *data;

  TYPECHECK(dict1, PDF_DICT);
  TYPECHECK(dict2, PDF_DICT);

  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 1129 of file pdfobj.c.

{
  pdf_name *data;

  TYPECHECK(object, PDF_NAME);

  data = object->data;

  return data->name;
}

Here is the caller graph for this function:

pdf_obj* pdf_new_array ( void  )

Definition at line 1146 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 746 of file pdfobj.c.

{
  pdf_obj     *result;
  pdf_boolean *data;

  result = pdf_new_obj(PDF_BOOLEAN);
  data   = NEW(1, pdf_boolean);
  data->value  = value;
  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_dict ( void  )

Definition at line 1371 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_indirect ( pdf_file pf,
unsigned long  label,
unsigned short  generation 
)

Definition at line 2267 of file pdfobj.c.

{
  pdf_obj      *result;
  pdf_indirect *indirect;

  indirect = NEW(1, pdf_indirect);
  indirect->pf         = pf;
  indirect->label      = obj_num;
  indirect->generation = obj_gen;

  result   = pdf_new_obj(PDF_INDIRECT);
  result->data = indirect;

  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 1034 of file pdfobj.c.

{
  pdf_obj  *result;
  unsigned  length;
  pdf_name *data;

  result = pdf_new_obj(PDF_NAME);
  data   = NEW (1, pdf_name);
  result->data = data;
  length = strlen(name);
  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:

pdf_obj* pdf_new_null ( void  )

Definition at line 723 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 801 of file pdfobj.c.

{
  pdf_obj    *result;
  pdf_number *data;

  result = pdf_new_obj(PDF_NUMBER);
  data   = NEW(1, pdf_number);
  data->value  = value;
  result->data = data;

  return result;
}

Here is the call graph for this function:

pdf_obj* pdf_new_stream ( int  flags)

Definition at line 1589 of file pdfobj.c.

{
  pdf_obj    *result;
  pdf_stream *data;

  result = pdf_new_obj(PDF_STREAM);
  data   = NEW(1, pdf_stream);
  /*
   * 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->dict   = pdf_new_dict();
  data->_flags = flags;
  data->stream = NULL;
  data->stream_length = 0;
  data->max_length    = 0;
  data->objstm_data = NULL;

  result->data = data;
  result->flags |= OBJ_NO_OBJSTM;

  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 *  str,
unsigned  length 
)

Definition at line 855 of file pdfobj.c.

{
  pdf_obj    *result;
  pdf_string *data;

  ASSERT(str);

  result = pdf_new_obj(PDF_STRING);
  data   = NEW(1, pdf_string);
  result->data = data;

  data->length = length;
  data->string = NEW(length+1, unsigned char);
  memcpy(data->string, str, length);
  /* Shouldn't assume NULL terminated. */
  data->string[length] = '\0';

  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 712 of file pdfobj.c.

{
  pdf_obj *result;

  result = pdf_new_obj(PDF_UNDEFINED);
  result->data = 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 843 of file pdfobj.c.

{
  pdf_number *data;

  TYPECHECK(object, PDF_NUMBER);

  data = object->data;

  return data->value;
}

Here is the caller graph for this function:

int pdf_obj_get_verbose ( void  )

Definition at line 264 of file pdfobj.c.

{
  return verbose;
}

Here is the caller graph for this function:

void pdf_obj_set_verbose ( void  )

Definition at line 270 of file pdfobj.c.

{
  verbose++;
}
int pdf_obj_typeof ( pdf_obj object)

Definition at line 615 of file pdfobj.c.

{
  if (INVALIDOBJ(object))
    return PDF_OBJ_INVALID;

  return object->type;
}

Here is the caller graph for this function:

pdf_file* pdf_open ( const char *  ident,
FILE *  file 
)

Definition at line 2919 of file pdfobj.c.

{
  pdf_file *pf;

  ASSERT(pdf_files);

  pf = (pdf_file *) ht_lookup_table(pdf_files, ident, strlen(ident));

  if (pf) {
    pf->file = file;
  } else {
    int version;
    pdf_obj *new_version;

    version = check_for_pdf_version(file);
    if (version < 0) {
      WARN("Not a PDF file.");
      return NULL;
    }

    pf = pdf_file_new(file);
    pf->version = version;

    if (!(pf->trailer = read_xref(pf)))
      goto error;

    if (pdf_lookup_dict(pf->trailer, "Encrypt")) {
      WARN("PDF document is encrypted.");
      goto error;
    }

    pf->catalog = pdf_deref_obj(pdf_lookup_dict(pf->trailer, "Root"));
    if (!PDF_OBJ_DICTTYPE(pf->catalog)) {
      WARN("Cannot read PDF document catalog. Broken PDF file?");
      goto error;
    }

    new_version = pdf_deref_obj(pdf_lookup_dict(pf->catalog, "Version"));
    if (new_version) {
      unsigned short minor;

      if (!PDF_OBJ_NAMETYPE(new_version) ||
         sscanf(pdf_name_value(new_version), "1.%hu", &minor) != 1) {
       pdf_release_obj(new_version);
       WARN("Illegal Version entry in document catalog. Broken PDF file?");
       goto error;
      }

      if (pf->version < minor)
       pf->version = minor;

      pdf_release_obj(new_version);
    }

    ht_append_table(pdf_files, ident, strlen(ident), pf);
  }

  return pf;

 error:
  pdf_file_free(pf);
  return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pdf_out_flush ( void  )

Definition at line 419 of file pdfobj.c.

{
  if (pdf_output_file) {
    long length;

    /* Flush current object stream */
    if (current_objstm) {
      release_objstm(current_objstm);
      current_objstm =NULL;
    }

    /*
     * Label xref stream - we need the number of correct objects
     * for the xref stream dictionary (= trailer).
     * Labelling it in pdf_out_init (with 1)  does not work (why?).
     */
    if (xref_stream)
      pdf_label_obj(xref_stream);

    /* Record where this xref is for trailer */
    startxref = pdf_output_file_position;

    pdf_add_dict(trailer_dict, pdf_new_name("Size"),
               pdf_new_number(next_label));

    if (xref_stream)
      dump_xref_stream();
    else {
      dump_xref_table();
      dump_trailer_dict();
    }

    /* Done with xref table */
    RELEASE(output_xref);

    pdf_out(pdf_output_file, "startxref\n", 10);
    length = sprintf(format_buffer, "%lu\n", startxref);
    pdf_out(pdf_output_file, format_buffer, length);
    pdf_out(pdf_output_file, "%%EOF\n", 6);

    MESG("\n");
    if (verbose) {
      if (compression_level > 0) {
       MESG("Compression saved %ld bytes%s\n", compression_saved,
            pdf_version < 5 ? ". Try \"-V 5\" for better compression" : "");
      }
    }
    MESG("%ld 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,
int  do_encryption 
)

Definition at line 295 of file pdfobj.c.

{
  char v;

  output_xref = NULL;
  pdf_max_ind_objects = 0;
  add_xref_entry(0, 0, 0, 0xffff);
  next_label = 1;

  if (pdf_version >= 5) {
    xref_stream = pdf_new_stream(STREAM_COMPRESS);
    xref_stream->flags |= OBJ_NO_ENCRYPT;
    trailer_dict = pdf_stream_dict(xref_stream);
    pdf_add_dict(trailer_dict, pdf_new_name("Type"), pdf_new_name("XRef"));
    do_objstm = 1;
  } else {
    xref_stream = NULL;
    trailer_dict = pdf_new_dict();
    do_objstm = 0;
  }

  output_stream = NULL;

  pdf_output_file = MFOPEN(filename, FOPEN_WBIN_MODE);
  if (!pdf_output_file) {
    if (strlen(filename) < 128)
      ERROR("Unable to open \"%s\".", filename);
    else
      ERROR("Unable to open file.");
  }
  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);
  pdf_out(pdf_output_file, BINARY_MARKER, strlen(BINARY_MARKER));

  enc_mode = 0;
  doc_enc_mode = do_encryption;
}

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 670 of file pdfobj.c.

{
  if (INVALIDOBJ(object))
    ERROR("pdf_ref_obj(): passed invalid object.");
  
  if (object->refcount == 0) {
    MESG("\nTrying to refer already released object!!!\n");
    pdf_write_obj(object, stderr);
    ERROR("Cannot continue...");
  }

  if (PDF_OBJ_INDIRECTTYPE(object)) {
    return pdf_link_obj(object);
  } else {
    if (object->label == 0) {
      pdf_label_obj(object);
    }
    return pdf_new_indirect(NULL, object->label, object->generation);
  }
}

Here is the call graph for this function:

void pdf_release_obj ( pdf_obj object)

Definition at line 2074 of file pdfobj.c.

{
  if (object == NULL)
    return;
  if (INVALIDOBJ(object) || object->refcount <= 0) {
    MESG("\npdf_release_obj: object=%p, type=%d, refcount=%d\n",
        object, object->type, object->refcount);
    pdf_write_obj(object, stderr);
    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) {
      if (!do_objstm || object->flags & OBJ_NO_OBJSTM
         || (doc_enc_mode && object->flags & OBJ_NO_ENCRYPT)
         || object->generation)
       pdf_flush_obj(object, pdf_output_file);
      else {
        if (!current_objstm) {
         long *data = NEW(2*OBJSTM_MAX_OBJS+2, long);
         data[0] = data[1] = 0;
         current_objstm = pdf_new_stream(STREAM_COMPRESS);
         set_objstm_data(current_objstm, data);
         pdf_label_obj(current_objstm);
       }
       if (pdf_add_objstm(current_objstm, object) == OBJSTM_MAX_OBJS) {
         release_objstm(current_objstm);
         current_objstm = NULL;
       }
      }
    }
    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;
    object->data = NULL;
    RELEASE(object);
  }
}

Here is the call graph for this function:

void pdf_remove_dict ( pdf_obj dict,
const char *  key 
)

Definition at line 1567 of file pdfobj.c.

{
  pdf_dict *data, **data_p;

  TYPECHECK(dict, PDF_DICT);

  data   = dict->data;
  data_p = (pdf_dict **) (void *) &(dict->data);
  while (data->key != NULL) {
    if (pdf_match_name(data->key, name)) {
      pdf_release_obj(data->key);
      pdf_release_obj(data->value);
      *data_p = data->next;
      RELEASE(data);
      break;
    }
    data_p = &(data->next);
    data   = data->next;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pdf_set_compression ( int  level)

Definition at line 227 of file pdfobj.c.

{
#ifndef   HAVE_ZLIB
  ERROR("You don't have compression compiled in. Possibly libz wasn't found by configure.");
#else
#ifndef HAVE_ZLIB_COMPRESS2
  if (level != 0) 
    WARN("Unable to set compression level -- your zlib doesn't have compress2().");
#endif
  if (level >= 0 && level <= 9) 
    compression_level = level;
  else {
    ERROR("set_compression: invalid compression level: %d", level);
  }
#endif /* !HAVE_ZLIB */

  return;
}

Here is the call graph for this function:

void pdf_set_encrypt ( pdf_obj encrypt)

Definition at line 516 of file pdfobj.c.

{
  if (pdf_add_dict(trailer_dict, pdf_new_name("Encrypt"), pdf_ref_obj(encrypt))) {
    ERROR("Encrypt object already set!");
  }
  encrypt->flags |= OBJ_NO_ENCRYPT;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pdf_set_id ( pdf_obj id)

Definition at line 508 of file pdfobj.c.

{
  if (pdf_add_dict(trailer_dict, pdf_new_name("ID"), id)) {
    ERROR ("ID already set!");
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pdf_set_info ( pdf_obj obj)

Definition at line 500 of file pdfobj.c.

{
  if (pdf_add_dict(trailer_dict, pdf_new_name("Info"), pdf_ref_obj(object))) {
    ERROR ("Info object already set!");
  }
}

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 832 of file pdfobj.c.

{
  pdf_number *data;

  TYPECHECK(object, PDF_NUMBER);

  data = object->data;
  data->value = value;
}
void pdf_set_root ( pdf_obj obj)

Definition at line 485 of file pdfobj.c.

{
  if (pdf_add_dict(trailer_dict, pdf_new_name("Root"), pdf_ref_obj(object))) {
    ERROR("Root object already set!");
  }
  /* Adobe Readers don't like a document catalog inside an encrypted
   * object stream, although the PDF v1.5 spec seems to allow this.
   * Note that we don't set OBJ_NO_ENCRYPT since the name dictionary in
   * a document catalog may contain strings, which should be encrypted.
   */
  if (doc_enc_mode)
    object->flags |= OBJ_NO_OBJSTM;
}

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 *  str,
unsigned  length 
)

Definition at line 1011 of file pdfobj.c.

{
  pdf_string *data;

  TYPECHECK(object, PDF_STRING);

  data = object->data;
  if (data->string != 0) {
    RELEASE(data->string);
  }
  if (length != 0) {
    data->length = length;
    data->string = NEW(length + 1, unsigned char);
    memcpy(data->string, str, length);
    data->string[length] = '\0';
  } else {
    data->length = 0;
    data->string = NULL;
  }
}
void pdf_set_version ( unsigned  version)

Definition at line 249 of file pdfobj.c.

{
  /* Don't forget to update CIDFont_stdcc_def[] in cid.c too! */
  if (version >= PDF_VERSION_MIN && version <= PDF_VERSION_MAX) {
    pdf_version = version;
  }
}

Here is the caller graph for this function:

const void* pdf_stream_dataptr ( pdf_obj stream)

Definition at line 1754 of file pdfobj.c.

{
  pdf_stream *data;

  TYPECHECK(stream, PDF_STREAM);

  data = stream->data;

  return (const void *) data->stream;
}

Here is the caller graph for this function:

Definition at line 1742 of file pdfobj.c.

{
  pdf_stream *data;

  TYPECHECK(stream, PDF_STREAM);

  data = stream->data;

  return data->dict;
}

Here is the caller graph for this function:

long pdf_stream_length ( pdf_obj stream)

Definition at line 1766 of file pdfobj.c.

{
  pdf_stream *data;

  TYPECHECK(stream, PDF_STREAM);

  data = stream->data;

  return (long) data->stream_length;
}

Here is the caller graph for this function:

unsigned pdf_string_length ( pdf_obj object)

Definition at line 888 of file pdfobj.c.

{
  pdf_string *data;

  TYPECHECK(object, PDF_STRING);

  data = object->data;

  return (unsigned) (data->length);
}

Here is the caller graph for this function:

void* pdf_string_value ( pdf_obj object)

Definition at line 876 of file pdfobj.c.

{
  pdf_string *data;

  TYPECHECK(object, PDF_STRING);

  data = object->data;

  return data->string;
}

Here is the caller graph for this function:

void pdf_transfer_label ( pdf_obj dst,
pdf_obj src 
)

Definition at line 643 of file pdfobj.c.

{
  ASSERT(dst && !dst->label && src);

  dst->label      = src->label;
  dst->generation = src->generation;
  src->label      = 0;
  src->generation = 0;
}

Here is the caller graph for this function:

void pdf_unshift_array ( pdf_obj array,
pdf_obj object 
)

Definition at line 1308 of file pdfobj.c.

{
  pdf_array *data;
  int        i;

  TYPECHECK(array, PDF_ARRAY);

  data = array->data;
  if (data->size >= data->max) {
    data->max   += ARRAY_ALLOC_SIZE;
    data->values = RENEW(data->values, data->max, pdf_obj *);
  }
  for (i = 0; i < data->size; i++)
    data->values[i+1] = data->values[i];
  data->values[0] = object;
  data->size++;
}

Here is the caller graph for this function:

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

Definition at line 904 of file pdfobj.c.

{
  int result = 0;
  int i;

  for (i = 0; i < len; i++) {
    unsigned char ch;

    ch = s[i];
    if (result > bufsize - 4)
      ERROR("pdfobj_escape_str: Buffer overflow");

    /*
     * We always write three octal digits. Optimization only gives few Kb
     * smaller size for most documents when zlib compressed.
     */
    if (ch < 32 || ch > 126) {
      buffer[result++] = '\\';
#if 0
      if (i < len - 1 && !isdigit(s[i+1]))
       result += sprintf(buffer+result, "%o", ch);
      else
       result += sprintf(buffer+result, "%03o", ch);
#endif
      result += sprintf(buffer+result, "%03o", ch);
    } else {
      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: