JKQTPlotter trunk/v5.0.0
an extensive Qt5+Qt6 Plotter framework (including a feature-richt plotter widget, a speed-optimized, but limited variant and a LaTeX equation renderer!), written fully in C/C++ and without external dependencies
Loading...
Searching...
No Matches
jkqtmathtextsymbolnode.h
1/*
2 Copyright (c) 2008-2024 Jan W. Krieger (<jan@jkrieger.de>)
3 with contributions from: Razi Alavizadeh
4
5
6
7 This software is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License (LGPL) as published by
9 the Free Software Foundation, either version 2.1 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License (LGPL) for more details.
16
17 You should have received a copy of the GNU Lesser General Public License (LGPL)
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
19*/
20
21
22
23
24#ifndef JKQTMATHTEXTSYMBOLNODE_H
25#define JKQTMATHTEXTSYMBOLNODE_H
26#include "jkqtmathtext/jkqtmathtext_imexport.h"
27#include "jkqtmathtext/jkqtmathtexttools.h"
28#include "jkqtmathtext/nodes/jkqtmathtextnode.h"
29#include <QPainter>
30#include <cstdint>
31
32class JKQTMathText; // forward
33// JKQTMATHTEXT_LIB_EXPORT
34
35
36/** \brief subclass representing one symbol (e.g. \c \\alpha , \c \\cdot ...) node in the syntax tree
37 * \ingroup jkqtmathtext_items
38 *
39 * All supported symbols are stored in the static table symbols, which is filled by fillSymbolTable().
40 * The latter function is also the customization point for new symbols:
41 * - For each symbol, the instruction name is stored as key, e.g. for \c \\alpha the key \c "alpha" is stored.
42 * - for each instruction a SymbolFullProps describes the symbol and stores how to draw it.
43 * - Each symbol has global properties (GlobalSymbolFlags, e.g. how to treat it's with etz.) and a set of representations.
44 * Each representation is for one font-encoding (JKQTMathTextFontEncoding, i.e. Unicode, WinSymbol or Standard)
45 * - each encoding representation SymbolProps specifies a text to represent the symol in SymbolProps::symbol and
46 * can have additional flags, properties etc.
47 * .
48 *
49 * Font Lookup for symbols works as follows in JKQTMathTextSymbolNode:
50 * - if a character is found in the current (or to be used) font, it is taken from there (the font is specified in
51 * SymbolFullProps::fontType)
52 * - if the character is not found, it is looked for in the fallback fonts MTEFallbackGreek and MTEFallbackSymbols
53 * - as a last resort, some symbols can be created otherwise, so if neither of the two options above
54 * contain the required symbol, the symbol might be synthesized otherwise, or a rectangle with the size of "X" is drawn instead
55 * .
56 *
57 */
59 public:
60 explicit JKQTMathTextSymbolNode(JKQTMathText* parent, const QString& name);
61 virtual ~JKQTMathTextSymbolNode() override;
62 /** \copydoc JKQTMathTextNode::getTypeName() */
63 virtual QString getTypeName() const override;
64 /** \copydoc JKQTMathTextNode::draw() */
65 virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) const override;
66 /** \copydoc JKQTMathTextNode::toHtml() */
67 virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const override;
68
69 /** \copydoc symbolName */
70 QString getSymbolName() const;
71 /** \brief return type for getSymbolSize(), extends JKQTMathTextNodeSize with information about x-correction for sub- and superscript */
74 /** \brief x-correction as described for JKQTMathParser::intsubsuper_xcorrection_factor for placing sub-/superscript below/above the symbol, e.g. for integral signs, where the subscript is slightly shifted to the left (from center) and the superscript slightly to the right */
76
78 NodeSize& operator=(const NodeSize& other);
80 NodeSize(const NodeSize& other);
81 };
82
83 /** \brief determine the size of the node, calls getSizeInternal() implementation of the actual type \see getSizeInternal()
84 *
85 * \param painter painter to use for determining the size
86 * \param currentEv current environment object
87 *
88 * \return all important size properties, packed into a NodeSize struct
89 */
90 NodeSize getSymbolSize(QPainter& painter, JKQTMathTextEnvironment currentEv) const;
91 /** \brief checks whether the given symbol name can be prepresented by this type of node */
92 static bool hasSymbol(const QString& symbolName);
93 /** \brief return a list of all defined symbols */
94 static QStringList getSymbols();
95 /** \brief checks whether the given symbol name codes for an instruction that has SymbolFullProps::SubSuperscriptBelowAboveSymbol , does not neccessarily return the same value as JKQTMathTextNode::isSubSuperscriptAboveBelowNode() */
96 static bool isSubSuperscriptBelowAboveSymbol(const QString& symbolName);
97 /** \brief checks whether the given symbol has global flags SymbolFullProps::ExtendWidthInMathmode or SymbolFullProps::SmallExtendWidthInMathmode defined */
98 static bool isExtendedWidthSymbol(const QString& symbolName);
99 /** \brief returns the length of the symbol string for the given symbol */
100 static int getSymbolLength(const QString& symbolName);
101 protected:
102 /** \copydoc JKQTMathTextNode::getSizeInternal() */
103 virtual JKQTMathTextNodeSize getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv) const override;
104
105
106 /** \brief this string will be sent to the drawText method with properly set fonts */
107 QString symbolName;
108
109 /** \brief flags specifying additional symbol features */
110 enum SymbolFlags: uint64_t {
111 AsOutside= 0, /*!< \brief indicates that no properties are activated */
112 ItalicOn= 1 << 0, /*!< \brief make font italic in any case */
113 ItalicOff= 1 << 1, /*!< \brief make font non-italic (i.e. upright) in any case */
114 BoldOn= 1 << 2, /*!< \brief make font bold in any case */
115 BoldOff= 1 << 3, /*!< \brief make font non-bold (i,,e, normal weight) in any case */
116 DrawLeftHBar= 1 << 4, /*!< \brief indicates whether to draw a bar on the left half of the character, above the xHeight (like for \c \\hbar ), implements an italic-correction */
117 DrawRightHBar= 1 << 5, /*!< \brief indicates whether to draw a bar on the right half of the character, above the xHeight, implements an italic-correction */
118 FlipSymbolUpDown=1 << 6, /*!< \brief indicates to flip the given symbol upside-down */
119 FlipSymbolLeftRight=1 << 7, /*!< \brief indicates to flip the given symbol left-right */
120 RotateSymbol90=1 << 8, /*!< \brief indicates to rotate the symbol 90 degree */
121 DrawSlash=1 << 9, /*!< \brief indicates to overdraw a slash (e.g. to combine 0 and / to form \\varnothing ) */
122 DrawBackSlash=1 << 10, /*!< \brief indicates to overdraw a backslash */
123 DrawVertLine=1 << 11, /*!< \brief indicates to overdraw a centered vertical line (slightly tilted if italic) */
124 HeightIsAscent= 1 << 12, /*!< \brief if true, the height of the symbol equals the ascent of the font */
125 Upright=ItalicOff,
126 NormalWeight=BoldOff,
127 };
128
129 friend inline SymbolFlags operator~ (SymbolFlags a) { return (SymbolFlags)~static_cast<uint64_t>(a); }
130 friend inline SymbolFlags operator| (SymbolFlags a, SymbolFlags b) { return static_cast<SymbolFlags>(static_cast<uint64_t>(a) | static_cast<uint64_t>(b)); }
131 friend inline SymbolFlags operator& (SymbolFlags a, SymbolFlags b) { return static_cast<SymbolFlags>(static_cast<uint64_t>(a) & static_cast<uint64_t>(b)); }
132 friend inline SymbolFlags operator^ (SymbolFlags a, SymbolFlags b) { return static_cast<SymbolFlags>(static_cast<uint64_t>(a) ^ static_cast<uint64_t>(b)); }
133 friend inline SymbolFlags& operator|= (SymbolFlags& a, SymbolFlags b) { return reinterpret_cast<SymbolFlags&>(reinterpret_cast<uint64_t&>(a) |= static_cast<uint64_t>(b)); }
134 friend inline SymbolFlags& operator&= (SymbolFlags& a, SymbolFlags b) { return reinterpret_cast<SymbolFlags&>(reinterpret_cast<uint64_t&>(a) &= static_cast<uint64_t>(b)); }
135 friend inline SymbolFlags& operator^= (SymbolFlags& a, SymbolFlags b) { return reinterpret_cast<SymbolFlags&>(reinterpret_cast<uint64_t&>(a) ^= static_cast<uint64_t>(b)); }
136 friend inline bool has(SymbolFlags a, SymbolFlags b) { return (a&b)==b; }
137
138 /** \brief flags specifying additional symbol features */
139 enum GlobalSymbolFlags: uint64_t {
140 NoGLobalSymbolFlags= 0, /*!< \brief indicates that no properties are activated */
141 ExtendWidthInMathmode= 1 << 0, /*!< \brief this symbol has an extended width, when used within a moth-environment/in math-mode */
142 SmallExtendWidthInMathmode= 1 << 1, /*!< \brief like ExtendWidthInMathmode but adds a smaller whitespace */
143 MakeWhitespaceHalf= 1 << 2, /*!< \brief symbol uses whitespaces in its text (SymbolProps::symbol). These should be typeset as half-spaces */
144 IntLikeSymbolCorrection= 1 << 3, /*!< \brief symbols, like \c \\int,\\iint,... require a correction in x-direction for subsequent sub-/superscripts ... this flag marks such symbols */
145 SubSuperscriptBelowAboveSymbol= 1 << 4, /*!< \brief symbols, like \c \\int,\\iint,... if appearing in math-mode cause typesetting following sub-/superscripts below/above the symbol, not besides it. */
146 SubscriptCorrection= 1 << 5, /*!< \brief symbols, like \c \\nabla,... require a subscript correction in x-direction for subsequent subscripts ... this flag marks such symbols */
147 };
148
149 friend inline GlobalSymbolFlags operator~ (GlobalSymbolFlags a) { return (GlobalSymbolFlags)~static_cast<uint64_t>(a); }
150 friend inline GlobalSymbolFlags operator| (GlobalSymbolFlags a, GlobalSymbolFlags b) { return static_cast<GlobalSymbolFlags>(static_cast<uint64_t>(a) | static_cast<uint64_t>(b)); }
151 friend inline GlobalSymbolFlags operator& (GlobalSymbolFlags a, GlobalSymbolFlags b) { return static_cast<GlobalSymbolFlags>(static_cast<uint64_t>(a) & static_cast<uint64_t>(b)); }
152 friend inline GlobalSymbolFlags operator^ (GlobalSymbolFlags a, GlobalSymbolFlags b) { return static_cast<GlobalSymbolFlags>(static_cast<uint64_t>(a) ^ static_cast<uint64_t>(b)); }
153 friend inline GlobalSymbolFlags& operator|= (GlobalSymbolFlags& a, GlobalSymbolFlags b) { return reinterpret_cast<GlobalSymbolFlags&>(reinterpret_cast<uint64_t&>(a) |= static_cast<uint64_t>(b)); }
154 friend inline GlobalSymbolFlags& operator&= (GlobalSymbolFlags& a, GlobalSymbolFlags b) { return reinterpret_cast<GlobalSymbolFlags&>(reinterpret_cast<uint64_t&>(a) &= static_cast<uint64_t>(b)); }
155 friend inline GlobalSymbolFlags& operator^= (GlobalSymbolFlags& a, GlobalSymbolFlags b) { return reinterpret_cast<GlobalSymbolFlags&>(reinterpret_cast<uint64_t&>(a) ^= static_cast<uint64_t>(b)); }
156 friend inline bool has(GlobalSymbolFlags a, GlobalSymbolFlags b) { return (a&b)==b; }
157
158 /** \brief calculates the bounding rect of \a text using \a fm and taking the flags from \a globalFlags into account */
159 static QRectF getBoundingRect(const QFont &fm, const QString& text, GlobalSymbolFlags globalFlags, QPaintDevice *pd);
160 /** \brief calculates the tight bounding rect of \a text using \a fm and taking the flags from \a globalFlags into account */
161 static QRectF getTightBoundingRect(const QFont& fm, const QString& text, GlobalSymbolFlags globalFlags, QPaintDevice *pd);
162 /** \brief draw \a text at (0,0) using QPainter \a p and taking the flags from \a globalFlags into account */
163 static void drawText(QPainter &p, const QString &text, GlobalSymbolFlags globalFlags, SymbolFlags symflags);
164
165 /** \brief properties of the symbol */
166 struct SymbolProps {
168 /** \brief this constructor sets the given properties and sets html=symbol! replaces whitespaces in \a _ymbol with \c &thinsp; for html, iff MakeWhitespaceHalf is set in \a _flags*/
169 SymbolProps(const QString& _symbol, SymbolFlags _flags=AsOutside, double _fontScalingFactor=1.0, double _yShiftFactor=0.0);
170 SymbolProps(SymbolProps&& other)=default;
171 SymbolProps(const SymbolProps& other)=default;
173 SymbolProps& operator=(const SymbolProps& other)=default;
174 /** \brief the symbol or text used to render the symbol (i.e. not the name,
175 * e.g. if the instruction/symbol name \c \\int is used, this would be \c QChar(0xF2) ,
176 * for \c \\sin it would be \c QString("sin") ...) */
177 QString symbol;
178 /** \brief if \a symbol is a single character, this returns it, otherwise (empty or multi-character) it returns QChar() */
179 inline QChar getSymbolSingleChar() const {
180 if (symbol.size()==1) return symbol[0];
181 return QChar();
182 }
183 /** \brief flags switching special features */
185 /** \brief magnification factor for the font size */
187 /** \brief this corrects the y position of a symbol: draws at y <- y+ height*yfactor) */
189 };
190
191 /** \brief properties of the symbol, extends SymbolProps with font... */
193 /** \brief default constructor */
196 SymbolFullProps(const SymbolFullProps& other)=default;
199 /** \brief typesets the symbol (described in \a props ) from the specified \a font, \a props is stored with encoding MTFEStandard, an optional HTML-string \a _html can be given */
200 SymbolFullProps(const QString& font, const SymbolProps& props, const QString& _html=QString(), SymbolFlags _htmlflags=AsOutside, double _htmlfontScalingFactor=1.0, double _htmlyShiftFactor=0.0);
201 /** \brief typesets the \a symbol from the specified \a font, \a props is stored with encoding MTFEStandard, an optional HTML-string \a _html can be given */
202 SymbolFullProps(const QString& font, const QString& symbol, const QString& _html=QString(), SymbolFlags _htmlflags=AsOutside, double _htmlfontScalingFactor=1.0, double _htmlyShiftFactor=0.0);
203 /** \brief \a props is stored with encoding MTFEStandard, an optional HTML-string \a _html can be given */
204 SymbolFullProps(const SymbolProps& props, const QString& _html=QString(), SymbolFlags _htmlflags=AsOutside, double _htmlfontScalingFactor=1.0, double _htmlyShiftFactor=0.0);
205 /** \brief \a props is stored with encoding MTFEStandard, uses the specified \a _fontType for drawing, an optional HTML-string \a _html can be given */
206 SymbolFullProps(JKQTMathTextEnvironmentFont _fontType, const SymbolProps& props, const QString& _html=QString(), SymbolFlags _htmlflags=AsOutside, double _htmlfontScalingFactor=1.0, double _htmlyShiftFactor=0.0);
207 /** \brief takes a \a symbol from the specified \a _fontType assuming MTFEStandard encoding, an optional HTML-string \a _html can be given */
208 SymbolFullProps(JKQTMathTextEnvironmentFont _fontType, const QString& symbol, const QString& _html=QString(), SymbolFlags _htmlflags=AsOutside, double _htmlfontScalingFactor=1.0, double _htmlyShiftFactor=0.0);
209 /** \brief single-alternative symbol for encoding \a enc0 and using symbol description \a props0 for it. An optional HTML-string \a _html can be provided */
210 SymbolFullProps(JKQTMathTextFontEncoding enc0, const SymbolProps& props0, const QString& _html=QString(), SymbolFlags _htmlflags=AsOutside, double _htmlfontScalingFactor=1.0, double _htmlyShiftFactor=0.0);
211 /** \brief single-alternative symbol for encoding \a enc0 and using symbol description \a props0 for it, uses the specified \a _fontType for drawing. An optional HTML-string \a _html can be provided */
212 SymbolFullProps(JKQTMathTextEnvironmentFont _fontType, JKQTMathTextFontEncoding enc0, const SymbolProps& props0, const QString& _html=QString(), SymbolFlags _htmlflags=AsOutside, double _htmlfontScalingFactor=1.0, double _htmlyShiftFactor=0.0);
213 /** \brief double-alternative symbol for encoding \a enc0 + \a enc1 and using symbol descriptions \a props0 + \a props1 for it. An optional HTML-string \a _html can be provided */
214 SymbolFullProps(JKQTMathTextFontEncoding enc0, const SymbolProps& props0, JKQTMathTextFontEncoding enc1, const SymbolProps& props1, const QString& _html=QString(), SymbolFlags _htmlflags=AsOutside, double _htmlfontScalingFactor=1.0, double _htmlyShiftFactor=0.0);
215 /** \brief double-alternative symbol for encoding \a enc0 + \a enc1 and using symbol descriptions \a props0 + \a props1 for it, uses the specified \a _fontType for drawing. An optional HTML-string \a _html can be provided */
216 SymbolFullProps(JKQTMathTextEnvironmentFont _fontType, JKQTMathTextFontEncoding enc0, const SymbolProps& props0, JKQTMathTextFontEncoding enc1, const SymbolProps& props1, const QString& _html=QString(), SymbolFlags _htmlflags=AsOutside, double _htmlfontScalingFactor=1.0, double _htmlyShiftFactor=0.0);
217 /** \brief triple-alternative symbol for encoding \a enc0 + \a enc1 + \a enc2 and using symbol descriptions \a props0 + \a props1 + \a props2 for it. An optional HTML-string \a _html can be provided */
218 SymbolFullProps(JKQTMathTextFontEncoding enc0, const SymbolProps& props0, JKQTMathTextFontEncoding enc1, const SymbolProps& props1, JKQTMathTextFontEncoding enc2, const SymbolProps& props2, const QString& _html=QString(), SymbolFlags _htmlflags=AsOutside, double _htmlfontScalingFactor=1.0, double _htmlyShiftFactor=0.0);
219 /** \brief triple-alternative symbol for encoding \a enc0 + \a enc1 + \a enc2 and using symbol descriptions \a props0 + \a props1 + \a props2 for it, uses the specified \a _fontType for drawing. An optional HTML-string \a _html can be provided */
220 SymbolFullProps(JKQTMathTextEnvironmentFont _fontType, JKQTMathTextFontEncoding enc0, const SymbolProps& props0, JKQTMathTextFontEncoding enc1, const SymbolProps& props1, JKQTMathTextFontEncoding enc2, const SymbolProps& props2, const QString& _html=QString(), SymbolFlags _htmlflags=AsOutside, double _htmlfontScalingFactor=1.0, double _htmlyShiftFactor=0.0);
221 /** \brief font type to use for typesetting the symbol (default is MTcurrentFont, which just takes the font set in the surrounding environment) */
223 /** \brief font to use for output when fontType==MTcustomFont */
225 /** \brief here the actual symbol properties for each JKQTMathTextFontEncoding are stored */
226 QHash<JKQTMathTextFontEncoding, SymbolProps> props;
227 /** \brief HTML entity/text to represent the symbol (empty html.symbol not available) */
229 /** \brief specifies global symbol flags */
231 /** \brief accesses entries in props for a given \a key. This also looks for fallback options (e.g. MTFEStandard when MTFEUnicode is not available). Returns \a defaultValue when nothing is found */
232 SymbolProps getProps(JKQTMathTextFontEncoding key, const SymbolProps& defaultValue=SymbolProps(), JKQTMathTextFontEncoding* foundEncodingOut=nullptr) const;
233
235 SymbolFullProps& addWinSymbol(const QString& _symbol, SymbolFlags _flags=AsOutside, double _fontScalingFactor=1.0, double _yShiftFactor=0.0);
236 SymbolFullProps& addMathOperatorWinSymbol(const QString& _symbol, double _fontScalingFactor=1.0, double _yShiftFactor=0.0);
237 SymbolFullProps& addUprightWinSymbol(const QString& _symbol, double _fontScalingFactor=1.0, double _yShiftFactor=0.0);
238 SymbolFullProps& addUnicode(const QString& _symbol, SymbolFlags _flags=AsOutside, double _fontScalingFactor=1.0, double _yShiftFactor=0.0);
239 SymbolFullProps& addUprightUnicode(const QString& _symbol, double _fontScalingFactor=1.0, double _yShiftFactor=0.0);
240 SymbolFullProps& addMathOperatorUnicode(const QString& _symbol, double _fontScalingFactor=1.0, double _yShiftFactor=0.0);
241 SymbolFullProps& addStd(const QString& _symbol, SymbolFlags _flags=AsOutside, double _fontScalingFactor=1.0, double _yShiftFactor=0.0);
242 SymbolFullProps& addMathOperatorStd(const QString& _symbol, double _fontScalingFactor=1.0, double _yShiftFactor=0.0);
243 SymbolFullProps& addUprightStd(const QString& _symbol, double _fontScalingFactor=1.0, double _yShiftFactor=0.0);
244 SymbolFullProps& addHtml(const QString& _symbol, SymbolFlags _flags=AsOutside, double _fontScalingFactor=1.0, double _yShiftFactor=0.0);
245 SymbolFullProps& addMathOperatorHtml(const QString& _symbol, double _fontScalingFactor=1.0, double _yShiftFactor=0.0);
246 SymbolFullProps& addUprightHtml(const QString& _symbol, double _fontScalingFactor=1.0, double _yShiftFactor=0.0);
249
250 /** \brief returns the QFont to use for drawing and the QString to draw with it */
251 QPair<QFont, SymbolProps> getDrawingData(JKQTMathTextEnvironment currentEv, JKQTMathText *parent, QPainter& painter) const;
252 };
253
254 /** \brief creates a SymbolFullProps object for a symbol that can be typeset in any font, for SymbolFullProps::html the same text as a\a symbol is used */
255 static SymbolFullProps SimpleTextSymbol(const QString& symbol, SymbolFlags _flags=AsOutside, double _fontScalingFactor=1.0, double _yShiftFactor=0.0);
256 /** \brief creates a SymbolFullProps object for a symbol that can be typeset in any font, a special html-string is given */
257 static SymbolFullProps SimpleTextSymbol(const QString& symbol, const QString& html);
258 /** \brief creates a SymbolFullProps object for a symbol that can be typeset in any font, for SymbolFullProps::html the same text as a\a symbol is used */
259 static SymbolFullProps SimpleUprightTextSymbol(const QString& symbol);
260 /** \brief creates a SymbolFullProps object for a symbol that can be typeset in any font, a special html-string is given */
261 static SymbolFullProps SimpleUprightTextSymbol(const QString& symbol, const QString& html);
262 /** \brief constructs a SymbolProps for a math-operator like \c \\sin ..., i.e. ItalicOff, BoldOff, ExtendWidthInMathmode */
263 static SymbolFullProps MathOperatorSymbol(const QString& op);
264 /** \brief constructs a SymbolProps with explicit HTML for a math-operator like \c \\sin ..., i.e. ItalicOff, BoldOff, ExtendWidthInMathmode */
265 static SymbolFullProps MathOperatorSymbol(const QString& op, const QString& ophtml);
266 /** \brief constructs a SymbolProps for a math-operator like \c \\sin ..., i.e. ItalicOff, BoldOff, HeightIsAscent, ExtendWidthInMathmode */
267 static SymbolFullProps MathOperatorText(const QString& op);
268 /** \brief constructs a SymbolProps with explicit HTML for a math-operator like \c \\sin ..., i.e. ItalicOff, BoldOff, HeightIsAscent, ExtendWidthInMathmode */
269 static SymbolFullProps MathOperatorText(const QString& op, const QString& ophtml);
270 /** \brief constructs a SymbolProps for an italic greek letter with the symbol in unicode-encoding \a letterUnicode and in WinSymbol-encoding letterWinWsymbol */
271 static SymbolFullProps MathGreekLetter_WinSymbol_Unicode_Html(const QString& letterWinSymbol, const QString& letterUnicode, const QString& html);
272 /** \brief constructs a SymbolProps for an upright greek letter with the symbol in unicode-encoding \a letterUnicode and in WinSymbol-encoding letterWinWsymbol */
273 static SymbolFullProps UprightGreekLetter_WinSymbol_Unicode_Html(const QString& letterWinSymbol, const QString& letterUnicode, const QString& html);
274 /** \brief constructs a SymbolProps for a greek letter with the format from outside with the symbol in unicode-encoding \a letterUnicode and in WinSymbol-encoding letterWinWsymbol */
275 static SymbolFullProps AsOutsiudeGreekLetter_WinSymbol_Unicode_Html(const QString& letterWinSymbol, const QString& letterUnicode, const QString& html);
276 /** \brief insert GreekLetter_WinSymbol_Unicode_Html() as \a baseInstructionName and UprightGreekLetter_WinSymbol_Unicode_Html and "up"+\a letterWinSymbol into symbols */
277 static void addGreekLetterVariants_WinSymbol_Unicode_Html(QHash<QString, JKQTMathTextSymbolNode::SymbolFullProps>& symbols,const QString& baseInstructionName, const QString& letterWinSymbol, const QString& letterUnicode, const QString& html);
278 /** \brief constructs a SymbolProps for a symbol with encoding in Standard-fonts a */
279 static SymbolFullProps StdSymbol(const QString& symbol, const QString& html);
280 /** \brief constructs a SymbolProps for a symbol with encoding in UnicodeFull-fonts a */
281 static SymbolFullProps UnicodeSymbol(const QString& symbol, const QString& html);
282 /** \brief constructs a SymbolProps for a symbol with encoding in Standard-fonts a */
283 static SymbolFullProps StdSymbol(const QString& symbol, SymbolFlags _flags=AsOutside, double _fontScalingFactor=1.0, double _yShiftFactor=0.0);
284 /** \brief constructs a SymbolProps for a symbol with encoding in UnicodeFull-fonts a */
285 static SymbolFullProps UnicodeSymbol(const QString& symbol, SymbolFlags _flags=AsOutside, double _fontScalingFactor=1.0, double _yShiftFactor=0.0);
286 /** \brief constructs a SymbolProps for a symbol with encoding in Standard-fonts a */
287 static SymbolFullProps UprightSymbolStd(const QString& symbol);
288 /** \brief constructs a SymbolProps for a symbol with encoding in UnicodeFull-fonts a */
289 static SymbolFullProps UprightSymbolUnicode(const QString& symbol);
290 /** \brief constructs a SymbolProps for a symbol with encoding in Standard-fonts a */
291 static SymbolFullProps UprightSymbolStd(const QString& symbol, const QString& html);
292 /** \brief constructs a SymbolProps for a symbol with encoding in UnicodeFull-fonts a */
293 static SymbolFullProps UprightSymbolUnicode(const QString& symbol, const QString& html);
294 /** \brief constructs a SymbolProps for a math-operator symbol like \c \\pm ... in unicode-full-encoding, i.e. ItalicOff, BoldOff, ExtendWidthInMathmode */
295 static SymbolFullProps MathOperatorSymbolUnicode(const QString& unicode);
296 /** \brief constructs a SymbolProps for a narrow math-operator symbol like \c \\pm ... in unicode-full-encoding, i.e. ItalicOff, BoldOff, SmallExtendWidthInMathmode */
297 static SymbolFullProps NarrowMathOperatorSymbolUnicode(const QString& unicode);
298 /** \brief constructs a SymbolProps for a narrow math-operator symbol like \c \\pm ... in unicode-full-encoding, i.e. ItalicOff, BoldOff, SmallExtendWidthInMathmode */
299 static SymbolFullProps NarrowMathOperatorSymbolStd(const QString& symbol);
300 /** \brief constructs a SymbolProps for a narrow math-operator symbol like \c \\pm ... in unicode-full-encoding, i.e. ItalicOff, BoldOff, SmallExtendWidthInMathmode */
301 static SymbolFullProps NarrowMathOperatorSymbolStd(const QString& symbol, const QString& symbolHTML);
302 /** \brief constructs a SymbolProps for a narrow math-operator like \c \\sin ..., i.e. ItalicOff, BoldOff, HeightIsAscent, ExtendWidthInMathmode */
303 static SymbolFullProps NarrowMathOperatorText(const QString& op);
304 /** \brief constructs a SymbolProps with explicit HTML for a narrow math-operator like \c \\sin ..., i.e. ItalicOff, BoldOff, HeightIsAscent, ExtendWidthInMathmode */
305 static SymbolFullProps NarrowMathOperatorText(const QString& op, const QString& ophtml);
306
307
308 /** \brief symbols that can be generated in any standard-font */
309 static const QHash<QString, SymbolFullProps>& symbols();
310
311 /** \brief retrieve the properties to render the given symbol \a symName in the current environment \a currentEv */
312 SymbolFullProps getSymbolProp(const QString& symName, const JKQTMathTextEnvironment& currentEv) const;
313};
314
315#endif // JKQTMATHTEXTSYMBOLNODE_H
316
317
318
319
320
321
322
323
324
this class parses a mathematical markup string and can then draw the contained text/equation onto a Q...
Definition jkqtmathtext.h:192
subclass representing one node in the syntax tree
Definition jkqtmathtextnode.h:37
subclass representing one symbol (e.g. \alpha , \cdot ...) node in the syntax tree
Definition jkqtmathtextsymbolnode.h:58
static SymbolFullProps MathOperatorSymbolUnicode(const QString &unicode)
constructs a SymbolProps for a math-operator symbol like \pm ... in unicode-full-encoding,...
static SymbolFullProps AsOutsiudeGreekLetter_WinSymbol_Unicode_Html(const QString &letterWinSymbol, const QString &letterUnicode, const QString &html)
constructs a SymbolProps for a greek letter with the format from outside with the symbol in unicode-e...
static void addGreekLetterVariants_WinSymbol_Unicode_Html(QHash< QString, JKQTMathTextSymbolNode::SymbolFullProps > &symbols, const QString &baseInstructionName, const QString &letterWinSymbol, const QString &letterUnicode, const QString &html)
insert GreekLetter_WinSymbol_Unicode_Html() as baseInstructionName and UprightGreekLetter_WinSymbol_U...
static SymbolFullProps SimpleTextSymbol(const QString &symbol, const QString &html)
creates a SymbolFullProps object for a symbol that can be typeset in any font, a special html-string ...
static SymbolFullProps StdSymbol(const QString &symbol, const QString &html)
constructs a SymbolProps for a symbol with encoding in Standard-fonts a
static SymbolFullProps StdSymbol(const QString &symbol, SymbolFlags _flags=AsOutside, double _fontScalingFactor=1.0, double _yShiftFactor=0.0)
constructs a SymbolProps for a symbol with encoding in Standard-fonts a
static SymbolFullProps SimpleTextSymbol(const QString &symbol, SymbolFlags _flags=AsOutside, double _fontScalingFactor=1.0, double _yShiftFactor=0.0)
creates a SymbolFullProps object for a symbol that can be typeset in any font, for SymbolFullProps::h...
NodeSize getSymbolSize(QPainter &painter, JKQTMathTextEnvironment currentEv) const
determine the size of the node, calls getSizeInternal() implementation of the actual type
virtual bool toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const override
convert node to HTML and returns true on success
virtual QString getTypeName() const override
return the name of this class as a string
QString getSymbolName() const
this string will be sent to the drawText method with properly set fonts
QString symbolName
this string will be sent to the drawText method with properly set fonts
Definition jkqtmathtextsymbolnode.h:107
static SymbolFullProps SimpleUprightTextSymbol(const QString &symbol)
creates a SymbolFullProps object for a symbol that can be typeset in any font, for SymbolFullProps::h...
static bool hasSymbol(const QString &symbolName)
checks whether the given symbol name can be prepresented by this type of node
static SymbolFullProps MathOperatorSymbol(const QString &op)
constructs a SymbolProps for a math-operator like \sin ..., i.e. ItalicOff, BoldOff,...
static SymbolFullProps UprightGreekLetter_WinSymbol_Unicode_Html(const QString &letterWinSymbol, const QString &letterUnicode, const QString &html)
constructs a SymbolProps for an upright greek letter with the symbol in unicode-encoding letterUnicod...
GlobalSymbolFlags
flags specifying additional symbol features
Definition jkqtmathtextsymbolnode.h:139
static SymbolFullProps MathOperatorSymbol(const QString &op, const QString &ophtml)
constructs a SymbolProps with explicit HTML for a math-operator like \sin ..., i.e....
static SymbolFullProps SimpleUprightTextSymbol(const QString &symbol, const QString &html)
creates a SymbolFullProps object for a symbol that can be typeset in any font, a special html-string ...
virtual JKQTMathTextNodeSize getSizeInternal(QPainter &painter, JKQTMathTextEnvironment currentEv) const override
determine the size of the node, overwrite this function in derived classes
static QStringList getSymbols()
return a list of all defined symbols
static SymbolFullProps MathOperatorText(const QString &op, const QString &ophtml)
constructs a SymbolProps with explicit HTML for a math-operator like \sin ..., i.e....
SymbolFullProps getSymbolProp(const QString &symName, const JKQTMathTextEnvironment &currentEv) const
retrieve the properties to render the given symbol symName in the current environment currentEv
static SymbolFullProps MathOperatorText(const QString &op)
constructs a SymbolProps for a math-operator like \sin ..., i.e. ItalicOff, BoldOff,...
SymbolFlags
flags specifying additional symbol features
Definition jkqtmathtextsymbolnode.h:110
static bool isExtendedWidthSymbol(const QString &symbolName)
checks whether the given symbol has global flags SymbolFullProps::ExtendWidthInMathmode or SymbolFull...
friend bool has(SymbolFlags a, SymbolFlags b)
Definition jkqtmathtextsymbolnode.h:136
static void drawText(QPainter &p, const QString &text, GlobalSymbolFlags globalFlags, SymbolFlags symflags)
draw text at (0,0) using QPainter p and taking the flags from globalFlags into account
friend bool has(GlobalSymbolFlags a, GlobalSymbolFlags b)
Definition jkqtmathtextsymbolnode.h:156
static const QHash< QString, SymbolFullProps > & symbols()
symbols that can be generated in any standard-font
static SymbolFullProps NarrowMathOperatorSymbolStd(const QString &symbol)
constructs a SymbolProps for a narrow math-operator symbol like \pm ... in unicode-full-encoding,...
static SymbolFullProps NarrowMathOperatorText(const QString &op)
constructs a SymbolProps for a narrow math-operator like \sin ..., i.e. ItalicOff,...
static SymbolFullProps MathGreekLetter_WinSymbol_Unicode_Html(const QString &letterWinSymbol, const QString &letterUnicode, const QString &html)
constructs a SymbolProps for an italic greek letter with the symbol in unicode-encoding letterUnicode...
static SymbolFullProps UnicodeSymbol(const QString &symbol, SymbolFlags _flags=AsOutside, double _fontScalingFactor=1.0, double _yShiftFactor=0.0)
constructs a SymbolProps for a symbol with encoding in UnicodeFull-fonts a
JKQTMathTextSymbolNode(JKQTMathText *parent, const QString &name)
static bool isSubSuperscriptBelowAboveSymbol(const QString &symbolName)
checks whether the given symbol name codes for an instruction that has SymbolFullProps::SubSuperscrip...
static QRectF getTightBoundingRect(const QFont &fm, const QString &text, GlobalSymbolFlags globalFlags, QPaintDevice *pd)
calculates the tight bounding rect of text using fm and taking the flags from globalFlags into accoun...
static SymbolFullProps NarrowMathOperatorSymbolStd(const QString &symbol, const QString &symbolHTML)
constructs a SymbolProps for a narrow math-operator symbol like \pm ... in unicode-full-encoding,...
static SymbolFullProps NarrowMathOperatorText(const QString &op, const QString &ophtml)
constructs a SymbolProps with explicit HTML for a narrow math-operator like \sin ....
static SymbolFullProps UprightSymbolUnicode(const QString &symbol, const QString &html)
constructs a SymbolProps for a symbol with encoding in UnicodeFull-fonts a
static int getSymbolLength(const QString &symbolName)
returns the length of the symbol string for the given symbol
static SymbolFullProps NarrowMathOperatorSymbolUnicode(const QString &unicode)
constructs a SymbolProps for a narrow math-operator symbol like \pm ... in unicode-full-encoding,...
virtual double draw(QPainter &painter, double x, double y, JKQTMathTextEnvironment currentEv) const override
draw the contents at the designated position
static QRectF getBoundingRect(const QFont &fm, const QString &text, GlobalSymbolFlags globalFlags, QPaintDevice *pd)
calculates the bounding rect of text using fm and taking the flags from globalFlags into account
static SymbolFullProps UprightSymbolStd(const QString &symbol)
constructs a SymbolProps for a symbol with encoding in Standard-fonts a
static SymbolFullProps UprightSymbolStd(const QString &symbol, const QString &html)
constructs a SymbolProps for a symbol with encoding in Standard-fonts a
static SymbolFullProps UnicodeSymbol(const QString &symbol, const QString &html)
constructs a SymbolProps for a symbol with encoding in UnicodeFull-fonts a
static SymbolFullProps UprightSymbolUnicode(const QString &symbol)
constructs a SymbolProps for a symbol with encoding in UnicodeFull-fonts a
virtual ~JKQTMathTextSymbolNode() override
#define JKQTMATHTEXT_LIB_EXPORT
Definition jkqtmathtext_imexport.h:108
JKQTMathTextEnvironmentFont
the available logical fonts (default is MTEroman)
Definition jkqtmathtexttools.h:284
JKQTMathTextFontEncoding
used to specify the font encoding used for drawing
Definition jkqtmathtexttools.h:175
describes the current drawing environment (base fontname ...)
Definition jkqtmathtexttools.h:304
beschreibt die Größe(n) eines Knotens
Definition jkqtmathtexttools.h:393
return type for getSymbolSize(), extends JKQTMathTextNodeSize with information about x-correction for...
Definition jkqtmathtextsymbolnode.h:72
NodeSize(const JKQTMathTextNodeSize &other)
NodeSize(const NodeSize &other)
NodeSize & operator=(const NodeSize &other)
double subSuperAboveBelowXCorrection
x-correction as described for JKQTMathParser::intsubsuper_xcorrection_factor for placing sub-/supersc...
Definition jkqtmathtextsymbolnode.h:75
NodeSize & operator=(const JKQTMathTextNodeSize &other)
properties of the symbol, extends SymbolProps with font...
Definition jkqtmathtextsymbolnode.h:192
SymbolProps getProps(JKQTMathTextFontEncoding key, const SymbolProps &defaultValue=SymbolProps(), JKQTMathTextFontEncoding *foundEncodingOut=nullptr) const
accesses entries in props for a given key. This also looks for fallback options (e....
SymbolFullProps & operator=(SymbolFullProps &&other)=default
SymbolFullProps & operator=(const SymbolFullProps &other)=default
SymbolFullProps(JKQTMathTextEnvironmentFont _fontType, const SymbolProps &props, const QString &_html=QString(), SymbolFlags _htmlflags=AsOutside, double _htmlfontScalingFactor=1.0, double _htmlyShiftFactor=0.0)
props is stored with encoding MTFEStandard, uses the specified _fontType for drawing,...
SymbolFullProps(const QString &font, const SymbolProps &props, const QString &_html=QString(), SymbolFlags _htmlflags=AsOutside, double _htmlfontScalingFactor=1.0, double _htmlyShiftFactor=0.0)
typesets the symbol (described in props ) from the specified font, props is stored with encoding MTFE...
JKQTMathTextEnvironmentFont fontType
font type to use for typesetting the symbol (default is MTcurrentFont, which just takes the font set ...
Definition jkqtmathtextsymbolnode.h:222
QPair< QFont, SymbolProps > getDrawingData(JKQTMathTextEnvironment currentEv, JKQTMathText *parent, QPainter &painter) const
returns the QFont to use for drawing and the QString to draw with it
SymbolFullProps & addMathOperatorHtml(const QString &_symbol, double _fontScalingFactor=1.0, double _yShiftFactor=0.0)
SymbolFullProps(JKQTMathTextEnvironmentFont _fontType, const QString &symbol, const QString &_html=QString(), SymbolFlags _htmlflags=AsOutside, double _htmlfontScalingFactor=1.0, double _htmlyShiftFactor=0.0)
takes a symbol from the specified _fontType assuming MTFEStandard encoding, an optional HTML-string _...
SymbolFullProps & addMathOperatorUnicode(const QString &_symbol, double _fontScalingFactor=1.0, double _yShiftFactor=0.0)
QHash< JKQTMathTextFontEncoding, SymbolProps > props
here the actual symbol properties for each JKQTMathTextFontEncoding are stored
Definition jkqtmathtextsymbolnode.h:226
SymbolFullProps & addStd(const QString &_symbol, SymbolFlags _flags=AsOutside, double _fontScalingFactor=1.0, double _yShiftFactor=0.0)
SymbolFullProps(JKQTMathTextEnvironmentFont _fontType, JKQTMathTextFontEncoding enc0, const SymbolProps &props0, const QString &_html=QString(), SymbolFlags _htmlflags=AsOutside, double _htmlfontScalingFactor=1.0, double _htmlyShiftFactor=0.0)
single-alternative symbol for encoding enc0 and using symbol description props0 for it,...
SymbolFullProps(JKQTMathTextFontEncoding enc0, const SymbolProps &props0, JKQTMathTextFontEncoding enc1, const SymbolProps &props1, JKQTMathTextFontEncoding enc2, const SymbolProps &props2, const QString &_html=QString(), SymbolFlags _htmlflags=AsOutside, double _htmlfontScalingFactor=1.0, double _htmlyShiftFactor=0.0)
triple-alternative symbol for encoding enc0 + enc1 + enc2 and using symbol descriptions props0 + prop...
SymbolFullProps(JKQTMathTextFontEncoding enc0, const SymbolProps &props0, const QString &_html=QString(), SymbolFlags _htmlflags=AsOutside, double _htmlfontScalingFactor=1.0, double _htmlyShiftFactor=0.0)
single-alternative symbol for encoding enc0 and using symbol description props0 for it....
SymbolFullProps(const SymbolFullProps &other)=default
SymbolFullProps & add(JKQTMathTextFontEncoding enc, const SymbolProps &props)
SymbolFullProps & addUnicode(const QString &_symbol, SymbolFlags _flags=AsOutside, double _fontScalingFactor=1.0, double _yShiftFactor=0.0)
SymbolProps html
HTML entity/text to represent the symbol (empty html.symbol not available)
Definition jkqtmathtextsymbolnode.h:228
SymbolFullProps & addWinSymbol(const QString &_symbol, SymbolFlags _flags=AsOutside, double _fontScalingFactor=1.0, double _yShiftFactor=0.0)
SymbolFullProps & addUprightHtml(const QString &_symbol, double _fontScalingFactor=1.0, double _yShiftFactor=0.0)
SymbolFullProps & setGlobalFlags(GlobalSymbolFlags addglobalFlags)
SymbolFullProps(const SymbolProps &props, const QString &_html=QString(), SymbolFlags _htmlflags=AsOutside, double _htmlfontScalingFactor=1.0, double _htmlyShiftFactor=0.0)
props is stored with encoding MTFEStandard, an optional HTML-string _html can be given
SymbolFullProps & addUprightStd(const QString &_symbol, double _fontScalingFactor=1.0, double _yShiftFactor=0.0)
SymbolFullProps & addMathOperatorWinSymbol(const QString &_symbol, double _fontScalingFactor=1.0, double _yShiftFactor=0.0)
SymbolFullProps & addUprightWinSymbol(const QString &_symbol, double _fontScalingFactor=1.0, double _yShiftFactor=0.0)
SymbolFullProps(JKQTMathTextEnvironmentFont _fontType, JKQTMathTextFontEncoding enc0, const SymbolProps &props0, JKQTMathTextFontEncoding enc1, const SymbolProps &props1, const QString &_html=QString(), SymbolFlags _htmlflags=AsOutside, double _htmlfontScalingFactor=1.0, double _htmlyShiftFactor=0.0)
double-alternative symbol for encoding enc0 + enc1 and using symbol descriptions props0 + props1 for ...
SymbolFullProps & addUprightUnicode(const QString &_symbol, double _fontScalingFactor=1.0, double _yShiftFactor=0.0)
SymbolFullProps(SymbolFullProps &&other)=default
SymbolFullProps(JKQTMathTextEnvironmentFont _fontType, JKQTMathTextFontEncoding enc0, const SymbolProps &props0, JKQTMathTextFontEncoding enc1, const SymbolProps &props1, JKQTMathTextFontEncoding enc2, const SymbolProps &props2, const QString &_html=QString(), SymbolFlags _htmlflags=AsOutside, double _htmlfontScalingFactor=1.0, double _htmlyShiftFactor=0.0)
triple-alternative symbol for encoding enc0 + enc1 + enc2 and using symbol descriptions props0 + prop...
SymbolFullProps(JKQTMathTextFontEncoding enc0, const SymbolProps &props0, JKQTMathTextFontEncoding enc1, const SymbolProps &props1, const QString &_html=QString(), SymbolFlags _htmlflags=AsOutside, double _htmlfontScalingFactor=1.0, double _htmlyShiftFactor=0.0)
double-alternative symbol for encoding enc0 + enc1 and using symbol descriptions props0 + props1 for ...
SymbolFullProps & addGlobalFlags(GlobalSymbolFlags addglobalFlags)
QString customFontFamily
font to use for output when fontType==MTcustomFont
Definition jkqtmathtextsymbolnode.h:224
SymbolFullProps(const QString &font, const QString &symbol, const QString &_html=QString(), SymbolFlags _htmlflags=AsOutside, double _htmlfontScalingFactor=1.0, double _htmlyShiftFactor=0.0)
typesets the symbol from the specified font, props is stored with encoding MTFEStandard,...
GlobalSymbolFlags globalFlags
specifies global symbol flags
Definition jkqtmathtextsymbolnode.h:230
SymbolFullProps & addHtml(const QString &_symbol, SymbolFlags _flags=AsOutside, double _fontScalingFactor=1.0, double _yShiftFactor=0.0)
SymbolFullProps & addMathOperatorStd(const QString &_symbol, double _fontScalingFactor=1.0, double _yShiftFactor=0.0)
properties of the symbol
Definition jkqtmathtextsymbolnode.h:166
double yShiftFactor
this corrects the y position of a symbol: draws at y <- y+ height*yfactor)
Definition jkqtmathtextsymbolnode.h:188
SymbolProps(const QString &_symbol, SymbolFlags _flags=AsOutside, double _fontScalingFactor=1.0, double _yShiftFactor=0.0)
this constructor sets the given properties and sets html=symbol! replaces whitespaces in _ymbol with ...
SymbolProps & operator=(SymbolProps &&other)=default
SymbolFlags flags
flags switching special features
Definition jkqtmathtextsymbolnode.h:184
SymbolProps(const SymbolProps &other)=default
QString symbol
the symbol or text used to render the symbol (i.e. not the name, e.g. if the instruction/symbol name ...
Definition jkqtmathtextsymbolnode.h:177
SymbolProps & operator=(const SymbolProps &other)=default
QChar getSymbolSingleChar() const
if symbol is a single character, this returns it, otherwise (empty or multi-character) it returns QCh...
Definition jkqtmathtextsymbolnode.h:179
double fontScalingFactor
magnification factor for the font size
Definition jkqtmathtextsymbolnode.h:186
SymbolProps(SymbolProps &&other)=default