SV* Application_fonts( Handle self, char * name, char * encoding) { int count, i; AV * glo = newAV(); PFont fmtx = apc_fonts( self, name[0] ? name : nil, encoding[0] ? encoding : nil, &count); for ( i = 0; i < count; i++) { SV * sv = sv_Font2HV( &fmtx[ i]); HV * profile = ( HV*) SvRV( sv); if ( fmtx[i]. utf8_flags & FONT_UTF8_NAME) { SV ** entry = hv_fetch(( HV*) SvRV( sv), "name", 4, 0); if ( entry && SvOK( *entry)) SvUTF8_on( *entry); } if ( fmtx[i]. utf8_flags & FONT_UTF8_FAMILY) { SV ** entry = hv_fetch(( HV*) SvRV( sv), "family", 6, 0); if ( name && SvOK( *entry)) SvUTF8_on( *entry); } if ( fmtx[i]. utf8_flags & FONT_UTF8_ENCODING) { SV ** entry = hv_fetch(( HV*) SvRV( sv), "encoding", 8, 0); if ( name && SvOK( *entry)) SvUTF8_on( *entry); } if ( name[0] == 0 && encoding[0] == 0) { /* Read specially-coded (const char*) encodings[] vector, stored in fmtx[i].encoding. First pointer is filled with 0s, except the last byte which is a counter. Such scheme allows max 31 encodings per entry to be coded with sizeof(char*)==8. The interface must be re-implemented, but this requires either change in gencls syntax so arrays can be members of hashes, or passing of a dynamic-allocated pointer vector here. */ char ** enc = (char**) fmtx[i].encoding; unsigned char * shift = (unsigned char*) enc + sizeof(char *) - 1, j = *shift; AV * loc = newAV(); pset_sv_noinc( encoding, newSVpv(( j > 0) ? *(++enc) : "", 0)); while ( j--) av_push( loc, newSVpv(*(enc++),0)); pset_sv_noinc( encodings, newRV_noinc(( SV*) loc)); } pdelete( resolution); pdelete( codepage); av_push( glo, sv); } free( fmtx); return newRV_noinc(( SV *) glo); }
SV* Widget_fetch_resource( char *className, char *name, char *classRes, char *res, Handle owner, int resType) { char *str = nil; Color clr; void *parm; Font font; SV * ret; switch ( resType) { case frColor: parm = &clr; break; case frFont: parm = &font; bzero( &font, sizeof( font)); break; default: parm = &str; resType = frString; } if ( !apc_fetch_resource( prima_normalize_resource_string( className, true), prima_normalize_resource_string( name, false), prima_normalize_resource_string( classRes, true), prima_normalize_resource_string( res, false), owner, resType, parm)) return nilSV; switch ( resType) { case frColor: ret = newSViv( clr); break; case frFont: ret = sv_Font2HV( &font); break; default: ret = str ? newSVpv( str, 0) : nilSV; free( str); } return ret; }