diff --git a/src/export.cpp b/src/export.cpp
index 31c6c375..720841c1 100644
--- a/src/export.cpp
+++ b/src/export.cpp
@@ -724,6 +724,9 @@ void VectorFileWriter::OutputLinesAndMesh(SBezierLoopSetSet *sblss, SMesh *sm) {
}
StartFile();
+ if(SS.exportBackgroundColor) {
+ Background(SS.backgroundColor);
+ }
if(sm && SS.exportShadedTriangles) {
for(tr = sm->l.First(); tr; tr = sm->l.NextAfter(tr)) {
Triangle(tr);
diff --git a/src/exportvector.cpp b/src/exportvector.cpp
index 4de45f56..4a184abb 100644
--- a/src/exportvector.cpp
+++ b/src/exportvector.cpp
@@ -551,6 +551,9 @@ void DxfFileWriter::StartFile() {
paths.clear();
}
+void DxfFileWriter::Background(RgbaColor color) {
+}
+
void DxfFileWriter::StartPath(RgbaColor strokeRgb, double lineWidth,
bool filled, RgbaColor fillRgb, hStyle hs)
{
@@ -696,6 +699,35 @@ void EpsFileWriter::StartFile() {
MmToPts(ptMax.y - ptMin.y));
}
+void EpsFileWriter::Background(RgbaColor color) {
+ double width = ptMax.x - ptMin.x;
+ double height = ptMax.y - ptMin.y;
+
+ fprintf(f,
+"%.3f %.3f %.3f setrgbcolor\r\n"
+"newpath\r\n"
+" %.3f %.3f moveto\r\n"
+" %.3f %.3f lineto\r\n"
+" %.3f %.3f lineto\r\n"
+" %.3f %.3f lineto\r\n"
+" closepath\r\n"
+"gsave fill grestore\r\n",
+ color.redF(), color.greenF(), color.blueF(),
+ MmToPts(0), MmToPts(0),
+ MmToPts(width), MmToPts(0),
+ MmToPts(width), MmToPts(height),
+ MmToPts(0), MmToPts(height));
+
+ // same issue with cracks, stroke it to avoid them
+ double sw = max(width, height) / 1000;
+ fprintf(f,
+"1 setlinejoin\r\n"
+"1 setlinecap\r\n"
+"%.3f setlinewidth\r\n"
+"gsave stroke grestore\r\n",
+ MmToPts(sw));
+}
+
void EpsFileWriter::StartPath(RgbaColor strokeRgb, double lineWidth,
bool filled, RgbaColor fillRgb, hStyle hs)
{
@@ -926,6 +958,30 @@ void PdfFileWriter::FinishAndCloseFile() {
}
+void PdfFileWriter::Background(RgbaColor color) {
+ double width = ptMax.x - ptMin.x;
+ double height = ptMax.y - ptMin.y;
+ double sw = max(width, height) / 1000;
+
+ fprintf(f,
+"1 J 1 j\r\n"
+"%.3f %.3f %.3f RG\r\n"
+"%.3f %.3f %.3f rg\r\n"
+"%.3f w\r\n"
+"%.3f %.3f m\r\n"
+"%.3f %.3f l\r\n"
+"%.3f %.3f l\r\n"
+"%.3f %.3f l\r\n"
+"b\r\n",
+ color.redF(), color.greenF(), color.blueF(),
+ color.redF(), color.greenF(), color.blueF(),
+ MmToPts(sw),
+ MmToPts(0), MmToPts(0),
+ MmToPts(width), MmToPts(0),
+ MmToPts(width), MmToPts(height),
+ MmToPts(0), MmToPts(height));
+}
+
void PdfFileWriter::StartPath(RgbaColor strokeRgb, double lineWidth,
bool filled, RgbaColor fillRgb, hStyle hs)
{
@@ -1051,6 +1107,16 @@ void SvgFileWriter::StartFile() {
fprintf(f, "]]>\r\n");
}
+void SvgFileWriter::Background(RgbaColor color) {
+ fprintf(f,
+"\r\n",
+ color.red, color.green, color.blue);
+}
+
void SvgFileWriter::StartPath(RgbaColor strokeRgb, double lineWidth,
bool filled, RgbaColor fillRgb, hStyle hs)
{
@@ -1146,6 +1212,9 @@ void HpglFileWriter::StartFile() {
fprintf(f, "SP1;\r\n");
}
+void HpglFileWriter::Background(RgbaColor color) {
+}
+
void HpglFileWriter::StartPath(RgbaColor strokeRgb, double lineWidth,
bool filled, RgbaColor fillRgb, hStyle hs)
{
@@ -1187,6 +1256,8 @@ void GCodeFileWriter::StartPath(RgbaColor strokeRgb, double lineWidth,
bool filled, RgbaColor fillRgb, hStyle hs)
{
}
+void GCodeFileWriter::Background(RgbaColor color) {
+}
void GCodeFileWriter::FinishPath(RgbaColor strokeRgb, double lineWidth,
bool filled, RgbaColor fillRgb, hStyle hs)
{
@@ -1248,6 +1319,9 @@ void Step2dFileWriter::StartFile() {
sfw.WriteHeader();
}
+void Step2dFileWriter::Background(RgbaColor color) {
+}
+
void Step2dFileWriter::Triangle(STriangle *tr) {
}
diff --git a/src/solvespace.h b/src/solvespace.h
index f98a53f0..425e4c8d 100644
--- a/src/solvespace.h
+++ b/src/solvespace.h
@@ -339,6 +339,7 @@ public:
virtual void Bezier(SBezier *sb) = 0;
virtual void Triangle(STriangle *tr) = 0;
virtual bool OutputConstraints(IdList *) { return false; }
+ virtual void Background(RgbaColor color) = 0;
virtual void StartFile() = 0;
virtual void FinishAndCloseFile() = 0;
virtual bool HasCanvasSize() const = 0;
@@ -363,6 +364,7 @@ public:
bool filled, RgbaColor fillRgb, hStyle hs) override;
void Triangle(STriangle *tr) override;
void Bezier(SBezier *sb) override;
+ void Background(RgbaColor color) override;
void StartFile() override;
void FinishAndCloseFile() override;
bool HasCanvasSize() const override { return false; }
@@ -380,6 +382,7 @@ public:
bool filled, RgbaColor fillRgb, hStyle hs) override;
void Triangle(STriangle *tr) override;
void Bezier(SBezier *sb) override;
+ void Background(RgbaColor color) override;
void StartFile() override;
void FinishAndCloseFile() override;
bool HasCanvasSize() const override { return true; }
@@ -398,6 +401,7 @@ public:
bool filled, RgbaColor fillRgb, hStyle hs) override;
void Triangle(STriangle *tr) override;
void Bezier(SBezier *sb) override;
+ void Background(RgbaColor color) override;
void StartFile() override;
void FinishAndCloseFile() override;
bool HasCanvasSize() const override { return true; }
@@ -414,6 +418,7 @@ public:
bool filled, RgbaColor fillRgb, hStyle hs) override;
void Triangle(STriangle *tr) override;
void Bezier(SBezier *sb) override;
+ void Background(RgbaColor color) override;
void StartFile() override;
void FinishAndCloseFile() override;
bool HasCanvasSize() const override { return true; }
@@ -428,6 +433,7 @@ public:
bool filled, RgbaColor fillRgb, hStyle hs) override;
void Triangle(STriangle *tr) override;
void Bezier(SBezier *sb) override;
+ void Background(RgbaColor color) override;
void StartFile() override;
void FinishAndCloseFile() override;
bool HasCanvasSize() const override { return false; }
@@ -441,6 +447,7 @@ class Step2dFileWriter : public VectorFileWriter {
bool filled, RgbaColor fillRgb, hStyle hs) override;
void Triangle(STriangle *tr) override;
void Bezier(SBezier *sb) override;
+ void Background(RgbaColor color) override;
void StartFile() override;
void FinishAndCloseFile() override;
bool HasCanvasSize() const override { return false; }
@@ -455,6 +462,7 @@ public:
bool filled, RgbaColor fillRgb, hStyle hs) override;
void Triangle(STriangle *tr) override;
void Bezier(SBezier *sb) override;
+ void Background(RgbaColor color) override;
void StartFile() override;
void FinishAndCloseFile() override;
bool HasCanvasSize() const override { return false; }