[TD]fix Text sizes not exact
This commit is contained in:
committed by
WandererFan
parent
8b4e114b9d
commit
71426aa467
@@ -54,7 +54,7 @@ QGIGhostHighlight::QGIGhostHighlight()
|
||||
m_dragging = false;
|
||||
|
||||
//make the ghost very visible
|
||||
QFont f(QGIView::getPrefFont());
|
||||
QFont f(Preferences::labelFontQString());
|
||||
double fontSize = Preferences::labelFontSizeMM();
|
||||
setFont(f, fontSize);
|
||||
setReference("drag");
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include <App/Material.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Parameter.h>
|
||||
#include <Base/Tools.h>
|
||||
|
||||
#include <Mod/TechDraw/App/DrawUtil.h>
|
||||
|
||||
@@ -94,7 +95,9 @@ void QGIHighlight::makeHighlight()
|
||||
void QGIHighlight::makeReference()
|
||||
{
|
||||
prepareGeometryChange();
|
||||
m_refFont.setPixelSize(QGIView::calculateFontPixelSize(m_refSize));
|
||||
int fontSize = QGIView::exactFontSize(Base::Tools::toStdString(m_refFont.family()),
|
||||
m_refSize);
|
||||
m_refFont .setPixelSize(fontSize);
|
||||
m_reference->setFont(m_refFont);
|
||||
m_reference->setPlainText(m_refText);
|
||||
double fudge = Rez::guiX(1.0);
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <App/Material.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Parameter.h>
|
||||
#include <Base/Tools.h>
|
||||
|
||||
//#include <Mod/TechDraw/App/Preferences.h>
|
||||
#include <Mod/TechDraw/App/DrawUtil.h>
|
||||
@@ -189,7 +190,9 @@ void QGISectionLine::makeSymbols()
|
||||
void QGISectionLine::makeSymbolsTrad()
|
||||
{
|
||||
prepareGeometryChange();
|
||||
m_symFont.setPixelSize(QGIView::calculateFontPixelSize(m_symSize));
|
||||
// m_symFont.setPixelSize(QGIView::calculateFontPixelSize(m_symSize));
|
||||
int fontSize = QGIView::exactFontSize(Base::Tools::toStdString(m_symFont.family()), m_symSize);
|
||||
m_symFont.setPixelSize(fontSize);
|
||||
m_symbol1->setFont(m_symFont);
|
||||
m_symbol1->setPlainText(QString::fromUtf8(m_symbol));
|
||||
m_symbol2->setFont(m_symFont);
|
||||
@@ -222,7 +225,9 @@ void QGISectionLine::makeSymbolsTrad()
|
||||
void QGISectionLine::makeSymbolsISO()
|
||||
{
|
||||
prepareGeometryChange();
|
||||
m_symFont.setPixelSize(QGIView::calculateFontPixelSize(m_symSize));
|
||||
// m_symFont.setPixelSize(QGIView::calculateFontPixelSize(m_symSize));
|
||||
int fontSize = QGIView::exactFontSize(Base::Tools::toStdString(m_symFont.family()), m_symSize);
|
||||
m_symFont.setPixelSize(fontSize);
|
||||
m_symbol1->setFont(m_symFont);
|
||||
m_symbol1->setPlainText(QString::fromUtf8(m_symbol));
|
||||
m_symbol2->setFont(m_symFont);
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
#include <App/DocumentObject.h>
|
||||
#include <App/Material.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Tools.h>
|
||||
#include <Gui/Selection.h>
|
||||
#include <Gui/Command.h>
|
||||
#include <Gui/Application.h>
|
||||
@@ -104,10 +105,6 @@ QGIView::QGIView()
|
||||
m_colCurrent = m_colNormal;
|
||||
m_pen.setColor(m_colCurrent);
|
||||
|
||||
//Border/Label styling
|
||||
// m_font.setPixelSize(calculateFontPixelSize(getPrefFontSize()));
|
||||
m_font.setPixelSize(PreferencesGui::labelFontSizePX());
|
||||
|
||||
m_decorPen.setStyle(Qt::DashLine);
|
||||
m_decorPen.setWidth(0); // 0 => 1px "cosmetic pen"
|
||||
|
||||
@@ -445,8 +442,10 @@ void QGIView::drawCaption()
|
||||
prepareGeometryChange();
|
||||
QRectF displayArea = customChildrenBoundingRect();
|
||||
m_caption->setDefaultTextColor(m_colCurrent);
|
||||
m_font.setFamily(getPrefFont());
|
||||
m_font.setPixelSize(PreferencesGui::labelFontSizePX());
|
||||
m_font.setFamily(Preferences::labelFontQString());
|
||||
int fontSize = exactFontSize(Preferences::labelFont(),
|
||||
Preferences::labelFontSizeMM());
|
||||
m_font.setPixelSize(fontSize);
|
||||
m_caption->setFont(m_font);
|
||||
QString captionStr = QString::fromUtf8(getViewObject()->Caption.getValue());
|
||||
m_caption->setPlainText(captionStr);
|
||||
@@ -485,10 +484,12 @@ void QGIView::drawBorder()
|
||||
m_lock->hide();
|
||||
|
||||
m_label->setDefaultTextColor(m_colCurrent);
|
||||
m_font.setFamily(getPrefFont());
|
||||
m_font.setPixelSize(PreferencesGui::labelFontSizePX());
|
||||
|
||||
m_font.setFamily(Preferences::labelFontQString());
|
||||
int fontSize = exactFontSize(Preferences::labelFont(),
|
||||
Preferences::labelFontSizeMM());
|
||||
m_font.setPixelSize(fontSize);
|
||||
m_label->setFont(m_font);
|
||||
|
||||
QString labelStr = QString::fromUtf8(getViewObject()->Label.getValue());
|
||||
m_label->setPlainText(labelStr);
|
||||
QRectF labelArea = m_label->boundingRect(); //m_label coords
|
||||
@@ -728,21 +729,10 @@ Base::Reference<ParameterGrp> QGIView::getParmGroupCol()
|
||||
return hGrp;
|
||||
}
|
||||
|
||||
QString QGIView::getPrefFont()
|
||||
{
|
||||
return Preferences::labelFontQString();
|
||||
}
|
||||
|
||||
double QGIView::getPrefFontSize()
|
||||
{
|
||||
return Preferences::labelFontSizeMM();
|
||||
}
|
||||
|
||||
double QGIView::getDimFontSize()
|
||||
{
|
||||
return Preferences::dimFontSizeMM();
|
||||
}
|
||||
|
||||
//convert input font size in mm to scene units
|
||||
//note that when used to set font size this will result in
|
||||
//text that is smaller than sizeInMillimetres. If exactly
|
||||
//correct sized text is required, use exactFontSize.
|
||||
int QGIView::calculateFontPixelSize(double sizeInMillimetres)
|
||||
{
|
||||
// Calculate font size in pixels by using resolution conversion
|
||||
@@ -763,15 +753,30 @@ void QGIView::dumpRect(const char* text, QRectF rect) {
|
||||
rect.left(), rect.top(), rect.right(), rect.bottom());
|
||||
}
|
||||
|
||||
void QGIView::makeMark(double xPos, double yPos, QColor c)
|
||||
//determine the required font size to generate text with upper case
|
||||
//letter height = nominalSize
|
||||
int QGIView::exactFontSize(std::string fontFamily, double nominalSize)
|
||||
{
|
||||
double sceneSize = Rez::guiX(nominalSize); //desired height in scene units
|
||||
QFont font;
|
||||
font.setFamily(QString::fromUtf8(fontFamily.c_str()));
|
||||
font.setPixelSize(sceneSize);
|
||||
|
||||
QFontMetricsF fm(font);
|
||||
double capHeight = fm.capHeight();
|
||||
double ratio = sceneSize / capHeight;
|
||||
return (int) sceneSize * ratio;
|
||||
}
|
||||
|
||||
void QGIView::makeMark(double xPos, double yPos, QColor color)
|
||||
{
|
||||
QGIVertex* vItem = new QGIVertex(-1);
|
||||
vItem->setParentItem(this);
|
||||
vItem->setPos(xPos, yPos);
|
||||
vItem->setWidth(2.0);
|
||||
vItem->setRadius(20.0);
|
||||
vItem->setNormalColor(c);
|
||||
vItem->setFillColor(c);
|
||||
vItem->setNormalColor(color);
|
||||
vItem->setFillColor(color);
|
||||
vItem->setPrettyNormal();
|
||||
vItem->setZValue(ZVALUE::VERTEX);
|
||||
}
|
||||
|
||||
@@ -149,6 +149,9 @@ public:
|
||||
static double getDimFontSize();
|
||||
QFont getFont() { return m_font; };
|
||||
void setFont(QFont font) { m_font = font; }
|
||||
|
||||
static int exactFontSize(std::string fontFamily, double nominalSize);
|
||||
|
||||
virtual void removeChild(QGIView* child);
|
||||
|
||||
virtual void addArbitraryItem(QGraphicsItem* qgi);
|
||||
|
||||
@@ -127,14 +127,14 @@ void QGIViewAnnotation::drawAnnotation()
|
||||
}
|
||||
|
||||
const std::vector<std::string>& annoText = viewAnno->Text.getValues();
|
||||
int fontSize = calculateFontPixelSize(viewAnno->TextSize.getValue());
|
||||
int scaledSize = exactFontSize(viewAnno->Font.getValue(), viewAnno->TextSize.getValue());
|
||||
|
||||
//build HTML/CSS formatting around Text lines
|
||||
std::stringstream ss;
|
||||
ss << "<html>\n<head>\n<style>\n";
|
||||
ss << "p {";
|
||||
ss << "font-family:" << viewAnno->Font.getValue() << "; ";
|
||||
ss << "font-size:" << fontSize << "px; ";
|
||||
ss << "font-size:" << scaledSize << "px; ";
|
||||
if (viewAnno->TextStyle.isValue("Normal")) {
|
||||
ss << "font-weight:normal; font-style:normal; ";
|
||||
} else if (viewAnno->TextStyle.isValue("Bold")) {
|
||||
@@ -160,7 +160,7 @@ void QGIViewAnnotation::drawAnnotation()
|
||||
std::string lt = std::regex_replace((*it), std::regex("<"), "<");
|
||||
ss << lt;
|
||||
}
|
||||
ss << "<br></p>\n</body>\n</html> ";
|
||||
ss << "</p>\n</body>\n</html> ";
|
||||
|
||||
prepareGeometryChange();
|
||||
m_textItem->setTextWidth(Rez::guiX(viewAnno->MaxWidth.getValue()));
|
||||
|
||||
@@ -437,9 +437,10 @@ void QGIViewBalloon::updateBalloon(bool obtuse)
|
||||
return;
|
||||
}
|
||||
|
||||
QFont font = balloonLabel->getFont();
|
||||
font.setPixelSize(calculateFontPixelSize(vp->Fontsize.getValue()));
|
||||
QFont font;
|
||||
font.setFamily(QString::fromUtf8(vp->Font.getValue()));
|
||||
font.setPixelSize(exactFontSize(vp->Font.getValue(),
|
||||
vp->Fontsize.getValue()));
|
||||
balloonLabel->setFont(font);
|
||||
|
||||
QString labelText = QString::fromUtf8(balloon->Text.getStrValue().data());
|
||||
@@ -575,7 +576,10 @@ void QGIViewBalloon::placeBalloon(QPointF pos)
|
||||
QFont font = balloonLabel->getFont();
|
||||
font.setPixelSize(calculateFontPixelSize(vp->Fontsize.getValue()));
|
||||
font.setFamily(QString::fromUtf8(vp->Font.getValue()));
|
||||
font.setPixelSize(exactFontSize(vp->Font.getValue(),
|
||||
vp->Fontsize.getValue()));
|
||||
balloonLabel->setFont(font);
|
||||
|
||||
prepareGeometryChange();
|
||||
|
||||
// Default label position
|
||||
|
||||
@@ -655,7 +655,9 @@ void QGIViewDimension::updateDim()
|
||||
|
||||
QFont font = datumLabel->getFont();
|
||||
font.setFamily(QString::fromUtf8(vp->Font.getValue()));
|
||||
font.setPixelSize(calculateFontPixelSize(vp->Fontsize.getValue()));
|
||||
int fontSize = QGIView::exactFontSize(vp->Font.getValue(),
|
||||
vp->Fontsize.getValue());
|
||||
font.setPixelSize(fontSize);
|
||||
datumLabel->setFont(font);
|
||||
|
||||
prepareGeometryChange();
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
#include <App/Material.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Parameter.h>
|
||||
#include <Base/Tools.h>
|
||||
#include <Base/Vector3D.h>
|
||||
#include <Gui/ViewProvider.h>
|
||||
|
||||
|
||||
@@ -197,9 +197,8 @@ void QGIWeldSymbol::drawTile(TechDraw::DrawTileWeld* tileFeat)
|
||||
if (!vp)
|
||||
return;
|
||||
std::string fontName = vp->Font.getValue();
|
||||
double sizeMM = vp->TileFontSize.getValue();
|
||||
double fontSize = QGIView::calculateFontPixelSize(sizeMM);
|
||||
|
||||
int fontSize = QGIView::exactFontSize(vp->Font.getValue(),
|
||||
vp->TileFontSize.getValue());
|
||||
double featScale = m_leadFeat->getScale();
|
||||
|
||||
std::string tileTextL = tileFeat->LeftText.getValue();
|
||||
@@ -268,12 +267,12 @@ void QGIWeldSymbol::drawTailText()
|
||||
if (!sym)
|
||||
return;
|
||||
auto vp = static_cast<ViewProviderWeld*>(getViewProvider(getViewObject()));
|
||||
if (!vp)
|
||||
if (!vp) {
|
||||
return;
|
||||
std::string fontName = vp->Font.getValue();
|
||||
QString qFontName = Base::Tools::fromStdString(fontName);
|
||||
double sizeMM = vp->FontSize.getValue();
|
||||
double fontSize = QGIView::calculateFontPixelSize(sizeMM);
|
||||
}
|
||||
QString qFontName = Base::Tools::fromStdString(vp->Font.getValue());
|
||||
int fontSize = QGIView::exactFontSize(vp->Font.getValue(),
|
||||
vp->FontSize.getValue());
|
||||
|
||||
m_font.setFamily(qFontName);
|
||||
m_font.setPixelSize(fontSize);
|
||||
|
||||
Reference in New Issue
Block a user