Skip to content

Commit

Permalink
TTF checksums are calculated now.
Browse files Browse the repository at this point in the history
  • Loading branch information
snb2013 committed Jul 19, 2013
1 parent 5e16ec0 commit ffa3e1c
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions lib/ttf.js
Original file line number Diff line number Diff line change
@@ -1,6 1,6 @@
'use strict';

var _ = require('lodash');
var _ = require('lodash');
var jDataView = require('jDataView');

var createCMapTable = require('./ttf/tables/cmap');
Expand Down Expand Up @@ -51,24 51,33 @@ function calc_checksum(buf) {
var nlongs = Math.floor(buf.byteLength / 4);

for (var i = 0; i < nlongs; i) {
var t = buf.getUint32(i*4);
var t = buf.getUint32(i * 4);
sum = ulong(sum t);
}
var leftBytes = buf.byteLength - nlongs * 4; //extra 1..3 bytes found, because table is not aligned. Need to include them in checksum too.
if (leftBytes > 0) {
var leftRes = 0;
for (i = 0; i < 4; i ) {
/*jshint bitwise:false*/
leftRes = (leftRes << 8) ((i < leftBytes) ? buf.getUint8(nlongs * 4 i) : 0);
}
sum = ulong(sum leftRes);
}
return sum;
}

function generateTTF(font) {

// Prepare TTF contours objects. Note, that while sfnt countours are classes,
// ttf contours are just plain arrays of points
_.forEach(font.glyphs, function(glyph) {
glyph.ttfContours = _.map(glyph.contours, function(contour) {
_.forEach(font.glyphs, function (glyph) {
glyph.ttfContours = _.map(glyph.contours, function (contour) {
return contour.points;
});
});

// Process ttf contours data
_.forEach(font.glyphs, function(glyph) {
_.forEach(font.glyphs, function (glyph) {

// 0.3px accuracy is ok. fo 1000x1000.
glyph.ttfContours = utils.simplify(glyph.ttfContours, 0.3);
Expand Down

0 comments on commit ffa3e1c

Please sign in to comment.