| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
7.3 mglFont class
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.
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.
Parsing of the string to special (TeX-like) commands will be done if variable parse is true (it's default). There are commands for the font style changing inside the string (for example, use \b for bold font): \a or \overline – over-lined, \b or \textbf – bold, \i or \textit – italic, \r or \textrm – roman (disable bold and italic attributes), \u or \underline – underlined, \w or \wire – wired, \big – bigger size, @ – smaller size. The lower and upper indexes are specified by ‘_’ and ‘^’ symbols. At this the changed font style is applied only on next symbol or symbols in braces {}. The text in braces {} are treated as single symbol that allow one to print the index of index. For example, compare the strings ‘sin (x^{2^3})’ and ‘sin (x^2^3)’. You may also change text color inside string by command #? or by \color? where ‘?’ is symbolic id of the color (see section mglColor class). For example, words ‘Blue’ and ‘red’ will be colored in the string ‘#b{Blue} and \colorr{red} text’.
The most of commands for special TeX or AMSTeX symbols, the commands for font style changing (\textrm, \textbf, \textit, \overline, \underline), accents (\hat, \tilde, \dot, \ddot, \acute, \check, \grave, \bar, \breve) and roots (\sqrt, \sqrt3, \sqrt4) are recognized. The full list contain approximately 2000 commands. Note that first space symbol after the command is ignored, but second one is printed as normal symbol (space). For example, the following strings produce the same result \tilde a: ‘\tilde{a}’; ‘\tilde a’; ‘\tilde{}a’.
The Greek letters are recognizable special symbols: α – \alpha, β – \beta, γ – \gamma, δ – \delta, ε – \epsilon, η – \eta, ι – \iota, χ – \chi, κ – \kappa, λ – \lambda, μ – \mu, ν – \nu, o – \o, ω – \omega, ϕ – \phi, π – \pi, ψ – \psi, ρ – \rho, σ – \sigma, θ – \theta, τ – \tau, υ – \upsilon, ξ – \xi, ζ – \zeta, ς – \varsigma, ɛ – \varepsilon, ϑ – \vartheta, φ – \varphi, ϰ – \varkappa; A – \Alpha, B – \Beta, Γ – \Gamma, Δ – \Delta, E – \Epsilon, H – \Eta, I – \Iota, C – \Chi, K – \Kappa, Λ – \Lambda, M – \Mu, N – \Nu, O – \O, Ω – \Omega, Φ – \Phi, Π – \Pi, Ψ – \Psi, R – \Rho, Σ – \Sigma, Θ – \Theta, T – \Tau, Υ – \Upsilon, Ξ – \Xi, Z – \Zeta.The small part of most common special TeX symbols are: ∠ – \angle, ⋅ – \cdot, ♣ – \clubsuit, ✓ – \checkmark, ∪ – \cup, ∩ – \cap, ♢ – \diamondsuit, ◇ – \diamond, ÷ – \div, ↓ – \downarrow, † – \dag, ‡ – \ddag, ≡ – \equiv, ∃ – \exists, ⌢ – \frown, ♭ – \flat, ≥ – \ge, ≥ – \geq, ≧ – \geqq, ← – \gets, ♡ – \heartsuit, ∞ – \infty, ∫ – \int, \Int, ℑ – \Im, ♢ – \lozenge, ⟨ – \langle, ≤ – \le, ≤ – \leq, ≦ – \leqq, ← – \leftarrow, ∓ – \mp, ∇ – \nabla, ≠ – \ne, ≠ – \neq, ♮ – \natural, ∮ – \oint, ⊙ – \odot, ⊕ – \oplus, ∂ – \partial, ∥ – \parallel, ⊥ –\perp, ± – \pm, ∝ – \propto, ∏ – \prod, ℜ – \Re, → – \rightarrow, ⟩ – \rangle, ♠ – \spadesuit, ~ – \sim, ⌣ – \smile, ⊂ – \subset, ⊃ – \supset, √ – \sqrt or \surd, § – \S, ♯ – \sharp, ∑ – \sum, × – \times, → – \to, ∴ – \therefore, ↑ – \uparrow, ℘ – \wp.
| 7.3.1 Format of font files |
- Method on mglFont:
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=
NULLlimited data from memory (default for Windows).
- Method on mglFont:
boolLoad (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.
- Method on mglFont:
floatHeight (intfont) Gets height of text for font specified by integer constant.
- Method on mglFont:
floatPuts (const char *str,intfont=0,intalign=0) Prints 8-bit text string for font specified by integer constant.
- Method on mglFont:
floatWidth (const char *str,intfont=0) Gets width of 8-bit text string for font specified by integer constant.
- Method on mglFont:
floatPuts (const wchar_t *str,intfont=0,intalign=0) Prints Unicode text string for font specified by integer constant.
- Method on mglFont:
floatWidth (const wchar_t *str,intfont=0) Gets width of Unicode text string for font specified by integer constant.
- Method on mglFont:
floatPuts (const char *str,const char *how) Prints 8-bit text string for font specified by string.
- Method on mglFont:
floatWidth (const char *str,const char *how) Gets width of 8-bit text string for font specified by string.
- Method on mglFont:
floatPuts (const wchar_t *str,const char *how) Prints Unicode text string for font specified by string.
- Method on mglFont:
floatWidth (const wchar_t *str,const char *how) Gets width of Unicode text string for font specified by string.
- Parameter of mglFont:
boolparse Flag for switching on/off the parsing of TeX commands. Default value is
true.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
