soimy / msdf-bmfont-xml

Generate BMFont texture and spec XML using msdfgen
https://soimy.github.io/msdf-bmfont-xml/
MIT License
316 stars 46 forks source link

Recent changes regarding fontBuffer does not seem to work if fontPath is a string #49

Closed Sechgulo closed 4 years ago

Sechgulo commented 4 years ago

There is some confusion regarding 2.5.3 and the latest changes done here regarding how fontFace is set: https://github.com/soimy/msdf-bmfont-xml/commit/6b659b4db492c3667ef0943cb5f43920d85790a1

Setting fontFace to filename (which can be an atlas_path string) if it exists, over path.basename(fontPath, path.extname(fontPath)); results in fontFace now being the full path if filename is a path.

Either let extracted filename take precedence: const fontface = path.basename(fontPath, path.extname(fontPath)) || filename;

Or set fontFace afterwards (not sure if option X and Y is one and the same in all cases, depending on if fontPath is a Buffer or not).

Option X:

let fontface = filename || path.basename(fontPath, path.extname(fontPath));
if(!filename) {
  filename = fontface;
  console.log(`Use font-face as filename : ${filename}`);
} else {
  if (opt.filename) fontDir = path.dirname(opt.filename);
  filename = opt.filename = fontface = path.basename(filename, path.extname(filename));
}

Option Y:

let fontface = filename || path.basename(fontPath, path.extname(fontPath));
if(!filename) {
  filename = fontface;
  console.log(`Use font-face as filename : ${filename}`);
} else {
  if (opt.filename) fontDir = path.dirname(opt.filename);
  fontface = path.basename(fontPath, path.extname(fontPath));
  filename = opt.filename = fontface = path.basename(filename, path.extname(filename));
}
soimy commented 4 years ago

@Sechgulo this commit ae559fd should fix your problem, thanks for the report! If this fix do work, I'll publish a new version.