texlive[72975] Build/source/texk/web2c/hitexdir: HiTeX: adding cmyk
commits+mruckert at tug.org
commits+mruckert at tug.org
Tue Nov 26 15:30:29 CET 2024
Revision: 72975
https://tug.org/svn/texlive?view=revision&revision=72975
Author: mruckert
Date: 2024-11-26 15:30:29 +0100 (Tue, 26 Nov 2024)
Log Message:
-----------
HiTeX: adding cmyk color specifications
Modified Paths:
--------------
trunk/Build/source/texk/web2c/hitexdir/doc/hitexman.hnt
trunk/Build/source/texk/web2c/hitexdir/doc/hitexman.pdf
trunk/Build/source/texk/web2c/hitexdir/doc/hitexman.tex
trunk/Build/source/texk/web2c/hitexdir/hitex.w
Modified: trunk/Build/source/texk/web2c/hitexdir/doc/hitexman.hnt
===================================================================
(Binary files differ)
Modified: trunk/Build/source/texk/web2c/hitexdir/doc/hitexman.pdf
===================================================================
(Binary files differ)
Modified: trunk/Build/source/texk/web2c/hitexdir/doc/hitexman.tex
===================================================================
--- trunk/Build/source/texk/web2c/hitexdir/doc/hitexman.tex 2024-11-26 00:41:57 UTC (rev 72974)
+++ trunk/Build/source/texk/web2c/hitexdir/doc/hitexman.tex 2024-11-26 14:30:29 UTC (rev 72975)
@@ -115,7 +115,7 @@
\medskip
{\tt ruckert\:@cs.hm.edu}
\medskip
-Last commit: Sat Sep 14 14:38:07 2024
+Last commit: Tue Nov 26 15:28:24 2024
\par
}
\eject
@@ -345,7 +345,7 @@
hexadecimal notation. In \TeX, hexadecimal values are written with
a \.{"}~prefix. The same colors as before are then written
\.{FG\{"FF 0 0\}}, \.{FG\{"FF 0 0 "FF\}},
-\.{FG\{0 0 "FF\}} and \.{FG\{"FF "FF "7F\}}.
+\.{FG\{0 0 "FF\}} and \.{FG\{"FF "FF 0 "7F\}}.
Values greater than 255 or less than 0 are not allowed.
A common alternative to the color representation just described
@@ -366,8 +366,33 @@
Values greater than 1 and less than 0 are not allowed.
Note that \.{fg\{1 1 1\}} is pure white while \.{FG\{1 1 1\}} is
the darkest possible gray, which on most devices is indistinguishable
-from pure black.
+from pure black.
+While specifying colors using red, green, and blue components is natural for
+computer screens, for printing on paper, the specification using cyan, magenta, yellow,
+and black is the default. Since collections of named colors using the latter format
+are common, Hi\TeX\ allows the use of this format by prefixing the numbers with
+the keyword \.{cmyk}. Specifying the keyword \.{rgb} is also possible and has the
+same effect as giving no keyword. Using the new syntax the transparent yellow
+can be written \.{fg\{cmyk 0 0 1 0 0.5\}}, \.{FG\{cmyk 0 0 "FF 0 "7F\}},
+ \.{fg\{rgb 1 1 0 0.5\}}, or \.{FG\{rgb "FF "FF 0 "7F\}}.
+
+The additional syntax rules are:
+
+\medskip
+\rule\sym{foreground}\index{foreground+\sym{foreground}}:
+\.{fg} \.{\{ rgb} \sym{number} \sym{number} \sym{number} \opt{\sym{number}} \.{\}}.
+\rule\sym{foreground}\index{foreground+\sym{foreground}}:
+\.{fg} \.{\{ cmyk} \sym{number} \sym{number} \sym{number} \sym{number} \opt{\sym{number}} \.{\}}.
+\rule\sym{foreground}\index{foreground+\sym{foreground}}:
+ \.{FG} \.{\{ rgb} \sym{integer} \sym{integer} \sym{integer} \opt{\sym{integer}} \.{\}}.
+\rule\sym{foreground}\index{foreground+\sym{foreground}}:
+ \.{FG} \.{\{ cmyk} \sym{integer} \sym{integer} \sym{integer} \sym{integer} \opt{\sym{integer}} \.{\}}.
+\medskip
+
+
+
+
\subsubsection{Defining and Using Colors}
As we will see, colors come in whole sets of colors.
To define such a set of colors, Hi\TeX\ provides
@@ -407,10 +432,14 @@
\sym{color} \opt{\sym{color} \opt{\sym{color}}}.
\rule\sym{color}\index{color+\sym{color}}:
\sym{foreground} \opt{\sym{background}}.
-\rule\sym{background}:
-\.{BG} \.{\{} \sym{integer} \sym{integer} \sym{integer} \opt{\sym{integer}} \.{\}}.
-\rule\sym{background}:
-\.{bg} \.{\{} \sym{number} \sym{number} \sym{number} \opt{\sym{number}} \.{\}}.
+\rule\sym{background}\index{foreground+\sym{foreground}}:
+ \.{FG} \.{\{} \opt{\.{rgb}} \sym{integer} \sym{integer} \sym{integer} \opt{\sym{integer}} \.{\}}.
+\rule\sym{background}\index{foreground+\sym{foreground}}:
+ \.{fg} \.{\{} \opt{\.{rgb}} \sym{number} \sym{number} \sym{number} \opt{\sym{number}} \.{\}}.
+\rule\sym{background}\index{foreground+\sym{foreground}}:
+ \.{FG} \.{\{ cmyk} \sym{integer} \sym{integer} \sym{integer} \sym{integer} \opt{\sym{integer}} \.{\}}.
+\rule\sym{background}\index{foreground+\sym{foreground}}:
+ \.{fg} \.{\{ cmyk} \sym{number} \sym{number} \sym{number} \sym{number} \opt{\sym{number}} \.{\}}.
\medskip
If some of the optional parts in the \sym{color specification} are missing,
the corresponding colors from the set of default colors, as described below,
Modified: trunk/Build/source/texk/web2c/hitexdir/hitex.w
===================================================================
--- trunk/Build/source/texk/web2c/hitexdir/hitex.w 2024-11-26 00:41:57 UTC (rev 72974)
+++ trunk/Build/source/texk/web2c/hitexdir/hitex.w 2024-11-26 14:30:29 UTC (rev 72975)
@@ -30994,13 +30994,15 @@
@ A color specification starting with ``FG'' or ``BG'' expects
integers in the range 0 to |0xFF|;
a color specification starting with ``fg'' or ``bg'' expects
-real numbers in the range 0 to 1 which are then scalled to the
-same range as before.
-The four color components are enclosed in braces. The last
-component is optional and its default value is |0xFF|.
+real numbers in the range 0 to 1.
+ The last component for the alpha value is optional and its default value is |0xFF| respectively 1.0.
+The color components are enclosed in braces.
+After the initial brace the keyword \.{rgb} specifies color values encoded with red/green/blue/alpha values;
+the keyword \.{cmyk} specifies color values encoded with cyan/magenta/yellow/black/alpha values.
+Giving no keyword is equivalent to giving the keyword \.{rgb}.
@<Declare procedures needed in |do_extension|@>=
-static uint8_t scan_color_component(bool expect_reals)
+static uint8_t scan_rgb_component(bool expect_reals)
{ if (expect_reals)
{ scan_scaled(); cur_val=(cur_val*0xFF+0x1000)>>16; }
else
@@ -31010,18 +31012,51 @@
else return cur_val;
}
-static uint32_t scan_color(bool expect_reals)
+static uint32_t scan_rgb_color(bool expect_reals)
{ uint8_t r,g,b,a;
- scan_left_brace();
- r=scan_color_component(expect_reals);
- g=scan_color_component(expect_reals);
- b=scan_color_component(expect_reals);
+ r=scan_rgb_component(expect_reals);
+ g=scan_rgb_component(expect_reals);
+ b=scan_rgb_component(expect_reals);
+ a=0xFF;
@<Get the next non-blank non-relax...@>;
- if (cur_cmd==right_brace)
- a=0xFF;
+ if (cur_cmd!=right_brace)
+ { back_input();
+ a=scan_rgb_component(expect_reals);
+ @<Get the next non-blank non-call token@>;
+ if (cur_cmd!=right_brace)
+ { back_input();
+ print_err("Missing right brace after color definition");
+ }
+ }
+ return (r<<24)|(g<<16)|(b<<8)|a;
+}
+
+static double scan_cmyk_component(bool expect_reals)
+{ double c;
+ if (expect_reals)
+ { scan_scaled(); c=cur_val/(double)ONE;
+ }
else
+ { scan_int(); c=cur_val/255.0;
+ }
+ if (c>1.0) return 1.0;
+ else if (c<0.0) return 0.0;
+ else return c;
+}
+
+
+static uint32_t scan_cmyk_color(bool expect_reals)
+{ uint8_t r,g,b,a;
+ double c,m,y,k;
+ c=scan_cmyk_component(expect_reals);
+ m=scan_cmyk_component(expect_reals);
+ y=scan_cmyk_component(expect_reals);
+ k=scan_cmyk_component(expect_reals);
+ a=0xFF;
+ @<Get the next non-blank non-relax...@>;
+ if (cur_cmd!=right_brace)
{ back_input();
- a=scan_color_component(expect_reals);
+ a=scan_cmyk_component(expect_reals)*0xFF+0.5;
@<Get the next non-blank non-call token@>;
if (cur_cmd!=right_brace)
{ back_input();
@@ -31028,9 +31063,23 @@
print_err("Missing right brace after color definition");
}
}
+ r=(1-c)*(1-k)*255+0.5;
+ g=(1-m)*(1-k)*255+0.5;
+ b=(1-y)*(1-k)*255+0.5;
return (r<<24)|(g<<16)|(b<<8)|a;
}
+static uint32_t scan_color(bool expect_reals)
+{ uint8_t r,g,b,a;
+ scan_left_brace();
+ if (scan_keyword("cmyk"))
+ return scan_cmyk_color(expect_reals);
+ else if (scan_keyword("rgb"))
+ return scan_rgb_color(expect_reals);
+ else
+ return scan_rgb_color(expect_reals);
+}
+
@ Colors are specified in pairs of a foreground color, prefixed
by ``FG'' or ``fg'', followed by an optional background color
prefixed by ``BG'' or ``bg''.
More information about the tex-live-commits
mailing list.