w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

pdfobj.c File Reference
#include <ctype.h>
#include <string.h>
#include "system.h"
#include "config.h"
#include "mem.h"
#include "error.h"
#include "mfileio.h"
#include "pdflimits.h"
#include "pdfobj.h"
#include "pdfspecial.h"
#include "pdfparse.h"
#include "twiddle.h"
#include <zlib.h>
Include dependency graph for pdfobj.c:

Go to the source code of this file.

Classes

struct  xref_entry
 
struct  object
 

Macros

#define FORMAT_BUF_SIZE   4096
 
#define COMPRESS_LEVEL   9
 
#define THRESHOLD   100
 

Functions

static void pdf_flush_obj (FILE *file, pdf_obj *object)
 
static void pdf_label_obj (pdf_obj *object)
 
static void pdf_out_char (FILE *file, char c)
 
static void pdf_out (FILE *file, void *buffer, int length)
 
static void release_indirect (pdf_indirect *data)
 
static void write_indirect (FILE *file, pdf_indirect *indirect)
 
static void release_boolean (pdf_obj *data)
 
static void write_boolean (FILE *file, pdf_boolean *data)
 
static void write_null (FILE *file)
 
static void release_null (void *data)
 
static void release_number (pdf_number *data)
 
static void write_number (FILE *file, pdf_number *number)
 
static void write_string (FILE *file, pdf_string *string)
 
static void release_string (pdf_string *data)
 
static void write_name (FILE *file, pdf_name *name)
 
static void release_name (pdf_name *data)
 
static void write_array (FILE *file, pdf_array *array)
 
static void release_array (pdf_array *data)
 
static void write_dict (FILE *file, pdf_dict *dict)
 
static void release_dict (pdf_dict *data)
 
static void write_stream (FILE *file, pdf_stream *stream)
 
static void release_stream (pdf_stream *stream)
 
static int pdf_match_name (pdf_obj *name_obj, char *name)
 
void pdf_obj_set_compression (int level)
 
void pdf_set_version (unsigned version)
 
void pdf_obj_set_debug (void)
 
void pdf_obj_set_verbose (void)
 
void pdf_out_init (char *filename)
 
static void dump_xref (void)
 
static void dump_trailer (void)
 
void pdf_out_flush (void)
 
void pdf_error_cleanup (void)
 
void pdf_set_root (pdf_obj *object)
 
void pdf_set_info (pdf_obj *object)
 
static void pdf_out_white (FILE *file)
 
pdf_objpdf_new_obj (pdf_obj_type type)
 
pdf_objpdf_link_obj (pdf_obj *object)
 
pdf_objpdf_ref_obj (pdf_obj *object)
 
pdf_objpdf_new_null (void)
 
pdf_objpdf_new_boolean (char value)
 
void pdf_set_boolean (pdf_obj *object, char value)
 
pdf_objpdf_new_number (double value)
 
void pdf_set_number (pdf_obj *object, double value)
 
double pdf_number_value (pdf_obj *object)
 
pdf_objpdf_new_string (void *string, unsigned length)
 
voidpdf_string_value (pdf_obj *a_pdf_string)
 
unsigned int pdf_string_length (pdf_obj *a_pdf_string)
 
int pdfobj_escape_str (char *buffer, int bufsize, unsigned char *s, int len, int remap)
 
void pdf_set_string (pdf_obj *object, unsigned char *string, unsigned length)
 
int pdf_check_name (char *name)
 
pdf_objpdf_new_name (char *name)
 
void pdf_set_name (pdf_obj *object, char *name)
 
char * pdf_name_value (pdf_obj *object)
 
pdf_objpdf_new_array (void)
 
pdf_objpdf_get_array (pdf_obj *array, unsigned long index)
 
void pdf_add_array (pdf_obj *array, pdf_obj *object)
 
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 (pdf_obj *dict, char *name)
 
void pdf_remove_dict (pdf_obj *dict, char *name)
 
char * pdf_get_dict (pdf_obj *dict, int index)
 
pdf_objpdf_new_stream (int flags)
 
pdf_objpdf_stream_dict (pdf_obj *stream)
 
void pdf_add_stream (pdf_obj *stream, char *stream_data, unsigned length)
 
void pdf_write_obj (FILE *file, pdf_obj *object)
 
void pdf_release_obj (pdf_obj *object)
 
static int backup_line (void)
 
static long find_xref (void)
 
pdf_objparse_trailer (void)
 
long next_object (unsigned long obj)
 
pdf_objpdf_ref_file_obj (unsigned long obj_no)
 
pdf_objpdf_new_ref (unsigned long label, int generation)
 
pdf_objpdf_read_object (unsigned long obj_no)
 
pdf_objpdf_deref_obj (pdf_obj *obj)
 
static void extend_xref (long new_size)
 
static int parse_xref (void)
 
pdf_objread_xref (void)
 
pdf_objpdf_open (FILE *file)
 
void pdf_close (void)
 
int check_for_pdf (FILE *file)
 

Variables

FILEpdf_output_file = NULL
 
FILEpdf_input_file = NULL
 
unsigned long pdf_output_file_position = 0
 
unsigned long compression_saved = 0
 
int pdf_output_line_position = 0
 
char format_buffer [4096]
 
static struct xref_entryoutput_xref = NULL
 
static unsigned long pdf_max_ind_objects = 0
 
static unsigned long next_label = 1
 
static unsigned long startxref
 
static unsigned pdf_root_obj = 0
 
static unsigned pdf_info_obj = 0
 
static unsigned char debug = 0
 
static unsigned char verbose = 0
 
static char compression_level = 9
 
static unsigned pdf_version = 4
 
static unsigned long pdf_file_size = 0
 
struct objectxref_table = NULL
 
long num_input_objects
 
static char any_open = 0
 

Macro Definition Documentation

◆ COMPRESS_LEVEL

#define COMPRESS_LEVEL   9

◆ FORMAT_BUF_SIZE

#define FORMAT_BUF_SIZE   4096

Definition at line 47 of file pdfobj.c.

◆ THRESHOLD

#define THRESHOLD   100

Function Documentation

◆ backup_line()

static int backup_line ( void  )
static

Definition at line 1205 of file pdfobj.c.

References ch, debug, fgetc, fprintf, pdf_input_file, seek_relative(), and tell_position().

Referenced by find_xref().

◆ check_for_pdf()

int check_for_pdf ( FILE file)

Definition at line 1716 of file pdfobj.c.

References fprintf, fread, pdf_version, check-static-inits::result, strlen(), strncmp(), and work_buffer.

◆ dump_trailer()

static void dump_trailer ( void  )
static

◆ dump_xref()

static void dump_xref ( void  )
static

Definition at line 163 of file pdfobj.c.

References format_buffer, i, L, length, next_label, output_xref, pdf_out(), pdf_output_file_position, RELEASE, sprintf, and startxref.

Referenced by pdf_out_flush().

◆ extend_xref()

static void extend_xref ( long  new_size)
static

◆ find_xref()

◆ next_object()

long next_object ( unsigned long  obj)

◆ parse_trailer()

pdf_obj* parse_trailer ( void  )

◆ parse_xref()

◆ pdf_add_array()

void pdf_add_array ( pdf_obj array,
pdf_obj object 
)

Definition at line 778 of file pdfobj.c.

References ARRAY_ALLOC_SIZE, data, ERROR, max, NULL, PDF_ARRAY, RENEW, size, and type.

◆ pdf_add_dict()

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

◆ pdf_add_stream()

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

Definition at line 1076 of file pdfobj.c.

References data, ERROR, length, memcpy, NULL, PDF_STREAM, RENEW, STREAM_ALLOC_SIZE, and type.

◆ pdf_check_name()

int pdf_check_name ( char *  name)

Definition at line 625 of file pdfobj.c.

References name, strlen(), and strspn().

Referenced by pdf_new_name().

◆ pdf_close()

void pdf_close ( void  )

◆ pdf_deref_obj()

◆ pdf_error_cleanup()

void pdf_error_cleanup ( void  )

Definition at line 230 of file pdfobj.c.

References MFCLOSE.

◆ pdf_flush_obj()

static void pdf_flush_obj ( FILE file,
pdf_obj object 
)
static

◆ pdf_get_array()

pdf_obj* pdf_get_array ( pdf_obj array,
unsigned long  index 
)

Definition at line 750 of file pdfobj.c.

References data, ERROR, NULL, PDF_ARRAY, check-static-inits::result, size, and type.

◆ pdf_get_dict()

char* pdf_get_dict ( pdf_obj dict,
int  index 
)

Definition at line 945 of file pdfobj.c.

References data, ERROR, key, next, NULL, PDF_DICT, pdf_name_value(), check-static-inits::result, and type.

◆ pdf_label_obj()

static void pdf_label_obj ( pdf_obj object)
static

◆ pdf_link_obj()

pdf_obj* pdf_link_obj ( pdf_obj object)

Definition at line 328 of file pdfobj.c.

References ERROR, NULL, and object.

◆ pdf_lookup_dict()

pdf_obj* pdf_lookup_dict ( pdf_obj dict,
char *  name 
)

Definition at line 910 of file pdfobj.c.

References data, ERROR, key, name, next, NULL, PDF_DICT, pdf_match_name(), and type.

◆ pdf_match_name()

static int pdf_match_name ( pdf_obj name_obj,
char *  name 
)
static

Definition at line 903 of file pdfobj.c.

References data, name, and strcmp().

Referenced by pdf_lookup_dict(), and pdf_remove_dict().

◆ pdf_merge_dict()

void pdf_merge_dict ( pdf_obj dict1,
pdf_obj dict2 
)

Definition at line 888 of file pdfobj.c.

References data, ERROR, key, next, NULL, pdf_add_dict(), PDF_DICT, pdf_link_obj(), and type.

◆ pdf_name_value()

char* pdf_name_value ( pdf_obj object)

Definition at line 705 of file pdfobj.c.

References data, ERROR, name, NULL, PDF_NAME, and type.

◆ pdf_new_array()

pdf_obj* pdf_new_array ( void  )

◆ pdf_new_boolean()

pdf_obj* pdf_new_boolean ( char  value)

Definition at line 429 of file pdfobj.c.

References data, NEW, PDF_BOOLEAN, pdf_new_obj(), and check-static-inits::result.

◆ pdf_new_dict()

pdf_obj* pdf_new_dict ( void  )

Definition at line 813 of file pdfobj.c.

References data, key, NEW, next, NULL, PDF_DICT, pdf_new_obj(), and check-static-inits::result.

◆ pdf_new_name()

pdf_obj* pdf_new_name ( char *  name)

◆ pdf_new_null()

pdf_obj* pdf_new_null ( void  )

Definition at line 411 of file pdfobj.c.

References data, NULL, pdf_new_obj(), PDF_NULL, and check-static-inits::result.

◆ pdf_new_number()

pdf_obj* pdf_new_number ( double  value)

Definition at line 463 of file pdfobj.c.

References data, NEW, pdf_new_obj(), PDF_NUMBER, and check-static-inits::result.

◆ pdf_new_obj()

◆ pdf_new_ref()

pdf_obj* pdf_new_ref ( unsigned long  label,
int  generation 
)

◆ pdf_new_stream()

◆ pdf_new_string()

pdf_obj* pdf_new_string ( void string,
unsigned  length 
)

Definition at line 503 of file pdfobj.c.

References data, length, memcpy, NEW, NULL, pdf_new_obj(), PDF_STRING, and check-static-inits::result.

◆ pdf_number_value()

double pdf_number_value ( pdf_obj object)

Definition at line 495 of file pdfobj.c.

References data, ERROR, NULL, PDF_NUMBER, and type.

◆ pdf_obj_set_compression()

void pdf_obj_set_compression ( int  level)

Definition at line 102 of file pdfobj.c.

References compression_level, ERROR, fprintf, and level.

Referenced by do_args().

◆ pdf_obj_set_debug()

void pdf_obj_set_debug ( void  )

Definition at line 124 of file pdfobj.c.

References debug.

◆ pdf_obj_set_verbose()

void pdf_obj_set_verbose ( void  )

Definition at line 129 of file pdfobj.c.

References verbose.

Referenced by do_args().

◆ pdf_open()

pdf_obj* pdf_open ( FILE file)

◆ pdf_out()

◆ pdf_out_char()

static void pdf_out_char ( FILE file,
char  c 
)
static

◆ pdf_out_flush()

void pdf_out_flush ( void  )

◆ pdf_out_init()

void pdf_out_init ( char *  filename)

◆ pdf_out_white()

static void pdf_out_white ( FILE file)
static

Definition at line 285 of file pdfobj.c.

References pdf_out_char(), and pdf_output_line_position.

Referenced by write_array(), and write_dict().

◆ pdf_read_object()

◆ pdf_ref_file_obj()

pdf_obj* pdf_ref_file_obj ( unsigned long  obj_no)

◆ pdf_ref_obj()

pdf_obj* pdf_ref_obj ( pdf_obj object)

◆ pdf_release_obj()

◆ pdf_remove_dict()

void pdf_remove_dict ( pdf_obj dict,
char *  name 
)

◆ pdf_set_boolean()

void pdf_set_boolean ( pdf_obj object,
char  value 
)

Definition at line 455 of file pdfobj.c.

References data, ERROR, NULL, PDF_BOOLEAN, and type.

◆ pdf_set_info()

void pdf_set_info ( pdf_obj object)

Definition at line 250 of file pdfobj.c.

References ERROR, label, pdf_info_obj, and pdf_label_obj().

◆ pdf_set_name()

void pdf_set_name ( pdf_obj object,
char *  name 
)

Definition at line 685 of file pdfobj.c.

References data, ERROR, length, memcpy, name, NEW, NULL, PDF_NAME, RELEASE, strlen(), and type.

◆ pdf_set_number()

void pdf_set_number ( pdf_obj object,
double  value 
)

Definition at line 487 of file pdfobj.c.

References data, ERROR, NULL, PDF_NUMBER, and type.

◆ pdf_set_root()

void pdf_set_root ( pdf_obj object)

Definition at line 239 of file pdfobj.c.

References ERROR, label, pdf_label_obj(), and pdf_root_obj.

◆ pdf_set_string()

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

Definition at line 603 of file pdfobj.c.

References data, ERROR, length, memcpy, NEW, NULL, PDF_STRING, RELEASE, and type.

◆ pdf_set_version()

void pdf_set_version ( unsigned  version)

Definition at line 117 of file pdfobj.c.

References pdf_version, and version.

Referenced by do_args(), and main().

◆ pdf_stream_dict()

pdf_obj* pdf_stream_dict ( pdf_obj stream)

Definition at line 1066 of file pdfobj.c.

References data, ERROR, NULL, PDF_STREAM, and type.

◆ pdf_string_length()

unsigned int pdf_string_length ( pdf_obj a_pdf_string)

Definition at line 529 of file pdfobj.c.

References data, and length.

◆ pdf_string_value()

void* pdf_string_value ( pdf_obj a_pdf_string)

Definition at line 522 of file pdfobj.c.

References data, and string.

◆ pdf_write_obj()

◆ pdfobj_escape_str()

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

Definition at line 540 of file pdfobj.c.

References bufsize, ch, ERROR, i, len, check-static-inits::result, s, sprintf, and twiddle.

◆ read_xref()

◆ release_array()

static void release_array ( pdf_array data)
static

Definition at line 767 of file pdfobj.c.

References data, i, pdf_release_obj(), RELEASE, and gen-indic-table::values.

Referenced by pdf_release_obj().

◆ release_boolean()

static void release_boolean ( pdf_obj data)
static

Definition at line 440 of file pdfobj.c.

References data, and RELEASE.

Referenced by pdf_release_obj().

◆ release_dict()

static void release_dict ( pdf_dict data)
static

Definition at line 826 of file pdfobj.c.

References data, key, next, NULL, pdf_release_obj(), and RELEASE.

Referenced by pdf_release_obj().

◆ release_indirect()

static void release_indirect ( pdf_indirect data)
static

Definition at line 373 of file pdfobj.c.

References data, and RELEASE.

Referenced by pdf_release_obj().

◆ release_name()

static void release_name ( pdf_name data)
static

Definition at line 678 of file pdfobj.c.

References data, name, NULL, and RELEASE.

Referenced by pdf_release_obj().

◆ release_null()

static void release_null ( void data)
static

Definition at line 419 of file pdfobj.c.

Referenced by pdf_release_obj().

◆ release_number()

static void release_number ( pdf_number data)
static

Definition at line 474 of file pdfobj.c.

References data, and RELEASE.

Referenced by pdf_release_obj().

◆ release_stream()

static void release_stream ( pdf_stream stream)
static

Definition at line 1058 of file pdfobj.c.

References pdf_release_obj(), and RELEASE.

Referenced by pdf_release_obj().

◆ release_string()

static void release_string ( pdf_string data)
static

Definition at line 596 of file pdfobj.c.

References data, NULL, and RELEASE.

Referenced by pdf_release_obj().

◆ write_array()

static void write_array ( FILE file,
pdf_array array 
)
static

Definition at line 731 of file pdfobj.c.

References i, PDF_ARRAY, PDF_NAME, pdf_out_char(), pdf_out_white(), PDF_STRING, pdf_write_obj(), size, and write_null().

Referenced by pdf_write_obj().

◆ write_boolean()

static void write_boolean ( FILE file,
pdf_boolean data 
)
static

Definition at line 445 of file pdfobj.c.

References data, and pdf_out().

Referenced by pdf_write_obj().

◆ write_dict()

static void write_dict ( FILE file,
pdf_dict dict 
)
static

◆ write_indirect()

◆ write_name()

static void write_name ( FILE file,
pdf_name name 
)
static

Definition at line 656 of file pdfobj.c.

References i, length, name, NULL, pdf_out_char(), s, and strlen().

Referenced by pdf_write_obj().

◆ write_null()

static void write_null ( FILE file)
static

Definition at line 424 of file pdfobj.c.

References pdf_out().

Referenced by pdf_write_obj(), and write_array().

◆ write_number()

static void write_number ( FILE file,
pdf_number number 
)
static

Definition at line 479 of file pdfobj.c.

References count, format_buffer, pdf_out(), and sprintf.

Referenced by pdf_write_obj().

◆ write_stream()

◆ write_string()

static void write_string ( FILE file,
pdf_string string 
)
static

Definition at line 577 of file pdfobj.c.

References count, FORMAT_BUF_SIZE, format_buffer, i, pdf_out(), pdf_out_char(), pdfobj_escape_str(), s, and string.

Referenced by pdf_write_obj().

Variable Documentation

◆ any_open

char any_open = 0
static

Definition at line 1645 of file pdfobj.c.

Referenced by pdf_close(), and pdf_open().

◆ compression_level

char compression_level = 9
static

◆ compression_saved

unsigned long compression_saved = 0

Definition at line 45 of file pdfobj.c.

Referenced by pdf_out_flush(), and write_stream().

◆ debug

unsigned char debug = 0
static

◆ format_buffer

char format_buffer[4096]

◆ next_label

unsigned long next_label = 1
static

Definition at line 56 of file pdfobj.c.

Referenced by dump_trailer(), dump_xref(), and pdf_label_obj().

◆ num_input_objects

long num_input_objects

◆ output_xref

struct xref_entry * output_xref = NULL
static

◆ pdf_file_size

unsigned long pdf_file_size = 0
static

Definition at line 1233 of file pdfobj.c.

Referenced by find_xref(), and next_object().

◆ pdf_info_obj

unsigned pdf_info_obj = 0
static

Definition at line 60 of file pdfobj.c.

Referenced by dump_trailer(), and pdf_set_info().

◆ pdf_input_file

◆ pdf_max_ind_objects

unsigned long pdf_max_ind_objects = 0
static

Definition at line 55 of file pdfobj.c.

Referenced by pdf_label_obj().

◆ pdf_output_file

Definition at line 43 of file pdfobj.c.

◆ pdf_output_file_position

unsigned long pdf_output_file_position = 0

Definition at line 45 of file pdfobj.c.

Referenced by dump_trailer(), dump_xref(), pdf_flush_obj(), pdf_out(), pdf_out_char(), and pdf_out_flush().

◆ pdf_output_line_position

int pdf_output_line_position = 0

Definition at line 46 of file pdfobj.c.

Referenced by pdf_out(), pdf_out_char(), and pdf_out_white().

◆ pdf_root_obj

unsigned pdf_root_obj = 0
static

Definition at line 60 of file pdfobj.c.

Referenced by dump_trailer(), and pdf_set_root().

◆ pdf_version

unsigned pdf_version = 4
static

Definition at line 116 of file pdfobj.c.

Referenced by check_for_pdf(), pdf_out_init(), pdf_set_version(), and write_xbb().

◆ startxref

unsigned long startxref
static

Definition at line 58 of file pdfobj.c.

Referenced by dump_trailer(), dump_xref(), and term_pdf().

◆ verbose

unsigned char verbose = 0
static

Definition at line 99 of file pdfobj.c.

Referenced by pdf_obj_set_verbose(), and pdf_out_flush().

◆ xref_table