Back to index

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

Go to the source code of this file.

Defines

#define add_to_used_chars2(b, c)   {(b)[(c)/8] |= (1 << (7-((c)%8)));}
#define is_used_char2(b, c)   (((b)[(c)/8]) & (1 << (7-((c)%8))))

Typedefs

typedef struct Type0Font

Functions

void Type0Font_set_verbose (void)
int Type0Font_get_wmode (Type0Font *font)
char * Type0Font_get_usedchars (Type0Font *font)
pdf_objType0Font_get_resource (Type0Font *font)
void Type0Font_set_ToUnicode (Type0Font *font, pdf_obj *cmap_ref)
int pdf_font_findfont0 (const char *font_name, int cmap_id, fontmap_opt *fmap_opt)
void Type0Font_cache_init (void)
Type0FontType0Font_cache_get (int id)
int Type0Font_cache_find (const char *map_name, int cmap_id, fontmap_opt *fmap_opt)
void Type0Font_cache_close (void)

Define Documentation

#define add_to_used_chars2 (   b,
 
)    {(b)[(c)/8] |= (1 << (7-((c)%8)));}

Definition at line 28 of file type0.h.

#define is_used_char2 (   b,
 
)    (((b)[(c)/8]) & (1 << (7-((c)%8))))

Definition at line 29 of file type0.h.


Typedef Documentation

typedef struct Type0Font

Definition at line 31 of file type0.h.


Function Documentation

int pdf_font_findfont0 ( const char *  font_name,
int  cmap_id,
fontmap_opt fmap_opt 
)

Definition at line 560 of file type0.c.

{
  return Type0Font_cache_find(font_name, cmap_id, fmap_opt);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Type0Font_cache_close ( void  )

Definition at line 529 of file type0.c.

{
  int   font_id;

  /*
   * This need to be fixed.
   *
   * CIDFont_cache_close() before Type0Font_release because of used_chars.
   * ToUnicode support want descendant CIDFont's CSI and fontname.
   */
  if (__cache.fonts) {
    for (font_id = 0; font_id < __cache.count; font_id++)
      Type0Font_dofont(&__cache.fonts[font_id]);
  }
  CIDFont_cache_close();
  if (__cache.fonts) {
    for (font_id = 0; font_id < __cache.count; font_id++) {
      Type0Font_flush(&__cache.fonts[font_id]);
      Type0Font_clean(&__cache.fonts[font_id]);
    }
    RELEASE(__cache.fonts);
  }
  __cache.fonts    = NULL;
  __cache.count    = 0;
  __cache.capacity = 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int Type0Font_cache_find ( const char *  map_name,
int  cmap_id,
fontmap_opt fmap_opt 
)

Definition at line 365 of file type0.c.

{
  int         font_id = -1;
  Type0Font  *font;
  CIDFont    *cidfont;
  CMap       *cmap;
  CIDSysInfo *csi;
  char       *fontname = NULL;
  int         cid_id = -1, parent_id = -1, wmode = 0;
  int         pdf_ver;

  pdf_ver = pdf_get_version();
  if (!map_name || cmap_id < 0 || pdf_ver < 2)
    return -1;

  /*
   * Encoding is Identity-H or Identity-V according as thier WMode value.
   * 
   * We do not use match against the map_name since fonts (TrueType) covers
   * characters across multiple character collection (eg, Adobe-Japan1 and
   * Adobe-Japan2) must be splited into multiple CID-keyed fonts.
   */

  cmap = CMap_cache_get(cmap_id);
  csi  = (CMap_is_Identity(cmap)) ? NULL : CMap_get_CIDSysInfo(cmap) ;

  cid_id = CIDFont_cache_find(map_name, csi, fmap_opt);

  if (cid_id < 0) 
    return -1;

  /*
   * The descendant CID-keyed font has already been registerd.
   * If CID-keyed font with ID = cid_id is new font, then create new parent
   * Type 0 font. Otherwise, there already exists parent Type 0 font and
   * then we find him and return his ID. We must check against their WMode.
   */

  cidfont = CIDFont_cache_get(cid_id);
  wmode   = CMap_get_wmode(cmap);

  /* Does CID-keyed font already have parent ? */
  parent_id = CIDFont_get_parent_id(cidfont, wmode);
  if (parent_id >= 0)
    return parent_id; /* If so, we don't need new one. */

  /*
   * CIDFont does not have parent or his parent's WMode does not matched with
   * wmode. Create new Type0 font.
   */

  if (__cache.count >= __cache.capacity) {
    __cache.capacity += CACHE_ALLOC_SIZE;
    __cache.fonts     = RENEW(__cache.fonts, __cache.capacity, struct Type0Font);
  }
  font_id =  __cache.count;
  font    = &__cache.fonts[font_id];

  Type0Font_init_font_struct(font);

  /*
   * All CJK double-byte characters are mapped so that resulting
   * character codes coincide with CIDs of given character collection.
   * So, the Encoding is always Identity-H for horizontal fonts or
   * Identity-V for vertical fonts.
   */
  if (wmode) {
    font->encoding = NEW(strlen("Identity-V")+1, char);
    strcpy(font->encoding, "Identity-V");
  } else {
    font->encoding = NEW(strlen("Identity-H")+1, char);
    strcpy(font->encoding, "Identity-H");
  }
  font->wmode = wmode;

  /*
   * Now we start font dictionary.
   */
  font->fontdict = pdf_new_dict();
  pdf_add_dict(font->fontdict, pdf_new_name ("Type"),    pdf_new_name ("Font"));
  pdf_add_dict(font->fontdict, pdf_new_name ("Subtype"), pdf_new_name ("Type0"));

  /*
   * Type0 font does not have FontDescriptor because it is not a simple font.
   * Instead, DescendantFonts appears here.
   *
   * Up to PDF version 1.5, Type0 font must have single descendant font which
   * is a CID-keyed font. Future PDF spec. will allow multiple desecendant
   * fonts.
   */
  font->descendant = cidfont;
  CIDFont_attach_parent(cidfont, font_id, wmode);

  /*
   * PostScript Font name:
   *
   *  Type0 font's fontname is usually descendant CID-keyed font's font name 
   *  appended by -ENCODING.
   */
  fontname = CIDFont_get_fontname(cidfont);

  if (__verbose) {
    if (CIDFont_get_embedding(cidfont) && strlen(fontname) > 7)
      MESG("(CID:%s)", fontname+7); /* skip XXXXXX+ */
    else
      MESG("(CID:%s)", fontname);
  }

  /*
   * The difference between CID-keyed font and TrueType font appears here.
   *
   * Glyph substitution for vertical writing is done in CMap mapping process
   * for CID-keyed fonts. But we must rely on OpenType layout table in the
   * case of TrueType fonts. So, we must use different used_chars for each
   * horizontal and vertical fonts in that case.
   *
   * In most PDF file, encoding name is not appended to fontname for Type0
   * fonts having CIDFontType 2 font as their descendant.
   */

  font->used_chars = NULL;
  font->flags      = FLAG_NONE;

  switch (CIDFont_get_subtype(cidfont)) {
  case CIDFONT_TYPE0:
    font->fontname = NEW(strlen(fontname)+strlen(font->encoding)+2, char);
    sprintf(font->fontname, "%s-%s", fontname, font->encoding);
    pdf_add_dict(font->fontdict,
                 pdf_new_name("BaseFont"), pdf_new_name(font->fontname));
    /*
     * Need used_chars to write W, W2.
     */
    if ((parent_id = CIDFont_get_parent_id(cidfont, wmode ? 0 : 1)) < 0)
      font->used_chars = new_used_chars2();
    else {
      /* Don't allocate new one. */
      font->used_chars = Type0Font_get_usedchars(Type0Font_cache_get(parent_id));
      font->flags     |= FLAG_USED_CHARS_SHARED;
    }
    break;
  case CIDFONT_TYPE2:
    /*
     * TrueType:
     *
     *  Use different used_chars for H and V.
     */
    pdf_add_dict(font->fontdict,
                 pdf_new_name("BaseFont"), pdf_new_name(fontname));
    font->used_chars = new_used_chars2();
    break;
  default:
    ERROR("Unrecognized CIDFont Type");
    break;
  }

  pdf_add_dict(font->fontdict,
               pdf_new_name("Encoding"), pdf_new_name(font->encoding));

  __cache.count++;

  return font_id;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 357 of file type0.c.

{
  CHECK_ID(id);

  return &__cache.fonts[id];
}

Here is the caller graph for this function:

void Type0Font_cache_init ( void  )

Definition at line 347 of file type0.c.

{
  if (__cache.fonts)
    ERROR("%s: Already initialized.", TYPE0FONT_DEBUG_STR);
  __cache.count    = 0;
  __cache.capacity = 0;
  __cache.fonts    = NULL;
}

Here is the caller graph for this function:

Definition at line 310 of file type0.c.

{
  ASSERT(font);

  /*
   * This looks somewhat strange.
   */
  if (!font->indirect) {
    pdf_obj *array;

    array = pdf_new_array();
    pdf_add_array(array, CIDFont_get_resource(font->descendant));
    pdf_add_dict(font->fontdict, pdf_new_name("DescendantFonts"), array);
    font->indirect = pdf_ref_obj(font->fontdict);
  }

  return pdf_link_obj(font->indirect);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 302 of file type0.c.

{
  ASSERT(font);

  return font->used_chars;
}

Here is the caller graph for this function:

int Type0Font_get_wmode ( Type0Font font)

Definition at line 284 of file type0.c.

{
  ASSERT(font);

  return font->wmode;
}

Here is the caller graph for this function:

void Type0Font_set_ToUnicode ( Type0Font font,
pdf_obj cmap_ref 
)

Definition at line 248 of file type0.c.

{
  ASSERT(font);

  pdf_add_dict(font->fontdict,
              pdf_new_name("ToUnicode"), cmap_ref);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Type0Font_set_verbose ( void  )

Definition at line 59 of file type0.c.

{
  __verbose++;
}

Here is the caller graph for this function: