Skip to content

Commit

Permalink
[TD] fix hatch color issue
Browse files Browse the repository at this point in the history
as discussed: https://forum.freecadweb.org/viewtopic.php?f=35&t=47536&p=407916#p407916
there are 2 types of SVG declarations possible
  • Loading branch information
donovaly authored and WandererFan committed Jun 13, 2020
1 parent 7eaa049 commit 79b267a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
12 changes: 12 additions & 0 deletions src/Mod/TechDraw/Gui/QGIFace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
//
#include "Rez.h"
#include "DrawGuiUtil.h"
#include <QByteArrayMatcher>
#include "QGCustomSvg.h"
#include "QGCustomImage.h"
#include "QGCustomRect.h"
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions src/Mod/TechDraw/Gui/QGIFace.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -68,7 +67,7 @@ class QGIFace : public QGIPrimPath
GeomHatchFill,
PlainFill
};

std::string SVGCOLPREFIX = ""; // will be determined on runtime

int getProjIndex() const { return projIndex; }

Expand Down

0 comments on commit 79b267a

Please sign in to comment.