#include #include #include #include #include #include #include #include //--- // Interface functions //--- /* Rendering-related interface functions */ void (*TeX_pixel)(int x, int y, int color) = NULL; void (*TeX_line)(int x1, int y1, int x2, int y2, int color) = NULL; void (*TeX_size)(char const *str, int *width, int *height) = NULL; void (*TeX_text)(char const *str, int x, int y, int color) = NULL; /* TeX_intf_pixel(): Set a single pixel */ void TeX_intf_pixel(void (*draw_pixel)(int x, int y, int color)) { TeX_pixel = draw_pixel; } /* TeX_intf_line(): Draw a line */ void TeX_intf_line(void (*draw_line)(int x1, int y1, int x2, int y2, int color)) { TeX_line = draw_line; } /* TeX_intf_size(): Get the dimensions of a string */ void TeX_intf_size(void (*text_size)(char const *str, int *width,int *height)) { TeX_size = text_size; } /* TeX_intf_text(): Draw variable-width text */ void TeX_intf_text(void (*draw_text)(char const *str, int x, int y,int color)) { TeX_text = draw_text; } //--- // Object management //--- /* TeX_free(): Free an allocated TeX formula */ void TeX_free(struct TeX_Env *env) { if(env) env->free(env); } //--- // Module functions //--- /* TeX_parse(): Parse a TeX formula */ struct TeX_Env *TeX_parse(char const *formula) { /* Provided by the parser. */ struct TeX_Env *parse(char const *str); struct TeX_Env *env = parse(formula); if(!env) return NULL; env->layout(env); return env; } /* TeX_draw(): Render a parsed formula */ void TeX_draw(struct TeX_Env *formula, int x, int y, int color) { formula->render(formula, x, y, color); } /* TeX_interpret(): Parse and render, in sequence */ void TeX_interpret(char const *formula, int x, int y, int color) { struct TeX_Env *env = TeX_parse(formula); if(!env) return; TeX_draw(env, x, y, color); TeX_free(env); }