2022-08-03 21:23:14 +08:00
/*
2022-06-08 21:38:26 +08:00
Copyright ( c ) 2008 - 2022 Jan W . Krieger ( < jan @ jkrieger . de > )
with contributions from : Razi Alavizadeh
This software is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License ( LGPL ) as published by
the Free Software Foundation , either version 2.1 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License ( LGPL ) for more details .
You should have received a copy of the GNU Lesser General Public License ( LGPL )
along with this program . If not , see < http : //www.gnu.org/licenses/>.
*/
# ifndef JKQTMATHTEXTTEXTNODE_H
# define JKQTMATHTEXTTEXTNODE_H
# include "jkqtmathtext/jkqtmathtext_imexport.h"
# include "jkqtmathtext/jkqtmathtexttools.h"
# include "jkqtmathtext/nodes/jkqtmathtextnode.h"
# include <QPainter>
class JKQTMathText ; // forward
// JKQTMATHTEXT_LIB_EXPORT
2022-08-03 21:23:14 +08:00
/** \brief base class for nodes representing text in the syntax tree
* \ ingroup jkqtmathtext_items
*
* This node is a collection of tools , necessary to draw text . It
* is the base for nodes , such as :
* - JKQTMathTextTextNode
* - JKQTMathTextVerbatimNode
* .
*/
class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextTextBaseNode : public JKQTMathTextNode {
public :
explicit JKQTMathTextTextBaseNode ( JKQTMathText * parent , const QString & text ) ;
virtual ~ JKQTMathTextTextBaseNode ( ) override ;
/** \copydoc JKQTMathTextNode::toHtml() */
2022-08-17 05:05:04 +08:00
virtual bool toHtml ( QString & html , JKQTMathTextEnvironment currentEv , JKQTMathTextEnvironment defaultEv ) const override ;
2022-08-03 21:23:14 +08:00
/** \copydoc text */
QString getText ( ) const ;
protected :
/** \brief text-contents of the node */
QString text ;
/** \brief transforms the \a text before sizing/drawing (may e.g. exchange special letters for other unicode symbols etc.) */
virtual QString textTransform ( const QString & text , const JKQTMathTextEnvironment & currentEv ) const ;
} ;
2022-06-08 21:38:26 +08:00
/** \brief subclass representing one text node in the syntax tree
* \ ingroup jkqtmathtext_items
*/
2022-08-03 21:23:14 +08:00
class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextTextNode : public JKQTMathTextTextBaseNode {
2022-06-08 21:38:26 +08:00
public :
explicit JKQTMathTextTextNode ( JKQTMathText * parent , const QString & text , bool addWhitespace , bool stripInnerWhitepace = false ) ;
virtual ~ JKQTMathTextTextNode ( ) override ;
/** \copydoc JKQTMathTextNode::draw() */
2022-08-17 05:05:04 +08:00
virtual double draw ( QPainter & painter , double x , double y , JKQTMathTextEnvironment currentEv ) const override ;
2022-06-08 21:38:26 +08:00
/** \copydoc JKQTMathTextNode::getTypeName() */
virtual QString getTypeName ( ) const override ;
2022-08-12 18:54:10 +08:00
/** \brief remove trailing whitespace, is used by simplifyJKQTMathTextNode() */
void removeTrailingWhitespace ( ) ;
/** \brief remove leading whitespace, is used by simplifyJKQTMathTextNode() */
void removeLeadingWhitespace ( ) ;
2022-06-08 21:38:26 +08:00
protected :
2022-08-10 18:12:30 +08:00
/** \brief defines how a character shold be drawn, used by splitTextForLayout */
enum FontMode {
2022-08-14 01:47:35 +08:00
FMasDefined , /*!< \brief use current font */
FMasDefinedForceUpright , /*!< \brief use current font, but force it upright (e.g. for digits in math mode) */
FMasDefinedOutline , /*!< \brief use current font and draw as outline, e.g. used for simulating blackboard fonts */
FMroman , /*!< \brief use JKQTMathText::getFontRoman() */
FMfallbackSymbol , /*!< \brief use JKQTMathText::getFallbackFontSymbols() */
2022-08-10 18:12:30 +08:00
} ;
2022-06-08 21:38:26 +08:00
/** \copydoc JKQTMathTextNode::getSizeInternal() */
2022-08-17 05:05:04 +08:00
virtual JKQTMathTextNodeSize getSizeInternal ( QPainter & painter , JKQTMathTextEnvironment currentEv ) const override ;
/** \brief describes the layout of the whole node */
struct LayoutInfo : public JKQTMathTextNodeSize {
LayoutInfo ( ) ;
LayoutInfo ( const LayoutInfo & other ) ;
LayoutInfo ( const JKQTMathTextNodeSize & other ) ;
LayoutInfo & operator = ( const JKQTMathTextNodeSize & other ) ;
LayoutInfo & operator = ( const LayoutInfo & other ) ;
/** \brief the text that shall be printed is split up into different parts (with different formatting each) */
QStringList textpart ;
/** \brief formatting for each entry in textpart */
QList < FontMode > fontMode ;
/** \brief drawing x-position for each entry in textpart */
QList < double > textpartXPos ;
} ;
2022-08-02 18:16:10 +08:00
/** \brief calculates the size of the node, much like JKQTMathTextNode::getSizeInternal(), but returns additional properties that can be reused for drawing */
2022-08-17 05:05:04 +08:00
LayoutInfo calcLayout ( QPainter & painter , JKQTMathTextEnvironment currentEv ) const ;
2022-08-10 18:12:30 +08:00
/** \brief split text for Math-Modelayout into sections, where each section has a defined way of output
*
* \ param painter the QPainter to use for sizing / drawing
* \ param currentEv the environment that defines the formatting of the text
* \ param txt the text to split up
2022-09-20 03:53:53 +08:00
* \ param [ out ] textpart the input \ a txt split up into sections
2022-08-10 18:12:30 +08:00
* \ param [ out ] fontMode formating of each section in \ a textpart
*/
void splitTextForLayout ( QPainter & painter , JKQTMathTextEnvironment currentEv , const QString & txt , QStringList & textpart , QList < FontMode > & fontMode ) const ;
/** \brief translation table for blackboard-font characters from "normal" Latin-1 encoding to unicode-encoding of blackboards */
2024-01-06 06:26:47 +08:00
static const QHash < QChar , uint32_t > & blackboardUnicodeTable ( ) ;
2022-08-10 18:12:30 +08:00
/** \copydoc JKQTMathTextTextBaseNode::textTransform() */
2022-08-03 21:23:14 +08:00
virtual QString textTransform ( const QString & text , const JKQTMathTextEnvironment & currentEv ) const override ;
2022-06-08 21:38:26 +08:00
} ;
2022-08-03 21:23:14 +08:00
2022-06-08 21:38:26 +08:00
# endif // JKQTMATHTEXTTEXTNODE_H