manpagez: man pages & more
info mathgl
Home | html | info | man
[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.2.4 Text printing example

MathGL prints text by vector font. There are functions for manual specifying of text position (like Puts) and for its automatic selection (like Label, Legend and so on). MathGL prints text always in specified position even if it lies outside the bounding box. The default size of font is specified by variables FontSize (see section Font settings). However, the actual size of output string depends on position of axes (depends on functions SubPlot, InPlot). The switching of the font style (italic, bold, wire and so on) can be done for the whole string (by function parameter) or inside the string. By default MathGL parses TeX-like commands for symbols and indexes (see see section Font styles). Example of MathGL font drawing is:

    int sample(mglGraph *gr, void *)
    {
        setlocale(LC_CTYPE, "ru_RU.cp1251");
        gr->Puts(mglPoint(0,1),"Text can be in ASCII and in Unicode");
        gr->Puts(mglPoint(0,0.6),"It can be \\wire{wire}, \\big{big} "
            "or #r{colored}");
        gr->Puts(mglPoint(0,0.2),"One can change style in string: "
            "\\b{bold}, \\i{italic, \\b{both}}");
        gr->Puts(mglPoint(0,-0.2),"Easy to \\a{overline} or "
            "\\u{underline}");
        gr->Puts(mglPoint(0,-0.6),"Easy to change indexes "
            "^{up} _{down} @{center}");
        gr->Puts(mglPoint(0,-1),"It parse TeX: \\int \\alpha \\cdot "
            "\\sqrt3{sin(\\pi x)^2 + \\gamma_{i_k}} dx");
        return 0;
    }
../png/sample4

Example of text printing with different font effects

Another example demonstrate the features of TeX formula parsing.

    int sample(mglGraph *gr, void *)
    {
        gr->Puts(mglPoint(0), "\\sqrt{\\frac{\\alpha^{\\gamma^2}+"
            "\\overset 1{\\big\\infty}}{\\sqrt3{2+b}}}", 0, -4);
        return 0;
    }
../png/samplee

Example of TeX formula parsing

Finally you can change font during execution (this work well for mglGraphZB class only).

    int sample(mglGraph *gr, void *)
    {
        float h=1.1, d=0.25;
        gr->LoadFont("STIX");       gr->Puts(mglPoint(0,h), "default font (STIX)");
        gr->LoadFont("adventor");   gr->Puts(mglPoint(0,h-d), "adventor font");
        gr->LoadFont("bonum");      gr->Puts(mglPoint(0,h-2*d), "bonum font");
        gr->LoadFont("chorus");     gr->Puts(mglPoint(0,h-3*d), "chorus font");
        gr->LoadFont("cursor");     gr->Puts(mglPoint(0,h-4*d), "cursor font");
        gr->LoadFont("heros");      gr->Puts(mglPoint(0,h-5*d), "heros font");
        gr->LoadFont("heroscn");    gr->Puts(mglPoint(0,h-6*d), "heroscn font");
        gr->LoadFont("pagella");    gr->Puts(mglPoint(0,h-7*d), "pagella font");
        gr->LoadFont("schola");     gr->Puts(mglPoint(0,h-8*d), "schola font");
        gr->LoadFont("termes");     gr->Puts(mglPoint(0,h-9*d), "termes font");
    }
../png/fonts

Example of font face changing.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]
© manpagez.com 2000-2024
Individual documents may contain additional copyright information.