From 41b28f6a62236e5dd3111637c1face4c9036c58c Mon Sep 17 00:00:00 2001 From: Lephenixnoir Date: Thu, 30 May 2019 13:22:30 -0400 Subject: [PATCH] core: add products and integrals Also adding a new font to try out in the SDL2 backend. --- README.md | 3 +- TODO.md | 2 -- font5x7.bmp | Bin 24330 -> 24314 bytes font8x9.bmp | Bin 0 -> 44202 bytes src/classes.c | 67 ++++++++++++++++++++++++++++++++++++++++---- src/flow.c | 6 +++- src/platform/sdl2.c | 25 +++++++++++------ 7 files changed, 84 insertions(+), 19 deletions(-) create mode 100644 font8x9.bmp 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 40e6f0d069368765103aab633076459777cda4f5..47863754e7036043ddc1c770f51cd68473879bb0 100644 GIT binary patch delta 197 zcmeC$$M|b6BfpdHuQ&!Ur~;BX6ZzFmo!oFNPBsvFHF<#=+vEUt wiOB_0JRpUW{h9bDSsG7%z{@!~4k+adl)AvgKY4-~8`!J^{G6K~2y1x*0QY7uS^xk5 delta 240 zcmeyhm$7RfBfpa`S3Cn4bOFhliTvuW3=IEa2qf{}$vvpJ;m}u&gdK9C3azgh9gK~I z8`9F$9MaO*7R;QdK%g(g1`5(Vl5>fvXb zyug`%vVyVbBvYZuFUS0|3Q3M&tkh diff --git a/font8x9.bmp b/font8x9.bmp new file mode 100644 index 0000000000000000000000000000000000000000..9805dd6e8a50524f24de943b2b394bf7def89560 GIT binary patch literal 44202 zcmeH{y^dwo5rrFpEJ2D$(MU!X5rIhw5JGa~#IXaSc>z)fBqSt`CqoV`9)Osa@IyEz z9=fLejn^zy)vj~Txwm`7*dAEf^3umAq(?$!C>{^vjL|NZO!-`Ds5-nn~r z_wGGDyZ8V2*~7nk`oHt??(X5g;4i=W%iq5J?w4Ob{pRP7KYI54f8Y7?^Upv0?)mdS zefj+PAAWrC;{7i^_|Lna{QaMQW;^gbCHM2o^PFGc`~v3}IKRLfUm*T8?)mfR`_A9E z%m`UWi@m0+T;`*_E|H=0BIdsHEJJ;l4X--vWmxTmPW~2|?hZWOQz1E!9DFPKzVoWD z%1w38IgfkM0{y6$`MS?8JMb)nmu2^Q>^pXMY4+%xcKcl2wbJnwt8UFOlXZ?h#cIFO z>8<=scg?wX;)D30>(0q3cA3u84(4h8=p6TFSlzW(pYB(=?yc;AT{iPVt9CQpHRs-^ zzRvm8qY>A5C{v%XHpF4i0YBx9&~*A1lZ216J?A51eF< z&T(g8){XzllphnF3@GcbMszSlot@)>uS($#XlyEH2FWPmDXP!xJ{%uJ2hkl@e&oqGY8Rerx~n=_ zN6qN2=BkY96&wLTd?YI-8px-?wp)sm2=&>_c)*A$z(_$ z9vrOn@H>xv#VoIy&bsGwms78rqfb5UcilPJO2?ld9T~EZ2M1kuPR_B)xel*z+Dnce zIOw|bDu*6e?Px~lERP0izM8wNdet1g>gheMJ11M|_?M#hI;Yol=j0r#oa@f%aUJeR z9>j-(t~;-C=z-OaW^~T-s_CqIK6g3wsyX`9(|*^TldW`oFmlz&I$VQ$54v_=sQ!^};05YI@3btVdFDxuj3WDi=sK&W z*(?*;?9hP^_bfW-K78dzjtr<;)+Cu8vz+I<3|Z|| z?UH$V-zD9;v-cj~cdmDJ^QC)T=fu0@-b;2SZ#gQ%`vUhKy7u<0_K&!S4sdm6=3lbA z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3;Z6w z0Doim{;uBR-1}GlG*1s0dpdj17QX6P`CIPVlD)>gtIn0b<^5UqsDAHp&fVya_`ZeEnRJZpy=lh{M z;yaRa9gZJ()S+|Qx60##-iuzL=U2SyL0|1xKKp@3AG)(%zt6euc#reQs;0B{WOJ8Q zFXkhTc24@bJf36KORn-CTff%(x?cC3^G(nz^jvVVK4*NYX=m*CS^4Crxm8|!s+kT@ zb7)Tqul2sJ*FER@ecW?S7Tpm)5Kpyi_MG#{PL>I6()F0R>fN`{r{8AFTe?p7oa;UA wIoE8=E8p`Krw6QZp_2)m9P(9mwidth = 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; }