From 529578f58c8221f7fe3deaceecec3a4cf3ff8f2d Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 2 Feb 2017 22:59:15 +0100 Subject: [db] fix design size scaling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As discussed in issue #398. Ad futuram rei memoriam the gist of it: - For the index, all values are scaled (decipoints * sp) / 10 * (7227 / 7200). - The ``bp`` case (the default, OT-standard), needs no conversion because it matches how values are stored in the index. - The ``pt`` case essentially reverts the bp→pt part of scaling done for the database by scaling the asked size by the same factor, i. e. by 7227 / 7200. - The ``dd`` needs an extra 1238 / 1157. Requesting a font at 10pt will then: - ask for a size of 655360 for ``bp`` / default; - ask for 657817 for ``pt``; - ask for 703870 for ``dd``. --- src/luaotfload-database.lua | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/src/luaotfload-database.lua b/src/luaotfload-database.lua index 5e4fd7a..fbe0961 100644 --- a/src/luaotfload-database.lua +++ b/src/luaotfload-database.lua @@ -1042,22 +1042,27 @@ local lookup_fontname = function (specification, name, style) return nil, nil end -local design_size_dimension -local set_size_dimension +local design_size_dimension --- scale asked size if not using bp +local set_size_dimension --- called from config do - --- cf. TeXbook p. 57 + --- cf. TeXbook p. 57; the index stores sizes pre-scaled from bp to + --- sp. This allows requesting sizes we got from the TeX end + --- without further conversion. For the other options *pt* and *dd* + --- we scale the requested size as though the value in the font was + --- specified in the requested unit. + local dimens = { - pt = function (v) return v end, - bp = function (v) return (v * 7227) / 7200 end, - dd = function (v) return (v * 1238) / 1157 end, + bp = false, + pt = function (v) return v * (7227 / 7200) end, + dd = function (v) return v * (7227 / 7200) * (1238 / 1157) end, } design_size_dimension = dimens.bp set_size_dimension = function (dim) local f = dimens [dim] - if f then + if f ~= nil then logreport ("both", 4, "db", "Interpreting design sizes as %q, factor %.6f.", dim, f (1.000000)) @@ -1135,7 +1140,10 @@ lookup_font_name = function (specification) askedsize = 0 end end - askedsize = design_size_dimension (askedsize) + + if design_size_dimension ~= false then + askedsize = design_size_dimension (askedsize) + end resolved, subfont = lookup_familyname (specification, name, @@ -1350,9 +1358,16 @@ local load_font_file = function (filename, subfont) return ret end +--- Design sizes in the fonts are specified in decipoints. For the +--- index these values are prescaled to sp which is what we’re dealing +--- with at the TeX end. + local get_size_info do --- too many upvalues :/ --- rawdata -> (int * int * int | bool) + local sp = 2^16 -- pt + local bp = 7227 / 7200 -- pt + get_size_info = function (rawinfo) local design_size = rawinfo.design_size local design_range_top = rawinfo.design_range_top @@ -1363,13 +1378,13 @@ local get_size_info do --- too many upvalues :/ or design_range_top ~= 0 and design_range_top if fallback_size then - design_size = ((design_size or fallback_size) * 2^16) / 10 - design_range_top = ((design_range_top or fallback_size) * 2^16) / 10 - design_range_bottom = ((design_range_bottom or fallback_size) * 2^16) / 10 + design_size = ((design_size or fallback_size) * sp) / 10 + design_range_top = ((design_range_top or fallback_size) * sp) / 10 + design_range_bottom = ((design_range_bottom or fallback_size) * sp) / 10 - design_size = (design_size * 7227) / 7200 - design_range_top = (design_range_top * 7227) / 7200 - design_range_bottom = (design_range_bottom * 7227) / 7200 + design_size = design_size * bp + design_range_top = design_range_top * bp + design_range_bottom = design_range_bottom * bp return { design_size, design_range_top, design_range_bottom, -- cgit v1.2.3