]> mj.ucw.cz Git - paperjam.git/commitdiff
Settable colors of cropmarks
authorMartin Mares <mj@ucw.cz>
Fri, 6 Apr 2018 20:41:31 +0000 (22:41 +0200)
committerMartin Mares <mj@ucw.cz>
Fri, 6 Apr 2018 20:41:31 +0000 (22:41 +0200)
TODO
cmds.cc

diff --git a/TODO b/TODO
index e38d0d80c2cc6e04139041856663f44a8b1659bc..558dc726a5930418e87e5bab0e9880e9a03d81a5 100644 (file)
--- a/TODO
+++ b/TODO
@@ -3,7 +3,6 @@
 - Better error messages from instantiation
 - "-f" switch
 - Help
-- Cropmarks: settable colors
 
 | # Position bbox on a new paper
 | paper("a4")
@@ -38,6 +37,7 @@
 |      pen=1pt         # Line width
 |      len=5mm         # Cross arm length
 |      offset=5mm      # Distance from border
+|      color="RRGGBB"
 
 | book
 |      signature=<n>
@@ -74,7 +74,7 @@ duplex
 |      rotate=1        # Override rotation decision
 |      scale=1         # Override scaling factor
 |      hspace / vspace / space # Distance between tiles
-|      cmark, cpen, clen, coffset      # Cropmark parameters
+|      cmark, cpen, clen, coffset, ccolor      # Cropmark parameters
 
 # Send pages to multiple pipes and merge their results
 mix { ..., ..., ...}
diff --git a/cmds.cc b/cmds.cc
index 87dc17bfca9e3578467e3db8534ab36469a27bca..2082ffec7517bc02f13146492428d79e81dee061 100644 (file)
--- a/cmds.cc
+++ b/cmds.cc
@@ -227,6 +227,37 @@ public:
   { "t" sx,    AT_DIMEN },             \
   { "b" sx,    AT_DIMEN }
 
+// Colors
+
+class color_spec {
+  double rgb[3];
+public:
+  color_spec(string s)
+    {
+      if (s.length() != 6)
+       die("Invalid color specification \"%s\": expecting 6 hex digits", s.c_str());
+      for (int i=0; i<3; i++)
+       {
+         int x = 0;
+         for (int j=0; j<2; j++)
+           {
+             char c = s[2*i+j];
+             if (c >= '0' && c <= '9')
+               x = (x << 4) | (c - '0');
+             else if (c >= 'a' && c <= 'f')
+               x = (x << 4) | (c - 'a' + 10);
+             else if (c >= 'A' && c <= 'F')
+               x = (x << 4) | (c - 'A' + 10);
+           }
+         rgb[i] = x / 255.;
+       }
+    }
+  string to_string()
+    {
+      return pdf_coord(rgb[0]) + " " + pdf_coord(rgb[1]) + " " + pdf_coord(rgb[2]);
+    }
+};
+
 // Cropmarks
 
 class cropmark_spec {
@@ -242,8 +273,9 @@ class cropmark_spec {
   double offset;
   string crop_cross(double x, double y, uint mask);
   QPDFObjectHandle egstate;
+  color_spec color;
 public:
-  cropmark_spec(cmd *c, const string prefix="", const string def_type="cross")
+  cropmark_spec(cmd *c, const string prefix="", const string def_type="cross") : color(c->arg(prefix + "color")->as_string("000000"))
     {
       string t = c->arg(prefix + "mark")->as_string(def_type);
       if (t == "none")
@@ -294,7 +326,7 @@ string cropmark_spec::pdf_stream(out_context *out, BBox &box, pdf_matrix &xform)
     return "";
 
   string s = "q ";
-  s += "0 0 0 RG ";
+  s += color.to_string() + " RG ";
   s += xform.to_string() + " cm ";
 
   if (egstate.isNull())
@@ -352,7 +384,8 @@ string cropmark_spec::pdf_stream(out_context *out, BBox &box, pdf_matrix &xform)
   { px "mark", AT_STRING },            \
   { px "pen",  AT_DIMEN },             \
   { px "len",  AT_DIMEN },             \
-  { px "offset",AT_DIMEN }
+  { px "offset",AT_DIMEN },            \
+  { px "color",        AT_STRING }
 
 // Scaling preserving aspect ratio