Mercurial > MadButterfly
diff src/shape_path.c @ 197:bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
author | wycc@wycc-desktop |
---|---|
date | Wed, 19 Nov 2008 00:27:20 +0800 |
parents | 530bb7728546 |
children | 75ec0124202a |
line wrap: on
line diff
--- a/src/shape_path.c Tue Nov 18 21:42:30 2008 +0800 +++ b/src/shape_path.c Wed Nov 19 00:27:20 2008 +0800 @@ -713,6 +713,42 @@ return (shape_t *)path; } +shape_t *rdman_shape_path_new_from_binary(redraw_man_t *rdman, char *commands, co_aix *arg,int arg_cnt,int *fix_arg,int fix_arg_cnt) { + sh_path_t *path; + int msz; + int cmd_cnt = strlen(commands); + + /*! \todo Use elmpool to manage sh_path_t objects. */ + path = (sh_path_t *)malloc(sizeof(sh_path_t)); + /*! \todo Remove this memset()? */ + memset(&path->shape, 0, sizeof(shape_t)); + path->shape.sh_type = SHT_PATH; + path->cmd_len = strlen(commands); + path->arg_len = arg_cnt; + path->fix_arg_len = fix_arg_cnt; + msz = cmd_cnt + sizeof(co_aix) * arg_cnt + sizeof(int) * fix_arg_cnt; + path->user_data = (char *)malloc(msz * 2); + if(path->user_data == NULL) { + free(path); + return NULL; + } + + path->dev_data = path->user_data + msz; + memcpy(path->user_data,commands,cmd_cnt); + memcpy(path->user_data+cmd_cnt,arg, sizeof(co_aix)*arg_cnt); + memcpy(path->user_data+cmd_cnt+arg_cnt*sizeof(co_aix),fix_arg, sizeof(int)*fix_arg_cnt); + memcpy(path->dev_data, path->user_data, msz); + + path->shape.free = sh_path_free; + +#ifndef UNITTEST + rdman_shape_man(rdman, (shape_t *)path); +#endif + + return (shape_t *)path; +} + + /*! \brief Transform a path from user space to device space. * */