From f5d316a7caefa52c482e47d98c2c7e7149d340c2 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Fri, 6 Apr 2018 22:41:31 +0200 Subject: [PATCH] Settable colors of cropmarks --- TODO | 4 ++-- cmds.cc | 39 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/TODO b/TODO index e38d0d8..558dc72 100644 --- 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= @@ -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 87dc17b..2082ffe 100644 --- 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 -- 2.39.2