From 76be82dc2e34e7f9898fac8e25d7153e539ea522 Mon Sep 17 00:00:00 2001 From: wandererfan Date: Sun, 25 Aug 2019 19:07:19 -0400 Subject: [PATCH] [Gui]Add options for page size, lineWidth and background --- src/Gui/SoFCVectorizeSVGAction.cpp | 27 +++++++++++++++++++-------- src/Gui/SoFCVectorizeSVGAction.h | 10 ++++++++++ 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/Gui/SoFCVectorizeSVGAction.cpp b/src/Gui/SoFCVectorizeSVGAction.cpp index e36a366a9a..893e0f2190 100644 --- a/src/Gui/SoFCVectorizeSVGAction.cpp +++ b/src/Gui/SoFCVectorizeSVGAction.cpp @@ -31,6 +31,7 @@ #include #include +#include #include "SoFCVectorizeSVGAction.h" using namespace Gui; @@ -306,7 +307,7 @@ void SoFCVectorizeSVGActionP::printTriangle(const SbVec3f * v, const SbColor * c << "; stroke:#" << std::hex << std::setw(6) << std::setfill('0') << (cc >> 8) << ";" << std::endl - << " stroke-width:1.0;" << std::endl + << " stroke-width:" << publ->getLineWidth() << ";" << std::endl << " stroke-linecap:round;stroke-linejoin:round\"/>" << std::endl; } @@ -350,8 +351,9 @@ void SoFCVectorizeSVGActionP::printLine(const SoVectorizeLine * item) const << "x1=\"" << v[0][0] << "\" y1=\"" << v[0][1] << "\" " << "x2=\"" << v[1][0] << "\" y2=\"" << v[1][1] << "\" " << "stroke=\"#" - << std::hex << std::setw(6) << std::setfill('0') << (cc >> 8) - << "\" stroke-width=\"1px\" />\n"; + << std::hex << std::setw(6) << std::setfill('0') << (cc >> 8) << "\"" + << " stroke-linecap=\"square\" " + << " stroke-width=\"" << publ->getLineWidth() << "\" />\n"; } void SoFCVectorizeSVGActionP::printPoint(const SoVectorizePoint * item) const @@ -375,7 +377,10 @@ void SoFCVectorizeSVGAction::initClass(void) SO_ACTION_INIT_CLASS(SoFCVectorizeSVGAction, SoVectorizeAction); } -SoFCVectorizeSVGAction::SoFCVectorizeSVGAction() +SoFCVectorizeSVGAction::SoFCVectorizeSVGAction() : + m_backgroundState(true), + m_lineWidth(1.0), + m_usemm(false) { SO_ACTION_CONSTRUCTOR(SoFCVectorizeSVGAction); this->setOutput(new SoSVGVectorOutput); @@ -400,12 +405,18 @@ void SoFCVectorizeSVGAction::printHeader(void) const str << "" << std::endl; str << "getOrientation() == LANDSCAPE) + if (this->getOrientation() == LANDSCAPE) { SbSwap(size[0], size[1]); - str << " width=\"" << size[0] << "\" height=\"" << size[1] << "\">" << std::endl; + } + if (getUseMM()) { + str << " width=\"" << size[0] << "mm\" height=\"" << size[1] << "mm\""<< std::endl; + str << " viewBox=\"0 0 " << size[0] << " " << size[1] << "\">" << std::endl; + } else { //original code used px + str << " width=\"" << size[0] << "\" height=\"" << size[1] << "\">" << std::endl; + } str << "" << std::endl; } @@ -447,7 +458,7 @@ void SoFCVectorizeSVGAction::printBackground(void) const str << " style=\"fill:#" << std::hex << std::setw(6) << std::setfill('0') << (cc >> 8) << ";fill-opacity:1;fill-rule:evenodd;stroke:none;" - "stroke-width:1px;stroke-linecap:butt;stroke-linejoin:" + "stroke-width:" << getLineWidth() << ";stroke-linecap:butt;stroke-linejoin:" "miter;stroke-opacity:1\" />\n"; str << "" << std::endl; } diff --git a/src/Gui/SoFCVectorizeSVGAction.h b/src/Gui/SoFCVectorizeSVGAction.h index bf6a750fc5..9728d13423 100644 --- a/src/Gui/SoFCVectorizeSVGAction.h +++ b/src/Gui/SoFCVectorizeSVGAction.h @@ -62,6 +62,13 @@ public: static void initClass(void); SoSVGVectorOutput * getSVGOutput(void) const; + virtual void setBackgroundState(bool b) { m_backgroundState = b; } + virtual bool getBackgroundState(void) const { return m_backgroundState; } + virtual void setLineWidth(double w) { m_lineWidth = w; } + virtual double getLineWidth(void) const { return m_lineWidth; } + virtual void setUseMM(bool b) { m_usemm = b; } + virtual bool getUseMM(void) const { return m_usemm; } + protected: virtual void printHeader(void) const; virtual void printFooter(void) const; @@ -72,6 +79,9 @@ protected: private: SoFCVectorizeSVGActionP* p; friend class SoFCVectorizeSVGActionP; + bool m_backgroundState; + double m_lineWidth; + bool m_usemm; }; } // namespace Gui