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
jkqtmathtextwhitespacenode.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 JKQTMATHTEXTWHITESPACENODE_H
25#define JKQTMATHTEXTWHITESPACENODE_H
26#include "jkqtmathtext/jkqtmathtext_imexport.h"
27#include "jkqtmathtext/jkqtmathtexttools.h"
28#include "jkqtmathtext/nodes/jkqtmathtextnode.h"
29#include "jkqtmathtext/nodes/jkqtmathtextinstructionnode.h"
30#include <QPainter>
31
32class JKQTMathText; // forward
33
34
35/** \brief subclass representing one whitepsace node in the syntax tree
36 * \ingroup jkqtmathtext_items
37 *
38 * It can represent different types of spaces, see Types and different multiples of that space.
39 * so \c JKQTMathTextWhitespaceNode(WST1em,2,parent) will represent two 1em wide spaces, i.e. a 2em space.
40 */
42 public:
43 enum Types {
44 WSTNormal, /*!< \brief a normal-width whitespace */
45 WSTNonbreaking, /*!< \brief a normal-width, non-breaking whitespace */
46 WST1en, /*!< \brief 1en (= 0.5 * pointsize of the font) whitespace */
47 WST1em, /*!< \brief 1em (= pointsize of the font) whitespace */
48 WSTQuad=WST1em, /*!< \copydoc WST1em */
49 WSThair, /*!< \brief hair (thinner than thin) whitespace (1/12 em = pointsize/12) */
50 WSTthin, /*!< \brief thin whitespace (1/6 em = pointsize/6) */
51 WSTnegthin, /*!< \brief negative thin whitespace (-1/6 em = -pointsize/6) */
52 WSTmedium, /*!< \brief medium whitespace (2/9 em = pointsize*2/9) */
53 WSTnegmedium, /*!< \brief negative medium whitespace (-2/9 em = -pointsize*2/9) */
54 WSTthick, /*!< \brief thick whitespace (5/18 em = pointsize*5/18) */
55 WSTnegthick, /*!< \brief negative thick whitespace (-5/18 em = -pointsize*5/18) */
56 WSTthicker, /*!< \brief thicker whitespace (1/3 em = pointsize/3) */
57
58 };
59 /** \brief converts Types \a type into a string */
60 static QString Type2String(Types type);
61 /** \brief converts Types \a type into its width in pixels, based on \a currentEv and \a pd */
62 double Type2PixelWidth(Types type, JKQTMathTextEnvironment currentEv, QPaintDevice *pd) const;
63 /** \brief checks whether a given LaTeX instruction name is supported by this node class type */
64 static bool supportsInstructionName(const QString& instruction);
65 /** \brief constructs a node with count=1 and type=WSTNormal */
67 /** \brief constructs a node with count=1 and the width derived from the instruction name \a type */
68 explicit JKQTMathTextWhitespaceNode(const QString& type, JKQTMathText* parent);
69 /** \brief constructs a node with the specified \a count and the width derived from the instruction name \a type */
70 explicit JKQTMathTextWhitespaceNode(const QString& type, size_t count, JKQTMathText* parent);
71 /** \brief constructs a node with count=1 and the given \a type */
73 /** \brief constructs a node with the given \a type and \a count */
74 explicit JKQTMathTextWhitespaceNode(Types type, size_t cound, JKQTMathText* parent);
75 virtual ~JKQTMathTextWhitespaceNode() override;
76 /** \copydoc JKQTMathTextNode::getTypeName() */
77 virtual QString getTypeName() const override;
78 /** \copydoc JKQTMathTextNode::toHtml() */
79 virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const override;
80 /** \copydoc WhitespaceProps::type */
82 /** \copydoc WhitespaceProps::count */
83 size_t getWhitespaceCount() const;
84 /** \copydoc JKQTMathTextNode::draw() */
85 virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) const override;
86 protected:
87 /** \copydoc JKQTMathTextNode::getSizeInternal() */
88 virtual JKQTMathTextNodeSize getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv) const override;
89 /** \brief describes a whitespace */
91 WhitespaceProps(Types type=WSTNormal, size_t count=1);
94 /** \brief type of the whitespace represented by this node */
96 /** \brief number of whitespaces of the given type, represented by this node (default: 1) */
97 size_t count;
98 };
99 /** \brief properties of the whitespace represented by this node */
101 /** \brief converts Types \a type into its HTML representation */
102 static QString Type2HTML(Types type);
103 /** \brief translation table between latex instruction and WhitespaceProps
104 *
105 * \note This is a customization point for additional whitespace instructions!
106 */
107 static const QHash<QString, WhitespaceProps>& supportedInstructions();
108};
109
110
111/** \brief subclass representing an empty bbox with defined width/height in the syntax tree
112 * \ingroup jkqtmathtext_items
113 *
114 */
116 public:
117 enum Units {
118 EBUem, /*!< \brief 1em = width('M') */
119 EBUex, /*!< \brief 1ex = xHeight */
120 };
121 /** \brief converts Types \a type into a string */
122 static QString Units2String(Units type);
123 /** \brief converts Types \a type into a string */
124 static Units String2Units(QString type);
125 /** \brief converts Types \a type into its width in pixels, based on \a currentEv and \a pd */
126 double Units2PixelWidth(double value, Units unit, JKQTMathTextEnvironment currentEv, QPaintDevice *pd) const;
127 /** \brief constructs a node */
128 explicit JKQTMathTextEmptyBoxNode(JKQTMathText* parent, double width_, Units widthUnit_, double height_, Units heightUnit_);
129 virtual ~JKQTMathTextEmptyBoxNode() override;
130 /** \copydoc JKQTMathTextNode::getTypeName() */
131 virtual QString getTypeName() const override;
132 /** \copydoc JKQTMathTextNode::toHtml() */
133 virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const override;
134 /** \copydoc widthUnit */
136 /** \copydoc width */
137 double getWidth() const;
138 /** \copydoc heightUnit */
140 /** \copydoc height */
141 double getHeight() const;
142 /** \copydoc JKQTMathTextNode::draw() */
143 virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) const override;
144 protected:
145 /** \copydoc JKQTMathTextNode::getSizeInternal() */
146 virtual JKQTMathTextNodeSize getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv) const override;
147 /** \brief width of the (empty) box, units of this value defined in widthUnit */
148 double width;
149 /** \brief units to interpret width */
151 /** \brief height of the (empty) box, units of this value defined in heightUnit */
152 double height;
153 /** \brief units to interpret height */
155};
156
157
158
159
160/** \brief generates whitespace with the size of the contained node
161 * \ingroup jkqtmathtext_items
162 */
164 public:
165 /** \brief type of the phantom instrcution */
166 enum Mode {
167 FMwidthAndHeight, /*!< \brief implementes \c \\phantom{CHILD} which is whitespace in the width and height of \c CHILD */
168 FMwidth, /*!< \brief implementes \c \\hphantom{CHILD} which is whitespace in the width of \c CHILD and height 0. */
169 FMheight /*!< \brief implementes \c \\vphantom{CHILD} which is whitespace in the height of \c CHILD and width 0. */
170 };
171 /** \brief convert a Mode into a LaTeX instruction name */
172 static QString Mode2Instruction(Mode mode);
173 explicit JKQTMathTextPhantomNode(JKQTMathText* parent, const QString& mode, JKQTMathTextNode* child);
175 virtual ~JKQTMathTextPhantomNode() override;
176 /** \copydoc JKQTMathTextNode::getTypeName() */
177 virtual QString getTypeName() const override;
178 /** \copydoc JKQTMathTextNode::draw() */
179 virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) const override;
180 /** \copydoc JKQTMathTextNode::toHtml() */
181 virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const override;
182
183 /** \brief returns true, if the given \a instructionName can be represented by this node
184 * \see instructions
185 */
186 static bool supportsInstructionName(const QString& instructionName);
187
188 protected:
189 /** \copydoc JKQTMathTextNode::getSizeInternal() */
190 virtual JKQTMathTextNodeSize getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv) const override;
191 /** \brief defines all implemented instructions in this node
192 *
193 * \note this is the customization point for new instructions!
194 */
195 static const QHash<QString, Mode>& instructions();
196};
197#endif // JKQTMATHTEXTWHITESPACENODE_H
198
199
200
201
202
203
204
205
206
subclass representing an empty bbox with defined width/height in the syntax tree
Definition jkqtmathtextwhitespacenode.h:115
Units getHeightUnit() const
units to interpret height
double height
height of the (empty) box, units of this value defined in heightUnit
Definition jkqtmathtextwhitespacenode.h:152
double Units2PixelWidth(double value, Units unit, JKQTMathTextEnvironment currentEv, QPaintDevice *pd) const
converts Types type into its width in pixels, based on currentEv and pd
virtual double draw(QPainter &painter, double x, double y, JKQTMathTextEnvironment currentEv) const override
draw the contents at the designated position
double getWidth() const
width of the (empty) box, units of this value defined in widthUnit
Units getWidthUnit() const
units to interpret width
virtual QString getTypeName() const override
return the name of this class as a string
double width
width of the (empty) box, units of this value defined in widthUnit
Definition jkqtmathtextwhitespacenode.h:148
virtual bool toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const override
convert node to HTML and returns true on success
double getHeight() const
height of the (empty) box, units of this value defined in heightUnit
Units
Definition jkqtmathtextwhitespacenode.h:117
@ EBUex
1ex = xHeight
Definition jkqtmathtextwhitespacenode.h:119
@ EBUem
1em = width('M')
Definition jkqtmathtextwhitespacenode.h:118
JKQTMathTextEmptyBoxNode(JKQTMathText *parent, double width_, Units widthUnit_, double height_, Units heightUnit_)
constructs a node
virtual ~JKQTMathTextEmptyBoxNode() override
Units heightUnit
units to interpret height
Definition jkqtmathtextwhitespacenode.h:154
virtual JKQTMathTextNodeSize getSizeInternal(QPainter &painter, JKQTMathTextEnvironment currentEv) const override
determine the size of the node, overwrite this function in derived classes
static Units String2Units(QString type)
converts Types type into a string
static QString Units2String(Units type)
converts Types type into a string
Units widthUnit
units to interpret width
Definition jkqtmathtextwhitespacenode.h:150
this class parses a mathematical markup string and can then draw the contained text/equation onto a Q...
Definition jkqtmathtext.h:192
subclass representing an instruction node with exactly one argument and possibly additional parameter...
Definition jkqtmathtextinstructionnode.h:45
subclass representing one node in the syntax tree
Definition jkqtmathtextnode.h:37
generates whitespace with the size of the contained node
Definition jkqtmathtextwhitespacenode.h:163
virtual QString getTypeName() const override
return the name of this class as a string
static bool supportsInstructionName(const QString &instructionName)
returns true, if the given instructionName can be represented by this node
JKQTMathTextPhantomNode(JKQTMathText *parent, const QString &mode, JKQTMathTextNode *child)
JKQTMathTextPhantomNode(JKQTMathText *parent, Mode mode, JKQTMathTextNode *child)
virtual bool toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const override
convert node to HTML and returns true on success
virtual double draw(QPainter &painter, double x, double y, JKQTMathTextEnvironment currentEv) const override
draw the contents at the designated position
virtual JKQTMathTextNodeSize getSizeInternal(QPainter &painter, JKQTMathTextEnvironment currentEv) const override
determine the size of the node, overwrite this function in derived classes
Mode
type of the phantom instrcution
Definition jkqtmathtextwhitespacenode.h:166
@ FMwidth
implementes \hphantom{CHILD} which is whitespace in the width of CHILD and height 0.
Definition jkqtmathtextwhitespacenode.h:168
@ FMwidthAndHeight
implementes \phantom{CHILD} which is whitespace in the width and height of CHILD
Definition jkqtmathtextwhitespacenode.h:167
static const QHash< QString, Mode > & instructions()
defines all implemented instructions in this node
virtual ~JKQTMathTextPhantomNode() override
static QString Mode2Instruction(Mode mode)
convert a Mode into a LaTeX instruction name
subclass representing one whitepsace node in the syntax tree
Definition jkqtmathtextwhitespacenode.h:41
Types getWhitespaceType() const
type of the whitespace represented by this node
JKQTMathTextWhitespaceNode(JKQTMathText *parent)
constructs a node with count=1 and type=WSTNormal
JKQTMathTextWhitespaceNode(const QString &type, JKQTMathText *parent)
constructs a node with count=1 and the width derived from the instruction name type
WhitespaceProps whitespace
properties of the whitespace represented by this node
Definition jkqtmathtextwhitespacenode.h:100
static const QHash< QString, WhitespaceProps > & supportedInstructions()
translation table between latex instruction and WhitespaceProps
static bool supportsInstructionName(const QString &instruction)
checks whether a given LaTeX instruction name is supported by this node class type
virtual JKQTMathTextNodeSize getSizeInternal(QPainter &painter, JKQTMathTextEnvironment currentEv) const override
determine the size of the node, overwrite this function in derived classes
double Type2PixelWidth(Types type, JKQTMathTextEnvironment currentEv, QPaintDevice *pd) const
converts Types type into its width in pixels, based on currentEv and pd
Types
Definition jkqtmathtextwhitespacenode.h:43
@ WSThair
hair (thinner than thin) whitespace (1/12 em = pointsize/12)
Definition jkqtmathtextwhitespacenode.h:49
@ WSTthicker
thicker whitespace (1/3 em = pointsize/3)
Definition jkqtmathtextwhitespacenode.h:56
@ WST1en
1en (= 0.5 * pointsize of the font) whitespace
Definition jkqtmathtextwhitespacenode.h:46
@ WSTnegthin
negative thin whitespace (-1/6 em = -pointsize/6)
Definition jkqtmathtextwhitespacenode.h:51
@ WSTmedium
medium whitespace (2/9 em = pointsize*2/9)
Definition jkqtmathtextwhitespacenode.h:52
@ WSTNormal
a normal-width whitespace
Definition jkqtmathtextwhitespacenode.h:44
@ WST1em
1em (= pointsize of the font) whitespace
Definition jkqtmathtextwhitespacenode.h:47
@ WSTnegthick
negative thick whitespace (-5/18 em = -pointsize*5/18)
Definition jkqtmathtextwhitespacenode.h:55
@ WSTnegmedium
negative medium whitespace (-2/9 em = -pointsize*2/9)
Definition jkqtmathtextwhitespacenode.h:53
@ WSTthin
thin whitespace (1/6 em = pointsize/6)
Definition jkqtmathtextwhitespacenode.h:50
@ WSTNonbreaking
a normal-width, non-breaking whitespace
Definition jkqtmathtextwhitespacenode.h:45
@ WSTthick
thick whitespace (5/18 em = pointsize*5/18)
Definition jkqtmathtextwhitespacenode.h:54
static QString Type2String(Types type)
converts Types type into a string
static QString Type2HTML(Types type)
converts Types type into its HTML representation
virtual ~JKQTMathTextWhitespaceNode() override
virtual double draw(QPainter &painter, double x, double y, JKQTMathTextEnvironment currentEv) const override
draw the contents at the designated position
virtual QString getTypeName() const override
return the name of this class as a string
JKQTMathTextWhitespaceNode(Types type, JKQTMathText *parent)
constructs a node with count=1 and the given type
virtual bool toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const override
convert node to HTML and returns true on success
JKQTMathTextWhitespaceNode(const QString &type, size_t count, JKQTMathText *parent)
constructs a node with the specified count and the width derived from the instruction name type
JKQTMathTextWhitespaceNode(Types type, size_t cound, JKQTMathText *parent)
constructs a node with the given type and count
size_t getWhitespaceCount() const
number of whitespaces of the given type, represented by this node (default: 1)
#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 a whitespace
Definition jkqtmathtextwhitespacenode.h:90
Types type
type of the whitespace represented by this node
Definition jkqtmathtextwhitespacenode.h:95
size_t count
number of whitespaces of the given type, represented by this node (default: 1)
Definition jkqtmathtextwhitespacenode.h:97
WhitespaceProps & operator=(const WhitespaceProps &other)
WhitespaceProps(const WhitespaceProps &other)
WhitespaceProps(Types type=WSTNormal, size_t count=1)