mirror of
https://github.com/mapbox/node-fontnik.git
synced 2026-02-01 16:47:18 +00:00
Tests take place of api/.
This commit is contained in:
parent
7cdecbbe50
commit
824e51f702
18
api/api.js
18
api/api.js
@ -1,18 +0,0 @@
|
||||
|
||||
|
||||
var metrics = new Font('Open Sans Regular').metrics;
|
||||
zlib.deflate(metrics);
|
||||
send(metrics);
|
||||
|
||||
style = {
|
||||
layername: ['fontstack', 'fontstack']
|
||||
};
|
||||
|
||||
zlib.inflate(tile);
|
||||
fontserver.shapeTile(tile, style, function(err, tile) {
|
||||
});
|
||||
|
||||
tile.shape(style, function(err, buffer) {
|
||||
zlib.deflate(tile);
|
||||
send(tile);
|
||||
});
|
||||
@ -1,12 +0,0 @@
|
||||
var fontserver = require('./');
|
||||
var zlib = require('zlib');
|
||||
|
||||
var font = new fontserver.Font('Arial Unicode MS');
|
||||
|
||||
var metrics = font.metrics;
|
||||
console.warn('uncompressed', metrics.length);
|
||||
zlib.deflate(metrics, function(err, data) {
|
||||
if (err) throw err;
|
||||
console.warn('compressed', data.length);
|
||||
console.warn('ok');
|
||||
});
|
||||
@ -1,32 +0,0 @@
|
||||
<meta charset="utf-8">
|
||||
<body>
|
||||
<script type="text/javascript">
|
||||
|
||||
var canvas = document.createElement('canvas');
|
||||
canvas.width = 512;
|
||||
canvas.height = 512;
|
||||
var ctx = canvas.getContext('2d');
|
||||
|
||||
if (window.devicePixelRatio) {
|
||||
canvas.style.width = canvas.width + 'px';
|
||||
canvas.style.height = canvas.height + 'px';
|
||||
canvas.width *= devicePixelRatio;
|
||||
canvas.height *= devicePixelRatio;
|
||||
ctx.scale(devicePixelRatio, devicePixelRatio);
|
||||
}
|
||||
|
||||
var text = "Foo Bar! این یک آزمایش است";
|
||||
|
||||
ctx.fillStyle = '#ccc';
|
||||
ctx.font = "14px Open Sans, Arial Unicode MS";
|
||||
var metrics = ctx.measureText(text);
|
||||
ctx.fillRect(200, 188, metrics.width, 16);
|
||||
ctx.fillStyle = 'black';
|
||||
ctx.fillText(text, 200, 200);
|
||||
|
||||
|
||||
|
||||
|
||||
document.body.appendChild(canvas);
|
||||
|
||||
</script>
|
||||
61
api/tile.js
61
api/tile.js
@ -1,61 +0,0 @@
|
||||
var zlib = require('zlib');
|
||||
var fs = require('fs');
|
||||
var async = require('async');
|
||||
var fontserver = require('./');
|
||||
|
||||
|
||||
// var tile = new Tile(<uncompressed data as buffer>)
|
||||
// tile.serialize() => <uncompressed data as buffer>
|
||||
// tile.simplify(function(err) {})
|
||||
|
||||
|
||||
function workflow(finalize) {
|
||||
// var data = fs.readFileSync('./tiles/14-8801-5373.vector.pbf'); // berlin
|
||||
var data = fs.readFileSync('./tiles/14-14553-6450.vector.pbf');
|
||||
// console.warn('SIZE initial compressed', data.length);
|
||||
zlib.inflate(data, function(err, data) {
|
||||
// console.warn('SIZE initial', data.length);
|
||||
if (err) throw err;
|
||||
var tile = new fontserver.Tile(data);
|
||||
|
||||
// console.time('simplify');
|
||||
tile.simplify(function(err) {
|
||||
// console.timeEnd('simplify');
|
||||
if (err) throw err;
|
||||
|
||||
// console.warn('SIZE simplified', tile.serialize().length);
|
||||
|
||||
console.time('shape');
|
||||
tile.shape('Open Sans, Arial Unicode MS', function(err) {
|
||||
console.timeEnd('shape');
|
||||
if (err) throw err;
|
||||
|
||||
// console.time('serialize');
|
||||
var after = tile.serialize();
|
||||
// console.timeEnd('serialize');
|
||||
// console.warn('SIZE after', after.length);
|
||||
|
||||
zlib.deflate(after, function(err, compressed) {
|
||||
if (err) throw err;
|
||||
fs.writeFileSync('out.sdf', compressed);
|
||||
// console.warn('SIZE after compressed', compressed.length);
|
||||
finalize(null);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
var count = 0;
|
||||
async.whilst(
|
||||
function() { return count < 10; },
|
||||
function(callback) {
|
||||
count++;
|
||||
workflow(callback);
|
||||
},
|
||||
function(err) {
|
||||
console.warn(err, 'ok');
|
||||
}
|
||||
);
|
||||
Loading…
x
Reference in New Issue
Block a user