TechDraw: Fix font size issues when exporting to SVG
This commit is contained in:
committed by
WandererFan
parent
5a4373a3c4
commit
fad4db3300
@@ -98,7 +98,7 @@ QGIView::QGIView()
|
||||
m_pen.setColor(m_colCurrent);
|
||||
|
||||
//Border/Label styling
|
||||
m_font.setPointSize(getPrefFontSize()); //scene units (mm), not points
|
||||
m_font.setPointSizeF(calculateFontPointSizeF(getPrefFontSize()));
|
||||
|
||||
m_decorPen.setStyle(Qt::DashLine);
|
||||
m_decorPen.setWidth(0); // 0 => 1px "cosmetic pen"
|
||||
@@ -430,7 +430,7 @@ void QGIView::drawCaption()
|
||||
QRectF displayArea = customChildrenBoundingRect();
|
||||
m_caption->setDefaultTextColor(m_colCurrent);
|
||||
m_font.setFamily(getPrefFont());
|
||||
m_font.setPointSize(getPrefFontSize()); //scene units (0.1 mm), not points
|
||||
m_font.setPointSizeF(calculateFontPointSizeF(getPrefFontSize()));
|
||||
m_caption->setFont(m_font);
|
||||
QString captionStr = QString::fromUtf8(getViewObject()->Caption.getValue());
|
||||
m_caption->setPlainText(captionStr);
|
||||
@@ -473,7 +473,8 @@ void QGIView::drawBorder()
|
||||
|
||||
m_label->setDefaultTextColor(m_colCurrent);
|
||||
m_font.setFamily(getPrefFont());
|
||||
m_font.setPointSize(getPrefFontSize()); //scene units (0.1 mm), not points
|
||||
m_font.setPointSizeF(calculateFontPointSizeF(getPrefFontSize()));
|
||||
|
||||
m_label->setFont(m_font);
|
||||
QString labelStr = QString::fromUtf8(getViewObject()->Label.getValue());
|
||||
m_label->setPlainText(labelStr);
|
||||
@@ -608,21 +609,10 @@ QGVPage* QGIView::getGraphicsView(TechDraw::DrawView* dv)
|
||||
}
|
||||
return graphicsView;
|
||||
}
|
||||
|
||||
MDIViewPage* QGIView::getMDIViewPage(void) const
|
||||
{
|
||||
MDIViewPage* result = nullptr;
|
||||
QGraphicsScene* s = scene();
|
||||
QObject* parent = nullptr;
|
||||
if (s != nullptr) {
|
||||
parent = s->parent();
|
||||
}
|
||||
if (parent != nullptr) {
|
||||
MDIViewPage* mdi = dynamic_cast<MDIViewPage*>(parent);
|
||||
if (mdi != nullptr) {
|
||||
result = mdi;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return MDIViewPage::getFromScene(scene());
|
||||
}
|
||||
|
||||
bool QGIView::getFrameState(void)
|
||||
@@ -690,10 +680,37 @@ double QGIView::getPrefFontSize()
|
||||
{
|
||||
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter().
|
||||
GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Labels");
|
||||
double fontSize = hGrp->GetFloat("LabelSize", 3.5);
|
||||
return Rez::guiX(fontSize);
|
||||
return hGrp->GetFloat("LabelSize", DefaultFontSizeInMM);
|
||||
}
|
||||
|
||||
double QGIView::calculateFontPointSizeF(const QGraphicsItem *item, 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);
|
||||
}
|
||||
|
||||
const double QGIView::DefaultFontSizeInMM = 5.0;
|
||||
|
||||
void QGIView::dumpRect(char* text, QRectF r) {
|
||||
Base::Console().Message("DUMP - %s - rect: (%.3f,%.3f) x (%.3f,%.3f)\n",text,
|
||||
r.left(),r.top(),r.right(),r.bottom());
|
||||
|
||||
Reference in New Issue
Block a user