diff options
author | Karl Berry <karl@freefriends.org> | 2021-09-30 20:12:57 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2021-09-30 20:12:57 +0000 |
commit | 4bc5590f847b8998f6582c923607d8464804c427 (patch) | |
tree | d04f49c6604b8da2987c49b193f42e51e6994806 | |
parent | e0203f54b481dfa2e7dc0ef0d286e443bc188ac0 (diff) |
luapstricks (30sep21)
git-svn-id: svn://tug.org/texlive/trunk@60659 c570f23f-e606-0410-a88d-b1316a301751
-rw-r--r-- | Master/texmf-dist/fonts/opentype/public/luapstricks/PSTricksDotFont.otf | bin | 0 -> 7624 bytes | |||
-rw-r--r-- | Master/texmf-dist/tex/lualatex/luapstricks/luapstricks.lua | 103 |
2 files changed, 86 insertions, 17 deletions
diff --git a/Master/texmf-dist/fonts/opentype/public/luapstricks/PSTricksDotFont.otf b/Master/texmf-dist/fonts/opentype/public/luapstricks/PSTricksDotFont.otf Binary files differnew file mode 100644 index 00000000000..eaa5a6b93eb --- /dev/null +++ b/Master/texmf-dist/fonts/opentype/public/luapstricks/PSTricksDotFont.otf diff --git a/Master/texmf-dist/tex/lualatex/luapstricks/luapstricks.lua b/Master/texmf-dist/tex/lualatex/luapstricks/luapstricks.lua index eebca868012..8ae9eed76d1 100644 --- a/Master/texmf-dist/tex/lualatex/luapstricks/luapstricks.lua +++ b/Master/texmf-dist/tex/lualatex/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 |