TechDraw: SVG export refactoring - Keep correct font sizes

This commit is contained in:
Tomas Pavlicek
2019-06-07 21:11:36 +02:00
committed by WandererFan
parent f4ca09f985
commit 28b2df05da
7 changed files with 18 additions and 37 deletions

View File

@@ -84,7 +84,7 @@ void QGIHighlight::makeHighlight()
void QGIHighlight::makeReference()
{
prepareGeometryChange();
m_refFont.setPointSizeF(QGIView::calculateFontPointSizeF(this, m_refSize));
m_refFont.setPixelSize(QGIView::calculateFontPixelSize(m_refSize));
m_reference->setFont(m_refFont);
m_reference->setPlainText(QString::fromUtf8(m_refText));
double fudge = Rez::guiX(1.0);

View File

@@ -54,6 +54,8 @@ public:
void draw();
virtual void updateView(bool update = false);
TechDraw::DrawSVGTemplate *getSVGTemplate();
protected:
void openFile(const QFile &file);
void load (const QString & fileName);
@@ -61,7 +63,6 @@ protected:
protected:
bool firstTime;
TechDraw::DrawSVGTemplate * getSVGTemplate();
QGraphicsSvgItem *m_svgItem;
QSvgRenderer *m_svgRender;
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);

View File

@@ -195,7 +195,7 @@ void QGISectionLine::makeSymbolsTrad()
extLineStart = m_start + offset;
extLineEnd = m_end + offset;
prepareGeometryChange();
m_symFont.setPointSizeF(QGIView::calculateFontPointSizeF(this, m_symSize));
m_symFont.setPixelSize(QGIView::calculateFontPixelSize(m_symSize));
m_symbol1->setFont(m_symFont);
m_symbol1->setPlainText(QString::fromUtf8(m_symbol));
if (m_arrowDir.y < 0.0) { //pointing down
@@ -238,7 +238,7 @@ void QGISectionLine::makeSymbolsISO()
symPosEnd = m_end - offset;
prepareGeometryChange();
m_symFont.setPointSizeF(QGIView::calculateFontPointSizeF(this, m_symSize));
m_symFont.setPixelSize(QGIView::calculateFontPixelSize(m_symSize));
m_symbol1->setFont(m_symFont);
m_symbol1->setPlainText(QString::fromUtf8(m_symbol));
m_symbol1->centerAt(symPosStart);

View File

@@ -96,7 +96,7 @@ QGIView::QGIView()
m_pen.setColor(m_colCurrent);
//Border/Label styling
m_font.setPointSizeF(calculateFontPointSizeF(getPrefFontSize()));
m_font.setPixelSize(calculateFontPixelSize(getPrefFontSize()));
m_decorPen.setStyle(Qt::DashLine);
m_decorPen.setWidth(0); // 0 => 1px "cosmetic pen"
@@ -428,7 +428,7 @@ void QGIView::drawCaption()
QRectF displayArea = customChildrenBoundingRect();
m_caption->setDefaultTextColor(m_colCurrent);
m_font.setFamily(getPrefFont());
m_font.setPointSizeF(calculateFontPointSizeF(getPrefFontSize()));
m_font.setPixelSize(calculateFontPixelSize(getPrefFontSize()));
m_caption->setFont(m_font);
QString captionStr = QString::fromUtf8(getViewObject()->Caption.getValue());
m_caption->setPlainText(captionStr);
@@ -469,7 +469,7 @@ void QGIView::drawBorder()
m_label->setDefaultTextColor(m_colCurrent);
m_font.setFamily(getPrefFont());
m_font.setPointSizeF(calculateFontPointSizeF(getPrefFontSize()));
m_font.setPixelSize(calculateFontPixelSize(getPrefFontSize()));
m_label->setFont(m_font);
QString labelStr = QString::fromUtf8(getViewObject()->Label.getValue());
@@ -686,30 +686,11 @@ double QGIView::getDimFontSize()
return hGrp->GetFloat("FontSize", DefaultFontSizeInMM);
}
double QGIView::calculateFontPointSizeF(const QGraphicsItem *item, double sizeInMillimetres)
int QGIView::calculateFontPixelSize(double sizeInMillimetres)
{
const QWidget *widget = MDIViewPage::getFromScene(item->scene());
if (widget == nullptr && !QApplication::topLevelWidgets().isEmpty()) {
// Fallback to some top level window if we are not assigned to a scene/widget yet
widget = QApplication::topLevelWidgets().first();
}
double logicalDPI = 96.0; // This is the most common value in PC world
if (widget != nullptr) {
logicalDPI = widget->logicalDpiY();
}
// Now calculate the correct font size to be used by a QGraphicsTextItem:
// 1) Start with font size in mm.
// 2) Convert it to "pixels" via Rex::GuiX().
// 3) Convert "pixels" to inches dividing them by DPI.
// 4) Convert inches to points - there are exactly 72 points to one inch.
return 72.0*Rez::guiX(sizeInMillimetres)/logicalDPI;
}
double QGIView::calculateFontPointSizeF(double sizeInMillimetres) const
{
return calculateFontPointSizeF(this, sizeInMillimetres);
// Calculate font size in pixels by using resolution conversion
// and round to nearest integer
return (int) (Rez::guiX(sizeInMillimetres) + 0.5);
}
const double QGIView::DefaultFontSizeInMM = 5.0;

View File

@@ -111,7 +111,7 @@ public:
static Gui::ViewProvider* getViewProvider(App::DocumentObject* obj);
static QGVPage* getGraphicsView(TechDraw::DrawView* dv);
static double calculateFontPointSizeF(const QGraphicsItem *graphicsItem, double sizeInMillimetres);
static int calculateFontPixelSize(double sizeInMillimetres);
static const double DefaultFontSizeInMM;
MDIViewPage* getMDIViewPage(void) const;
@@ -138,7 +138,6 @@ protected:
QString getPrefFont(void);
double getPrefFontSize(void);
double getDimFontSize(void);
double calculateFontPointSizeF(double sizeInMillimetres) const;
Base::Reference<ParameterGrp> getParmGroupCol(void);

View File

@@ -181,7 +181,7 @@ void QGIViewBalloon::placeBalloon(QPointF pos)
balloon->Text.setValue(std::to_string(idx).c_str());
QFont font = balloonLabel->getFont();
font.setPointSizeF(calculateFontPointSizeF(vp->Fontsize.getValue()));
font.setPixelSize(calculateFontPixelSize(vp->Fontsize.getValue()));
font.setFamily(QString::fromUtf8(vp->Font.getValue()));
balloonLabel->setFont(font);
prepareGeometryChange();
@@ -263,7 +263,7 @@ void QGIViewBalloon::updateBalloon(bool obtuse)
}
QFont font = balloonLabel->getFont();
font.setPointSizeF(calculateFontPointSizeF(vp->Fontsize.getValue()));
font.setPixelSize(calculateFontPixelSize(vp->Fontsize.getValue()));
font.setFamily(QString::fromUtf8(vp->Font.getValue()));
balloonLabel->setFont(font);

View File

@@ -208,9 +208,9 @@ void QGIDatumLabel::setFont(QFont f)
{
m_dimText->setFont(f);
QFont tFont(f);
double fontSize = f.pointSizeF();
double fontSize = f.pixelSize();
double tolAdj = getTolAdjust();
tFont.setPointSizeF(fontSize * tolAdj);
tFont.setPixelSize((int) (fontSize * tolAdj));
m_tolText->setFont(tFont);
}
@@ -481,7 +481,7 @@ void QGIViewDimension::updateDim(bool obtuse)
QFont font = datumLabel->getFont();
font.setFamily(QString::fromUtf8(vp->Font.getValue()));
font.setPointSizeF(calculateFontPointSizeF(this, vp->Fontsize.getValue()));
font.setPixelSize(calculateFontPixelSize(vp->Fontsize.getValue()));
datumLabel->setFont(font);
prepareGeometryChange();