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
jkqtmathtexttextnode.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 JKQTMATHTEXTTEXTNODE_H
25#define JKQTMATHTEXTTEXTNODE_H
26#include "jkqtmathtext/jkqtmathtext_imexport.h"
27#include "jkqtmathtext/jkqtmathtexttools.h"
28#include "jkqtmathtext/nodes/jkqtmathtextnode.h"
29#include <QPainter>
30
31class JKQTMathText; // forward
32// JKQTMATHTEXT_LIB_EXPORT
33
34
35/** \brief base class for nodes representing text in the syntax tree
36 * \ingroup jkqtmathtext_items
37 *
38 * This node is a collection of tools, necessary to draw text. It
39 * is the base for nodes, such as:
40 * - JKQTMathTextTextNode
41 * - JKQTMathTextVerbatimNode
42 * .
43 */
45 public:
46 explicit JKQTMathTextTextBaseNode(JKQTMathText* parent, const QString& text);
47 virtual ~JKQTMathTextTextBaseNode() override;
48 /** \copydoc JKQTMathTextNode::toHtml() */
49 virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const override;
50 /** \copydoc text */
51 QString getText() const;
52 protected:
53 /** \brief text-contents of the node */
54 QString text;
55 /** \brief transforms the \a text before sizing/drawing (may e.g. exchange special letters for other unicode symbols etc.) */
56 virtual QString textTransform(const QString& text, const JKQTMathTextEnvironment& currentEv) const;
57};
58
59
60/** \brief subclass representing one text node in the syntax tree
61 * \ingroup jkqtmathtext_items
62 */
64 public:
65 explicit JKQTMathTextTextNode(JKQTMathText* parent, const QString& text, bool addWhitespace, bool stripInnerWhitepace=false);
66 virtual ~JKQTMathTextTextNode() override;
67 /** \copydoc JKQTMathTextNode::draw() */
68 virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) const override;
69 /** \copydoc JKQTMathTextNode::getTypeName() */
70 virtual QString getTypeName() const override ;
71 /** \brief remove trailing whitespace, is used by simplifyJKQTMathTextNode() */
73 /** \brief remove leading whitespace, is used by simplifyJKQTMathTextNode() */
75 protected:
76 /** \brief defines how a character shold be drawn, used by splitTextForLayout */
77 enum FontMode {
78 FMasDefined, /*!< \brief use current font */
79 FMasDefinedForceUpright, /*!< \brief use current font, but force it upright (e.g. for digits in math mode) */
80 FMasDefinedOutline, /*!< \brief use current font and draw as outline, e.g. used for simulating blackboard fonts */
81 FMroman, /*!< \brief use JKQTMathText::getFontRoman() */
82 FMfallbackSymbol, /*!< \brief use JKQTMathText::getFallbackFontSymbols() */
83 };
84 /** \copydoc JKQTMathTextNode::getSizeInternal() */
85 virtual JKQTMathTextNodeSize getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv) const override;
86
87 /** \brief describes the layout of the whole node */
90 LayoutInfo(const LayoutInfo& other);
94 /** \brief the text that shall be printed is split up into different parts (with different formatting each) */
95 QStringList textpart;
96 /** \brief formatting for each entry in textpart */
97 QList<FontMode> fontMode;
98 /** \brief drawing x-position for each entry in textpart */
99 QList<double> textpartXPos;
100 };
101 /** \brief calculates the size of the node, much like JKQTMathTextNode::getSizeInternal(), but returns additional properties that can be reused for drawing */
102 LayoutInfo calcLayout(QPainter& painter, JKQTMathTextEnvironment currentEv) const ;
103 /** \brief split text for Math-Modelayout into sections, where each section has a defined way of output
104 *
105 * \param painter the QPainter to use for sizing/drawing
106 * \param currentEv the environment that defines the formatting of the text
107 * \param txt the text to split up
108 * \param[out] textpart the input \a txt split up into sections
109 * \param[out] fontMode formating of each section in \a textpart
110 */
111 void splitTextForLayout(QPainter &painter, JKQTMathTextEnvironment currentEv, const QString& txt, QStringList& textpart, QList<FontMode>& fontMode) const;
112 /** \brief translation table for blackboard-font characters from "normal" Latin-1 encoding to unicode-encoding of blackboards */
113 static const QHash<QChar, uint32_t>& blackboardUnicodeTable();
114 /** \copydoc JKQTMathTextTextBaseNode::textTransform() */
115 virtual QString textTransform(const QString& text, const JKQTMathTextEnvironment& currentEv) const override;
116};
117
118
119#endif // JKQTMATHTEXTTEXTNODE_H
120
121
122
123
124
125
126
127
128
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
base class for nodes representing text in the syntax tree
Definition jkqtmathtexttextnode.h:44
virtual bool toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const override
convert node to HTML and returns true on success
JKQTMathTextTextBaseNode(JKQTMathText *parent, const QString &text)
virtual QString textTransform(const QString &text, const JKQTMathTextEnvironment &currentEv) const
transforms the text before sizing/drawing (may e.g. exchange special letters for other unicode symbol...
QString text
text-contents of the node
Definition jkqtmathtexttextnode.h:54
virtual ~JKQTMathTextTextBaseNode() override
QString getText() const
text-contents of the node
subclass representing one text node in the syntax tree
Definition jkqtmathtexttextnode.h:63
virtual JKQTMathTextNodeSize getSizeInternal(QPainter &painter, JKQTMathTextEnvironment currentEv) const override
determine the size of the node, overwrite this function in derived classes
void splitTextForLayout(QPainter &painter, JKQTMathTextEnvironment currentEv, const QString &txt, QStringList &textpart, QList< FontMode > &fontMode) const
split text for Math-Modelayout into sections, where each section has a defined way of output
FontMode
defines how a character shold be drawn, used by splitTextForLayout
Definition jkqtmathtexttextnode.h:77
@ FMasDefined
use current font
Definition jkqtmathtexttextnode.h:78
@ FMfallbackSymbol
use JKQTMathText::getFallbackFontSymbols()
Definition jkqtmathtexttextnode.h:82
@ FMasDefinedOutline
use current font and draw as outline, e.g. used for simulating blackboard fonts
Definition jkqtmathtexttextnode.h:80
@ FMroman
use JKQTMathText::getFontRoman()
Definition jkqtmathtexttextnode.h:81
@ FMasDefinedForceUpright
use current font, but force it upright (e.g. for digits in math mode)
Definition jkqtmathtexttextnode.h:79
virtual QString textTransform(const QString &text, const JKQTMathTextEnvironment &currentEv) const override
transforms the text before sizing/drawing (may e.g. exchange special letters for other unicode symbol...
JKQTMathTextTextNode(JKQTMathText *parent, const QString &text, bool addWhitespace, bool stripInnerWhitepace=false)
void removeLeadingWhitespace()
remove leading whitespace, is used by simplifyJKQTMathTextNode()
static const QHash< QChar, uint32_t > & blackboardUnicodeTable()
translation table for blackboard-font characters from "normal" Latin-1 encoding to unicode-encoding o...
void removeTrailingWhitespace()
remove trailing whitespace, is used by simplifyJKQTMathTextNode()
virtual ~JKQTMathTextTextNode() override
LayoutInfo calcLayout(QPainter &painter, JKQTMathTextEnvironment currentEv) const
calculates the size of the node, much like JKQTMathTextNode::getSizeInternal(), but returns additiona...
virtual QString getTypeName() const override
return the name of this class as a string
virtual double draw(QPainter &painter, double x, double y, JKQTMathTextEnvironment currentEv) const override
draw the contents at the designated position
#define JKQTMATHTEXT_LIB_EXPORT
Definition jkqtmathtext_imexport.h:108
describes the current drawing environment (base fontname ...)
Definition jkqtmathtexttools.h:304
beschreibt die Größe(n) eines Knotens
Definition jkqtmathtexttools.h:393
describes the layout of the whole node
Definition jkqtmathtexttextnode.h:88
LayoutInfo & operator=(const JKQTMathTextNodeSize &other)
QStringList textpart
the text that shall be printed is split up into different parts (with different formatting each)
Definition jkqtmathtexttextnode.h:95
QList< FontMode > fontMode
formatting for each entry in textpart
Definition jkqtmathtexttextnode.h:97
LayoutInfo & operator=(const LayoutInfo &other)
LayoutInfo(const LayoutInfo &other)
LayoutInfo(const JKQTMathTextNodeSize &other)
QList< double > textpartXPos
drawing x-position for each entry in textpart
Definition jkqtmathtexttextnode.h:99