From 384a9e723799ea39034e1317d6a64a8cd62c1bed Mon Sep 17 00:00:00 2001 From: kiliman Date: Mon, 18 Sep 2017 14:32:18 -0400 Subject: [PATCH] Fix corrupt Windows font (due to CLRF vs LF in charstrings) --- index.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index eb12165..953dbb1 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,9 @@ const Promise = require('bluebird'); const fs = Promise.promisifyAll(require('fs')); +const os = require('os'); +if (!os.EOL) { + os.EOL = (process.platform === 'win32' ? '\r\n' : '\n'); +} const xpath = require('xpath'); const { DOMParser, XMLSerializer } = require('xmldom'); @@ -260,7 +264,8 @@ async function patchCharStrings(dom) { const patchCharStringSubrs = (node, subrs, gsubrs) => { // check for callsubr/callgsubr - const lines = node.childNodes[0].textContent.split('\n'); + + const lines = node.childNodes[0].textContent.split(os.EOL); const newLines = []; let patched = false; lines.forEach(line => { @@ -301,7 +306,7 @@ const patchCharStringSubrs = (node, subrs, gsubrs) => { newLines.push(line); }); if (patched) { - node.childNodes[0].textContent = newLines.join('\n'); + node.childNodes[0].textContent = newLines.join(os.EOL); } };