Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented Max-Rects packing #15

Closed
wants to merge 18 commits into from
Closed
Changes from 1 commit
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
29 changes: 12 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,12 @@ function generateBMFont (fontPath, opt, callback) {
if (err) callback(err);
packer.addArray(results);
const textures = packer.bins.map((bin, index) => {
context.fillStyle = '#ffffff';
context.fillRect(0, 0, canvas.width, canvas.height);
// context.clearRect(0, 0, canvas.width, canvas.height);
if(fieldType == "msdf") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use === for equality checks

context.fillStyle = '#ffffff';
context.fillRect(0, 0, canvas.width, canvas.height);
} else {
context.clearRect(0, 0, canvas.width, canvas.height);
}
bin.rects.forEach(rect => {
if (rect.data.imageData) {
context.putImageData(rect.data.imageData, rect.x, rect.y);
Expand Down Expand Up @@ -161,7 +164,6 @@ function generateImage (opt, callback) {
contours.push(currentContour);

let shapeDesc = '';
let firstCommand = true;
contours.forEach(contour => {
shapeDesc += '{';
const lastIndex = contour.length - 1;
Expand All @@ -176,18 +178,10 @@ function generateImage (opt, callback) {
shapeDesc += `(${command.x1}, ${command.y1}); `;
}
shapeDesc += `${command.x}, ${command.y}`;
if (firstCommand) {
bBox.left = command.x;
bBox.bottom = command.y;
bBox.right = command.x;
bBox.top = command.y;
firstCommand = false;
} else {
bBox.left = Math.min(bBox.left, command.x);
bBox.bottom = Math.min(bBox.bottom, command.y);
bBox.right = Math.max(bBox.right, command.x);
bBox.top = Math.max(bBox.top, command.y);
}
bBox.left = Math.min(bBox.left, command.x);
bBox.bottom = Math.min(bBox.bottom, command.y);
bBox.right = Math.max(bBox.right, command.x);
bBox.top = Math.max(bBox.top, command.y);
}
if (index !== lastIndex) {
shapeDesc += '; ';
Expand Down Expand Up @@ -221,7 +215,8 @@ function generateImage (opt, callback) {
}
} else {
for (let i = 0; i < rawImageData.length; i += channelCount) {
pixels.push(rawImageData[i], rawImageData[i], rawImageData[i], 255); // make monochrome w/ alpha
var sdfValue = rawImageData[i];
pixels.push(sdfValue, sdfValue, sdfValue, sdfValue); // make monochrome w/ alpha
}
}
let imageData;
Expand Down