parent
9b14ec8755
commit
9be3414e96
@ -1,4 +1,4 @@
|
||||
# Simple command-line parsing and layout troubleshooter
|
||||
TARGET = TeX-cli
|
||||
CFLAGS = -D TEX_PLATFORM_CLI -D TEX_DEBUG -g
|
||||
CFLAGS = -D TEX_PLATFORM_CLI -D TEX_PRINT -g
|
||||
CC = gcc
|
||||
|
@ -1,6 +1,6 @@
|
||||
# SDL2 layout and rendering (not interactive)
|
||||
SRC = main-SDL.c
|
||||
TARGET = TeX-SDL
|
||||
CFLAGS = -D TEX_PLATFORM_SDL -D TEX_DEBUG -g
|
||||
CFLAGS = -D TEX_PLATFORM_SDL -D TEX_PRINT -g
|
||||
LDFLAGS = -lSDL2
|
||||
CC = gcc
|
||||
|
@ -0,0 +1,61 @@
|
||||
//---
|
||||
// class: Node classes
|
||||
//---
|
||||
|
||||
#include <TeX/node.h>
|
||||
|
||||
/* TeX_Class
|
||||
Essentially the prototype of a node class, which implements the layout and
|
||||
rendering function of a fixed mathematical construct. */
|
||||
struct TeX_Class
|
||||
{
|
||||
/* Most of the time this name appears in the formula using the "\name"
|
||||
notation, but some classes (superscript, parentheses, matrices...)
|
||||
have special syntax and their names are hardcoded. To avoid
|
||||
conflicts, built-in class names start with a backslash. */
|
||||
char const *name;
|
||||
|
||||
/* layout()
|
||||
This function must calculate the width, height and base line of the
|
||||
node and store the results in the structure fields. It is allowed to
|
||||
access the .width, .height and .line fields of its children because
|
||||
they will have had their size calculated beforehand.
|
||||
|
||||
This TeX module provides classes with a primitive function that
|
||||
calculates the size of raw strings:
|
||||
#include <TeX/interface.h>
|
||||
void TeX_size(char const *str, int *width, int *height);
|
||||
|
||||
@node A node of the described class, for size calculation */
|
||||
void (*layout)(struct TeX_Node *node);
|
||||
|
||||
/* render()
|
||||
This function must render the given node at the provided (x, y)
|
||||
coordinates. The (x, y) point is the top-left corner of the bounding
|
||||
box of the expression and is inside the box (ie. it can be drawn
|
||||
to). This function must honor the size estimates provided by
|
||||
calculate_size() and not draw outside the bounding box.
|
||||
|
||||
This TeX module provides three primitive functions for rendering:
|
||||
#include <TeX/interface.h>
|
||||
void TeX_pixel(int x, int y, int color);
|
||||
void TeX_line(int x1, int y1, int x2, int y2, int color);
|
||||
void TeX_text(char const *str, int x, int y, int color);
|
||||
|
||||
@node A node of the described class, for rendering
|
||||
@x Horizontal coordinate of the requested rendering position
|
||||
@y Vertical coordinate of the requested rendering position
|
||||
@color Requested rendering color */
|
||||
void (*render)(struct TeX_Node const * node, int x, int y, int color);
|
||||
};
|
||||
|
||||
/* TeX_class_find(): Find a class using a command name
|
||||
@name Command name
|
||||
Returns a positive class id representing the requested TeX_Class object (if
|
||||
a class with this name is found in the table, a negative number otherwise.
|
||||
This function never returns 0, which is reserved for TEX_NODECLASS_TEXT. */
|
||||
int TeX_class_find(char const *name);
|
||||
|
||||
/* TeX_class_of(): Get the class pointer of a node */
|
||||
struct TeX_Class const *TeX_class_of(struct TeX_Node const * node);
|
||||
|
@ -0,0 +1,76 @@
|
||||
//---
|
||||
// config: Implementation and graphical settings of the library
|
||||
//---
|
||||
|
||||
#ifndef TEX_CONFIG
|
||||
#define TEX_CONFIG
|
||||
|
||||
//---
|
||||
// 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_DEPTH 16
|
||||
|
||||
/* Maximum number of nested environments */
|
||||
#define TEX_ENV_DEPTH 16
|
||||
|
||||
/* Maximum number of command arguments allowed by the library (each node has
|
||||
exactly this number of children; memory usage is better if this is small) */
|
||||
#define TEX_NODE_MAX_CHILDREN 2
|
||||
|
||||
/* Enable or disable printing functions with TEX_PRINT. 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_PRINT
|
||||
#elif !defined(TEX_PRINT)
|
||||
#define TEX_PRINT
|
||||
#endif
|
||||
|
||||
//---
|
||||
// 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
|
||||
/* Width of resizable "<" and ">" delimiters */
|
||||
#define TEX_LEFTRIGHT_ANGLE_WIDTH 4
|
||||
|
||||
/* 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
|
||||
/* Height of the integral symbol */
|
||||
#define TEX_INT_HEIGHT 21
|
||||
|
||||
/* Length of arrow extensions from the tip of a vector */
|
||||
#define TEX_VEC_ARROW_LENGTH 2
|
||||
/* Horizontal margin around vector */
|
||||
#define TEX_VEC_MARGIN 0
|
||||
/* Extra height between argument and vector */
|
||||
#define TEX_VEC_SPACING TEX_LAYOUT_SPACING
|
||||
|
||||
/* 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
|
||||
|
||||
#endif /* TEX_CONFIG */
|
@ -0,0 +1,58 @@
|
||||
//---
|
||||
// env: Environments
|
||||
//---
|
||||
|
||||
#ifndef TEX_ENV
|
||||
#define TEX_ENV
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
struct TeX_Node;
|
||||
|
||||
/* Simple type definition trick to use struct TeX_Env inside prototypes within
|
||||
the struct definition itself */
|
||||
typedef struct TeX_Env TeX_Env;
|
||||
|
||||
struct TeX_Env
|
||||
{
|
||||
/* Environment name */
|
||||
char const * name;
|
||||
|
||||
/* free(): Free an environment instance */
|
||||
void (*free)(TeX_Env *env);
|
||||
|
||||
/* add_node(): Add a node to an environment */
|
||||
void (*add_node)(TeX_Env *env, struct TeX_Node *node);
|
||||
|
||||
/* add_separator(): Add a separator ("&") */
|
||||
void (*add_separator)(TeX_Env *env);
|
||||
|
||||
/* add_break(): Add a break ("\\") */
|
||||
void (*add_break)(TeX_Env *env);
|
||||
|
||||
/* size(): Compute environment size */
|
||||
void (*size)(TeX_Env *env);
|
||||
|
||||
/* render(): Render environment */
|
||||
void (*render)(TeX_Env *env, int x, int y, int color);
|
||||
|
||||
/* Dimensions */
|
||||
uint16_t width;
|
||||
uint16_t height;
|
||||
uint16_t line;
|
||||
|
||||
/* More data, each TeX_Env_* subtype will decide */
|
||||
};
|
||||
|
||||
//---
|
||||
// Environment construction functions
|
||||
//---
|
||||
|
||||
/* TeX_env_primary(): make a primary, single-flow environment
|
||||
This is the environment type of whole formulas. It consists of a single
|
||||
flow and ignores separators and breaks.
|
||||
Creates and returns a new environment [env] which must be freed by a call
|
||||
to [env->free(env)]. */
|
||||
struct TeX_Env *TeX_env_primary(void);
|
||||
|
||||
#endif /* TEX_ENV */
|
@ -0,0 +1,57 @@
|
||||
//---
|
||||
// flow: Horizontal flows of nodes arranged from left to right
|
||||
//---
|
||||
|
||||
#ifndef TEX_FLOW
|
||||
#define TEX_FLOW
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
struct TeX_Node;
|
||||
|
||||
/* TeX_Flow
|
||||
This object represents a horizontal line of nodes following the flow of the
|
||||
text; each node can be a plain string or a functional node. All share the
|
||||
same base line when rendered. */
|
||||
struct TeX_Flow
|
||||
{
|
||||
/* Pointer to first and last elements of the line */
|
||||
struct TeX_Node *first;
|
||||
struct TeX_Node *last;
|
||||
|
||||
uint16_t width;
|
||||
uint16_t height;
|
||||
uint16_t line;
|
||||
|
||||
} __attribute__((packed, aligned(sizeof (void *))));
|
||||
|
||||
//---
|
||||
// Flow construction and destruction functions
|
||||
//---
|
||||
|
||||
/* TeX_flow_add_node(): Add a new node to a flow
|
||||
The provided node is added at the right of the flow. If [flow] is NULL,
|
||||
creates and returns a new flow. Otherwise, always returns [flow]. */
|
||||
struct TeX_Flow *TeX_flow_add_node(struct TeX_Flow *flow,
|
||||
struct TeX_Node *node);
|
||||
|
||||
/* TeX_flow_free(): Free TeX_Flow objects
|
||||
Destroys a flow and all of its contained elements. */
|
||||
void TeX_flow_free(struct TeX_Flow *flow);
|
||||
|
||||
//---
|
||||
// Layout and rendering
|
||||
//---
|
||||
|
||||
/* TeX_flow_layout(): Calculate the layout of a flow
|
||||
This function calculates the size taken by nodes sharing the same baseline.
|
||||
It heeds for special size and alignment exceptions such as parenthesis-type
|
||||
characters and subscripts/superscripts. Modifies the flow's metadata. */
|
||||
void TeX_flow_layout(struct TeX_Flow *flow);
|
||||
|
||||
/* TeX_flow_render(): Render a flow and all its components
|
||||
This function renders all horizontal objects in a flow. The layout of the
|
||||
flow must have been computed. */
|
||||
void TeX_flow_render(struct TeX_Flow const * flow, int x, int y, int color);
|
||||
|
||||
#endif /* TEX_FLOW */
|
@ -0,0 +1,14 @@
|
||||
//---
|
||||
// interface: Interface functions
|
||||
//---
|
||||
|
||||
#ifndef TEX_INTF
|
||||
#define TEX_INTF
|
||||
|
||||
/* Rendering-related interface functions */
|
||||
extern void (*TeX_pixel)(int x, int y, int color);
|
||||
extern void (*TeX_line)(int x1, int y1, int x2, int y2, int color);
|
||||
extern void (*TeX_size)(char const * str, int *width, int *height);
|
||||
extern void (*TeX_text)(char const * str, int x, int y, int color);
|
||||
|
||||
#endif /* TEX_INTF */
|
@ -0,0 +1,94 @@
|
||||
//---
|
||||
// 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>
|
||||
|
||||
/* A special class number for nodes that contain plain text. Class numbers from
|
||||
1 onwards are used by TeX_Class. See also the class array in nodes.c. */
|
||||
#define TEX_NODECLASS_TEXT 0
|
||||
|
||||
struct TeX_Flow;
|
||||
|
||||
/* 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;
|
||||
/* 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;
|
||||
|
||||
} __attribute__((packed, aligned(sizeof (void *))));
|
||||
|
||||
//---
|
||||
// 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);
|
||||
|
||||
/* 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. */
|
||||
void TeX_node_layout(struct TeX_Node *node);
|
||||
|
||||
/* 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 */
|
@ -1,44 +0,0 @@
|
||||
//---
|
||||
// parser: interface to the TeX parser
|
||||
//---
|
||||
|
||||
#ifndef TEX_PARSER
|
||||
#define TEX_PARSER
|
||||
|
||||
#include <TeX/TeX.h>
|
||||
#include <TeX/structure.h>
|
||||
|
||||
/* parse_start(): Configure parser to run on a string
|
||||
@str Input data, must be NULL-terminated */
|
||||
void parse_start(const char *str);
|
||||
|
||||
/* parse(): Parse into a TeX flow
|
||||
Uses input data set by parse_start(). Returns a flow object on success (free
|
||||
with TeX_free()), NULL on error (generally syntax issues).
|
||||
TODO: Fine-grained error detection? */
|
||||
struct TeX_Flow *parse(void);
|
||||
|
||||
#ifdef TEX_DEBUG
|
||||
|
||||
/* TeX_debug_lex(): Display the result of lexing
|
||||
Makes a lexical analysis of the given formula and prints the stream of
|
||||
tokens to standard output. */
|
||||
void TeX_debug_lex(const char *formula);
|
||||
|
||||
/* TeX_debug_node(): Recursively display the structure of a node
|
||||
Displays the nature and dimensions of the given node and its children,
|
||||
making recursive calls to TeX_debug_flow().
|
||||
@node Displayed node
|
||||
@indent Indent level, in spaces (goes up by groups of 4) */
|
||||
void TeX_debug_node(struct TeX_Node *node, int indent);
|
||||
|
||||
/* TeX_debug_flow(): Recursively display the structure of a flow
|
||||
Displays the dimensions of the given flow and its contents, making recursive
|
||||
calls to TeX_debug_node().
|
||||
@flow Displayed flow
|
||||
@indent Indent level, in spaces (goes up by groups of 4) */
|
||||
void TeX_debug_flow(struct TeX_Flow *flow, int indent);
|
||||
|
||||
#endif /* TEX_DEBUG */
|
||||
|
||||
#endif /* TEX_PARSER */
|
@ -0,0 +1,29 @@
|
||||
//---
|
||||
// print: Command-line structure printing
|
||||
//---
|
||||
|
||||
#ifdef TEX_PRINT
|
||||
|
||||
#include <TeX/node.h>
|
||||
#include <TeX/flow.h>
|
||||
#include <TeX/env.h>
|
||||
|
||||
#define GRAY "\e[30;1m"
|
||||
#define END "\e[0m"
|
||||
|
||||
/* TeX_print_node(): Print a node's tree */
|
||||
void TeX_print_node(struct TeX_Node *node, int indent);
|
||||
|
||||
/* TeX_print_flow(): Print a flow's tree */
|
||||
void TeX_print_flow(struct TeX_Flow *flow, int indent);
|
||||
|
||||
/* TeX_print_env(): Recursively print an environment */
|
||||
void TeX_print_env(struct TeX_Env *env, int indent);
|
||||
|
||||
/* TeX_print_env_primary(): Print a primary environment to stdout */
|
||||
void TeX_print_env_primary(struct TeX_Env *env, int indent);
|
||||
|
||||
/* TeX_print_lex(): Print the result of lexing */
|
||||
void TeX_print_lex(char const *formula);
|
||||
|
||||
#endif /* TEX_PRINT */
|
@ -1,23 +0,0 @@
|
||||
//---
|
||||
// render: Rendering functions
|
||||
//---
|
||||
|
||||
#ifndef TEX_RENDER
|
||||
#define TEX_RENDER
|
||||
|
||||
/* Rendering-related interface functions */
|
||||
extern void (*TeX_pixel)(int x, int y, int color);
|
||||
extern void (*TeX_line)(int x1, int y1, int x2, int y2, int color);
|
||||
extern void (*TeX_size)(char const * str, int *width, int *height);
|
||||
extern void (*TeX_text)(char const * str, int x, int y, int color);
|
||||
|
||||
/* render_node() - Recursively render a node
|
||||
This function all nodes types (including text). The node's size must have
|
||||
been computed first. */
|
||||
void render_node(struct TeX_Node const * node, int x, int y, int color);
|
||||
|
||||
/* render_flow() - Render a flow and all its components
|
||||
This function arranges and renders all horizontal objects in a flow. */
|
||||
void render_flow(struct TeX_Flow const * flow, int x, int y, int color);
|
||||
|
||||
#endif /* TEX_RENDER */
|
@ -1,153 +0,0 @@
|
||||
//---
|
||||
// structure: Recursive node/flow data structure
|
||||
//---
|
||||
|
||||
#ifndef TEX_STRUCTURE
|
||||
#define TEX_STRUCTURE
|
||||
|
||||
#include <TeX/defs.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/* Maximum number of command arguments allowed by the library (each node has
|
||||
exactly this number of children; memory usage is better if this is small) */
|
||||
#define TEX_MAX_CHILDREN 2
|
||||
|
||||
/* A special class number for nodes that contain plain text. Class numbers from
|
||||
1 onwards are used by TeX_Class. See also the class array in nodes.c. */
|
||||
#define TEX_NODECLASS_TEXT 0
|
||||
|
||||
//---
|
||||
// Data structures
|
||||
// The structure mixes linked lists (text flow along a line, TeX_Flow) and
|
||||
// trees (arguments to commands, TeX_Node) in a mutually-recursive way.
|
||||
//---
|
||||
|
||||
/* TeX_Flow
|
||||
This object represents a horizontal line of nodes following the flow of the
|
||||
text; each node can be a plain string or a functional node. All share the
|
||||
same base line when rendered. */
|
||||
struct TeX_Flow
|
||||
{
|
||||
/* Pointer to first and last elements of the line */
|
||||
struct TeX_Node *first;
|
||||
struct TeX_Node *last;
|
||||
|
||||
uint16_t width;
|
||||
uint16_t height;
|
||||
uint16_t line;
|
||||
|
||||
} __attribute__((packed, aligned(sizeof (void *))));
|
||||
|
||||
/* TeX_Node
|
||||
Here's the main deal. TeX_Flow objects handle the flow and TeX_Node objects
|
||||
handle the content and its structure. */
|
||||
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;
|
||||
/* Functional arguments */
|
||||
struct TeX_Flow *args[TEX_MAX_CHILDREN];
|
||||
};
|
||||
|
||||
/* Invalid or hidden node */
|
||||
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 withing flow, as x and baseline displacement */
|
||||
uint16_t x;
|
||||
int16_t l;
|
||||
|
||||
} __attribute__((packed, aligned(sizeof (void *))));
|
||||
|
||||
//---
|
||||
// Class nodes
|
||||
// These are the nodes that have arguments, and specific size-calculation
|
||||
// and rendering methods. Most interesting nodes (fractions, sums,
|
||||
// matrices...) fall into this category.
|
||||
//---
|
||||
|
||||
/* TeX_Class
|
||||
A class of nodes (ie. "\name{arg}{arg}..."): function name, size-calculation
|
||||
method, rendering method. */
|
||||
struct TeX_Class
|
||||
{
|
||||
/* Most of the time this name appears in the formula using the "\name"
|
||||
notation, but some classes (superscript, parentheses, matrices...)
|
||||
have special syntax and their names are hardcoded. To avoid
|
||||
conflicts, built-in class names start with a backslash. */
|
||||
const char *name;
|
||||
|
||||
/* size()
|
||||
This function must calculate the width, height and base line of the
|
||||
node and store the results in the structure fields. It is allowed to
|
||||
access the .width, .height and .line fields of its children because
|
||||
they will have had their size calculated beforehand.
|
||||
|
||||
This TeX module provides classes with a primitive function that
|
||||
calculates the size of raw strings:
|
||||
void text_size(const char *str, int *width, int *height);
|
||||
|
||||
@node A node of the described class, for size calculation */
|
||||
void (*size)(struct TeX_Node *node);
|
||||
|
||||
/* render()
|
||||
This function must render the given node at the provided (x, y)
|
||||
coordinates. The (x, y) point is the top-left corner of the bounding
|
||||
box of the expression and is inside the box (ie. it can be drawn
|
||||
to). This function must honor the size estimates provided by
|
||||
calculate_size() and not draw outside the bounding box.
|
||||
|
||||
This TeX module provides two primitive functions for rendering:
|
||||
void pixel(int x, int y, int color);
|
||||
void text(const char *str, int x, int y, int color);
|
||||
|
||||
@node A node of the described class, for rendering
|
||||
@x Horizontal coordinate of the requested rendering position
|
||||
@y Vertical coordinate of the requested rendering position
|
||||
@color Requested rendering color */
|
||||
void (*render)(struct TeX_Node const * node, int x, int y, int color);
|
||||
};
|
||||
|
||||
/* class_find() - Find a class using a command name
|
||||
@name Command name
|
||||
Returns a positive class id representing the requested TeX_Class object (if
|
||||
a class with this name is found in the table, a negative number otherwise.
|
||||
This function never returns 0, which is reserved for TEX_NODECLASS_TEXT. */
|
||||
int class_find(const char *name);
|
||||
|
||||
/* Class table. This is an array that can be indexed by class_id - 1 where
|
||||
class_id is an id returned by class_find(). It is terminated by a class
|
||||
with a NULL command name. Be careful because the first element in this array
|
||||
has class id 1. */
|
||||
extern struct TeX_Class TeX_table[];
|
||||
|
||||
//---
|
||||
// Recursive size computation
|
||||
//---
|
||||
|
||||
/* size_node() - Calculate the size of node
|
||||
This function handles all node classes (including text) and computes the
|
||||
size of the children in advance, as required by the class' calculate_size()
|
||||
method. Modifies the node structure. */
|
||||
void size_node(struct TeX_Node *node);
|
||||
|
||||
/* size_flow() - Calculate the size of a flow
|
||||
This function calculates the size taken by nodes sharing the same baseline.
|
||||
It heeds for special size and alignment exceptions such as parenthesis-type
|
||||
characters and subscripts/superscripts. Modifies the flow structure. */
|
||||
void size_flow(struct TeX_Flow *flow);
|
||||
|
||||
#endif /* TEX_STRUCTURE */
|
@ -0,0 +1,36 @@
|
||||
//---
|
||||
// vector: Simple vectors that only grow
|
||||
//---
|
||||
|
||||
#ifndef TEX_VECTOR
|
||||
#define TEX_VECTOR
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int len;
|
||||
int size;
|
||||
int elsize;
|
||||
|
||||
/* This pointer can be cast to the vector type and indexed */
|
||||
void *data;
|
||||
} vector_t;
|
||||
|
||||
/* vector_make(): Make a new vector of a given type
|
||||
@vector Pointer to preallocated vector structure
|
||||
@type Data type */
|
||||
void vector_make(vector_t *vector, size_t elsize);
|
||||
|
||||
#define vector_make(v, T) vector_make(v, sizeof(T))
|
||||
|
||||
/* vector_append(): Append a new element to a vector
|
||||
@vector Pointer to initialized vector
|
||||
@element Pointer to new element, which will be *copied* */
|
||||
void vector_append(vector_t *v, void *element);
|
||||
|
||||
/* vector_free(): Free a vector's contents */
|
||||
void vector_free(vector_t *v);
|
||||
|
||||
#endif /* TEX_VECTOR */
|