Export backgrounds in vector files
VectorFileWriter::Background() is an empty impl, except that it writes * a rectangle the size of the output for EPS and PDF, and * a <style> element setting background-color for SVG Ref: #525pull/694/head
parent
028b613f10
commit
360b347ad7
|
@ -724,6 +724,9 @@ void VectorFileWriter::OutputLinesAndMesh(SBezierLoopSetSet *sblss, SMesh *sm) {
|
||||||
}
|
}
|
||||||
|
|
||||||
StartFile();
|
StartFile();
|
||||||
|
if(SS.exportBackgroundColor) {
|
||||||
|
Background(SS.backgroundColor);
|
||||||
|
}
|
||||||
if(sm && SS.exportShadedTriangles) {
|
if(sm && SS.exportShadedTriangles) {
|
||||||
for(tr = sm->l.First(); tr; tr = sm->l.NextAfter(tr)) {
|
for(tr = sm->l.First(); tr; tr = sm->l.NextAfter(tr)) {
|
||||||
Triangle(tr);
|
Triangle(tr);
|
||||||
|
|
|
@ -551,6 +551,9 @@ void DxfFileWriter::StartFile() {
|
||||||
paths.clear();
|
paths.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DxfFileWriter::Background(RgbaColor color) {
|
||||||
|
}
|
||||||
|
|
||||||
void DxfFileWriter::StartPath(RgbaColor strokeRgb, double lineWidth,
|
void DxfFileWriter::StartPath(RgbaColor strokeRgb, double lineWidth,
|
||||||
bool filled, RgbaColor fillRgb, hStyle hs)
|
bool filled, RgbaColor fillRgb, hStyle hs)
|
||||||
{
|
{
|
||||||
|
@ -696,6 +699,35 @@ void EpsFileWriter::StartFile() {
|
||||||
MmToPts(ptMax.y - ptMin.y));
|
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,
|
void EpsFileWriter::StartPath(RgbaColor strokeRgb, double lineWidth,
|
||||||
bool filled, RgbaColor fillRgb, hStyle hs)
|
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,
|
void PdfFileWriter::StartPath(RgbaColor strokeRgb, double lineWidth,
|
||||||
bool filled, RgbaColor fillRgb, hStyle hs)
|
bool filled, RgbaColor fillRgb, hStyle hs)
|
||||||
{
|
{
|
||||||
|
@ -1051,6 +1107,16 @@ void SvgFileWriter::StartFile() {
|
||||||
fprintf(f, "]]></style>\r\n");
|
fprintf(f, "]]></style>\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SvgFileWriter::Background(RgbaColor color) {
|
||||||
|
fprintf(f,
|
||||||
|
"<style><![CDATA[\r\n"
|
||||||
|
"svg {\r\n"
|
||||||
|
"background-color:#%02x%02x%02x;\r\n"
|
||||||
|
"}\r\n"
|
||||||
|
"]]></style>\r\n",
|
||||||
|
color.red, color.green, color.blue);
|
||||||
|
}
|
||||||
|
|
||||||
void SvgFileWriter::StartPath(RgbaColor strokeRgb, double lineWidth,
|
void SvgFileWriter::StartPath(RgbaColor strokeRgb, double lineWidth,
|
||||||
bool filled, RgbaColor fillRgb, hStyle hs)
|
bool filled, RgbaColor fillRgb, hStyle hs)
|
||||||
{
|
{
|
||||||
|
@ -1146,6 +1212,9 @@ void HpglFileWriter::StartFile() {
|
||||||
fprintf(f, "SP1;\r\n");
|
fprintf(f, "SP1;\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HpglFileWriter::Background(RgbaColor color) {
|
||||||
|
}
|
||||||
|
|
||||||
void HpglFileWriter::StartPath(RgbaColor strokeRgb, double lineWidth,
|
void HpglFileWriter::StartPath(RgbaColor strokeRgb, double lineWidth,
|
||||||
bool filled, RgbaColor fillRgb, hStyle hs)
|
bool filled, RgbaColor fillRgb, hStyle hs)
|
||||||
{
|
{
|
||||||
|
@ -1187,6 +1256,8 @@ void GCodeFileWriter::StartPath(RgbaColor strokeRgb, double lineWidth,
|
||||||
bool filled, RgbaColor fillRgb, hStyle hs)
|
bool filled, RgbaColor fillRgb, hStyle hs)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
void GCodeFileWriter::Background(RgbaColor color) {
|
||||||
|
}
|
||||||
void GCodeFileWriter::FinishPath(RgbaColor strokeRgb, double lineWidth,
|
void GCodeFileWriter::FinishPath(RgbaColor strokeRgb, double lineWidth,
|
||||||
bool filled, RgbaColor fillRgb, hStyle hs)
|
bool filled, RgbaColor fillRgb, hStyle hs)
|
||||||
{
|
{
|
||||||
|
@ -1248,6 +1319,9 @@ void Step2dFileWriter::StartFile() {
|
||||||
sfw.WriteHeader();
|
sfw.WriteHeader();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Step2dFileWriter::Background(RgbaColor color) {
|
||||||
|
}
|
||||||
|
|
||||||
void Step2dFileWriter::Triangle(STriangle *tr) {
|
void Step2dFileWriter::Triangle(STriangle *tr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -339,6 +339,7 @@ public:
|
||||||
virtual void Bezier(SBezier *sb) = 0;
|
virtual void Bezier(SBezier *sb) = 0;
|
||||||
virtual void Triangle(STriangle *tr) = 0;
|
virtual void Triangle(STriangle *tr) = 0;
|
||||||
virtual bool OutputConstraints(IdList<Constraint,hConstraint> *) { return false; }
|
virtual bool OutputConstraints(IdList<Constraint,hConstraint> *) { return false; }
|
||||||
|
virtual void Background(RgbaColor color) = 0;
|
||||||
virtual void StartFile() = 0;
|
virtual void StartFile() = 0;
|
||||||
virtual void FinishAndCloseFile() = 0;
|
virtual void FinishAndCloseFile() = 0;
|
||||||
virtual bool HasCanvasSize() const = 0;
|
virtual bool HasCanvasSize() const = 0;
|
||||||
|
@ -363,6 +364,7 @@ public:
|
||||||
bool filled, RgbaColor fillRgb, hStyle hs) override;
|
bool filled, RgbaColor fillRgb, hStyle hs) override;
|
||||||
void Triangle(STriangle *tr) override;
|
void Triangle(STriangle *tr) override;
|
||||||
void Bezier(SBezier *sb) override;
|
void Bezier(SBezier *sb) override;
|
||||||
|
void Background(RgbaColor color) override;
|
||||||
void StartFile() override;
|
void StartFile() override;
|
||||||
void FinishAndCloseFile() override;
|
void FinishAndCloseFile() override;
|
||||||
bool HasCanvasSize() const override { return false; }
|
bool HasCanvasSize() const override { return false; }
|
||||||
|
@ -380,6 +382,7 @@ public:
|
||||||
bool filled, RgbaColor fillRgb, hStyle hs) override;
|
bool filled, RgbaColor fillRgb, hStyle hs) override;
|
||||||
void Triangle(STriangle *tr) override;
|
void Triangle(STriangle *tr) override;
|
||||||
void Bezier(SBezier *sb) override;
|
void Bezier(SBezier *sb) override;
|
||||||
|
void Background(RgbaColor color) override;
|
||||||
void StartFile() override;
|
void StartFile() override;
|
||||||
void FinishAndCloseFile() override;
|
void FinishAndCloseFile() override;
|
||||||
bool HasCanvasSize() const override { return true; }
|
bool HasCanvasSize() const override { return true; }
|
||||||
|
@ -398,6 +401,7 @@ public:
|
||||||
bool filled, RgbaColor fillRgb, hStyle hs) override;
|
bool filled, RgbaColor fillRgb, hStyle hs) override;
|
||||||
void Triangle(STriangle *tr) override;
|
void Triangle(STriangle *tr) override;
|
||||||
void Bezier(SBezier *sb) override;
|
void Bezier(SBezier *sb) override;
|
||||||
|
void Background(RgbaColor color) override;
|
||||||
void StartFile() override;
|
void StartFile() override;
|
||||||
void FinishAndCloseFile() override;
|
void FinishAndCloseFile() override;
|
||||||
bool HasCanvasSize() const override { return true; }
|
bool HasCanvasSize() const override { return true; }
|
||||||
|
@ -414,6 +418,7 @@ public:
|
||||||
bool filled, RgbaColor fillRgb, hStyle hs) override;
|
bool filled, RgbaColor fillRgb, hStyle hs) override;
|
||||||
void Triangle(STriangle *tr) override;
|
void Triangle(STriangle *tr) override;
|
||||||
void Bezier(SBezier *sb) override;
|
void Bezier(SBezier *sb) override;
|
||||||
|
void Background(RgbaColor color) override;
|
||||||
void StartFile() override;
|
void StartFile() override;
|
||||||
void FinishAndCloseFile() override;
|
void FinishAndCloseFile() override;
|
||||||
bool HasCanvasSize() const override { return true; }
|
bool HasCanvasSize() const override { return true; }
|
||||||
|
@ -428,6 +433,7 @@ public:
|
||||||
bool filled, RgbaColor fillRgb, hStyle hs) override;
|
bool filled, RgbaColor fillRgb, hStyle hs) override;
|
||||||
void Triangle(STriangle *tr) override;
|
void Triangle(STriangle *tr) override;
|
||||||
void Bezier(SBezier *sb) override;
|
void Bezier(SBezier *sb) override;
|
||||||
|
void Background(RgbaColor color) override;
|
||||||
void StartFile() override;
|
void StartFile() override;
|
||||||
void FinishAndCloseFile() override;
|
void FinishAndCloseFile() override;
|
||||||
bool HasCanvasSize() const override { return false; }
|
bool HasCanvasSize() const override { return false; }
|
||||||
|
@ -441,6 +447,7 @@ class Step2dFileWriter : public VectorFileWriter {
|
||||||
bool filled, RgbaColor fillRgb, hStyle hs) override;
|
bool filled, RgbaColor fillRgb, hStyle hs) override;
|
||||||
void Triangle(STriangle *tr) override;
|
void Triangle(STriangle *tr) override;
|
||||||
void Bezier(SBezier *sb) override;
|
void Bezier(SBezier *sb) override;
|
||||||
|
void Background(RgbaColor color) override;
|
||||||
void StartFile() override;
|
void StartFile() override;
|
||||||
void FinishAndCloseFile() override;
|
void FinishAndCloseFile() override;
|
||||||
bool HasCanvasSize() const override { return false; }
|
bool HasCanvasSize() const override { return false; }
|
||||||
|
@ -455,6 +462,7 @@ public:
|
||||||
bool filled, RgbaColor fillRgb, hStyle hs) override;
|
bool filled, RgbaColor fillRgb, hStyle hs) override;
|
||||||
void Triangle(STriangle *tr) override;
|
void Triangle(STriangle *tr) override;
|
||||||
void Bezier(SBezier *sb) override;
|
void Bezier(SBezier *sb) override;
|
||||||
|
void Background(RgbaColor color) override;
|
||||||
void StartFile() override;
|
void StartFile() override;
|
||||||
void FinishAndCloseFile() override;
|
void FinishAndCloseFile() override;
|
||||||
bool HasCanvasSize() const override { return false; }
|
bool HasCanvasSize() const override { return false; }
|
||||||
|
|
Loading…
Reference in New Issue