summaryrefslogtreecommitdiff
path: root/otfl-font-tfm.lua
diff options
context:
space:
mode:
Diffstat (limited to 'otfl-font-tfm.lua')
-rw-r--r--otfl-font-tfm.lua23
1 files changed, 19 insertions, 4 deletions
diff --git a/otfl-font-tfm.lua b/otfl-font-tfm.lua
index c5140ff..2f96de4 100644
--- a/otfl-font-tfm.lua
+++ b/otfl-font-tfm.lua
@@ -228,12 +228,27 @@ local charactercache = { }
-- a virtual font has italic correction make sure to set the
-- has_italic flag. Some more flags will be added in the future.
-function tfm.do_scale(tfmtable, scaledpoints)
- -- tfm.prepare_base_kerns(tfmtable) -- optimalization
+
+function tfm.calculate_scale(tfmtable, scaledpoints, relativeid)
if scaledpoints < 0 then
scaledpoints = (- scaledpoints/1000) * tfmtable.designsize -- already in sp
end
local delta = scaledpoints/(tfmtable.units or 1000) -- brr, some open type fonts have 2048
+ return scaledpoints, delta
+end
+
+function tfm.do_scale(tfmtable, scaledpoints, relativeid)
+ -- tfm.prepare_base_kerns(tfmtable) -- optimalization
+ local scaledpoints, delta = tfm.calculate_scale(tfmtable, scaledpoints, relativeid)
+ if enable_auto_r_scale and relativeid then -- for the moment this is rather context specific
+ local relativedata = fontdata[relativeid]
+ local id_x_height = relativedata and relativedata.parameters and relativedata.parameters.x_height
+ local tf_x_height = id_x_height and tfmtable.parameters and tfmtable.parameters.x_height * delta
+ if tf_x_height then
+ scaledpoints = (id_x_height/tf_x_height) * scaledpoints
+ delta = scaledpoints/(tfmtable.units or 1000)
+ end
+ end
local hdelta, vdelta = delta, delta
local t = { }
-- unicoded unique descriptions shared cidinfo characters changed parameters indices
@@ -628,8 +643,8 @@ end
function tfm.cleanup(tfmdata) -- we need a cleanup callback, now we miss the last one
end
-function tfm.scale(tfmtable, scaledpoints)
- local t, factor = tfm.do_scale(tfmtable, scaledpoints)
+function tfm.scale(tfmtable, scaledpoints, relativeid)
+ local t, factor = tfm.do_scale(tfmtable, scaledpoints, relativeid)
t.factor = factor
t.ascender = factor*(tfmtable.ascender or 0)
t.descender = factor*(tfmtable.descender or 0)