mirror of
https://gitlab.com/pholy/OSCAR-code.git
synced 2025-04-14 09:40:45 +00:00
printer scaling fix for Retina macs
This commit is contained in:
parent
cbbae2e700
commit
a97bb0be80
sleepyhead
@ -14,6 +14,9 @@
|
|||||||
#include <QGLPixelBuffer>
|
#include <QGLPixelBuffer>
|
||||||
#include <QGLFramebufferObject>
|
#include <QGLFramebufferObject>
|
||||||
#include <QPixmapCache>
|
#include <QPixmapCache>
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
|
||||||
|
#include <QWindow>
|
||||||
|
#endif
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
|
||||||
#include "Graphs/gYAxis.h"
|
#include "Graphs/gYAxis.h"
|
||||||
@ -2086,16 +2089,22 @@ void gGraphView::DrawTextQue(QPainter &painter)
|
|||||||
TextQue &q = m_textque[i];
|
TextQue &q = m_textque[i];
|
||||||
painter.setBrush(q.color);
|
painter.setBrush(q.color);
|
||||||
painter.setRenderHint(QPainter::TextAntialiasing,q.antialias);
|
painter.setRenderHint(QPainter::TextAntialiasing,q.antialias);
|
||||||
|
|
||||||
if (q.angle==0) { // normal text
|
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
|
|
||||||
QFont font=*q.font;
|
QFont font=*q.font;
|
||||||
font.setPointSizeF(q.font->pointSizeF()*dpr);
|
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
|
||||||
|
int fs=font.pointSize();
|
||||||
|
if (fs>0)
|
||||||
|
font.setPointSize(fs*dpr);
|
||||||
|
else {
|
||||||
|
font.setPixelSize(font.pixelSize()*dpr);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
painter.setFont(font);
|
painter.setFont(font);
|
||||||
|
|
||||||
|
if (q.angle==0) { // normal text
|
||||||
|
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
|
||||||
painter.drawText(q.x*dpr,q.y*dpr,q.text);
|
painter.drawText(q.x*dpr,q.y*dpr,q.text);
|
||||||
#else
|
#else
|
||||||
painter.setFont(*q.font);
|
|
||||||
painter.drawText(q.x,q.y,q.text);
|
painter.drawText(q.x,q.y,q.text);
|
||||||
#endif
|
#endif
|
||||||
} else { // rotated text
|
} else { // rotated text
|
||||||
@ -2240,7 +2249,11 @@ QPixmap gGraph::renderPixmap(int w, int h, bool printing)
|
|||||||
|
|
||||||
sg->setScaleY(1.0);
|
sg->setScaleY(1.0);
|
||||||
|
|
||||||
|
|
||||||
sg->makeCurrent(); // has to be current for fbo creation
|
sg->makeCurrent(); // has to be current for fbo creation
|
||||||
|
|
||||||
|
float dpr=sg->devicePixelRatio();
|
||||||
|
sg->setDevicePixelRatio(1);
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
if (pm.isNull()){
|
if (pm.isNull()){
|
||||||
pm=sg->renderPixmap(w,h,false);
|
pm=sg->renderPixmap(w,h,false);
|
||||||
@ -2258,8 +2271,10 @@ QPixmap gGraph::renderPixmap(int w, int h, bool printing)
|
|||||||
pm=QPixmap::fromImage(sg->pbRenderPixmap(w,h));
|
pm=QPixmap::fromImage(sg->pbRenderPixmap(w,h));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
sg->setDevicePixelRatio(dpr);
|
||||||
//sg->doneCurrent();
|
//sg->doneCurrent();
|
||||||
sg->trashGraphs();
|
sg->trashGraphs();
|
||||||
|
|
||||||
m_graphview=tgv;
|
m_graphview=tgv;
|
||||||
|
|
||||||
m_height=tmp;
|
m_height=tmp;
|
||||||
@ -2437,6 +2452,12 @@ gGraphView::gGraphView(QWidget *parent, gGraphView * shared) :
|
|||||||
m_fadedir=false;
|
m_fadedir=false;
|
||||||
m_blockUpdates=false;
|
m_blockUpdates=false;
|
||||||
use_pixmap_cache=true;
|
use_pixmap_cache=true;
|
||||||
|
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
|
||||||
|
m_dpr=this->windowHandle()->devicePixelRatio();
|
||||||
|
#else
|
||||||
|
m_dpr=1;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
gGraphView::~gGraphView()
|
gGraphView::~gGraphView()
|
||||||
@ -2589,13 +2610,16 @@ void gGraphView::DrawTextQue()
|
|||||||
QBrush b(q.color);
|
QBrush b(q.color);
|
||||||
imgpainter.setBrush(b);
|
imgpainter.setBrush(b);
|
||||||
|
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
|
|
||||||
QFont font=*q.font;
|
QFont font=*q.font;
|
||||||
font.setPointSizeF(q.font->pointSizeF()*dpr);
|
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
|
||||||
imgpainter.setFont(font);
|
int fs=font.pointSize();
|
||||||
#else
|
if (fs>0) {
|
||||||
imgpainter.setFont(*q.font);
|
font.setPointSize(fs*dpr);
|
||||||
|
} else {
|
||||||
|
font.setPixelSize(font.pixelSize()*dpr);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
imgpainter.setFont(font);
|
||||||
|
|
||||||
imgpainter.setRenderHint(QPainter::TextAntialiasing, q.antialias);
|
imgpainter.setRenderHint(QPainter::TextAntialiasing, q.antialias);
|
||||||
imgpainter.drawText(buf/2,h,q.text);
|
imgpainter.drawText(buf/2,h,q.text);
|
||||||
|
@ -994,6 +994,10 @@ public:
|
|||||||
|
|
||||||
void setCubeImage(QImage *);
|
void setCubeImage(QImage *);
|
||||||
|
|
||||||
|
inline const float & devicePixelRatio() { return m_dpr; }
|
||||||
|
void setDevicePixelRatio(float dpr) { m_dpr=dpr; }
|
||||||
|
|
||||||
|
|
||||||
// Cube fun
|
// Cube fun
|
||||||
QVector<QImage *> cubeimg;
|
QVector<QImage *> cubeimg;
|
||||||
GLuint cubetex;
|
GLuint cubetex;
|
||||||
@ -1107,6 +1111,7 @@ protected:
|
|||||||
int m_offsetX;
|
int m_offsetX;
|
||||||
//! \variable Scale used to enlarge graphs when less graphs than can fit on screen.
|
//! \variable Scale used to enlarge graphs when less graphs than can fit on screen.
|
||||||
float m_scaleY;
|
float m_scaleY;
|
||||||
|
float m_dpr;
|
||||||
|
|
||||||
void renderSomethingFun(float alpha=1);
|
void renderSomethingFun(float alpha=1);
|
||||||
|
|
||||||
|
@ -447,6 +447,9 @@ void Report::PrintReport(gGraphView *gv,QString name, QDate date)
|
|||||||
|
|
||||||
int page=1;
|
int page=1;
|
||||||
int gcnt=0;
|
int gcnt=0;
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
|
||||||
|
float dpr=gv->devicePixelRatio();
|
||||||
|
#endif
|
||||||
for (int i=0;i<graphs.size();i++) {
|
for (int i=0;i<graphs.size();i++) {
|
||||||
|
|
||||||
if ((top+full_graph_height+normal_height) > virt_height) {
|
if ((top+full_graph_height+normal_height) > virt_height) {
|
||||||
@ -498,7 +501,11 @@ void Report::PrintReport(gGraphView *gv,QString name, QDate date)
|
|||||||
//painter.beginNativePainting();
|
//painter.beginNativePainting();
|
||||||
//g->showTitle(false);
|
//g->showTitle(false);
|
||||||
int hhh=full_graph_height-normal_height;
|
int hhh=full_graph_height-normal_height;
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
|
||||||
QPixmap pm2=g->renderPixmap(virt_width,hhh,1);
|
QPixmap pm2=g->renderPixmap(virt_width,hhh,1);
|
||||||
|
#else
|
||||||
|
QPixmap pm2=g->renderPixmap(virt_width,hhh,1);
|
||||||
|
#endif
|
||||||
QImage pm=pm2.toImage();//fscale);
|
QImage pm=pm2.toImage();//fscale);
|
||||||
pm2.detach();
|
pm2.detach();
|
||||||
//g->showTitle(true);
|
//g->showTitle(true);
|
||||||
@ -508,9 +515,11 @@ void Report::PrintReport(gGraphView *gv,QString name, QDate date)
|
|||||||
|
|
||||||
|
|
||||||
if (!pm.isNull()) {
|
if (!pm.isNull()) {
|
||||||
painter.drawImage(0,top,pm);;
|
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
|
||||||
|
painter.drawImage(QRect(0,top,pm.width(),pm.height()),pm);
|
||||||
|
#else
|
||||||
|
painter.drawImage(0,top,pm);
|
||||||
|
#endif
|
||||||
|
|
||||||
//painter.drawImage(0,top,virt_width,full_graph_height-normal_height,pm);
|
//painter.drawImage(0,top,virt_width,full_graph_height-normal_height,pm);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user