Start of the pretty print handling; actually using a 'popup' system

This commit is contained in:
Nemh 2015-04-17 00:42:15 +02:00
parent f839d0d678
commit 30e5039012
12 changed files with 1266 additions and 73 deletions

View File

@ -152,12 +152,16 @@ SourceFile=:variables.cpp
SourceFile=:vectorize.cpp
SourceFile=:zero.cpp
SourceFile=:display.cpp
SourceFile=:print.cpp
SourceFile=:main.cpp
SourceFile=:test.cpp
SourceFile=:console.c
SourceFile=:syscalls_.src
SourceFile=:memory.c
SourceFile=:tex\debug.c
SourceFile=:tex\disp.src
SourceFile=:tex\libText.c
SourceFile=:tex\math.c
SourceFile=:print.cpp
HeaderFile=:defs.h
HeaderFile=:prototypes.h
HeaderFile=:setjmp.h
@ -165,3 +169,6 @@ HeaderFile=:stdafx.h
HeaderFile=:console.h
HeaderFile=:syscalls.h
HeaderFile=:memory.h
HeaderFile=:tex\TeX.h
HeaderFile=:tex\debug.h
HeaderFile=:tex\libText.h

View File

@ -6,6 +6,7 @@ extern "C"{
#include "console.h"
#include "fxlib.h"
#include "syscalls.h"
#include "tex/TeX.h"
#define EXPR_BUF_SIZE 256
extern U ** mem;
@ -24,6 +25,18 @@ initialize_tuamath()
logbuf = (char*) calloc(256,1);
}
void TeX_init(void)
{
Txt_Init(FONT_SYSTEM);
//debug_init();
}
void TeX_quit(void)
{
//debug_quit();
Txt_Quit();
}
const unsigned char *Setup[]={
"logab(a,b)=log(b)/log(a)",
"log10(x)=log(x)/log(10)",
@ -64,18 +77,20 @@ int AddIn_main(int isAppli, unsigned short OptionNum)
run((char *)Setup[i++]);
}
TeX_init();
Console_Init();
Console_Disp();
while(1)
{
if((expr=Console_GetLine())==NULL) stop("memory error");
run((char *)expr);
//print_mem_info();
Console_NewLine(LINE_TYPE_OUTPUT,1);
//GetKey(&key);
Console_Disp();
}
TeX_quit();
for(;;)GetKey(&key);
return 1;
}

291
console.c
View File

@ -1,9 +1,13 @@
#include <stdio.h>
#include "console.h"
#include "tex/TeX.h"
#include "syscalls.h"
#include "memory.h"
#define POPUP_PRETTY 1
#define POPUP_PRETTY_STR "Pretty print"
extern void run(char *s);
static struct line Line[LINE_MAX];
@ -17,20 +21,37 @@ static int Case;
#define Current_Col (Line[Cursor.y + Start_Line].start_col + Cursor.x)
/*
n个字符121
ÒÔϺ¯Êý½«ÓÃÓÚɾ³ý×Ö·û´®Ö¸¨Î»ÖÃ֮ǰ¹²n¸ö×Ö·û¡£ÆäÖУ¬1¸ö¿í×Ö·û£¨Õ¼2×Ö½Ú£©½«Ëã×÷1¸ö×Ö·û¡£
str
ÀýÈ磬ÎÒÃÇÓÐÈçÏÂ×Ö·û´®str£º
| 0 | 1 | 2 | 3 | 4 | 5 | 6 |
|'a'|'b'|'c'|'d'|'e'|'f'| 0 |
λÖà | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
×Ö·û |'a'|'b'|'c'|'d'|'e'|'f'| 0 |
Console_DelStr(str, 3, 2)12
Ôòµ÷ÓÃConsole_DelStr(str, 3, 2)ºó£¬Î»ÖÃ1¡¢2µÄ×Ö·û½«±»É¾³ý£¬ÆäºóµÄ×Ö·û½«±»ÌáÇ°¡£
½á¹ûÈçÏ£º
| 0 | 1 | 2 | 3 | 4 | 5 | 6 |
|'a'|'d'|'e'|'f'| 0 |'f'| 0 |
λÖà | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
×Ö·û |'a'|'d'|'e'|'f'| 0 |'f'| 0 |
£¨×¢Ò⣺àÓàµÄλÖò¢²»»á±»Ìî³äΪ'\0'£¬µ«ÊÇÔ­×Ö·û´®Ä©Î²µÄ'\0'½«±»¿½±´¡££©
The following functions will be used to specify the location before deleting a string of n characters altogether. Among them, a wide character (2 bytes) will be counted as a character.
For example, we have the following string str:
Location | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
Character | 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 0 |
After the call Console_DelStr (str, 3, 2), position 1 and 2 characters will be deleted, then the characters will be in advance.
Results are as follows:
Location | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
Character | 'a' | 'd' | 'e' | 'f' | 0 | 'f' | 0 |
(Note: the extra positions will not be filled with '\ 0', but '\ 0' will be a copy of the original end of the string.)
'\0''\0'
*/
int Console_DelStr(unsigned char *str, int end_pos, int n)
@ -54,9 +75,12 @@ int Console_DelStr(unsigned char *str, int end_pos, int n)
}
/*
ÒÔϺ¯ÊýÓÃÓÚÔÚÖ¸¨Î»ÖòåÈëÖ¸¨µÄ×Ö·û´®¡£
£¨×¢Ò⣺ÕâÀïµÄλÖÃÖ¸µÄÊÇ´òӡʱµÄλÖã¬ø²»ÊÇʵ¼ÊµÄλÖᣣ©
The following functions are used to specify the location of the insertion in the specified string.
(Note: This refers to the position of the printing position when, rather than the actual position.)
*/
int Console_InsStr(unsigned char *dest, const unsigned char *src, int disp_pos)
@ -85,20 +109,35 @@ int Console_InsStr(unsigned char *dest, const unsigned char *src, int disp_pos)
}
/*
ÒÔϺ¯ÊýÓÃÓÚÈ·¨ÔÓ¦ÓÚ×Ö·û´®´òӡλÖõÄÕæʵλÖá£
str中
ÀýÈ磬ÔÚÒÔÏÂÕâÒ»°üº¬¿í×Ö·ûµÄ×Ö·û´®strÖУ¬´òӡʱµÄλÖÃÈçÏ£º
| 00 | 01 | 02 | 03 | 04 | 05 | 06 |
| | | | | | | \0 |
λÖà | 00 | 01 | 02 | 03 | 04 | 05 | 06 |
×Ö·û | Ò» | þ | Èý | ËÄ | Îå | Áù | \0 |
øÔÚʵ¼Ê´æ´¢Ê±µÄλÖÃÈçÏ£º
| 00 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 | 11 |
| 0xD2 | 0xBB | 0xB6 | 0xFE | 0xC8 | 0xFD | 0xCB | 0xC4 | 0xCE | 0xE5 | 0xC1 | 0xF9 |
λÖà | 00 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 | 11 |
Öµ | 0xD2 | 0xBB | 0xB6 | 0xFE | 0xC8 | 0xFD | 0xCB | 0xC4 | 0xCE | 0xE5 | 0xC1 | 0xF9 |
48
Console_GetActualPos(str, 4)8
¿ÉÒÔ·¢ÏÖ£¬µÚ4¸ö×Ö·û¡®Î塯ʵ¼ÊÉÏ´æ´¢ÓÚµÚ8µÄλÖá£
Òò´Ë£¬µ±µ÷ÓÃConsole_GetActualPos(str, 4)ʱ£¬½«·µ»Ø8¡£
The following function is used to determine the true position of the string corresponding to the printing position.
For example, in the following this string str contains wide characters, the location of the print is as follows:
Location | 00 | 01 | 02 | 03 | 04 | 05 | 06 |
Character | one | two | three | four | five | six | \ 0 |
The actual storage location is as follows:
Location | 00 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 | 11 |
Value | 0xD2 | 0xBB | 0xB6 | 0xFE | 0xC8 | 0xFD | 0xCB | 0xC4 | 0xCE | 0xE5 | 0xC1 | 0xF9 |
You can find the first four characters 'five' is actually stored in the eighth position.
So, when you call Console_GetActualPos (str, 4), it will return 8.
*/
int Console_GetActualPos(const unsigned char *str, int disp_pos)
@ -123,7 +162,8 @@ int Console_GetActualPos(const unsigned char *str, int disp_pos)
}
/*
121
ÒÔϺ¯ÊýÓÃÓÚ»ñÈ¡×Ö·û´®µÄ´òÓ¡³¤È£¬¼´£¬1¸ö¿í×Ö·û£¨Õ¼ÓÃ2×Ö½Ú£©¼Ç×÷1×Ö·û¡£
The following functions are used to obtain a string of print length, ie, a wide character (2 bytes) recorded as a character.
*/
int Console_GetDispLen(const unsigned char *str)
@ -146,7 +186,8 @@ int Console_GetDispLen(const unsigned char *str)
}
/*
ÒÔϺ¯ÊýÓÃÓÚÒƯ¹â±ê¡£
The following functions are used to move the cursor.
*/
int Console_MoveCursor(int direction)
@ -154,10 +195,12 @@ int Console_MoveCursor(int direction)
switch (direction)
{
case CURSOR_UP:
//如果需要操作。
//Èç¹ûÐèÒª²Ù×÷¡£
//If you need to operate.
if ((Cursor.y > 0) || (Start_Line > 0))
{
//如果当前行不是只读的,则将Edit_Line拷贝给当前行。
//Èç¹ûµ±Ç°Ðв»ÊÇÖ»¶ÁµÄ,Ôò½«Edit_Line¿½±´¸øµ±Ç°ÐС£
//If the current line is not read-only, then Edit_Line copy to the current line.
if (!Line[Current_Line].readonly)
{
if ((Line[Current_Line].str = (unsigned char *)malloc(strlen((const char *)Edit_Line) + 1)) == NULL) return CONSOLE_MEM_ERR;
@ -166,18 +209,21 @@ int Console_MoveCursor(int direction)
Line[Current_Line].type = LINE_TYPE_INPUT;
}
//如果光标未移到最上方,则直接将光标向上移。
//Èç¹û¹â±êδÒƵ½×îÉÏ·½,ÔòÖ±½Ó½«¹â±êÏòÉÏÒÆ¡£
//If the cursor does not move to the top of, directly move the cursor upward.
if (Cursor.y > 0)
{
Cursor.y--;
}
//否则,如果屏幕上首行不是第一行,则将开始显示的行数减一。
//·ñÔò£¬Èç¹ûÆÁÄ»ÉÏÊ×Ðв»ÊǵÚÒ»ÐУ¬Ôò½«¿ªÊ¼ÏÔʾµÄÐÐÊý¼õÒ»¡£
//Otherwise, the number of rows, if the screen's first line is not the first line, then began to show minus one.
else if (Start_Line > 0)
{
Start_Line--;
}
//如果移动后光标水平位置超过行末,则将光标移至行末。
//Èç¹ûÒƶ¯ºó¹â±êˮƽλÖó¬¹ýÐÐÄ©£¬Ôò½«¹â±êÒÆÖÁÐÐÄ©¡£
//End if the horizontal position after moving the cursor over the line, then move the cursor to the end of the line.
if (Cursor.x > Line[Current_Line].disp_len)
{
Cursor.x = Line[Current_Line].disp_len;
@ -187,10 +233,12 @@ int Console_MoveCursor(int direction)
if (Cursor.x == COL_DISP_MAX) Cursor.x = COL_DISP_MAX - 1;
}
//如果移动后光标在行首且该行前面有字符未显示则将光标移至位置1。
//Èç¹ûÒƶ¯ºó¹â±êÔÚÐÐÊ×£¬ÇÒ¸ÃÐÐÇ°ÃæÓÐ×Ö·ûδÏÔʾ£¬Ôò½«¹â±êÒÆÖÁλÖÃ1¡£
//If you move the cursor to the line after the first, and the front of the line there is a character does not appear, then move the cursor to position 1.
if (Cursor.x == 0 && Line[Current_Line].start_col > 0) Cursor.x = 1;
//如果现在光标所在行不是只读的则将其字符串拷贝给Edit_Line以供编辑。
//Èç¹ûÏÖÔÚ¹â±êËùÔÚÐв»ÊÇÖ»¶ÁµÄ£¬Ôò½«Æä×Ö·û´®¿½±´¸øEdit_LineÒÔ¹©±à¼­¡£
//If the current cursor line is not read-only, then it is a string copy to Edit_Line for editing.
if (!Line[Current_Line].readonly)
{
strcpy((char *)Edit_Line, (const char *)Line[Current_Line].str);
@ -200,10 +248,12 @@ int Console_MoveCursor(int direction)
}
break;
case CURSOR_DOWN:
//如果需要操作。
//Èç¹ûÐèÒª²Ù×÷¡£
//If you need to operate.
if ((Cursor.y < LINE_DISP_MAX - 1) && (Current_Line < Last_Line) || (Start_Line + LINE_DISP_MAX - 1 < Last_Line))
{
//如果当前行不是只读的,则将Edit_Line拷贝给当前行。
//Èç¹ûµ±Ç°Ðв»ÊÇÖ»¶ÁµÄ,Ôò½«Edit_Line¿½±´¸øµ±Ç°ÐС£
//If the current line is not read-only, then Edit_Line copy to the current line.
if (!Line[Current_Line].readonly)
{
if ((Line[Current_Line].str = (unsigned char *)malloc(strlen((const char *)Edit_Line) + 1)) == NULL) return CONSOLE_MEM_ERR;
@ -212,18 +262,21 @@ int Console_MoveCursor(int direction)
Line[Current_Line].type = LINE_TYPE_INPUT;
}
//如果光标未移到最下方,则直接将光标向下移。
//Èç¹û¹â±êδÒƵ½×îÏ·½,ÔòÖ±½Ó½«¹â±êÏòÏÂÒÆ¡£
//If the cursor does not move to the bottom, the cursor moves down directly.
if (Cursor.y < LINE_DISP_MAX - 1 && Current_Line < Last_Line)
{
Cursor.y++;
}
//否则,如果屏幕上末行不是最后一行,则将开始显示的行数加一。
//·ñÔò£¬Èç¹ûÆÁÄ»ÉÏÄ©Ðв»ÊÇ×îºóÒ»ÐУ¬Ôò½«¿ªÊ¼ÏÔʾµÄÐÐÊý¼ÓÒ»¡£
//The number of rows Otherwise, if the last line is not the last line on the screen, it will begin to show a plus.
else if (Start_Line + LINE_DISP_MAX - 1 < Last_Line)
{
Start_Line++;
}
//如果移动后光标水平位置超过行末,则将光标移至行末。
//Èç¹ûÒƶ¯ºó¹â±êˮƽλÖó¬¹ýÐÐÄ©£¬Ôò½«¹â±êÒÆÖÁÐÐÄ©¡£
//If you move the cursor after the end of the horizontal position over the line, then move the cursor to the end of the line.
if (Cursor.x > Line[Current_Line].disp_len)
{
Cursor.x = Line[Current_Line].disp_len;
@ -233,10 +286,12 @@ int Console_MoveCursor(int direction)
if (Cursor.x == COL_DISP_MAX) Cursor.x = COL_DISP_MAX - 1;
}
//如果移动后光标在行首且该行前面有字符未显示则将光标移至位置1。
//Èç¹ûÒƶ¯ºó¹â±êÔÚÐÐÊ×£¬ÇÒ¸ÃÐÐÇ°ÃæÓÐ×Ö·ûδÏÔʾ£¬Ôò½«¹â±êÒÆÖÁλÖÃ1¡£
//If you move the cursor to the line after the first, and the front of the line there is a character does not appear, then move the cursor to position 1.
if (Cursor.x == 0 && Line[Current_Line].start_col > 0) Cursor.x = 1;
//如果现在光标所在行不是只读的则将其字符串拷贝给Edit_Line以供编辑。
//Èç¹ûÏÖÔÚ¹â±êËùÔÚÐв»ÊÇÖ»¶ÁµÄ£¬Ôò½«Æä×Ö·û´®¿½±´¸øEdit_LineÒÔ¹©±à¼­¡£
//If the current cursor line is not read-only, then it is a string copy to Edit_Line for editing.
if (!Line[Current_Line].readonly)
{
strcpy((char *)Edit_Line, (const char *)Line[Current_Line].str);
@ -289,8 +344,11 @@ int Console_MoveCursor(int direction)
}
/*
ÒÔϺ¯ÊýÓÃÓÚÊäÈë¡£
×Ö·û´®½«ÊäÈëµ½¹â±ê´¦£¬¹â±ê½«×Ô¯ÒƯ¡£
The following function is used for input.
String input to the cursor, the cursor will automatically move.
*/
int Console_Input(const unsigned char *str)
@ -316,7 +374,8 @@ int Console_Input(const unsigned char *str)
}
/*
ÒÔϺ¯ÊýÓÃÓÚÊä³ö×Ö·û´®µ½µ±Ç°ÐС£
The following functions are used to output the string to the current line.
*/
int Console_Output(const unsigned char *str)
@ -345,9 +404,27 @@ int Console_Output(const unsigned char *str)
}
/*
pre_line_type用于指定上一行的类型pre_line_readonly用于指定上一行是否只读
new_line_type用于指定下一行的类型new_line_readonly用于指定下一行是否只读
Clear the current output line
*/
int Console_Clear_EditLine()
{
if(!Line[Current_Line].readonly) {
Edit_Line[0] = '\0';
Line[Current_Line].start_col = 0;
Line[Current_Line].disp_len = 0;
Cursor.x = 0;
}
}
/*
ÒÔϺ¯ÊýÓÃÓÚ´´½¨ÐÂÐС£
²ÎÊýpre_line_typeÓÃÓÚÖ¸¨ÉÏÒ»ÐеÄÀàÐÍ£¬²ÎÊýpre_line_readonlyÓÃÓÚÖ¸¨ÉÏÒ»ÐÐÊÇ·ñÖ»Á¡£
²ÎÊýnew_line_typeÓÃÓÚÖ¸¨ÏÂÒ»ÐеÄÀàÐÍ£¬²ÎÊýnew_line_readonlyÓÃÓÚÖ¸¨ÏÂÒ»ÐÐÊÇ·ñÖ»Á¡£
The following functions are used to create a new line.
Pre_line_type type parameter is used to specify the line, pre_line_readonly parameter is used to specify the line is read-only.
New_line_type parameter is used to specify the type of the next line, new_line_readonly parameter is used to specify the next line is read-only.
*/
int Console_NewLine(int pre_line_type, int pre_line_readonly)
@ -356,7 +433,8 @@ int Console_NewLine(int pre_line_type, int pre_line_readonly)
if (strlen((const char *)Edit_Line)||Line[Current_Line].type==LINE_TYPE_OUTPUT)
{
//如果已经是所能存储的最后一行,则删除第一行。
//Èç¹ûÒѾ­ÊÇËùÄÜ´æ´¢µÄ×îºóÒ»ÐУ¬Ôòɾ³ýµÚÒ»ÐС£
//If this is the last line we can store, delete the first line.
if (Last_Line == LINE_MAX - 1)
{
for (i = 0; i < Last_Line; i++)
@ -373,10 +451,27 @@ int Console_NewLine(int pre_line_type, int pre_line_readonly)
}
if (Line[Last_Line].type == LINE_TYPE_OUTPUT && strlen((const char *)Edit_Line) == 0) Console_Output((const unsigned char *)"Done");
//将Edit_Line的内容拷贝给最后一行。
if (TeX_isTeX((char*)Edit_Line)) Line[Last_Line].tex_flag = 1;
if (Line[Last_Line].type == LINE_TYPE_OUTPUT && Line[Last_Line].tex_flag) TeX_sizeComplex ((char*)Edit_Line, &(Line[Last_Line].tex_width), &(Line[Last_Line].tex_height), NULL);
else Line[Last_Line].tex_flag = 0;
//½«Edit_LineµÄÄÚÈÝ¿½±´¸ø×îºóÒ»ÐС£
//Edit_Line copy the contents to the last line.
#ifdef POPUP_PRETTY
if(Line[Last_Line].tex_flag) {
if ((Line[Last_Line].str = (unsigned char *)malloc(strlen(POPUP_PRETTY_STR) + 1)) == NULL) return CONSOLE_MEM_ERR;
strcpy((char*)Line[Last_Line].str, (const char*)POPUP_PRETTY_STR);
if ((Line[Last_Line].tex_str = (unsigned char *)malloc(strlen((const char *)Edit_Line) + 1)) == NULL) return CONSOLE_MEM_ERR;
strcpy((char *)Line[Last_Line].tex_str, (const char *)Edit_Line);
}
else {
if ((Line[Last_Line].str = (unsigned char *)malloc(strlen((const char *)Edit_Line) + 1)) == NULL) return CONSOLE_MEM_ERR;
strcpy((char *)Line[Last_Line].str, (const char *)Edit_Line);
}
#else
if ((Line[Last_Line].str = (unsigned char *)malloc(strlen((const char *)Edit_Line) + 1)) == NULL) return CONSOLE_MEM_ERR;
strcpy((char *)Line[Last_Line].str, (const char *)Edit_Line);
#endif
if ((Line[Last_Line].disp_len = Console_GetDispLen(Line[Last_Line].str)) == CONSOLE_ARG_ERR) return CONSOLE_ARG_ERR;
Line[Last_Line].type = pre_line_type;
Line[Last_Line].readonly = pre_line_readonly;
@ -412,7 +507,8 @@ int Console_NewLine(int pre_line_type, int pre_line_readonly)
}
/*
ÒÔϺ¯ÊýÓÃÓÚɾ³ý¹â±êÇ°µÄÒ»¸ö×Ö·û¡£
The following function is used to delete a character before the cursor.
*/
int Console_Backspace()
@ -426,7 +522,8 @@ int Console_Backspace()
}
/*
ÒÔϺ¯ÊýÓÃÓÚ´¦Àí°´¼ü¡£
The following functions are used to deal with the key.
*/
int Console_GetKey()
@ -516,7 +613,16 @@ int Console_GetKey()
return CONSOLE_SUCCEEDED;
}
//if (key == KEY_CTRL_INS) return Console_Init();
if (key == KEY_CTRL_INS) {
if (!Line[Current_Line].readonly) {
Edit_Line[0] = '\0';
Line[Current_Line].start_col = 0;
Line[Current_Line].type = LINE_TYPE_INPUT;
Line[Current_Line].disp_len = 0;
Cursor.x = 0;
}
return Console_Init();
}
if (key == KEY_CTRL_EXE)
{
@ -534,15 +640,22 @@ int Console_GetKey()
if (key == KEY_CTRL_CLIP)
{
tmp = Line[Current_Line].str;
#ifdef POPUP_PRETTY
if(Line[Current_Line].tex_flag) Console_Draw_TeX_Popup(Line[Current_Line].tex_str, Line[Current_Line].tex_width, Line[Current_Line].tex_height);
else {
#endif
tmp = Line[Current_Line].str;
move_line = Last_Line - Current_Line;
for (i = 0; i <= move_line; i++) Console_MoveCursor(CURSOR_DOWN);
move_line = Last_Line - Current_Line;
for (i = 0; i <= move_line; i++) Console_MoveCursor(CURSOR_DOWN);
move_col = Line[Current_Line].disp_len - Current_Col;
for (i = 0; i <= move_col; i++) Console_MoveCursor(CURSOR_RIGHT);
move_col = Line[Current_Line].disp_len - Current_Col;
for (i = 0; i <= move_col; i++) Console_MoveCursor(CURSOR_RIGHT);
Console_Input(tmp);
Console_Input(tmp);
#ifdef POPUP_PRETTY
}
#endif
}
return CONSOLE_NO_EVENT;
@ -685,7 +798,7 @@ int Console_Draw_FMenu(int key, struct FMenu* menu)
}
/*
ÒÔϺ¯ÊýÓÃÓÚ³õʼ»¯¡£
*/
int Console_Init()
@ -697,7 +810,7 @@ int Console_Init()
for (i = 0; i < LINE_MAX; i++)
{
free(Line[i].str);
if(Line[i].str) free(Line[i].str);
Line[i].readonly = 0;
Line[i].type = LINE_TYPE_INPUT;
Line[i].start_col = 0;
@ -770,8 +883,10 @@ void Console_FMenu_Init()
}
/*
ÒÔϺ¯ÊýÓÃÓÚÏÔʾËùÓÐÐС£
×¢Ò⣺µ÷Óøú¯Êýºó£¬½«Ê×ÏÈÇå¿ÕÏÔ´æ¡£
The following functions are used to display all lines.
Note: After calling this function, the first clear the memory.
*/
int Console_Disp()
@ -780,13 +895,16 @@ int Console_Disp()
char temp_fkey[FMENU_TITLE_LENGHT] = {'\0'};
int i, alpha_shift_status;
DISPBOX ficon;
int print_y = 0; //pixel y cursor
int print_y_locate;
Bdisp_AllClr_VRAM();
//GetFKeyIconPointer( 0x01BE, &ficon );
//DisplayFKeyIcon( i, ficon);
for (i = 0; (i < LINE_DISP_MAX) && (i + Start_Line <= Last_Line); i++)
//Reading each "line" that will be printed
for (i = 0; (i < LINE_DISP_MAX) && (i + Start_Line <= Last_Line); i++)
{
if (i == Cursor.y)
{
@ -816,7 +934,13 @@ int Console_Disp()
if (Line[i + Start_Line].readonly)
{
Cursor_SetFlashMode(0);
PrintRev(Line[i + Start_Line].str);
if(Line[i+Start_Line].tex_flag) {
locate(COL_DISP_MAX - strlen("Pretty print"),i+1);
PrintRev((unsigned char*)"Pretty print");
}
else {
PrintRev(Line[i + Start_Line].str);
}
}
else
{
@ -889,8 +1013,14 @@ int Console_Disp()
}
else
{
locate(COL_DISP_MAX - Line[i + Start_Line].disp_len + 1, i + 1);
Print(Line[i + Start_Line].str);
if(Line[i+Start_Line].tex_flag) {
locate(COL_DISP_MAX - strlen("Pretty print"),i+1);
Print((unsigned char*)"Pretty print");
}
else {
locate(COL_DISP_MAX - Line[i + Start_Line].disp_len + 1, i + 1);
Print(Line[i + Start_Line].str);
}
}
if (Line[i + Start_Line].start_col > 0)
@ -906,7 +1036,6 @@ int Console_Disp()
}
}
}
//Draw the "fkeys icons"
for(i=0; i<6; i++) {
@ -930,7 +1059,33 @@ int Console_Disp()
}
/*
Draw a popup at the center of the screen containing the str expression drawn in pretty print.
*/
#ifdef POPUP_PRETTY
void Console_Draw_TeX_Popup(unsigned char* str, int width, int height)
{
DISPBOX popup;
int margin = 2, border = 1;
int key;
popup.left = 64 - width/2 - margin - border;
popup.right = 128 - popup.left;
popup.top = 32 - height/2 - margin - border;
popup.bottom = 64 - popup.top;
Bdisp_AreaClr_VRAM(&popup);
Bdisp_AreaReverseVRAM(popup.left, popup.top, popup.right, popup.bottom);
Bdisp_AreaReverseVRAM(popup.left + border, popup.top + border, popup.right - border, popup.bottom - border);
TeX_drawComplex((char*)str, popup.left+border+margin, popup.top+border+margin);
GetKey(&key);
}
#endif
/*
ÒÔϺ¯ÊýÓÃÓÚÊäÈëÐУ¬³É¹¦ºó½«·µ»Ø¸ÃÐеÄ×Ö·û´®¡£
*/
unsigned char *Console_GetLine()
@ -945,4 +1100,12 @@ unsigned char *Console_GetLine()
} while (return_val != CONSOLE_NEW_LINE_SET);
return Line[Current_Line - 1].str;
}
/*
Simple accessor to the Edit_Line buffer.
*/
unsigned char* Console_GetEditLine()
{
return Edit_Line;
}

View File

@ -48,10 +48,13 @@ extern "C"{
struct line{
unsigned char *str;
unsigned char *tex_str;
int readonly;
int type;
int start_col;
int disp_len;
unsigned char tex_flag;
int tex_height, tex_width;
};
struct FMenu{
@ -78,6 +81,7 @@ extern "C"{
int Console_MoveCursor(int direction);
int Console_Input(const unsigned char *str);
int Console_Output(const unsigned char *str);
int Console_Clear_EditLine();
int Console_NewLine(int pre_line_type, int pre_line_readonly);
int Console_Backspace(void);
int Console_GetKey(void);
@ -88,6 +92,8 @@ extern "C"{
int Console_Draw_FMenu(int key, struct FMenu* menu);
char *Console_Make_Entry(const unsigned char* str);
unsigned char *Console_GetLine(void);
unsigned char* Console_GetEditLine();
void Console_Draw_TeX_Popup(unsigned char* str, int width, int height);
#ifdef __cplusplus
}

View File

@ -4,6 +4,14 @@
#include "defs.h"
#include "console.h"
#include "tex/TeX.h"
#define TEX 1
#define MAX_TEX_WIDTH 110
#define MAX_TEX_HEIGHT 50
static char tex_flag = 0;
int out_index, out_length;
char *out_str;
static int char_count, last_char;
@ -19,7 +27,20 @@ print(U *p)
void
printline(U *p)
{
#ifdef TEX
int width, height, baseline;
char* edit_line = (char*)Console_GetEditLine();
tex_flag = 1;
#endif
print_expr(p);
#ifdef TEX
TeX_sizeComplex(edit_line, &width, &height, &baseline);
if(width > MAX_TEX_WIDTH || height > MAX_TEX_HEIGHT) {
tex_flag = 0;
Console_Clear_EditLine();
print_expr(p);
}
#endif
}
void
@ -117,6 +138,10 @@ print_a_over_b(U *p)
p1 = cdr(p1);
}
//#ifdef TEX
if(tex_flag) print_str("\\frac{");
//#endif
if (n == 0)
print_char('1');
else {
@ -142,14 +167,19 @@ print_a_over_b(U *p)
}
}
if (test_flag == 0)
print_str(" / ");
else
print_str("/");
if (d > 1)
print_char('(');
//#ifdef TEX
if(tex_flag) print_str("}{");
else {
//#else
if (test_flag == 0)
print_str(" / ");
else
print_str("/");
if (d > 1)
print_char('(');
}
//#endif
flag = 0;
p1 = cdr(p);
@ -173,9 +203,15 @@ print_a_over_b(U *p)
p1 = cdr(p1);
}
//#ifdef TEX
//#else
if (d > 1)
print_char(')');
if(tex_flag) print_str("}");
//#endif
restore();
}
@ -228,6 +264,16 @@ print_denom(U *p, int d)
if (d == 1 && !isminusone(EXPO))
print_char('(');
#ifdef TEX
if (tex_flag && equalq(EXPO, -1, 2)) {
print_str("\\sqrt{");
print_expr(BASE);
print_str("}");
restore();
return;
}
#endif
if (isfraction(BASE) || car(BASE) == symbol(ADD) || car(BASE) == symbol(MULTIPLY) || car(BASE) == symbol(POWER) || lessp(BASE, zero)) {
print_char('(');
print_expr(BASE);
@ -316,6 +362,15 @@ print_factor(U *p)
return;
}
#ifdef TEX
if (tex_flag && equalq(caddr(p), 1, 2)) {
print_str("\\sqrt{");
print_expr(cadr(p));
print_str("}");
return;
}
#endif
if (isadd(cadr(p)) || caadr(p) == symbol(MULTIPLY) || caadr(p) == symbol(POWER) || isnegativenumber(cadr(p))) {
print_str("(");
print_expr(cadr(p));

41
tex/TeX.h Normal file
View File

@ -0,0 +1,41 @@
#ifndef _TEX_H
#define _TEX_H
#ifdef __cplusplus
extern "C"{
#endif
// Standard headers inclusion.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
// Casual types definition.
typedef unsigned int uint;
// Additional headers inclusion.
#include "libText.h"
#include "fxlib.h"
#include "debug.h"
// Symbols used in program.
#define TEX_FONT TXT_SYSTEM
#define TEX_MAXP 2
#define TEX_MODE TXT_XOR
// Global functions prototypes.
int TeX_isTeX (char* expr);
void TeX_sizeComplex (char *expression, int *width, int *height, int *baseline);
void TeX_sizeSimple (char *element, int *width, int *height, int *baseline);
char *TeX_getElement (char *expression);
char *TeX_getParameter (char *command);
char *TeX_extract (char *begin, char *end);
int TeX_getParamNumber (char *command);
void TeX_drawComplex (char *expression, int x, int y);
void TeX_drawSimple (char *element, int x, int baseline);
#ifdef __cplusplus
}
#endif
#endif // _TEX_H

55
tex/debug.c Normal file
View File

@ -0,0 +1,55 @@
#include "debug.h"
#ifdef DEBUG
int debug_handle;
#ifndef DEBUG_PATH
#define DEBUG_PATH "\\\\crd0\\TeX.log"
#endif
#ifndef DEBUG_FILE
#define DEBUG_FILE 10000
#endif
#ifndef DEBUG_SIZE
#define DEBUG_SIZE 100
#endif
void debug_init(void)
{
char debug_path[] = DEBUG_PATH;
unsigned short *bfile_path;
int i=0;
while(debug_path[i]) i++;
bfile_path = calloc(i+1,2);
for(i=0;debug_path[i];i++) bfile_path[i] = debug_path[i];
bfile_path[i] = 0x0;
Bfile_DeleteFile(bfile_path);
Bfile_CreateFile(bfile_path,DEBUG_FILE);
debug_handle = Bfile_OpenFile(bfile_path,_OPENMODE_WRITE);
free(bfile_path);
}
void debug(const char *format, ...)
{
char ch[DEBUG_SIZE+1];
va_list args;
va_start(args,format);
vsprintf(ch,format,args);
va_end(args);
ch[DEBUG_SIZE] = 0;
Bfile_WriteFile(debug_handle,ch,strlen(ch));
}
void debug_quit(void)
{
Bfile_CloseFile(debug_handle);
}
#endif // DEBUG

10
tex/debug.h Normal file
View File

@ -0,0 +1,10 @@
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include "fxlib.h"
#define DEBUG 0
void debug_init(void);
void debug(const char *format, ...);
void debug_quit(void);

43
tex/disp.src Normal file
View File

@ -0,0 +1,43 @@
;;
;; setPixel() function.
;; Sets the color of a pixel on the screen.
;;
.global _setPixel
_setPixel:
mov.l #127,r1
cmp/hi r1,r4
bt end
mov.l #63,r1
cmp/hi r1,r5
bt end
mov r4,r0
shll2 r5
shll2 r5
mov #-3,r1
shld r1,r4
add r4,r7
add r5,r7
mov.b @r7,r1
mov #7,r2
and r0,r2
neg r2,r2
mov.l #128,r3
shld r2,r3
tst r6,r6
bt white
black:
or r3,r1
rts
mov.b r1,@r7
white:
not r3,r3
and r3,r1
rts
mov.b r1,@r7
end:
rts
nop
.end

382
tex/libText.c Normal file
View File

@ -0,0 +1,382 @@
#include <stdio.h>
#include <stdlib.h>
#include "LibText.h"
// Thanks to Simon Lothar for this function
typedef char*(*Txt_SC)(void);
const unsigned int Txt_SC_VRAM[] = { 0xD201D002, 0x422B0009, 0x80010070, 0x0135 };
#define Txt_GetVRAM (*(Txt_SC)Txt_SC_VRAM)
char *Txt_VRAM;
unsigned int *Txt_Fonts[TXT_FONTS];
void Txt_Init(int fonts)
{
int i;
Txt_VRAM = Txt_GetVRAM();
for(i=0;i<TXT_FONTS;i++) Txt_Fonts[i] = NULL;
if(fonts & FONT_MINISD)
{
unsigned int FontMINISD[60] = {
4141870527, 3682580223, 1845419005, 3086708726, 3756900315, 2142699373, 4275830199, 4218418911,
3988773759, 3070193150, 3690838011, 1878450157, 3218833334, 4285398747, 4256693103, 37386,
3490052053, 4092635221, 1436811305, 588403370, 6094850, 1081081857, 312768220, 2992611135,
754678078, 1945958386, 2465718255, 1008762945, 581051278, 573203074, 3319574455, 1567855165,
1843292668, 3526962103, 3687996563, 2109397284, 4158356918, 2875905864, 2907135339, 2297336406,
3689788763, 2109037418, 1268071241, 823204133, 2499805191, 2550144430, 1802531378, 3982580954,
3912945306, 3666238595, 1555782802, 3808118454, 2238323432, 493116704, 2045104738, 3687167243,
2098551341, 2021112657, 882006293, 2210430975 };
Txt_Fonts[TXT_MINISD] = malloc(240);
for(i=0;i<60;i++) Txt_Fonts[TXT_MINISD][i] = FontMINISD[i];
}
if(fonts & FONT_7SEGMINI)
{
unsigned int Font7SEGMINI[60] = {
4141870527, 3682580223, 1845419005, 3086708726, 3756900315, 2142699373, 4275830199, 4218418911,
3988773759, 3070193150, 3690838011, 1878450157, 3218833334, 4285398747, 4256693103, 37386,
3490052052, 4090538069, 1436811346, 1149840042, 6094850, 2154823681, 44103390, 1227333439,
1023113534, 1945958386, 1240981487, 1008762945, 1117922190, 573203074, 3302879159, 3716125309,
1843296764, 4068044727, 3687997348, 3048921380, 4158356918, 4218419145, 3992968559, 2633929302,
3689788763, 2109037418, 1268072338, 1896946835, 3573547015, 1140953022, 1333272178, 2112813532,
4063940243, 3665976580, 3029818514, 3808116982, 2179931896, 1038384043, 2632574176, 1539355915,
2097326597, 1215806289, 882006293, 2155380735 };
Txt_Fonts[TXT_7SEGMINI] = malloc(240);
for(i=0;i<60;i++) Txt_Fonts[TXT_7SEGMINI][i] = Font7SEGMINI[i];
}
if(fonts & FONT_SYSTEM)
{
unsigned int FontSYSTEM[140] = {
4234352839, 4287390488, 4294020195, 536752524, 1677706801, 2357196998, 831520536, 3325165539,
415645692, 1662568447, 2355304703, 4052509471, 4264660067, 4291178892, 2147010097, 2415859910,
838853400, 3326082147, 415760268, 1662582769, 2355306494, 831284223, 3325135999, 4173738383,
4279813681, 4293073094, 1073505048, 3355413603, 419426700, 1663041073, 2355363782, 831291384,
3325136895, 415642111, 3810051647, 0, 69273664, 290082816, 2711383, 3567402638,
797543560, 2291718442, 582118152, 2147483665, 277090376, 545530400, 78355794, 8714504,
97, 268436448, 0, 207618594, 570455143, 1556464741, 138575313, 143167484,
1141924577, 424867973, 4168622475, 2357754417, 2009211408, 2222220008, 3318647902, 288361568,
415236492, 50888840, 2283831808, 2082406432, 2181597315, 2719027204, 1950538453, 3465314072,
3352399779, 523907204, 586041905, 2360997955, 3498573576, 2047902627, 163983244, 1677248063,
554189436, 3792733478, 1179960613, 406982788, 1058920113, 2355305686, 1904976664, 3324965987,
3896643212, 1666791377, 2410227898, 812671727, 2424578313, 415641995, 2736309802, 610491094,
2861323333, 1177652308, 1108599057, 286243080, 1108402241, 68174049, 138548104, 2826960896,
31, 1627652096, 230136, 3188766307, 520097412, 585139635, 2354970682, 1065584199,
277094400, 4173082244, 764986912, 538460728, 1076921638, 1108518441, 638616609, 469789365,
2906655590, 830996712, 3324903485, 524419075, 3807413248, 3059812352, 260277220, 1896366668,
4600219, 1074316618, 536942806, 2852139618, 845153362, 1650458872, 2291107972, 1091052048,
2216757378, 272900608, 81149959, 4294967295 };
Txt_Fonts[TXT_SYSTEM] = malloc(560);
for(i=0;i<140;i++) Txt_Fonts[TXT_SYSTEM][i] = FontSYSTEM[i];
}
if(fonts & FONT_7SEG)
{
unsigned int Font7SEG[140] = {
4234352839, 4287390488, 4294020195, 536752524, 1677706801, 2357196998, 831520536, 3325165539,
415645692, 1662568447, 2355304703, 4052509471, 4264660067, 4291178892, 2147010097, 2415859910,
838853400, 3326082147, 415760268, 1662582769, 2355306494, 831284223, 3325135999, 4173738383,
4279813681, 4293073094, 1073505048, 3355413603, 419426700, 1663041073, 2355363782, 831291384,
3325136895, 415642111, 3810051647, 0, 69273664, 290082816, 2711383, 3567402638,
797542536, 2290669866, 582117640, 1073741858, 277094532, 277094672, 78355794, 8714504,
33, 134218720, 0, 2097698, 570489955, 415752456, 1108379617, 266407932,
569918456, 3326019651, 4165198095, 4278746673, 4290908292, 570188792, 3355413630, 284951552,
134217856, 17318024, 2283831808, 2082406432, 2181597319, 3256057860, 4165204167, 4287397656,
3354496931, 536744068, 570377777, 2357065795, 4035444488, 2115012577, 147210124, 1677248063,
554189439, 3827370062, 1179960613, 406982788, 1058919985, 2355305686, 1905255192, 3326082147,
4165083020, 1666807793, 2409830654, 284705791, 2424578313, 415641999, 3810051626, 610491094,
3146536005, 1177652308, 1108599057, 286260752, 2216816705, 68174320, 2216759240, 2826960896,
31, 1627652096, 508920, 4262496227, 528490372, 569410623, 2357067902, 1065864775,
277094401, 4177280900, 569951776, 538460728, 1076921383, 1108518441, 638616609, 469789365,
2906656710, 830996984, 3326017599, 532807687, 3824190464, 4230023168, 528991220, 1896366620,
4600207, 3221800490, 536942806, 2852135586, 706741347, 4043047160, 2291112068, 1091068432,
2216757442, 272900864, 215375879, 4294967295 };
Txt_Fonts[TXT_7SEG] = malloc(560);
for(i=0;i<140;i++) Txt_Fonts[TXT_7SEG][i] = Font7SEG[i];
}
if(fonts & FONT_ARCADIUM)
{
unsigned int FontARCADIUM[100] = {
4234354686, 831520536, 3355413603, 4291179007, 3810066417, 2357196998, 1073505055, 4264660991,
415760268, 1677706801, 4293073151, 4052516856, 3326082147, 536752527, 4279814143, 2355363782,
838853400, 4294020223, 4173742076, 1663041073, 2415859911, 4287390719, 3325165539, 419426700,
2147010111, 16, 2214663328, 719550, 2815542774, 1682231281, 2357117472, 2232450,
272765204, 1334920231, 3359637892, 1073868800, 202769, 286291051, 387023911, 4229383166,
193194183, 3775914464, 4191220829, 4035478644, 1561803311, 194560049, 2349009025, 285478974,
260113425, 283678724, 1885034298, 1066171679, 1204782112, 4282790391, 3788013552, 3827361870,
780959512, 4236519422, 692687247, 2736275984, 4235679942, 967631592, 3324966013, 138031515,
4246685231, 2206461840, 2216977176, 3123808905, 416721546, 2292761924, 557720099, 3997307112,
545393540, 557353608, 31, 822345784, 797679887, 1203797024, 4035309947, 2749905361,
3290491068, 1048949528, 2684895644, 554274948, 3106152712, 808803028, 479503367, 1177421731,
3892441464, 1097646606, 2198194298, 275785001, 806524176, 147237382, 2290811210, 570548771,
3324119138, 277095176, 573573548, 2181038079 };
Txt_Fonts[TXT_ARCADIUM] = malloc(400);
for(i=0;i<100;i++) Txt_Fonts[TXT_ARCADIUM][i] = FontARCADIUM[i];
}
if(fonts & FONT_SERIF)
{
unsigned int FontSERIF[168] = {
4263010694, 536839704, 1636302817, 2249744895, 4167140888, 2147358817, 2250243974, 409044991,
3783661665, 4294467974, 411041304, 1636179967, 2249744775, 4292970008, 1644165217, 2249752574,
409044511, 4286978145, 2281693574, 409075704, 1636178047, 4263010694, 536839704, 1636302817,
2249744895, 4167140888, 2147358817, 2250243974, 409044991, 3783661665, 4294467974, 411041304,
1636179967, 2249744775, 4292970008, 1644165217, 2249752574, 409044511, 4286978145, 2281693574,
409075704, 1636178047, 0, 532610, 134251796, 1342177281, 1161712613, 343058972,
715600072, 1108383846, 614533796, 1757480960, 4226, 136347912, 272696336, 2325508768,
520, 4169269248, 12354, 3968, 0, 798736, 2216757248, 1915529882,
654860930, 136570658, 138547451, 3775402024, 2618344740, 4165025410, 117606851, 277072034,
1944093728, 2181591592, 2626299676, 2317845009, 2148282371, 201327372, 12650504, 1108353088,
2147741759, 264208, 554189256, 2182119432, 1914733162, 2802067620, 1598537617, 1172591097,
3898638856, 1593381969, 1159708485, 1192511487, 3511797008, 1105748126, 408874260, 1598365438,
545392675, 4018675842, 675517588, 1631893985, 68174111, 4050474321, 1203687781, 1423044072,
1636178014, 4178861633, 236881432, 1581318033, 1172640485, 3898636312, 1593483784, 545733445,
340870382, 3510964874, 330584405, 1430948389, 139602082, 2302806049, 3483504772, 586727944,
545393666, 67637280, 1276133636, 281154696, 0, 63, 1619066880, 385,
479308816, 1097224568, 1870344, 2618040474, 2586279937, 3367928259, 306414608, 3771044408,
613204228, 375723072, 537266209, 3254804610, 138609682, 1367675488, 2181570695, 173397,
1431306457, 2488394752, 478816412, 3650376057, 68852264, 2651353088, 3649310944, 1999296,
3158541328, 1090715651, 3025224928, 15536778, 268450629, 1430913032, 2485209216, 19172369,
2147547714, 318292488, 1082264608, 2181570690, 202391684, 281018442, 2835350527, 4294967295 };
Txt_Fonts[TXT_SERIF] = malloc(672);
for(i=0;i<168;i++) Txt_Fonts[TXT_SERIF][i] = FontSERIF[i];
}
if(fonts & FONT_SERIFITALIC)
{
unsigned int FontSERIFITALIC[168] = {
4263010694, 536839704, 1636302817, 2249744895, 4167140888, 2147358817, 2250243974, 409044991,
3783661665, 4294467974, 411041304, 1636179967, 2249744775, 4292970008, 1644165217, 2249752574,
409044511, 4286978145, 2281693574, 409075704, 1636178047, 4263010694, 536839704, 1636302817,
2249744895, 4167140888, 2147358817, 2250243974, 409044991, 3783661665, 4294467974, 411041304,
1636179967, 2249744775, 4292970008, 1644165217, 2249752574, 409044511, 4286978145, 2281693574,
409075704, 1636178047, 0, 266434, 134284470, 2415919104, 2457816057, 607737100,
715600528, 1124607283, 2454817444, 3904964608, 4226, 272695812, 136348688, 2236510880,
260, 2021785600, 12354, 1920, 0, 798720, 53673984, 957769098,
654586177, 136431489, 99098873, 4030869536, 3155731620, 4232126273, 117574595, 3493980322,
1944618000, 2182101268, 1586112270, 1159168523, 3222024198, 402653964, 25301000, 1108353088,
2147741759, 264208, 554189256, 2182119440, 2047885674, 2802197652, 1598535569, 1206428400,
3830481416, 2625180769, 2318344005, 138183655, 3510767392, 2163495054, 413025556, 1660561550,
272762913, 3280212098, 146871444, 3800638017, 69239343, 2439861346, 2317637974, 681740516,
1367746716, 949113209, 235816216, 1651536777, 622301924, 3830460456, 2625458436, 545732933,
342002638, 1363748116, 1672761738, 2863957301, 2355832930, 2441220163, 2278623428, 586736136,
1090788417, 34086977, 235413764, 297863752, 0, 63, 1619066880, 224,
2626790920, 1120707184, 935432, 2617512026, 2586279936, 3831464897, 2300822544, 3771044408,
1226359044, 751446144, 268633121, 3254804612, 281216148, 1661609008, 1090789511, 173397,
2862612584, 3562203136, 239474844, 3650379330, 136026663, 69320704, 1824788704, 999616,
3156328976, 1090715651, 3026356672, 15537300, 1610627910, 445906952, 2485209216, 19172387,
30786, 284188932, 1619135504, 1091051650, 202392464, 1124073546, 2835350527, 4294967295 };
Txt_Fonts[TXT_SERIFITALIC] = malloc(672);
for(i=0;i<168;i++) Txt_Fonts[TXT_SERIFITALIC][i] = FontSERIFITALIC[i];
}
if(fonts & FONT_SERIFBOLD)
{
unsigned int FontSERIFBOLD[168] = {
4263010694, 536839704, 1636302817, 2249744895, 4167140888, 2147358817, 2250243974, 409044991,
3783661665, 4294467974, 411041304, 1636179967, 2249744775, 4292970008, 1643903073, 2249752574,
409044511, 4286978145, 2281693574, 409075704, 1636178047, 4263010694, 536839704, 1636302817,
2249744895, 4167140888, 2147358817, 2250243974, 409044991, 3783661665, 4294467974, 411041304,
1636179967, 2249744775, 4292970008, 1644165217, 2249752574, 409044511, 4286978145, 2281693574,
409075704, 1636178047, 0, 817635, 201379254, 3623878657, 1161712613, 343629086,
391623116, 1662570039, 3019476854, 2095156224, 12678, 409043724, 409044504, 3399250592,
49983, 4240637952, 798786, 262080, 0, 798736, 3325135904, 2067724239,
931950787, 204597171, 2355304957, 3972216892, 3726173606, 4234264519, 260279783, 3015961843,
2080163376, 3272375100, 3738122142, 3476538317, 3758895107, 201327372, 12650520, 3325059265,
2147741759, 396312, 831283692, 3273179148, 2066793326, 3080638271, 4090445721, 1709595129,
3966812940, 1593415257, 1704968037, 2274912255, 3647071768, 1642885327, 475985302, 1600495454,
818089009, 3884724419, 753121180, 1640479729, 2249744799, 4058996081, 3340563439, 2096352748,
4090445022, 4187381345, 2401161020, 4264591257, 1709595125, 3975182396, 3741242124, 818396517,
2522440942, 4056356506, 867987927, 1566232375, 2356886771, 3454209073, 4024637638, 838714904,
1636179075, 101455920, 1310220678, 417471706, 536870912, 63, 1891729408, 449,
2660891696, 3278795256, 2019084, 3725340891, 2654453761, 3967730163, 2573452824, 4056524408,
1771881228, 921115712, 12590129, 3808456899, 744688690, 3549246064, 3272356039, 2147659125,
3612344539, 2624709632, 516898014, 3684463099, 203136568, 3742134272, 3989182704, 2015712,
3731080728, 1636007939, 3161572832, 15668890, 805321671, 1566179340, 3727813824, 40475699,
2147548771, 436003596, 1623395888, 3272356035, 472957324, 834666570, 2835350527, 4294967295 };
Txt_Fonts[TXT_SERIFBOLD] = malloc(672);
for(i=0;i<168;i++) Txt_Fonts[TXT_SERIFBOLD][i] = FontSERIFBOLD[i];
}
if(fonts & FONT_SERIFBOLDITALIC)
{
unsigned int FontSERIFBOLDITALIC[168] = {
4263010694, 536839704, 1636302817, 2249744895, 4167140888, 2147358817, 2250243974, 409044991,
3783661665, 4294467974, 411041304, 1636179967, 2249744775, 4292970008, 1644165217, 2249752574,
409044511, 4286978145, 2281693574, 409075704, 1636178047, 4263010694, 536839704, 1636302817,
2249744895, 4167140888, 2147358817, 2250243974, 409044991, 3783661665, 4294467974, 411041304,
1636179967, 2249744775, 4292970008, 1644165217, 2249752574, 409044511, 4286978145, 2281693574,
409075704, 1636178047, 0, 399587, 201426651, 3680501760, 2457816057, 612062540,
2864165592, 1124625715, 2454817444, 3921876992, 6339, 409043724, 409046065, 2236510880,
49982, 4186308608, 28870, 257920, 0, 798720, 3488808960, 966161867,
654719075, 2352080771, 233582833, 4039536737, 3155997926, 4234256225, 2273513443, 3630296307,
2079901208, 3273144726, 1590372126, 3476522523, 3222024198, 402653964, 25301016, 3325059265,
2147741759, 396312, 831283692, 3273179160, 2050016110, 3876482486, 4292568985, 1743565552,
3864576780, 2625214065, 3408863077, 2410728423, 3647204400, 3237370063, 480179606, 2127244958,
818354275, 3284539627, 1013036763, 4224562017, 2251342639, 2439861346, 2317770095, 481478886,
1506225308, 953375097, 2400085404, 1919972237, 899127796, 3864539241, 2633945884, 1636777317,
2524105679, 1500096284, 1672761738, 2863975271, 141781427, 4259519587, 3487766726, 838656780,
1636179041, 2198614113, 2383962892, 834735725, 805306368, 63, 1891729408, 224,
3751394320, 2196562808, 943884, 2618044630, 3127345152, 3839853505, 2368988696, 4041593660,
1771880708, 785333440, 402884145, 3808456902, 417531094, 1938765368, 1636184263, 2147657045,
2862612584, 3562203136, 240007580, 3652509250, 136027703, 2251415552, 1824921840, 2023905,
4264682264, 1636007939, 3035011520, 15545558, 1879063366, 714342412, 3727813824, 20237875,
2147515491, 418964236, 3783662616, 1636577475, 236479448, 1669333066, 2835350527, 4294967295 };
Txt_Fonts[TXT_SERIFBOLDITALIC] = malloc(672);
for(i=0;i<168;i++) Txt_Fonts[TXT_SERIFBOLDITALIC][i] = FontSERIFBOLDITALIC[i];
}
if(fonts & FONT_RUNES)
{
unsigned int FontRUNES[224] = {
0, 84, 3668859510, 1360793681, 1378110090, 134754467, 1166678048, 3187432,
780802108, 2252313636, 2231631985, 341669343, 469763068, 3102378504, 6365763, 67899392,
1629733382, 135791074, 1199836176, 805338386, 608735612, 7460030, 4200012800, 551727082,
2382953734, 3436724192, 4279259475, 1699383816, 128031, 4066443008, 33030128, 1627324472,
2333750178, 939580415, 4293889544, 14318841, 4019062784, 3665623531, 2382889178, 2096752778,
134273612, 405309960, 798375, 2319344640, 541101794, 67633184, 1095525636, 134217732,
1204879360, 2130443, 3431533568, 17907976, 2315784273, 276990080, 7153162, 674388736,
33295, 3892838400, 2109408, 2181038112, 3802202628, 134225984, 2164952584, 8303,
3783393280, 8589292, 134217760, 3823174148, 134225984, 2165280264, 12698567, 3474731008,
410118087, 2265317376, 1103618047, 2147614715, 3816947712, 41519, 3901358096, 1901101322,
2382888960, 2742021514, 1077744, 2165280264, 8462887, 3766616064, 143798216, 134217968,
541238146, 30849, 177080320, 1053684, 1225785344, 1091036228, 2164260880, 1901101342,
16837, 1107562240, 8462951, 3783393280, 143863756, 134217968, 541320066, 30849,
260966400, 1061876, 3373268992, 1099425348, 2164260880, 1911587102, 16839, 3255045888,
238, 0, 1086407174, 168820800, 3242394892, 268451969, 33950242, 17243481,
896647424, 2310186056, 2434924713, 2456258576, 536871442, 1124471362, 37346, 1200169472,
4227330, 67633152, 1082196484, 268443712, 2164458769, 4243778, 67637248, 2310186696,
2434924576, 1115914884, 134255042, 76419104, 5284290, 118100992, 2310186058, 2602696768,
3242395146, 301998145, 58786824, 2155173, 1107560448, 2172814473, 304349184, 2434942220,
268436052, 2840900932, 11096513, 33818624, 4044498890, 2504130592, 1082197781, 704647458,
3800109594, 8458819, 169582592, 2174788169, 304087084, 1218955812, 1744855075, 3825733378,
5284295, 3656891904, 1352746969, 4156424272, 2705608823, 3187691681, 1146118334, 5284399,
4193762816, 1352804411, 4156424272, 2720542839, 3187691682, 674259134, 5284391, 3416202240,
2705606807, 1043857488, 2720286879, 469782690, 608735516, 798378, 2318035968, 3978994346,
1809842200, 1364538864, 3112, 2726963296, 1853586, 3391643648, 68702500, 2457337856,
1885422640, 536899860, 2683457820, 33426581, 1217005568, 547579213, 2315780217, 207178821,
67109299, 2452132376, 32, 2315790336, 131, 2334130176, 2146954, 939524096,
545392672, 96, 3255312384, 255045, 67108864, 21416081, 1040187393, 1116246300 };
Txt_Fonts[TXT_RUNES] = malloc(896);
for(i=0;i<224;i++) Txt_Fonts[TXT_RUNES][i] = FontRUNES[i];
}
if(fonts & FONT_DOS)
{
unsigned int FontDOS[280] = {
4278586392, 811647363, 4294711344, 1623294726, 268431456, 3246589452, 406847425, 2198211608,
811663359, 101455920, 1623294975, 4229443680, 3246589455, 4293943489, 2198211608, 1073725827,
101455920, 1627389702, 202911840, 3246653436, 405823681, 2198212607, 4032872835, 101455935,
4290872070, 202911840, 4294903308, 405823681, 2214591512, 811647363, 101711856, 1623294726,
202915839, 3246589452, 405823743, 4278586392, 811647363, 4294711344, 1623294726, 268431456,
3246589452, 406847425, 2198211608, 811663359, 101455920, 1623294975, 4229443680, 3246589455,
4293943489, 2198211608, 1073725827, 101455920, 1627389702, 202911840, 3246653436, 405823681,
2198212607, 4032872835, 101455935, 4290872070, 202911840, 4294903308, 405823681, 2214591512,
811647363, 101711856, 1623294726, 202915839, 3246589452, 405823743, 0, 0,
6415303, 2248939520, 1623616729, 2449473536, 54, 1845343078, 3755685392, 4217280259,
2783673376, 102523270, 409046552, 59611932, 2008757868, 3469085720, 1610612736, 6241,
2198211608, 808464576, 3233907462, 202924416, 13881, 4242759680, 12387, 4158850560,
0, 1548, 408944640, 4194048, 0, 0, 99072, 400497,
3340513280, 2106531453, 2096227270, 4167157635, 101455920, 1677187265, 2198614211, 209706851,
101511216, 1626455564, 955477215, 3271953471, 4131133503, 50827035, 3889754208, 4254015036,
1874846470, 204522246, 202931599, 506976497, 3821468150, 1014554499, 101653472, 396288,
49536, 6192, 774, 402656304, 3272346636, 202113024, 264241278, 12,
202116108, 818088991, 1673926752, 3246392844, 2106531453, 2062937792, 4193664120, 4060071823,
507497689, 3011300763, 914329395, 3280143884, 408526584, 3650827884, 3652414963, 4214631710,
1013499295, 4293712052, 2029101830, 504312771, 2198240376, 3651061647, 507508977, 3821505776,
3246589452, 405823969, 3783460364, 456551631, 968058585, 3821456601, 4092641667, 101455921,
1744772991, 4294304711, 2401123452, 4261404575, 507279583, 1674022686, 1014559166, 4241333047,
3424137313, 3791010936, 4058767096, 813681881, 3011310003, 1719459683, 3353473264, 2029108862,
4251500931, 101455995, 507279601, 3821506331, 3967349219, 3348045687, 3341935559, 2405350783,
4223059853, 3018032927, 919047579, 913100556, 405823983, 4175529496, 1636179071, 3474468960,
3246589452, 503317255, 117901063, 100724832, 3246589452, 405922055, 459472896, 0,
0, 127, 1623244992, 0, 15, 54447515, 868092952, 1046924699,
913276928, 16457228, 405913116, 406056153, 3009858796, 4017, 4290872091, 3787902104,
2019606915, 251658240, 4013320129, 3007111361, 2204593369, 3009924096, 198144, 942694880,
768, 471545447, 3090178253, 3016199577, 4080545888, 3246589452, 410517504, 499117015,
2942185472, 7235277, 2604035264, 64286, 1014559166, 1766, 1826209377, 3758096398,
4083600632, 821035008, 1853279619, 102629376, 16456451, 2175909392, 1623712518, 202913336,
6579, 1724750643, 2952790115, 3348045366, 3338665985, 2401156474, 4290117632, 104253198,
476941312, 1634787, 2114728896, 32716, 818089087, 3280738352, 3246490374, 119025760,
3246589452, 405913793, 2198013464, 811827200, 30648, 63, 4294967295, 4294967295 };
Txt_Fonts[TXT_DOS] = malloc(1120);
for(i=0;i<280;i++) Txt_Fonts[TXT_DOS][i] = FontDOS[i];
}
}
void Txt_Pixel(int x, int y, int v)
{
if(x&~127 || y&~63) return;
if(v) *(Txt_VRAM+(y<<4)+(x>>3)) |= (128>>(x&7));
else *(Txt_VRAM+(y<<4)+(x>>3)) &= ~(128>>(x&7));
}
void Txt_Point(int x, int y, int v, int m)
{
switch(m)
{
case TXT_OR: if(v) Txt_Pixel(x,y,1); break;
case TXT_ON: Txt_Pixel(x,y,v); break;
case TXT_AND: if(v) Txt_Pixel(x,y,0); break;
case TXT_REV: Txt_Pixel(x,y,!v); break;
case TXT_XOR: if(v) Txt_Pixel(x,y,!Txt_Get(x,y)); break;
}
}
int Txt_Get(int x, int y)
{
return (*(Txt_VRAM+(y<<4)+(x>>3)) >> (~x&7))&1;
}
void Txt_Char(char c, int x, int y, int f, int w, int h, int m)
{
unsigned int *font = Txt_Fonts[f];
unsigned char a,b,v;
int offbyte = (c*w*h)>>5;
int offbit = (c*w*h)&31;
if(!font) return;
for(b=0;b<h;b++)
{
for(a=0;a<w;a++)
{
v = (font[offbyte]&(1<<(31-offbit)))!=0;
Txt_Point(x+a,y+b,v,m);
if(offbit++==31) offbyte++, offbit=0;
}
}
}
void Txt_Text(char *s, int x, int y, int f, int m)
{
int w = Txt_Width(f);
int h = Txt_Height(f);
int i;
while(*s)
{
Txt_Char(*(s++),x,y,f,w,h,m);
x += w+1;
if(*s) for(i=0;i<h;i++) Txt_Point(x-1,y+i,0,m);
}
}
int Txt_Width(int f)
{
const unsigned int w[TXT_FONTS] = { 3, 3, 5, 5, 5, 6, 6, 6, 6, 7, 7 };
return w[f];
}
int Txt_Height(int f)
{
const unsigned int h[TXT_FONTS] = { 5, 5, 7, 7, 5, 7, 7, 7, 7, 8, 10 };
return h[f];
}
void Txt_Quit(void)
{
int i;
for(i=0;i<TXT_FONTS;i++) if(Txt_Fonts[i]) free(Txt_Fonts[i]);
}

47
tex/libText.h Normal file
View File

@ -0,0 +1,47 @@
#ifndef _LIBTEXT_H
#define _LIBTEXT_H
#define TXT_FONTS 11
void Txt_Init (int);
void Txt_Pixel (int,int,int);
void Txt_Point (int,int,int,int);
int Txt_Get (int,int);
void Txt_Char (char,int,int,int,int,int,int);
void Txt_Text (char *,int,int,int,int);
int Txt_Width (int);
int Txt_Height (int);
void Txt_Quit (void);
#define TXT_OR 0x01
#define TXT_ON 0x02
#define TXT_AND 0x04
#define TXT_REV 0x08
#define TXT_XOR 0x10
#define TXT_MINISD 0x00
#define TXT_7SEGMINI 0x01
#define TXT_SYSTEM 0x02
#define TXT_7SEG 0x03
#define TXT_ARCADIUM 0x04
#define TXT_SERIF 0x05
#define TXT_SERIFITALIC 0x06
#define TXT_SERIFBOLD 0x07
#define TXT_SERIFBOLDITALIC 0x08
#define TXT_RUNES 0x09
#define TXT_DOS 0x0A
#define FONT_MINISD 0x00000001
#define FONT_7SEGMINI 0x00000002
#define FONT_SYSTEM 0x00000004
#define FONT_7SEG 0x00000008
#define FONT_ARCADIUM 0x00000010
#define FONT_SERIF 0x00000020
#define FONT_SERIFITALIC 0x00000040
#define FONT_SERIFBOLD 0x00000080
#define FONT_SERIFBOLDITALIC 0x00000100
#define FONT_RUNES 0x00000200
#define FONT_DOS 0x00000400
#define FONT_ALL 0xFFFFFFFF
#endif // _LIBTEXT_H

369
tex/math.c Normal file
View File

@ -0,0 +1,369 @@
#include "TeX.h"
int TeX_isTeX(char* expr)
{
while(*expr)
{
if(*expr == '\\')
{
expr++;
if(!strncmp(expr,"frac",4)) return 1;
else if(!strncmp(expr,"sum", 3)) return 1;
else if(!strncmp(expr,"sqrt",4)) return 1;
else if(!strncmp(expr,"vec", 3)) return 1;
}
expr++;
}
return 0;
}
void TeX_sizeComplex(char *expr, int *width, int *height, int *line)
{
/*
** This functions returns the size in pixels of any complex expression.
** Calls TeX_sizeSimple() and can be called by it.
** Does not handle maximum call level. Therefore, the call stack is supposed unlimited. Any call to TeX_sizeComplex()
** needs at least one level of subsequent calls to TeX_sizeSimple().
*/
int w=0, h=0, l=0; // These variables will contain the final properties of the expression.
int tw, th, tl; // These variables store temporary data needed for comparison between elements.
char *next; // This pointer will parse the expression with expr.
char *element; // This pointer will contain dynamically-allocated temporary data -- the text of an element.
while(*expr)
{
// Getting copied data of the next element in the pointer element.
next = TeX_getElement(expr);
element = TeX_extract(expr,next);
// Getting the properties of the found element and adapting existant properties for the expression.
TeX_sizeSimple(element,&tw,&th,&tl);
w += tw+1;
if(th>h) h=th;
if(tl>l) l=tl;
// Freeing the allocated memory and preparing the next iteration.
free(element);
expr = next;
}
// A pixel of spacing was added for each element, but the last one didn't need one.
w -= 1;
if(width) *width = w;
if(height) *height = h;
if(line) *line = l;
}
void TeX_sizeSimple(char *element, int *width, int *height, int *line)
{
/*
** This function returns the size of any simple TeX element, based on its parameters. Detects if the parameter is plain
** text, command or any complex expression.
** Any call to TeX_sizeSimple() needs at least one level of subsequent calls to TeX_sizeComplex() if the element is a
** command that has at least one parameter.
** Otherwise, TeX_sizeSimple() will return a fixed size without calling any subroutine.
*/
int w=0, h=0, l=0; // These variables will contain the properties of the element.
int *tw, *th, *tl; // These variables store temporary data needed for comparison between parameters.
char *name; // This pointer will save the value of element to know which command was used.
char *next; // This pointer will parse the element to find the parameters.
char *parameter; // This pointer will contain dynamically-allocated temporary data -- a parameter.
int param; // Contains the number of parameters the command use. Not used if element is plain text.
int i, x; // An incremental loop counter, and just a stupid variable.
// Testing if the element is only plain text.
if(*element != '\\')
{
if(width) *width = (Txt_Width(TEX_FONT)+1)*strlen(element)-1;
if(height) *height = Txt_Height(TEX_FONT);
if(line) *line = Txt_Height(TEX_FONT)>>1;
return;
}
// Otherwise, the element is obviously a command.
name = element+1;
param = TeX_getParamNumber(element+1);
while(*element != '{') element++;
// Allocating memory to store the properties of parameters.
tw = calloc(TEX_MAXP,4);
th = calloc(TEX_MAXP,4);
tl = calloc(TEX_MAXP,4);
// Processing each parameter.
for(i=0;i<param;i++)
{
// Getting the next parameter of the detected command.
next = TeX_getParameter(element);
parameter = TeX_extract(element+1,next);
// Getting the size of the parameter.
TeX_sizeComplex(parameter,tw+i,th+i,tl+i);
// Freeing the temporary data and preparing the next iteration.
free(parameter);
element = next+1;
}
// Debugging data.
// debug("\n** data for simple expression \"%s\":\n",name-1);
// for(i=0;i<param;i++) debug("** tw[%d]=%d, th[%d]=%d, tl[%d]=%d\n",i,tw[i],i,th[i],i,tl[i]);
// Determining the properties of the command using the properties of the parameters.
if(!strncmp(name,"frac",4)) w=(tw[0]>tw[1]?tw[0]:tw[1])+2, h=th[0]+th[1]+3, l=th[0]+1;
else if(!strncmp(name,"sum", 3)) x=(tw[0]>tw[1]?tw[0]:tw[1]), w=(x>8?x:8), h=th[0]+th[1]+11, l=th[0]+4;
else if(!strncmp(name,"sqrt",4)) w=tw[0]+6, h=th[0]+3, l=tl[0]+2;
else if(!strncmp(name,"vec", 3)) w=tw[0], h=th[0]+4, l=tl[0]+4;
else w=-1, h=-1, l=-1;
if(width) *width = w;
if(height) *height = h;
if(line) *line = l;
// Freeing the allocated data.
free(tw);
free(th);
free(tl);
}
char *TeX_getElement(char *expr)
{
/*
** This function returns a pointer to the end of the first element pointed to by expr. If *expr is '\\', the element is
** considered as a command and TeX_getElement() returns a pointer to the character just after the '}' closing the command.
** In any other cases, the element is supposed to be plain text and TeX_getElement() returns a pointer to the first '\\'
** opening a command.
*/
char *next = expr;
// Looking for any '\\' as first character.
if(*expr=='\\')
{
// Getting the number of parameters for the detected command.
const int param = TeX_getParamNumber(expr+1);
int c,i;
// Determining the end of each parameter based on sublevel elements.
for(i=0,c=0;i<param;i++)
{
while(*next)
{
if(*next=='{') c++;
if(*next=='}') c--;
if(*next=='}' && !c) break;
next++;
}
next++;
}
}
// If element is plain text, the next element is the first command found.
else while(*next!='\\' && *next) next++;
return next;
}
char *TeX_getParameter(char *com)
{
/*
** This function returns a pointer to the end of the first parameter foud at com. It follows a simple parameter : the
** parameters begins with the first '{' and ends at the '}' which is at level 0, to handle subcommands in parameters.
*/
char *end; // Will be returned. Contains the address of the closing '}'.
int c=0;
// Positioning com on the first '{' (spaces handling).
while(*com != '{') com++;
end = com;
while(*end)
{
if(*end=='{') c++;
if(*end=='}') c--;
if(*end=='}' && !c) break;
end++;
}
return end;
}
char *TeX_extract(char *begin, char *end)
{
/*
** This function returns a pointer to a dynamically-allocated memory block the contains the copied data found between the
** pointers got as arguments.
** Returns NULL if any error occur.
*/
char *data; // Will be allocated.
int length = end-begin; // Length of data to be copied.
int i; // Incremental loop counter.
// Allocating data to store a copy of the memory block.
data = calloc(length+1,1);
if(!data) return NULL;
// Copying the memory block and returning the resulting pointer.
for(i=0;i<length;i++) *(data+i) = *(begin+i);
*(data+length) = 0;
return data;
}
int TeX_getParamNumber(char *expr)
{
/*
** This function returns the number of parameters used by a defined command given as only parameter.
** Returns 0 if the command is unknown.
*/
// Constant 2-parameters commands.
if(!strncmp(expr,"frac",4)) return 2;
if(!strncmp(expr,"sum", 3)) return 2;
// Constant 1-parameter commands.
if(!strncmp(expr,"sqrt",4)) return 1;
if(!strncmp(expr,"vec", 3)) return 1;
// Other commands that don't use any parameter.
return 0;
}
void TeX_drawComplex(char *expr, int x, int y)
{
/*
** This function draws the complex expression expr at point (x;y) on the screen. The is the mainly used function of the
** program.
*/
int w; // These variable will contain the width of the element being drawn.
int baseline; // This integer will contain the baseline of the whole expression.
char *next; // This pointer will parse the expression with expr.
char *element; // This pointer will contain dynamically-allocated temporary data -- the text of an element.
TeX_sizeComplex(expr,NULL,NULL,&baseline);
while(*expr)
{
// Getting copied data of the next element in the pointer element.
next = TeX_getElement(expr);
element = TeX_extract(expr,next);
// Getting the properties of the found element and drawing it.
TeX_sizeSimple(element,&w,NULL,NULL);
TeX_drawSimple(element,x,baseline+y);
// Freeing the allocated memory and preparing the next iteration.
free(element);
expr = next;
x += w+1;
}
// A pixel of spacing was added for each element, but the last one didn't need one.
w -= 1;
}
void TeX_drawSimple(char *element, int x, int l)
{
/*
** This function draw the simple element at the given position on the screen, defined by the baseline.
*/
#define setPixel(x,y,v) setPixel(x,y,v,Txt_VRAM)
extern char *Txt_VRAM; // Needed for using setPixel().
char *name = element+1; // Saving the element address before changing.
char *next; // This pointer will parse the element to find the parameters.
char **parameters; // This pointer will contain the parameters.
int *tw, *th, *tl; // These variables store temporary data needed for comparison between parameters.
int w,h,b; // Contain the properties of the element.
int param; // Contains the number of parameters of the detected command.
int i,j; // Incremental loop counters.
TeX_sizeSimple(element,&w,&h,&b);
debug("Baseline of \"%s\" is %d.\n",element,b);
// Cheking if the element is plain text.
if(*element != '\\')
{
Txt_Text(element,x,l-b,TEX_FONT,TEX_MODE);
return;
}
// Otherwise, the element is obviously a command.
name = element+1;
param = TeX_getParamNumber(element+1);
while(*element != '{') element++;
// Allocating memory to store the properties of parameters.
tw = calloc(TEX_MAXP,4);
th = calloc(TEX_MAXP,4);
tl = calloc(TEX_MAXP,4);
parameters = calloc(TEX_MAXP,sizeof(char *));
// Processing each parameter.
for(i=0;i<param;i++)
{
// Getting the next parameter of the detected command.
next = TeX_getParameter(element);
parameters[i] = TeX_extract(element+1,next);
// Getting the size of the parameter.
TeX_sizeComplex(parameters[i],tw+i,th+i,tl+i);
// Preparing the next iteration.
element = next+1;
}
// Drawing the element depending on the detected command.
if(!strncmp(name,"frac",4))
{
for(j=0;j<w;j++) setPixel(x+j,l,1);
TeX_drawComplex(parameters[0],x+(w>>1)-(tw[0]>>1),l-th[0]-1);
TeX_drawComplex(parameters[1],x+(w>>1)-(tw[1]>>1),l+2);
}
else if(!strncmp(name,"sum",3))
{
for(j=0;j<8;j++) setPixel(x+(w>>1)+j-4,l-4,1), setPixel(x+(w>>1)+j-4,l+4,1);
for(j=1;j<4;j++) setPixel(x+(w>>1)-j,l-j,1), setPixel(x+(w>>1)-j,l+j,1);
setPixel(x+(w>>1),l,1);
setPixel(x+(w>>1)+3,l-3,1);
setPixel(x+(w>>1)+3,l+3,1);
TeX_drawComplex(parameters[0],x+(w>>1)-(tw[0]>>1),l+6);
TeX_drawComplex(parameters[1],x+(w>>1)-(tw[1]>>1),l-5-th[1]);
}
else if(!strncmp(name,"sqrt",4))
{
for(j=0;j<h;j++) setPixel(x+2,l-tl[0]-2+j,1);
setPixel(x+1,l-tl[0]+h-4,1);
setPixel(x,l-tl[0]+h-5,1);
for(j=2;j<w;j++) setPixel(x+j,l-tl[0]-2,1);
setPixel(x+w-1,l-tl[0]-1,1);
setPixel(x+w-1,l-tl[0],1);
TeX_drawComplex(parameters[0],x+4,l-tl[0]);
}
else if(!strncmp(name,"vec",3))
{
for(j=0;j<w;j++) setPixel(x+j,l-tl[0]-3,1); j-=2;
setPixel(x+j,l-tl[0]-4,1);
setPixel(x+j,l-tl[0]-2,1);
TeX_drawComplex(parameters[0],x,l-tl[0]);
}
else setPixel(x,l-b,1);
// Finally freeing the allocated data.
free(tw);
free(th);
free(tl);
for(i=0;i<param;i++) free(parameters[i]);
free(parameters);
}