Skip to content

Commit

Permalink
FIXed slicing warning, by making the slice-operation explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
jkriege2 committed Jan 11, 2024
1 parent ef07a02 commit f07c013
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 14 deletions.
14 changes: 7 additions & 7 deletions lib/jkqtmathtext/jkqtmathtexttools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -757,13 +757,13 @@ QString JKQTMathTextEnvironment::toHtmlAfter(JKQTMathTextEnvironment /*defaultEv
return "</span>";
}

JKQTMathTextNodeSize::JKQTMathTextNodeSize():
width(0),
baselineHeight(0),
overallHeight(0),
strikeoutPos(),
baselineXCorrection(0),
topXCorrection(0)
JKQTMathTextNodeSize::JKQTMathTextNodeSize(double width_, double baselineHeight_, double overallHeight_, double strikeoutPos_, double baselineXCorrection_, double topXCorrection_):
width(width_),
baselineHeight(baselineHeight_),
overallHeight(overallHeight_),
strikeoutPos(strikeoutPos_),
baselineXCorrection(baselineXCorrection_),
topXCorrection(topXCorrection_)
{

}
Expand Down
4 changes: 3 additions & 1 deletion lib/jkqtmathtext/jkqtmathtexttools.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ struct JKQTMATHTEXT_LIB_EXPORT JKQTMathTextEnvironment {
* \ingroup jkqtmathtext_tools
*/
struct JKQTMATHTEXT_LIB_EXPORT JKQTMathTextNodeSize {
JKQTMathTextNodeSize();
JKQTMathTextNodeSize(double width=0, double baselineHeight=0, double overallHeight=0, double strikeoutPos=0, double baselineXCorrection=0,double topXCorrection=0);
/** \brief width of whole block */
double width;
/** \brief baselineHeight of whole block, i.e. the ascent */
Expand Down Expand Up @@ -419,6 +419,8 @@ struct JKQTMATHTEXT_LIB_EXPORT JKQTMathTextNodeSize {
inline QSizeF getSize() const { return QSizeF(width, overallHeight); }
/** \brief calculate the overall size in floating-point precision */
inline QSize getIntSize() const { return QSize(qCeil(width+1.0), qCeil(overallHeight+1.0)); }
/** \brief helper function, which generates a copy of this object, used to suppress slicing warning due to GSL E.63: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Res-slice */
inline JKQTMathTextNodeSize sliceToNodeSize() const { return *this; }
};

/** \brief summarizes all information available on a font for a specific MTenvironmentFont
Expand Down
2 changes: 1 addition & 1 deletion lib/jkqtmathtext/nodes/jkqtmathtextbracenode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ JKQTMathTextBraceNode::~JKQTMathTextBraceNode() {
}

JKQTMathTextNodeSize JKQTMathTextBraceNode::getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv) const {
return getSizeInternalAndBrace(painter, currentEv);
return getSizeInternalAndBrace(painter, currentEv).sliceToNodeSize();
}

JKQTMathTextBraceNode::NodeSize JKQTMathTextBraceNode::getSizeInternalAndBrace(QPainter &painter, JKQTMathTextEnvironment currentEv) const
Expand Down
2 changes: 1 addition & 1 deletion lib/jkqtmathtext/nodes/jkqtmathtextmatrixnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ JKQTMathTextMatrixNode::LayoutInfo JKQTMathTextMatrixNode::calcLayout(QPainter &
}

JKQTMathTextNodeSize JKQTMathTextMatrixNode::getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv) const {
return calcLayout(painter, currentEv);
return calcLayout(painter, currentEv).sliceToNodeSize();
}

double JKQTMathTextMatrixNode::draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) const {
Expand Down
2 changes: 1 addition & 1 deletion lib/jkqtmathtext/nodes/jkqtmathtextsymbolnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ QString JKQTMathTextSymbolNode::getTypeName() const


JKQTMathTextNodeSize JKQTMathTextSymbolNode::getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv) const {
return getSymbolSize(painter, currentEv);
return getSymbolSize(painter, currentEv).sliceToNodeSize();
}

QRectF JKQTMathTextSymbolNode::getBoundingRect(const QFont &f, const QString &text, GlobalSymbolFlags globalFlags, QPaintDevice *pd)
Expand Down
2 changes: 1 addition & 1 deletion lib/jkqtmathtext/nodes/jkqtmathtexttextnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ JKQTMathTextTextNode::JKQTMathTextTextNode(JKQTMathText* _parent, const QString&
JKQTMathTextTextNode::~JKQTMathTextTextNode() = default;

JKQTMathTextNodeSize JKQTMathTextTextNode::getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv) const {
return calcLayout(painter, currentEv);
return calcLayout(painter, currentEv).sliceToNodeSize();
}

JKQTMathTextTextNode::LayoutInfo JKQTMathTextTextNode::calcLayout(QPainter &painter, JKQTMathTextEnvironment currentEv) const
Expand Down
2 changes: 1 addition & 1 deletion lib/jkqtmathtext/nodes/jkqtmathtextverbatimnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ bool JKQTMathTextVerbatimNode::toHtml(QString &html, JKQTMathTextEnvironment cur
JKQTMathTextNodeSize JKQTMathTextVerbatimNode::getSizeInternal(QPainter &painter, JKQTMathTextEnvironment currentEv) const
{
transformEnvironment(currentEv);
return calcLayout(painter, currentEv);
return calcLayout(painter, currentEv).sliceToNodeSize();
}

void JKQTMathTextVerbatimNode::transformEnvironment(JKQTMathTextEnvironment &currentEv) const
Expand Down
2 changes: 1 addition & 1 deletion lib/jkqtmathtext/nodes/jkqtmathtextverticallistnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ QString JKQTMathTextVerticalListNode::getTypeName() const
}

JKQTMathTextNodeSize JKQTMathTextVerticalListNode::getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv) const {
return calcLayout(painter, currentEv);
return calcLayout(painter, currentEv).sliceToNodeSize();
}

JKQTMathTextVerticalListNode::LayoutInfo JKQTMathTextVerticalListNode::calcLayout(QPainter &painter, JKQTMathTextEnvironment ev) const
Expand Down

0 comments on commit f07c013

Please sign in to comment.