[TD] fix hatch color issue

as discussed: https://forum.freecadweb.org/viewtopic.php?f=35&t=47536&p=407916#p407916
there are 2 types of SVG declarations possible
This commit is contained in:
donovaly
2020-06-13 02:48:52 +02:00
committed by WandererFan
parent 7eaa0497cf
commit 79b267a3dc
2 changed files with 14 additions and 3 deletions

View File

@@ -59,6 +59,7 @@
//
#include "Rez.h"
#include "DrawGuiUtil.h"
#include <QByteArrayMatcher>
#include "QGCustomSvg.h"
#include "QGCustomImage.h"
#include "QGCustomRect.h"
@@ -222,6 +223,17 @@ void QGIFace::loadSvgHatch(std::string fileSpec)
return;
}
m_svgXML = f.readAll();
// search in the file for the "stroke" specifiction in order to find out what specification style is used
// this is necessary to apply a color set by the user to the SVG
QByteArray pattern("stroke:");
QByteArrayMatcher matcher(pattern);
int pos = 0;
if ((pos = matcher.indexIn(m_svgXML, pos)) != -1)
SVGCOLPREFIX = "stroke:"; // declaration part of a style= statement
else
SVGCOLPREFIX = "stroke=\""; // declaration of its own
if (!m_svg->load(&m_svgXML)) {
Base::Console().Error("Error - Could not load hatch into SVG renderer for %s\n", fileSpec.c_str());
return;

View File

@@ -44,8 +44,7 @@ class QGCustomImage;
const double SVGSIZEW = 64.0; //width and height of standard FC SVG pattern
const double SVGSIZEH = 64.0;
const std::string SVGCOLPREFIX = "stroke:";
const std::string SVGCOLDEFAULT = "#000000";
const std::string SVGCOLDEFAULT = "#000000";
class QGIFace : public QGIPrimPath
{
@@ -68,7 +67,7 @@ public:
GeomHatchFill,
PlainFill
};
std::string SVGCOLPREFIX = ""; // will be determined on runtime
int getProjIndex() const { return projIndex; }