diff options
| author | Michael Williamson <mike@zwobble.org> | 2021-01-19 20:25:21 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2021-01-19 20:25:21 +0000 |
| commit | a423d1a368eb1e81951e5d8a75347fa7997152bf (patch) | |
| tree | 4c8cf748c3f01552831ca538a9846ac19a075bfa /lib | |
| parent | f141817b947e36a9db7c56600c5031de32bb0fb9 (diff) | |
Convert symbols in supported fonts to corresponding Unicode characters
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/docx/body-reader.js | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/docx/body-reader.js b/lib/docx/body-reader.js index 2616dde..90c2b39 100644 --- a/lib/docx/body-reader.js +++ b/lib/docx/body-reader.js @@ -1,6 +1,7 @@ exports.createBodyReader = createBodyReader; exports._readNumberingProperties = readNumberingProperties; +var dingbatToUnicode = require("dingbat-to-unicode"); var _ = require("underscore"); var documents = require("../documents"); @@ -167,6 +168,24 @@ function BodyReader(options) { return emptyResult(); } + function readSymbol(element) { + // See 17.3.3.30 sym (Symbol Character) of ECMA-376 4th edition Part 1 + var font = element.attributes["w:font"]; + var char = element.attributes["w:char"]; + var unicodeCharacter = dingbatToUnicode.hex(font, char); + if (unicodeCharacter == null && /^F0..$/.test(char)) { + unicodeCharacter = dingbatToUnicode.hex(font, char.substring(2)); + } + + if (unicodeCharacter == null) { + return emptyResultWithMessages([warning( + "A w:sym element with an unsupported character was ignored: char " + char + " in font " + font + )]); + } else { + return elementResult(new documents.Text(unicodeCharacter.string)); + } + } + function noteReferenceReader(noteType) { return function(element) { var noteId = element.attributes["w:id"]; @@ -240,6 +259,7 @@ function BodyReader(options) { "w:softHyphen": function(element) { return elementResult(new documents.Text("\u00AD")); }, + "w:sym": readSymbol, "w:hyperlink": function(element) { var relationshipId = element.attributes["r:id"]; var anchor = element.attributes["w:anchor"]; |
