Преглед на файлове

core: add products and integrals

Also adding a new font to try out in the SDL2 backend.
master
Lephenixnoir преди 6 месеца
родител
ревизия
41b28f6a62
променени са 7 файла, в които са добавени 84 реда и са изтрити 19 реда
  1. +1
    -2
      README.md
  2. +0
    -2
      TODO.md
  3. Двоични данни
      font5x7.bmp
  4. Двоични данни
      font8x9.bmp
  5. +61
    -6
      src/classes.c
  6. +5
    -1
      src/flow.c
  7. +17
    -8
      src/platform/sdl2.c

+ 1
- 2
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)

+ 0
- 2
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

Двоични данни
font5x7.bmp Целия файл

Before After

Двоични данни
font8x9.bmp Целия файл

Before After

+ 61
- 6
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 */

+ 5
- 1
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;
}

+ 17
- 8
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; }

Loading…
Отказ
Запис