TeX/include/TeX/node.h

103 lines
3.0 KiB
C
Raw Permalink Normal View History

2019-06-12 18:53:50 +02:00
//---
// node: Mathematical constructs in the formula tree
//---
#ifndef TEX_NODE
#define TEX_NODE
#include <TeX/config.h>
#include <TeX/defs.h>
#include <stddef.h>
#include <stdint.h>
2019-06-18 03:27:04 +02:00
/* A special class number for nodes that contain plain text. */
2019-06-12 18:53:50 +02:00
#define TEX_NODECLASS_TEXT 0
2019-06-18 03:27:04 +02:00
/* Special class for environment nodes, also a special case */
#define TEX_NODECLASS_ENV 1
2019-06-12 18:53:50 +02:00
struct TeX_Flow;
2019-06-18 03:27:04 +02:00
struct TeX_Env;
2019-06-12 18:53:50 +02:00
/* TeX_Node
This object represents a mathematical construct. It can be plain text, a
fraction, a square root or a matrix. It has specific layout and rendering
that are supplied by its class. */
struct TeX_Node
{
/* Pointer to next element in the flow */
struct TeX_Node *next;
union {
/* Plain text content encoded as UTF-8 */
uint8_t *text;
2019-06-18 03:27:04 +02:00
/* Environment pointer */
struct TeX_Env *env;
2019-06-12 18:53:50 +02:00
/* Functional arguments */
struct TeX_Flow *args[TEX_NODE_MAX_CHILDREN];
};
/* Node is invalid or hidden */
uint hidden :1;
/* Node class identifier */
uint type :7;
/* Class variant or fixed argument */
uint subtype :8;
/* Size and placement */
uint16_t width;
uint16_t height;
uint16_t line;
/* Location within the flow, as x and baseline displacement */
uint16_t x;
int16_t l;
2019-06-19 17:52:09 +02:00
};
2019-06-12 18:53:50 +02:00
//---
// Node creation and destruction functions
//---
/* TeX_node_text(): Make a text node */
struct TeX_Node *TeX_node_text(char const *utf8);
/* TeX_node_command(): Make a command node without arguments
Returns NULL if no such command is defined. */
struct TeX_Node *TeX_node_command(char const *command);
/* TeX_node_add_arg(): Add an argument to a command node
If [node] is a command node and has at least on free argument slot, then
adds [arg] to it. Otherwise, destroys [arg].
Always returns [flow] (useful for nested calls). */
struct TeX_Node *TeX_node_add_arg(struct TeX_Node *node, struct TeX_Flow *arg);
/* TeX_node_absorb(): Absorb text into a command node
This special function is for command nodes that use the absorption syntax,
eg. "\left(" where the argument consists of a single character and is not
surrounded by braces. The first character of [text] (which should be only
one character if it comes from the parser) is saved as argument. [text] is
not freed. Always returns [node]. */
struct TeX_Node *TeX_node_absorb(struct TeX_Node *node, char const *text);
2019-06-18 03:27:04 +02:00
/* TeX_node_env(): Make a environment node
This function creates an node that wraps an environment and inserts it into
a formula. */
struct TeX_Node *TeX_node_env(struct TeX_Env *env);
2019-06-12 18:53:50 +02:00
/* TeX_node_free(): Free a TeX_Node and all its children */
void TeX_node_free(struct TeX_Node *node);
//---
// Layout and rendering
//---
/* TeX_node_layout(): Compute the layout of a node
This functions computes the layout of a node and its children, and stores
the results in the node's metadata. */
2019-06-19 17:52:09 +02:00
void TeX_node_layout(struct TeX_Node *node, int display);
2019-06-12 18:53:50 +02:00
/* TeX_node_render(): Render a node and its children
The node's layout must have been computed first. */
void TeX_node_render(struct TeX_Node const * node, int x, int y, int color);
#endif /* TEX_NODE */