texlive[60659] Master/texmf-dist: luapstricks (30sep21)

commits+karl at tug.org commits+karl at tug.org
Thu Sep 30 22:12:57 CEST 2021


Revision: 60659
          http://tug.org/svn/texlive?view=revision&revision=60659
Author:   karl
Date:     2021-09-30 22:12:57 +0200 (Thu, 30 Sep 2021)
Log Message:
-----------
luapstricks (30sep21)

Modified Paths:
--------------
    trunk/Master/texmf-dist/tex/lualatex/luapstricks/luapstricks.lua

Added Paths:
-----------
    trunk/Master/texmf-dist/fonts/opentype/public/luapstricks/
    trunk/Master/texmf-dist/fonts/opentype/public/luapstricks/PSTricksDotFont.otf

Added: trunk/Master/texmf-dist/fonts/opentype/public/luapstricks/PSTricksDotFont.otf
===================================================================
(Binary files differ)

Index: trunk/Master/texmf-dist/fonts/opentype/public/luapstricks/PSTricksDotFont.otf
===================================================================
--- trunk/Master/texmf-dist/fonts/opentype/public/luapstricks/PSTricksDotFont.otf	2021-09-30 20:12:42 UTC (rev 60658)
+++ trunk/Master/texmf-dist/fonts/opentype/public/luapstricks/PSTricksDotFont.otf	2021-09-30 20:12:57 UTC (rev 60659)

Property changes on: trunk/Master/texmf-dist/fonts/opentype/public/luapstricks/PSTricksDotFont.otf
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Modified: trunk/Master/texmf-dist/tex/lualatex/luapstricks/luapstricks.lua
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/luapstricks/luapstricks.lua	2021-09-30 20:12:42 UTC (rev 60658)
+++ trunk/Master/texmf-dist/tex/lualatex/luapstricks/luapstricks.lua	2021-09-30 20:12:57 UTC (rev 60659)
@@ -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 @@
 
 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 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 @@
     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 @@
     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 @@
     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 @@
         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 @@
     push(rand())
   end,
 
+  readonly = function() end, -- Concept not implemented
   type = function()
     local val = pop()
     local tval = type(val)
@@ -3293,6 +3368,7 @@
   ['true'] = true,
   ['false'] = false,
   systemdict = systemdict,
+  statusdict = statusdict,
   globaldict = globaldict,
   FontDirectory = FontDirectory,
 
@@ -3556,7 +3632,7 @@
   }}
 }}
 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 @@
 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



More information about the tex-live-commits mailing list.