iproved JKQTMathText::drawIntoPixmap() and drawIntoPicture(): using ARGB32_Premultiplied for QPixmap + enabled QPainter::VerticalSubpixelPositioning when available

This commit is contained in:
jkriege2 2023-07-01 14:49:56 +02:00
parent 3b136c7320
commit 8719208acf

View File

@ -64,7 +64,7 @@ QString JKQTMathText::init_caligraphicFont="decorative";
QString JKQTMathText::init_blackboardFont="blackboard";
QString JKQTMathText::init_fracturFont="fraktur";
bool JKQTMathText::s_firstStart=true;
std::mutex JKQTMathText::s_mutex=std::mutex();
std::mutex JKQTMathText::s_mutex;
@ -1256,6 +1256,9 @@ QPixmap JKQTMathText::drawIntoPixmap(bool drawBoxes, QColor backgroundColor, int
painter.setRenderHint(QPainter::Antialiasing);
painter.setRenderHint(QPainter::TextAntialiasing);
painter.setRenderHint(QPainter::SmoothPixmapTransform);
#if (QT_VERSION>=QT_VERSION_CHECK(6, 1, 0))
painter.setRenderHint(QPainter::VerticalSubpixelPositioning);
#endif
const JKQTMathTextNodeSize size=getSizeDetail(painter);
const QSize pixsize=size.getIntSize()+QSize(2*sizeincrease,2*sizeincrease);
painter.end();
@ -1270,6 +1273,9 @@ QPixmap JKQTMathText::drawIntoPixmap(bool drawBoxes, QColor backgroundColor, int
painter.setRenderHint(QPainter::Antialiasing);
painter.setRenderHint(QPainter::TextAntialiasing);
painter.setRenderHint(QPainter::SmoothPixmapTransform);
#if (QT_VERSION>=QT_VERSION_CHECK(6, 1, 0))
painter.setRenderHint(QPainter::VerticalSubpixelPositioning);
#endif
draw(painter, Qt::AlignVCenter|Qt::AlignHCenter, QRect(QPoint(0,0),pixsize), drawBoxes);
painter.end();
}
@ -1281,7 +1287,7 @@ QImage JKQTMathText::drawIntoImage(bool drawBoxes, QColor backgroundColor, int s
// 1. generate dummy QPixmap that is needed to use a QPainter
// we need the dummy, because we first need to determine the size of the render output
// for which we need a QPainter.
QImage img(1,1,QImage::Format_ARGB32);
QImage img(1,1,QImage::Format_ARGB32_Premultiplied);
img.setDevicePixelRatio(devicePixelRatio);
img.setDotsPerMeterX(resolution_dpi*(10000/254));
img.setDotsPerMeterY(resolution_dpi*(10000/254));
@ -1294,6 +1300,9 @@ QImage JKQTMathText::drawIntoImage(bool drawBoxes, QColor backgroundColor, int s
painter.setRenderHint(QPainter::Antialiasing);
painter.setRenderHint(QPainter::TextAntialiasing);
painter.setRenderHint(QPainter::SmoothPixmapTransform);
#if (QT_VERSION>=QT_VERSION_CHECK(6, 1, 0))
painter.setRenderHint(QPainter::VerticalSubpixelPositioning);
#endif
const JKQTMathTextNodeSize size=getSizeDetail(painter);
const QSize pixsize=size.getIntSize()+QSize(2*sizeincrease,2*sizeincrease);
painter.end();
@ -1301,7 +1310,7 @@ QImage JKQTMathText::drawIntoImage(bool drawBoxes, QColor backgroundColor, int s
// 3. finally we can generate a QPixmap with the appropriate
// size to contain the full rendering. We fill it with the
// color white and finally paint the math markup/LaTeX string
img=QImage(pixsize*devicePixelRatio,QImage::Format_ARGB32);
img=QImage(pixsize*devicePixelRatio,QImage::Format_ARGB32_Premultiplied);
img.setDevicePixelRatio(devicePixelRatio);
img.setDotsPerMeterX(resolution_dpi*(10000/254));
img.setDotsPerMeterY(resolution_dpi*(10000/254));
@ -1310,6 +1319,9 @@ QImage JKQTMathText::drawIntoImage(bool drawBoxes, QColor backgroundColor, int s
painter.setRenderHint(QPainter::Antialiasing);
painter.setRenderHint(QPainter::TextAntialiasing);
painter.setRenderHint(QPainter::SmoothPixmapTransform);
#if (QT_VERSION>=QT_VERSION_CHECK(6, 1, 0))
painter.setRenderHint(QPainter::VerticalSubpixelPositioning);
#endif
draw(painter, Qt::AlignVCenter|Qt::AlignHCenter, QRect(QPoint(0,0),pixsize), drawBoxes);
painter.end();
}
@ -1331,6 +1343,9 @@ QPicture JKQTMathText::drawIntoPicture(bool drawBoxes)
painter.setRenderHint(QPainter::Antialiasing);
painter.setRenderHint(QPainter::TextAntialiasing);
painter.setRenderHint(QPainter::SmoothPixmapTransform);
#if (QT_VERSION>=QT_VERSION_CHECK(6, 1, 0))
painter.setRenderHint(QPainter::VerticalSubpixelPositioning);
#endif
const JKQTMathTextNodeSize size=getSizeDetail(painter);
painter.end();
@ -1341,6 +1356,9 @@ QPicture JKQTMathText::drawIntoPicture(bool drawBoxes)
painter.setRenderHint(QPainter::Antialiasing);
painter.setRenderHint(QPainter::TextAntialiasing);
painter.setRenderHint(QPainter::SmoothPixmapTransform);
#if (QT_VERSION>=QT_VERSION_CHECK(6, 1, 0))
painter.setRenderHint(QPainter::VerticalSubpixelPositioning);
#endif
draw(painter, 0, size.baselineHeight, drawBoxes);
painter.end();
}