JKQTMathText:

NEW: added \c \\snugshade{...}
  NEW: added \c \\snugbox{...}
  NEW: added \c \\phantom{xXy} , \c \\vphantom{xXy} and \c \\hphantom{xXy} instructions for whitespaces with the size of \c xXy
This commit is contained in:
jkriege2 2022-08-10 14:36:16 +02:00
parent 5283a1a995
commit 868b89a99e
14 changed files with 185 additions and 1 deletions

View File

@ -60,6 +60,7 @@
These instructions draw boxes in various ways: These instructions draw boxes in various ways:
- \c \\boxed{...} : draw text with a box around it \image html jkqtmathtext/jkqtmathtext_boxed.png - \c \\boxed{...} : draw text with a box around it \image html jkqtmathtext/jkqtmathtext_boxed.png
- \c \\snugbox{...} : draw text with a snug box around it \image html jkqtmathtext/jkqtmathtext_snugbox.png
- \c \\doublebox{...} : draw text with a rounded box around it \image html jkqtmathtext/jkqtmathtext_doublebox.png - \c \\doublebox{...} : draw text with a rounded box around it \image html jkqtmathtext/jkqtmathtext_doublebox.png
- \c \\ovalbox{...} : draw text with a rounded box around it \image html jkqtmathtext/jkqtmathtext_ovalboxed.png - \c \\ovalbox{...} : draw text with a rounded box around it \image html jkqtmathtext/jkqtmathtext_ovalboxed.png
- \c \\Ovalbox{...} : draw a thick oval box \image html jkqtmathtext/jkqtmathtext_oovalbox.png - \c \\Ovalbox{...} : draw a thick oval box \image html jkqtmathtext/jkqtmathtext_oovalbox.png
@ -68,6 +69,7 @@
- \c \\ovaldoublebox{...} : draw a double oval box \image html jkqtmathtext/jkqtmathtext_doubleovalbox.png - \c \\ovaldoublebox{...} : draw a double oval box \image html jkqtmathtext/jkqtmathtext_doubleovalbox.png
- \c \\colorbox{bordercolor}{...} : draw a colored box \image html jkqtmathtext/jkqtmathtext_colorbox.png - \c \\colorbox{bordercolor}{...} : draw a colored box \image html jkqtmathtext/jkqtmathtext_colorbox.png
- \c \\shaded{backgroundcolor}{...} : draw a filled box \image html jkqtmathtext/jkqtmathtext_shaded.png - \c \\shaded{backgroundcolor}{...} : draw a filled box \image html jkqtmathtext/jkqtmathtext_shaded.png
- \c \\snugshade{...} : draw text with a snug shade around it \image html jkqtmathtext/jkqtmathtext_snugshade.png
- \c \\fcolorbox{bordercolor}{backgroundcolor}{...} : draw a colored, filled box \image html jkqtmathtext/jkqtmathtext_fcolorbox.png - \c \\fcolorbox{bordercolor}{backgroundcolor}{...} : draw a colored, filled box \image html jkqtmathtext/jkqtmathtext_fcolorbox.png
- \c \\colorbox{color}{...} : draw a colored box around text \image html jkqtmathtext/jkqtmathtext_colorbox.png - \c \\colorbox{color}{...} : draw a colored box around text \image html jkqtmathtext/jkqtmathtext_colorbox.png
. .
@ -152,6 +154,18 @@
<td>"<code>\\negthickspace</code>" <td>"<code>\\negthickspace</code>"
<td>negative thick whitespace <td>negative thick whitespace
<td>\image html jkqtmathtext/jkqtmathtext_whitespace_negthickspace.png <td>\image html jkqtmathtext/jkqtmathtext_whitespace_negthickspace.png
<tr>
<td>"<code>\\phantom{XXX}</code>"
<td>whitespace with the width and height of <code>XXX</code> (may contain LaTeX instructions)
<td>\image html jkqtmathtext/jkqtmathtext_whitespace_phantom.png
<tr>
<td>"<code>\\vphantom{XXX}</code>"
<td>whitespace with the height of <code>XXX</code> (may contain LaTeX instructions) and width 0
<td>\image html jkqtmathtext/jkqtmathtext_whitespace_vphantom.png
<tr>
<td>"<code>\\hphantom{XXX}</code>"
<td>whitespace with the width of <code>XXX</code> (may contain LaTeX instructions) and height 0
<td>\image html jkqtmathtext/jkqtmathtext_whitespace_hphantom.png
</table> </table>

View File

@ -69,12 +69,15 @@ Changes, compared to \ref page_whatsnew_V4_0_0 "v4.0.0" include:
<li>NEW: added \c \\shaded{color}{...} </li> <li>NEW: added \c \\shaded{color}{...} </li>
<li>NEW: added \c \\dashbox{...} </li> <li>NEW: added \c \\dashbox{...} </li>
<li>NEW: added \c \\dottedbox{...} </li> <li>NEW: added \c \\dottedbox{...} </li>
<li>NEW: added \c \\snugshade{...} </li>
<li>NEW: added \c \\snugbox{...} </li>
<li>NEW: added \c \\acute{X}, \c \\grave{X}, \c \\acute{X}</li> <li>NEW: added \c \\acute{X}, \c \\grave{X}, \c \\acute{X}</li>
<li>NEW: added functions to set the font-size in pixels (as alternative to the existing functions that set them in points), implements request <a href="https://github.com/jkriege2/JKQtPlotter/issues/76">#76</a> from <a href="https://github.com/igormironchik">user:igormironchik</a> </li> <li>NEW: added functions to set the font-size in pixels (as alternative to the existing functions that set them in points), implements request <a href="https://github.com/jkriege2/JKQtPlotter/issues/76">#76</a> from <a href="https://github.com/igormironchik">user:igormironchik</a> </li>
<li>NEW: added \c \\userfont{SystemFontName}{Text} instruction</li> <li>NEW: added \c \\userfont{SystemFontName}{Text} instruction</li>
<li>NEW: added \c \\unicode{HEX} and \c \\utfeight{HEX} instruction to draw unicide characters by code</li> <li>NEW: added \c \\unicode{HEX} and \c \\utfeight{HEX} instruction to draw unicide characters by code</li>
<li>NEW: JKQTMathTextVerticalListNode allows to typeset a vertical list of lines</li> <li>NEW: JKQTMathTextVerticalListNode allows to typeset a vertical list of lines</li>
<li>NEW: added \c \\substack[lcr]{...\\\\...} , \c \\lsubstack{...\\\\...} , \c \\rsubstack{...\\\\...} instructions</li> <li>NEW: added \c \\substack[lcr]{...\\\\...} , \c \\lsubstack{...\\\\...} , \c \\rsubstack{...\\\\...} instructions</li>
<li>NEW: added \c \\phantom{xXy} , \c \\vphantom{xXy} and \c \\hphantom{xXy} instructions for whitespaces with the size of \c xXy </li>
<li>NEW: added support for flushleft/flushright/center-environments with linebreaks</li> <li>NEW: added support for flushleft/flushright/center-environments with linebreaks</li>
<li>NEW: added support for framed/shaded/snugshade-environments with linebreaks and framed</li> <li>NEW: added support for framed/shaded/snugshade-environments with linebreaks and framed</li>
<li>NEW: added support for -- and --- for en- and em-dashes</li> <li>NEW: added support for -- and --- for en- and em-dashes</li>

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 351 B

After

Width:  |  Height:  |  Size: 339 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -2,6 +2,9 @@
jkqtmathtext_boxed.png jkqtmathtext_boxed.png
{\backslash}boxed: \boxed{boxed text} {\backslash}boxed: \boxed{boxed text}
--- ---
jkqtmathtext_snugbox.png
{\backslash}snugbox: \snugbox{boxed text}
---
jkqtmathtext_ovalboxed.png jkqtmathtext_ovalboxed.png
{\backslash}ovalbox: \ovalbox{boxed text} {\backslash}ovalbox: \ovalbox{boxed text}
--- ---
@ -29,6 +32,9 @@ jkqtmathtext_fcolorbox.png
jkqtmathtext_shaded.png jkqtmathtext_shaded.png
{\backslash}shaded\{yellow\}: \shaded{yellow}{boxed text} {\backslash}shaded\{yellow\}: \shaded{yellow}{boxed text}
--- ---
jkqtmathtext_snugshade.png
{\backslash}snugshade\{yellow\}: \snugshade{yellow}{boxed text}
---
jkqtmathtext_beginshaded.png jkqtmathtext_beginshaded.png
{\backslash}begin\{shaded\}: \begin{shaded}boxed text\\ 2^{nd} line\end{shaded} {\backslash}begin\{shaded\}: \begin{shaded}boxed text\\ 2^{nd} line\end{shaded}
--- ---

View File

@ -3,7 +3,7 @@ jkqtmathtext_whitespace_thicker.png
\rightarrow\ \leftarrow \rightarrow\ \leftarrow
--- ---
jkqtmathtext_whitespace_enspace.png jkqtmathtext_whitespace_enspace.png
\rightarrow\enspace^\leftarrow \rightarrow\enspace\leftarrow
--- ---
jkqtmathtext_whitespace_emspace.png jkqtmathtext_whitespace_emspace.png
\rightarrow\emspace\leftarrow \rightarrow\emspace\leftarrow
@ -28,3 +28,12 @@ jkqtmathtext_whitespace_negmedspace.png
--- ---
jkqtmathtext_whitespace_negthickspace.png jkqtmathtext_whitespace_negthickspace.png
\rightarrow\negthickspace\leftarrow \rightarrow\negthickspace\leftarrow
---
jkqtmathtext_whitespace_phantom.png
\begin{flushleft}\rightarrow\snugbox{\snugshade{yellow}{\phantom{XXX}}}\leftarrow\\\rightarrow\snugbox{\snugshade{yellow}{XXX}}\leftarrow\end{flushleft}
---
jkqtmathtext_whitespace_vphantom.png
\begin{flushleft}\rightarrow\snugbox{\snugshade{yellow}{\vphantom{XXq}}}\leftarrow\\\rightarrow\snugbox{\snugshade{yellow}{XXq}}\leftarrow\end{flushleft}
---
jkqtmathtext_whitespace_hphantom.png
\begin{flushleft}\rightarrow\snugbox{\snugshade{yellow}{\hphantom{XXX}}}\leftarrow\\\rightarrow\snugbox{\snugshade{yellow}{XXX}}\leftarrow\end{flushleft}

View File

@ -1922,6 +1922,13 @@ JKQTMathTextNode* JKQTMathText::parseInstruction(bool *_foundError, bool* getNew
if (foundError){ if (foundError){
error_list.append(tr("error @ ch. %1: expected %3 arguments in '{...}' braces after '%2' command").arg(currentTokenID).arg(currentInstructionName).arg(Nparams+1)); error_list.append(tr("error @ ch. %1: expected %3 arguments in '{...}' braces after '%2' command").arg(currentTokenID).arg(currentInstructionName).arg(Nparams+1));
} }
} else if (JKQTMathTextPhantomNode::supportsInstructionName(currentInstructionName)) {
if (getNew) *getNew=true;
if (getToken()==MTTopenbrace) {
child=new JKQTMathTextPhantomNode(this, currentInstructionName, parseLatexString(true));
} else {
error_list.append(tr("error @ ch. %1: expected one argument in '{...}' braces after '%2' command").arg(currentTokenID).arg(currentInstructionName));
}
} else if (currentInstructionName=="substack" || currentInstructionName=="rsubstack" || currentInstructionName=="lsubstack") { } else if (currentInstructionName=="substack" || currentInstructionName=="rsubstack" || currentInstructionName=="lsubstack") {
getToken(); getToken();
JKQTMathTextHorizontalAlignment alignment=MTHACentered; JKQTMathTextHorizontalAlignment alignment=MTHACentered;

View File

@ -886,6 +886,14 @@ void JKQTMathTextBoxInstructionNode::fillInstructions()
/*Nparams=*/1); /*Nparams=*/1);
instructions["snugshade"] = i; instructions["snugshade"] = i;
} }
{
InstructionProperties i(InstructionProperties::NoModification,
InstructionProperties::DefaultPen,
InstructionProperties::NoBrush,
0,
/*Nparams=*/0);
instructions["snugbox"] = i;
}
{ {
InstructionProperties i(InstructionProperties::NoModification, InstructionProperties i(InstructionProperties::NoModification,
[](JKQTMathTextEnvironment& ev, const QStringList& parameters, JKQTMathText* parent){ [](JKQTMathTextEnvironment& ev, const QStringList& parameters, JKQTMathText* parent){

View File

@ -319,3 +319,97 @@ void JKQTMathTextEmptyBoxNode::getSizeInternal(QPainter &painter, JKQTMathTextEn
} }
strikeoutPos=fm.strikeOutPos(); strikeoutPos=fm.strikeOutPos();
} }
QString JKQTMathTextPhantomNode::Mode2Instruction(Mode mode)
{
switch(mode) {
case FMwidthAndHeight: return "phantom";
case FMwidth: return "hphantom";
case FMheight: return "vphantom";
}
return "phantom";
}
JKQTMathTextPhantomNode::JKQTMathTextPhantomNode(JKQTMathText *parent, const QString &mode, JKQTMathTextNode *child):
JKQTMathTextInstruction1Node(parent, mode, child)
{
fillInstructions();
}
JKQTMathTextPhantomNode::JKQTMathTextPhantomNode(JKQTMathText* _parent, Mode mode, JKQTMathTextNode* child):
JKQTMathTextInstruction1Node(_parent, Mode2Instruction(mode), child)
{
fillInstructions();
}
JKQTMathTextPhantomNode::~JKQTMathTextPhantomNode() {
}
QString JKQTMathTextPhantomNode::getTypeName() const
{
return QLatin1String("JKQTMathTextPhantomNode(")+instructionName+")";
}
void JKQTMathTextPhantomNode::getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos, const JKQTMathTextNodeSize* /*prevNodeSize*/) {
fillInstructions();
JKQTMathTextEnvironment ev=currentEv;
getChild()->getSize(painter, ev, width, baselineHeight, overallHeight, strikeoutPos);
switch(instructions[getInstructionName()]) {
case FMwidth:
overallHeight=0;
baselineHeight=0;
strikeoutPos=0;
break;
case FMwidthAndHeight:
break;
case FMheight:
width=0;
break;
}
}
double JKQTMathTextPhantomNode::draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv, const JKQTMathTextNodeSize* /*prevNodeSize*/) {
doDrawBoxes(painter, x, y, currentEv);
JKQTMathTextEnvironment ev=currentEv;
const JKQTMathTextNodeSize s=getSize(painter, currentEv);
return x+s.width;
}
bool JKQTMathTextPhantomNode::toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) {
JKQTMathTextEnvironment ev=currentEv;
fillInstructions();
return "&nbsp;";
}
bool JKQTMathTextPhantomNode::supportsInstructionName(const QString &instructionName)
{
fillInstructions();
return instructions.contains(instructionName);
}
QHash<QString, JKQTMathTextPhantomNode::Mode> JKQTMathTextPhantomNode::instructions;
void JKQTMathTextPhantomNode::fillInstructions()
{
instructions["phantom"] = FMwidthAndHeight;
instructions["hphantom"] = FMwidth;
instructions["vphantom"] = FMheight;
}

View File

@ -26,6 +26,7 @@
#include "jkqtmathtext/jkqtmathtext_imexport.h" #include "jkqtmathtext/jkqtmathtext_imexport.h"
#include "jkqtmathtext/jkqtmathtexttools.h" #include "jkqtmathtext/jkqtmathtexttools.h"
#include "jkqtmathtext/nodes/jkqtmathtextnode.h" #include "jkqtmathtext/nodes/jkqtmathtextnode.h"
#include "jkqtmathtext/nodes/jkqtmathtextinstructionnode.h"
#include <QPainter> #include <QPainter>
class JKQTMathText; // forward class JKQTMathText; // forward
@ -150,6 +151,48 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextEmptyBoxNode: public JKQTMathTextNode
Units heightUnit; Units heightUnit;
}; };
/** \brief generates whitespace with the size of the contained node
* \ingroup jkqtmathtext_items
*/
class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextPhantomNode: public JKQTMathTextInstruction1Node {
public:
/** \brief type of the phantom instrcution */
enum Mode {
FMwidthAndHeight, /*!< \brief implementes \c \\phantom{CHILD} which is whitespace in the width and height of \c CHILD */
FMwidth, /*!< \brief implementes \c \\hphantom{CHILD} which is whitespace in the width of \c CHILD and height 0. */
FMheight /*!< \brief implementes \c \\vphantom{CHILD} which is whitespace in the height of \c CHILD and width 0. */
};
/** \bbrief convert a Mode into a LaTeX instruction name */
static QString Mode2Instruction(Mode mode);
explicit JKQTMathTextPhantomNode(JKQTMathText* parent, const QString& mode, JKQTMathTextNode* child);
explicit JKQTMathTextPhantomNode(JKQTMathText* parent, Mode mode, JKQTMathTextNode* child);
virtual ~JKQTMathTextPhantomNode() override;
/** \copydoc JKQTMathTextNode::getTypeName() */
virtual QString getTypeName() const override;
/** \copydoc JKQTMathTextNode::draw() */
virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv, const JKQTMathTextNodeSize* prevNodeSize=nullptr) override;
/** \copydoc JKQTMathTextNode::toHtml() */
virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) override;
/** \brief returns true, if the given \a instructionName can be represented by this node
* \see instructions
*/
static bool supportsInstructionName(const QString& instructionName);
protected:
/** \copydoc JKQTMathTextNode::getSizeInternal() */
virtual void getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos, const JKQTMathTextNodeSize* prevNodeSize=nullptr) override;
/** \brief fills instructions
*
* \note this is the customization point for new instructions!
*/
static void fillInstructions();
/** \brief defines all implemented instructions in this node */
static QHash<QString, Mode> instructions;
};
#endif // JKQTMATHTEXTWHITESPACENODE_H #endif // JKQTMATHTEXTWHITESPACENODE_H