/* The caller guarantees that *op is a dictionary. */ int build_gs_sub_font(i_ctx_t *i_ctx_p, const ref *op, gs_font **ppfont, font_type ftype, gs_memory_type_ptr_t pstype, const build_proc_refs * pbuild, const ref *pencoding, ref *fid_op) { gs_matrix mat, omat; ref fname; /* t_string */ gs_font *pfont; font_data *pdata; /* * Make sure that we allocate the font data * in the same VM as the font dictionary. */ uint space = ialloc_space(idmemory); int code = sub_font_params(imemory, op, &mat, &omat, &fname); if (code < 0) return code; ialloc_set_space(idmemory, r_space(op)); pfont = gs_font_alloc(imemory, pstype, &gs_font_procs_default, NULL, "buildfont(font)"); pdata = ialloc_struct(font_data, &st_font_data, "buildfont(data)"); if (pfont == 0 || pdata == 0) code = gs_note_error(e_VMerror); else if (fid_op) code = add_FID(i_ctx_p, fid_op, pfont, iimemory); if (code < 0) { ifree_object(pdata, "buildfont(data)"); ifree_object(pfont, "buildfont(font)"); ialloc_set_space(idmemory, space); return code; } refset_null((ref *) pdata, sizeof(font_data) / sizeof(ref)); ref_assign_new(&pdata->dict, op); ref_assign_new(&pdata->BuildChar, &pbuild->BuildChar); ref_assign_new(&pdata->BuildGlyph, &pbuild->BuildGlyph); if (pencoding) ref_assign_new(&pdata->Encoding, pencoding); pfont->client_data = pdata; pfont->FontType = ftype; pfont->FontMatrix = mat; pfont->orig_FontMatrix = omat; pfont->BitmapWidths = false; pfont->ExactSize = fbit_use_bitmaps; pfont->InBetweenSize = fbit_use_outlines; pfont->TransformedChar = fbit_use_outlines; pfont->WMode = 0; pfont->procs.encode_char = zfont_encode_char; pfont->procs.glyph_name = zfont_glyph_name; ialloc_set_space(idmemory, space); copy_font_name(&pfont->font_name, &fname); *ppfont = pfont; return 0; }
/* Create a Type 0 wrapper for a CIDFont/CMap pair. */ static int type0_from_cidfont_cmap(gs_font_type0 **ppfont0, gs_font *font, gs_cmap_t *pcmap, int wmode, const gs_matrix *psmat, gs_memory_t *mem) { gs_font_type0 *font0 = (gs_font_type0 *) gs_font_alloc(mem, &st_gs_font_type0, &gs_font_procs_default, NULL, "gs_type0_from_cidfont(font)"); /* We allocate Encoding dynamically only for the sake of the GC. */ uint *encoding = (uint *) gs_alloc_bytes(mem, sizeof(uint), "gs_type0_from_cidfont(Encoding)"); gs_font **fdep = gs_alloc_struct_array(mem, 1, gs_font *, &st_gs_font_ptr_element, "gs_type0_from_cidfont(FDepVector)"); int code; if (font0 == 0 || encoding == 0 || fdep == 0) { gs_free_object(mem, fdep, "gs_type0_from_cidfont(FDepVector)"); gs_free_object(mem, encoding, "gs_type0_from_cidfont(Encoding)"); gs_free_object(mem, font0, "gs_type0_from_cidfont(font)"); return_error(gs_error_VMerror); } if (psmat) font0->FontMatrix = *psmat; else gs_make_identity(&font0->FontMatrix); font0->FontType = ft_composite; font0->procs.init_fstack = gs_type0_init_fstack; font0->procs.define_font = gs_no_define_font; font0->procs.make_font = 0; /* not called */ font0->procs.next_char_glyph = gs_type0_next_char_glyph; font0->key_name = font->key_name; font0->font_name = font->font_name; font0->data.FMapType = fmap_CMap; encoding[0] = 0; font0->data.Encoding = encoding; font0->data.encoding_size = 1; fdep[0] = font; font0->data.FDepVector = fdep; font0->data.fdep_size = 1; font0->data.CMap = pcmap; font0->data.SubsVector.data = 0; font0->data.SubsVector.size = 0; code = gs_definefont(font->dir, (gs_font *)font0); if (code < 0) return code; *ppfont0 = font0; return 0; }