Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optionally export background colour in vector files #568

Merged

Conversation

nabijaczleweli
Copy link
Contributor

@nabijaczleweli nabijaczleweli commented Mar 25, 2020

Produces non-zero diffs for EPS, PDF, and SVG:

EPS
diff --git a/no.eps b/yes.eps
index 3d6a0a9..86fcb68 100644
--- a/no.eps
+++ b/yes.eps
@@ -9,6 +9,18 @@
 
 gsave
 
+0.000 0.400 0.000 setrgbcolor
+newpath
+    0.000 0.000 moveto
+    176.882 0.000 lineto
+    176.882 159.307 lineto
+    0.000 159.307 lineto
+    closepath
+gsave fill grestore
+1 setlinejoin
+1 setlinecap
+0.177 setlinewidth
+gsave stroke grestore
 newpath
     162.709 14.173 moveto
     162.709 145.134 lineto
PDF
diff --git a/no.pdf b/yes.pdf
index 1a6d964..3d231c0 100644
--- a/no.pdf
+++ b/yes.pdf
@@ -30,6 +30,15 @@ endobj
 5 0 obj
   << /Length 6 0 R >>
 stream
+1 J 1 j
+0.000 0.400 0.000 RG
+0.000 0.400 0.000 rg
+0.177 w
+0.000 0.000 m
+176.882 0.000 l
+176.882 159.307 l
+0.000 159.307 l
+b
 1 J 1 j 0.344 w [] 0 d 0.000 0.000 0.000 RG
 162.709 14.173 m
 162.709 145.134 l
@@ -60,7 +69,7 @@ S
 endstream
 endobj
 6 0 obj
-  501
+  634
 endobj
 7 0 obj
   [/PDF /Text]
@@ -84,10 +93,10 @@ xref
 0000000162 00000 n
 0000000239 00000 n
 0000000457 00000 n
-0000001017 00000 n
-0000001041 00000 n
-0000001074 00000 n
-0000001213 00000 n
+0000001150 00000 n
+0000001174 00000 n
+0000001207 00000 n
+0000001346 00000 n
 
 trailer
   << /Size 10
@@ -95,5 +104,5 @@ trailer
      /Info 9 0 R
   >>
 startxref
-1256
+1389
 %%EOF
SVG
diff --git a/no.svg b/yes.svg
index e1cb614..bc5e698 100644
--- a/no.svg
+++ b/yes.svg
@@ -115,6 +115,7 @@ stroke-linejoin:round;
 fill:none;
 }
 ]]></style>
+<polygon points='0.000,56.200 62.400,56.200 62.400,0.000 0.000,0.000' stroke='#006600' fill='#006600'/>
 <path d='M57.400 51.200 L57.400,5.000 L5.000,5.000 L5.000,51.200 L57.400,51.200 ' class='s0' />
 <path d='M56.147 27.574 L56.470,28.545 L56.794,27.574 M30.917 50.702 L30.917,49.812 M31.483 50.702 L31.483,49.812 M30.917 50.207 L31.483,50.207 M5.606 27.574 L5.930,28.545 L6.253,27.574 M30.917 6.388 L30.917,5.418 M31.483 6.388 L31.483,5.418 M30.917 5.849 L31.483,5.849 ' class='s6' />

Converted to PNG with imagemagick:
EPS, no:
no-eps
EPS, yes:
yes-eps

PDF, no:
no-pdf
PDF, yes:
yes-pdf

SVG, no:
no-svg
SVG, yes:
yes-svg

Config GUI option name might need some bikeshedding: "export background color" isn't exactly right since it's for vector files only "export background color in vector files" maybe?

Exports tested in the GUI only due to #567, but the option gets loaded right before crashing, so it should work.

This doesn't change exporting PNGs since those are screenshots and I don't know how to make them not so/if that's viable at all.

Ref: #525

@whitequark
Copy link
Contributor

I think a new Rectangle function isn't the right approach because, for example, SVG files natively have a notion of background color that isn't exactly replicated by placing such a rectangle.

@nabijaczleweli
Copy link
Contributor Author

That's the approach I tried first but generalising which was quickly defeated by the PDF spec, heh.

Moved the code to Background(), which writes a style element for SVG and the same rectangles for EPS and PDF.

New SVG diff
diff --git a/no.svg b/yes.svg
index 934e483..b2cb55b 100644
--- a/no.svg
+++ b/yes.svg
@@ -115,6 +115,11 @@ stroke-linejoin:round;
 fill:none;
 }
 ]]></style>
+<style><![CDATA[
+svg {
+background-color:#006600;
+}
+]]></style>
 <path d='M57.400 51.200 L57.400,5.000 L5.000,5.000 L5.000,51.200 L57.400,51.200 ' class='s0' />
 <path d='M54.795 27.120 L55.465,28.965 L56.136,27.120 M30.649 50.093 L30.649,48.248 M31.655 50.093 L31.655,48.248 M30.649 49.068 L31.655,49.068 M6.335 27.120 L6.922,28.965 L7.509,27.120 M30.649 7.837 L30.649,5.825 M31.655 7.837 L31.655,5.825 M30.649 6.719 L31.655,6.719 ' class='s6' />

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: solvespace#525
@nabijaczleweli nabijaczleweli force-pushed the export-background-colour-vector branch from d4b0a64 to 5fc14c1 Compare June 27, 2020 20:44
@phkahler
Copy link
Member

phkahler commented Sep 4, 2020

@whitequark what's the status of this one?

@phkahler phkahler merged commit 360b347 into solvespace:master Sep 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants