core: support angle brackets \left< and \right>

This commit is contained in:
Lephenixnoir 2019-05-29 15:58:46 -04:00
parent b8299dbbf7
commit a72c09e100
6 changed files with 21 additions and 10 deletions

View File

@ -67,7 +67,7 @@ Before using the library in a program, a configuration step is needed. The libra
The three rendering functions are available in fxlib; for monospaced fonts the fourth can be implemented trivially. In gint, the four can be defined as wrappers for `dpixel()`, `dline()`, `dsize()` and `dtext()`.
The type of formulae is `TeX_Flow`. To parse and compute the size of a formula, use the `TeX_parse()` functions, which returns a new formula object (or `NULL` if a critical error occurs).
The type of formulae is `TeX_Flow`. To parse and compute the size of a formula, use the `TeX_parse()` function, which returns a new formula object (or `NULL` if a critical error occurs).
```c
char *code = "\\frac{x_7}{\\left\\{\\frac{\\frac{2}{3}}{27}\\right\\}^2}";

View File

@ -3,6 +3,7 @@
* Support Unicode symbols (probably requires help from the font side, urgh)
* Don't use TEX_LAYOUT_SPACING for everything, just make it the default
* Add a parameter to resolve as inline style or display style
* Support character-level spacing
* Add sum and products
* Add square roots, and honor TEX_SQRT_SLANTED and TEX_SQRT_BAR_LENGTH

View File

@ -24,8 +24,8 @@
#define TEX_LEFTRIGHT_ALIGNED 0
/* Make them extend symmetrically around baseline */
#define TEX_LEFTRIGHT_SYMMETRICAL 0
/* Maximum angle for resizable "<" and ">" delimiters (radians) */
#define TEX_LEFTRIGHT_MAX_ANGLE 2.50
/* 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

View File

@ -92,7 +92,7 @@ void size_node(struct TeX_Node *node)
node->width = w;
node->height = h;
node->line = (h+1) >> 1;
node->line = h >> 1;
return;
}

View File

@ -176,7 +176,7 @@ flow:
node:
TEXT { $$ = mknode_text($1); }
| COMMAND { $$ = mknode_command($1); }
| node_abs { $$ = $1; }
| node_abs TEXT { $$ = mknode_absarg($1, $2); }
| node '{' flow '}' { $$ = mknode_arg($1, $3); }
/* Special shortcuts for the superscript and subscript classes */
| '^' TEXT { $$ = mknode_t("\\sup", $2); }
@ -184,11 +184,8 @@ node:
| '^' '{' flow '}' { $$ = mknode_f("\\sup", $3); }
| '_' '{' flow '}' { $$ = mknode_f("\\sub", $3); }
/* TODO: shift/reduce for [COMMAND_ABS TEXT] - could split in two nodes */
node_abs:
COMMAND_ABS { $$ = mknode_command($1); }
| node_abs TEXT { $$ = mknode_absarg($1, $2); }
%%
//---

View File

@ -114,12 +114,15 @@ void leftright_size(struct TeX_Node *node)
/* TODO: Not the same on fxcg50 */
node->width = 3;
node->height = height;
node->line = (height+1) >> 1;
node->line = height >> 1;
if(node->subtype == '<' || node->subtype == '>')
node->width = TEX_LEFTRIGHT_ANGLE_WIDTH;
}
void leftright_render(struct TeX_Node const * node, int x, int y, int color)
{
int h = node->height, l = node->line;
int h = node->height, w = node->width, l = node->line;
switch(node->subtype)
{
@ -170,6 +173,16 @@ void leftright_render(struct TeX_Node const * node, int x, int y, int color)
TeX_line(x + 1, y + l + 1, x + 1, y + h - 2, color);
TeX_pixel(x, y + h - 1, color);
break;
case '<':
TeX_line(x, y + l, x + w - 1, y, color);
TeX_line(x, y + l, x + w - 1, y + h - 1, color);
break;
case '>':
TeX_line(x + w - 1, y + l, x, y, color);
TeX_line(x + w - 1, y + l, x, y + h - 1, color);
break;
}
}