moved font plotter allocation

Delayed font plotter alloction until the requested
font plotter is found.
This commit is contained in:
Ole Loots 2013-09-15 04:15:26 +02:00
parent 2c0bcc39bd
commit 258477ad28
1 changed files with 51 additions and 47 deletions

View File

@ -45,63 +45,67 @@ void dump_font_drivers(void)
} }
/* /**
* Create an new text plotter object * Create an new text plotter object
* Available: "vdi", "freetype" *
* @param vdihandle the vdi handle to act upon, * Available: "vdi", "freetype", "internal"
* @param name selector ID (string) of the font plotter. * \param vdihandle the vdi handle to act upon,
* @flags flags configration flags of the plotter, * \param name selector ID (string) of the font plotter.
* flags flags configration flags of the plotter,
* available flags: * available flags:
* FONTPLOT_FLAG_MONOGLYPH - Enable 1 bit font plotting * FONTPLOT_FLAG_MONOGLYPH - Enable 1 bit font plotting
* @param error set to != 0 when errors occur * \param error set to != 0 when errors occur
* \return the new font plotter instance on success, or NULL on failure.
*/ */
FONT_PLOTTER new_font_plotter( int vdihandle, char * name, unsigned long flags, FONT_PLOTTER new_font_plotter(int vdihandle, char * name, unsigned long flags,
int * error) int * error)
{ {
int i=0; int i=0;
int res = 0-ERR_PLOTTER_NOT_AVAILABLE; int res = 0-ERR_PLOTTER_NOT_AVAILABLE;
FONT_PLOTTER fplotter; FONT_PLOTTER fplotter = NULL;
/* allocate the font plotter instance: */ /* set the default error code: */
fplotter = (FONT_PLOTTER)malloc( sizeof(struct s_font_plotter) ); *error = 0-ERR_PLOTTER_NOT_AVAILABLE;
if( fplotter == NULL ) {
*error = 0-ERR_NO_MEM;
return( NULL );
}
/* Initialize the font plotter with the requested settings: */
memset( fplotter, 0, sizeof(FONT_PLOTTER));
fplotter->vdi_handle = vdihandle;
fplotter->name = name;
fplotter->flags = 0;
fplotter->flags |= flags;
/* Find the selector string in the font plotter table: */ /* Find the selector string in the font plotter table, */
/* And bail out when the font plotter is not available: */ /* and bail out when the font plotter is not available: */
for( i = 0; ; i++) { for (i = 0; font_driver_table[i].name != NULL; i++) {
if( font_driver_table[i].name == NULL ) {
res = 0-ERR_PLOTTER_NOT_AVAILABLE; /* found selector in driver table? */
break; if (strcmp(name, font_driver_table[i].name) == 0) {
} else {
if( strcmp(name, font_driver_table[i].name) == 0 ) { /* allocate the font plotter instance: */
if( font_driver_table[i].ctor ) { fplotter = (FONT_PLOTTER)malloc(sizeof(struct s_font_plotter));
res = font_driver_table[i].ctor( fplotter ); if (fplotter == NULL) {
*error = 0; *error = 0-ERR_NO_MEM;
} else { return(NULL);
res = 0-ERR_PLOTTER_NOT_AVAILABLE;
*error = res;
return (NULL);
}
break;
} }
/* Initialize the font plotter with the requested settings: */
memset( fplotter, 0, sizeof(FONT_PLOTTER));
fplotter->vdi_handle = vdihandle;
fplotter->name = name;
fplotter->flags = 0;
fplotter->flags |= flags;
/* Execute the constructor: */
assert(font_driver_table[i].ctor);
res = font_driver_table[i].ctor(fplotter);
/* success? */
if (res < 0) {
/* NO success! */
free(fplotter);
*error = res;
return(NULL);
}
*error = 0;
break;
} }
} }
if( res < 0 ) {
free( fplotter ); return(fplotter);
*error = res;
return( NULL );
}
return( fplotter );
} }
/* /*
@ -109,13 +113,13 @@ FONT_PLOTTER new_font_plotter( int vdihandle, char * name, unsigned long flags,
*/ */
int delete_font_plotter(FONT_PLOTTER p) int delete_font_plotter(FONT_PLOTTER p)
{ {
if( p ) { if (p) {
p->dtor(p); p->dtor(p);
free( p ); free(p);
p = NULL; p = NULL;
} }
else else
return( -1 ); return(-1);
return( 0 ); return(0);
} }