/* Copyright (c) 2008-2022 Jan W. Krieger () 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 . */ #include "jkqtmathtext/nodes/jkqtmathtextverbatimnode.h" #include "jkqtmathtext/jkqtmathtexttools.h" #include "jkqtmathtext/nodes/jkqtmathtextnode.h" #include "jkqtmathtext/jkqtmathtext.h" #include "jkqtcommon/jkqtpcodestructuring.h" #include "jkqtcommon/jkqtpstringtools.h" #include "jkqtcommon/jkqtpdebuggingtools.h" #include #include #include #include #include #include #include JKQTMathTextVerbatimNode::JKQTMathTextVerbatimNode(JKQTMathText *_parent, const QString& _text, bool visibleWhitespace_, JKQTMathTextHorizontalAlignment _alignment, double _linespacingFactor, JKQTMathTextVerticalOrientation _verticalOrientation, size_t tabSize_): JKQTMathTextTextBaseNode(_parent, _text), alignment(_alignment), lineSpacingFactor(_linespacingFactor), verticalOrientation(_verticalOrientation), visibleWhitespace(visibleWhitespace_), tabSize(tabSize_) { } QString JKQTMathTextVerbatimNode::getTypeName() const { return QLatin1String("JKQTMathTextVerbatimNode"); } JKQTMathTextHorizontalAlignment JKQTMathTextVerbatimNode::getAlignment() const { return alignment; } JKQTMathTextVerticalOrientation JKQTMathTextVerbatimNode::getVerticalOrientation() const { return verticalOrientation; } double JKQTMathTextVerbatimNode::getLineSpacingFactor() const { return lineSpacingFactor; } bool JKQTMathTextVerbatimNode::getVisibleWhitespace() const { return visibleWhitespace; } size_t JKQTMathTextVerbatimNode::getTabSize() const { return tabSize; } double JKQTMathTextVerbatimNode::draw(QPainter &painter, double x, double y, JKQTMathTextEnvironment currentEv) const { #ifdef JKQTBP_AUTOTIMER JKQTPAutoOutputTimer jkaat(QString("JKQTMathTextVerbatimNode[]::draw()")); #endif transformEnvironment(currentEv); const LayoutInfo l=calcLayout(painter, currentEv); doDrawBoxes(painter, x, y, l); QFont f=currentEv.getFont(parentMathText); f.setStyleStrategy(QFont::PreferDefault); f.setFixedPitch(true); painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); painter.setFont(f); for (int i=0; i0; html+=currentEv.toHtmlStart(defaultEv, parentMathText); if (isMultiLine) { if (alignment==MTHALeft) { html+="
"; } else if (alignment==MTHACentered) { html+="
"; } else if (alignment==MTHARight) { html+="
"; } } html+="
";
    html+=textTransform(text, currentEv).toHtmlEscaped();
    html+="
"; if (isMultiLine) html+="
"; html+=currentEv.toHtmlAfter(defaultEv, parentMathText); return true; } JKQTMathTextNodeSize JKQTMathTextVerbatimNode::getSizeInternal(QPainter &painter, JKQTMathTextEnvironment currentEv) const { transformEnvironment(currentEv); return calcLayout(painter, currentEv); } void JKQTMathTextVerbatimNode::transformEnvironment(JKQTMathTextEnvironment ¤tEv) const { currentEv.font=MTEtypewriter; } JKQTMathTextVerbatimNode::LayoutInfo JKQTMathTextVerbatimNode::calcLayout(QPainter &painter, const JKQTMathTextEnvironment& currentEv) const { LayoutInfo l; QFont f=currentEv.getFont(parentMathText); f.setStyleStrategy(QFont::PreferDefault); f.setFixedPitch(true); const qreal fascent=JKQTMathTextGetFontAscent(f, painter.device()); const double linespacing=JKQTMathTextGetFontLineSpacing(f, painter.device())*lineSpacingFactor; const double fleading=JKQTMathTextGetFontLeading(f, painter.device()); const double synLeading=JKQTMathTextGetFontLineWidth(f, painter.device()); const double lineLeading=((fabs(fleading)>1e-6)?fleading:synLeading)*lineSpacingFactor; if (text.size()<=0) { return l; } l.lines=textTransform(text, currentEv).split('\n'); // from now on we have at least one child node!!! QList widths, heights, ascents, descents, strikeouts; double heightSum=0; QList ysFromFirstLine; // y-position of each line, where the first line is always at y=0 (i.e. ysFromFirstLine[0]==0) double y=0; for (int i=0; i0) { const double deltaLine=qMax(linespacing, descents.last()+lineLeading+fascent); heightSum=heightSum+deltaLine; y=y+deltaLine; } widths<