diff --git a/README.md b/README.md index 42a043d..a689af3 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,7 @@ List of currently supported elements: Features that are partially implemented (and what is left to finish them): -* Support for inline style and display style (compute display-style subscript - and superscript layout, and expose a parameter) +* Support for inline style and display style (expose a parameter) * API functions to build TeX objects without a TeX formula (expose functions which are currently in the parser) * Full fx-CG 50 support (suitable parenthesis styles) diff --git a/TODO.md b/TODO.md index 3b7c9a6..b661a82 100644 --- a/TODO.md +++ b/TODO.md @@ -5,9 +5,7 @@ * Support character-level spacing * Be more generic in what nodes have display mode by default -* Add products * Add square roots, and honor TEX_SQRT_SLANTED and TEX_SQRT_BAR_LENGTH * Add vectors * Add limits -* Add integrals, and honor TEX_INT_DISPLAY * Add matrices diff --git a/font5x7.bmp b/font5x7.bmp index 40e6f0d..4786375 100644 Binary files a/font5x7.bmp and b/font5x7.bmp differ diff --git a/font8x9.bmp b/font8x9.bmp new file mode 100644 index 0000000..9805dd6 Binary files /dev/null and b/font8x9.bmp differ diff --git a/src/classes.c b/src/classes.c index 6c2a05e..cec4ab4 100644 --- a/src/classes.c +++ b/src/classes.c @@ -241,7 +241,7 @@ void supsubscript_render(struct TeX_Node const * node, int x, int y, } //--- -// Summation symbols. +// Summation symbol. // * args: 0 (ignored) // * flow: default // @@ -268,6 +268,55 @@ void sum_render(__attribute__((unused)) struct TeX_Node const * node, int x, TeX_pixel(x + 8, y + 7, color); } +//--- +// Product symbol. +// * args: 0 (ignored) +// * flow: default +// +// Just like summation symbols, uses display mode by default. +//--- + +void prod_size(struct TeX_Node *node) +{ + node->width = 9; + node->height = 9; + node->line = 4; +} + +void prod_render(__attribute__((unused)) struct TeX_Node const * node, int x, + int y, int color) +{ + TeX_line(x, y, x + 8, y, color); + TeX_line(x + 1, y, x + 1, y + 8, color); + TeX_line(x + 0, y + 8, x + 2, y + 8, color); + TeX_line(x + 7, y, x + 7, y + 8, color); + TeX_line(x + 6, y + 8, x + 8, y + 8, color); +} + +//--- +// Integral symbol +// * args: 0 (ignored) +// * flow: default +//--- + +void int_size(struct TeX_Node *node) +{ + node->width = 5; + node->height = 19; + node->line = 9; +} + +void int_render(struct TeX_Node const * node, int x, int y, int color) +{ + int h = node->height; + + TeX_pixel(x + 3, y, color); + TeX_pixel(x + 4, y + 1, color); + TeX_line(x + 2, y + 1, x + 2, y + h - 2, color); + TeX_pixel(x, y + h - 2, color); + TeX_pixel(x + 1, y + h - 1, color); +} + //--- // The class table and lookup functions //--- @@ -276,19 +325,25 @@ struct TeX_Class TeX_table[] = { /* Text is omitted from the table and has ID 0 */ /* Fractions */ - { "frac", frac_size, frac_render }, + { "frac", frac_size, frac_render }, + /* Size-aware opening and closing elements */ { "left", leftright_size, leftright_render }, { "right", leftright_size, leftright_render }, + /* Superscripts and subscripts */ { "\\sup", supsubscript_size, supsubscript_render }, { "\\sub", supsubscript_size, supsubscript_render }, - /* Sum symbol */ - { "sum", sum_size, sum_render }, + + /* Large operator symbols */ + { "sum", sum_size, sum_render }, + { "prod", prod_size, prod_render }, + /* Integral */ - { "int", NULL, NULL }, + { "int", int_size, int_render }, + /* NULL terminator */ - { NULL, NULL, NULL }, + { NULL }, }; /* class_find() - Find a class using a command name */ diff --git a/src/flow.c b/src/flow.c index dfab93a..4adb9f1 100644 --- a/src/flow.c +++ b/src/flow.c @@ -321,7 +321,11 @@ void size_flow(struct TeX_Flow *flow) update(&c, &x, &above, &below); int mode = TEX_CHUNK_INLINE; - if(!strcmp(class, "sum")) + if(!strcmp(class, "sum") || !strcmp(class, "prod") + #if TEX_INT_DISPLAY + || !strcmp(class, "int") + #endif + ) { mode = TEX_CHUNK_DISPLAY; } diff --git a/src/platform/sdl2.c b/src/platform/sdl2.c index 6c2df8d..2722c27 100644 --- a/src/platform/sdl2.c +++ b/src/platform/sdl2.c @@ -17,26 +17,34 @@ static SDL_Renderer *r = NULL; static SDL_Texture *font = NULL; /* Font configuration */ +#define FONT_SIZE 1 -#ifndef LARGE_FONT /* Small font */ - +#if FONT_SIZE==1 #define FONT_FILE "font5x7.bmp" #define FONT_WIDTH 5 #define FONT_HEIGHT 7 #define FONT_OUTER 1 #define FONT_INNER 2 #define FONT_OFFSET 0 +#endif -#else /* Large font */ +#if FONT_SIZE==2 +#define FONT_FILE "font8x9.bmp" +#define FONT_WIDTH 8 +#define FONT_HEIGHT 9 +#define FONT_OUTER 2 +#define FONT_INNER 2 +#define FONT_OFFSET 32 +#endif +#if FONT_SIZE==3 #define FONT_FILE "font10x12.bmp" #define FONT_WIDTH 10 #define FONT_HEIGHT 12 #define FONT_OUTER 3 #define FONT_INNER 3 #define FONT_OFFSET 32 - -#endif /* Font size */ +#endif //--- // Interface functions @@ -161,9 +169,10 @@ static void fini(void) int main(void) { char const * formula = - "\\frac{x^7\\left[X,Y\\right]+3\\left|\\frac{A}{B}\\right>}{" - "\\left\\{\\frac{a_k+b_k}{5!}\\right\\}^n" - "} + \\sum_{k=1}^nk(-1)^k"; + "\\frac{x^7\\left[X,Y\\right]+3\\left|\\frac{A}{B}\\right>}" + "{\\prod_{k=1}^n\\left\\{\\frac{a_k+b_k}{k!}\\right\\}^5}" + " + \\sum_{k=1}^n\\frac{(b-a)^k}{k!}" + "+\\int_a^b\\frac{(b-t)^{n+1}}{n!}dt"; struct TeX_Flow *flow = TeX_parse(formula); if(!flow) { puts("parsing error!"); return 1; }