aboutsummaryrefslogtreecommitdiff
path: root/mammoth/docx/body_xml.py
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2021-01-19 22:04:39 +0000
committerMichael Williamson <mike@zwobble.org>2021-01-19 22:04:39 +0000
commitef75769d9e46ec370d51a845cb893efc07ab4ac8 (patch)
treea419d7d70826d6a7a2fdf89a9915e032fc4f6f32 /mammoth/docx/body_xml.py
parent1c118c9f4457b6d1fd5c3108fd9145ad0153bcab (diff)
Convert symbols in supported fonts to corresponding Unicode characters
Diffstat (limited to 'mammoth/docx/body_xml.py')
-rw-r--r--mammoth/docx/body_xml.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/mammoth/docx/body_xml.py b/mammoth/docx/body_xml.py
index d4fdccf..8329bcf 100644
--- a/mammoth/docx/body_xml.py
+++ b/mammoth/docx/body_xml.py
@@ -6,6 +6,7 @@ from .. import documents
from .. import results
from .. import lists
from . import complex_fields
+from .dingbats import dingbats
from .xmlparser import node_types, XmlElement
from .styles_xml import Styles
from .uris import replace_fragment, uri_to_zip_entry_name
@@ -244,6 +245,25 @@ def _create_reader(numbering, content_types, relationships, styles, docx_file, f
def soft_hyphen(element):
return _success(documents.text(u"\u00ad"))
+ def symbol(element):
+ # See 17.3.3.30 sym (Symbol Character) of ECMA-376 4th edition Part 1
+ font = element.attributes.get("w:font")
+ char = element.attributes.get("w:char")
+
+ unicode_code_point = dingbats.get((font, int(char, 16)))
+
+ if unicode_code_point is None and re.match("^F0..", char):
+ unicode_code_point = dingbats.get((font, int(char[2:], 16)))
+
+ if unicode_code_point is None:
+ warning = results.warning("A w:sym element with an unsupported character was ignored: char {0} in font {1}".format(
+ char,
+ font,
+ ))
+ return _empty_result_with_message(warning)
+ else:
+ return _success(documents.text(unichr(unicode_code_point)))
+
def table(element):
properties = element.find_child_or_null("w:tblPr")
@@ -491,6 +511,7 @@ def _create_reader(numbering, content_types, relationships, styles, docx_file, f
"w:tab": tab,
"w:noBreakHyphen": no_break_hyphen,
"w:softHyphen": soft_hyphen,
+ "w:sym": symbol,
"w:tbl": table,
"w:tr": table_row,
"w:tc": table_cell,