2019-05-29 04:11:05 +02:00
|
|
|
//---
|
|
|
|
// TeX: Natural rendering for mathematical formulae
|
|
|
|
//---
|
|
|
|
|
|
|
|
#ifndef TEX_H
|
|
|
|
#define TEX_H
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
//---
|
|
|
|
// Graphical settings
|
|
|
|
// A few quirks that can be adjusted to your needs.
|
|
|
|
//---
|
|
|
|
|
|
|
|
/* Thickness and horizontal margin of fraction bars */
|
|
|
|
#define TEX_FRACTION_BAR_THICKNESS 1
|
|
|
|
#define TEX_FRACTION_BAR_MARGIN 1
|
|
|
|
|
|
|
|
/* Vertical placement of subscripts and superscripts (relative to object) */
|
|
|
|
#define TEX_SUBSCRIPT_ELEVATION 3
|
|
|
|
#define TEX_SUPERSCRIPT_DEPTH 3
|
|
|
|
|
|
|
|
/* Align the center of the resizable brackets with the baseline */
|
|
|
|
#define TEX_LEFTRIGHT_ALIGNED 0
|
|
|
|
/* Make them extend symmetrically around baseline */
|
|
|
|
#define TEX_LEFTRIGHT_SYMMETRICAL 0
|
2019-05-29 21:58:46 +02:00
|
|
|
/* Width of resizable "<" and ">" delimiters */
|
|
|
|
#define TEX_LEFTRIGHT_ANGLE_WIDTH 4
|
2019-05-29 04:11:05 +02:00
|
|
|
|
|
|
|
/* Spacing: between layout elements, letters, and width of space character */
|
|
|
|
#define TEX_LAYOUT_SPACING 1
|
|
|
|
#define TEX_LETTER_SPACING 1
|
|
|
|
#define TEX_WORD_SPACING 6
|
|
|
|
|
|
|
|
/* Whether to place bounds above and below integrals (display mode) */
|
|
|
|
#define TEX_INT_DISPLAY 0
|
|
|
|
|
|
|
|
/* Make the vertical part of the square root symbol slanted at low heights */
|
|
|
|
#define TEX_SQRT_SLANTED 1
|
|
|
|
/* Length of the top-right bar of square roots (0 to disable) */
|
|
|
|
#define TEX_SQRT_BAR_LENGTH 0
|
|
|
|
|
|
|
|
//---
|
|
|
|
// Implementation settings
|
|
|
|
//---
|
|
|
|
|
|
|
|
/* Size of the lexer buffer; must be large enough to hold all command names.
|
|
|
|
Longer than the longest literal string is a waste of space */
|
|
|
|
#define TEX_LEXER_BUFSIZE 64
|
|
|
|
|
|
|
|
/* Maximum number of nested left/right pairs */
|
|
|
|
#define TEX_LEFTRIGHT_NESTING 16
|
|
|
|
|
|
|
|
/* Enable or disable debugging functions with TEX_DEBUG. Currently this is
|
|
|
|
enabled (and used) by all computer targets and disabled on calculator. */
|
|
|
|
#if defined(TEX_PLATFORM_FX9860G) || defined(TEX_PLATFORM_FXCG50)
|
|
|
|
#undef TEX_DEBUG
|
|
|
|
#elif !defined(TEX_DEBUG)
|
|
|
|
#define TEX_DEBUG
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//---
|
|
|
|
// 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/structure.h> for the details */
|
|
|
|
struct TeX_Flow;
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
Returns a dynamically-allocated TeX_Flow object that can be used in further
|
|
|
|
calls to TeX_draw() and must be freed by a call to TeX_free(). */
|
|
|
|
struct TeX_Flow *TeX_parse(char const *formula);
|
|
|
|
|
|
|
|
/* 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_Flow *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_Flow *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)
|
|
|
|
@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 x, int y, int color);
|
|
|
|
|
|
|
|
#endif /* TEX_H */
|