summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts/make4ht/domfilters/make4ht-odtfonts.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/scripts/make4ht/domfilters/make4ht-odtfonts.lua')
-rw-r--r--Master/texmf-dist/scripts/make4ht/domfilters/make4ht-odtfonts.lua26
1 files changed, 26 insertions, 0 deletions
diff --git a/Master/texmf-dist/scripts/make4ht/domfilters/make4ht-odtfonts.lua b/Master/texmf-dist/scripts/make4ht/domfilters/make4ht-odtfonts.lua
new file mode 100644
index 00000000000..68c8ecadc25
--- /dev/null
+++ b/Master/texmf-dist/scripts/make4ht/domfilters/make4ht-odtfonts.lua
@@ -0,0 +1,26 @@
+return function(dom, params)
+ -- fix ODT style for fonts
+ -- sometimes, fonts have missing size, we need to patch styles
+ local properties = get_filter_settings "odtfonts" or {}
+ local fix_lgfile_fonts = params.patched_lg_fonts or properties.patched_lg_fonts or {}
+ for _, style in ipairs(dom:query_selector "style|style") do
+ local typ = style:get_attribute("style:family")
+ if typ == "text" then
+ -- detect if the style is for font
+ local style_name = style:get_attribute("style:name")
+ local name, size, size2, size3 = style_name:match("(.-)%-(%d*)x%-(%d*)x%-(%d+)")
+ if name then
+ -- find if the style corresponds to a problematic font (it is set in formats/make4ht-odt.lua)
+ local used_name = name .. "-" .. size
+ if fix_lgfile_fonts[used_name] then
+ -- copy current style and fix the name
+ local new = style:copy_node()
+ new:set_attribute("style:name", string.format("%s-x-%sx-%s", name, size2, size3))
+ local parent = style:get_parent()
+ parent:add_child_node(new)
+ end
+ end
+ end
+ end
+ return dom
+end