Skip to content

Commit

Permalink
Upgrade to shelf-pack v1
Browse files Browse the repository at this point in the history
  • Loading branch information
bhousel committed Mar 30, 2016
1 parent 7ba2cfb commit 7b61aa9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
10 changes: 5 additions & 5 deletions js/symbol/glyph_atlas.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ GlyphAtlas.prototype.addGlyph = function(id, name, glyph, buffer) {
packWidth += (4 - packWidth % 4);
packHeight += (4 - packHeight % 4);

var rect = this.bin.allocate(packWidth, packHeight);
if (rect.x < 0) {
var rect = this.bin.packOne(packWidth, packHeight);
if (!rect) {
this.resize();
rect = this.bin.allocate(packWidth, packHeight);
rect = this.bin.packOne(packWidth, packHeight);
}
if (rect.x < 0) {
if (!rect) {
console.warn('glyph bitmap overflow');
return { glyph: glyph, rect: null };
return null;
}

this.index[key] = rect;
Expand Down
12 changes: 5 additions & 7 deletions js/symbol/sprite_atlas.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,10 @@ SpriteAtlas.prototype.allocateImage = function(pixelWidth, pixelHeight) {
var packWidth = pixelWidth + padding + (4 - (pixelWidth + padding) % 4);
var packHeight = pixelHeight + padding + (4 - (pixelHeight + padding) % 4);// + 4;

// We have to allocate a new area in the bin, and store an empty image in it.
// Add a 1px border around every image.
var rect = this.bin.allocate(packWidth, packHeight);
if (rect.x < 0) {
var rect = this.bin.packOne(packWidth, packHeight);
if (!rect) {
console.warn('SpriteAtlas out of space.');
return rect;
return null;
}

return rect;
Expand All @@ -79,8 +77,8 @@ SpriteAtlas.prototype.getImage = function(name, wrap) {
}

var rect = this.allocateImage(pos.width, pos.height);
if (rect.x < 0) {
return rect;
if (!rect) {
return null;
}

var image = new AtlasImage(rect, pos.width / pos.pixelRatio, pos.height / pos.pixelRatio, pos.sdf, pos.pixelRatio / this.pixelRatio);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"point-geometry": "^0.0.0",
"request": "^2.39.0",
"resolve-url": "^0.2.1",
"shelf-pack": "^0.0.1",
"shelf-pack": "^1.0.0",
"supercluster": "^2.0.0",
"unassertify": "^2.0.0",
"unitbezier": "^0.0.0",
Expand Down

0 comments on commit 7b61aa9

Please sign in to comment.