From 17ea4c24b987d526d95d6b72406341fab755b78d Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Tue, 25 Feb 2020 01:20:35 +0000 Subject: luacolor (25feb20) git-svn-id: svn://tug.org/texlive/trunk@53901 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/tex/latex/luacolor/luacolor.lua | 227 ++++++++++++++++++++++ Master/texmf-dist/tex/latex/luacolor/luacolor.sty | 98 +++------- 2 files changed, 255 insertions(+), 70 deletions(-) create mode 100644 Master/texmf-dist/tex/latex/luacolor/luacolor.lua (limited to 'Master/texmf-dist/tex') diff --git a/Master/texmf-dist/tex/latex/luacolor/luacolor.lua b/Master/texmf-dist/tex/latex/luacolor/luacolor.lua new file mode 100644 index 00000000000..d1075136a73 --- /dev/null +++ b/Master/texmf-dist/tex/latex/luacolor/luacolor.lua @@ -0,0 +1,227 @@ +-- +-- This is file `luacolor.lua', +-- generated with the docstrip utility. +-- +-- The original source files were: +-- +-- luacolor.dtx (with options: `lua') +-- +-- This is a generated file. +-- +-- Project: luacolor +-- Version: 2020-02-22 v1.14 +-- +-- Copyright (C) +-- 2007, 2009-2011 Heiko Oberdiek +-- 2016-2020 Oberdiek Package Support Group +-- +-- This work may be distributed and/or modified under the +-- conditions of the LaTeX Project Public License, either +-- version 1.3c of this license or (at your option) any later +-- version. This version of this license is in +-- https://www.latex-project.org/lppl/lppl-1-3c.txt +-- and the latest version of this license is in +-- https://www.latex-project.org/lppl.txt +-- and version 1.3 or later is part of all distributions of +-- LaTeX version 2005/12/01 or later. +-- +-- This work has the LPPL maintenance status "maintained". +-- +-- The Current Maintainers of this work are +-- Heiko Oberdiek and the Oberdiek Package Support Group +-- https://github.com/ho-tex/luacolor/issues +-- +-- +-- This work consists of the main source file luacolor.dtx +-- and the derived files +-- luacolor.sty, luacolor.pdf, luacolor.ins, luacolor.drv, +-- luacolor.lua, +-- +oberdiek = oberdiek or {} +local luacolor = oberdiek.luacolor or {} +oberdiek.luacolor = luacolor +function luacolor.getversion() + tex.write("2020-02-22 v1.14") +end +local ifpdf = tonumber(tex.outputmode or tex.pdfoutput) > 0 +local prefix +local prefixes = { + dvips = "color ", + dvipdfm = "pdf:sc ", + truetex = "textcolor:", + pctexps = "ps::", +} +local patterns = { + ["^color "] = "dvips", + ["^pdf: *begincolor "] = "dvipdfm", + ["^pdf: *bcolor "] = "dvipdfm", + ["^pdf: *bc "] = "dvipdfm", + ["^pdf: *setcolor "] = "dvipdfm", + ["^pdf: *scolor "] = "dvipdfm", + ["^pdf: *sc "] = "dvipdfm", + ["^textcolor:"] = "truetex", + ["^ps::"] = "pctexps", +} +local function info(msg, term) + local target = "log" + if term then + target = "term and log" + end + texio.write_nl(target, "Package luacolor info: " .. msg .. ".") + texio.write_nl(target, "") +end +function luacolor.dvidetect() + local v = tex.box[0] + assert(v.id == node.id("hlist")) + for v in node.traverse_id(node.id("whatsit"), v.head) do + if v and v.subtype == node.subtype("special") then + local data = v.data + for pattern, driver in pairs(patterns) do + if string.find(data, pattern) then + prefix = prefixes[driver] + tex.write(driver) + return + end + end + info("\\special{" .. data .. "}", true) + return + end + end + info("Missing \\special", true) +end +local map = { + n = 0, +} +function luacolor.get(color) + tex.write("" .. luacolor.getvalue(color)) +end +function luacolor.getvalue(color) + local n = map[color] + if not n then + n = map.n + 1 + map.n = n + map[n] = color + map[color] = n + end + return n +end +local attribute +function luacolor.setattribute(attr) + attribute = attr +end +function luacolor.getattribute() + return attribute +end +local LIST = 1 +local LIST_LEADERS = 2 +local LIST_DISC = 3 +local COLOR = 4 +local RULE = node.id("rule") +local node_types = { + [node.id("hlist")] = LIST, + [node.id("vlist")] = LIST, + [node.id("rule")] = COLOR, + [node.id("glyph")] = COLOR, + [node.id("disc")] = LIST_DISC, + [node.id("whatsit")] = { + [node.subtype("special")] = COLOR, + [node.subtype("pdf_literal")] = COLOR, + [node.subtype("pdf_save")] = COLOR, + [node.subtype("pdf_restore")] = COLOR, -- probably not needed +-- TODO (DPC) [node.subtype("pdf_refximage")] = COLOR, + }, + [node.id("glue")] = + function(n) + if n.subtype >= 100 then -- leaders + if n.leader.id == RULE then + return COLOR + else + return LIST_LEADERS + end + end + end, +} +local function get_type(n) + local ret = node_types[n.id] + if type(ret) == 'table' then + ret = ret[n.subtype] + end + if type(ret) == 'function' then + ret = ret(n) + end + return ret +end +local mode = 2 -- luatex.pdfliteral.direct +local WHATSIT = node.id("whatsit") +local SPECIAL = node.subtype("special") +local PDFLITERAL = node.subtype("pdf_literal") +local DRY_FALSE = false +local DRY_TRUE = true +local function traverse(list, color, dry) + if not list then + return color + end + local head + if get_type(list) == LIST then + head = list.head + elseif get_type(list) == LIST_DISC then + head = list.replace + else + texio.write_nl("!!! Error: Wrong list type: " .. node.type(list.id)) + return color + end + for n in node.traverse(head) do + local t = get_type(n) + if t == LIST or t == LIST_DISC then + color = traverse(n, color, dry) + elseif t == LIST_LEADERS then + local color_after = traverse(n.leader, color, DRY_TRUE) + if color == color_after then + traverse(n.leader, color, DRY_FALSE or dry) + else + traverse(n.leader, '', DRY_FALSE or dry) + color = '' + end + elseif t == COLOR then + local v = node.has_attribute(n, attribute) + if v then + local newColor = map[v] + if newColor ~= color then + color = newColor + if dry == DRY_FALSE then + local newNode + if ifpdf then + newNode = node.new(WHATSIT, PDFLITERAL) + newNode.mode = mode + newNode.data = color + else + newNode = node.new(WHATSIT, SPECIAL) + newNode.data = prefix .. color + end + head = node.insert_before(head, n, newNode) + end + end + end + end + end + if get_type(list) == LIST then + list.head = head + else + list.replace = head + end + return color +end +function luacolor.process(box) + local color = "" + local list = tex.getbox(box) + traverse(list, color, DRY_FALSE) +end +if luaotfload.set_colorhandler then + local set_attribute = node.direct.set_attribute + luaotfload.set_colorhandler(function(head, n, color) + set_attribute(n, attribute, luacolor.getvalue(color)) + return head, n + end) +end +-- +-- End of File `luacolor.lua'. diff --git a/Master/texmf-dist/tex/latex/luacolor/luacolor.sty b/Master/texmf-dist/tex/latex/luacolor/luacolor.sty index 08c38b5f543..bad536ceae4 100644 --- a/Master/texmf-dist/tex/latex/luacolor/luacolor.sty +++ b/Master/texmf-dist/tex/latex/luacolor/luacolor.sty @@ -9,11 +9,11 @@ %% This is a generated file. %% %% Project: luacolor -%% Version: 2019/11/29 v1.13 +%% Version: 2020-02-22 v1.14 %% %% Copyright (C) %% 2007, 2009-2011 Heiko Oberdiek -%% 2016-2019 Oberdiek Package Support Group +%% 2016-2020 Oberdiek Package Support Group %% %% This work may be distributed and/or modified under the %% conditions of the LaTeX Project Public License, either @@ -35,7 +35,6 @@ %% This work consists of the main source file luacolor.dtx %% and the derived files %% luacolor.sty, luacolor.pdf, luacolor.ins, luacolor.drv, -%% luacolor-test1.tex, luacolor-test2.tex, luacolor-test3.tex, %% luacolor.lua, %% \begingroup\catcode61\catcode48\catcode32=10\relax% @@ -90,25 +89,17 @@ \edef\LuaCol@AtEnd{\LuaCol@AtEnd\noexpand\endinput} \NeedsTeXFormat{LaTeX2e} \ProvidesPackage{luacolor}% - [2019/11/29 v1.13 Color support via LuaTeX's attributes (HO)] -\RequirePackage{infwarerr}[2010/04/08]% -\RequirePackage{iftex}[2019/11/07]% -\RequirePackage{ltxcmds}[2011/04/18]% + [2020-02-22 v1.14 Color support via LuaTeX's attributes (HO)] \RequirePackage{color} -\ifluatex - \ifx\newattribute\@undefined - \RequirePackage{ltluatex}% - \fi -\else - \@PackageError{luacolor}{% +\ifx\directlua\@undefined + \PackageError{luacolor}{% This package may only be run using LuaTeX% }\@ehc \expandafter\LuaCol@AtEnd \fi% - \let\LuaCol@directlua\directlua \ifcolors@ \else - \@PackageWarningNoLine{luacolor}{% + \PackageWarningNoLine{luacolor}{% Colors are disabled by option `monochrome'% }% \def\set@color{}% @@ -117,13 +108,13 @@ \def\define@color#1#2{}% \expandafter\LuaCol@AtEnd \fi% -\LuaCol@directlua{% +\directlua{% require("luacolor")% } \begingroup - \edef\x{\LuaCol@directlua{tex.write("2019/11/29 v1.13")}}% + \edef\x{\directlua{tex.write("2020-02-22 v1.14")}}% \edef\y{% - \LuaCol@directlua{% + \directlua{% if oberdiek.luacolor.getversion then % oberdiek.luacolor.getversion()% end% @@ -131,14 +122,14 @@ }% \ifx\x\y \else - \@PackageError{luacolor}{% + \PackageError{luacolor}{% Wrong version of lua module.\MessageBreak Package version: \x\MessageBreak Lua module: \y }\@ehc \fi \endgroup -\ifpdf +\ifnum\outputmode=\@ne \else \begingroup \def\current@color{}% @@ -149,47 +140,39 @@ \endgroup }% \edef\reserved@a{% - \LuaCol@directlua{% + \directlua{% oberdiek.luacolor.dvidetect()% }% }% \ifx\reserved@a\@empty - \@PackageError{luacolor}{% + \PackageError{luacolor}{% DVI driver detection failed because of\MessageBreak unrecognized color \string\special }\@ehc \endgroup \expandafter\expandafter\expandafter\LuaCol@AtEnd \else - \@PackageInfoNoLine{luacolor}{% + \PackageInfo{luacolor}{% Type of color \string\special: \reserved@a - }% + \@gobble}% \fi% \endgroup \fi -\ltx@IfUndefined{newluatexattribute}{% - \newattribute\LuaCol@Attribute -}{% - \newluatexattribute\LuaCol@Attribute -} -\ltx@IfUndefined{setluatexattribute}{% - \let\LuaCol@setattribute\setattribute -}{% - \let\LuaCol@setattribute\setluatexattribute -} -\LuaCol@directlua{% +\newattribute\LuaCol@Attribute +\let\LuaCol@setattribute\setattribute +\directlua{% oberdiek.luacolor.setattribute(\number\allocationnumber)% } \protected\def\set@color{% \LuaCol@setattribute\LuaCol@Attribute{% - \LuaCol@directlua{% + \directlua{% oberdiek.luacolor.get("\luaescapestring{\current@color}")% }% }% } \def\reset@color{} \def\luacolorProcessBox#1{% - \LuaCol@directlua{% + \directlua{% oberdiek.luacolor.process(\number#1)% }% } @@ -198,41 +181,16 @@ \luacolorProcessBox\AtBeginShipoutBox } \set@color -\ifpdf - \ifx\pdfxform\@undefined - \let\pdfxform\saveboxresource - \fi - \ltx@IfUndefined{pdfxform}{% - \directlua{% - tex.enableprimitives('',{% - 'pdfxform','pdflastxform','pdfrefxform'% - })% +\ifnum\outputmode=\@ne + \let\LuaCol@org@pdfxform\saveboxresource + \protected\def\saveboxresource{% + \directlua{ + local c = token.scan_int() + oberdiek.luacolor.process(c) + token.put_next(token.create'LuaCol@org@pdfxform', token.new(c, token.command_id'char_given')) }% - }{}% - \ltx@IfUndefined{protected}{% - \directlua{tex.enableprimitives('',{'protected'})}% - }{}% - \ltx@IfUndefined{pdfxform}{% - \@PackageWarning{luacolor}{\string\pdfxform\space not found}% - }{% - \let\LuaCol@org@pdfxform\pdfxform - \begingroup\expandafter\expandafter\expandafter\endgroup - \expandafter\ifx\csname protected\endcsname\relax - \@PackageWarning{luacolor}{\string\protected\space not found}% - \else - \expandafter\protected - \fi - \def\pdfxform{% - \begingroup - \afterassignment\LuaCol@pdfxform - \count@=% }% - \def\LuaCol@pdfxform{% - \luacolorProcessBox\count@ - \LuaCol@org@pdfxform\count@ - \endgroup - }% - }% + \let\pdfxform\saveboxresource \fi \LuaCol@AtEnd% \endinput -- cgit v1.2.3