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

Run from electron #18

Closed Apidcloud closed 5 years ago

Apidcloud commented 6 years ago

Good evening!

I have no problems using this package from node, but I wonder if there a good way to make this run from electron?

The following error is raised when I attempt to do so: Uncaught Error: A dynamic link library (DLL) initialization routine failed.

Uncaught Error: A dynamic link library (DLL) initialization routine failed.
\\?\D:\Workspace\GitHub\_Scarlett\scarlett-editor\node_modules\canvas-prebuilt\canvas\build\Release\canvas.node
    at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:173:20)
    at Object.Module._extensions..node (module.js:598:18)
    at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:173:20)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (D:\Workspace\GitHub\_Scarlett\scarlett-editor\node_modules\canvas-prebuilt\canvas\lib\bindings.js:3:18)
    at Object.<anonymous> (D:\Workspace\GitHub\_Scarlett\scarlett-editor\node_modules\canvas-prebuilt\canvas\lib\bindings.js:5:3)

I tried to run electron-rebuild on it, but it still happens. I wonder if I would need a specific build from canvas-prebuilt. Any ideas?

Apidcloud commented 6 years ago

Also opened an issue on canvas-prebuilt itself: https://github.com/node-gfx/node-canvas-prebuilt/issues/30

I'll try to build it targeting node 7.9 and use it in this package.

Edit: no luck thus far.

soimy commented 6 years ago

Haven't tried this on electron yet. Maybe it relates to path canvas-prebuild loading local dynamic libraries. Why not search a solution in electron community?

msdf-bmfont-xml is designed as a back-end program. If you decide to use it as front-end, it's better to substitute node-canvas to DOM canvas or WebGL framework like Pixi.js. They are used to render glyphs to final atlas, nothing more.

Apidcloud commented 6 years ago

I think it’s because electron uses a different node version within (1.7.11 uses 7.9), so node canvas has to be built targeting that version instead. I’ve opened an issue in that repository as well, to check whether that’s possible. I’ll keep you updated :) thanks!

Apidcloud commented 6 years ago

Good news! It does seem to work under electron when targeting it (e.g., 1.7.11). See https://github.com/node-gfx/node-canvas-prebuilt/issues/30 for the discussion.

If the author is able to release a version with said target, could you do the same?

For now, I rebuilt node-canvas-prebuilt inside a clone of this package (in its node_modules), and then linked it to a project that consumes it under electron.

Thanks! 💯

soimy commented 6 years ago

Good to hear that! Let me know the news from canvas-prebuilt and I'll update accordingly.

BTW: I'm planning to replace node-canvas and opentype.js to some more light-weighted dependencies in the near future.

Apidcloud commented 6 years ago

Thanks!

Still got no news from canvas-prebuilt, but I'm curious about replacing those libraries. Anything in mind yet?

Edit: I know https://github.com/nascherman/opentype-bmfont (see https://github.com/nascherman/opentype-bmfont/issues/4 though) but it still uses opentype.js under the hood. The generation is accomplished through text-to-svg and svg-to-image.

soimy commented 6 years ago

Haven't got time on this yet, but my plan is replace node-canvas with node-pngjs on back-end, or pixi.js on front-end. opentype.js to more light-weight typr.js on runtime-parser or fontkit maybe.

Apidcloud commented 6 years ago

Still no answer from canvas-prebuilt. Can we release an electron version ourselves for the time being?

soimy commented 5 years ago

@Apidcloud Recent update replaced canvas-prebuilt with jimp, let me know if this update has any luck solving your problem.

Apidcloud commented 5 years ago

Meanwhile I got it working by publishing my own builds of canvas.

But using jimp seems simpler. I will try to test it soon!

Edit: Seems to work 💯 I had no problems with the new version!

It showed the following, though (I guess it makes sense): Use font-face as filename : arialbd Generating 0%|░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░| (0/95) 0s Warning: no bitmap for character ' ' (32), adding to font as empty Generation complete!

Apidcloud commented 5 years ago

Ah. Still regarding that message, the bar doesn't really go further (from 0% to 100%) despite actually working.

soimy commented 5 years ago

Ah, that's absolutely normal. space does not have any glyph so a blank bitmap warning is given. The progress bar just shows that the warning is triggered at 0/95. Just ignore it.

soimy commented 5 years ago

Fixed the progress bar info above warning message via fa5e9a90755e20762b96d75995a4f07a54b96a73 Since it's minor fix, will merge to master in next release.