-
Notifications
You must be signed in to change notification settings - Fork 70
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
Conversation
According to BMFont format, channel 15 means use all rgba channel for glyph. Also, the recent commit on bounding box computing fix present weird positioning on msdfgen output image data, so I revert the first command fix.
SDF distanceRange should be taken into account for padding and baseline computation. Also for accurate and platform dependent metric computation, we should use os2 table sTypoAscender instead of font.ascender.
According to BMFont format, channel 15 means use all rgba channel for glyph. Also, the recent commit on bounding box computing fix present weird positioning on msdfgen output image data, so I revert the first command fix.
Typically set it to 0 for pixel snapping
# Conflicts: # index.js
msdfgen xOffset should be computed from boundBox.left + pad Also x/y offset decimal round have been added for accurate result. (With small bitmap font, decimal >=1 is recommended for accurate result)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're using the Dimbo font to test instead of Roboto, we should remove the Roboto ttf.
index.js
Outdated
context.fillStyle = '#ffffff'; | ||
context.fillRect(0, 0, canvas.width, canvas.height); | ||
// context.clearRect(0, 0, canvas.width, canvas.height); | ||
if(fieldType == "msdf") { |
There was a problem hiding this comment.
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
.eslintrc
Outdated
@@ -0,0 +1,16 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather use prettier
to explicitly format code than eslint to enforce a code style.
index.js
Outdated
@@ -136,6 +137,7 @@ function generateBMFont (fontPath, opt, callback) { | |||
}, | |||
kernings: kernings | |||
}; | |||
if(roundDecimal != null) RoundAllValue(fontData, roundDecimal); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use strict equality checking !==
index.js
Outdated
@@ -248,3 +250,37 @@ function generateImage (opt, callback) { | |||
callback(null, container); | |||
}); | |||
} | |||
|
|||
function RoundAllValue (obj, decimal = 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function names should be camelCased
index.js
Outdated
@@ -248,3 +250,37 @@ function generateImage (opt, callback) { | |||
callback(null, container); | |||
}); | |||
} | |||
|
|||
function RoundAllValue (obj, decimal = 0) { | |||
for (var key in obj) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use let
and const
rather than var
index.js
Outdated
for (var key in obj) { | ||
if (obj.hasOwnProperty(key)) { | ||
if (obj[key] !== null) { | ||
if (typeof(obj[key]) == "object") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use ===
index.js
Outdated
} | ||
|
||
function isNumeric (n) { | ||
return !isNaN(parseFloat(n)) && isFinite(n); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe global.isNaN
coerces its argument to a number anyways, so the parseFloat call is unnecessary. Additionally, isFinite(NaN)
will return false, so I believe use of this function can just be replaced with isFinite
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These codes are based on this solution Validate decimal numbers in JavaScript.
I'm new to js, not sure whether all nodejs version uses ES6. If so we could use Number.isFinite()
instead?
index.js
Outdated
if(!("" + num).includes("e")) { | ||
return +(Math.round(num + "e+" + scale) + "e-" + scale); | ||
} else { | ||
var arr = ("" + num).split("e"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use let
and const
lib/maxrectpacker.js
Outdated
@@ -0,0 +1,35 @@ | |||
"use strict"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would serve better as a separate node module that we could introduce as a dependency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will try to package it in npm module after finished the fine-tuning of these codes. This is my first node.js project, still a lot to learn ;)
index.js
Outdated
function RoundAllValue (obj, decimal = 0) { | ||
for (var key in obj) { | ||
if (obj.hasOwnProperty(key)) { | ||
if (obj[key] !== null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe refactor this to
if(typeof(obj[key]) === "object" && obj[key] !== null) {
...
}
so we don't have to do the null check if it's a number?
Main reason of these artifacts is because msdfgen 1.4 invert both msdf/sdf output channel, so the bg color for msdf atlas should be black now.
This reverts commit 5adb655.
This font will show glyph feather much better, also visual represent of kerning and alignment is more obvious.
@soimy thanks for this terrific PR. The fonts are packed much more efficiently, and the edge artifacts are gone. Fantastic work! I did have one minor issue with running this on my 10.11.6 MacOS computer. Specifically, the executable generated the error |
@neurolabusc msdfgen 1.4 osx binary in this repo is built on freetype v2.8.
|
@neurolabusc Can you help me test the private dynamic library version of the msdf binary? |
@soimy the new version generates the error |
@soimy your inclusion of the additional libraries works. Thanks again. Future versions of my MRIcroGL and Surfice will benefit from your work. |
@neurolabusc Happy to hear that! Keep an eye on my dev branch for more feature and fixes. |
package.json
Outdated
@@ -39,6 +39,8 @@ | |||
"dependencies": { | |||
"canvas": "^1.4.0", | |||
"map-limit": "0.0.1", | |||
"maxrects-packer": "^1.0.2", | |||
"js2xmlparser": "^3.0.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this dependency for anything?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arilotter Sorry about that, it was leaked from another branch (Export xml format)
Major improvement:
Bug fixed: