summaryrefslogtreecommitdiff
path: root/macros/luatex/optex/colors.opm
diff options
context:
space:
mode:
Diffstat (limited to 'macros/luatex/optex/colors.opm')
-rw-r--r--macros/luatex/optex/colors.opm155
1 files changed, 86 insertions, 69 deletions
diff --git a/macros/luatex/optex/colors.opm b/macros/luatex/optex/colors.opm
index 90d3d6d7a3..2745e0fc51 100644
--- a/macros/luatex/optex/colors.opm
+++ b/macros/luatex/optex/colors.opm
@@ -3,8 +3,8 @@
\_codedecl \colordef {Colors <2020-03-18>} % loaded in format
\_doc -----------------------------
- We declare internal boolean value `\_iflocalcolor` ad do
- `\localcolor` as default.
+ We declare internal boolean value \`\_iflocalcolor` ad do
+ \`\localcolor` as default.
\_cod -----------------------------
\_newifi \_iflocalcolor \_localcolortrue
@@ -13,7 +13,10 @@
\_public \localcolor \nolocalcolor ;
\_doc -----------------------------
- The basic colors in CMYK are here.
+ The basic colors in CMYK
+ \`\Blue` \`\Red` \`\Brown` \`\Green` \`\Yellow` \`\Cyan` \`\Magenta`
+ \`\Grey` \`\LightGrey` \`\White` and \`\Black`
+ are declared here.
\_cod -----------------------------
\_def\Blue {\_setcmykcolor{1 1 0 0}}
@@ -29,9 +32,16 @@
\_def\Black {\_setgreycolor{0}}
\_doc -----------------------------
- By default, `\set/cmyk/rgb/grey/color` macros expands to `\_setcolor{<pdf-primitive>}`
+ By default, the \`\setcmykcolor` \`\setrgbcolor` and \`\setgreycolor`
+ macros with `{<componetns>}` parameter
+ expand to `\_setcolor{<pdf-primitive>}` using \`\_formatcmyk`
+ or \`\_formatrgb` or \`\_formatgrey` expandable macros.
+ For example `\setrgbcolor{1 0 0}` expands to `\_setcolor{1 0 0 rg 1 0 0 RG}`.\nl
We set both types of colors (for lines (`K` or `RG` or `G`) and for fills
(`r` or `rg` or `g`) together in the <pdf-primitive> command.
+ This is the reason why the \`\_fillstroke` uses both its parameters.
+ If only fills are needed you can do `\def\_fillstroke#1#2{#1}`.
+ If only strokes are needed you can do `\def\_fillstroke#1#2{#2}`.
\_cod -----------------------------
\_def\_setcmykcolor#1{\_setcolor{\_formatcmyk{#1}}}
@@ -40,22 +50,19 @@
\_def\_formatcmyk#1{\_fillstroke{#1 k}{#1 K}}
\_def\_formatrgb#1{\_fillstroke{#1 rg}{#1 RG}}
\_def\_formatgrey#1{\_fillstroke{#1 g}{#1 G}}
+\_def\_fillstroke#1#2{#1 #2}
\_public \setcmykcolor \setrgbcolor \setgreycolor ;
\_doc -----------------------------
- The `\onlyrgb` declaration redefines `\_formatcmyk` in ordet it expands
+ The \`\onlyrgb` declaration redefines \^`\_formatcmyk` in order it expands
to its conversion to RGB <pdf-primitive>. This conversion is done by
- the `\_cmyktorgb` macro. Moreover, `\onlyrgb` re-defines three basic RGB
- colors for RGB color space and re-declares `\_colordef` as `\_rgbcolordef`.
- The `\onlycmyk` macro does a similar work, it re-defines `\_formatrgb`
- macro. The Grey color space is unnchanged and works in both main
+ the \^`\_cmyktorgb` macro. Moreover, `\onlyrgb` re-defines three basic RGB
+ colors for RGB color space and re-declares \^`\colordef` as \^`\rgbcolordef`.
+ The \hbox{\`\onlycmyk`} macro does a similar work, it re-defines \^`\_formatrgb`
+ macro. The Grey color space is unchanged and works in both main
settings (RGB or CMYK) without collisions.
- The `\_fillstroke` uses the same color for fills and strokes.
- If only fills are needed to declare do `\def\_fillstroke#1#2{#1}`.
- If only strokes are needed to declare do `\def\_fillstroke#1#2{#2}`.
\_cod -----------------------------
-\_def\_fillstroke#1#2{#1 #2}
\_def\_onlyrgb{\_def\Red{\_setrgbcolor{1 0 0}}%
\_def\Green{\_setrgbcolor{0 1 0}}\_def\Blue{\_setrgbcolor{0 0 1}}%
\_let\_colordef=\_rgbcolordef
@@ -66,10 +73,10 @@
\_public \onlyrgb \onlycmyk ;
\_doc -----------------------------
- The `\_setcolor` macro redefines empty `\_ensureblack` macro (used in
- output routine for headres and footers) to `\_encureblackA` which keeps
- Black at start ot its parameter and retunrs to the current color at the
- end of its parameter. Then the current color
+ The \`\_setcolor` macro redefines empty `\_ensureblack` macro (used in
+ output routine for headres and footers) to `\_ensureblackA` which sets
+ Black at the start of its parameter and retunrs to the current color at the
+ end of its parameter. The current color
is saved into `\_currentcolor` macro and colorstack is pushed.
Finally, the `\_colorstackpop` is initialized by `\aftergroup` if
`\localcolor` is declared.
@@ -89,8 +96,8 @@
\_colorstackpush\_pdfblackcolor #1\_colorstackpop}
\_doc -----------------------------
- The colorstack is initialized here and basic macros
- `\_colorstackpush`, `\_colorstackpop` and `\_colorstackset`
+ The colorstack is initialized here and the basic macros
+ \`\_colorstackpush`, \`\_colorstackpop` and \`\_colorstackset`
are defined here.
\_cod -----------------------------
@@ -102,23 +109,25 @@
\_doc -----------------------------
We need to open a special color stack for footnotes, because footnotes
can follow on next pages and their colors are independent on colors
- used in man page-body.
+ used in the main page-body. The \`\_openfnotestack` is defined as
+ \`\_openfnotestackA` when the \^`\_setcolor` is used first.
+ The \`\_fnotestack` is initializedin in `\everyjob` because the
+ initialization is not saved to the format.
\_cod -----------------------------
-%\_mathchardef\_fnotestack=\_pdfcolorstackinit page {0 g 0 G}
-% must be in \everyjob^^^
+%\_mathchardef\_fnotestack=\_pdfcolorstackinit page {0 g 0 G} % must be in \everyjob
\_def \_openfnotestackA {\_pdfcolorstack\_fnotestack current}
\_doc -----------------------------
We use lua codes for RGB to CMYK or CMYK to RGB conversions and for
- addition color components in the `\colordef` macro.
- `\_rgbtocmyk <R> <G> <B> ;` expands to <C> <M> <Y> <K>.
- `\_cmyktorgb <C> <M> <Y> <K> ;` expands to <R> <G> <B>.
- The `\_colorcrop`, `\_colordefFin` and `\_douseK` are auxiliary macros
- used in `\colordef`. The `\colorcrop` rescales color components in order
+ addition color components in the \^`\colordef` macro.
+ The \`\_rgbtocmyk` `<R> <G> <B> ;` expands to `<C> <M> <Y> <K>` and
+ the \`\_cmyktorgb` `<C> <M> <Y> <K> ;` expands to `<R> <G> <B>`.
+ The \`\_colorcrop`, \`\_colordefFin` and \`\_douseK` are auxiliary macros
+ used in the \^`\colordef`. The `\_colorcrop` rescales color components in order
to they are in $[0,1]$ interval. The `\colordefFin` expands to the values
accumulated in Lua code `color_C`, `color_M`, `color_Y` and `color_K`.
- The `\_douseK` applies `\useK` to CMYK components.
+ The `\_douseK` applies \^`\useK` to CMYK components.
\_cod -----------------------------
\_def\_rgbtocmyk #1 #2 #3 ;{%
@@ -160,7 +169,7 @@
\_doc -----------------------------
We have a problem with the `%.3f` directive in Lua code. It prints trailed
zeros: (0.300 instead desired 0.3) but we want to save PDF file space. The macro
- `\_stripzeros` removes these trailing zeros at expand processor
+ \`\_stripzeros` removes these trailing zeros at expand processor
level. So `\_stripzeros 0.300 0.400 0.560 ;` expands to `.3 .4 .56`.
\_cod -----------------------------
@@ -171,22 +180,22 @@
\_def\_stripzeroC #1 #2:{#1}
\_doc -----------------------------
- The `\rgbcolordef` and `\cmykcolordef` use common macro
- `\_commoncolordef` with different first four parameters.
+ The \`\rgbcolordef` and \`\cmykcolordef` use common macro
+ \`\_commoncolordef` with different first four parameters.
The `\_commoncolordef <selector><K><R><G><what-define>{<data>}` does the
real work. It initializes the Lua variables for summation.
It expands <data> in the group where color selectors have
- special meaning, then it adjusts the resulting string by `\replstring`
+ special meaning, then it adjusts the resulting string by \^`\replstring`
and runs it. Example shows how the <data> are processed:
\begtt
- input <data>: ".3\Blue +.6^\KhakiC \useK -\Black"
+ input <data>: ".3\Blue + .6^\KhakiC \useK -\Black"
expanded to: ".3 !=K 1 1 0 0 +.6^!=R .804 .776 .45 \_useK -!=G 0"
adjusted to: "\_addcolor .3!=K 1 1 0 0 \_addcolor .6!^R .804 .776 .45
\_useK \_addcolor -1!=G 0"
and this is processed.
\endtt
- `\_addcolor <coef.>!<mod><type>` expands to `\_addcolor:<mod><type> <coef>`
- for example to `\_addcolor:=K <coef>` followed by one or three or four
+ \`\_addcolor` `<coef.>!<mod><type>` expands to `\_addcolor:<mod><type> <coef>`
+ for example it expands to `\_addcolor:=K <coef>` followed by one or three or four
numbers (depending on <type>). <mod> is `=` (use as is) or `^` (use
complementary color). <type> is `K` for CMYK, `R` for RGB and `G` for
GREY color space. Uppercase <type> informs that `\cmykcolordef` is
@@ -201,7 +210,8 @@
using `\_colordefFin`. If `\rgbcolordef` is processed, then we must to
remove the last <K> component which is in the format `.0` in such case.
The `\_stripK` macro does it.
- Finaly, the <what-define> is defined as `<selector>{<expanded _tmpb>}`.
+ Finally, the `<what-define>` is defined as `<selector>{<expanded _tmpb>}`,
+ for example `\_setcmykclor{1 0 .5 .3}`.
\_cod -----------------------------
\_def\_rgbcolordef {\_commoncolordef \_setrgbcolor krg}
@@ -214,6 +224,7 @@
\_def\_setgreycolor##1{!=#4 ##1 }%
\_let\_useK=\_relax
\_edef\_tmpb{+#6}%
+ \_replstring\_tmpb{+ }{+}\_replstring\_tmpb{- }{-}%
\_replstring\_tmpb{+}{\_addcolor}\_replstring\_tmpb{-}{\_addcolor-}%
\_replstring\_tmpb{^!=}{!^}\_replstring\_tmpb{-!}{-1!}%
\_ifx K#2\_let\_useK=\_douseK \_fi
@@ -252,7 +263,7 @@
\_let\_colordef=\_cmykcolordef % default \_colordef is \_cmykcolordef
\_doc -----------------------------
- Public versions of `\colordef` and `\useK` macros are declared using
+ Public versions of \`\colordef` and \`\useK` macros are declared using
`\_def`, because the internal versions `\_colordef` and `\_useK` are
changed during processing.
\_cod -----------------------------
@@ -262,14 +273,14 @@
\_public \cmykcolordef \rgbcolordef ;
\_doc -----------------------------
- The \LaTeX/ file `x11nam.def` is read by `\morecolors`. The numbers
- 0,1,2,3,4 are trasformed to letters O, <none>, B, C, D in the name of the
- color. Colors defined already are not re-defined. The empty \_showcolor`
+ The \LaTeX/ file `x11nam.def` is read by \`\morecolors`. The numbers
+ 0,1,2,3,4 are transformed to letters O, <none>, B, C, D in the name of the
+ color. Colors defined already are not re-defined. The empty \`\_showcolor`
macro should be re-defined for color catalog printing. For example:
\begtt
\def\vr{\vrule height10pt depth2pt width20pt}
- \def\_showcolor{\hbox{\tt \_bslash\_tmpb: \csname \_tmpb\endcsname \vr}\space\space}
- \typosize[11/14] \begmulti 4
+ \def\_showcolor{\hbox{\tt\_bslash\_tmpb: \csname\_tmpb\endcsname \vr}\space\space}
+ \begmulti 4 \typosize[11/14]
\morecolors
\endmulti
\endtt
@@ -298,45 +309,47 @@ and switches colors according to them. This
is totally independent on \TeX/ group mechanism. You can declare
`\nolocalcolor` at the beginning of the document, if you want this behavior.
In this case, if you set a color then you must to return back to black color
-using `\Black` manualy.
+using `\Black` manually.
By default, \OpTeX/ sets `\localcolor`. It means that the typesetting
returns back to a previous color at the end of current group, so you cannot
-write `\Black` explicitly. This is implemented using `\afterroup` feature.
-There is a limitiation of this feature: when a color selector is used in a
+write `\Black` explicitly. This is implemented using `\aftergroup` feature.
+There is a limitation of this feature: when a color selector is used in a
group of a box, which is saved by `\setbox`, then the activity or
-recontruction of previous color are processed at `\setbox` time, no in the
-box itself. You must to correct it by double group:
+reconstruction of previous color are processed at `\setbox` time, no in the
+box itself. You must correct it by double group:
\begtt
-\setbox=\hbox{\Red something} % bad: the \Black is done after \setbox
-\setbox=\hbox{{\Red something}} % good: the \Black is done after group inside the box
+\setbox0=\hbox{\Red text} % bad: \Black is done after \setbox
+\setbox0=\hbox{{\Red text}} % good: \Black is done after group inside the box
\endtt
The implementation of colors is based on colorstack, so the current color
-can follow acros more pages. It is not so obvious because PDF viewer (or PDF
+can follow across more pages. It is not so obvious because PDF viewer (or PDF
interpreter) manipulates with colors locally at each PDF page and it
initializes each PDF page with black on white color.
-Macros `\setcmykcolor{<C> <M> <Y> <K>}` or `\setrgbcolor{<R> <G> <B>}`
-or `\_setgreycolor{<Grey>}` should be used in color selectors or user can
+Macros \^`\setcmykcolor``{<C> <M> <Y> <K>}` or \^`\setrgbcolor``{<R> <G> <B>}`
+or\nl \^`\setgreycolor``{<Grey>}` should be used in color selectors or user can
specify these macros explicitly.
-The color mixing processed by `\colordef` is done in the substractive color
+The color mixing processed by the \^`\colordef` is done in the substractive color
model CMYK. If the result has a component greater than 1 then all
components are multiplied by a coefficient in order to maximal component is
equal to 1.
-You can move a common amount of CMY components (i.e. their minimum) to the
+You can move a shared amount of CMY components (i.e. their minimum) to the
$K$ component. This saves the color tonners and the result is more true.
-This should be done by `\useK` command at the end of a linear combination
+This should be done by \^`\useK` command at the end of a linear combination
used in `\colordef`. For example
-$$
- \colordef \myColor {.3\Green + .4\Blue \useK}
-$$
+\begtt
+\colordef \myColor {.3\Green + .4\Blue \useK}
+\endtt
The `\useK` command exactly does:
$$
- k' =\min(C,M,Y), \ C=(C-k')/(1-k'), \ M=(M-k')/(1-k'), \ Y=(Y-k')/(1-k'), \
+ \displaylines{
+ k' =\min(C,M,Y), \cr \ C=(C-k')/(1-k'), \ M=(M-k')/(1-k'), \ Y=(Y-k')/(1-k'), \cr
K = \min(1,K+k').
+}
$$
You can use minus instead plus in the linear combination in `\colordef`. The
@@ -352,25 +365,29 @@ occured during color mixing.
Finally, you can use `^` immediately preceeded before macro name of the
color. Then the complementary color is used here.
\begtt
-\colordef \mycolor {\Grey + .6^\Blue} % the same as \colordef\mycolor{\Grey+.6\Yellow}
+\colordef\mycolor{\Grey+.6^\Blue} % the same as \colordef\mycolor{\Grey+.6\Yellow}
\endtt
-The `\rgbcolordef` can be used to mix colors in additive color model RGB.
-If `\onlyrgb` is declared, then `\colordef` works as `\rgbcolordef`.
+The \^`\rgbcolordef` can be used to mix colors in additive color model RGB.
+If \^`\onlyrgb` is declared, then \^`\colordef` works as \^`\rgbcolordef`.
-If a CMYK to RGB or RGB to CMYK conversion is needed then no ICC profiles are
-supposed, but only the following simple formulae are used
+If a CMYK to RGB or RGB to CMYK conversion is needed then
+the following simple formulae are used
+(ICC profiles are not supported):
$$
\displaylines{
- \hbox{CMYK to RGB:}\quad
+ \hbox{CMYK to RGB:}\cr
R = (1-C)(1-K), \ G = (1-M)(1-K), \ B = (1-Y)(1-K). \cr
- \hbox{RGB to CMYK:}\quad
+ \hbox{RGB to CMYK:}\cr
K'=\max(R,G,B), \ C=(K'-R)/K', \ M=(K'-G)/K', \ Y=(K'-B)/K', \ K=1-K'.
}
$$
The RGB to CMYK conversion is invoked when a color is declared using `\setrgbcolor`
-and it is used in `\colordef` or if it is printed when `\onlycmyk` is declared.
-The CMYK to RGB conversion is invoked when a color is declared using `\setcmykcolor`
-and it is used in `\rgbcolordef` or if it is printed when `\onlyrgb` is declared.
+and it is used in \^`\colordef` or if it is printed when \^`\onlycmyk` is declared.
+The CMYK to RGB conversion is invoked when a color is declared using \^`\setcmykcolor`
+and it is used in \^`\rgbcolordef` or if it is printed when \^`\onlyrgb` is declared.
+\_endinput
+2020-04-22 \replstring\tmpb{+ }{+}, {- }{-} added in \colordef, bug fixed
+2020-03-18 introduced