Back to index

texmacs  1.0.7.15
Classes | Defines | Typedefs | Functions | Variables
pdfresource.c File Reference
#include "system.h"
#include "mem.h"
#include "error.h"
#include "dpxutil.h"
#include "pdfobj.h"
#include "pdfresource.h"

Go to the source code of this file.

Classes

struct  pdf_res
struct  res_cache

Defines

#define PDF_RESOURCE_DEBUG_STR   "PDF"
#define PDF_RESOURCE_DEBUG   3
#define PDF_RESOURCE_FONT   0
#define PDF_RESOURCE_CIDFONT   1
#define PDF_RESOURCE_ENCODING   2
#define PDF_RESOURCE_CMAP   3
#define PDF_RESOURCE_XOBJECT   4
#define PDF_RESOURCE_COLORSPACE   5
#define PDF_RESOURCE_SHADING   6
#define PDF_RESOURCE_PATTERN   7
#define PDF_RESOURCE_GSTATE   8
#define PDF_NUM_RESOURCE_CATEGORIES   (sizeof(pdf_resource_categories)/sizeof(pdf_resource_categories[0]))
#define CACHE_ALLOC_SIZE   16u

Typedefs

typedef struct pdf_res pdf_res

Functions

static void pdf_init_resource (pdf_res *res)
static void pdf_flush_resource (pdf_res *res)
static void pdf_clean_resource (pdf_res *res)
void pdf_init_resources (void)
void pdf_close_resources (void)
static int get_category (const char *category)
long pdf_defineresource (const char *category, const char *resname, pdf_obj *object, int flags)
long pdf_findresource (const char *category, const char *resname)
pdf_objpdf_get_resource_reference (long rc_id)

Variables

struct {
const char * name
int cat_id
pdf_resource_categories []
static struct res_cache [PDF_NUM_RESOURCE_CATEGORIES]

Class Documentation

struct pdf_res

Definition at line 56 of file pdfresource.c.

Collaboration diagram for pdf_res:
Class Members
int category
void * cdata
int flags
char * ident
pdf_obj * object
pdf_obj * reference
struct res_cache

Definition at line 87 of file pdfresource.c.

Collaboration diagram for res_cache:
Class Members
int capacity
int count
pdf_res * resources

Define Documentation

#define CACHE_ALLOC_SIZE   16u

Definition at line 86 of file pdfresource.c.

Definition at line 84 of file pdfresource.c.

#define PDF_RESOURCE_CIDFONT   1

Definition at line 47 of file pdfresource.c.

#define PDF_RESOURCE_CMAP   3

Definition at line 49 of file pdfresource.c.

#define PDF_RESOURCE_COLORSPACE   5

Definition at line 51 of file pdfresource.c.

#define PDF_RESOURCE_DEBUG   3

Definition at line 44 of file pdfresource.c.

#define PDF_RESOURCE_DEBUG_STR   "PDF"

Definition at line 43 of file pdfresource.c.

#define PDF_RESOURCE_ENCODING   2

Definition at line 48 of file pdfresource.c.

#define PDF_RESOURCE_FONT   0

Definition at line 46 of file pdfresource.c.

#define PDF_RESOURCE_GSTATE   8

Definition at line 54 of file pdfresource.c.

#define PDF_RESOURCE_PATTERN   7

Definition at line 53 of file pdfresource.c.

#define PDF_RESOURCE_SHADING   6

Definition at line 52 of file pdfresource.c.

#define PDF_RESOURCE_XOBJECT   4

Definition at line 50 of file pdfresource.c.


Typedef Documentation

typedef struct pdf_res pdf_res

Function Documentation

static int get_category ( const char *  category) [static]

Definition at line 180 of file pdfresource.c.

{
  int  i;

  for (i = 0;
       i < PDF_NUM_RESOURCE_CATEGORIES; i++) {
    if (!strcmp(category, pdf_resource_categories[i].name)) {
      return pdf_resource_categories[i].cat_id;
    }
  }

  return -1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void pdf_clean_resource ( pdf_res res) [static]

Definition at line 126 of file pdfresource.c.

{
  if (res) {
    if (res->reference || res->object)
      WARN("Trying to release un-flushed object.");
    if (res->reference)
      pdf_release_obj(res->reference);
    if (res->object)
      pdf_release_obj(res->object);
    if (res->ident)
      RELEASE(res->ident);
    res->ident    = NULL;
    res->category = -1;
    res->flags    = 0;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pdf_close_resources ( void  )

Definition at line 157 of file pdfresource.c.

{
  int  i;

  for (i = 0;
       i < PDF_NUM_RESOURCE_CATEGORIES; i++) {
    struct res_cache *rc;
    int    j;

    rc = &resources[i];
    for (j = 0; j < rc->count; j++) {
      pdf_flush_resource(&rc->resources[j]);
      pdf_clean_resource(&rc->resources[j]);
    }
    RELEASE(rc->resources);

    rc->count     = 0;
    rc->capacity  = 0;
    rc->resources = NULL;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

long pdf_defineresource ( const char *  category,
const char *  resname,
pdf_obj object,
int  flags 
)

Definition at line 195 of file pdfresource.c.

{
  int      res_id;
  struct res_cache *rc;
  int      cat_id;
  pdf_res *res = NULL;

  ASSERT(category && object);

  cat_id = get_category(category);
  if (cat_id < 0) {
    ERROR("Unknown resource category: %s", category);
    return -1;
  }

  rc = &resources[cat_id];
  if (resname) {
    for (res_id = 0; res_id < rc->count; res_id++) {
      res = &rc->resources[res_id];
      if (!strcmp(resname, res->ident)) {
       WARN("Resource %s (category: %s) already defined...",
            resname, category);
       pdf_flush_resource(res);
       res->flags    = flags;
       if (flags & PDF_RES_FLUSH_IMMEDIATE) {
         res->reference = pdf_ref_obj(object);
         pdf_release_obj(object);
       } else {
         res->object = object;
       }
       return (long) ((cat_id << 16)|(res_id));
      }
    }
  } else {
    res_id = rc->count;
  }

  if (res_id == rc->count) {
    if (rc->count >= rc->capacity) {
      rc->capacity += CACHE_ALLOC_SIZE;
      rc->resources = RENEW(rc->resources, rc->capacity, pdf_res);
    }
    res = &rc->resources[res_id];

    pdf_init_resource(res);
    if (resname && resname[0] != '\0') {
      res->ident = NEW(strlen(resname) + 1, char);
      strcpy(res->ident, resname);
    }
    res->category = cat_id;
    res->flags    = flags;
    if (flags & PDF_RES_FLUSH_IMMEDIATE) {
      res->reference = pdf_ref_obj(object);
      pdf_release_obj(object);
    } else {
      res->object = object;
    }
    rc->count++;
  }

  return (long) ((cat_id << 16)|(res_id));
}

Here is the call graph for this function:

Here is the caller graph for this function:

long pdf_findresource ( const char *  category,
const char *  resname 
)

Definition at line 288 of file pdfresource.c.

{
  pdf_res *res;
  int      res_id, cat_id;
  struct res_cache *rc;

  ASSERT(resname && category);

  cat_id = get_category(category);
  if (cat_id < 0) {
    ERROR("Unknown resource category: %s", category);
    return -1;
  }

  rc = &resources[cat_id];
  for (res_id = 0; res_id < rc->count; res_id++) {
    res = &rc->resources[res_id];
    if (!strcmp(resname, res->ident)) {
      return (long) (cat_id << 16|res_id);
    }
  }

  return -1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void pdf_flush_resource ( pdf_res res) [static]

Definition at line 112 of file pdfresource.c.

{
  if (res) {
    if (res->reference)
      pdf_release_obj(res->reference);
    if (res->object)
      pdf_release_obj(res->object);

    res->reference = NULL;
    res->object    = NULL;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 314 of file pdfresource.c.

{
  int  cat_id, res_id;
  struct res_cache *rc;
  pdf_res *res;

  cat_id = (rc_id >> 16) & 0xffff;
  res_id = rc_id & 0xffff;

  if (cat_id < 0 ||
      cat_id >= PDF_NUM_RESOURCE_CATEGORIES) {
    ERROR("Invalid category ID: %d", cat_id);
    return NULL;
  }
  rc  = &resources[cat_id];
  if (res_id < 0 || res_id >= rc->count) {
    ERROR("Invalid resource ID: %d", res_id);
    return NULL;
  }

  res = &rc->resources[res_id];
  if (!res->reference) {
    if (!res->object) {
      ERROR("Undefined object...");
      return NULL;
    } else {
      res->reference = pdf_ref_obj(res->object);
    }
  }

  return pdf_link_obj(res->reference);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void pdf_init_resource ( pdf_res res) [static]

Definition at line 97 of file pdfresource.c.

{
  ASSERT(res);

  res->ident     = NULL;
  res->category  = -1;
  res->flags     = 0;
  res->cdata     = NULL;
  res->object    = NULL;
  res->reference = NULL;

  return;
}

Here is the caller graph for this function:

void pdf_init_resources ( void  )

Definition at line 144 of file pdfresource.c.

{
  int  i;

  for (i = 0;
       i < PDF_NUM_RESOURCE_CATEGORIES; i++) {
    resources[i].count     = 0;
    resources[i].capacity  = 0;
    resources[i].resources = NULL;
  }
}

Here is the caller graph for this function:


Variable Documentation

struct { ... } pdf_resource_categories[] [static]

Definition at line 94 of file pdfresource.c.