/* The caller guarantees that *op is a dictionary. */ int build_gs_primitive_font(i_ctx_t *i_ctx_p, os_ptr op, gs_font_base ** ppfont, font_type ftype, gs_memory_type_ptr_t pstype, const build_proc_refs * pbuild, build_font_options_t options) { ref *pcharstrings = 0; ref CharStrings; gs_font_base *pfont; font_data *pdata; int code; if (dict_find_string(op, "CharStrings", &pcharstrings) <= 0) { if (!(options & bf_CharStrings_optional)) return_error(e_invalidfont); } else { ref *ignore; if (!r_has_type(pcharstrings, t_dictionary)) return_error(e_invalidfont); if ((options & bf_notdef_required) != 0 && dict_find_string(pcharstrings, ".notdef", &ignore) <= 0 ) return_error(e_invalidfont); /* * Since build_gs_simple_font may resize the dictionary and cause * pointers to become invalid, save CharStrings. */ CharStrings = *pcharstrings; } code = build_gs_outline_font(i_ctx_p, op, ppfont, ftype, pstype, pbuild, options, build_gs_simple_font); if (code != 0) return code; pfont = *ppfont; pdata = pfont_data(pfont); if (pcharstrings) ref_assign(&pdata->CharStrings, &CharStrings); else make_null(&pdata->CharStrings); /* Check that the UniqueIDs match. This is part of the */ /* Adobe protection scheme, but we may as well emulate it. */ if (uid_is_valid(&pfont->UID) && !dict_check_uid_param(op, &pfont->UID) ) uid_set_invalid(&pfont->UID); if (uid_is_valid(&pfont->UID)) { const gs_font *pfont0 = (const gs_font *)pfont; code = gs_font_find_similar(ifont_dir, &pfont0, font_with_same_UID_and_another_metrics); if (code < 0) return code; /* Must not happen. */ if (code) uid_set_invalid(&pfont->UID); } return 0; }
int build_gs_FDArray_font(i_ctx_t *i_ctx_p, ref *op, gs_font_base **ppfont, font_type ftype, gs_memory_type_ptr_t pstype, const build_proc_refs * pbuild) { gs_font_base *pfont; font_data *pdata; int code = build_gs_outline_font(i_ctx_p, op, &pfont, ftype, pstype, pbuild, bf_options_none, build_FDArray_sub_font); static const double bbox[4] = { 0, 0, 0, 0 }; gs_uid uid; if (code < 0) return code; pdata = pfont_data(pfont); /* Fill in members normally set by build_gs_primitive_font. */ make_null(&pdata->CharStrings); /* Fill in members normally set by build_gs_simple_font. */ uid_set_invalid(&uid); init_gs_simple_font(pfont, bbox, &uid); pfont->encoding_index = ENCODING_INDEX_UNKNOWN; pfont->nearest_encoding_index = ENCODING_INDEX_UNKNOWN; /* Fill in members normally set by build_gs_font. */ pfont->key_name = pfont->font_name; *ppfont = pfont; return 0; }
/* Initialize a generic pattern template. */ void gs_pattern_common_init(gs_pattern_template_t * ppat, const gs_pattern_type_t *type) { ppat->type = type; ppat->PatternType = type->PatternType; uid_set_invalid(&ppat->uid); ppat->client_data = 0; /* for GC */ }
/* The caller guarantees that *op is a dictionary. */ int build_gs_simple_font(i_ctx_t *i_ctx_p, os_ptr op, gs_font_base ** ppfont, font_type ftype, gs_memory_type_ptr_t pstype, const build_proc_refs * pbuild, build_font_options_t options) { double bbox[4]; gs_uid uid; int code; gs_font_base *pfont; uint space = ialloc_space(idmemory); code = font_bbox_param(imemory, op, bbox); if (code < 0) return code; /* * Make sure that we allocate uid * in the same VM as the font dictionary * (see build_gs_sub_font). */ ialloc_set_space(idmemory, r_space(op)); code = dict_uid_param(op, &uid, 0, imemory, i_ctx_p); ialloc_set_space(idmemory, space); if (code < 0) return code; if ((options & bf_UniqueID_ignored) && uid_is_UniqueID(&uid)) uid_set_invalid(&uid); code = build_gs_font(i_ctx_p, op, (gs_font **) ppfont, ftype, pstype, pbuild, options); if (code != 0) /* invalid or scaled font */ return code; pfont = *ppfont; pfont->procs.init_fstack = gs_default_init_fstack; pfont->procs.define_font = gs_no_define_font; pfont->procs.decode_glyph = gs_font_map_glyph_to_unicode; pfont->procs.make_font = zbase_make_font; pfont->procs.next_char_glyph = gs_default_next_char_glyph; pfont->FAPI = 0; pfont->FAPI_font_data = 0; init_gs_simple_font(pfont, bbox, &uid); lookup_gs_simple_font_encoding(pfont); get_GlyphNames2Unicode(i_ctx_p, (gs_font *)pfont, op); return 0; }
/* If there is no uid, return default. */ int dict_uid_param(const ref * pdict, gs_uid * puid, int defaultval, gs_memory_t * mem, const i_ctx_t *i_ctx_p) { ref *puniqueid; if (pdict == 0) { uid_set_invalid(puid); return defaultval; } /* In a Level 2 environment, check for XUID first. */ if (level2_enabled && dict_find_string(pdict, "XUID", &puniqueid) > 0 ) { long *xvalues; uint size, i; if (!r_has_type(puniqueid, t_array)) return_error(e_typecheck); size = r_size(puniqueid); if (size == 0) return_error(e_rangecheck); xvalues = (long *)gs_alloc_byte_array(mem, size, sizeof(long), "get XUID"); if (xvalues == 0) return_error(e_VMerror); /* Get the values from the XUID array. */ for (i = 0; i < size; i++) { const ref *pvalue = puniqueid->value.const_refs + i; if (!r_has_type(pvalue, t_integer)) { gs_free_object(mem, xvalues, "get XUID"); return_error(e_typecheck); } xvalues[i] = pvalue->value.intval; } uid_set_XUID(puid, xvalues, size); return 1; } /* If no UniqueID entry, set the UID to invalid, */ /* because UniqueID need not be present in all fonts, */ /* and if it is, the legal range is 0 to 2^24-1. */ if (dict_find_string(pdict, "UniqueID", &puniqueid) <= 0) { uid_set_invalid(puid); return defaultval; } else { if (!r_has_type(puniqueid, t_integer)) return_error(e_typecheck); if (puniqueid->value.intval < 0 || puniqueid->value.intval > 0xffffff) return_error(e_rangecheck); /* Apparently fonts created by Fontographer often have */ /* a UniqueID of 0, contrary to Adobe's specifications. */ /* Treat 0 as equivalent to -1 (no UniqueID). */ if (puniqueid->value.intval == 0) { uid_set_invalid(puid); return defaultval; } else uid_set_UniqueID(puid, puniqueid->value.intval); } return 0; }