/* Make a transformed font (common code for makefont/scalefont). */ static int make_font(i_ctx_t *i_ctx_p, const gs_matrix * pmat) { os_ptr op = osp; os_ptr fp = op - 1; gs_font *oldfont, *newfont; int code; ref *pencoding = 0; code = font_param(fp, &oldfont); if (code < 0) return code; { uint space = ialloc_space(idmemory); ialloc_set_space(idmemory, r_space(fp)); if (dict_find_string(fp, "Encoding", &pencoding) > 0 && !r_is_array(pencoding) ) code = gs_note_error(e_invalidfont); else { /* * Temporarily substitute the new dictionary * for the old one, in case the Encoding changed. */ ref olddict; olddict = *pfont_dict(oldfont); *pfont_dict(oldfont) = *fp; code = gs_makefont(ifont_dir, oldfont, pmat, &newfont); *pfont_dict(oldfont) = olddict; } ialloc_set_space(idmemory, space); } if (code < 0) return code; /* * We have to allow for the possibility that the font's Encoding * is different from that of the base font. Note that the * font_data of the new font was simply copied from the old one. */ if (pencoding != 0 && !obj_eq(imemory, pencoding, &pfont_data(newfont)->Encoding) ) { if (newfont->FontType == ft_composite) return_error(e_rangecheck); /* We should really do validity checking here.... */ ref_assign(&pfont_data(newfont)->Encoding, pencoding); lookup_gs_simple_font_encoding((gs_font_base *) newfont); } *fp = *pfont_dict(newfont); pop(1); return 0; }
/* 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; }