| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
| 7.1 mglParse class | ||
| 7.2 mglFormula class | ||
| 7.3 mglFont class | ||
| 7.4 mglColor class | ||
| 7.5 mglPoint class | ||
| 7.6 mglVar class | ||
| 7.7 mglCommand class | ||
| 7.8 mglArg class |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Class for parsing and executing MGL script. This class is defined in #include <mgl/mgl_parse.h>.
Class mglParse is the interpreter for MGL scripts (see section MGL language). The main function of mglParse class is Parse(). Exactly this function parses and executes the script string-by-string. Also there are two subservient functions for the finding and creation of a variable. These functions can be useful for displaying values of variables (arrays) in some external program (in window, for example). The variable DataList contains full list of variables in script. Flag AllowSetSize allows one to prevent changing the size of the picture inside the script (forbids the MGL command setsize).
Note an important feature – if user defines function func in variable then it will be called before the destroying of this variable (see section mglVar class).
mglParse (C++, Python): mglParse (bool setsize=false)HMPR mgl_create_parser ()Constructor initializes all values with zero and set AllowSetSize value.
mglParse (C++, Python): ~mglParse ()void mgl_delete_parser (HMPR p)Destructor delete parser
mglParse (C++, Python): int Parse (mglGraph *gr, const char *str, long pos=0)mglParse (C++): int Parse (mglGraph *gr, const wchar_t *str, long pos=0)int mgl_parse (HMGL gr, HMPR p, const char *str, int pos)int mgl_parsew (HMGL gr, HMPR p, const wchar_t *str, int pos)Main function in the class. It parses the string str and executes it by using gr as a graphics plotter. Returns the value depending on an error presence in the string str: 0 – no error, 1 – wrong command argument(s), 2 – unknown command, 3 – string is too long. Optional argument pos allows to save the string position in the document (or file) for using for|next command.
mglParse (C++): int Export (wchar_t cpp_out[1024], mglGraph *gr, const wchar_t *str)Function parses the string str, executes it by using gr as a graphics plotter and exports it to C++ code. Returns the value depending on an error presence in the string str: 0 – no error, 1 – wrong command argument(s), 2 – unknown command, 3 – string is too long. Output C++ text will be placed in out variable. If string str have options (defined after ’;’ symbol) then the corresponding C++ texts are placed in variables op1, op2.
mglParse (C++): void Execute (mglGraph *gr, FILE *fp, bool print=false)Function parse and execute line-by-line MGL script in file fp. If print=true then all warnings and information will be printed in stdout. Also this function support the for|next MGL commands.
mglParse (C++): void Execute (mglGraph *gr, int num, const wchar_t **text, void (* error )(int line, int kind)=NULL)Function parse and execute line-by-line MGL script in array text. If error is not NULL then this function will be called for all warnings, information and other messages. Also this function support the for|next MGL commands.
mglParse (C++, Python): void Execute (mglGraph *gr, const char *text, void (* error )(int line, int kind)=NULL)mglParse (C++): void Execute (mglGraph *gr, const wchar_t *text, void (* error )(int line, int kind)=NULL)void mgl_parse_text (HMGL gr, HMPR p, const char *text)void mgl_parsew_text (HMGL gr, HMPR p, const wchar_t *text)Function parse and execute line-by-line MGL script in string text. Lines are separated by ‘\n’ symbol as usual. If error is not NULL then this function will be called for all warnings, information and other messages. Also this function support the for|next MGL commands.
mglParse (C++, Python): bool AddParam (int n, const char *str, bool isstr=true)mglParse (C++): bool AddParam (int n, const wchar_t *str, bool isstr=true)void mgl_add_param (HMPR p, int id, const char *val)void mgl_add_paramw (HMPR p, int id, const wchar_t *val)Function set the value of n-th parameter as string str (n=0, 1 ... 9). It return true for success.
mglParse (C++, Python): mglVar * FindVar (const char *name)mglParse (C++): mglVar * FindVar (const wchar_t *name)const HMDT mgl_find_var (HMPR p, const char *name)Function returns the pointer to variable with name name or zero if variable is absent. Use this function to put external data array to the script or get the data from the script.
mglParse (C++, Python): mglVar * AddVar (const char *name)mglParse (C++): mglVar * AddVar (const wchar_t *name)const HMDT mgl_add_var (HMPR p, const char *name)Function returns the pointer to variable with name name. If variable is absent then new variable is created with name name. Use this function to put external data array to the script or get the data from the script.
mglParse (C++): void DeleteVar (mglVar *v)mglParse (C++): void DeleteVar (const char *name)mglParse (C++): void DeleteVar (const wchar_t *name)Function delete the variable specified by its name or by its pointer.
mglParse (C++, Python): inline void RestoreOnce ()void mgl_restore_once (HMPR p)Restore Once flag.
mglParse (Python): void AllowSetSize (bool a)void mgl_parser_allow_setsize (HMPR p, int a)Allow to parse ’setsize’ command or not.
mglParse (C++): void AddCommand (mglCommand *cmd, int num=0)Add num commands cmd to the defined MGL commands list. Parameter cmd is array of mglCommand structures. If parameter num=0 then it will be determined automatically. At this, array cmd must have last element with name=L""
mglVar * DataListList of variables defined in script.
bool AllowSetSizeFlag which allows/forbids the command setsize in scripts.
bool StopFlag which interrupt script execution.
mglCommand * CmdTable (array) of recognizable MGL commands (can be changed by user). Items in the table MUST be sorted by name field !!! Last items must have empty name (i.e. L"").
wchar_t * op1These strings contain command options and should be placed before the command. These variables are used for MGL->C++ (or other language) conversion.
wchar_t * op2These strings contain command options and should be placed after the command. These variables are used for MGL->C++ (or other language) conversion.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Class for evaluating of formula specified by the string. This class is defined in #include <mgl/mgl_eval.h>.
It is the fast variant of formula evaluation. At creation it will be recognized and compiled to tree-like internal code. At evaluation stage only fast calculations are performed. There is no difference between lower or upper case in formulas. If argument value lie outside the range of function definition then function returns NaN. See section Textual formulas.
mglFormula (const char *str)Parses the formula str and creates formula-tree. Constructor recursively parses the formula and creates a tree-like structure containing functions and operators for fast further evaluating by Calc() or CalcD() functions.
float Calc (float x, float y=0, float z=0, float u=0)Evaluates the formula for 'x','r'=x, 'y','n'=y, 'z','t'=z, 'a','u'=u. Error code (if one) can be obtained from function GetError().
float Calc (float x, float y, float z, float u, float v, float w)Evaluates the formula for 'x'=x, 'y'=y, 'z'=z, 'u'=u, 'v'=v, 'w'=w. Error code (if one) can be obtained from function GetError().
float Calc (float var['z'-'a'+1])Evaluates the formula for variables in array var[’z’-’a’]. Error code (if one) can be obtained from function GetError().
float CalcD (float var['z'-'a'+1], char diff)Evaluates the formula derivation respect to diff for variables in array var[’z’-’a’]. Error code (if one) can be obtained from function GetError().
int GetError ()Returns error code: 0 means no error; ERR_LOG means error in logarithm or power functions; ERR_ARC means error in inverse functions (like asin); ERR_SQRT means error in sqrt function.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Class for working with font: load, get metrics, parse and draw strings. This class is defined in #include <mgl/mgl_font.h>.
The class is based on loading and drawing of vector Hershey font. There are two styles of specifying of the font type and aligning: by integer parameters or by string.
The string can be any combination of characters: ‘rbiLCRwou’. The font types are: ‘r’ – roman font, ‘i’ – italic style, ‘b’ – bold style. By default roman font (that is ‘’ or ‘r’) is used. The align types are: ‘L’ – align left (default), ‘C’ – align center, ‘R’ – align right. Additional font effects are: ‘w’ – wire, ‘o’ – over-lined, ‘u’ – underlined. Parsing of the string to special (TeX-like) commands will be done if variable parse is true (it’s default). See also see section Font styles.
The over way of font and alignment setting is the using of the integer constant. Integer font Id can be one of predefined constants: MGL_FONT_ITAL, MGL_FONT_BOLD, MGL_FONT_BOLD_ITAL = MGL_FONT_ITAL+MGL_FONT_BOLD. Default font is MGL_FONT_ROMAN. Also there are flags MGL_FONT_ULINE, MGL_FONT_OLINE, MGL_FONT_WIRE for additional font effects. Align parameter controls the text alignment: 0 – align left, 1 – align center, 2 – align right.
| 7.3.1 Format of font files |
mglFont (const char *name=MGL_DEF_FONT_NAME, const char *path=NULL)Initialize the font and load data from file name (default name is "STIX" for Linux and MacOS) or if name=NULL limited data from memory (default for Windows).
bool Load (const char * base, const char *path=NULL)Load font from file path/base into the memory. The font may contain 4 files: base.vfm, base_b.vfm, base_i.vfm, base_bi.vfm. Appendix contain detailed description of font format.
void Restore ()Restore default font.
void (mglFont * fnt)Copy data from other font instance.
void Clear ()Clear memory by deleting the loaded font.
inline unsigned GetNumGlyph ()Return the number of glyphs in the font.
inline bool Ready ()Return true if font is loaded and ready for use.
float Height (int font)Gets height of text for font specified by integer constant.
float Puts (const char *str, int font=0, int align=0)Prints 8-bit text string for font specified by integer constant.
float Width (const char *str, int font=0)Gets width of 8-bit text string for font specified by integer constant.
float Puts (const wchar_t *str, int font=0, int align=0)Prints Unicode text string for font specified by integer constant.
float Width (const wchar_t *str, int font=0)Gets width of Unicode text string for font specified by integer constant.
float Height (const char *how)Gets height of text for font specified by string.
float Puts (const char *str, const char *how)Prints 8-bit text string for font specified by string.
float Width (const char *str, const char *how)Gets width of 8-bit text string for font specified by string.
float Puts (const wchar_t *str, const char *how)Prints Unicode text string for font specified by string.
float Width (const wchar_t *str, const char *how)Gets width of Unicode text string for font specified by string.
mglGraph * grInstance of mglGraph class which is used for character drawing.
bool parseFlag for switching on/off the parsing of TeX commands. Default value is true.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Starting from v.1.6 the MathGL library uses new font files. The font is defined in 4 files with suffixes ‘*.vfm’, ‘*_b.vfm’, ‘*_i.vfm’, ‘*_bi.vfm’. These files are text files containing the data for roman font, bold font, italic font and bold italic font. The files (or some symbols in the files) for bold, italic or bold italic fonts can be absent. In this case the roman glyph will be used for them. By analogy, if the bold italic font is absent but the bold font is present then bold glyph will be used for bold italic. You may create these font files by yourself from *.ttf, *.otf files with the help of program font_tools. This program can be found at MathGL home site.
The format of font files (*.vfm – vector font for MathGL) is the following.
Each font file can be compressed by gzip.
Note: the closing contour line is done automatically (so the last segment may be absent). For starting new contour use a point with coordinates {0x3fff, 0x3fff}.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Structure for working with colors. This structure is defined in #include <mgl/mgl.h>.
There are two ways to set the color in MathGL. First one is using of float values of red, green and blue channels for precise color definition. The second way is the using of character id. There are a set of characters specifying frequently used colors. Normally capital letter gives more dark color than lowercase one. See section Line styles.
float r, g, bReg, green and blue component of color.
mglColor (float R, float G, float B)Constructor sets the color by float values of Red, Green and Blue channels.
mglColor (char c='k')Constructor sets the color from character id. The black color is used by default.
void Set (float R, float G, float B)Sets color from values of Red, Green and Blue channels. This values should be in interval [0,1].
void Set (mglColor c, float bright=1)Sets color as “lighted” version of color c.
void Set (char p)Sets color from symbolic id.
bool Valid ()Checks correctness of the color.
float Norm ()Gets maximal of spectral component.
bool operator== (const mglColor &c)Compare with another color
const mglColor &a, const mglColor &b)Adds colors by its RGB values.
const mglColor &a, const mglColor &b)Subtracts colors by its RGB values.
const mglColor &a, float b)Multiplies color by number.
float a, const mglColor &b)Multiplies color by number.
const mglColor &a, float b)Divide color by number.
const mglColor &a)Return inverted color.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Structure describes point in space. This structure is defined in #include <mgl/mgl.h>
float x, y, zPoint coordinates. By default all values are zero.
const mglPoint &a, const mglPoint &b)Point of summation (summation of vectors).
const mglPoint &a, const mglPoint &b)Point of difference (difference of vectors).
float a, const mglPoint &b)Multiplies (scale) points by number.
const mglPoint &a, float b)Multiplies (scale) points by number.
const mglPoint &a, float b)Multiplies (scale) points by number 1/b.
const mglPoint &a, const mglPoint &b)Scalar product of vectors.
const mglPoint &a, const mglPoint &b)Cross-product of vectors.
const mglPoint &a, const mglPoint &b)The part of a which is perpendicular to vector b.
const mglPoint &a, const mglPoint &b)The part of a which is parallel to vector b.
const mglPoint &a)Return vector perpendicular to vector a.
const mglPoint &a)Return the norm |a|^2 of vector a.
const mglPoint &a, const mglPoint &b)Return true if points are the same.
const mglPoint &a, const mglPoint &b)Return true if points are different.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Structure describes variable of type mglData and its name in MGL script. This structure is used by mglParse and is defined in #include <mgl/mgl_parse.h>.
mglData dData itself
wchar_t s[256]Data name
void * oPointer to external object for function func.
mglVar * nextPointer to next instance in list
mglVar * prevPointer to prev instance in list
bool tempFlag for temporar variable. Temporal variables will be destroyed after script execution.
void (* func )(void *)Callback function for destroying non-temporal variable.
void MoveAfter (mglVar *var)Move variable after var and copy func from var (if func is not 0)
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Structure describes MGL command, its name, short description, executable and export functions. The structure is used by mglParse and is defined in #include <mgl/mgl_parse.h>.
const wchar_t * nameName of command.
const wchar_t * descShort command description (can be NULL).
const wchar_t * formFormat of command arguments (can be NULL).
int (* exec )(mglGraph *gr, long n, mglArg *a, int k[10])const wchar_t *Function for executing (plotting) the command using grapher gr and having n-th arguments a. Function must return 0 if all is OK; or 1 if arguments are wrong.
void (* save )(wchar_t out[1024], long n, mglArg *a, int k[10])const wchar_t *Function for exporting in C++ (can be NULL).
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Structure describes arguments of functions in the stucture mglCommand. It is defined in #include <mgl/mgl_parse.h>.
int typeType of argument: 0-data, 1-string, 2-number.
mglData * dPointer to data (used if type=0).
wchar_t w[2048]String with parameters (used if type=1 or if type=0 as variable name).
char s[2048]String with parameters (used if type=1).
float vNumerical value (used if type==2)
| [ << ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated by Alexey Balakin on May 2, 2013 using texi2html 1.82.