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.lua103
1 files changed, 86 insertions, 17 deletions
diff --git a/graphics/pstricks/contrib/luapstricks/luapstricks.lua b/graphics/pstricks/contrib/luapstricks/luapstricks.lua
index eebca86801..8ae9eed76d 100644
--- a/graphics/pstricks/contrib/luapstricks/luapstricks.lua
+++ b/graphics/pstricks/contrib/luapstricks/luapstricks.lua
@@ -18,8 +18,8 @@
if luatexbase then
luatexbase.provides_module {
name = 'luapstricks',
- version = 'v0.1',
- date = '2021-09-16',
+ version = 'v0.2',
+ date = '2021-09-30',
description = 'PSTricks backend for LuaLaTeX',
}
end
@@ -823,15 +823,20 @@ end
local mark = {kind = 'mark'}
local null = {kind = 'null'}
+local statusdict = {kind = 'dict', value = {}}
local globaldict = {kind = 'dict', value = {}}
local userdict = {kind = 'dict', value = {
SDict = {kind = 'dict', value = {
normalscale = {kind = 'executable', value = {kind = 'array', value = {}}},
}},
+ TeXDict = {kind = 'dict', value = {
+ Resolution = function() push((pdf.getpkresolution())) end,
+ }},
['@beginspecial'] = {kind = 'executable', value = {kind = 'array', value = {}}},
['@setspecial'] = {kind = 'executable', value = {kind = 'array', value = {}}},
['@endspecial'] = {kind = 'executable', value = {kind = 'array', value = {}}},
}}
+userdict.value.TeXDict.value.VResolution = userdict.value.TeXDict.value.Resolution
local FontDirectory = {kind = 'dict', value = {}}
local ResourceCategories = {kind = 'dict', value = {}}
@@ -860,8 +865,8 @@ local function generic_show(str, ax, ay)
local matrix = psfont.FontMatrix.value
local fonttype = psfont.FontType
if fonttype ~= 0x1CA and fonttype ~= 3 then
- texio.write_nl'Font support is not implemented'
- return true
+ texio.write_nl'luapstricks: Attempt to use unsupported font type.'
+ return nil, 'invalidfont'
end
local x0, y0 = current_point[1], current_point[2]
update_matrix(
@@ -1181,6 +1186,73 @@ systemdict = {kind = 'dict', value = {
end
end,
+ reversepath = function()
+ local state = graphics_stack[#graphics_stack]
+ local path = state.current_path
+ if not path then return end
+ local newpath = lua.newtable(#path, 0)
+ local i = 1
+ local out_ptr = 1
+ -- Iterate over groups starting with "x y m". These can contain multiple subpaths separated with `h`.
+ while path[i+2] == 'm' do
+ local x0, y0 = path[i], path[i + 1]
+ local after = i + 3
+ while path[after] and path[after + 2] ~= 'm' do
+ after = after + 1
+ end
+ local j = after
+ out_ptr = out_ptr + 3 -- Leave space for the initial `x y m`
+ newpath[out_ptr - 1] = 'm'
+ local drop_closepath = true -- If this is true we do not end with a closepath and therefore have to remove the first one.
+ while true do
+ j = j - 1
+ local cmd = path[j]
+ if cmd == 'h' then
+ if j ~= after - 1 then
+ newpath[out_ptr - 3], newpath[out_ptr - 2] = x0, y0
+ if not drop_closepath then
+ newpath[out_ptr] = 'h'
+ out_ptr = out_ptr + 1
+ end
+ out_ptr = out_ptr + 3 -- Leave space for the initial `x y m`
+ newpath[out_ptr - 1] = 'm'
+ end
+ drop_closepath = false
+ elseif cmd == 'm' then
+ newpath[out_ptr - 3], newpath[out_ptr - 2] = path[j - 2], path[j - 1]
+ break
+ else
+ if cmd == 'c' then
+ newpath[out_ptr - 3], newpath[out_ptr - 2] = path[j - 2], path[j - 1]
+ newpath[out_ptr], newpath[out_ptr + 1], newpath[out_ptr + 2], newpath[out_ptr + 3] = path[j - 4], path[j - 3], path[j - 6], path[j - 5]
+ out_ptr = out_ptr + 6
+ newpath[out_ptr] = 'c'
+ j = j - 6
+ elseif cmd == 'l' then
+ newpath[out_ptr - 3], newpath[out_ptr - 2] = path[j - 2], path[j - 1]
+ out_ptr = out_ptr + 2
+ j = j - 2
+ else
+ assert(false)
+ end
+ newpath[out_ptr] = cmd
+ out_ptr = out_ptr + 1
+ end
+ end
+ if not drop_closepath then
+ newpath[out_ptr] = 'h'
+ out_ptr = out_ptr + 1
+ end
+ i = after
+ end
+ state.current_path = newpath
+ local last_cmd = #newpath
+ if newpath[last_cmd] == 'h' then
+ last_cmd = last_cmd - 1
+ end
+ state.current_point[1], state.current_point[2] = newpath[last_cmd - 2], newpath[last_cmd - 1]
+ end,
+
pathforall = function()
local close = pop_proc()
local curve = pop_proc()
@@ -2029,6 +2101,7 @@ systemdict = {kind = 'dict', value = {
local current_path = state.current_path
local current_point = state.current_point
if not current_path then return end
+ if current_path[#current_path] == 'h' then return end
local x, y
for i=#current_path, 1, -1 do
if current_path[i] == 'm' then
@@ -2774,8 +2847,8 @@ systemdict = {kind = 'dict', value = {
local matrix = psfont.FontMatrix.value
local fonttype = psfont.FontType
if fonttype ~= 0x1CA and fonttype ~= 3 then
- texio.write_nl'Font support is not implemented'
- return
+ texio.write_nl'luapstricks: Attempt to use unsupported font type.'
+ ps_error('invalidfont')
end
local w = 0
if fonttype == 0x1CA then
@@ -2858,8 +2931,9 @@ systemdict = {kind = 'dict', value = {
fonts.definers.register(data, fid)
end
fontdict.FID = fid
+ elseif fontdict.FontType == 3 then
else
- texio.write_nl'definefont is not implemnted. Pushing dummy font.'
+ texio.write_nl'luapstricks: definefont has been called with a font type which is not supported by luapstricks. I will continue, but attempts to use this font will fail.'
end
FontDirectory[fontkey] = raw_fontdict
push(raw_fontdict)
@@ -3068,6 +3142,7 @@ systemdict = {kind = 'dict', value = {
push(rand())
end,
+ readonly = function() end, -- Concept not implemented
type = function()
local val = pop()
local tval = type(val)
@@ -3293,6 +3368,7 @@ systemdict = {kind = 'dict', value = {
['true'] = true,
['false'] = false,
systemdict = systemdict,
+ statusdict = statusdict,
globaldict = globaldict,
FontDirectory = FontDirectory,
@@ -3556,7 +3632,7 @@ systemdict = {kind = 'dict', value = {
}}
}}
systemdict.value.systemdict = systemdict
-dictionary_stack = {systemdict, globaldict, userdict}
+dictionary_stack = {systemdict, globaldict, userdict, userdict.value.TeXDict}
-- local execution_stack = {} -- Currently not implemented
-- Quite some stuff is missing here since these aren't implemented yet. Anyway mostly useful for testing.
@@ -3783,17 +3859,10 @@ local func = luatexbase.new_luafunction'showPS'
token.set_lua('showPS', func, 'protected')
lua.get_functions_table()[func] = function()
local command = token.scan_argument(true)
+ -- This will break if any graphics commands are used.
local tokens = parse_ps(command)
execute_ps(tokens)
- for i = 1, #operand_stack do
- local op = operand_stack[i]
- operand_stack[i] = nil
- if type(op) == 'table' then
- print(op.kind, op.value)
- else
- print(op)
- end
- end
+ systemdict.value.stack()
end
local ps_tokens, ps_direct, ps_context, ps_pos_x, ps_pos_y