summaryrefslogtreecommitdiff
path: root/graphics/pstricks/contrib/luapstricks/luapstricks.lua
diff options
context:
space:
mode:
Diffstat (limited to 'graphics/pstricks/contrib/luapstricks/luapstricks.lua')
-rw-r--r--graphics/pstricks/contrib/luapstricks/luapstricks.lua67
1 files changed, 62 insertions, 5 deletions
diff --git a/graphics/pstricks/contrib/luapstricks/luapstricks.lua b/graphics/pstricks/contrib/luapstricks/luapstricks.lua
index ee88e48993..9797073d2d 100644
--- a/graphics/pstricks/contrib/luapstricks/luapstricks.lua
+++ b/graphics/pstricks/contrib/luapstricks/luapstricks.lua
@@ -1,5 +1,5 @@
---- luapstricks.lua
--- Copyright 2021--2022 Marcel Krüger <tex@2krueger.de>
+-- Copyright 2021--2023 Marcel Krüger <tex@2krueger.de>
--
-- This work may be distributed and/or modified under the
-- conditions of the LaTeX Project Public License, either version 1.3
@@ -13,13 +13,13 @@
--
-- The Current Maintainer of this work is M. Krüger
--
--- This work consists of the file luapstricks.lua.
+-- This work consists of the files luapstricks.lua and luapstricks-plugin-pstmarble.lua
if luatexbase then
luatexbase.provides_module {
name = 'luapstricks',
- version = 'v0.8',
- date = '2023-02-17',
+ version = 'v0.9',
+ date = '2023-04-14',
description = 'PSTricks backend for LuaLaTeX',
}
end
@@ -917,6 +917,17 @@ local function num_to_base(num, base, ...)
return num_to_base(remaining, base, digit, ...)
end
+local plugin_interface = {
+ push = push,
+ pop = pop,
+ pop_num = pop_num,
+ pop_dict = pop_dict,
+ pop_array = pop_array,
+ pop_key = pop_key,
+ pop_proc = pop_proc,
+ exec = nil, -- execute_tok, -- filled in later
+}
+
local systemdict
local function generic_show(str, ax, ay)
local state = graphics_stack[#graphics_stack]
@@ -3846,7 +3857,52 @@ systemdict = {kind = 'dict', value = {
{kind = 'name', value = 'yacute'},
{kind = 'name', value = 'thorn'},
{kind = 'name', value = 'ydieresis'},
- }}
+ }},
+
+ -- In internal interface to allow package specific commands to be defined in separate file.
+ -- This does not provide a stable interface for external extensions
+ ['.loadplugin'] = function()
+ local name = pop_key()
+ local found = kpse.find_file(string.format('luapstricks-plugin-%s', name), 'lua')
+ if not found then
+ return push(false)
+ end
+ local loader = assert(loadfile(found))
+ local plugin, version = loader('luapstricks', 0, plugin_interface)
+ push{kind = 'dict', value = plugin}
+ push(version)
+ push(true)
+ end,
+
+ ['.build-image'] = function()
+ local y = pop_num()
+ local x = pop_num()
+ local image = pop_array().value
+ for i = 1, x*y do
+ local rgb = image[i].value
+ image[i] = string.pack('BBB', (rgb[1] * 255 + .5) // 1, (rgb[2] * 255 + .5) // 1, (rgb[3] * 255 + .5) // 1)
+ end
+ local i = img.scan {
+ stream = table.concat(image),
+ attr = string.format("/Type /XObject /Subtype /Image /Width %i /Height %i /BitsPerComponent 8 /ColorSpace /DeviceRGB", x, y),
+ notype = true,
+ nobbox = true,
+ bbox = {0, 0, 65781.76, 65781.76}
+ }
+ push(function()
+ flush_delayed()
+ local state = graphics_stack[#graphics_stack]
+ register_point(state, 0, 0)
+ register_point(state, 1, 1)
+ vf.push()
+ local n = node.new'hlist'
+ n.dir = 'TLT'
+ n.head = img.node(i)
+ vf.node(node.direct.todirect(n))
+ node.free(n)
+ vf.pop()
+ end)
+ end,
}}
systemdict.value.systemdict = systemdict
dictionary_stack = {systemdict, globaldict, userdict, userdict.value.TeXDict}
@@ -4040,6 +4096,7 @@ function execute_tok(tok, suppress_proc)
return push(tok)
end
end
+plugin_interface.exec = execute_tok
function execute_ps(tokens)
for i=1, #tokens do