[latex3-commits] [git/LaTeX3-latex3-luaotfload] dev: Improve rounding (7a69806)

Marcel Fabian Krüger tex at 2krueger.de
Wed Apr 22 05:58:57 CEST 2020


Repository : https://github.com/latex3/luaotfload
On branch  : dev
Link       : https://github.com/latex3/luaotfload/commit/7a6980658fbc4b41cd407bfce2c433478a5cc5c3

>---------------------------------------------------------------

commit 7a6980658fbc4b41cd407bfce2c433478a5cc5c3
Author: Marcel Fabian Krüger <tex at 2krueger.de>
Date:   Wed Apr 22 05:58:45 2020 +0200

    Improve rounding


>---------------------------------------------------------------

7a6980658fbc4b41cd407bfce2c433478a5cc5c3
 src/luaotfload-harf-define.lua | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/luaotfload-harf-define.lua b/src/luaotfload-harf-define.lua
index 12461a0..56d4a74 100644
--- a/src/luaotfload-harf-define.lua
+++ b/src/luaotfload-harf-define.lua
@@ -43,6 +43,11 @@ local gpostag = hb.Tag.new("GPOS")
 local invalid_l         = hb.Language.new()
 local invalid_s         = hb.Script.new()
 
+local floor = math.floor
+local function round(x)
+  return floor(x + 0.5)
+end
+
 local get_designsize do
   -- local lpeg = lpeg or require'lpeg'
   -- local size_patt = 'size' * lpeg.C(2)/function(s)
@@ -62,7 +67,7 @@ local get_designsize do
         local off = feature_off + 1 + unpack(">H", buf, off + 4)
         local off = off + unpack(">H", buf, off)
         local design_size = unpack(">H", buf, off) -- unpack(">HHHHH", buf, off))
-        return math.floor(design_size * factor)
+        return round(design_size * factor)
       end
     end
     return 655360
@@ -263,7 +268,7 @@ local function scalefont(data, spec)
   local gid_offset = data.gid_offset
 
   if size < 0 then
-    size = size * data.designsize // -1000
+    size = round(size * data.designsize / -1000)
   end
 
   -- We shape in font units (at UPEM) and then scale output with the desired





More information about the latex3-commits mailing list.