diff --git a/src/confscreen.cpp b/src/confscreen.cpp index b988df5..347d77b 100644 --- a/src/confscreen.cpp +++ b/src/confscreen.cpp @@ -94,6 +94,10 @@ void TextWindow::ScreenChangeFixExportColors(int link, uint32_t v) { SS.fixExportColors = !SS.fixExportColors; } +void TextWindow::ScreenChangeExportBackgroundColor(int link, uint32_t v) { + SS.exportBackgroundColor = !SS.exportBackgroundColor; +} + void TextWindow::ScreenChangeBackFaces(int link, uint32_t v) { SS.drawBackFaces = !SS.drawBackFaces; SS.GW.Invalidate(/*clearPersistent=*/true); @@ -299,6 +303,9 @@ void TextWindow::ShowConfiguration() { Printf(false, " %Fd%f%Ll%s fix white exported lines%E", &ScreenChangeFixExportColors, SS.fixExportColors ? CHECK_TRUE : CHECK_FALSE); + Printf(false, " %Fd%f%Ll%s export background color%E", + &ScreenChangeExportBackgroundColor, + SS.exportBackgroundColor ? CHECK_TRUE : CHECK_FALSE); Printf(false, ""); Printf(false, "%Ft export canvas size: " diff --git a/src/platform/entrycli.cpp b/src/platform/entrycli.cpp index 95d60a9..8d961b4 100644 --- a/src/platform/entrycli.cpp +++ b/src/platform/entrycli.cpp @@ -25,6 +25,8 @@ Common options: piecewise linear, and exact surfaces into triangle meshes. For export commands, the unit is mm, and the default is 1.0 mm. For non-export commands, the unit is %%, and the default is 1.0 %%. + -b, --bg-color + Whether to export the background colour in vector formats. Defaults to off. Commands: thumbnail --output --size --view @@ -33,6 +35,7 @@ Commands: is x, in pixels. Graphics acceleration is not used, and the output may look slightly different from the GUI. export-view --output --view [--chord-tol ] + [--bg-color ] Exports a view of the sketch, in a 2d vector format. export-wireframe --output [--chord-tol ] Exports a wireframe of the sketch, in a 3d vector format. @@ -155,6 +158,21 @@ static bool RunCommand(const std::vector args) { } else return false; }; + bool bg_color = false; + auto ParseBgColor = [&](size_t &argn) { + if(argn + 1 < args.size() && (args[argn] == "--bg-color" || + args[argn] == "-b")) { + argn++; + if(args[argn] == "on") { + bg_color = true; + return true; + } else if(args[argn] == "off") { + bg_color = false; + return true; + } else return false; + } else return false; + }; + unsigned width = 0, height = 0; if(args[1] == "thumbnail") { auto ParseSize = [&](size_t &argn) { @@ -221,7 +239,8 @@ static bool RunCommand(const std::vector args) { if(!(ParseInputFile(argn) || ParseOutputPattern(argn) || ParseViewDirection(argn) || - ParseChordTolerance(argn))) { + ParseChordTolerance(argn) || + ParseBgColor(argn))) { fprintf(stderr, "Unrecognized option '%s'.\n", args[argn].c_str()); return false; } @@ -233,9 +252,10 @@ static bool RunCommand(const std::vector args) { } runner = [&](const Platform::Path &output) { - SS.GW.projRight = projRight; - SS.GW.projUp = projUp; - SS.exportChordTol = chordTol; + SS.GW.projRight = projRight; + SS.GW.projUp = projUp; + SS.exportChordTol = chordTol; + SS.exportBackgroundColor = bg_color; SS.ExportViewOrWireframeTo(output, /*exportWireframe=*/false); }; diff --git a/src/solvespace.cpp b/src/solvespace.cpp index b058651..697e740 100644 --- a/src/solvespace.cpp +++ b/src/solvespace.cpp @@ -68,6 +68,8 @@ void SolveSpaceUI::Init() { exportOffset = settings->ThawFloat("ExportOffset", 0.0); // Rewrite exported colors close to white into black (assuming white bg) fixExportColors = settings->ThawBool("FixExportColors", true); + // Export background color + exportBackgroundColor = settings->ThawBool("ExportBackgroundColor", false); // Draw back faces of triangles (when mesh is leaky/self-intersecting) drawBackFaces = settings->ThawBool("DrawBackFaces", true); // Use turntable mouse navigation @@ -246,6 +248,8 @@ void SolveSpaceUI::Exit() { settings->FreezeFloat("ExportOffset", exportOffset); // Rewrite exported colors close to white into black (assuming white bg) settings->FreezeBool("FixExportColors", fixExportColors); + // Export background color + settings->FreezeBool("ExportBackgroundColor", exportBackgroundColor); // Draw back faces of triangles (when mesh is leaky/self-intersecting) settings->FreezeBool("DrawBackFaces", drawBackFaces); // Draw closed polygons areas diff --git a/src/solvespace.h b/src/solvespace.h index 4278439..f98a53f 100644 --- a/src/solvespace.h +++ b/src/solvespace.h @@ -559,6 +559,7 @@ public: double exportScale; double exportOffset; bool fixExportColors; + bool exportBackgroundColor; bool drawBackFaces; bool showContourAreas; bool checkClosedContour; diff --git a/src/ui.h b/src/ui.h index fc2d7d8..9e9bf50 100644 --- a/src/ui.h +++ b/src/ui.h @@ -434,6 +434,7 @@ public: static void ScreenGoToWebsite(int link, uint32_t v); static void ScreenChangeFixExportColors(int link, uint32_t v); + static void ScreenChangeExportBackgroundColor(int link, uint32_t v); static void ScreenChangeBackFaces(int link, uint32_t v); static void ScreenChangeShowContourAreas(int link, uint32_t v); static void ScreenChangeCheckClosedContour(int link, uint32_t v);