Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

svg2ttf

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svg2ttf - npm Package Compare versions

Comparing version 2.0.2 to 2.1.0

6

CHANGELOG.md

@@ -0,1 +1,7 @@

2.1.0 / 2015-10-28
------------------
- Fixed smoothness at the ends of interpolated cubic beziers.
2.0.2 / 2015-08-23

@@ -2,0 +8,0 @@ ------------------

10

index.js

@@ -130,2 +130,8 @@ /*

// Calculate accuracy for cubicToQuad transformation
// For glyphs with height and width smaller than 500 use relative 0.06% accuracy,
// for larger glyphs use fixed accuracy 0.3.
var glyphSize = Math.max(glyph.width, glyph.height);
var accuracy = (glyphSize > 500) ? 0.3 : glyphSize * 0.0006;
//SVG transformations

@@ -136,3 +142,5 @@ var svgPath = new SvgPath(glyph.d)

.unarc()
.iterate(svg.cubicToQuad);
.iterate(function(segment, index, x, y) {
return svg.cubicToQuad(segment, index, x, y, accuracy);
});
var sfntContours = svg.toSfntCoutours(svgPath);

@@ -139,0 +147,0 @@

46

lib/math.js

@@ -32,48 +32,3 @@ 'use strict';

// converts cubic bezier to quad
function toQuad(p1, c1, c2, p2) {
// Quad control point is (3*c2 - p2 + 3*c1 - p1)/4
return [p1, c2.mul(3).sub(p2).add(c1.mul(3)).sub(p1).div(4), p2];
}
/*
* Aproximates cubic curve to 2 quad curves. Returns array of quad curves
*
* 1. Split cubic bezier-> 2 cubic beziers, by midpoint
* 2. Replace each cubic bezier with quad bezier
*
* This is a simplified approach. It can be improved by adaptive splitting,
* but in real life that's not needed.
*
* (!) We could use more slices, but FONT SIZE DOES MATTER !!!
*/
function bezierCubicToQuad(p1, c1, c2, p2) {
// check first, if we can aproximate with quad directly
// |p2 - 3*c2 + 3*c1 - p1|/2 should be small (zero in ideal)
// http://www.caffeineowl.com/graphics/2d/vectorial/cubic2quad01.html
var cpDistance = p2.sub(c2.mul(3)).add(c1.mul(3)).sub(p1).dist()/2;
if (cpDistance <= 3) {
return [ toQuad(p1, c1, c2, p2) ];
}
// Split to 2 qubic beziers
// https://www.atalasoft.com/blogs/stevehawley/may-2013/how-to-split-a-cubic-bezier-curve
// http://www.timotheegroleau.com/Flash/articles/cubic_bezier/bezier_lib.as
// midpoints of qubic bezier
// (p2 + 3*c2 + 3*c1 + p1)/8
var mp = p2.add(c2.mul(3)).add(c1.mul(3)).add(p1).div(8);
var q1 = toQuad(p1, p1.add(c1).div(2), p1.add(c2).add(c1.mul(2)).div(4), mp);
var q2 = toQuad(mp, p2.add(c1).add(c2.mul(2)).div(4), p2.add(c2).div(2), p2);
// now replace each half with quad curve
return [ q1, q2 ];
}
/*
* Check if 3 points are in line, and second in the midle.

@@ -100,3 +55,2 @@ * Used to replace quad curves with lines or join lines

module.exports.Point = Point;
module.exports.bezierCubicToQuad = bezierCubicToQuad;
module.exports.isInLine = isInLine;
'use strict';
var _ = require('lodash');
var cubic2quad = require('cubic2quad');
var DOMParser = require('xmldom').DOMParser;
var math = require('./math');
var ucs2 = require('./ucs2');

@@ -154,16 +154,16 @@

function cubicToQuad(segment, index, x, y) {
function cubicToQuad(segment, index, x, y, accuracy) {
if (segment[0] === 'C') {
var quadCurves = math.bezierCubicToQuad(
new math.Point(x, y),
new math.Point(segment[1], segment[2]),
new math.Point(segment[3], segment[4]),
new math.Point(segment[5], segment[6]),
0.3
var quadCurves = cubic2quad(
x, y,
segment[1], segment[2],
segment[3], segment[4],
segment[5], segment[6],
accuracy
);
var res = [];
_.forEach(quadCurves, function(curve) {
res.push(['Q', curve[1].x, curve[1].y, curve[2].x, curve[2].y]);
});
for (var i = 2; i < quadCurves.length; i += 4) {
res.push(['Q', quadCurves[i], quadCurves[i + 1], quadCurves[i + 2], quadCurves[i + 3]]);
}
return res;

@@ -170,0 +170,0 @@ }

{
"name": "svg2ttf",
"version": "2.0.2",
"version": "2.1.0",
"description": "Converts SVG font to TTF font",

@@ -18,2 +18,3 @@ "keywords": [

"argparse": "^1.0.2",
"cubic2quad": "^1.0.0",
"lodash": "^3.6.0",

@@ -20,0 +21,0 @@ "microbuffer": "^1.0.0",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc