Ejemplo n.º 1
0
int
Type0Font_cache_find (const char *map_name, int cmap_id, fontmap_opt *fmap_opt)
{
  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);
  }
Ejemplo n.º 2
0
int
CMap_parse (CMap *cmap, FILE *fp)
{
  pst_obj  *tok1, *tok2;
  ifreader *input;
  int       status = 0, tmpint = -1;

  ASSERT(cmap && fp);

  input = ifreader_create(fp, file_size(fp), INPUT_BUF_SIZE-1);

  while (status >= 0) {
    tok1 = tok2 = NULL;
    ifreader_read(input, INPUT_BUF_SIZE/2);
    tok1 = pst_get_token(&(input->cursor), input->endptr);
    if (tok1 == NULL)
      break;
    else if (MATCH_NAME(tok1, "CMapName")) {
      if ((tok2 = pst_get_token(&(input->cursor), input->endptr)) == NULL ||
	  !(PST_NAMETYPE(tok2) || PST_STRINGTYPE(tok2)) ||
	  check_next_token(input, "def") < 0)
	status = -1;
      else
	CMap_set_name(cmap, pst_data_ptr(tok2));
    } else if (MATCH_NAME(tok1, "CMapType")) {
      if ((tok2 = pst_get_token(&(input->cursor), input->endptr)) == NULL ||
	  !PST_INTEGERTYPE(tok2) ||
	  check_next_token(input, "def") < 0)
	status = -1;
      else
	CMap_set_type(cmap, pst_getIV(tok2));
    } else if (MATCH_NAME(tok1, "WMode")) {
      if ((tok2 = pst_get_token(&(input->cursor), input->endptr)) == NULL ||
	  !PST_INTEGERTYPE(tok2) ||
	  check_next_token(input, "def") < 0)
	status = -1;
      else
	CMap_set_wmode(cmap, pst_getIV(tok2));
    } else if (MATCH_NAME(tok1, "CIDSystemInfo")) {
      status = do_cidsysteminfo(cmap, input);
    } else if (MATCH_NAME(tok1, "Version") ||
	       MATCH_NAME(tok1, "UIDOffset") ||
	       MATCH_NAME(tok1, "XUID")) {
	/* Ignore */
    } else if (PST_NAMETYPE(tok1)) {
      /* Possibly usecmap comes next */
      if ((tok2 = pst_get_token(&(input->cursor), input->endptr)) != NULL &&
	  MATCH_OP(tok2, "usecmap")) {
	int   id;
	CMap *ucmap;
	id = CMap_cache_find(pst_data_ptr(tok1));
	if (id < 0)
	  status = -1;
	else {
	  ucmap = CMap_cache_get(id);
	  CMap_set_usecmap(cmap, ucmap);
	}
      }
    } else if (MATCH_OP(tok1, "begincodespacerange")) {
      status = do_codespacerange(cmap, input, tmpint);
    } else if (MATCH_OP(tok1, "beginnotdefrange")) {
      status = do_notdefrange(cmap, input, tmpint);
    } else if (MATCH_OP(tok1, "beginnotdefchar")) {
      status = do_notdefchar(cmap, input, tmpint);
    } else if (MATCH_OP(tok1, "beginbfrange")) {
      status = do_bfrange(cmap, input, tmpint);
    } else if (MATCH_OP(tok1, "beginbfchar")) {
      status =  do_bfchar(cmap, input, tmpint);
    } else if (MATCH_OP(tok1, "begincidrange")) {
      status = do_cidrange(cmap, input, tmpint);
    } else if (MATCH_OP(tok1, "begincidchar")) {
      status =  do_cidchar(cmap, input, tmpint);
    } else if (PST_INTEGERTYPE(tok1)) {
      tmpint = pst_getIV(tok1);
    } /* else Simply ignore */
    if (tok1)
      pst_release_obj(tok1);
    if (tok2)
      pst_release_obj(tok2);
  }

  ifreader_destroy(input);

  return (status < 0) ? -1 : CMap_is_valid(cmap);
}