Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ export default class TinySDF {
gridInner[j] = INF;

} else { // aliased pixels
const d = 0.5 - a;
// gamma correction
const aLin = Math.pow(a, 1.0 / 2.2);
const d = 0.5 - aLin;
gridOuter[j] = d > 0 ? d * d : 0;
gridInner[j] = d < 0 ? d * d : 0;
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"scripts": {
"pretest": "eslint index.js index.html test",
"test": "node --test",
"bench": "node ./test/bench.js",
"start": "st --no-cache --localhost --index index.html ."
},
"repository": {
Expand Down
31 changes: 31 additions & 0 deletions test/bench.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import TinySDF from '../index.js';
import nodeCanvas from 'canvas';


class MockTinySDF extends TinySDF {
_createCanvas(size) {
return nodeCanvas.createCanvas(size, size);
}
}

function bench(iterationsCount) {
const sdf = new MockTinySDF({
fontSize: 48,
buffer: 3
});
for (let i = 0; i < iterationsCount; ++i) {
sdf.draw('@');
}
}

function getCurrentTimestamp() {
return performance.now();
}

const ITERATIONS_COUNT = 1e5;
const tStart = getCurrentTimestamp();
bench(ITERATIONS_COUNT);
const tEnd = getCurrentTimestamp();
const dtSec = (tEnd - tStart) * 0.001;
console.log(`Durations for ${ITERATIONS_COUNT} iterations: ${dtSec} seconds`);

16 changes: 8 additions & 8 deletions test/fixtures/1-metrics.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"width": 48,
"actualBoundingBoxLeft": 0,
"actualBoundingBoxRight": 48,
"actualBoundingBoxAscent": 39.2158203125,
"actualBoundingBoxDescent": 4.6083984375,
"emHeightAscent": 50.8798828125,
"emHeightDescent": 16.3203125,
"alphabeticBaseline": 13.9189453125
"width": 48.2197265625,
"actualBoundingBoxLeft": 1.8720703125,
"actualBoundingBoxRight": 45.263671875,
"actualBoundingBoxAscent": 39.16796875,
"actualBoundingBoxDescent": 4.65625,
"emHeightAscent": 51,
"emHeightDescent": 17,
"alphabeticBaseline": 14.0390625
}
6 changes: 3 additions & 3 deletions test/fixtures/1-out.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"width": 54,
"width": 50,
"height": 51,
"glyphWidth": 48,
"glyphWidth": 44,
"glyphHeight": 45,
"glyphTop": 40,
"glyphLeft": 0,
"glyphAdvance": 48
"glyphAdvance": 48.2197265625
}
Binary file modified test/fixtures/1-raw.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/fixtures/1-sdf.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading