[latex3-commits] [git/LaTeX3-latex3-luaotfload] dev: Add l3color luaotfload integration (6985740)
Marcel Fabian Krüger
tex at 2krueger.de
Mon Jun 6 18:55:45 CEST 2022
Repository : https://github.com/latex3/luaotfload
On branch : dev
Link : https://github.com/latex3/luaotfload/commit/69857401ef3e7a0817e9b10a9b435a6c2a9f5966
>---------------------------------------------------------------
commit 69857401ef3e7a0817e9b10a9b435a6c2a9f5966
Author: Marcel Fabian Krüger <tex at 2krueger.de>
Date: Mon Jun 6 18:55:45 2022 +0200
Add l3color luaotfload integration
>---------------------------------------------------------------
69857401ef3e7a0817e9b10a9b435a6c2a9f5966
src/luaotfload-l3color.lua | 59 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 59 insertions(+)
diff --git a/src/luaotfload-l3color.lua b/src/luaotfload-l3color.lua
new file mode 100644
index 0000000..bd27574
--- /dev/null
+++ b/src/luaotfload-l3color.lua
@@ -0,0 +1,59 @@
+if not luaotfload.set_colorsplitter then return end
+local l = lpeg
+local spaces = l.P' '^0
+local digit16 = l.R('09', 'af', 'AF')
+local function rep(patt, count)
+ local result = patt
+ for i=2, count do
+ result = result * patt
+ end
+ return result
+end
+local traditional = spaces * l.C(rep(digit16, 6)) * (rep(l.S'fF', 2) + l.C(rep(digit16, 2)))^-1 * spaces * -1
+local field = l.C((1 - l.S' ,')^1)
+local new_syntax = spaces * field * (spaces * ',' * spaces * field)^-1 * spaces * -1
+local split_patt = traditional + new_syntax
+
+luaotfload.set_colorsplitter(function (value)
+ local rgb, a = split_patt:match(value)
+ return split_patt:match(value)
+end)
+
+local octet = rep(digit16, 2) / function(s) return string.format('%.3g ', tonumber(s, 16) / 255) end
+local htmlcolor = l.Cs(rep(octet, 3) * -1 * l.Cc'rg')
+local color_export = {
+ token.create'endlocalcontrol',
+ token.create'tex_hpack:D',
+ token.new(0, 1),
+ token.create'color_export:nnN',
+ token.new(0, 1),
+ '',
+ token.new(0, 2),
+ token.new(0, 1),
+ 'backend',
+ token.new(0, 2),
+ token.create'l_tmpa_tl',
+ token.create'exp_after:wN',
+ token.create'__color_select:nn',
+ token.create'l_tmpa_tl',
+ token.new(0, 2),
+}
+local group_end = token.create'group_end:'
+local value = (1 - l.P'}')^0
+luaotfload.set_colorparser(function (value)
+ local html = htmlcolor:match(value)
+ if html then return html end
+
+ tex.runtoks(function()
+ token.get_next()
+ color_export[6] = value
+ tex.sprint(-1, color_export)
+ end)
+ local list = token.scan_list()
+ if not list.head or list.head.next or list.head.subtype ~= node.subtype'pdf_colorstack' then
+ error'Unexpected backend behavior'
+ end
+ local cmd = list.head.data
+ node.free(list)
+ return cmd
+end)
More information about the latex3-commits
mailing list.