TeX/include/TeX/TeX.h

105 lines
4.3 KiB
C

//---
// TeX: Natural rendering for mathematical formulae
//---
#ifndef TEX_TEX
#define TEX_TEX
#include <TeX/config.h>
#include <stddef.h>
//---
// Module interface
// This TeX module does not have its own primitive rendering methods;
// instead it relies on a few user-provided functions.
// This gives a certain amount on freedom on rendering. For instance, you
// can render a formula in a scrollable sub-rectangle of the screen by
// having pixel() and text() translate coordinates and check bounds.
//---
/* Opaque declaration: see <TeX/env.h> for the details */
struct TeX_Env;
/* TeX_intf_pixel(): Set a single pixel
This function configures the pixel-rendering procedure used by the module.
The argument should expect three parameters:
@x Horizontal position of the pixel (left --> right)
@y Vertical position of the pixel (top --> bottom)
@color Requested color */
void TeX_intf_pixel(void (*draw_pixel)(int x, int y, int color));
/* TeX_intf_line(): Draw a line
This function sets the line drawing procedure of the module. The argument
should take give parameters:
@x1 @y1 Location of the first endpoint of the line
@x2 @y2 Location of the second endpoint of the line
@color Requested color */
void TeX_intf_line(void (*draw_line)(int x1, int y1, int x2, int y2,
int color));
/* TeX_intf_size(): Get the dimensions of a string
This function configures the procedure used by the module to compute the
size of a string node. The argument should expect three parameters:
@str String whose dimensions are requested
@width Pointer to width value (must be updated by function)
@height Pointer to height value (must be updated by function) */
void TeX_intf_size(void (*text_size)(char const *str, int *width,int *height));
/* TeX_intf_text(): Draw variable-width text
This function configures the text-rendering procedure used by the module.
Four arguments will be passed:
@x x coordinate of the left-side of the bounding box (included)
@y y coordinate of the top-size of the bounding box (included)
@str String to render
@color Requested color for the rendered pixels
The rendering function must honor the size estimates provided by the
procedure assigned to TeX_intf_size() and never draw pixel outside the
announced bounding box. */
void TeX_intf_text(void (*draw_text)(char const *str, int x, int y,int color));
//---
// Parsing
// The following functions create recursive TeX_Flow objects that
// represent the structure of the formulae. Once parsed, TeX_Node objects
// are rendered very quickly.
//---
/* TeX_parse(): Parse a TeX formula
@formula TeX formula to parse
@display Use full-size display mode instead of inline mode (as in LaTeX)
Returns a dynamically-allocated TeX_Env object that can be used in further
calls to TeX_draw() and must be freed by a call to TeX_free(). */
struct TeX_Env *TeX_parse(char const *formula, int display);
/* TeX_free(): Free an allocated TeX formula
Freed formulas become dangling and must not be used in any further call.
@formula Formula to free, assumed allocated by TeX_parse() */
void TeX_free(struct TeX_Env *formula);
//---
// Rendering
// These functions are used to draw formulae on the screen. As doing
// parsing several times is inefficient, it is advised to use TeX_draw()
// as much as possible by reusing the same TeX_Flow object.
//---
/* TeX_draw(): Render a parsed formula
@formula Formula to render
@x x coordinate of the left-side of the bounding box (included)
@y y coordinate of the top-size of the bounding box (included)
@color Requested color for the rendered pixels */
void TeX_draw(struct TeX_Env *formula, int x, int y, int color);
/* TeX_interpret(): Parse and render, in sequence
This function parses the provided formula, renders it and then frees it.
Only use it if you're going to render the formula only once or if you're
very short on memory.
@formula Formula to render (textual form)
@display Use display mode instead of inline mode (as in LaTeX)
@x x coordinate of the left-side of the bounding box (included)
@y y coordinate of the top-size of the bounding box (included)
@color Requested color for the rendered pixels */
void TeX_interpret(char const *formula, int display, int x, int y, int color);
#endif /* TEX_TEX */