/* Copyright (C) 1989, 1992 Aladdin Enterprises. All rights reserved.
Distributed by Free Software Foundation, Inc.
This file is part of Ghostscript.
Ghostscript is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY. No author or distributor accepts responsibility
to anyone for the consequences of using it or for whether it serves any
particular purpose or works at all, unless he says so in writing. Refer
to the Ghostscript General Public License for full details.
Everyone is granted permission to copy, modify and redistribute
Ghostscript, but only under the conditions described in the Ghostscript
General Public License. A copy of this license is supposed to have been
given to you along with Ghostscript so you can know your rights and
responsibilities. It should be in a file named COPYING. Among other
things, the copyright notice and this notice must be preserved on all
/* Font creation operator for Ghostscript */
/* Imported procedures */
int add_FID(P2(ref
*, gs_font
*)); /* in zfont */
int font_int_param(P6(ref
*pdict
, ref
*pname
, int minval
, int maxval
, int defaultval
, int *pvalue
));
int build_gs_simple_font(P4(os_ptr
, gs_font
**, font_type
, ref
*));
int build_gs_font(P4(os_ptr
, gs_font
**, font_type
, ref
*)); /* buildfont0 needs this */
/* Global font-related objects */
/* Names of system-known keys in font dictionaries: */
extern ref name_FID
; /* in zfont.c */
extern ref name_FontMatrix
; /* in zfont.c */
private ref name_FontType
;
private ref name_FontBBox
;
private ref name_Encoding
;
ref name_UniqueID
; /* used by zfont1 */
private ref name_BuildChar
;
/* The global font directory */
extern gs_font_dir
*ifont_dir
;
/* Initialize the font building operators */
{ static const names_def fnd2
[] = {
/* Create the names of the standard elements of */
{ "FontType", &name_FontType
},
{ "WMode", &name_WMode
},
{ "FontBBox", &name_FontBBox
},
{ "Encoding", &name_Encoding
},
{ "UniqueID", &name_UniqueID
},
{ "BuildChar", &name_BuildChar
},
/* Mark the end of the initalized name list. */
/* Build a type 3 (user-defined) font. */
check_type(*op
, t_dictionary
);
code
= dict_find(op
, &name_BuildChar
, &pbuildchar
);
if ( code
<= 0 ) return e_invalidfont
;
return build_gs_simple_font(op
, &pfont
, ft_user_defined
, pbuildchar
);
/* ------ Initialization procedure ------ */
op_def zfont2_op_defs
[] = {
{"1.buildfont3", zbuildfont3
},
/* ------ Subroutines ------ */
/* Get an integer parameter from a font-related dictionary. */
/* Return 0 if found, 1 if defaulted, <0 if missing or out of range. */
font_int_param(ref
*pdict
, ref
*pname
, int minval
, int maxval
,
int defaultval
, int *pvalue
)
if ( dict_find(pdict
, pname
, &pdval
) <= 0 )
if ( !r_has_type(pdval
, t_integer
) )
if ( pdval
->value
.intval
< minval
|| pdval
->value
.intval
> maxval
)
*pvalue
= (int)pdval
->value
.intval
;
/* Do the common work for building a font of any non-composite FontType. */
/* The caller guarantees that *op is a dictionary. */
build_gs_simple_font(os_ptr op
, gs_font
**ppfont
, font_type ftype
, ref
*pbuildchar
)
if ( dict_find(op
, &name_FontBBox
, &pbbox
) <= 0 )
default: return e_invalidfont
;
case t_array
: case t_mixedarray
: case t_shortarray
: ;
if ( r_size(pbbox
) != 4 ) return e_invalidfont
;
{ ushort
*pbe
= pbbox
->value
.packed
;
for ( i
= 0; i
< 4; i
++ )
{ packed_get(pbe
, rbe
+ i
);
if ( num_params(rbe
+ 3, 4, bbox
) < 0 )
/* If no UniqueID entry, set the UniqueID member to -1, */
/* 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(op
, &name_UniqueID
, &puniqueid
) <= 0 )
{ if ( !r_has_type(puniqueid
, t_integer
) ||
puniqueid
->value
.intval
< 0 ||
puniqueid
->value
.intval
> ((1L << 24) - 1)
unique_id
= puniqueid
->value
.intval
;
code
= build_gs_font(op
, ppfont
, ftype
, pbuildchar
);
if ( code
!= 0 ) return code
; /* invalid or scaled font */
pfont
->data
.base
.FontBBox
.p
.x
= bbox
[0];
pfont
->data
.base
.FontBBox
.p
.y
= bbox
[1];
pfont
->data
.base
.FontBBox
.q
.x
= bbox
[2];
pfont
->data
.base
.FontBBox
.q
.y
= bbox
[3];
pfont
->data
.base
.UniqueID
= unique_id
;
/* Do the common work for building a font of any FontType. */
/* The caller guarantees that *op is a dictionary. */
/* Return 0 for a new font, 1 for a font made by makefont or scalefont, */
/* or a negative error code. */
build_gs_font(os_ptr op
, gs_font
**ppfont
, font_type ftype
, ref
*pbuildchar
)
ref
*aop
= dict_access_ref(op
);
if ( dict_find(op
, &name_FontType
, &pftype
) <= 0 ||
!r_has_type(pftype
, t_integer
) ||
pftype
->value
.intval
!= (int)ftype
||
dict_find(op
, &name_FontMatrix
, &pmatrix
) <= 0 ||
dict_find(op
, &name_Encoding
, &pencoding
) <= 0 ||
read_matrix(pmatrix
, &mat
) < 0
switch ( r_type(pencoding
) )
default: return e_invalidfont
;
case t_array
: case t_mixedarray
: case t_shortarray
: ;
code
= font_int_param(op
, &name_WMode
, 0, 1, 0, &wmode
);
if ( code
< 0 ) return code
;
code
= dict_find(op
, &name_FID
, &pfid
);
if ( r_has_attr(aop
, a_write
) )
{ /* Assume this is a new font */
if ( code
> 0 ) return e_invalidfont
; /* has FID already */
if ( (pfont
= (gs_font
*)alloc(1, sizeof(gs_font
), "buildfont(font)")) == 0 ||
(pdata
= (font_data
*)alloc(1, sizeof(font_data
), "buildfont(data)")) == 0
if ( (code
= add_FID(op
, pfont
)) < 0 ) return code
;
ref_assign(&pdata
->dict
, op
);
ref_assign(&pdata
->BuildChar
, pbuildchar
);
ref_assign(&pdata
->Encoding
, pencoding
);
pfont
->client_data
= (char *)pdata
;
pfont
->build_char_proc
= gs_no_build_char_proc
;
{ /* Assume this was made by makefont or scalefont */
if ( code
<= 0 || !r_has_type(pfid
, t_fontID
) )
pfont
= pfid
->value
.pfont
;