testAtlas = {
const padding = 1;
const positions = {};
const bins = [];
testGlyphs.forEach(glyph => {
const { id, bitmap, metrics } = glyph;
const { width, height } = bitmap;
if (width === 0 || height === 0) return;
const bin = { x: 0, y: 0, w: width + 2 * padding, h: height + 2 * padding };
bins.push(bin);
positions[id] = { rect: bin, metrics };
});
const { w, h } = potpack(bins);
const image = new AlphaImage({ width: w || 1, height: h || 1 });
testGlyphs.forEach(glyph => {
const { id, bitmap, metrics } = glyph;
const bin = positions[id].rect;
let srcPt = { x: 0, y: 0 };
let dstPt = { x: bin.x + padding, y: bin.y + padding };
AlphaImage.copy(bitmap, image, srcPt, dstPt, bitmap);
});
return { image, positions };
}