Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
svg2ttf(filepath) {
const output = filepath.replace('.svg', '.ttf');
const svg = fs.readFileSync(filepath, 'utf-8');
fs.writeFileSync(output, new Buffer(svg2ttf(svg).buffer));
return Promise.resolve(output);
},
function toTtf(buffer, options) {
return Buffer.from(svg2ttf(buffer, options).buffer);
}
const generateTTFfromSVGFont = (svgFont: string, options: Object) => {
const font = svg2ttf(svgFont, options.formatOptions.ttf);
return new Buffer(font.buffer);
};
createSVG().then(() => {
const TTF_PATH = path.join(ORBIT_ICONS_DIR, "orbit-icons.ttf");
const TTF = svg2ttf(fs.readFileSync(path.join(ORBIT_ICONS_DIR, "orbit-icons.svg"), "utf8"), {});
fs.writeFileSync(TTF_PATH, Buffer.from(TTF.buffer));
fs.writeFileSync(
path.join(ORBIT_ICONS_DIR, "orbit-icons.woff2"),
ttf2woff2(fs.readFileSync(TTF_PATH)),
);
});
function generateVerifyFile(svgFont: string, iconSet, withPng, toFolder) {
//Convert the SVG file into a TTF file so that more browsers can parse and show it
const ttf = svg2ttf(svgFont, {});
fs.writeFileSync(
path.join(toFolder, "source-font.ttf"),
new Buffer(ttf.buffer)
);
//load the template for the verification file which contains some generic HTML
let htmlTemplate = fs.readFileSync(
path.join(__dirname, "..", "/resources/verify.html"),
"utf-8"
);
let iconContent = [];
let cssRules = [];
//Add a header to to the table
iconContent.push(
`<div class="row"></div>
function svgToContours({width, height, d}) {
const accuracy = Math.max(width, height) * 0.0006
const svgPath = new SvgPath(d)
.abs()
.unshort()
.unarc()
.iterate((segment, index, x, y) => svg.cubicToQuad(segment, index, x, y, accuracy))
const sfntContours = svg.toSfntCoutours(svgPath)
return sfntContours.map(sfntContour => {
const contour = new sfnt.Contour()
contour.points = sfntContour.map(sfntPoint => {
const point = new sfnt.Point()
point.x = sfntPoint.x
point.y = sfntPoint.y
point.onCurve = sfntPoint.onCurve
return point
})
return contour
})
}
return sfntContours.map(sfntContour => {
const contour = new sfnt.Contour()
contour.points = sfntContour.map(sfntPoint => {
const point = new sfnt.Point()
point.x = sfntPoint.x
point.y = sfntPoint.y
point.onCurve = sfntPoint.onCurve
return point
})
return contour
})
}
contour.points = sfntContour.map(sfntPoint => {
const point = new sfnt.Point()
point.x = sfntPoint.x
point.y = sfntPoint.y
point.onCurve = sfntPoint.onCurve
return point
})
.iterate((segment, index, x, y) => svg.cubicToQuad(segment, index, x, y, accuracy))