font-carrier
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -68,8 +68,15 @@ var Base = require('./base.js') | ||
var glys = this.getGlyph(keys) | ||
if (!_.isArray(glys)) { | ||
if (!glys) return '' | ||
if (glys instanceof Glyph) { | ||
return glys.toSvg() | ||
} | ||
return _.map(glys, function(gly) { | ||
return gly.toSvg() | ||
}) | ||
if (_.keys(glys).length > 0) { | ||
return _.map(glys, function(gly) { | ||
return (gly && gly instanceof Glyph) ? gly.toSvg() : '' | ||
}) | ||
} | ||
return '' | ||
}, | ||
@@ -149,4 +156,2 @@ /** | ||
if (glyph) { | ||
//self.__glyphs[unicode] = glyph | ||
//重写unicode | ||
@@ -220,2 +225,3 @@ glyph.set('unicode', unicode) | ||
output: function(options) { | ||
options = options || {} | ||
if (!options.input) { | ||
@@ -222,0 +228,0 @@ options.input = this.toString() |
@@ -60,3 +60,6 @@ var multiline = require('multiline') | ||
<missing-glyph /> | ||
<glyph glyph-name="x" unicode="x" horiz-adv-x="1001" | ||
d="M281 543q-27 -1 -53 -1h-83q-18 0 -36.5 -6t-32.5 -18.5t-23 -32t-9 -45.5v-76h912v41q0 16 -0.5 30t-0.5 18q0 13 -5 29t-17 29.5t-31.5 22.5t-49.5 9h-133v-97h-438v97zM955 310v-52q0 -23 0.5 -52t0.5 -58t-10.5 -47.5t-26 -30t-33 -16t-31.5 -4.5q-14 -1 -29.5 -0.5 | ||
t-29.5 0.5h-32l-45 128h-439l-44 -128h-29h-34q-20 0 -45 1q-25 0 -41 9.5t-25.5 23t-13.5 29.5t-4 30v167h911zM163 247q-12 0 -21 -8.5t-9 -21.5t9 -21.5t21 -8.5q13 0 22 8.5t9 21.5t-9 21.5t-22 8.5zM316 123q-8 -26 -14 -48q-5 -19 -10.5 -37t-7.5 -25t-3 -15t1 -14.5 | ||
t9.5 -10.5t21.5 -4h37h67h81h80h64h36q23 0 34 12t2 38q-5 13 -9.5 30.5t-9.5 34.5q-5 19 -11 39h-368zM336 498v228q0 11 2.5 23t10 21.5t20.5 15.5t34 6h188q31 0 51.5 -14.5t20.5 -52.5v-227h-327z" /> | ||
<% for(var i in glyphs){ | ||
@@ -63,0 +66,0 @@ var glyph = glyphs[i].options; |
@@ -6,3 +6,3 @@ var path = require('path') | ||
var opentype = require('opentype.js') | ||
var DOMParser = require('xmldom').DOMParser; | ||
var DOMParser = require('xmldom').DOMParser | ||
@@ -300,3 +300,3 @@ | ||
} | ||
return outFonts; | ||
return outFonts | ||
@@ -303,0 +303,0 @@ } |
@@ -10,23 +10,23 @@ var _ = require('lodash') | ||
try { | ||
var object = {}; | ||
var $defineProperty = Object.defineProperty; | ||
var result = $defineProperty(object, object, object) && $defineProperty; | ||
var object = {} | ||
var $defineProperty = Object.defineProperty | ||
var result = $defineProperty(object, object, object) && $defineProperty | ||
} catch (error) {} | ||
return result; | ||
return result | ||
}()); | ||
var stringFromCharCode = String.fromCharCode; | ||
var floor = Math.floor; | ||
var stringFromCharCode = String.fromCharCode | ||
var floor = Math.floor | ||
var fromCodePoint = function() { | ||
var MAX_SIZE = 0x4000; | ||
var codeUnits = []; | ||
var highSurrogate; | ||
var lowSurrogate; | ||
var index = -1; | ||
var length = arguments.length; | ||
var MAX_SIZE = 0x4000 | ||
var codeUnits = [] | ||
var highSurrogate | ||
var lowSurrogate | ||
var index = -1 | ||
var length = arguments.length | ||
if (!length) { | ||
return ''; | ||
return '' | ||
} | ||
var result = ''; | ||
var result = '' | ||
while (++index < length) { | ||
var codePoint = Number(arguments[index]); | ||
var codePoint = Number(arguments[index]) | ||
if (!isFinite(codePoint) || // `NaN`, `+Infinity`, or `-Infinity` | ||
@@ -37,19 +37,19 @@ codePoint < 0 || // not a valid Unicode code point | ||
) { | ||
throw RangeError('Invalid code point: ' + codePoint); | ||
throw RangeError('Invalid code point: ' + codePoint) | ||
} | ||
if (codePoint <= 0xFFFF) { // BMP code point | ||
codeUnits.push(codePoint); | ||
codeUnits.push(codePoint) | ||
} else { // Astral code point; split in surrogate halves | ||
// http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae | ||
codePoint -= 0x10000; | ||
highSurrogate = (codePoint >> 10) + 0xD800; | ||
lowSurrogate = (codePoint % 0x400) + 0xDC00; | ||
codeUnits.push(highSurrogate, lowSurrogate); | ||
codePoint -= 0x10000 | ||
highSurrogate = (codePoint >> 10) + 0xD800 | ||
lowSurrogate = (codePoint % 0x400) + 0xDC00 | ||
codeUnits.push(highSurrogate, lowSurrogate) | ||
} | ||
if (index + 1 == length || codeUnits.length > MAX_SIZE) { | ||
result += stringFromCharCode.apply(null, codeUnits); | ||
codeUnits.length = 0; | ||
result += stringFromCharCode.apply(null, codeUnits) | ||
codeUnits.length = 0 | ||
} | ||
} | ||
return result; | ||
return result | ||
}; | ||
@@ -61,5 +61,5 @@ if (defineProperty) { | ||
'writable': true | ||
}); | ||
}) | ||
} else { | ||
String.fromCodePoint = fromCodePoint; | ||
String.fromCodePoint = fromCodePoint | ||
} | ||
@@ -75,10 +75,10 @@ }()); | ||
if (this == null) { | ||
throw TypeError(); | ||
throw TypeError() | ||
} | ||
var string = String(this); | ||
var size = string.length; | ||
var string = String(this) | ||
var size = string.length | ||
// `ToInteger` | ||
var index = position ? Number(position) : 0; | ||
var index = position ? Number(position) : 0 | ||
if (index != index) { // better `isNaN` | ||
index = 0; | ||
index = 0 | ||
} | ||
@@ -90,3 +90,3 @@ // Account for out-of-bounds indices: | ||
// Get the first code unit | ||
var first = string.charCodeAt(index); | ||
var first = string.charCodeAt(index) | ||
var second; | ||
@@ -97,10 +97,10 @@ if ( // check if it’s the start of a surrogate pair | ||
) { | ||
second = string.charCodeAt(index + 1); | ||
second = string.charCodeAt(index + 1) | ||
if (second >= 0xDC00 && second <= 0xDFFF) { // low surrogate | ||
// http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae | ||
return (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000; | ||
return (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000 | ||
} | ||
} | ||
return first; | ||
}; | ||
return first | ||
} | ||
if (Object.defineProperty) { | ||
@@ -113,3 +113,3 @@ Object.defineProperty(String.prototype, 'codePointAt', { | ||
} else { | ||
String.prototype.codePointAt = codePointAt; | ||
String.prototype.codePointAt = codePointAt | ||
} | ||
@@ -192,7 +192,7 @@ }()); | ||
if (err.stack) { | ||
return err.stack.replace(/^/gm, ' ') + '\n\n'; | ||
return err.stack.replace(/^/gm, ' ') + '\n\n' | ||
} | ||
return err.toString(); | ||
return err.toString() | ||
} | ||
console.log(_getErrorString(err)) | ||
} |
{ | ||
"name": "font-carrier", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "字体搬运工,中文字体解决方案,iconfont", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
# font-carrier | ||
[![npm version](https://badge.fury.io/js/font-carrier.svg)](http://badge.fury.io/js/font-carrier) | ||
[![npm version](https://badge.fury.io/js/font-carrier.svg)](http://badge.fury.io/js/font-carrier) [![Build Status](https://travis-ci.org/purplebamboo/font-carrier.svg?branch=master)](https://travis-ci.org/purplebamboo/font-carrier) | ||
font-carrier是一个功能强大的字体操作库,使用它你可以随心所欲的操作字体。 | ||
@@ -175,3 +173,3 @@ | ||
先确保安装依赖包 `npm install` 再运行`npm test`之后访问 ./test/index.html | ||
先确保安装依赖包 `npm install` 再运行`npm test`之后访问 `./test/index.html` | ||
@@ -178,0 +176,0 @@ |
@@ -55,3 +55,6 @@ var fs = require('fs') | ||
//直接output | ||
transFont2.output() | ||
//导出字形 | ||
@@ -63,2 +66,5 @@ //var g = font.getGlyph('我') | ||
fs.writeFileSync('./test/export.svg',path) | ||
//测试多个 | ||
font.getSvg('我是好人') | ||
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
8252271
1120
180