Back to index

texmacs  1.0.7.15
Defines | Functions
pdfdoc.h File Reference
#include "pdfobj.h"
#include "pdfdev.h"
#include "pdfcolor.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define PDF_DOC_GRABBING_NEST_MAX   4
#define pdf_doc_page_tree()   pdf_doc_get_dictionary("Pages")
#define pdf_doc_catalog()   pdf_doc_get_dictionary("Catalog")
#define pdf_doc_docinfo()   pdf_doc_get_dictionary("Info")
#define pdf_doc_names()   pdf_doc_get_dictionary("Names")
#define pdf_doc_this_page()   pdf_doc_get_dictionary("@THISPAGE")
#define pdf_doc_this_page_ref()   pdf_doc_get_reference("@THISPAGE")
#define pdf_doc_next_page_ref()   pdf_doc_get_reference("@NEXTPAGE")
#define pdf_doc_prev_page_ref()   pdf_doc_get_reference("@PREVPAGE")

Functions

void pdf_doc_set_verbose (void)
void pdf_open_document (const char *filename, int do_encryption, double media_width, double media_height, double annot_grow_amount, int bookmark_open_depth, int check_gotos)
void pdf_close_document (void)
void pdf_doc_set_creator (const char *creator)
pdf_objpdf_doc_get_dictionary (const char *category)
pdf_objpdf_doc_get_reference (const char *category)
pdf_objpdf_doc_get_page (pdf_file *pf, long page_no, long *count_p, pdf_rect *bbox, pdf_obj **resources_p)
long pdf_doc_current_page_number (void)
pdf_objpdf_doc_current_page_resources (void)
pdf_objpdf_doc_ref_page (unsigned long page_no)
int pdf_doc_add_names (const char *category, const void *key, int keylen, pdf_obj *value)
void pdf_doc_set_bop_content (const char *str, unsigned length)
void pdf_doc_set_eop_content (const char *str, unsigned length)
void pdf_doc_begin_page (double scale, double x_origin, double y_origin)
void pdf_doc_end_page (void)
void pdf_doc_set_mediabox (unsigned page_no, const pdf_rect *mediabox)
void pdf_doc_get_mediabox (unsigned page_no, pdf_rect *mediabox)
void pdf_doc_add_page_content (const char *buffer, unsigned length)
void pdf_doc_add_page_resource (const char *category, const char *resource_name, pdf_obj *resources)
void pdf_doc_begin_article (const char *article_id, pdf_obj *info)
void pdf_doc_make_article (const char *article_id, const char **bead_order, int num_beads)
void pdf_doc_add_bead (const char *article_id, const char *bead_id, long page_no, const pdf_rect *rect)
int pdf_doc_bookmarks_up (void)
int pdf_doc_bookmarks_down (void)
void pdf_doc_bookmarks_add (pdf_obj *dict, int is_open)
int pdf_doc_bookmarks_depth (void)
int pdf_doc_begin_grabbing (const char *ident, double ref_x, double ref_y, const pdf_rect *cropbox)
void pdf_doc_end_grabbing (pdf_obj *attrib)
void pdf_doc_add_annot (unsigned page_no, const pdf_rect *rect, pdf_obj *annot_dict, int dest_is_new)
void pdf_doc_begin_annot (pdf_obj *dict)
void pdf_doc_end_annot (void)
void pdf_doc_break_annot (void)
void pdf_doc_expand_box (const pdf_rect *rect)
void pdf_doc_enable_manual_thumbnails (void)
void pdf_doc_set_bgcolor (const pdf_color *color)

Define Documentation

#define pdf_doc_catalog ( )    pdf_doc_get_dictionary("Catalog")

Definition at line 54 of file pdfdoc.h.

#define pdf_doc_docinfo ( )    pdf_doc_get_dictionary("Info")

Definition at line 55 of file pdfdoc.h.

#define PDF_DOC_GRABBING_NEST_MAX   4

Definition at line 31 of file pdfdoc.h.

#define pdf_doc_names ( )    pdf_doc_get_dictionary("Names")

Definition at line 56 of file pdfdoc.h.

#define pdf_doc_next_page_ref ( )    pdf_doc_get_reference("@NEXTPAGE")

Definition at line 67 of file pdfdoc.h.

#define pdf_doc_page_tree ( )    pdf_doc_get_dictionary("Pages")

Definition at line 53 of file pdfdoc.h.

#define pdf_doc_prev_page_ref ( )    pdf_doc_get_reference("@PREVPAGE")

Definition at line 68 of file pdfdoc.h.

#define pdf_doc_this_page ( )    pdf_doc_get_dictionary("@THISPAGE")

Definition at line 57 of file pdfdoc.h.

#define pdf_doc_this_page_ref ( )    pdf_doc_get_reference("@THISPAGE")

Definition at line 66 of file pdfdoc.h.


Function Documentation

void pdf_close_document ( void  )

Definition at line 2454 of file pdfdoc.c.

{
  pdf_doc *p = &pdoc;

  /*
   * Following things were kept around so user can add dictionary items.
   */
  pdf_doc_close_articles (p);
  pdf_doc_close_names    (p);
  pdf_doc_close_bookmarks(p);
  pdf_doc_close_page_tree(p);
  pdf_doc_close_docinfo  (p);

  pdf_doc_close_catalog  (p);

  pdf_close_images();
  pdf_close_fonts ();
  pdf_close_colors();

  pdf_close_resources(); /* Should be at last. */

  pdf_out_flush();

  if (thumb_basename)
    RELEASE(thumb_basename);

  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pdf_doc_add_annot ( unsigned  page_no,
const pdf_rect rect,
pdf_obj annot_dict,
int  dest_is_new 
)

Definition at line 1656 of file pdfdoc.c.

{
  pdf_doc  *p = &pdoc;
  pdf_page *page;
  pdf_obj  *rect_array;
  double    annot_grow = p->opt.annot_grow;
  double    xpos, ypos;
  pdf_rect  mediabox, annbox;

  page = doc_get_page_entry(p, page_no);
  if (!page->annots)
    page->annots = pdf_new_array();

  pdf_doc_get_mediabox(page_no, &mediabox);
  pdf_dev_get_coord(&xpos, &ypos);
  annbox.llx = rect->llx - xpos; annbox.lly = rect->lly - ypos;
  annbox.urx = rect->urx - xpos; annbox.ury = rect->ury - ypos;

  if (annbox.llx < mediabox.llx || annbox.urx > mediabox.urx ||
      annbox.lly < mediabox.lly || annbox.ury > mediabox.ury) {
    WARN("Annotation out of page boundary.");
    WARN("Current page's MediaBox: [%g %g %g %g]",
         mediabox.llx, mediabox.lly, mediabox.urx, mediabox.ury);
    WARN("Annotation: [%g %g %g %g]",
         annbox.llx, annbox.lly, annbox.urx, annbox.ury);
    WARN("Maybe incorrect paper size specified.");
  }
  if (annbox.llx > annbox.urx || annbox.lly > annbox.ury) {
    WARN("Rectangle with negative width/height: [%g %g %g %g]",
         annbox.llx, annbox.lly, annbox.urx, annbox.ury);
  }

  rect_array = pdf_new_array();
  pdf_add_array(rect_array, pdf_new_number(ROUND(annbox.llx - annot_grow, 0.001)));
  pdf_add_array(rect_array, pdf_new_number(ROUND(annbox.lly - annot_grow, 0.001)));
  pdf_add_array(rect_array, pdf_new_number(ROUND(annbox.urx + annot_grow, 0.001)));
  pdf_add_array(rect_array, pdf_new_number(ROUND(annbox.ury + annot_grow, 0.001)));
  pdf_add_dict (annot_dict, pdf_new_name("Rect"), rect_array);

  pdf_add_array(page->annots, pdf_ref_obj(annot_dict));

  if (new_annot)
    pdf_doc_add_goto(annot_dict);

  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pdf_doc_add_bead ( const char *  article_id,
const char *  bead_id,
long  page_no,
const pdf_rect rect 
)

Definition at line 1774 of file pdfdoc.c.

{
  pdf_doc     *p = &pdoc;
  pdf_article *article;
  pdf_bead    *bead;
  long         i;

  if (!article_id) {
    ERROR("No article identifier specified.");
  }

  article = NULL;
  for (i = 0; i < p->articles.num_entries; i++) {
    if (!strcmp(p->articles.entries[i].id, article_id)) {
      article = &(p->articles.entries[i]);
      break;
    }
  }
  if (!article) {
    ERROR("Specified article thread that doesn't exist.");
    return;
  }

  bead = bead_id ? find_bead(article, bead_id) : NULL;
  if (!bead) {
    if (article->num_beads >= article->max_beads) {
      article->max_beads += PDFDOC_BEAD_ALLOC_SIZE;
      article->beads = RENEW(article->beads,
                             article->max_beads, struct pdf_bead);
      for (i = article->num_beads; i < article->max_beads; i++) {
        article->beads[i].id = NULL;
        article->beads[i].page_no = -1;
      }
    }
    bead = &(article->beads[article->num_beads]);
    if (bead_id) {
      bead->id = NEW(strlen(bead_id)+1, char);
      strcpy(bead->id, bead_id);
    } else {
      bead->id = NULL;
    }
    article->num_beads++;
  }
  bead->rect.llx = rect->llx;
  bead->rect.lly = rect->lly;
  bead->rect.urx = rect->urx;
  bead->rect.ury = rect->ury;
  bead->page_no  = page_no;

  return;
}

Here is the call graph for this function:

int pdf_doc_add_names ( const char *  category,
const void *  key,
int  keylen,
pdf_obj value 
)

Definition at line 1441 of file pdfdoc.c.

{
  pdf_doc *p = &pdoc;
  int      i;

  for (i = 0; p->names[i].category != NULL; i++) {
    if (!strcmp(p->names[i].category, category)) {
      break;
    }
  }
  if (p->names[i].category == NULL) {
    WARN("Unknown name dictionary category \"%s\".", category);
    return -1;
  }
  if (!p->names[i].data) {
    p->names[i].data = pdf_new_name_tree();
  }

  return pdf_names_add_object(p->names[i].data, key, keylen, value);
}

Here is the call graph for this function:

void pdf_doc_add_page_content ( const char *  buffer,
unsigned  length 
)

Definition at line 2362 of file pdfdoc.c.

{
  pdf_doc  *p = &pdoc;
  pdf_page *currentpage;

  if (p->pending_forms) {
    pdf_add_stream(p->pending_forms->form.contents, buffer, length);
  } else {
    currentpage = LASTPAGE(p);
    pdf_add_stream(currentpage->contents, buffer, length);
  }

  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pdf_doc_add_page_resource ( const char *  category,
const char *  resource_name,
pdf_obj resources 
)

Definition at line 599 of file pdfdoc.c.

{
  pdf_doc *p = &pdoc;
  pdf_obj *resources;
  pdf_obj *duplicate;

  if (!PDF_OBJ_INDIRECTTYPE(resource_ref)) {
    WARN("Passed non indirect reference...");
    resource_ref = pdf_ref_obj(resource_ref); /* leak */
  }
  resources = pdf_doc_get_page_resources(p, category);
  duplicate = pdf_lookup_dict(resources, resource_name);
  if (duplicate && pdf_compare_reference(duplicate, resource_ref)) {
    WARN("Conflicting page resource found (page: %ld, category: %s, name: %s).",
         pdf_doc_current_page_number(), category, resource_name);
    WARN("Ignoring...");
    pdf_release_obj(resource_ref);
  } else {
    pdf_add_dict(resources, pdf_new_name(resource_name), resource_ref);
  }

  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pdf_doc_begin_annot ( pdf_obj dict)

Definition at line 2672 of file pdfdoc.c.

{
  breaking_state.annot_dict = dict;
  breaking_state.broken = 0;
  reset_box();
}

Here is the call graph for this function:

void pdf_doc_begin_article ( const char *  article_id,
pdf_obj info 
)

Definition at line 1721 of file pdfdoc.c.

{
  pdf_doc     *p = &pdoc;
  pdf_article *article;

  if (article_id == NULL || strlen(article_id) == 0)
    ERROR("Article thread without internal identifier.");

  if (p->articles.num_entries >= p->articles.max_entries) {
    p->articles.max_entries += PDFDOC_ARTICLE_ALLOC_SIZE;
    p->articles.entries = RENEW(p->articles.entries,
                                p->articles.max_entries, struct pdf_article);
  }
  article = &(p->articles.entries[p->articles.num_entries]);

  article->id = NEW(strlen(article_id)+1, char);
  strcpy(article->id, article_id);
  article->info = article_info;
  article->num_beads = 0;
  article->max_beads = 0;
  article->beads     = NULL;

  p->articles.num_entries++;

  return;
}
int pdf_doc_begin_grabbing ( const char *  ident,
double  ref_x,
double  ref_y,
const pdf_rect cropbox 
)

Definition at line 2541 of file pdfdoc.c.

{
  int         xobj_id = -1;
  pdf_doc    *p = &pdoc;
  pdf_form   *form;
  struct form_list_node *fnode;
  xform_info  info;

  pdf_dev_push_gstate();

  fnode = NEW(1, struct form_list_node);

  fnode->prev    = p->pending_forms;
  fnode->q_depth = pdf_dev_current_depth();
  form           = &fnode->form;

  /*
  * The reference point of an Xobject is at the lower left corner
  * of the bounding box.  Since we would like to have an arbitrary
  * reference point, we use a transformation matrix, translating
  * the reference point to (0,0).
  */

  form->matrix.a = 1.0; form->matrix.b = 0.0;
  form->matrix.c = 0.0; form->matrix.d = 1.0;
  form->matrix.e = -ref_x;
  form->matrix.f = -ref_y;

  form->cropbox.llx = ref_x + cropbox->llx;
  form->cropbox.lly = ref_y + cropbox->lly;
  form->cropbox.urx = ref_x + cropbox->urx;
  form->cropbox.ury = ref_y + cropbox->ury;

  form->contents  = pdf_new_stream(STREAM_COMPRESS);
  form->resources = pdf_new_dict();

  pdf_ximage_init_form_info(&info);

  info.matrix.a = 1.0; info.matrix.b = 0.0;
  info.matrix.c = 0.0; info.matrix.d = 1.0;
  info.matrix.e = -ref_x;
  info.matrix.f = -ref_y;

  info.bbox.llx = cropbox->llx;
  info.bbox.lly = cropbox->lly;
  info.bbox.urx = cropbox->urx;
  info.bbox.ury = cropbox->ury;

  /* Use reference since content itself isn't available yet. */
  xobj_id = pdf_ximage_defineresource(ident,
                                      PDF_XOBJECT_TYPE_FORM,
                                      &info, pdf_ref_obj(form->contents));

  p->pending_forms = fnode;

  /*
   * Make sure the object is self-contained by adding the
   * current font and color to the object stream.
   */
  pdf_dev_reset_fonts();
  pdf_dev_reset_color(1);  /* force color operators to be added to stream */

  return xobj_id;
}

Here is the call graph for this function:

void pdf_doc_begin_page ( double  scale,
double  x_origin,
double  y_origin 
)

Definition at line 2331 of file pdfdoc.c.

{
  pdf_doc     *p = &pdoc;
  pdf_tmatrix  M;

  M.a = scale; M.b = 0.0;
  M.c = 0.0  ; M.d = scale;
  M.e = x_origin;
  M.f = y_origin;

  /* pdf_doc_new_page() allocates page content stream. */
  pdf_doc_new_page(p);
  pdf_dev_bop(&M);

  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pdf_doc_bookmarks_add ( pdf_obj dict,
int  is_open 
)

Definition at line 1336 of file pdfdoc.c.

{
  pdf_doc    *p = &pdoc;
  pdf_olitem *item, *next;

  ASSERT(p && dict);

  item = p->outlines.current;

  if (!item) {
    item = NEW(1, pdf_olitem);
    item->parent = NULL;
    p->outlines.first = item;
  } else if (item->dict) { /* go to next item */
    item = item->next;
  }

#define BMOPEN(b,p) (((b) < 0) ? (((p)->outlines.current_depth > (p)->opt.outline_open_depth) ? 0 : 1) : (b))

#if 0
  item->dict    = pdf_link_obj(dict);
#endif
  item->dict    = dict; 
  item->first   = NULL;
  item->is_open = BMOPEN(is_open, p);

  item->next    = next = NEW(1, pdf_olitem);
  next->dict    = NULL;
  next->parent  = item->parent;
  next->first   = NULL;
  next->is_open = -1;
  next->next    = NULL;

  p->outlines.current = item;

  pdf_doc_add_goto(dict);

  return;
}

Here is the call graph for this function:

int pdf_doc_bookmarks_depth ( void  )

Definition at line 1328 of file pdfdoc.c.

{
  pdf_doc *p = &pdoc;

  return p->outlines.current_depth;
}
int pdf_doc_bookmarks_down ( void  )

Definition at line 1273 of file pdfdoc.c.

{
  pdf_doc    *p = &pdoc;
  pdf_olitem *item, *first;

  item = p->outlines.current;
  if (!item->dict) {
    pdf_obj *tcolor, *action;

    WARN("Empty bookmark node!");
    WARN("You have tried to jump more than 1 level.");

    item->dict = pdf_new_dict();

#define TITLE_STRING "<No Title>"
    pdf_add_dict(item->dict,
                 pdf_new_name("Title"),
                 pdf_new_string(TITLE_STRING, strlen(TITLE_STRING)));

    tcolor = pdf_new_array();
    pdf_add_array(tcolor, pdf_new_number(1.0));
    pdf_add_array(tcolor, pdf_new_number(0.0));
    pdf_add_array(tcolor, pdf_new_number(0.0));
    pdf_add_dict (item->dict,
                  pdf_new_name("C"), pdf_link_obj(tcolor));
    pdf_release_obj(tcolor);

    pdf_add_dict (item->dict,
                  pdf_new_name("F"), pdf_new_number(1.0));

#define JS_CODE "app.alert(\"The author of this document made this bookmark item empty!\", 3, 0)"
    action = pdf_new_dict();
    pdf_add_dict(action,
                 pdf_new_name("S"), pdf_new_name("JavaScript"));
    pdf_add_dict(action, 
                 pdf_new_name("JS"), pdf_new_string(JS_CODE, strlen(JS_CODE)));
    pdf_add_dict(item->dict,
                 pdf_new_name("A"), pdf_link_obj(action));
    pdf_release_obj(action);
  }

  item->first    = first = NEW(1, pdf_olitem);
  first->dict    = NULL;
  first->is_open = 0;
  first->parent  = item;
  first->next    = NULL;
  first->first   = NULL;

  p->outlines.current = first;
  p->outlines.current_depth++;

  return 0;
}

Here is the call graph for this function:

int pdf_doc_bookmarks_up ( void  )

Definition at line 1246 of file pdfdoc.c.

{
  pdf_doc    *p = &pdoc;
  pdf_olitem *parent, *item;

  item = p->outlines.current;
  if (!item || !item->parent) {
    WARN("Can't go up above the bookmark root node!");
    return -1;
  }
  parent = item->parent;
  item   = parent->next;
  if (!parent->next) {
    parent->next  = item = NEW(1, pdf_olitem);
    item->dict    = NULL;
    item->first   = NULL;
    item->next    = NULL;
    item->is_open = 0;
    item->parent  = parent->parent;
  }
  p->outlines.current = item;
  p->outlines.current_depth--;

  return 0;
}

Here is the call graph for this function:

void pdf_doc_break_annot ( void  )

Definition at line 2687 of file pdfdoc.c.

{
  if (breaking_state.dirty) {
    pdf_obj  *annot_dict;

    /* Copy dict */
    annot_dict = pdf_new_dict();
    pdf_merge_dict(annot_dict, breaking_state.annot_dict);
    pdf_doc_add_annot(pdf_doc_current_page_number(), &(breaking_state.rect),
                    annot_dict, !breaking_state.broken);
    pdf_release_obj(annot_dict);

    breaking_state.broken = 1;
  }
  reset_box();
}

Here is the call graph for this function:

Here is the caller graph for this function:

long pdf_doc_current_page_number ( void  )

Definition at line 2102 of file pdfdoc.c.

{
  pdf_doc *p = &pdoc;

  return (long) (PAGECOUNT(p) + 1);
}

Here is the caller graph for this function:

Definition at line 2038 of file pdfdoc.c.

{
  pdf_obj  *resources;
  pdf_doc  *p = &pdoc;
  pdf_page *currentpage;

  if (p->pending_forms) {
    if (p->pending_forms->form.resources) {
      resources = p->pending_forms->form.resources;
    } else {
      resources = p->pending_forms->form.resources = pdf_new_dict();
    }
  } else {
    currentpage = LASTPAGE(p);
    if (currentpage->resources) {
      resources = currentpage->resources;
    } else {
      resources = currentpage->resources = pdf_new_dict();
    }
  }

  return resources;
}

Here is the call graph for this function:

Definition at line 76 of file pdfdoc.c.

{
#if HAVE_LIBPNG
  manual_thumb_enabled = 1;
#else
  WARN("Manual thumbnail is not supported without the libpng library.");
#endif
}

Here is the call graph for this function:

void pdf_doc_end_annot ( void  )

Definition at line 2680 of file pdfdoc.c.

{
  pdf_doc_break_annot();
  breaking_state.annot_dict = NULL;
}

Here is the call graph for this function:

void pdf_doc_end_grabbing ( pdf_obj attrib)

Definition at line 2608 of file pdfdoc.c.

{
  pdf_form *form;
  pdf_obj  *procset;
  pdf_doc  *p = &pdoc;
  struct form_list_node *fnode;

  if (!p->pending_forms) {
    WARN("Tried to close a nonexistent form XOject.");
    return;
  }
  
  fnode = p->pending_forms;
  form  = &fnode->form;

  pdf_dev_grestore_to(fnode->q_depth);

  /*
   * ProcSet is obsolete in PDF-1.4 but recommended for compatibility.
   */
  procset = pdf_new_array();
  pdf_add_array(procset, pdf_new_name("PDF"));
  pdf_add_array(procset, pdf_new_name("Text"));
  pdf_add_array(procset, pdf_new_name("ImageC"));
  pdf_add_array(procset, pdf_new_name("ImageB"));
  pdf_add_array(procset, pdf_new_name("ImageI"));
  pdf_add_dict (form->resources, pdf_new_name("ProcSet"), procset);

  pdf_doc_make_xform(form->contents,
                     &form->cropbox, &form->matrix,
                     pdf_ref_obj(form->resources), attrib);
  pdf_release_obj(form->resources);
  pdf_release_obj(form->contents);
  if (attrib) pdf_release_obj(attrib);

  p->pending_forms = fnode->prev;
  
  pdf_dev_pop_gstate();

  pdf_dev_reset_fonts();
  pdf_dev_reset_color(0);

  RELEASE(fnode);

  return;
}

Here is the call graph for this function:

void pdf_doc_end_page ( void  )

Definition at line 2349 of file pdfdoc.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void pdf_doc_expand_box ( const pdf_rect rect)

Definition at line 2705 of file pdfdoc.c.

{
  breaking_state.rect.llx = MIN(breaking_state.rect.llx, rect->llx);
  breaking_state.rect.lly = MIN(breaking_state.rect.lly, rect->lly);
  breaking_state.rect.urx = MAX(breaking_state.rect.urx, rect->urx);
  breaking_state.rect.ury = MAX(breaking_state.rect.ury, rect->ury);
  breaking_state.dirty    = 1;
}
pdf_obj* pdf_doc_get_dictionary ( const char *  category)

Definition at line 2063 of file pdfdoc.c.

{
  pdf_doc *p    = &pdoc;
  pdf_obj *dict = NULL;

  ASSERT(category);

  if (!strcmp(category, "Names")) {
    if (!p->root.names)
      p->root.names = pdf_new_dict();
    dict = p->root.names;
  } else if (!strcmp(category, "Pages")) {
    if (!p->root.pages)
      p->root.pages = pdf_new_dict();
    dict = p->root.pages;
  } else if (!strcmp(category, "Catalog")) {
    if (!p->root.dict)
      p->root.dict = pdf_new_dict();
    dict = p->root.dict;
  } else if (!strcmp(category, "Info")) {
    if (!p->info)
      p->info = pdf_new_dict();
    dict = p->info;
  } else if (!strcmp(category, "@THISPAGE")) {
    /* Sorry for this... */
    pdf_page *currentpage;

    currentpage = LASTPAGE(p);
    dict =  currentpage->page_obj;
  }

  if (!dict) {
    ERROR("Document dict. \"%s\" not exist. ", category);
  }

  return dict;
}

Here is the call graph for this function:

void pdf_doc_get_mediabox ( unsigned  page_no,
pdf_rect mediabox 
)

Definition at line 2009 of file pdfdoc.c.

{
  pdf_doc  *p = &pdoc;
  pdf_page *page;

  if (page_no == 0) {
    mediabox->llx = p->pages.mediabox.llx;
    mediabox->lly = p->pages.mediabox.lly;
    mediabox->urx = p->pages.mediabox.urx;
    mediabox->ury = p->pages.mediabox.ury;
  } else {
    page = doc_get_page_entry(p, page_no);
    if (page->flags & USE_MY_MEDIABOX) {
      mediabox->llx = page->cropbox.llx;
      mediabox->lly = page->cropbox.lly;
      mediabox->urx = page->cropbox.urx;
      mediabox->ury = page->cropbox.ury;
    } else {
      mediabox->llx = p->pages.mediabox.llx;
      mediabox->lly = p->pages.mediabox.lly;
      mediabox->urx = p->pages.mediabox.urx;
      mediabox->ury = p->pages.mediabox.ury;
    }
  }

  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

pdf_obj* pdf_doc_get_page ( pdf_file pf,
long  page_no,
long *  count_p,
pdf_rect bbox,
pdf_obj **  resources_p 
)

Definition at line 941 of file pdfdoc.c.

                                                       {
  pdf_obj *page_tree = NULL;
  pdf_obj *resources = NULL, *box = NULL, *rotate = NULL;
  pdf_obj *catalog;

  catalog = pdf_file_get_catalog(pf);

  page_tree = pdf_deref_obj(pdf_lookup_dict(catalog, "Pages"));

  if (!PDF_OBJ_DICTTYPE(page_tree))
    goto error;

  {
    long count;
    pdf_obj *tmp = pdf_deref_obj(pdf_lookup_dict(page_tree, "Count"));
    if (!PDF_OBJ_NUMBERTYPE(tmp)) {
      if (tmp)
       pdf_release_obj(tmp);
      goto error;
    }
    count = pdf_number_value(tmp);
    pdf_release_obj(tmp);
    if (count_p)
      *count_p = count;
    if (page_no <= 0 || page_no > count) {
       WARN("Page %ld does not exist.", page_no);
       goto error_silent;
      }
  }

  /*
   * Seek correct page. Get MediaBox, CropBox and Resources.
   * (Note that these entries can be inherited.)
   */
  {
    pdf_obj *media_box = NULL, *crop_box = NULL, *kids, *tmp;
    int depth = PDF_OBJ_MAX_DEPTH;
    long page_idx = page_no-1, kids_length = 1, i = 0;

    while (--depth && i != kids_length) {
      if ((tmp = pdf_deref_obj(pdf_lookup_dict(page_tree, "MediaBox")))) {
       if (media_box)
         pdf_release_obj(media_box);
       media_box = tmp;
      }

      if ((tmp = pdf_deref_obj(pdf_lookup_dict(page_tree, "CropBox")))) {
       if (crop_box)
         pdf_release_obj(crop_box);
       crop_box = tmp;
      }

      if ((tmp = pdf_deref_obj(pdf_lookup_dict(page_tree, "Rotate")))) {
       if (rotate)
         pdf_release_obj(rotate);
       rotate = tmp;
      }

      if ((tmp = pdf_deref_obj(pdf_lookup_dict(page_tree, "Resources")))) {
       if (resources)
         pdf_release_obj(resources);
       resources = tmp;
      }

      kids = pdf_deref_obj(pdf_lookup_dict(page_tree, "Kids"));
      if (!kids)
       break;
      else if (!PDF_OBJ_ARRAYTYPE(kids)) {
       pdf_release_obj(kids);
       goto error;
      }
      kids_length = pdf_array_length(kids);

      for (i = 0; i < kids_length; i++) {
       long count;

       pdf_release_obj(page_tree);
       page_tree = pdf_deref_obj(pdf_get_array(kids, i));
       if (!PDF_OBJ_DICTTYPE(page_tree))
         goto error;

       tmp = pdf_deref_obj(pdf_lookup_dict(page_tree, "Count"));
       if (PDF_OBJ_NUMBERTYPE(tmp)) {
         /* Pages object */
         count = pdf_number_value(tmp);
         pdf_release_obj(tmp);
       } else if (!tmp)
         /* Page object */
         count = 1;
       else {
         pdf_release_obj(tmp);
         goto error;
       }

       if (page_idx < count)
         break;

       page_idx -= count;
      }
      
      pdf_release_obj(kids);
    }

    if (!depth || kids_length == i) {
      if (media_box)
       pdf_release_obj(media_box);
     if (crop_box)
       pdf_release_obj(crop_box);
      goto error;
    }

    if (crop_box)
      box = crop_box;
    else
      if (!(box = pdf_deref_obj(pdf_lookup_dict(page_tree, "ArtBox"))) &&
         !(box = pdf_deref_obj(pdf_lookup_dict(page_tree, "TrimBox"))) &&
         !(box = pdf_deref_obj(pdf_lookup_dict(page_tree, "BleedBox"))) &&
         media_box) {
         box = media_box;
         media_box = NULL;
      }
    if (media_box)
      pdf_release_obj(media_box);
  }

  if (!PDF_OBJ_ARRAYTYPE(box) || pdf_array_length(box) != 4 ||
      !PDF_OBJ_DICTTYPE(resources))
    goto error;

  if (PDF_OBJ_NUMBERTYPE(rotate)) {
    if (pdf_number_value(rotate))
      WARN("<< /Rotate %d >> found. (Not supported yet)", 
          (int) pdf_number_value(rotate));
    pdf_release_obj(rotate);
    rotate = NULL;
  } else if (rotate)
    goto error;

  {
    int i;

    for (i = 4; i--; ) {
      double x;
      pdf_obj *tmp = pdf_deref_obj(pdf_get_array(box, i));
      if (!PDF_OBJ_NUMBERTYPE(tmp)) {
       pdf_release_obj(tmp);
       goto error;
      }
      x = pdf_number_value(tmp);
      switch (i) {
      case 0: bbox->llx = x; break;
      case 1: bbox->lly = x; break;
      case 2: bbox->urx = x; break;
      case 3: bbox->ury = x; break;
      }
      pdf_release_obj(tmp);
    }
  }

  pdf_release_obj(box);

  if (resources_p)
    *resources_p = resources;
  else if (resources)
    pdf_release_obj(resources);

  return page_tree;

 error:
  WARN("Cannot parse document. Broken PDF file?");
 error_silent:
  if (box)
    pdf_release_obj(box);
  if (rotate)
    pdf_release_obj(rotate);
  if (resources)
    pdf_release_obj(resources);
  if (page_tree)
    pdf_release_obj(page_tree);

  return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

pdf_obj* pdf_doc_get_reference ( const char *  category)

Definition at line 2125 of file pdfdoc.c.

{
  pdf_obj *ref = NULL;
  long     page_no;

  ASSERT(category);

  page_no = pdf_doc_current_page_number();
  if (!strcmp(category, "@THISPAGE")) {
    ref = pdf_doc_ref_page(page_no);
  } else if (!strcmp(category, "@PREVPAGE")) {
    if (page_no <= 1) {
      ERROR("Reference to previous page, but no pages have been completed yet.");
    }
    ref = pdf_doc_ref_page(page_no - 1);
  } else if (!strcmp(category, "@NEXTPAGE")) {
    ref = pdf_doc_ref_page(page_no + 1);
  }

  if (!ref) {
    ERROR("Reference to \"%s\" not exist. ", category);
  }

  return ref;
}

Here is the call graph for this function:

void pdf_doc_make_article ( const char *  article_id,
const char **  bead_order,
int  num_beads 
)
pdf_obj* pdf_doc_ref_page ( unsigned long  page_no)

Definition at line 2110 of file pdfdoc.c.

{
  pdf_doc  *p = &pdoc;
  pdf_page *page;

  page = doc_get_page_entry(p, page_no);
  if (!page->page_obj) {
    page->page_obj = pdf_new_dict();
    page->page_ref = pdf_ref_obj(page->page_obj);
  }

  return pdf_link_obj(page->page_ref);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pdf_doc_set_bgcolor ( const pdf_color color)

Definition at line 2287 of file pdfdoc.c.

{
  if (color)
    pdf_color_copycolor(&bgcolor, color);
  else { /* as clear... */
    pdf_color_white(&bgcolor);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pdf_doc_set_bop_content ( const char *  str,
unsigned  length 
)

Definition at line 396 of file pdfdoc.c.

{
  pdf_doc *p = &pdoc;

  ASSERT(p);

  if (p->pages.bop) {
    pdf_release_obj(p->pages.bop);
    p->pages.bop = NULL;
  }

  if (length > 0) {
    p->pages.bop = pdf_new_stream(STREAM_COMPRESS);
    pdf_add_stream(p->pages.bop, content, length);
  } else {
    p->pages.bop = NULL;
  }

  return;
}

Here is the call graph for this function:

void pdf_doc_set_creator ( const char *  creator)

Definition at line 2442 of file pdfdoc.c.

{
  if (!creator ||
      creator[0] == '\0')
    return;

  doccreator = NEW(strlen(creator)+1, char);
  strcpy(doccreator, creator); /* Ugh */
}

Here is the caller graph for this function:

void pdf_doc_set_eop_content ( const char *  str,
unsigned  length 
)

Definition at line 418 of file pdfdoc.c.

{
  pdf_doc *p = &pdoc;

  if (p->pages.eop) {
    pdf_release_obj(p->pages.eop);
    p->pages.eop = NULL;
  }

  if (length > 0) {
    p->pages.eop = pdf_new_stream(STREAM_COMPRESS);
    pdf_add_stream(p->pages.eop, content, length);
  } else {
    p->pages.eop = NULL;
  }

  return;
}

Here is the call graph for this function:

void pdf_doc_set_mediabox ( unsigned  page_no,
const pdf_rect mediabox 
)

Definition at line 1986 of file pdfdoc.c.

{
  pdf_doc  *p = &pdoc;
  pdf_page *page;

  if (page_no == 0) {
    p->pages.mediabox.llx = mediabox->llx;
    p->pages.mediabox.lly = mediabox->lly;
    p->pages.mediabox.urx = mediabox->urx;
    p->pages.mediabox.ury = mediabox->ury;
  } else {
    page = doc_get_page_entry(p, page_no);
    page->cropbox.llx = mediabox->llx;
    page->cropbox.lly = mediabox->lly;
    page->cropbox.urx = mediabox->urx;
    page->cropbox.ury = mediabox->ury;
    page->flags |= USE_MY_MEDIABOX;
  }

  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pdf_doc_set_verbose ( void  )

Definition at line 124 of file pdfdoc.c.

Here is the call graph for this function:

void pdf_open_document ( const char *  filename,
int  do_encryption,
double  media_width,
double  media_height,
double  annot_grow_amount,
int  bookmark_open_depth,
int  check_gotos 
)

Definition at line 2380 of file pdfdoc.c.

{
  pdf_doc *p = &pdoc;

  pdf_out_init(filename, do_encryption);

  pdf_doc_init_catalog(p);

  p->opt.annot_grow = annot_grow_amount;
  p->opt.outline_open_depth = bookmark_open_depth;

  pdf_init_resources();
  pdf_init_colors();
  pdf_init_fonts();
  /* Thumbnail want this to be initialized... */
  pdf_init_images();

  pdf_doc_init_docinfo(p);
  if (doccreator) {
    pdf_add_dict(p->info,
                 pdf_new_name("Creator"),
                 pdf_new_string(doccreator, strlen(doccreator)));
    RELEASE(doccreator); doccreator = NULL;
  }

  pdf_doc_init_bookmarks(p, bookmark_open_depth);
  pdf_doc_init_articles (p);
  pdf_doc_init_names    (p, check_gotos);
  pdf_doc_init_page_tree(p, media_width, media_height);

  pdf_doc_set_bgcolor(NULL);

  if (do_encryption) {
    pdf_obj *encrypt = pdf_encrypt_obj();
    pdf_set_encrypt(encrypt);
    pdf_release_obj(encrypt);
  }
  pdf_set_id(pdf_enc_id_array());

  /* Create a default name for thumbnail image files */
  if (manual_thumb_enabled) {
    if (strlen(filename) > 4 &&
        !strncmp(".pdf", filename + strlen(filename) - 4, 4)) {
      thumb_basename = NEW(strlen(filename)-4+1, char);
      strncpy(thumb_basename, filename, strlen(filename)-4);
      thumb_basename[strlen(filename)-4] = 0;
    } else {
      thumb_basename = NEW(strlen(filename)+1, char);
      strcpy(thumb_basename, filename);
    }
  }

  p->pending_forms = NULL;
   
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function: