From f00fca5474fc5f2d289fda8e5333e2f33e184338 Mon Sep 17 00:00:00 2001 From: wandererfan Date: Thu, 6 Feb 2020 12:00:52 -0500 Subject: [PATCH] [TD]use plain text for Svg export --- src/Mod/TechDraw/Gui/QGIRichAnno.cpp | 76 ++++++++++++++++++++++++---- src/Mod/TechDraw/Gui/QGIRichAnno.h | 6 +-- 2 files changed, 68 insertions(+), 14 deletions(-) diff --git a/src/Mod/TechDraw/Gui/QGIRichAnno.cpp b/src/Mod/TechDraw/Gui/QGIRichAnno.cpp index b54ad551fa..b5db14c853 100644 --- a/src/Mod/TechDraw/Gui/QGIRichAnno.cpp +++ b/src/Mod/TechDraw/Gui/QGIRichAnno.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include @@ -49,6 +50,7 @@ #include #include #include +#include #include #include @@ -231,28 +233,54 @@ void QGIRichAnno::setTextItem() m_text->setTextWidth(Rez::guiX(annoFeat->MaxWidth.getValue())); m_text->setHtml(outHtml); +// setLineSpacing(50); //this has no effect on the display?! +// m_text->update(); + + if (annoFeat->ShowFrame.getValue()) { + QRectF r = m_text->boundingRect().adjusted(1,1,-1,-1); + m_rect->setPen(rectPen()); + m_rect->setBrush(Qt::NoBrush); + m_rect->setRect(r); + m_rect->show(); + } else { + m_rect->hide(); + } } else { - //TODO: fix line spacing. common solutions (style sheet, - // QTextBlock::setLineHeight(150, QTextBlockFormat::ProportionalHeight)) don't help + // don't force line wrap & strip formatting that doesn't export well! double realWidth = m_text->boundingRect().width(); m_text->setTextWidth(realWidth); - m_text->setHtml(inHtml); - } - if (annoFeat->ShowFrame.getValue()) { - QRectF r = m_text->boundingRect().adjusted(1,1,-1,-1); - m_rect->setPen(rectPen()); - m_rect->setBrush(Qt::NoBrush); - m_rect->setRect(r); - m_rect->show(); - } else { + QFont f = prefFont(); + double ptSize = prefPointSize(); + f.setPointSizeF(ptSize); + m_text->setFont(f); + + QString plainText = QTextDocumentFragment::fromHtml( inHtml ).toPlainText(); + m_text->setPlainText(plainText); + setLineSpacing(100); //this doesn't appear in the generated Svg, but does space the lines! m_rect->hide(); + m_rect->update(); } m_text->centerAt(0.0, 0.0); m_rect->centerAt(0.0, 0.0); } +void QGIRichAnno::setLineSpacing(int lineSpacing) +{ + //this line spacing should be px, but seems to be %? in any event, it does + //space out the lines. + QTextBlock block = m_text->document()->begin(); + for (; block.isValid(); block = block.next()) { + QTextCursor tc = QTextCursor(block); + QTextBlockFormat fmt = block.blockFormat(); +// fmt.setTopMargin(lineSpacing); //no effect??? + fmt.setBottomMargin(lineSpacing); //spaces out the lines! + tc.setBlockFormat(fmt); +// } + } +} + //void QGIRichAnno::drawBorder() //{ //////Leaders have no border! @@ -310,4 +338,30 @@ QPen QGIRichAnno::rectPen() const return pen; } +QFont QGIRichAnno::prefFont(void) +{ + Base::Reference hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Labels"); + std::string fontName = hGrp->GetASCII("LabelFont", "osifont"); + QString family = Base::Tools::fromStdString(fontName); + QFont result; + result.setFamily(family); + return result; +} + +double QGIRichAnno::prefPointSize(void) +{ +// Base::Console().Message("QGIRA::prefPointSize()\n"); + Base::Reference hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Dimensions"); + double fontSize = hGrp->GetFloat("FontSize", 5.0); // this is mm, not pts! + + //this conversion is only approximate. the factor changes for different fonts. +// double mmToPts = 2.83; //theoretical value + double mmToPts = 2.00; //practical value. seems to be reasonable for common fonts. + + double ptsSize = round(fontSize * mmToPts); + return ptsSize; +} + #include diff --git a/src/Mod/TechDraw/Gui/QGIRichAnno.h b/src/Mod/TechDraw/Gui/QGIRichAnno.h index 9d074338c2..cc96b1a18e 100644 --- a/src/Mod/TechDraw/Gui/QGIRichAnno.h +++ b/src/Mod/TechDraw/Gui/QGIRichAnno.h @@ -94,11 +94,11 @@ protected: virtual void draw() override; virtual QVariant itemChange( GraphicsItemChange change, const QVariant &value ) override; + void setLineSpacing(int lineSpacing); + double prefPointSize(void); + QFont prefFont(void); bool m_isExporting; - -protected: -/* QGMText* m_text;*/ QGCustomText* m_text; bool m_hasHover; QGCustomRect* m_rect;