forked from Lephenixnoir/TeX
expose a few more spacing parameters
This commit is contained in:
parent
3ff304014b
commit
3d88e387cb
1
TODO.md
1
TODO.md
|
@ -23,7 +23,6 @@
|
|||
-> U+3010
|
||||
-> U+3011
|
||||
|
||||
* Don't use TEX_LAYOUT_SPACING for everything, just make it the default
|
||||
* Add a parameter to resolve as inline style or display style
|
||||
* Parametrize character-level and word-level spacing
|
||||
* Be more generic in what nodes have display mode by default
|
||||
|
|
|
@ -36,13 +36,25 @@
|
|||
// A few quirks that can be adjusted to your needs.
|
||||
//---
|
||||
|
||||
/* 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
|
||||
|
||||
/* Thickness and horizontal margin of fraction bars */
|
||||
#define TEX_FRACTION_BAR_THICKNESS 1
|
||||
#define TEX_FRACTION_BAR_MARGIN 1
|
||||
#define TEX_FRACTION_MARGIN 1
|
||||
/* Vertical spacing between fraction bar and operands */
|
||||
#define TEX_FRACTION_SPACING TEX_LAYOUT_SPACING
|
||||
|
||||
/* Vertical placement of subscripts and superscripts (relative to object) */
|
||||
#define TEX_SUBSCRIPT_ELEVATION 3
|
||||
#define TEX_SUPERSCRIPT_DEPTH 3
|
||||
/* Horizontal spacing between object and subscripts and superscripts */
|
||||
#define TEX_SUBSCRIPT_SPACING TEX_LAYOUT_SPACING
|
||||
#define TEX_SUPERSCRIPT_SPACING TEX_LAYOUT_SPACING
|
||||
/* Vertical spacing between objects and sub/superscripts in display mode */
|
||||
#define TEX_DISPLAY_SPACING TEX_LAYOUT_SPACING
|
||||
|
||||
/* Align the center of the resizable brackets with the baseline */
|
||||
#define TEX_LEFTRIGHT_ALIGNED 0
|
||||
|
@ -51,11 +63,6 @@
|
|||
/* 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 */
|
||||
|
|
|
@ -54,7 +54,7 @@ void env_layout(struct TeX_Node *node)
|
|||
node->line = node->env->line;
|
||||
}
|
||||
|
||||
void env_render(struct TeX_Node *node, int x, int y, int color)
|
||||
void env_render(struct TeX_Node const * node, int x, int y, int color)
|
||||
{
|
||||
node->env->render(node->env, x, y, color);
|
||||
}
|
||||
|
@ -66,20 +66,20 @@ void env_render(struct TeX_Node *node, int x, int y, int color)
|
|||
//
|
||||
// Graphical parameters:
|
||||
//
|
||||
// TEX_LAYOUT_SPACING (inherited):
|
||||
// TEX_FRACTION_SPACING:
|
||||
// Spacing between bar and operands
|
||||
// TEX_FRACTION_BAR_THICKNESS:
|
||||
// Thickness (pixels) of fraction bar
|
||||
// TEX_FRACTION_BAR_MARGIN:
|
||||
// TEX_FRACTION_MARGIN:
|
||||
// Additional bar length that extends beyond the operands
|
||||
//
|
||||
// 1
|
||||
// ] TEX_LAYOUT_SPACING
|
||||
// ] TEX_FRACTION_SPACING
|
||||
// ####### ] TEX_FRACTION_BAR_THICKNESS
|
||||
// ] TEX_LAYOUT_SPACING
|
||||
// ] TEX_FRACTION_SPACING
|
||||
// 2
|
||||
// |_| |_|
|
||||
// TEX_FRACTION_BAR_MARGIN
|
||||
// TEX_FRACTION_MARGIN
|
||||
//---
|
||||
|
||||
void frac_layout(struct TeX_Node *node)
|
||||
|
@ -87,9 +87,9 @@ void frac_layout(struct TeX_Node *node)
|
|||
/* Drop the fraction if there are less than two arguments */
|
||||
if(!args[1]) { node->hidden = 1; return; }
|
||||
|
||||
int margin = TEX_FRACTION_BAR_MARGIN;
|
||||
int margin = TEX_FRACTION_MARGIN;
|
||||
int thickness = TEX_FRACTION_BAR_THICKNESS;
|
||||
int spacing = TEX_LAYOUT_SPACING;
|
||||
int spacing = TEX_FRACTION_SPACING;
|
||||
|
||||
node->width = max(w(0), w(1)) + 2 * margin;
|
||||
node->height = h(0) + h(1) + 2 * spacing + thickness;
|
||||
|
@ -101,7 +101,7 @@ void frac_render(struct TeX_Node const * node, int x, int y, int color)
|
|||
/* Fraction bar */
|
||||
for(int i = 0; i < TEX_FRACTION_BAR_THICKNESS; i++)
|
||||
{
|
||||
int y0 = y + h(0) + TEX_LAYOUT_SPACING + i;
|
||||
int y0 = y + h(0) + TEX_FRACTION_SPACING + i;
|
||||
TeX_line(x, y0, x + node->width - 1, y0, color);
|
||||
}
|
||||
|
||||
|
@ -114,7 +114,7 @@ void frac_render(struct TeX_Node const * node, int x, int y, int color)
|
|||
/* Second argument */
|
||||
TeX_flow_render(args[1],
|
||||
x + ((node->width - w(1)) >> 1),
|
||||
y + h(0) + 2 * TEX_LAYOUT_SPACING + TEX_FRACTION_BAR_THICKNESS,
|
||||
y + h(0) + 2*TEX_FRACTION_SPACING + TEX_FRACTION_BAR_THICKNESS,
|
||||
color);
|
||||
}
|
||||
|
||||
|
@ -246,26 +246,34 @@ void leftright_render(struct TeX_Node const * node, int x, int y, int color)
|
|||
// thing about them is their behavior in a flow, which depends on the
|
||||
// context and is handled by flow functions in [TeX.c].
|
||||
//
|
||||
// TODO: parameters for display mode (TEX_DISPLAY_SPACING)
|
||||
//
|
||||
// Graphical parameters:
|
||||
//
|
||||
// TEX_SUPERSCRIPT_DEPTH:
|
||||
// Distance between bottom of superscript and top of base
|
||||
// TEX_SUBSCRIPT_ELEVATION:
|
||||
// Distance between top of subscript and bottom of base
|
||||
// TEX_SUPERSCRIPT_SPACING:
|
||||
// Horizontal spacing between superscript and base
|
||||
// TEX_SUBSCRIPT_SPACING:
|
||||
// Horizontal spacing between subscript and base
|
||||
//
|
||||
// +-----+
|
||||
// | |
|
||||
// +------+ 1 | --,
|
||||
// | Base | | | TEX_SUPERSCRIPT_DEPTH
|
||||
// | +-----+ --'
|
||||
// +-----+
|
||||
// | |
|
||||
// +------+ | 1 | --,
|
||||
// | Base | | | | TEX_SUPERSCRIPT_DEPTH
|
||||
// | | +-----+ --'
|
||||
// +------+
|
||||
// >--< TEX_SUPERSCRIPT_SPACING
|
||||
//
|
||||
// +------+
|
||||
// | +-----+ --,
|
||||
// | Base | | | TEX_SUBSCRIPT_ELEVATION
|
||||
// +------| 1 | --'
|
||||
// | |
|
||||
// +-----+
|
||||
// | | +-----+ --,
|
||||
// | Base | | | | TEX_SUBSCRIPT_ELEVATION
|
||||
// +------+ | 1 | --'
|
||||
// | |
|
||||
// +-----+
|
||||
// >--< TEX_SUBSCRIPT_SPACING
|
||||
//---
|
||||
|
||||
void supsubscript_layout(struct TeX_Node *node)
|
||||
|
|
12
src/flow.c
12
src/flow.c
|
@ -148,27 +148,25 @@ static void chunk_layout_inline(struct chunk *chunk)
|
|||
{
|
||||
int elevation = TEX_SUBSCRIPT_ELEVATION;
|
||||
|
||||
sub->x = base->x + base->width + TEX_LAYOUT_SPACING;
|
||||
sub->x = base->x + base->width + TEX_SUBSCRIPT_SPACING;
|
||||
sub->l = base->l + (base->height - base->line + sub->line -
|
||||
elevation);
|
||||
|
||||
under = max(under, under + sub->height - elevation);
|
||||
right = max(right, sub->width);
|
||||
right = max(right, sub->width + TEX_SUBSCRIPT_SPACING);
|
||||
}
|
||||
if(sup)
|
||||
{
|
||||
int depth = TEX_SUPERSCRIPT_DEPTH;
|
||||
|
||||
sup->x = base->x + base->width + TEX_LAYOUT_SPACING;
|
||||
sup->x = base->x + base->width + TEX_SUPERSCRIPT_SPACING;
|
||||
sup->l = base->l - (base->line + (sup->height - sup->line) -
|
||||
depth);
|
||||
|
||||
over = max(over, over + sup->height - depth);
|
||||
right = max(right, sup->width);
|
||||
right = max(right, sup->width + TEX_SUPERSCRIPT_SPACING);
|
||||
}
|
||||
|
||||
if(right > 0) right += TEX_LAYOUT_SPACING;
|
||||
|
||||
chunk->width = base->width + right;
|
||||
chunk->height = over + under;
|
||||
chunk->line = over;
|
||||
|
@ -181,7 +179,7 @@ static void chunk_layout_display(struct chunk *chunk)
|
|||
struct TeX_Node *sup = chunk->sup;
|
||||
struct TeX_Node *sub = chunk->sub;
|
||||
|
||||
int spacing = TEX_LAYOUT_SPACING;
|
||||
int spacing = TEX_DISPLAY_SPACING;
|
||||
|
||||
/* Chunk width and height */
|
||||
chunk->width = base->width;
|
||||
|
|
Loading…
Reference in New Issue